function Form_Validator(theForm)
{
    if (theForm.FullName.value == "")
    {
        alert("Please enter a value for the \"Full Name\" field.");
        theForm.FullName.focus();
        return (false);
    }

    if ((theForm.Email.value == "") || !validate_email(theForm.Email.value))
    {
        alert("Please enter a valid \"Email\".");
        theForm.Email.focus();
        return (false);
    }

    if (theForm.Confirm.value == "")
    {
        alert("Please enter a value for the \"Confirm\" field.");
        theForm.Confirm.focus();
        return (false);
    }
    
    if (theForm.Email.value != theForm.Confirm.value)
    {
        alert("Please make sure that the email addresses match.");
        theForm.Email.focus();
        return (false);
    }


    if (theForm.Program_Requested.selectedIndex == 0)
    {
        alert("Please choose a \"Program\" option.");
        theForm.Program_Requested.focus();
        return (false);
    }

    var chkVal = theForm.Total.value;
    var prsVal = chkVal;
    if (chkVal != "" && !(prsVal != "0"))
    {
        alert("The \"Total\" field cannot be equal to \"0\".");
        return (false);
    }

    var radioSelected = false;
    var radioVal = "No";
    for (i = 0;  i < theForm.Agree.length;  i++)
    {
        if (theForm.Agree[i].checked)
        {
            radioSelected = true;
            radioVal = theForm.Agree[i].value;
        }
    }
    
    if (radioSelected) {
    	return (radioVal == "Yes");
    } else {
        alert("Please select one of the \"Agree\" options.");
        return (false);
    }
   
    return (true);
    
    function validate_email(emailStr){
        apos=emailStr.indexOf("@");
        dotpos=emailStr.lastIndexOf(".");
        if (apos<1||dotpos-apos<2) {
            return false;
        }
        else {
            return true;
        }
    }
}

function calc() {
    with (document.AppFrm) {
        if (Email.value != Confirm.value)
        {
            window.alert("Please make sure that the email addresses match.");
            Confirm.focus();
        }
        else {
            var CheckedButton = getSelected(document.forms[0].Airport_Pickup);
            var CheckedHomestay = getSelected(document.forms[0].Homestay);
            var si = Number_of_Homestay_Weeks.selectedIndex;
            var prices = new Array
            ( 705, 1380, 2025, 2640, 3225, 3780, 4305, 4800, 5400, 6000, 6600, 7200, 7800,
                920, 1800, 2640, 3440, 4200, 4920, 5600, 6240, 7020, 7800, 8580, 9360, 10140,
                1125, 2200, 3225, 4200, 5125, 6000, 6825, 7600, 8550, 9500, 10450, 11400, 12350);

            var i = Number_of_Hours_per_Week.selectedIndex * 13 + Number_of_Weeks_Requested.selectedIndex;

            if (CheckedHomestay == "Homestay")
            {
                Homestay_Service_Fee.value = 150;
                Homestay_Total.value = parseInt(Number_of_Homestay_Weeks.options[si].value) * 212.50;
            }
            else if (CheckedHomestay == "Residence")
            {
                Homestay_Service_Fee.value = 150;
                Homestay_Total.value = parseInt(Number_of_Homestay_Weeks.options[si].value) * 127.50;
            }
            else
            {
                Homestay_Service_Fee.value = 0;
                Homestay_Total.value = 0;
            }

            if (Health_Insurance.checked)
            {
                Health_Insurance_Total.value = parseInt(Number_of_Health_Insurance_Days.value) * 2.50;
            }
            else
            {
                Health_Insurance_Total.value = 0;
            }

            if (CheckedButton == "Airport Pickup")
            {
                Airport_Pickup_Fee.value = 100;
            }
            else if (CheckedButton == "Airport Pickup and Drop-off")
            {
                Airport_Pickup_Fee.value = 150;
            }
            else
            {
                Airport_Pickup_Fee.value = 0;
            }

            if (Program_Requested.options[Program_Requested.selectedIndex].value == "SelectOne")
            {
                Registration_Fee.value=0;
                Materials_Fee.value = 0;
                Airport_Pickup_Fee.value = 0;
                Health_Insurance_Total.value = 0;
                Homestay_Total.value = 0;
                Homestay_Service_Fee.value = 0;
                Programs_Tuition_Fee.value = 0;
            }
            else
            {
                Programs_Tuition_Fee.value = prices[i];
                Registration_Fee.value = 100;
                Materials_Fee.value = 50;
            }

            Total.value =
            parseFloat(Registration_Fee.value) +
            parseFloat(Programs_Tuition_Fee.value) +
            parseFloat(Materials_Fee.value) +
            parseFloat(Homestay_Total.value) +
            parseFloat(Homestay_Service_Fee.value) +
            parseFloat(Airport_Pickup_Fee.value) +
            parseFloat(Health_Insurance_Total.value);
            return;
        }
        }
}
function getSelected(allbuttons){
    for (i=0;i<allbuttons.length;i++) {
        if (allbuttons[i].checked) {
            return allbuttons[i].value;
        }
        return "";
    }
}
