/* Functions for the "Contact Us" prospective student inquiry form
   Written by Robert Bond, Sep 2008 */


/* ------------------------------- */
function acad(){

	var s = document.getElementById("stu_type");
	/* var c = document.getElementById("campus"); */
	var c = 'trad';
	var acad_interest_1 = document.getElementById('acad_interest_1');
	var acad_interest_2 = document.getElementById('acad_interest_2');
	var acad_interest_3 = document.getElementById('acad_interest_3');
		
	/* populate academic interests based on:
	  (a) stu_type and 
	  (b) campus 
	*/
	emptyThisNode(acad_interest_1);
	var acad_interest_select_1      = populateAcadPrograms(s.value,c);
	    acad_interest_select_1.name = 'acad_interest_1';
	    acad_interest_select_1.id   = 'acad_interest_1_select';
	    acad_interest_1.appendChild( acad_interest_select_1 );

	emptyThisNode(acad_interest_2);
	var acad_interest_select_2      = populateAcadPrograms(s.value,c);
	    acad_interest_select_2.name = 'acad_interest_2';
	    acad_interest_select_2.id   = 'acad_interest_2_select';
	    acad_interest_2.appendChild( acad_interest_select_2 );

	emptyThisNode(acad_interest_3);
	var acad_interest_select_3      = populateAcadPrograms(s.value,c);
	    acad_interest_select_3.name = 'acad_interest_3';
	    acad_interest_select_3.id   = 'acad_interest_3_select';
	    acad_interest_3.appendChild( acad_interest_select_3 );

}
/* ------------------------------- */
function populateAcadPrograms(stu_type, campus){

	/* pass in the stu_type and campus
	   returns a populated select.
	   note that you still have to assign it a name 
	   and append it, e.g. to an empty div */

	var programs = new Array();
	if(campus == 'trad'){

		if(stu_type == 'GR'){
			programs = new Array(
				'Masters of Education',
				'Master of Business Administration'
			);
		}else{

			programs = new Array(
			'Art',
			'Contemporary Music',
			'Creative Writing',
			'Education',
			'Graphic Design',
			'Moving Image Arts',
			'Musical Theater',
			'Photography',
			'Theater',
			'Undecided' );
		}

	}

	/* create the select */
	var acad_select = document.createElement("select");

	/* create the blank "Choose" option */
	var op   = document.createElement("option");
	op.text  = '';
	op.value = '';
	acad_select.appendChild(op);

	/* append the options */
	for(var i= 0; i < programs.length; i++){
		var op   = document.createElement("option");
		op.setAttribute('value', programs[i]);
		op.appendChild(document.createTextNode(programs[i]));
		acad_select.appendChild(op);

	}
	return acad_select;
}



/* ------------------------------- */
function emptyThisNode(node){
	while(node.firstChild){
			node.removeChild( node.firstChild );
		}
}
/* ------------------------------- */
function validate(){
	var f = document.getElementById("inquiry");

	var prefix   = document.getElementById("prefix");
	var fname    = document.getElementById("fname");
	var lname    = document.getElementById("lname");
	var address1 = document.getElementById("address1");
	var city     = document.getElementById("city");
	var state    = document.getElementById("state");
	var country  = document.getElementById("country");
	var zip      = document.getElementById("zip");
	var dob      = document.getElementById("dob");
	/* var campus   = document.getElementById("campus"); */
	var campus   = 'trad';
	var stu_type = document.getElementById("stu_type");
	var acad_interest_1_select = document.getElementById("acad_interest_1_select");

	/* PREFIX */
	if(prefix.selectedIndex == 0){
		alert("Please choose your prefix -- Mr. or Ms.");
		prefix.focus();
		return false;
	}	


	/* FNAME */
	if(fname.value == ''){
		alert("Please enter your first name.");
		fname.focus();
		return false;
	}	

	/* LNAME */
	if(lname.value == ''){
		alert("Please enter your last name.");
		lname.focus();
		return false;
	}	

	/* ADDRESS1 */
	if(address1.value == ''){
		alert("Please enter your address.");
		address1.focus();
		return false;
	}	

	/* CITY */
	if(city.value == ''){
		alert("Please enter your city.");
		city.focus();
		return false;
	}	

	/* STATE */
	if(state.selectedIndex == 0){
		alert("Please choose a state.");
		state.focus();
		return false;
	}

	/* COUNTRY WITH INVALID STATE */
	if(country.value == 'USA'){
		/* if the user chose "International" which is right after initial blank option */
		if(state.selectedIndex == 1){
			alert("Please enter your state.");
			state.focus();
			return false;
		}
	}

	/* ZIP */
	if(zip.value == ''){
		alert("Please enter your zip / postal code.");
		zip.focus();
		return false;
	}	


	/* DOB */
	if(dob.value == ''){
		alert("Please enter your date of birth: MMDDYYYY");
		dob.focus();
		return false;
	}else if(dob.value.length != 8){
		alert("Please enter your date of birth: MMDDYYYY");
		dob.focus();
		return false;
	}else if( dob.value.indexOf("/") > -1 || 
		  dob.value.indexOf("-") > -1   

		){
		alert("Please enter your date of birth without slashes or dashes: MMDDYYYY");
		dob.focus();
		return false;
	}

	/* DOB - ensure only digits */
	for (var x = 0; x < 8; x++){
		var y = dob.value.substr(x,1);
		if( isNaN( dob.value.substr(x,1) ) ){
			alert("Please enter your date of birth using only numbers: MMDDYYYY");
			dob.focus();
			return false;
		}
	}

	/* CAMPUS */
	if(campus.value == ''){
		alert("Please choose a campus.");
		campus.focus();
		return false;
	}

	/* STU_TYPE */
	if(stu_type.value == ''){
		alert("Please specify what kind of student you would be - Freshman, Transfer etc.");
		stu_type.focus();
		return false;
	}



	/* PRIMARY ACADEMIC INTEREST */
	if(acad_interest_1_select.value == ''){
		alert("Please choose a primary academic interest.");
		acad_interest_1_select.focus();
		return false;
	}



	return true; /* do we need this? */
}


