// Arizona Medical Reserve Corps 	--- */
// Author: Trevor Carlston	    	--- */
// Contains: Work around 			--- */
// Hiding No-Preference using JavaScript --- */
// Implemented on March 5 2010	--- */

document.title = "Hawaii Public Schools";

// Global Variables *******************
	/* --- Put in Global variables here --- */
	var schoolArray = [];
	var complexSchools = [];	
	var infoTabs;
	var tabObj;
	var intList = [];
	var careerArr = [];
	var studProjArr = [];
	var thisInterest = "";
	var careerHeader = "";	
	var seniorProject = false;
// End of Global Variables ***********		


// This is the onload event handler for the function _load_rec which occurs when the page loads
	if (window.attachEvent) { 
		window.attachEvent('onload', _load_rec);
	}
	else if (window.addEventListener) {
		window.addEventListener("load", _load_rec, false);
	} 
	else {
		window.onload = _load_rec;
	} // End if statements

	
// This function runs when the page loads.
function _load_rec() {

	if($('VOL_FIRST_NAME')) {
		try{
			islandArray = Array(["Hawaii","Hilo","Honoka`a","Ka`u","Kea`au","Kealakehe","Kohala","Konawaena","Laupahoehoe","Pahoa","Waiakea"],["Kaua`i","Kapa`a","Kaua`i","Waimea"],["Maui","Baldwin","Hana","Kekaulike","Lahainaluna","Maui"],["Moloka`i","Moloka`i"],["Oahu","Aiea","Campbell","Castle","Farrington","Kahuku","Kailua","Kaimuki","Kaiser","Kalaheo","Kalani","Kapolei","Leilehua","McKinley","Mililani","Moanalua","Nanakuli","Pearl City","Radford","Roosevelt","Waialua","Waianae","Waipahu"],["Lana`i","Lana`i"]);
			schoolArray = Array(["Aiea","Aiea Elementary","Aiea High","Aiea Intermediate","Alvah A. Scott Elementary","Pearl Ridge Elementary","Waimalu Elementary","Webling Elementary"],["Baldwin","Baldwin High","Iao Intermediate","Waihee Elementary","Wailuku Elementary"],["Campbell","Campbell High","Ewa Beach Elementary","Ewa Elementary","Ewa Makai Middle","Holomua Elementary","Ilima Intermediate","Iroquois Point Elementary","Kaimiloa Elementary","Keoneula Elementary","Pohakea Elementary"],["Castle","Ahuimanu Elementary","Castle High","Heeia Elementary","Kahaluu Elementary","Kaneohe Elementary","Kapunahala Elementary","King Intermediate","Parker Elementary","Puohala Elementary","Waiahole Elementary"],["Farrington","Dole Middle","Farrington High","Fern Elementary","Kaewai Elementary","Kalakaua Middle","Kalihi Elementary","Kalihi-kai Elementary","Kalihi-uka Elementary","Kalihi-waena Elementary","Kapalama Elementary","Linapuni Elementary","Puuhale Elementary"],["Hana","Hana High &amp; Elementary"],["Hilo","DeSilva Elementary","Haaheo Elementary","Hilo High","Hilo Intermediate","Hilo Union Elementary","Kalanianaole Elem. &amp; Inter.","Kapiolani Elementary","Kaumana Elementary","Keaukaha Elementary"],["Honoka`a","Honokaa Elementary","Honokaa High &amp; Intermediate","Paauilo Elem. &amp; Inter.","Waikoloa Elementary &amp; Middle","Waimea Elementary"],["Kahuku","Hauula Elementary","Kaaawa Elementary","Kahuku Elementary","Kahuku High &amp; Intermediate","Laie Elementary","Sunset Beach Elementary"],["Kailua","Enchanted Lake Elementary","Kaelepulu Elementary","Kailua Elementary","Kailua High","Keolu Elementary","Maunawili Elementary","Olomana","Pope Elementary","Waimanalo Elem. &amp; Inter."],["Kaimuki","Ala Wai Elementary","Aliiolani Elementary","Hokulani Elementary","Jarrett Middle","Jefferson Elementary","Kaimuki High School","Kuhio Elementary","Lunalilo Elementary","Palolo Elementary","Washington Middle"],["Kaiser","Aina Haina Elementary","Hahaione Elementary","Kaiser High","Kamiloiki Elementary","Koko Head Elementary","Niu Valley Middle"],["Kalaheo","Aikahi Elementary","Kailua Intermediate","Kainalu Elementary","Kalaheo High","Mokapu Elementary"],["Kalani","Kahala Elementary","Kaimuki Middle","Kalani High","Liholiho Elementary","Liliuokalani Elementary","Waikiki Elementary","Wilson Elementary"],["Kapa`a","Hanalei Elementary","Kapaa Elementary","Kapaa High","Kapaa Middle","Kilauea Elementary"],["Kapolei","Barbers Point Elementary","Kapolei Elementary","Kapolei High","Kapolei Middle","Makakilo Elementary","Mauka Lani Elementary"],["Ka`u","Kau High &amp; Pahala Elementary","Naalehu Elementary"],["Kaua`i","Kamakahelei Middle","Kauai High","Kaumualii Elementary","Koloa Elementary","Wilcox Elementary"],["Kea`au","Keaau Elementary","Keaau High","Keaau Middle","Mountain View Elementary"],["Kealakehe","Holualoa Elementary","Kahakai Elementary","Kealakehe Elementary","Kealakehe High","Kealakehe Intermediate"],["Kekaulike","Haiku Elementary","Kalama Intermediate","Kekaulike High","Kula Elementary","Makawao Elementary","Paia Elementary","Pukalani Elementary"],["Kohala","Kohala Elementary","Kohala High","Kohala Middle"],["Konawaena","Honaunau Elementary","Hookena Elementary","Ke Kula o Ehunuikaimalino","Konawaena Elementary","Konawaena High","Konawaena Middle"],["Lahainaluna","Kamehameha III Elementary","Lahaina Intermediate","Lahainaluna High","Nahienaena Elementary"],["Lana`i","Lanai High &amp; Elementary"],["Laupahoehoe","Laupahoehoe High &amp; Elementary"],["Leilehua","Hale Kula Elementary","Helemano Elementary","Iliahi Elementary","Kaala Elementary","Leilehua High","Solomon Elementary","Wahiawa Elementary","Wahiawa Middle","Wheeler Elementary","Wheeler Middle"],["Maui","Kahului Elementary","Kamalii Elementary","Kihei Elementary","Lihikai Elementary","Lokelani Intermediate","Maui High","Maui Waena Intermediate","Pomaikai Elementary"],["McKinley","Central Middle","Kaahumanu Elementary","Kaiulani Elementary","Kauluwela Elementary","Lanakila Elementary","Likelike Elementary","McKinley High","Royal Elementary"],["Mililani","Kipapa Elementary","Mililani High","Mililani Ike Elementary","Mililani Mauka Elementary","Mililani Middle","Mililani Uka Elementary","Mililani Waena Elementary"],["Moanalua","Moanalua Elementary","Moanalua High","Moanalua Middle","Red Hill Elementary","Salt Lake Elementary","Shafter Elementary"],["Moloka`i","Kaunakakai Elementary","Kilohana Elementary","Maunaloa Elementary","Molokai High","Molokai Middle"],["Nanakuli","Nanaikapono Elementary","Nanakuli Elementary","Nanakuli High &amp; Intermediate"],["Pahoa","Keonepoko Elementary","Pahoa Elementary","Pahoa High &amp; Intermediate"],["Pearl City","Highlands Intermediate","Kanoelani Elementary","Lehua Elementary","Manana Elementary","Momilani Elementary","Palisades Elementary","Pearl City Elementary","Pearl City High","Pearl City Highlands Elementary","Waiau Elementary"],["Radford","Aliamanu Elementary","Aliamanu Middle","Hickam Elementary","Makalapa Elementary","Mokulele Elementary","Nimitz Elementary","Pearl Harbor Elementary","Pearl Harbor Kai Elementary","Radford High"],["Roosevelt","Anuenue","Kawananakoa Middle","Lincoln Elementary","Maemae Elementary","Manoa Elementary","Noelani Elementary","Nuuanu Elementary","Pauoa Elementary","Roosevelt High","Stevenson Middle"],["Waiakea","Waiakea Elementary","Waiakea High","Waiakea Intermediate","Waiakeawaena Elementary"],["Waialua","Haleiwa Elementary","Waialua Elementary","Waialua High &amp; Intermediate"],["Waianae","Leihoku Elementary","Maili Elementary","Makaha Elementary","Waianae Elementary","Waianae High","Waianae Intermediate","Ohana Ola O Kahumana (shelter)","Ule Ke Kukui (shelter)"],["Waimea","Eleele Elementary","Kalaheo Elementary","Kekaha Elementary","Niihau High &amp; Elementary","Waimea Canyon Middle","Waimea High"],["Waipahu","August Ahrens Elementary","Honowai Elementary","Kaleiopuu Elementary","Waikele Elementary","Waipahu Elementary","Waipahu High","Waipahu Intermediate"]);
			tabObj = $$('.toggler')[2];
			infoTab = $$('.information')[2];
			intList = $$('#interests input');
			$$('.data-attr-header').each(function(findHideHead){
				if(findHideHead.innerHTML == 'Grade Level:&nbsp;' || findHideHead.innerHTML == 'Other:&nbsp;'){
					findHideHead.style.display="none";
				}else if(findHideHead.innerHTML == 'Please indicate your career background:&nbsp;'){
					careerHeader = findHideHead.parentNode;
					careerHeader.parentNode.removeChild(careerHeader);
				}
			});
			_saveButtons = sbuttons();
			setCareerPathway();
			$('INTEREST_23').parentNode.parentNode.style.display = 'none';
			$('INTEREST_24').parentNode.parentNode.style.display = 'none';
			$('INTEREST_25').parentNode.parentNode.style.display = 'none';
			$('INTEREST_5').parentNode.parentNode.getElementsByTagName('td')[1].children[0].innerHTML += '&nbsp; <a style=\'text-decoration: none;\' href=\'JavaScript:void(0);\' class=\'mytip\'  title=\'Community Coordinator :: Aids a school in identifying mentors, technical consultants and panelists; coaches and assists new mentors and serves as communication link to school.  Estimated time commitment: will vary by school and number of Senior Projects.\'>(?)</a>';
			$('INTEREST_6').parentNode.parentNode.getElementsByTagName('td')[1].children[0].innerHTML += '&nbsp; <a style=\'text-decoration: none;\' href=\'JavaScript:void(0);\' class=\'mytip\'  title=\'Mentor :: Works one-on-one with a student; serves as a subject matter expert; may provide job-shadowing; identifies other resource experts as needed.  Estimated time commitment: 15+ hours over a 4-9 month period.\'>(?)</a>';
			$('INTEREST_7').parentNode.parentNode.getElementsByTagName('td')[1].children[0].innerHTML += '&nbsp; <a style=\'text-decoration: none;\' href=\'JavaScript:void(0);\' class=\'mytip\'  title=\'Technical Consultant :: Is an expert in a field or subject who can provide short-term technical assistance as needed upon request.  Estimated time commitment: 1-2 hours or as needed.\'>(?)</a>';
			$('INTEREST_605').parentNode.parentNode.getElementsByTagName('td')[1].children[0].innerHTML += '&nbsp; <a style=\'text-decoration: none;\' href=\'JavaScript:void(0);\' class=\'mytip\'  title=\'Panelist :: Is an expert in a field related to a student’s Senior Project; serves as a member of a judging panel to rate a student’s Senior Project presentation; reviews student’s research paper and portfolio.  Estimated time commitment: 4+ hours.\'>(?)</a>';
			var theTbody = $('INTEREST_611').parentNode.parentNode.parentNode;
			var rowCount = theTbody.getElementsByTagName('tr').length;
			var thisCell = document.createElement('td');
			thisCell.colspan='2';
			thisCell.setAttribute('colspan','2');
			thisCell.innerHTML = '<label for=\"Additional Info::How I would like to help additional info\">Additional Info:</label> <input type="text" onblur="this.className=\'data-text\'" onfocus="this.className=\'data-text-selected\'" onmouseout="if(this.className==\'data-text-over\') { this.className=\'data-text\';}" onmouseover=" if(this.className==\'data-text\' ) this.className=\'data-text-over\'" class="data-text" value="" id="Additional Info::How I would like to help additional info" name="Additional Info::How I would like to help additional info"/>'; 
			var thisRow = theTbody.insertRow(rowCount);
			thisRow.appendChild(thisCell);
		}catch(err){}
	}
} // End Function	


function setCareerPathway(){
	seniorProject = false;
	for(var i = 0; i < intList.length; i++){
		if(intList[i].id != undefined){
			thisInterest = parseInt(intList[i].id.slice(9));
			if(4 < thisInterest && thisInterest < 8 || thisInterest == 605){
				studProjArr.push(intList[i]);
			}else if(605 < thisInterest && thisInterest < 612){
				careerArr.push(intList[i].parentNode.parentNode);
				intList[i].parentNode.parentNode.parentNode.removeChild(intList[i].parentNode.parentNode) //.style.display="none";
				// intList[i].parentNode.parentNode.style.display="none";
			}
		}
	}
	studProjArr.each(function(checkTheseOptions){
		if(checkTheseOptions.checked == true){
			$('INTEREST_7').parentNode.parentNode.parentNode.appendChild(careerHeader);
			for(var i = 0; i < careerArr.length;i++){
				$('INTEREST_7').parentNode.parentNode.parentNode.appendChild(careerArr[i]);
			}
		}
		checkTheseOptions.addEvent('click', function() {
			for(var o in studProjArr){
			   if(studProjArr[o].checked == true){
					seniorProject = true;
					showAtt = true;
					break;
			   }else{
					seniorProject = false;
					showAtt = false;
			   }
			}
			if(showAtt == true){
				$('INTEREST_7').parentNode.parentNode.parentNode.appendChild(careerHeader);
				for(var i = 0; i < careerArr.length;i++){
					$('INTEREST_7').parentNode.parentNode.parentNode.appendChild(careerArr[i]);		
				}
			}else{
				$('INTEREST_7').parentNode.parentNode.parentNode.removeChild(careerHeader);
				for(var i = 0; i < careerArr.length;i++){
					$('INTEREST_7').parentNode.parentNode.parentNode.removeChild(careerArr[i]);		
				}
			}
		});
	});
}

/* --- This function gets all of the submit buttons and sets the onclick to the function used to validate the fields. --- */
function sbuttons() {
	 var tmp_arr = $$('.savebutton');
		var sContainer = document.createElement('div');
		sContainer.setAttribute('class','sbutton');
		var buttonCopy = tmp_arr[0].cloneNode(true);
		buttonCopy.onclick = function(){
			_submit_application();
		}
		sContainer.appendChild(buttonCopy);
		$$('.rec-panel')[0].parentNode.appendChild(sContainer);

	 for(var i = 0; i < tmp_arr.length; i++) { // Loop through the input fields to find the save button.
		 tmp_arr[i].onclick = function(){
			_submit_application();
		 }
	 }
	 // tmp_arr[0].value = "Submit";
	 // setReqInd();
	
	 return tmp_arr;
} // End Function 

function openRecruiterTab(tnum,fieldFocus, focusWait){
		tabObj = $$('.toggler')[tnum];
		infoTab = $$('.information')[tnum];
		infoTabHeight = infoTab.style.height;
		reqFocus = fieldFocus;
		if(fieldFocus && tabObj.className == 'toggler closedtab' || !fieldFocus){
			setTimeout("tabObj.accordion.toggleSection(tabObj.togglerID);",500);
			setTimeout('if(tabObj.className == "toggler closedtab"){tabObj.accordion.toggleSection(tabObj.togglerID);}',600);
			setTimeout("if(parseInt(infoTabHeight) > 0){ infoTab.style.height = infoTabHeight; }",1000);
			if(!focusWait){
				focusWait = 1100;
			}else{
				focusWait += 500;
			}
		}
		if(fieldFocus) {
			setTimeout("if(reqFocus){$(reqFocus).focus();}",focusWait);
		}
}

function _submit_application() {
	var submitRegistration = false;
	var parentChild = false;
	// Verify that an affiliation has been selected
	for(i = 0; i < cbMainList.length; i++){
		if(cbMainList[i].checked == true || secondList[i].checked == true){
			if(cbMainList[i].id == 'ACTIVITY_521' || secondList[i].id == 'Extra Affiliations::Secondary Affiliation_236419'){
				parentChild = true;
				break;
			}else{
				submitRegistration = true;
			}
		}
	}
	if(parentChild == true) {
		if($('Extra Affiliations::Child First Name').value.trim('') != '' && $('Extra Affiliations::Child Last Name').value.trim('') != ''){
			 submitRegistration = true; 
		}else{
			alert("If you are the parent of a child attending a school please enter your child's first and last name.");
			var nameField = ($('Extra Affiliations::Child First Name').value.trim('') == '')? 'Extra Affiliations::Child First Name':'Extra Affiliations::Child Last Name';
			openRecruiterTab(4,nameField);
			return false;
		}
	}
	// If seniorProject is selected then verify that a school has been selected.
	if(seniorProject == true) {
		schoolFilled = false;
		schoolSearch = $$('#geo-list input');
		for(i=0;i< schoolSearch.length; i++) {
			if(schoolSearch[i].checked == true) {
				schoolFilled = true; 
				break;
			}
			schoolFilled = false;
		}
		if(schoolFilled == false) {
			var myFx = new Fx.Scroll(window).toElement('geo-list');
			$E("#geo-list .warning").innerHTML = "You must select a highschool before performing this opportunity search.";
			$E("#geo-list .warning").style.display = "block";
			setTimeout('$E("#geo-list .warning").fade("in"); ',200);
			openRecruiterTab(2,'map',1200);
			schoolSearch.each(function(geoField) {
				geoField.addEvent('click',function(inputField){
					if(inputField.checked == true) {
						$E("#geo-list .warning").innerHTML = "";
					}
				});	
			});
			return false;
		}
	}
	if(submitRegistration == true){
		doAction('saveForm');
	}else{
		var myFx = new Fx.Scroll(window).toElement('thisLabel');
		alert("Please select your affiliation with this school");
		openRecruiterTab(4,'ACTIVITY_525',1200);
		return false;
	}
}

/* This function will validate the form input */	
function rl_is_valid(_field){
	//alert($(_field).type);		//this line can be used to trace different types of fields that arent accounted for in this function but need to be added
	var filled = false;
	switch($(_field).type){
		case 'text':
			if($(_field).value != ''){filled = true;}
			break;
		case 'checkbox':
			filled = $(_field).checked;
			break;
		case 'select-one':
			if($(_field).value != ''){filled = true;}
			break;
		default:
			break;
	}
	return filled;
} // End Function
function _tooltip(){
	$('CONTACT_TYPE_7').parentNode.innerHTML += "<div style='display: inline;'>&nbsp; <a style='text-decoration: none;' href='#' class='mytip'  title='Email Address :: If you do not have an email address or use email, write NONE in this space (or indicate the email address of a family member who agrees to send and receive email on your behalf.)' >Help</a></div>";
}  // End Function
