//  Loads Google Map into display div on campus pages
function loadMap () {
	if (mapLoaded == false) {
		document.getElementById("googleMapContainer").innerHTML = mapContent;
		mapLoaded = true;
	}
}

//  Unique loader for Fresno Aviation
function loadFresnoAviationMap() {
	var aviationMap = '<img id="visitHeader_FresnoAviation" src="../../_presentation/images/visit_Fresno_Aviation.gif" alt="Come visit our Fresno Aviation Campus" title="" /><iframe width="450" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=4985+E+Andersen+Ave+Fresno,+CA+93727&amp;sll=37.020098,-95.712891&amp;sspn=49.531015,90.351563&amp;ie=UTF8&amp;s=AARTsJp5uIr1crfPxbYqD22yjqFu-zucLw&amp;ll=36.785298,-119.722309&amp;spn=0.030933,0.038624&amp;z=14&amp;iwloc=addr&amp;output=embed"></iframe><br /><br /><a target="_blank" href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=4985+E+Andersen+Ave+Fresno,+CA+93727&amp;sll=37.020098,-95.712891&amp;sspn=49.531015,90.351563&amp;ie=UTF8&amp;ll=36.785298,-119.722309&amp;spn=0.030933,0.038624&amp;z=14&amp;iwloc=addr" style="text-align: left; color: #4966ab; font-size: 11px;">View Larger Map</a>';
	
	document.getElementById("googleMapContainer").innerHTML = aviationMap;	
}

// Auto signature on textbox focus
function fillSignature(objSig, strSig){
	if (objSig && strSig){
		if (objSig.value == ""){
			objSig.value = strSig;
		}
	}
}

// Open & Close ID by ID
function openClose(divID){
	if (divID){
		objDiv = document.getElementById(divID);
		if (objDiv){
			if (objDiv.style.display == "none"){
				objDiv.style.display = "block";
			}else{
				objDiv.style.display = "none";
			}
		}
	}
}

//  Turns on the map display
function openMap () {
	document.getElementById("mapPop").style.visibility = "visible";
}

//  Turns off the map display
function closeMap () {
	document.getElementById("mapPop").style.visibility = "hidden";
}

//  Helps IE with select width issues; prevents text getting cut off
function selectFix (newWidth) {
	var programSelect = document.getElementById("programName");
		programSelect.style.width = newWidth+"px";
}

//  Enables Program select once a campus has been selected
function enableProgram () {
	document.getElementById("programName").disabled = false;	
}

//  Returns to user to the page they were on before going to the request information page
function thanksClose(previousPage) {
	window.location = previousPage;
}

//  Rollover functionality for offered at campus map
function campusRollover(imageSrc, imageId, direction) {
	if (direction == "over") {
		var newSrc = imageSrc.replace("link_", "rollover_");
	} else if (direction == "out") {
		var newSrc = imageSrc.replace("rollover_", "link_");
	}
	
	var currentImage = document.getElementById(imageId);
		currentImage.src = newSrc;	
}

//  Rollover functionality for buttons found on the various pages
function buttonRollover(imageSrc, imageId, direction) {
	if (direction == "over") {
		var newSrc = imageSrc.replace("btn_", "rollover_");
	} else if (direction == "out") {
		var newSrc = imageSrc.replace("rollover_", "btn_");
	}
	
	var currentImage = document.getElementById(imageId);
		currentImage.src = newSrc;	
}

//  Resets the form and any error messages that may have been written out to the page
function formReset() {
	var theForm = document.getElementById('requestForm');
	
	//  Reset form error messages
	var formInputs = theForm.elements;
		for (var i = 0; i < formInputs.length; i++) {
			//  Strips out the errorMessage CSS class name
			formInputs[i].className = formInputs[i].className.replace(/errorMessage/,'');
			
			if(formInputs[i].errorMessage) {
				formInputs[i].parentNode.removeChild(formInputs[i].errorMessage);
				formInputs[i].errorMessage = null;
				formInputs[i].parentNode.errorMessage = null;	
			}
			
			formInputs[i].onfocus = null;
		}
	
	theForm.reset();
}

//  Creates and then displays the results to the online quiz
function resultsDisplay() {
	var quizForm = document.getElementById('onlineQuiz');	
	var totalScore = 0;
	
	var quizQuestions = quizForm.elements;
		for (var i = 0; i < quizQuestions.length; i++) {
			var questionNum = Math.floor((i + 3)/3);
			
			if (quizQuestions[i].checked) {
				totalScore += Number(quizQuestions[i].value);
			} 
		}
	
	var resultsPop = document.createElement('div');
	document.body.appendChild(resultsPop);
		resultsPop.id = "resultsPop";
	
	
	
	var resultsBg = document.createElement('img');
	resultsPop.appendChild(resultsBg);
		resultsBg.className = "png";
		resultsBg.id = "resultsBg";
		resultsBg.src = "../../_presentation/images/background_ResultsPop.png";
	
	
	var closeBtn = document.createElement('img');
	resultsPop.appendChild(closeBtn);
		closeBtn.id = "closeResults";
		closeBtn.src = "../../_presentation/images/btn_CloseMap.gif";
		closeBtn.onclick = function () {
			document.body.removeChild(resultsPop);
			
			window.location.hash = "";
		}
	
	var resultsInfo = document.createElement('p');
	resultsPop.appendChild(resultsInfo);
		resultsInfo.id = "resultsInfo";
	
	var score = document.createElement('h2');
	resultsPop.appendChild(score);
		score.id = "score";
	
	var scoreText = document.createTextNode("Your score: " + totalScore);
	score.appendChild(scoreText);
	
	var feedback = document.createElement( 'p' );
	resultsPop.appendChild( feedback );
		feedback.id = "feedback";
	
	
	var feedbackHeader = document.createElement( 'span' );
	feedback.appendChild(feedbackHeader);
	
	var feedbackText = "";
	var feedbackHeaderText = "";
	
	if ( totalScore >= 20 ) {
		feedbackHeaderText = "20 points or higher";
		feedbackText = "an online course is a real possibility for you.";
	} else if ( (totalScore < 20) && (totalScore >= 11) ) {
		feedbackHeaderText = "Between 11 and 20 points";
		feedbackText = "an online course may work for you, but you may need to make a few adjustments in your schedule and study habits to succeed.";
	} else {
		feedbackHeaderText = "Less than 10 points";
		feedbackText = "an online course may not currently be the best alternative for you; talk to your counselor. ";
	}
	
	feedbackHeader.appendChild(document.createTextNode(feedbackHeaderText));
	feedback.appendChild(document.createTextNode(feedbackText));
	
	var infoText = document.createTextNode("No matter what you scored, remember that online learning is not easy. Your professor will demand at least the same quality of work as they would receive from you in a face-to-face classroom. A similar number of hours will need to be committed throughout the course of a semester for an online course as to a face-to-face course. Remember that your course may include deadlines and instructions on assignments, but there will not be anyone telling you to \"turn in your assignment.\" Online learning is convenient - you do not have to commute to campus, and you can attend class at your convenience - either early in the morning, late at night, or anytime in-between. Just remember, no matter when you decide to study, your professor will hold you accountable - so study hard, and have a great term!");
	resultsInfo.appendChild(infoText);
	
	window.location.hash = "top";
}

//  ===========================================================================================================
//  Functions brought straight over from SJVC provided code

if (parseInt(navigator.appVersion)>3){

	screenw = screen.width;

	screenh = screen.height;

}else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()){

	var jToolkit = java.awt.Toolkit.getDefaultToolkit();

	var jScreenSize = jToolkit.getScreenSize();

	screenw = jScreenSize.width;

	screenh = jScreenSize.height;

}

function popapp(jobid){

	var popapp = '';
	popapp = window.open('https://www.sjvc.edu/jobs/jobs_app.php?jobid='+jobid+'','popapp','toolbar=no,menubar=no,resizable=no,scrollbars=yes,status=no,location=no,width=710,height=' + (screenh - 100) + ',left=0,top=0');
	if (window.focus) {popapp.focus()}

}

function popapphelp(){

	var popapphelp = '';
	popapphelp = window.open('http://www.sjvc.edu/jobs/jobs_app_help.php','popapphelp','toolbar=no,menubar=no,resizable=no,scrollbars=yes,status=no,location=no,width=710,height=' + (screenh - 100) + ',left=0,top=0');
	if (window.focus) {popapphelp.focus()}

}

function checkKey(objinput,event,maxlength,nextfield){

	//KEYCODE (ON KEY UP CAUSES THESE KEYS TO FIRE)
	//9  = TAB
	//16 = SHIFT
	if (event.keyCode != 9 && event.keyCode != 16){

 		var ValidChars = "0123456789";
		var Char = "";
		var sText = objinput.value;
		var nText = "";

		for (i = 0; i < objinput.value.length; i++){
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) >= 0){
				nText = nText + Char;
				if (i + 1 >= maxlength){
					objinput.form.elements[nextfield].focus();
					objinput.form.elements[nextfield].select();
				}
			}
		}

		if (nText != null){
			objinput.value = nText;
		}else{
			objinput.value = "";
		}

	}

}

function ctlPastJobs(){
	objPJlnk = findObj("pastjobs_link");
	objPJdiv = findObj("pastjobs");
	if (objPJlnk && objPJdiv){
		if (objPJdiv.style.display == "inline"){
			objPJdiv.style.display = "none";
			objPJlnk.innerHTML = "[Click here to VIEW past jobs you've applied for]";
		}else{
			objPJdiv.style.display = "inline";
			objPJlnk.innerHTML = "[Click here to HIDE past jobs you've applied for]";
		} 
	}

}

function divContact(objCampus,key){
	if (objCampus.checked){
		objshow("dspcontact" + key);
	}else{
		objhide("dspcontact" + key);
	}
}

function divEmploymentApp(element){
	objDiv = findObj("div_"+element);
	objExp = findObj("exp_"+element);
	if (objDiv && objExp){
		if (objDiv.style.display == "inline"){
			objDiv.style.display = "none";
			objExp.innerHTML = "[+]";
		}else{
			objDiv.style.display = "inline";
			objExp.innerHTML = "[-]";
		}
	}
}

function objShowHide(id){

	objElem = findObj(id);

	// ICON IS [+] OR [-] - JUST TAG _ICON TO OBJ.ID
	// E.G. <SPAN ID="NAME_ICON">[+]</SPAN>
	objIcon = findObj(id + "_icon");

	if (objElem){
		if (objElem.style.display == "block"){
			if (objIcon){
				objIcon.innerHTML = "[+]";
			}
			objElem.style.display = "none";
		}else{
			if (objIcon){
				objIcon.innerHTML = "[-]";
			}
			objElem.style.display = "block";
		}
	}
}

function objshow(id){
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval("document.all." + id + ".style.display = 'inline'");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[id].display = "";
	}
	if (document.getElementById && !document.all) {
		document.getElementById(id).style.display = "inline";
	}
}
function objhide(id){
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval("document.all." + id + ".style.display = 'none'");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[id].display = "none";
	}
	if (document.getElementById && !document.all) {
		document.getElementById(id).style.display = "none";
	}
}

function countChars(inField,maxChars,outField){
	objIn = findObj(inField);
	objOut = findObj(outField);
	if (!maxChars){
		maxChars = 0;
	}
	if (objOut){
		if (objIn){
			if (objIn.value.length <= maxChars){
				objOut.innerHTML = (maxChars - objIn.value.length);
			}else{
				objOut.innerHTML = 0;
				objIn.value = objIn.value.substring(0,maxChars);
			}
		}else{
			objOut.innerHTML = "Error";
		}
	}else{
		return false;
	}
}

function stripTagsEasy(Str){
	var stripped = Str;
	stripped = stripped.replace(/(<-)/ig,"<");
	stripped = stripped.replace(/(<)/ig,"<-");
	stripped = stripped.replace(/(->)/ig,">");
	stripped = stripped.replace(/(>)/ig,"->");
	return stripped;
}

function Trim(Str){
	while(Str.charAt(0) == (" ")){
		Str = Str.substring(1);
	}
	while(Str.charAt(Str.length-1) == " "){
		Str = Str.substring(0,Str.length-1);
	}
	return Str;
}

function findObj(n, d){ //v4.01

	var p,i,x;
	if(!d){
		d=document;
	}
	if((p=n.indexOf("?"))>0&&parent.frames.length){
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all){
		x=d.all[n];
	}
	for (i=0;!x&&i<d.forms.length;i++){
		x=d.forms[i][n];
	}
	for(i=0;!x&&d.layers&&i<d.layers.length;i++){
		x=findObj(n,d.layers[i].document);
	}
	if(!x && d.getElementById){
		x=d.getElementById(n);
	}
	return x;

}

// MOVE FLOATING DIV TO TOP AND CENTER
// ---------------------------------------------------------------------------------------------------------------------------------------
function moveDiv(div){
	getScrollXY();
	getSize();
	var centerDiv = 0;
	centerDiv = ((myWidth / 2) - 385);
	if (centerDiv < 0){
		centerDiv = 0;
	}
	objDiv = findObj(div);
	if (objDiv){
		objDiv.style.left = centerDiv;
		objDiv.style.top = scrOfY + 35;
	}
}
var myWidth = 0, myHeight = 0;
function getSize(){
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
}
// scrOfX - Horizontal
// scrOfY - Vertical
var scrOfX = 0, scrOfY = 0;
function getScrollXY() {
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
}

// OBJECT VISIBILITY - INVISIBILITY
// ---------------------------------------------------------------------------------------------------------------------------------------
function objvisible(id){
	objThing = findObj(id);
	if (objThing){
		objThing.style.visibility = "visible";
	}
}
function objinvisible(id){
	objThing = findObj(id);
	if (objThing){
		objThing.style.visibility = "hidden";
	}
}
function objClear(id){
	objThing = findObj(id);
	if (objThing){
		objThing.innerHTML = '';
	}
}
function showBox(box){
	objBox = findObj(box + "Box");
	objData = findObj(box + "Data");
	if (objBox && objData){
		objBox.style.visibility = "visible";
		objData.innerHTML = "";
	}
}
function hideBox(box){
	objBox = findObj(box + "Box");
	objData = findObj(box + "Data");
	if (objBox && objData){
		objBox.style.visibility = "hidden";
		objData.innerHTML = "";
	}
}

// SEND COMMENTS (FROM JOBS_APP_MAIN)
// ---------------------------------------------------------------------------------------------------------------------------------------
function msgsendwm(id){

	msgsenderr('');
	var sendnow = true;
	objMsgBody = findObj('msgbody');
	objMsgErrBody = findObj('msgerrbody');
	objMsgErrDspBody = findObj('msgerrdspbody');
	objMsgStatus = findObj('msgstatus');

	// CHECK BODY
	var msgbody = "";
	if (objMsgBody && objMsgErrBody && objMsgErrDspBody){
		if (!objMsgBody.value){
			objMsgErrBody.style.display = "inline";
			objMsgErrDspBody.innerHTML = "Enter a descriptive plain text message";
			sendnow = false;
		}else{
			msgbody = objMsgBody.value;
			objMsgErrBody.style.display = "none";
			objMsgErrDspBody.innerHTML = "";
		}
	}	

	// AJAX CALL
	if (sendnow){
		// SHOW SENDING ANIMATED GIF
		if (objMsgStatus){
			objMsgStatus.innerHTML = "Sending Response...";
		}
		// AJAX POST TO ADSMSGI ROUTINE
		var postData = "id="+encodeURIComponent(id)+"&msgbody="+encodeURIComponent(msgbody);
		makePOSTRequest('jobs_ajxsndwm.php', postData);
	}

}

// SEND MESSAGE
// ---------------------------------------------------------------------------------------------------------------------------------------
function msgsend(jobid){

	// CLEAR GENERAL ERROR
	msgsenderr('');

	// GET OBJECTS
	objMsgEmail = findObj('msgemail');
	objMsgBody = findObj('msgbody');
	objMsgStatus = findObj('msgstatus');

	objMsgErrEmail = findObj('msgerremail');
	objMsgErrBody = findObj('msgerrbody');

	objMsgErrDspEmail = findObj('msgerrdspemail');
	objMsgErrDspBody = findObj('msgerrdspbody');

	var sendnow = true;

	// CHECK EMAIL
	var msgemail = "";
	if (objMsgEmail && objMsgErrEmail && objMsgErrDspEmail){
		if (!objMsgEmail.value){
			objMsgErrEmail.parentNode.parentNode.style.visibility = "visible";
			objMsgErrEmail.style.display = "inline";
			objMsgErrDspEmail.innerHTML = "Enter your email address";
			sendnow = false;
		}else{
			msgemail = objMsgEmail.value;
			objMsgErrEmail.style.display = "none";
			objMsgErrDspEmail.innerHTML = "";
		}
	}

	// CHECK BODY
	var msgbody = "";
	if (objMsgBody && objMsgErrBody && objMsgErrDspBody){
		if (!objMsgBody.value){
			objMsgErrBody.parentNode.parentNode.style.visibility = "visible";
			objMsgErrBody.style.display = "inline";
			objMsgErrDspBody.innerHTML = "Enter a descriptive plain text message";
			sendnow = false;
		}else{
			msgbody = objMsgBody.value;
			objMsgErrBody.style.display = "none";
			objMsgErrDspBody.innerHTML = "";
		}
	}	

	// AJAX CALL
	if (sendnow){
		// SHOW SENDING ANIMATED GIF
		if (objMsgStatus){
			objMsgStatus.innerHTML = "Sending Response...";
		}
		// AJAX POST TO ADSMSGI ROUTINE
		var postData = "jobid="+encodeURIComponent(jobid)+"&msgemail="+encodeURIComponent(msgemail)+"&msgbody="+encodeURIComponent(msgbody);
		makePOSTRequest('jobs_ajxsnd.php', postData);
	}

}

// CALLED FROM MSGSEND()
function msgsendscc(){

	objMsgEmail = findObj('msgemail');
	objMsgBody = findObj('msgbody');
	objMsgStatus = findObj('msgstatus');

	objMsgErrEmail = findObj('msgerremail');
	objMsgErrBody = findObj('msgerrbody');

	objMsgErrDspEmail = findObj('msgerrdspemail');
	objMsgErrDspBody = findObj('msgerrdspbody');

	// CLOSE ERRORS
	if (objMsgErrEmail && objMsgErrDspEmail){
		objMsgErrEmail.style.display = "none";
		objMsgErrDspEmail.innerHTML = "";
	}
	if (objMsgErrBody && objMsgErrDspBody){
		objMsgErrBody.style.display = "none";
		objMsgErrDspBody.innerHTML = "";
	}

	// CLEAR INPUT
	if (objMsgEmail){
		objMsgEmail.value = "";
	}
	if (objMsgBody){
		objMsgBody.value = "";
	}

	// SUCCESS MESSAGE
	if (objMsgStatus){
		objMsgStatus.innerHTML = "Your message has been sent.";
	}

}

// MESSAGE ERROR
function msgsenderr(value){

	objMsgStatus = findObj('msgstatus');
	objMsgErrEmail = findObj('msgerremail');
	objMsgErrDspEmail = findObj('msgerrdspemail');

	// DISPLAY ERROR
	if (objMsgErrEmail && objMsgErrDspEmail){
		if (value){
			objMsgErrEmail.style.display = "inline";
			objMsgErrDspEmail.innerHTML = value;
		}else{
			objMsgErrEmail.style.display = "inline";
			objMsgErrDspEmail.innerHTML = "Error not passed...";
		}
	}
	if (objMsgStatus){
		objMsgStatus.innerHTML = "";
	}

}

// AJAX XMLHTTP METHOD
// ---------------------------------------------------------------------------------------------------------------------------------------
// NOTE: In order to avoid a syntax error in Firefox, if the returned content is
// NOT valid XML, use the overrideMimeType method to set the content-type.

var http_request = false;

function makePOSTRequest(url, parameters){

	http_request = false;

	// IE7, Mozilla, Safari, etc: Use native object
	if (window.XMLHttpRequest){
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType){
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}

	 // IE5.X and IE6.X
	}else if (window.ActiveXObject){

		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}

	}

	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
      
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);

}

function alertContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			eval(http_request.responseText);
			//alert(http_request.responseText);
		} else {
			alert('There was a problem with the request.');
		}
	}
}