//
//==== JAVASCRIPT FOR DEPT WEBSITES =====
//


//loads on page load
function init() {
	//add mouse events to top level toolbar
	var Box = document.getElementById("Header_Toolbar");
	for(var i=0; i<Box.firstChild.childNodes.length; i++) {
		if(Box.firstChild.childNodes[i].firstChild.id == "H_"+Content) Box.firstChild.childNodes[i].className = "MenuButtonHA";
	}
	
	var SBox = document.getElementById("Header_SubToolbar");
	for(var i=0; i<SBox.firstChild.childNodes.length; i++) {
		if(SBox.firstChild.childNodes.length>1) {
			if(SBox.firstChild.childNodes[i].firstChild.id == "SH_"+Content) {
				SBox.firstChild.childNodes[i].className = "MenuButtonSHA";
			}
		}
	}
	
	//create splash content
	if(Content=="home") {
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) {BuildFlashObject('splash','/pics/home/splash-temp.swf','550','220');} else {document.getElementById("Home_SplashBox").innerHTML = ''}
	}
	
	//hook for AJAX functionality
	XmlHttp = setXMLHttpObject();
	if(XmlHttp && document.getElementById("FacultyFilter")!=null) document.getElementById("FacultyFilter").style.display="block";
	//if(XmlHttp!=false && document.getElementById("FacultyFilter")!=null) document.getElementById("FacultyFilter").style.display="block";
}


//builds flash object on page
function BuildFlashObject(who,what,width,height) {
	//build flash object
	document.getElementById("Home_SplashBox").innerHTML = ''+
		'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+who+'" align="middle">' +
		'<param name="allowScriptAccess" value="sameDomain" />'+
		'<param name="movie" value="'+what+'" />'+
		'<param name="loop" value="false" />'+
		'<param name="menu" value="false" />'+
		'<param name="quality" value="high" />'+
		'<param name="wmode" value="transparent" />'+
		'<embed src="../'+what+'" loop="false" menu="false" quality="high" wmode="transparent" width="'+width+'" height="'+height+'" name="'+who+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
		'</object>';
}

//create XMLHttpRequest Object
function setXMLHttpObject() {
	 
 
	//xho=false;
	if(window.XMLHttpRequest) return new XMLHttpRequest();
	if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
		try{ return new ActiveXObject("Msxml2.XMLHTTP.6.0") }catch(e){}
		try{ return new ActiveXObject("Msxml2.XMLHTTP.3.0") }catch(e){}
		try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
		try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
		throw new Error("This browser does not support XMLHttpRequest or XMLHTTP.")
	};
	//if(window.ActiveXObject) try {xho = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xho = new ActiveXObject("Microsoft.XMLHTTP"); }
	//return xho;
}

//retrieve specified data from server
function RetrieveData(who,what,filter) {
	//alert(filter);
	var parameters = "dept="+who+"&class="+what+"&filter="+filter;
	
	XmlHttp.open("GET", "/content/getdata.php?"+parameters, true);         
	XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	XmlHttp.setRequestHeader("Content-length", parameters.length);
	XmlHttp.setRequestHeader("Connection", "close");
	XmlHttp.send(parameters);
	XmlHttp.onreadystatechange = function() {
		if(XmlHttp.readyState == 4 && XmlHttp.status == 200) {
			Data = XmlHttp.responseXML.getElementsByTagName("data")[0].firstChild.nodeValue;
			document.getElementById("FSFilteredResults").innerHTML=Data;
		}
	}
}

//switch out page based on quicklist selection
function ProgramSelect(who) {
	document.location="/programs/"+who;
}

previousLength=0;
currentField="";

//checks status on form field
function CheckFillStatus(who) {	
	if(currentField=="ksu-n1") if(document.getElementById(who).value.length==4 && previousLength==3) { document.getElementById("ksu-n2").focus(); previousLength=0; }
	if(currentField=="ksu-v1") if(document.getElementById(who).value.length==4 && previousLength==3) { document.getElementById("ksu-v2").focus(); previousLength=0; }
	if(currentField=="phone-n1") if(document.getElementById(who).value.length==3 && previousLength==2) { document.getElementById("phone-n2").focus(); previousLength=0; }
	if(currentField=="phone-n2") if(document.getElementById(who).value.length==3 && previousLength==2) { document.getElementById("phone-n3").focus(); previousLength=0; }
	
	previousLength=document.getElementById(who).value.length;
	currentField=who;
}

//validate value of specific fields
function ValidateField(who) {
	//this will be used to validate that the user has properly completed certain fields
}




onload=init;