

//////////////////////////////////////
//  GENERIC RETURN ELEMENT FUNCTION //
//////////////////////////////////////

function getE( v ) {
  // e is for element!
  e = false;
  
	var d = window.document;
  if ( d.getElementById ) {
    e = d.getElementById( v );
  }
  else e = d[ v ];

  return e;
}

/*
	FOR SCHOOL STUFF
*/

function populateSchools(st,type,cty,sd,sc,url,access_code) {	

	cleanURL = url.substr(0,url.indexOf("?")) 
	if(cleanURL !=	"") {
		url = cleanURL;
	}
	
	
	switch (st) {
		case "MO": 
		case "KS":	
			url += "?state=" + st;
			break;
		case "OTHER":
			url += "?state=" + st;
			break;
	}
	
	if(access_code) url += "&access_code=" + access_code;
	
	if(type != "") url += "&type=" + type;
	
	if(cty != "") url += "&county=" + cty;

	if(sd != "") url +="&district=" + sd;
	
	if(sc != "") url +="&sc=" + sc;
	
	document.location = url;
}

function showHide(elem,display) {
	//alert('hello?');
	e = document.getElementById(elem);
	
	// I didn't know if this was used elsewhere than the editClass.php file
	
	if(display == "visible" || display == "hidden") {
		e.style.visibility = display;
	}
	
	if(display == "block" || display == "none") {
		e.style.display = display;
	}
}



/*
	AJAX BASE FUNCTIONALITY
*/

var xmlhttp = null;
var displayDiv = "";
var nextFunc = "";

////////////////////////////////
//	BASIC AJAX LOADER					//
////////////////////////////////

function getPage( url, second ) {

	if ( second != false ) nextFunc = second;
	else nextFunc = "";
	
	xmlhttp=null;
	if (window.XMLHttpRequest) {// code for all new browsers
  	xmlhttp=new XMLHttpRequest();
  }
	else if (window.ActiveXObject) {// code for IE5 and IE6
  	xmlhttp=new ActiveXObject( "Microsoft.XMLHTTP" );
  }
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=stateChange;
		xmlhttp.open( "GET", url, true );
		xmlhttp.send( null );
  }
	else {
  	alert( "Your browser does not support XMLHTTP." );
  }
}

////////////////////////////////
//	EVENT HANDLER FOR HTTP		//
//	STATE CHANGE							//
////////////////////////////////

function stateChange() {
	if (xmlhttp.readyState==4) {// 4 = "loaded"
		if (xmlhttp.status==200) {// 200 = OK
			e = getE( displayDiv );
			e.innerHTML = xmlhttp.responseText;
			if ( nextFunc != "" ) eval( nextFunc );
		}
		else {
			alert("Problem retrieving XML data");
		}
	}
}


/*
	FOR CONTENT PDF POPS
*/

var cats = new Array();
var co = "";

function popContent( id, t ) {
	clearCats();
	if ( co == id ) {
		co = "";
	}
	else {
		co = id;
		displayDiv = "conts_"+id;
		e = getE( displayDiv );
		e.innerHTML = "<p>loading...</p>";
		if ( t == "s" ) getPage( "getStudentContent.php?catid="+id );
		else getPage( "getTeacherContent.php?catid="+id );
	}
}

function clearCats() {
	for ( i=0, j=cats.length; i<j; i++ ) {
		id = cats[i];
		div = "conts_"+id;
		e = getE( div );
		e.innerHTML = "";
	}
}




	//////////////////////////////////////////////////////////////////////
	//	NEW STUFF HERE .. JAVASCRIPT SWAP .PNG TO .GIF IMAGES FOR IE6
	//////////////////////////////////////////////////////////////////////
	
	
function swapTransparentPNGForIE6() {
	var browserAgent = navigator.userAgent;
	
	if(browserAgent.match("MSIE 6.0")) {
		originalHTML = document.body.innerHTML;
		newHTML = originalHTML.replace(/\.png/g, ".gif");
		
		document.body.innerHTML = newHTML;
	}
}


function popEstarPreview() {
	window.open("/myaccount/estarPreview.php", "estar", "width=490,height=360,menubar=0,resizable=0,status=0,scrollbars=0,location=0");
}