// JavaScript Document

	/************************************************
	 bool ValidateName(string input)
	**************************************************/
	function ValidateName(theinput){
	 var s=theinput;
	 if(s.search)
	  return (s.search(new RegExp("^[A-Za-z'0-9 ]{1,40}$","gi"))>=0);
	 else
	  return false;
	}
	 
	/******************************************************************
	 bool ValidateDate(string input)
	 Return true or false
	 if the date is valid or not.
	 acepts format (MM-DD-YY)
	******************************************************************/
	function ValidateDate(theinput){
		var $valid=false
		var $s=theinput;
		var $formatIsGood=false;
		var $month;
		var $day;
		var $ano;
		if($s.search){
			if($s.search(new RegExp("^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{2}$","gi"))>=0){
				$formatIsGood=true;
				$month = parseInt($s.substr(0,2),10);
				$day = parseInt($s.substr(3,2),10);
				$ano = parseInt($s.substr(6,2),10);
			}
		}
		// Test if month is valid
		if($formatIsGood && (1<=$month) && ($month<=12)){
			// Test if day is valid
			switch ($month) {
			case 2 :
				  if (($ano % 4 == 0) && (($ano % 100 != 0) || ($ano % 400 == 0))){
					if((1<=$day)&&($day<=29)) $valid = true; 
				  } else if((1<=$day)&&($day<=28)) $valid = true; 
				  break
			case 4:
			case 6:
			case 9:
			case 11:
				  if((1<=$day)&&($day<=30)){
					 $valid = true; 
				  }
				  break
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
			  if((1<=$day)&&($day<=31)){
				 $valid = true; 
			  }
			  break
			} 
		}
		return $valid
	}
	
	/************************************************
	 bool ValidateZip(string input)
	 Return true or false
	 if the zip is valid or not.
	 acepts leters and numbers
	**************************************************/
	function ValidateZip(theinput)
	{
	 var s=theinput;
	 if(s.search)
	  return (s.search(new RegExp("[a-zA-Z0-9]+","gi"))>=0);
	 if(s.length<3)
	  return false;
	 else
	  return true;
	}
	 
	/************************************************
	 bool ValidateEmail(string input)
	 Return true or false
	 if the email is valid or not.
	 checks for @ and .
	**************************************************/
	function ValidateEmail(theinput){
	 var s=theinput;
	 if(s.search)
	  return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0);
	 if(s.indexOf)
	 {
	  at_character=s.indexOf('@');
	  if(at_character<=0 || at_character+4>s.length)
	   return false;
	 }
	 if(s.length<6)
	  return false;
	 else
	  return true;
	}
	 
	/************************************************
	 bool ValidatePhone(string input)
	 Return true or false
	 if the phone number is valid or not.
	 acepts - and + symbols
	**************************************************/
	function ValidatePhone(theinput){
	 var s=theinput;
	 if(s.search)
	  return (s.search(new RegExp("[-+0-9]+","gi"))>=0);
	 if(s.length<5)
	  return false;
	 else
	  return true;
	}

	/************************************************
	**************************************************/
	function wasChecked(checkboxarray){
		for (i = 0; i < checkboxarray.length; i++){
			if(checkboxarray[i].checked) return true;
		}
		return false;
	}

	/******************************************************************
	 deleteRecord(loc)
	******************************************************************/
	function deleteRecord(loc){
		if(confirm('are you sure you want to remove this record?')) document.location.href=loc;
	}
	
	/******************************************************************
	 CheckPreRegistrationForm()
	******************************************************************/
	function CheckPreRegistrationForm(){
		var error="";
	
		if(!ValidateName(document.frmPreRegistration.preReg.value))
			error+="\tCategory\n";
		if(!ValidateName(document.frmPreRegistration.firstName.value))
			error+="\tFirst Name\n";
		if(!ValidateName(document.frmPreRegistration.lastName.value))
			error+="\tLast Name\n";
		if(!ValidateName(document.frmPreRegistration.address1.value))
			error+="\tAddress 1\n";
		if(!ValidateName(document.frmPreRegistration.city.value))
			error+="\tCity\n";
		if(!ValidateName(document.frmPreRegistration.state.value))
			error+="\tState\n";
		if(!ValidateZip(document.frmPreRegistration.zip.value))
			error+="\tZip Code\n";
		if(!ValidatePhone(document.frmPreRegistration.phone.value))
			error+="\tPhone Number\n";
		if(!ValidateEmail(document.frmPreRegistration.email.value))
			error+="\tE-mail Address\n";
		
		if(document.frmPreRegistration.studentAge.value=="-1")
			error+="\tStudent's Age\n";
		if(document.frmPreRegistration.studentAge.value=="Under 18")
			if(!ValidateDate(document.frmPreRegistration.birthDate.value))
				error+="\tBirthdate\n";
		
		if(document.frmPreRegistration.employerCategory.value=="-1")
			error+="\tEmployed Category\n";
		if(document.frmPreRegistration.employerCategory.value=="Employed")
			if(!ValidateName(document.frmPreRegistration.employer.value))
				error+="\tEmployed\n";
		

		if(!wasChecked(document.forms['frmPreRegistration']['howDidYouHear[]']))
			error+="\tHow did you hear about the Music Conservatory of Westchester?\n";
		
		if((!wasChecked(document.forms['frmPreRegistration']['interest[]']))
				&&(!document.forms['frmPreRegistration']['SelectInstrument'].checked)
				&&(!document.forms['frmPreRegistration']['SelectMusicianshipClass'].checked)
				&&(!document.forms['frmPreRegistration']['SelectEarlyChildhood'].checked)
				&&(!document.forms['frmPreRegistration']['SelectEnsembles'].checked)
				&&(!document.forms['frmPreRegistration']['SelectOther'].checked)
			)
			error+="\tArea of Interest\n";
		
		if(!wasChecked(document.forms['frmPreRegistration']['days[]']))
			error+="\tPlease tell us your preferred days and time frames for instruction\n";
		



		if(document.frmPreRegistration.formOfContact.value=="-1")
			error+="\tPreferred form of contact\n";

		if(error!="")
			alert("Error! Please limit form entries to numbers and letters only (email address excluded). Please check:\n"+error);
		else {
			document.frmPreRegistration.submit();
		}
		return;
	}

	/******************************************************************
	 CheckPreRegistration2Form()
	******************************************************************/
	function CheckPreRegistration2Form(usertype){
		var error="";
	
		// SECTION 1 – Contact Information
		if(!ValidateName(document.frmPreRegistration.parentGuardian1Name.value))
			error+="\tParent/Guardian 1\n";
		if(!ValidateName(document.frmPreRegistration.parentGuardian1Address1.value))
			error+="\tAddress 1\n";
		if(!ValidateName(document.frmPreRegistration.parentGuardian1City.value))
			error+="\tCity\n";
		if(!ValidateName(document.frmPreRegistration.parentGuardian1State.value))
			error+="\tState\n";
		if(!ValidateZip(document.frmPreRegistration.parentGuardian1Zip.value))
			error+="\tZip\n";
		if(!ValidatePhone(document.frmPreRegistration.parentGuardian1Phone1Number.value))
			error+="\tPhone #1 Number\n";
		if(document.frmPreRegistration.parentGuardian1Phone1Type.value=="-1")
			error+="\tPhone #1 Type\n";
		if(!ValidateEmail(document.frmPreRegistration.parentGuardian1Email.value))
			error+="\tE-mail\n";
		// SECTION 2 – Student Information
		if(!ValidateName(document.frmPreRegistration.studentFirstName.value))
			error+="\tParent/Guardian 1\n";
		if(!ValidateName(document.frmPreRegistration.studentLastName.value))
			error+="\tParent/Guardian 1\n";
		if((!(document.frmPreRegistration.studentIsAdult.checked))&&((document.frmPreRegistration.studentBirthdateMonth.value=="99")||(document.frmPreRegistration.studentBirthdateDay.value=="99")||(document.frmPreRegistration.studentBirthdateYear.value=="9999")))
			error+="\tStudent’s birthdate\n";
		else document.frmPreRegistration.studentBirthdate.value = document.frmPreRegistration.studentBirthdateYear.value+'-'+document.frmPreRegistration.studentBirthdateMonth.value+'-'+document.frmPreRegistration.studentBirthdateDay.value;

/*			
		if(!wasChecked(document.forms['frmPreRegistration']['ensemble[]']))
			error+="\tSelect a ensemble\n";
		if(!wasChecked(document.forms['frmPreRegistration']['musicianship[]']))
			error+="\tSelect a musicianship\n";
*/
		// SECTION 3 – Payment Information
if(usertype=='user'){		
		if(!ValidateName(document.frmPreRegistration.paymentName.value))
			error+="\tName as it appears on credit card\n";
		if((!(document.frmPreRegistration.paymentIsSameAddress.checked))&&(
				(!ValidateName(document.frmPreRegistration.paymentAddress.value))||
				(!ValidateName(document.frmPreRegistration.paymentCity.value))||
				(!ValidateName(document.frmPreRegistration.paymentState.value))||
				(!ValidateZip(document.frmPreRegistration.paymentZip.value))
			))
			error+="\tBilling Data\n";
		if(document.frmPreRegistration.paymentCCType.value=="-1")
			error+="\tCredit Card Type\n";
		if(!ValidateName(document.frmPreRegistration.paymentCCNumber.value))
			error+="\tCredit Card Number\n";
		if(!ValidateName(document.frmPreRegistration.paymentCCSecurityCode.value))
			error+="\tCard Security Code\n";
		if((document.frmPreRegistration.paymentExpDateMonth.value=="99")||(document.frmPreRegistration.paymentExpDateYear.value=="9999"))
			error+="\tCard Expiration Date\n";
		else document.frmPreRegistration.paymentExpDate.value = document.frmPreRegistration.paymentExpDateMonth.value+'/'+document.frmPreRegistration.paymentExpDateYear.value;
		if(!(document.frmPreRegistration.agreePaymentPolicies.checked))
			error+="\tClick on I agree to the Conservatory’s Registration and Tuition Payment policies\n";
}
		if(error!="")
			alert("Error! Please limit form entries to numbers and letters only (email address excluded). Please check:\n"+error);
		else {
			document.frmPreRegistration.submit();
		}
		return;
	}

	/******************************************************************
	 CheckJoinOurAlumniForm()
	******************************************************************/
	function CheckJoinOurAlumniForm(){
		var error="";
	
		if(!ValidateName(document.frmJoinOurAlumni.firstName.value))
			error+="\tFirst Name\n";
		if(!ValidateName(document.frmJoinOurAlumni.lastName.value))
			error+="\tLast Name\n";
		if(!ValidateName(document.frmJoinOurAlumni.address1.value))
			error+="\tHome Address\n";
		if(!ValidateName(document.frmJoinOurAlumni.city.value))
			error+="\tCity\n";
		if(!ValidateName(document.frmJoinOurAlumni.state.value))
			error+="\tState\n";
		if(!ValidateZip(document.frmJoinOurAlumni.zip.value))
			error+="\tZip Code\n";
		if(!ValidatePhone(document.frmJoinOurAlumni.phone.value))
			error+="\tPhone Number\n";
		if(!ValidateEmail(document.frmJoinOurAlumni.email.value))
			error+="\tE-mail Address\n";
		if(error!="")
			alert("Error! Please limit form entries to numbers and letters only (email address excluded). Please check:\n"+error);
		else {
			document.frmJoinOurAlumni.submit();
		}
		return;
	}

	/******************************************************************
	 CheckAskUsForm()
	******************************************************************/
	function CheckAskUsForm(){
		var error="";
	
		if(!ValidateName(document.frmAskUs.preReg.value))
			error+="\tCategory\n";
		if(!ValidateName(document.frmAskUs.fullName.value))
			error+="\tFull Name\n";
		if(!ValidateName(document.frmAskUs.address1.value))
			error+="\tAddress 1\n";
		if(!ValidateName(document.frmAskUs.city.value))
			error+="\tCity\n";
		if(!ValidateName(document.frmAskUs.state.value))
			error+="\tState\n";
		if(!ValidateZip(document.frmAskUs.zip.value))
			error+="\tZip Code\n";
		if(!ValidateEmail(document.frmAskUs.email.value))
			error+="\tE-mail Address\n";
		if(!ValidatePhone(document.frmAskUs.phone.value))
			error+="\tPhone Number\n";
		if(!wasChecked(document.forms['frmAskUs']['howDidYouHear[]']))
			error+="\tHow did you hear about the Music Conservatory of Westchester?\n";
		if(error!="")
			alert("Error! Please limit form entries to numbers and letters only (email address excluded). Please check:\n"+error);
		else {
			document.frmAskUs.submit();
		}
		return;
	}

	function formHideShow(DivCheck, DivToChange){
		if(document.getElementById(DivCheck).checked) document.getElementById(DivToChange).className ='hid';
		else document.getElementById(DivToChange).className ='vis';
		
	}

