
$(document).ready(function() {

    //this is the instance of the "pop-up form"
    $("#dialog").dialog(
			{
			    autoOpen: false,
			    modal: true,
			    width: 480,
			    height: 250,
			    resizable: false,
			    position: "top"
			}
		);

    //remove the title bar		
    $("#dialog").dialog().parents(".ui-dialog").find(".ui-dialog-titlebar").remove();

    //Only submit the form if the user did not select "No Funds"
    $("#divEvalForm1_SubmitButton").click(function() {
        //alert($(".savedMethod").val());
        if (($('input[name=divEvalForm1_NoFunds]:checked').val() == 'NoFunds' || $(".savedMethod").val() == "NoFunds")
				&& Page_IsValid && $(".showPopup").val() == "True") {
            //hide all select buttons to get around IE 6 bug
            $("select").css("display", "none");

            //show popup asking if user wants to change their financing option
            $("#dialog").dialog("open");

            return false;
        }
        return true;
    });

    //if the yes button is clicked, change the financial sourcing question to be other
    $("#popup-submit").click(function() {
        $("#dialog").dialog("close");
        
        //change the income source to be "other"
        $("#divEvalForm1_FinanceOther").attr("checked", "checked");
        $("#divEvalForm1_FinanceOtherDesc").attr("value", "0");
        $("#divEvalForm1_savedFinancingMethod").attr("value", "other");

        //submit the form so user goes to thank u page
        $("#divEvalForm1_SubmitButton").click();
    });

    //if the no button is clicked hide the modal window and submt the form
    $("#popup-no").click(function() {
        
        $("#dialog").dialog("close");
        $(".showPopup").attr("value", "False");
        $("#divEvalForm1_SubmitButton").click();
    });
});
 
function radioCheck(oSrc, args) {
    var valid;
    var check = document.forms['form1'].elements[document.getElementById('divEvalForm1_Borrowing').name];

    for(var i = 0; i < check.length; i++)
    {    
        if (check[i].checked == true) {
            if ((check[i].value == "NoFunds")) {
                document.getElementById('divEvalForm1_savedFinancingMethod').value = "NoFunds";
                args.IsValid = true;
                break;
            }
            if ((check[i].value == "FinanceOther") && (document.getElementById('divEvalForm1_FinanceOtherDesc').value == "")) {              
               document.getElementById('divEvalForm1_FinanceOtherDesc').style.backgroundColor="#ff0000";
               args.IsValid = false;
               break;
            }
            
            args.IsValid = true;
            break;
        }  
        else {
            args.IsValid = false;
        }       
    }    
}

function showChildInfo(num) {
    var x;
    var age;
    var gender;
    var liveswith;

    for (x=1;x<=5;x++) {
        age = "divEvalForm1_Child" + x + "Age";
        gender = "divEvalForm1_Child" + x + "Gender";
        liveswith = "divEvalForm1_Child" + x + "LivesWith";

        document.getElementById(age).style.display = "none";
        document.getElementById(gender).style.display = "none";
        document.getElementById(liveswith).style.display = "none";
    }


    for (x=1;x<=num;x++) {
        age = "divEvalForm1_Child" + x + "Age";
        gender = "divEvalForm1_Child" + x + "Gender";
        liveswith = "divEvalForm1_Child" + x + "LivesWith";

        document.getElementById(age).style.display = "";
        document.getElementById(gender).style.display = "";
        document.getElementById(liveswith).style.display = "";
    }

    if (!(!(document.getElementById("divEvalForm1_ChildInfoLabel")))) 
     document.getElementById("divEvalForm1_ChildInfoLabel").style.display = "none";

    if (num > 0 && num <= 6)
        document.getElementById("divEvalForm1_ChildInfoLabel").style.display = "";
}

function checkChildCount() {
    var childCnt;
    var x;
    var age;
    var gender;
    var liveswith;

    childCnt = document.getElementById("divEvalForm1_ChildCount").value;

    for (x=1;x<=childCnt;x++) {
	    age = "divEvalForm1_Child" + x + "Age";
	    gender = "divEvalForm1_Child" + x + "Gender";
	    liveswith = "divEvalForm1_Child" + x + "LivesWith";

	    document.getElementById(age).style.display = "";
	    document.getElementById(gender).style.display = "";
	    document.getElementById(liveswith).style.display = "";
    }

     if (!(!(document.getElementById("divEvalForm1_ChildInfoLabel")))) 
     document.getElementById("divEvalForm1_ChildInfoLabel").style.display = "none";

    if (num > 0 && num <= 6)
        document.getElementById("divEvalForm1_ChildInfoLabel").style.display = "";
}