// JavaScript Document
var error;
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;


function checkForm()
{
	error='';
	
	if(document.form1.Applicant_Name.value==''){document.form1.Applicant_Name.style.background='yellow'; error=error+" Applicant Name Is A Required Field \n";}else{document.form1.Applicant_Name.style.background='#E9F5FE';}
	
	
	if(document.form1.Applicant_DateOfBirth.value==''){document.form1.Applicant_DateOfBirth.style.background='yellow'; error=error+" Applicant Date Of Birth Is A Required Field \n";}else{document.form1.Applicant_DateOfBirth.style.background='#E9F5FE';}
	
	for(var i=0; i<document.form1.Applicant_Gender.length;i++)
	{
		if(document.form1.Applicant_Gender[i].checked==true && document.form1.Applicant_Gender[i].value=='NONE')
		{
			document.getElementById('divgender').className='invalid';
			error=error+" Gender Is A Required Field \n";
		}
		else
		{
			document.getElementById('divgender').className='valid';
		}
	}
	
	
	if(document.form1.Applicant_StreetAddress.value==''){document.form1.Applicant_StreetAddress.style.background='yellow'; error=error+" Applicant Street Address Is A Required Field \n";}else{document.form1.Applicant_StreetAddress.style.background='#E9F5FE';}
	
	
	if(document.form1.Applicant_City.value==''){document.form1.Applicant_City.style.background='yellow'; error=error+" Applicant City Is A Required Field \n";}else{document.form1.Applicant_City.style.background='#E9F5FE';}
	
	
	
	if(document.form1.Applicant_State_Province.value==''){document.form1.Applicant_State_Province.style.background='yellow'; error=error+" Applicant State Province Is A Required Field \n";}else{document.form1.Applicant_State_Province.style.background='#E9F5FE';}
	
	
	
	if(document.form1.Applicant_Zip.value==''){document.form1.Applicant_Zip.style.background='yellow'; error=error+" Applicant Zip Is A Required Field \n";}else{document.form1.Applicant_Zip.style.background='#E9F5FE';}	
	
	
	CheckPhone('Applicant_EveningTelephone');
	emailcheck('Applicant_EmailAddress');
	
	
	if(document.form1.Current_SchoolProgram_Enrollment.value==''){document.form1.Current_SchoolProgram_Enrollment.style.background='yellow'; error=error+" Current School Program Enrollment Is A Required Field \n";}else{document.form1.Current_SchoolProgram_Enrollment.style.background='#E9F5FE';}	
	
	
	if(document.form1.Current_SchoolProgram_EnrollmentDate.value==''){document.form1.Current_SchoolProgram_EnrollmentDate.style.background='yellow';error=error+" Current School Program Enrollment Date Is A Required Field \n";}else{document.form1.Current_SchoolProgram_EnrollmentDate.style.background='#E9F5FE';}	
	
	
	if(document.form1.Current_SchoolProgram_StreetAddress.value==''){document.form1.Current_SchoolProgram_StreetAddress.style.background='yellow';error=error+" Current School Program Street Address Is A Required Field \n";}else{document.form1.Current_SchoolProgram_StreetAddress.style.background='#E9F5FE';}	
	
	
	if(document.form1.Current_SchoolProgram_City.value==''){document.form1.Current_SchoolProgram_City.style.background='yellow';error=error+" Current School Program City Is A Required Field \n";}else{document.form1.Current_SchoolProgram_City.style.background='#E9F5FE';}	
	
	
	if(document.form1.Current_SchoolProgram_State_Province.value==''){document.form1.Current_SchoolProgram_State_Province.style.background='yellow';error=error+" Current School Program State Province Is A Required Field \n";}else{document.form1.Current_SchoolProgram_State_Province.style.background='#E9F5FE';}
	
	
	if(document.form1.Current_SchoolProgram_Zip.value==''){document.form1.Current_SchoolProgram_Zip.style.background='yellow';error=error+" Current School Program Zip Is A Required Field \n";}else{document.form1.Current_SchoolProgram_Zip.style.background='#E9F5FE';}
	
	CheckPhone('Current_SchoolProgram_AdmissionOfficeTelephone');
	
	for(var i=0; i<document.form1.Current_SchoolProgram_CertifiedRealEstateProgram.length;i++)
	{
		if(document.form1.Current_SchoolProgram_CertifiedRealEstateProgram[i].checked==true && document.form1.Current_SchoolProgram_CertifiedRealEstateProgram[i].value=='NONE')
		{
			document.getElementById('accredited').className='invalid';
			error=error+" Current School Program Certified Real Estate Program Is A Required Field \n";
		}
		else
		{
			document.getElementById('accredited').className='valid';
		}
	}
	
	if(document.form1.Current_SchoolProgram_OverallGPA.value==''){document.form1.Current_SchoolProgram_OverallGPA.style.background='yellow';error=error+" Overall GPA Is A Required Field \n";}else{document.form1.Current_SchoolProgram_OverallGPA.style.background='#E9F5FE';}
	
	
	
	for(var i=0; i<document.form1.Current_SchoolProgram_ScholarshipApplyFor.length;i++)
	{
		if(document.form1.Current_SchoolProgram_ScholarshipApplyFor[i].checked==true && document.form1.Current_SchoolProgram_ScholarshipApplyFor[i].value=='NONE')
		{
			document.getElementById('yearapplyfor').className='invalid';
			error=error+" What Year You Are Applying For The Scholarship Is A Required Field \n";
		}
		else
		{
			document.getElementById('yearapplyfor').className='valid';
		}
	}
	
	
	
	if(document.form1.Applicant_Reference_Name1.value==''){document.form1.Applicant_Reference_Name1.style.background='yellow';error=error+"  Applicant Reference Name Is A Required Field \n";}else{document.form1.Applicant_Reference_Name1.style.background='#E9F5FE';}
	
	
	if(document.form1.Applicant_Reference_TitlePosition1.value==''){document.form1.Applicant_Reference_TitlePosition1.style.background='yellow';error=error+"  Applicant Reference Title/Position Is A Required Field \n";}else{document.form1.Applicant_Reference_TitlePosition1.style.background='#E9F5FE';}
	
	if(document.form1.Applicant_Reference_Relationship1.value==''){document.form1.Applicant_Reference_Relationship1.style.background='yellow';error=error+"  Applicant Reference Relationship Is A Required Field \n";}else{document.form1.Applicant_Reference_Relationship1.style.background='#E9F5FE';}
	
	
	CheckPhone('Applicant_Reference_Telephone1');
	
	
	if(document.form1.Applicant_Reference_Name2.value==''){document.form1.Applicant_Reference_Name2.style.background='yellow';error=error+" The second Applicant Reference Name Is A Required Field \n";}else{document.form1.Applicant_Reference_Name2.style.background='#E9F5FE';}
	
	
	
	if(document.form1.Applicant_Reference_TitlePosition2.value==''){document.form1.Applicant_Reference_TitlePosition2.style.background='yellow';error=error+" The second Applicant Reference Title Position Is A Required Field \n";}else{document.form1.Applicant_Reference_TitlePosition2.style.background='#E9F5FE';}
	
	if(document.form1.Applicant_Reference_Relationship2.value==''){document.form1.Applicant_Reference_Relationship2.style.background='yellow';error=error+" The second Applicant Reference Relationship Is A Required Field \n";}else{document.form1.Applicant_Reference_Relationship2.style.background='#E9F5FE';}
	
	CheckPhone('Applicant_Reference_Telephone2');
	
	
	if(document.form1.Applicant_EssayQuestion_Answer1.value==''){document.form1.Applicant_EssayQuestion_Answer1.style.background='yellow';error=error+" Applicant Essay Question Answer 1 Is A Required Field \n";}else{document.form1.Applicant_EssayQuestion_Answer1.style.background='#E9F5FE';}
	
	if(document.form1.Applicant_EssayQuestion_Answer2.value==''){document.form1.Applicant_EssayQuestion_Answer2.style.background='yellow';error=error+" Applicant Essay Question Answer 2 Is A Required Field \n";}else{document.form1.Applicant_EssayQuestion_Answer2.style.background='#E9F5FE';}
	
	if(document.form1.Application_Referal.value==''){document.form1.Application_Referal.style.background='yellow';error=error+" Application Referal Is A Required Field \n";}else{document.form1.Application_Referal.style.background='#E9F5FE';}
	
	if(document.form1.Electronic_Signature.value==''){document.form1.Electronic_Signature.style.background='yellow';error=error+" Your Electronic Signature Is A Required Field \n";}else{document.form1.Electronic_Signature.style.background='#E9F5FE';}		
	
	
	//JUST IN CASE THEY DON'T FILL IT OUT WE CLEAR THE DATE FIELDS
	
	if(document.form1.START_DatesEmployment1.value=='Start Date'){document.form1.START_DatesEmployment1.value='';}
	if(document.form1.START_DatesEmployment2.value=='Start Date'){document.form1.START_DatesEmployment2.value='';}
	if(document.form1.START_DatesEmployment3.value=='Start Date'){document.form1.START_DatesEmployment3.value='';}
	if(document.form1.START_DatesEmployment4.value=='Start Date'){document.form1.START_DatesEmployment4.value='';}
	
	if(document.form1.END_DatesEmployment1.value=='End Date'){document.form1.END_DatesEmployment1.value='';}
	if(document.form1.END_DatesEmployment2.value=='End Date'){document.form1.END_DatesEmployment2.value='';}
	if(document.form1.END_DatesEmployment3.value=='End Date'){document.form1.END_DatesEmployment3.value='';}
	if(document.form1.END_DatesEmployment4.value=='End Date'){document.form1.END_DatesEmployment4.value='';}
	
	if(document.form1.START_DatesAttended4.value=='Start Date'){document.form1.START_DatesAttended1.value='';}
	if(document.form1.START_DatesAttended2.value=='Start Date'){document.form1.START_DatesAttended2.value='';}
	if(document.form1.START_DatesAttended3.value=='Start Date'){document.form1.START_DatesAttended3.value='';}
	if(document.form1.START_DatesAttended4.value=='Start Date'){document.form1.START_DatesAttended4.value='';}
	
	if(document.form1.END_DatesAttended1.value=='End Date'){document.form1.END_DatesAttended1.value='';}
	if(document.form1.END_DatesAttended2.value=='End Date'){document.form1.END_DatesAttended2.value='';}
	if(document.form1.END_DatesAttended3.value=='End Date'){document.form1.END_DatesAttended3.value='';}
	if(document.form1.END_DatesAttended4.value=='End Date'){document.form1.END_DatesAttended4.value='';}
	
	if(error==''){document.form1.submit();}else{alert("I'm sorry the form is not complete or has invalid fields.  Please see the highlighted fields in yellow. \n\n" + " " + error);}
	
	

}


function emailcheck(fn)
{
	var str=document.getElementById(fn).value;
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	var emailFlag=true;

    if (str.indexOf(at)==-1){emailFlag=false;}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){emailFlag=false;}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){emailFlag=false;}

	 if (str.indexOf(at,(lat+1))!=-1){emailFlag=false;}

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){emailFlag=false;}

	 if (str.indexOf(dot,(lat+2))==-1){emailFlag=false;}
	
	 if (str.indexOf(" ")!=-1){emailFlag=false;}
	 
	 if(emailFlag){document.getElementById(fn).style.background='#E9F5FE'; return true; }else{document.getElementById(fn).style.background='yellow'; error=error+ fn+ ' is an invalid Email' + "\n";}					
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function CheckPhone(fn){
	var Phone=document.getElementById(fn);	
	var bad=false;
	if ((Phone.value==null)||(Phone.value=="")){
		bad=true;
		
	}
	if (checkInternationalPhone(Phone.value)==false){
		bad=true;
	}
	if(bad){document.getElementById(fn).style.background='yellow'; error=error+ fn + ' is an invalid Phone Number' + "\n";}else{document.getElementById(fn).style.background='#E9F5FE';}
 }
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}



















