// JavaScript Document


//Validate form input:
function checkform(theForm)
{

    if (theForm.firstName.value == "")
    {
        alert("Please enter a value for the \"First Name\" field.");
        theForm.firstName.focus();
        return (false);
    }

    if (theForm.firstName.value.length < 2)
    {
        alert("Please enter at least 2 characters in the \"First Name\" field.");
        theForm.firstName.focus();
        return (false);
    }
    
	if (theForm.lastName.value == "")
    {
        alert("Please enter a value for the \"Last Name\" field.");
        theForm.lastName.focus();
        return (false);
    }

    if (theForm.lastName.value.length < 2)
    {
        alert("Please enter at least 2 characters in the \"Last Name\" field.");
        theForm.lastName.focus();
        return (false);
    }

    if (theForm.streetAddress.value == "")
        {
            alert("Please enter a value for the \"Street Address\" field.");
            theForm.streetAddress.focus();
            return (false);
        }

    if (theForm.city.value == "")
        {
            alert("Please enter a value for the \"City\" field.");
            theForm.city.focus();
            return (false);
        }

	if (theForm.zipCode.value == "")
        {
            alert("Please enter a value for the \"Zip Code\" field.");
            theForm.zipCode.focus();
            return (false);
        }

     if (theForm.zipCode.value.length < 5)
        {
            alert("Please enter a valid ZIP code of at least 5 digits.");
            theForm.zipCode.focus();
            return (false);
        }

        if (theForm.zipCode.value.length > 10)
        {
            alert("Please enter at most 10 characters in the \"Zip Code\" field.");
            theForm.zipCode.focus();
            return (false);
        }
		
		if (theForm.stateinfo.selectedIndex == 0) {
			alert("Please select a state.");
			return (false);
		}

//** validate radio button gender **
   isSelected = false;

	for (i = 0; i < theForm.gender.length; i++)
	
		if(theForm.gender[i].checked)
		{
			isSelected = true;
			break; 
		}
	
	if (!isSelected)
		{
            alert("Please select your gender.");
  	        theForm.gender[0].focus();
            return (false);
		}
		
//** end radio button validation **

	if (theForm.gpa.value == "")
	{
        alert("Please provide your GPA.");
        theForm.gpa.focus();
        return (false);
    }
 	if (theForm.highschool.value== "")
	{
        alert("Please provide your high school.");
        theForm.highschool.focus();
        return (false);
    }

 	if (theForm.counselor.value == "")
	{
        alert("Please provide the name of your guidance counselor.");
        theForm.counselor.focus();
        return (false);
    }
	
	// ** Couselor Phone **
	if (theForm.couselorPhone.value.length == 0)
    {
        alert("Please provide your day time telephone number.");
        theForm.couselorPhone.focus();
        return (false);
    }
	var regCouselorPhone;
    var regCouselorPhoneExt;
    var msg_CouselorPhone;

    regCouselorPhone = /^( )*\(?\d{3}\)?[\/|\-|\.| ]*\d{3}[\/|\-|\.\ ]*\d{4}( )*$/;
    regCouselorPhoneExt = /^\d{1,5}$/;
    msg_CouselorPhone = "Please retype Couselor Phone number in the following format, including area code:\n\n(555)555-5555\n\n";


    if (theForm.couselorPhone.value.length > 0 && !regCouselorPhone.test(theForm.couselorPhone.value))
    {
        alert(msg_CouselorPhone);
        theForm.couselorPhone.focus();
        return (false);
    }
	
	// ** Day Phone  **
	if (theForm.dayPhone.value.length == 0)
    {
        alert("Please provide your day time telephone number.");
        theForm.dayPhone.focus();
        return (false);
    }
	var regPhone;
    var regPhoneExt;
    var msg;

    regPhone = /^( )*\(?\d{3}\)?[\/|\-|\.| ]*\d{3}[\/|\-|\.\ ]*\d{4}( )*$/;
    regPhoneExt = /^\d{1,5}$/;
    msg = "Please retype your phone number in the following format, including area code:\n\n(555)555-5555\n\n";


    if (theForm.dayPhone.value.length > 0 && !regPhone.test(theForm.dayPhone.value))
    {
        alert(msg);
        theForm.dayPhone.focus();
        return (false);
    }
 

    if ( theForm.Email.value == "" ) {
      	alert ( "Please enter e-mail!" )
     	theForm.Email.focus();
     	return false;
   	}

    //** validate e-mail format **
			if ( theForm.Email.value != "" ) 
			{
				if(!validEmail(theForm.Email.value)){	   
					alert("You must enter a validate e-mail (xxx@xx.xx)!")
					theForm.Email.focus();
					return false;
				}
			}

 	
 	if (theForm.whyAttend.value == "")
	{
        alert("Please provide why do you want to attend Axia College Online.");
        theForm.whyAttend.focus();
        return (false);
    }
 	if (theForm.whyAttend.value.length > 750)
        {
            alert("You can only enter less than 750 words.");
            theForm.whyAttend.focus();
            return (false);
        }

	if (theForm.activities.value == "")
	{
        alert("Please enter activities have you been involved in recently.");
        theForm.activities.focus();
        return (false);
    }
	
	
 	if (theForm.activities.value.length > 750)
        {
            alert("You can only enter less than 750 words.");
            theForm.activities.focus();
            return (false);
        }
		
	if (theForm.goals.value == "")
	{
        alert("Please provide your career and personal goals.");
        theForm.goals.focus();
        return (false);
    }
 	if (theForm.goals.value.length > 750)
        {
            alert("You can only enter less than 750 words.");
            theForm.goals.focus();
            return (false);
        }

	if (theForm.whyScholarship.value == "")
	{
        alert("Please enter why should you be awarded the scholarship.");
        theForm.whyScholarship.focus();
        return (false);
    }
 	if (theForm.whyScholarship.value.length > 750)
        {
            alert("You can only enter less than 750 words.");
            theForm.whyScholarship.focus();
            return (false);
        }
		if (theForm.whyonlineeducation.value == "")
	{
        alert("Please enter why you are considering an online education.");
        theForm.whyonlineeducation.focus();
        return (false);
    }
	if (theForm.whyonlineeducation.value.length > 750)
        {
            alert("You can only enter less than 750 words.");
            theForm.whyonlineeducation.focus();
            return (false);
        }	
	//newwindow = window.open('terms_and_conditions.asp','scholarship','width=760,height=750,scrollbars=1,status=1'); 
   //	theForm.action = newwindow;
	
    return (true);
	
}// end of checkForm()



//***** Validate e-mail with right format xx@xx.xx
function validEmail(email){
	invalidChars="/:,;"
	
	if(email=="")
		{return false}
	
	//loop through all invalidate chars to check each char in the email 
	for(i=0; i < invalidChars.length; i++){
	
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar, 0) > -1)
			{return false}
			
		atPos = email.indexOf("@", 1)
		
		if(atPos==-1)
			{return false}
		
		if(email.indexOf("@", atPos+1) > -1)
			{return false}
			
		periodPos = email.indexOf(".", atPos)
			
		if(periodPos == -1)
			{return false}
			
		if(periodPos+3 > email.length)
			{return false}
	}//end of for loop
	
	return true
	
}//end of validEmail

