// JavaScript Document
function isDate(dateStr)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); //check format
	if (matchArray == null) return false;
	var iMonth = matchArray[1]; // parse date into variables
	var iDay = matchArray[3];
	var iYear = matchArray[5];
	
	if (iMonth < 1 || iMonth > 12) return false;
	if (iDay < 1 || iDay > 31) return false;
	if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay==31) return false;
	if (iMonth == 2)
	{ // check for february 29th
		var isleap = (iYear % 4 == 0 && (iYear % 100 != 0 || iYear % 400 == 0));
		if (iDay > 29 || (iDay == 29 && !isleap)) return false;
	}
	return true;
}

function FixDate(oMonth, oDay, oYear)
{
	var iMonth = parseInt(oMonth[oMonth.selectedIndex].value);
	var iDay = parseInt(oDay[oDay.selectedIndex].value);
	var iYear = parseInt(oYear[oYear.selectedIndex].value);
	var iMax = 31;
	
	if (iMonth == 2)
	{
		if ((((iYear % 4) == 0) && ((iYear % 100) != 0)) || ((iYear % 400) == 0))
		{
			iMax = 29;
		}
		else
		{
			iMax = 28;
		}
	}
	else if ((iMonth == 4) || (iMonth == 6) || (iMonth == 9) || (iMonth == 11))
	{
		iMax = 30;
	}
	
	oDay.length = iMax;
	
	for (var i=iMax; i > 28; i--)
	{
		oDay[i - 1].text = i;
		oDay[i - 1].value = i;
	}
	
	if (iDay > iMax)
		oDay.selectedIndex = (iMax - 1);
}

function phoneIsValid(Obj,sLabel)
{
	var sPhone = Obj.value;
	var sPhoneTemp = sPhone;
	sPhone = '';
	var sNumbers = '1234567890';
	
	for (var i=0;i<sPhoneTemp.length;i++)
	{
		if (sNumbers.indexOf(sPhoneTemp.charAt(i)) > -1)
		{
			sPhone += sPhoneTemp.charAt(i);
		}
	}
	
	if (sPhone.charAt(0) == '1' || sPhone.charAt(0) == 1)
	{
		sPhone = sPhone.substring(1,(sPhone.length));
	}
	
	if (sPhone.length != 10)
	{
		return sLabel + ' must be a 10 digit number\n';
	}
	else
	{ 
		Obj.value = sPhone;
	}
	
	var sAreaCode = sPhone.substring(0,3);
	var sPrefix = sPhone.substring(3,6);
	var sNumber = sPhone.substring(6,10);
	ary7NotAllowed = new Array('1234567','4567890','0000000','1111111','2222222','3333333','4444444','5555555','6666666','7777777','8888888','9999999','3456789','4567890')
	ary3NotAllowed = new Array('000','911','555','012','123');
	
	for (var i=0;i<ary7NotAllowed.length;i++)
	{
		if (sPrefix.toString() + sNumber.toString() == ary7NotAllowed[i])
		{
			return sLabel + ' must be a valid phone number\n';
		}
	}
	
	for (var i=0;i<ary3NotAllowed.length;i++)
	{
		if (sPrefix.toString() == ary3NotAllowed[i].toString())
		{
			return sLabel + ' must be a valid phone number\n';
		}
	}
	return '';
}

function ValidateData(oPrmForm)
{ 
	var bBrowserGood = false;
	var bBrowserDrawsBordersCorrectly = false;
	var sBrowser = "Unknown";
	// check browser
	if (navigator.appName == "Netscape")
	{
		sBrowser = "Netscape";
		if (parseFloat(navigator.appVersion) >= 5)
		{
			bBrowserGood = true;
			bBrowserDrawsBordersCorrectly = true;
		}
	}
	else if (navigator.appName == "Microsoft Internet Explorer")
	{
		sBrowser = "IE";
		if (parseFloat(navigator.appVersion) >= 4)
		{
			bBrowserGood = true;
		}
	}
	
	var bReturn = true;
	var bFieldGood = true;
	var sErrors = '';
	// check firstname
	bFieldGood = true;
	if (oPrmForm.firstname.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'First Name missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.firstname.style.borderLeftColor = 'buttonface';
			oPrmForm.firstname.style.borderTopColor = 'buttonface';
			oPrmForm.firstname.style.borderRightColor = 'buttonface';
			oPrmForm.firstname.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.firstname.style.borderLeftColor = 'tomato';
			oPrmForm.firstname.style.borderTopColor = 'tomato';
			oPrmForm.firstname.style.borderRightColor = 'tomato';
			oPrmForm.firstname.style.borderBottomColor = 'tomato';
		}
	}
	// check lastname
	bFieldGood = true;
	if (oPrmForm.lastname.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'Last Name missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.lastname.style.borderLeftColor = 'buttonface';
			oPrmForm.lastname.style.borderTopColor = 'buttonface';
			oPrmForm.lastname.style.borderRightColor = 'buttonface';
			oPrmForm.lastname.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.lastname.style.borderLeftColor = 'tomato';
			oPrmForm.lastname.style.borderTopColor = 'tomato';
			oPrmForm.lastname.style.borderRightColor = 'tomato';
			oPrmForm.lastname.style.borderBottomColor = 'tomato';
		}
	}
	// check dayphone
	bFieldGood = true;
	if (oPrmForm.dayphone.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'Daytime Phone missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.dayphone.style.borderLeftColor = 'buttonface';
			oPrmForm.dayphone.style.borderTopColor = 'buttonface';
			oPrmForm.dayphone.style.borderRightColor = 'buttonface';
			oPrmForm.dayphone.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.dayphone.style.borderLeftColor = 'tomato';
			oPrmForm.dayphone.style.borderTopColor = 'tomato';
			oPrmForm.dayphone.style.borderRightColor = 'tomato';
			oPrmForm.dayphone.style.borderBottomColor = 'tomato';
		}
	}
	// check evephone	
	bFieldGood = true;
	if (oPrmForm.evephone.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'Evening Phone missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.evephone.style.borderLeftColor = 'buttonface';
			oPrmForm.evephone.style.borderTopColor = 'buttonface';
			oPrmForm.evephone.style.borderRightColor = 'buttonface';
			oPrmForm.evephone.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.evephone.style.borderLeftColor = 'tomato';
			oPrmForm.evephone.style.borderTopColor = 'tomato';
			oPrmForm.evephone.style.borderRightColor = 'tomato';
			oPrmForm.evephone.style.borderBottomColor = 'tomato';
		}
	}
	// check email
	bFieldGood = true;
	if (oPrmForm.email.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'Email Address missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.email.style.borderLeftColor = 'buttonface';
			oPrmForm.email.style.borderTopColor = 'buttonface';
			oPrmForm.email.style.borderRightColor = 'buttonface';
			oPrmForm.email.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.email.style.borderLeftColor = 'tomato';
			oPrmForm.email.style.borderTopColor = 'tomato';
			oPrmForm.email.style.borderRightColor = 'tomato';
			oPrmForm.email.style.borderBottomColor = 'tomato';
		}
	}
	// check address
	bFieldGood = true;
	if (oPrmForm.address.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'Street Address missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.address.style.borderLeftColor = 'buttonface';
			oPrmForm.address.style.borderTopColor = 'buttonface';
			oPrmForm.address.style.borderRightColor = 'buttonface';
			oPrmForm.address.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.address.style.borderLeftColor = 'tomato';
			oPrmForm.address.style.borderTopColor = 'tomato';
			oPrmForm.address.style.borderRightColor = 'tomato';
			oPrmForm.address.style.borderBottomColor = 'tomato';
		}
	}
	// check city
	bFieldGood = true;
	if (oPrmForm.city.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'City missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.city.style.borderLeftColor = 'buttonface';
			oPrmForm.city.style.borderTopColor = 'buttonface';
			oPrmForm.city.style.borderRightColor = 'buttonface';
			oPrmForm.city.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.city.style.borderLeftColor = 'tomato';
			oPrmForm.city.style.borderTopColor = 'tomato';
			oPrmForm.city.style.borderRightColor = 'tomato';
			oPrmForm.city.style.borderBottomColor = 'tomato';
		}
	}
	// check state
	bFieldGood = true;
	if (oPrmForm.state.selectedIndex > 0)
	{}
	else
	{
		sErrors = sErrors + 'State missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.state.style.backgroundColor = '#FFFFFF';
		}
		else
		{
			oPrmForm.state.style.backgroundColor = 'tomato';
		}
	}
	// check zip
	bFieldGood = true;
	if (oPrmForm.zip.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'Zip Code missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.zip.style.borderLeftColor = 'buttonface';
			oPrmForm.zip.style.borderTopColor = 'buttonface';
			oPrmForm.zip.style.borderRightColor = 'buttonface';
			oPrmForm.zip.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.zip.style.borderLeftColor = 'tomato';
			oPrmForm.zip.style.borderTopColor = 'tomato';
			oPrmForm.zip.style.borderRightColor = 'tomato';
			oPrmForm.zip.style.borderBottomColor = 'tomato';
		}
	}
	// check country
	bFieldGood = true;
	if (oPrmForm.country.value.length > 0)
	{}
	else
	{
		sErrors = sErrors + 'Country missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.country.style.borderLeftColor = 'buttonface';
			oPrmForm.country.style.borderTopColor = 'buttonface';
			oPrmForm.country.style.borderRightColor = 'buttonface';
			oPrmForm.country.style.borderBottomColor = 'buttonface';
		}
		else
		{
			oPrmForm.country.style.borderLeftColor = 'tomato';
			oPrmForm.country.style.borderTopColor = 'tomato';
			oPrmForm.country.style.borderRightColor = 'tomato';
			oPrmForm.country.style.borderBottomColor = 'tomato';
		}
	}
	// check gradyear
	bFieldGood = true;
	if (oPrmForm.gradyear.selectedIndex > 0)
	{}
	else
	{
		sErrors = sErrors + 'High School Graduation Year missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.gradyear.style.backgroundColor = '#FFFFFF';
		}
		else
		{
			oPrmForm.gradyear.style.backgroundColor = 'tomato';
		}
	}
	//check school_id
	bFieldGood = true;
	if (oPrmForm.school_id.selectedIndex > 0)
	{}
	else
	{
		sErrors = sErrors + 'Preferred Location missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.school_id.style.backgroundColor = '#FFFFFF';
		}
		else
		{
			oPrmForm.school_id.style.backgroundColor = 'tomato';
		}
	}
	// check program
	bFieldGood = true;
	if (oPrmForm.program.selectedIndex > 0 && oPrmForm.program.options[oPrmForm.program.selectedIndex].value != '0' && oPrmForm.program.options[oPrmForm.program.selectedIndex].value != '' )
	{}
	else
	{
		sErrors = sErrors + 'Program of Interest missing\n';
		bFieldGood = false;
	}
	if (bBrowserGood)
	{
		if (bFieldGood)
		{
			oPrmForm.program.style.backgroundColor = '#FFFFFF';
		}
		else
		{
			oPrmForm.program.style.backgroundColor = 'tomato';
		}
	}
	// output result to alert or return true and allow submit
	if (sErrors.length > 0)
	{
		bReturn = false;
		alert('The following errors occurred:\n' + sErrors);
	}
	return bReturn;
}

// routines to control display of divs
function disp_loading()
{
	var dNoScr = document.getElementById('noscript');
	var dLoading = document.getElementById('loading');
	dNoScr.style.display = 'none';
	dLoading.style.display = 'inline';
	return;
}

function disp_form()
{
	var dLoading = document.getElementById('loading');
	var dCntcForm = document.getElementById('cntcForm');
	dLoading.style.display = 'none';
	dCntcForm.style.display = 'inline';
	return;
}

function ProgramShow(obj)
{
	var list = document.contactform.program;
	var emailto = document.contactform.email_to;

	switch (obj.value)
	{
		case '0':
			list.length = 0;
			list[0] = new Option("Choose a location first","0");
			break;
			
		case '3087':
			list.length = 0;
			// Dallas #10
			var dtenArr = new Array();
			dtenArr["0"] = "Select One:";	
			dtenArr["Air Conditioning"] = "Air Conditioning";
			dtenArr["Automotive Service Technician"] = "Automotive Service Technician";
			dtenArr["Combination Welding"] = "Combination Welding";
            dtenArr["Electronic Systems Technician"] = "Electronic Systems Technician";
				
			for(var i in dtenArr)
			{
				list[list.length] = new Option(dtenArr[i],i);			
			}
			emailto.value = 'lead10@atienterprises.edu';
			break;
			
		case '3091':
			list.length = 0;
			// North Richland Hills #30
			// 7/12/07 Added Personal Fitness Trainer Ticket #13123
			var nrhArr = new Array();
			nrhArr["0"] = "Select One:";
			nrhArr["Air Conditioning, Heating, and Refrigeration"] = "Air Conditioning, Heating, and Refrigeration";
			nrhArr["Automotive Service Technician"] = "Automotive Service Technician";
			nrhArr["Dental Assisting"] = "Dental Assisting";
			nrhArr["Massage Therapy"] = "Massage Therapy";
			nrhArr["Medical Assisting"] = "Medical Assisting";
			nrhArr["Network Administration"] = "Network Administration";
			nrhArr["Personal Fitness Trainer"] = "Personal Fitness Trainer";

			for(var i in nrhArr)
			{
				list[list.length] = new Option(nrhArr[i],i);			
			}
			emailto.value = 'jwalsch@atienterprises.edu,9999medialead30@atienterprises.edu';
			break;
		
		case '70':
			list.length = 0;
			// Dallas #50
			var dfifArr = new Array();
			dfifArr["0"] = "Select One:";
			dfifArr["Business Administration Technology"] = "Business Administration Technology";
			dfifArr["Dental Assisting"] = "Dental Assisting";
			dfifArr["Massage Therapy"] = "Massage Therapy";
			dfifArr["Medical Assisting"] = "Medical Assisting";
			dfifArr["Pharmacy Technician"] = "Pharmacy Technician";
			//dfifArr["Respiratory Therapy Technology"] = "Respiratory Therapy Technology";

			for(var i in dfifArr)
			{
				list[list.length] = new Option(dfifArr[i],i);			
			}
			emailto.value = '9999medialead50@atienterprises.edu,drodriguez@atienterprises.edu';
			break;
		case '9332':
	
			list.length = 0;
			// Oklahoma
			var dfifArr = new Array();
			dfifArr["0"] = "Select One:";
			dfifArr["Business Administration Technology"] = "Business Administration Technology";
			dfifArr["Dental Assisting"] = "Dental Assisting";
			dfifArr["Medical Assisting"] = "Medical Assisting";
			dfifArr["Network Administration"] = "Network Administration";
			dfifArr["Pharmacy Technician"] = "Pharmacy Technician";

			for(var i in dfifArr)
			{
				list[list.length] = new Option(dfifArr[i],i);			
			}

			emailto.value = 'lead33@atienterprises.edu';
			break;

		case '9363':
	
			list.length = 0;
			// Richardson
			var dfifArr = new Array();
			dfifArr["0"] = "Select One:";
			dfifArr["Business Administration Technology"] = "Business Administration Technology";
			dfifArr["Dental Assisting"] = "Dental Assisting";
			dfifArr["Medical Assisting"] = "Medical Assisting";
			dfifArr["Pharmacy Technician"] = "Pharmacy Technician";

			for(var i in dfifArr)
			{
				list[list.length] = new Option(dfifArr[i],i);			
			}

			emailto.value = 'lead55@atienterprises.edu';
			break;
			
		case '9815':
	
			list.length = 0;
			// Albuquerque
			var albArr = new Array();
			albArr["0"] = "Select One:";
			albArr["Business Administration Technology"] = "Business Administration Technology";
			albArr["Dental Assisting"] =  "Dental Assisting";
			albArr["Medical Assisting"] =  "Medical Assisting";
			albArr["Network Administration"] =  "Network Administration";
			albArr["Pharmacy Technician"] =  "Pharmacy Technician";

			for(var i in albArr)
			{
				list[list.length] = new Option(albArr[i],i);			
			}

			emailto.value = 'achouinard@atienterprises.edu';
			break;
			
			case '9832':
	
			list.length = 0;
			// Garland
			var garArr = new Array();
			garArr["0"] = "Select One:";
			garArr["Automotive Service Technician"] = "Automotive Service Technician";
			garArr["Air Conditioning, Heating, & Refrigeration"] =  "Air Conditioning, Heating, & Refrigeration";

			for(var i in garArr)
			{
				list[list.length] = new Option(garArr[i],i);			
			}

			emailto.value = 'achouinard@atienterprises.edu';
			break;		
	
		}
	
	return true;
}
