// JavaScript Functions 
// Toggle functionality for content we do not want to display by default
//var toggledDisplay = new Object();
  //  toggledDisplay['faq1a'] = true;
    //toggledDisplay['faq2a'] = true;
    //toggledDisplay['faq3a'] = true;
		  
function toggleDisplay(bDisplayed) {
  if(!document.getElementById || toggleDisplay.arguments.length < 2) 
  	return;
	
  var displayed = new Object();
      displayed['true'] = 'block';
      displayed['false'] = 'none';
  
  for(var i = 1; i < toggleDisplay.arguments.length; i++) {
    oDisplay = document.getElementById(toggleDisplay.arguments[i]);
    
	if(oDisplay) {
      oDisplay.style.display = displayed[bDisplayed];
      // mozilla is the only browser out of the lot that can't get this right.  so, if we're
      // setting an object's display style to block, we gotta reload any images contained
      // within that block.  mozilla won't do it for you like every other browser that
      // supports the functionality of changing the display style dynamically.
      // begin crap browser hack
      if(bDisplayed) {
        oImages = oDisplay.getElementsByTagName('IMG');
        for(var j = 0; j < oImages.length; j++)
          oImages[j].src = oImages[j].src;
      }
      // end mozilla, err, crap browser hack
       if(typeof toggledDisplay[toggleDisplay.arguments[i]] != 'undefined')
        toggledDisplay[toggleDisplay.arguments[i]] = !bDisplayed;
    } // if(oDisplay) {
  } // for(var i = 1; i < toggleDisplay.arguments.length; i++) {
} // function toggleDisplay(bDisplayed) {}

//List of transitional effects to be randomly applied to billboard:
var billboardeffects=["GradientWipe(GradientSize=1.0 Duration=0.7)", "Inset", "Iris", "Pixelate(MaxSquare=5 enabled=false)", "RadialWipe", "RandomBars", "Slide(slideStyle='push')", "Spiral", "Stretch", "Strips", "Wheel", "ZigZag"];
//var billboardeffects=["Iris"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
// These effects are only experienced in Internet explorer and not in mozilla firefox.
var tickspeed=5000; //ticker speed in miliseconds (5000=5 seconds)
var effectduration=500; //Transitional effect duration in miliseconds
var hidecontent_from_legacy=1; //Should content be hidden in legacy browsers- IE4/NS4 (0=no, 1=yes).
var filterid=Math.floor(Math.random()*billboardeffects.length);
document.write('<style type="text/css">\n');
if (document.getElementById)
	document.write('.billcontent{display:none;\n'+'filter:progid:DXImageTransform.Microsoft.'+billboardeffects[filterid]+'}\n');
else if (hidecontent_from_legacy)
	document.write('#contentwrapper{display:none;}');
	document.write('</style>\n');
var selectedDiv=0;
var totalDivs=0;

function contractboard(){
	var inc=0;
	while (document.getElementById("billboard"+inc)){
		document.getElementById("billboard"+inc).style.display="none";
		inc++
	}
} // function contractboard(){}

function expandboard(){
	var selectedDivObj=document.getElementById("billboard"+selectedDiv);
	contractboard();
	if (selectedDivObj.filters){
		if (billboardeffects.length>1){
			filterid=Math.floor(Math.random()*billboardeffects.length);
			selectedDivObj.style.filter="progid:DXImageTransform.Microsoft."+billboardeffects[filterid];
		}
	selectedDivObj.filters[0].duration=effectduration/1000;
	selectedDivObj.filters[0].Apply();
	} // if (selectedDivObj.filters){}
	
	selectedDivObj.style.display="block";
	if (selectedDivObj.filters)
		selectedDivObj.filters[0].Play();
	selectedDiv=(selectedDiv<totalDivs-1)? selectedDiv+1 : 0;
	setTimeout("expandboard()",tickspeed);
} // function expandboard(){}

function startbill(){
	while (document.getElementById("billboard"+totalDivs)!=null)
		totalDivs++;
	
	if (document.getElementById("billboard0").filters)
		tickspeed+=effectduration;
		expandboard();
} // function startbill(){}
if (TitleCode == null) {
	if (window.addEventListener)
		window.addEventListener("load", startbill, false);
	else if (window.attachEvent)
		window.attachEvent("onload", startbill);
	else if (document.getElementById)
		window.onload=startbill;
}
/////// Vertical menu items begin here /////
//Contents for menu 1
var menu1=new Array();
menu1[0]='<a href="nu_vision.php">NU Vision</a>';
menu1[1]='<a href="nu_australia.php">NU Australia</a>';
menu1[2]='<a href="nu_zambia.php">NU Zambia</a>';
menu1[3]='<a href="nu_milestones.php">NU Milestones</a>';
menu1[4]='<a href="nu.php">Student Profiles</a>';
menu1[5]='<a href="nu_student_impact.php">NU Student Impact</a>';


//Contents for menu 2, and so on
var menu2=new Array();
menu2[0]='<a href="latest_news.php">Latest News</a>';
menu2[1]='<a href="graduations.php">Graduations</a>';
//menu2[2]='<a href="farm.php">NU Projects &#187;</a>';

//Contents for menu 3, and so on
var menu3=new Array();
menu3[0]='<a href="sponsor_student.php">Sponsor a Student</a>';
menu3[1]='<a href="sponsor_project.php">Support a Project</a>';

//Contents for submenu
var menu4=new Array();
menu4[0]='<a href="farm.php">Farm Projects</a>';
menu4[1]='<a href="campus.php">Campus Projects</a>';

var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var horizontaloffset=2 //horizontal offset of menu from default location. (0-5 is a good value)

// Functions for the menu begin here
var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width: 160px" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x-obj.offsetWidth < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move menu up?
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? (position at top of viewable window then)
edgeoffset=dropmenuobj.y
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
/* AJAX FUNCTIONS TO HANDLE THE XMLHTTP OBJECT*/
// onchange="ajaxManager('start_up', 'Pickup', this.value, 'process_ajax.php')
// start_up is the case label to appropriatly pass arguments to the next case block
// Pickup is the name of the container that the result will be displayed in
// this.value is the value to be used as the search creteria
// process_ajax.php is the php file return the results 
function ajaxManager(){
	/*Funtion arguments in new array*/
	var args = ajaxManager.arguments;
	/*Action based on first argument*/
	switch(args[0]){
		case 'load_data':
		
		var request = getXMLHttp(); /*Create an instance of the xmlhttp request object*/
		
		if (request){ /*IF object was succesfully created call the showdata function*/
			/*args[1] is the container id, args[2] is the element value, and args[3] is the php file name */
			showData(args[1], args[2], args[3], request);
			} else {
				document.getElementById(args[1]).innerHTML = 'Browser does not support AJAX!';
			}
		break;
		case 'start_up': 
		/*Return call to this function to change execution dicision. args[1] is the container id and args[2] is the element's value and args[3] is the php file */
		ajaxManager('load_data', args[1], args[2], args[3]);
		break;
		
	}
}
	
/*  Funtiion creates an instance of the xmlhttp request object for major browsers */
function getXMLHttp(){
	var xmlHttp = null;
	/*Mozilla based browsers use this object*/
	try{
		xmlHttp = new XMLHttpRequest();
		}
	catch(e){
		try{ /*Internet Explorer browsers use this object*/
			xmlHttp = new ActiveXObject('Msxml2.XMLHttp');
			}
		catch(e){
			xmlHttp = new ActiveXObject('Microsoft.XMLHttp');
			}
		}
	/* If object successfully created return object to caller */
	if (xmlHttp){ return xmlHttp; } else { return false; }
	}

/* Funtion handles the passes parameters to the file that handles the data request */
function showData(){
	/* Funtiion argument list in new array*/
	var args_data = showData.arguments;
	/* Extract second argument from list considered as first search ID*/
	if (args_data[1]){ 
	var search_id = escape(args_data[1]); 
	} else{ 
	var search_id = 1; 
	}
	//var search_id = 1;
	/* Extract third argument from list considered as second search ID*/
	//if (args_data[2].length > 0){ var search_id1 = escape(args_data[2]); }else{ var search_id1 = ''; }
	//if (args_data[5].length > 0){ var condition = escape(args_data[5]); }	
	/* Extract fourth argument from list considered as URl or path to the file that handles the data request*/	
	url1 = args_data[2];
	/* Set the output container's inner HTML property to an empty string to await new input*/
	document.getElementById( args_data[0]).innerHTML = '';
	if(!args_data[3]){ /* If xmlhttp object is not defined */ 
	document.getElementById( args_data[0]).innerHTML = 'Browser does not support AJAX!'; 
	} else{ 
	/* We have an bject Open connection to the server using the get methodargs_data[4].overrideMimeType("text/xml");*/
		args_data[3].open('POST', url1, true);
		args_data[3].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");/*args_data[4].setRequestHeader("Content-Lenght", url.length);*/
		args_data[3].setRequestHeader("Connection", "close");/* We are not sending anything to the server*/
		args_data[3].send("displayID="+search_id);/* Assign the state change event to this callback funtion */
		args_data[3].onreadystatechange = function (){ stateChanged(args_data[3], args_data[0], url1, search_id); }	
	}
}
function stateChanged(request, container, url1, search_id){
	if (request.readyState == 3){
		document.getElementById(container).innerHTML = 'Loading data...\n' + '<img src="../images/site/ajax-loader.gif" width="16" height="16" />';
	}
	if (request.readyState == 4 && request.status == 200) {
		document.getElementById(container).innerHTML = '';
		document.getElementById(container).innerHTML = request.responseText;
		
	}
}
