vFormName 			= 'mainform';
vState 				= 'state';
var form			= document.mainform;
var vRequiredFields	= '';

function do_validation()
{
	vRequiredFields = 	'firstname,First Name,text,'+
						'lastname,Last Name,text,'+
						'address1,Address,text,'+
						'city,City,text,'+
						'state,State,select,'+
						'zip,Zip,zip,'+
						'country,Country,select,'+
						'phone,Main Phone,phone,'+
						'phone2,Alternate Phone,phoneNR,'+
						'email,E-Mail Address,email,'+
						'extrafield11,Do you currently have a High School Diploma or GED,select,'+
						'dobmonth,Month of Birth,select,'+
						'dobday,Day of Birth,select,'+
						'dobyear,Year of Birth,select,'+
						'campus_key,Campus of Interest,select,'+
						'program_key,Program of Interest,select,'+
						'country,Country,select,'+
						check_highschool()+
						check_military()+
						'extrafield8,How did you hear about us?,select,';
	combine_extrafields();
	return Validator();
}

function check_military()
{
	var form 			= document.mainform;
	var country 		= form.country.value;
	var required_fields = '';
	if( country == 'USA' )
	{
		required_fields += 'extrafield6,Are you current or former military of any component?,radio,';
		
		// if student is former military component
		if( form.extrafield6a.checked )
		{
			required_fields += 'extrafield7a,Month of military separation,select,'+
							   'extrafield7b,Year of military separation,select,'+
							   'extrafield7d,Military Installation,select,';
		}
	}
	return required_fields;
}

function check_highschool()
{
	var form 			= document.mainform;
	var age				= getAge( form.dobyear.value, form.dobmonth.value, form.dobday.value );	
	var required_fields = '';
	if( age >= 16 && age <= 19 )
	{
		required_fields += 'gradmonth,Graduation Month,select,'+
						   'gradyear,Graduation Year,select,'+
						   'extrafield12a,State of the last High School you attended,select,'+
						   'extrafield12b,High School Name,text,';
	}
	return required_fields;
}

function toggle_military()
{
	var form 			 = document.mainform;
	var display_military = ( form.extrafield6a.checked ) ? true : false;
	var style			 = ( display_military ) ? 'block' : 'none';
	
	document.getElementById("div1").style.display = style;
	document.getElementById("div2").style.display = style;
	document.getElementById("div5").style.display = style;
	document.getElementById("div6").style.display = style;
	document.getElementById("div7").style.display = style;
	document.getElementById("div8").style.display = style;
}

function toggle_highschool()
{
	var form 	= document.mainform;
	var b_year 	= form.dobyear.value;
	var age		= getAge( form.dobyear.value, form.dobmonth.value, form.dobday.value );
	var style	= 'none';
	
	if( age >= 16 && age <= 19 )
	{
		style = 'block';
	}
	
	form.extrafield3.value		   				   = age;
	document.getElementById("div9").style.display  = style;
	document.getElementById("div10").style.display = style;
	document.getElementById("div11").style.display = style;
	document.getElementById("div12").style.display = style;
	document.getElementById("div15").style.display = style
	document.getElementById("div16").style.display = style;
}

function combine_extrafields()
{
	var form 			= document.mainform;
	var extrafield7 	= form.extrafield7;
	var extrafield12 	= form.extrafield12;
	
	// extrafield7 - Military Month, Year, Installation, Text
	var mil_month 			= document.getElementById('extrafield7a').value;
	var mil_year 			= document.getElementById('extrafield7b').value;
	var mil_installation 	= document.getElementById('extrafield7d').value;
	var mil_text 			= document.getElementById('extrafield7e').value;
	extrafield7.value 		= mil_month+'|'+mil_year+'|'+mil_installation+'|'+mil_text;
	
	// extrafield 12 - High School State, ID, High School Name
	var hs_state			= document.getElementById('extrafield12a').value;
	var hs_id				= document.getElementById('extrafield12b').value;
	var hs_text				= document.getElementById('extrafield12c').value;
	extrafield12.value 	    = hs_state+'|'+hs_id+'|'+hs_text;
}

function getAge(Y,M,D)
{
	var now = new Date(),m=now.getMonth()+1,d=now.getDate();
	return now.getFullYear()-Y+(M>m?-1:M==m&&D>d?-1:0);
}

function suggestSchool()
{
	document.getElementById("load").style.display = "block";
	var partialSchool = document.getElementById("school").value;
	ajaxRequest('/ce/uti/js/school.php', 'name=' + partialSchool, suggestSchoolCallback);
}

function suggestSchoolCallback(schoolList)
{
	list = schoolList.split('|');
	txt = '';
	i = 0;
	while(i < 6 && i < list.length)
	{
		txt += '<a href="#" onclick="document.getElementById(\'school\').value = \'' + list[i + 1] + '\';document.getElementById(\'extrafield12c\').value = \'' + list[i] + '\';document.getElementById(\'schools\').innerHTML = \'\';return false;">' + list[i+1] + '</a><br>';
		i += 2;
	}
	if(txt != '')
	{
		txt = 'Select a school:<br>' + txt;
	}
	document.getElementById("schools").innerHTML = txt;
	document.getElementById("load").style.display = "none";
}
