function swapCheck(id) {
  var box = eval("document.getElementById('box_"+id+"')");
  //alert(box);
  box.checked = true;
}

function checkSection(states) {
  /*alert(states[0]);*/
  for (var i=0; i<states.length; i++) {
  	var box = eval("document.getElementById('box_"+states[i]+"')");
    box.checked=true;
  }
}

function unCheckSection(states) {
  /*alert(states[0]);*/
  for (var i=0; i<states.length; i++) {
  	var box = eval("document.getElementById('box_"+states[i]+"')");
    box.checked=false;
  }
}

function submitForm(form,location){
	form.action=location;
  //alert(form.SubmitFunction.value);
  if(form.SubmitFunction){
    eval(form.SubmitFunction.value);
  }
	form.submit();
}

function moveAthletic(sourceList,radioset,destList){
  
	isThere=0;
	i=sourceList.options.length
	var selected;
	for(i = 0; i < radioset.length; i++){
		if(radioset[i].checked == true){
			selected = radioset[i].value;
		}	

	
	}
	if(sourceList.options[sourceList.selectedIndex]  && sourceList.options[sourceList.selectedIndex].value){
		var tmp1=selected+sourceList.options[sourceList.selectedIndex].value;
		var tmp2=sourceList.options[sourceList.selectedIndex].text+"("+selected+")";

		for (j=0; j<destList.options.length; j++){
			if(tmp1==destList.options[j].value){
					isThere=1;
			}
		
		}
		if(isThere==0){
			if(sourceList.options != null){
				var i=destList.options.length;
				destList.options[i]=new Option(tmp2);
				destList.options[i].value=tmp1;			
			}
		}
	}else{
		alert("Please select a sport!");
	}
  	
}
/////////////////////////////////////////////////////////////////////////////////

function fillSelectFromArray(selectCtrl, itemArray){
	var i, j;
 	var prompt;
	
 	// empty existing items
 	for (i = selectCtrl.options.length; i >= 0; i--) {
  		selectCtrl.options[i] = null; 
 	}
 	j=0;
 	if (itemArray != null) {
		//alert("testing good array: "+itemArray.length+":"+selectCtrl.options.length);
  		// add new items
  		for (i = 0; i < itemArray.length; i++) {
   			selectCtrl.options[i] = new Option(itemArray[i][1]);
   			if (itemArray[i][1] != null) {
    				selectCtrl.options[i].value = itemArray[i][0]; 
			}
   		}
   		j++;
  	}
	
}
////////////////////////////////////////////////////////////////////////////////

function moveTo(selectOne,selectTwo){
	isThere=0;
	i=selectTwo.options.length;
	if(selectOne.options[selectOne.selectedIndex] && selectOne.options[selectOne.selectedIndex].value){
	   for(k=0; k<selectOne.options.length; k++){
		isThere=0;
		if(selectOne.options[k].selected==true){
			for(j=0; j<selectTwo.options.length; j++){
				if(selectOne.options[k].value==selectTwo.options[j].value){
					isThere=1;
				}
			}
			i=selectTwo.options.length;
			if(selectTwo.options.length==50){
				alert("A maximum 50 majors can be search at one time");
				return;
			}
			if(isThere==0){
				selectTwo.options[i]=new Option(selectOne.options[k].text);
				selectTwo.options[i].value=selectOne.options[k].value;
			}
		}
	   }
	}else{
		alert("Please select a value!");
	}
}
////////////////////////////////////////////////////////////////////////////////

function moveAll(selectOne,selectTwo){
	isThere=0;

	for(k=0; k<selectOne.options.length; k++){
	        isThere=0;
		for(j=0; j<selectTwo.options.length; j++){
			if(selectOne.options[k].value==selectTwo.options[j].value){
				isThere=1;
			}
		}
		i=selectTwo.options.length;
		if(selectTwo.options.length==50){
                                alert("A maximum 50 majors can be search at one time");
                                return;
                }

		if(isThere==0){
			selectTwo.options[i]=new Option(selectOne.options[k].text);
			selectTwo.options[i].value=selectOne.options[k].value;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////

function moveFrom(selectform){
	if(selectform.selectedIndex!=-1){
		for(k=0; k<selectform.options.length; k++){	
			if(selectform.options[k].selected==true){
				selectform.options[k]=null;
				k--;
			}
		}
	}
}
////////////////////////////////////////////////////////////////////////////////
 
function moveTextAndSelect(textbox,sourceList,destList1,destList2){
 	moveTo(sourceList,destList2);
	value=textbox.value+":"+sourceList.options[sourceList.selectedIndex].value;
 
 	isThere=0;
	for(j=0; j<destList1.options.length; j++){
		if(destList1.options[j].value==value){
			isThere=1;
		}
	}
	if(isThere==0  && !textbox.value==""){
		i=destList1.options.length;
 		destList1.options[i]=new Option(textbox.value);
		destList1.options[i].value=value;
		
	}
}
////////////////////////////////////////////////////////////////////////////////

function moveSelectAndSelect(slist,sourceList,destList1,destList2){
 	moveTo(sourceList,destList2);
	value=slist.options[slist.selectedIndex].value;
 
 	isThere=0;
	for(j=0; j<destList1.options.length; j++){
		if(destList1.options[j].value==value){
			isThere=1;
		}
	}
	if(isThere==0){
		i=destList1.options.length;
 		destList1.options[i]=new Option(slist.options[slist.selectedIndex].text);
		destList1.options[i].value=value;
		
	}
}
////////////////////////////////////////////////////////////////////////////////


function test(sourceList,radioset,destList){
	var value;
	var text=sourceList.options[sourceList.selectedIndex].text+"("+radioset.value+")";
	if(radioset.value == "local"){
		value=sourceList.options[sourceList.selectedIndex].value+":true";
	}else{
		value=sourceList.options[sourceList.selectedIndex].value+":false";
	}
	var i=destList.options.length;
	destList.options[i]=new Option(text);
	destList.options[i].value=value;
}
////////////////////////////////////////////////////////////////////////////////

function moveRadiosetAndSelect(sourceList,radioset,destList){	
	isThere=0;
	i=sourceList.options.length
	for (j=0; j<destList.options.length; j++){

		reg=new RegExp(sourceList.options[sourceList.selectedIndex].text+":*");
		if(reg.test(destList.options[j].text)){
				isThere=1;
		}
		
	}
	if(isThere==0){
		var value;
			
		for(i = 0; i < radioset.length; i++){
			if(radioset[i].checked == true){
				var Selected = radioset[i].value;
			}	

	
		}
		var text=sourceList.options[sourceList.selectedIndex].text+"("+Selected+")";
		if(Selected == "local"){
			value=sourceList.options[sourceList.selectedIndex].value+":true";
		}else{
			value=sourceList.options[sourceList.selectedIndex].value+":false";
		}
		var i=destList.options.length;
		destList.options[i]=new Option(text);
		destList.options[i].value=value;
	}
	
}
////////////////////////////////////////////////////////////////////////////////

function moveSelect(sourceList,destList){
	isThere=0;
	i=destList.options.length;
	for (j=0; j<destList.options.length; j++){
		if(sourceList.options[sourceList.selectedIndex].text==destList.options[j].text){
				isThere=1;
		}
	}	
	if(isThere==0){				
	var text=sourceList.options[sourceList.selectedIndex].text;
	destList.options[i]=new Option(text);
	destList.options[i].text=text;
	}	

}
////////////////////////////////////////////////////////////////////////////////

function oldmoveSelect(sourceList,destList){

	var text=sourceList.options[sourceList.selectedIndex].text;
	var l=destList.options.length;
	destList.options[l]=new Option(text);
	destList.options[1].value=value;
	
}
////////////////////////////////////////////////////////////////////////////////

function moveSelect(sourceList1,sourceList2,sourceList3,destList){
	var text=sourceList1.options[sourceList1.selectedIndex].text+"("+sourceList2.options[sourceList2.selectedIndex].text+","+sourceList3.options[sourceList3.selectedIndex].text+")";
	var value=sourceList1.options[sourceList1.selectedIndex].value+":"+sourceList2.options[sourceList2.selectedIndex].value+":"+sourceList3.options[sourceList3.selectedIndex].value;
	isThere=0;
	i=destList.options.length;
	for (j=0; j<destList.options.length; j++){
		reg=new RegExp(sourceList1.options[sourceList1.selectedIndex].text+":*");
		
		if(reg.test(destList.options[j].text)){
				isThere=1;
		}
	}	
	if(isThere==0){				
		destList.options[i]=new Option(text);
		destList.options[i].value=value;
	}	

}
////////////////////////////////////////////////////////////////////////////////
function selectAll(sourceList1){
	for(i=0; i<sourceList1.options.length; i++){
		sourceList1.options[i].selected=true;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////

  function check_field(field,regEx,message){
	
    var x=field.value;
	
    var reg=new RegExp(regEx);
    if(reg.test(x)){
	    result=true;
    }else{
	    alert(message);
	    result=false;
    }
	
    return(result);
  }
////////////////////////////////////////////////////////////////////////////////

function hoverOn(targetDiv,setClass) {
  document.getElementById(targetDiv).className = setClass;
}
 
function hoverOff(targetDiv,setClass) {
  document.getElementById(targetDiv).className = setClass; 
}

function schoolInfo(scid,area,location) {
  window.location = "/school/school_hub.jsp?scid="+scid+"&location="+location+"&area="+area;
}

function schoolInfoNoArea(scid,location) {
  window.location = "/school/school_hub.jsp?scid="+scid+"&location="+location;
}

function openWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

////////////////////////////////////////////////////////////////////////////////
//David Gilardi 01/16/2008: Added following function changeLinkColor()
function changeLinkColor(id, onOff) {
  var browser = navigator.appName;

  // Set navCell and navBullet which will be concatenated with the input
  // id.  This will create a reference to the correct id within school_hub.jsp
  // where onOff == 1 || true.
  var navCell = 'navCell' + id;
  var navBullet = 'navBullet' + id;

  if (browser == 'Micorsoft Internet Explorer') {
    var navCellBulletColor = document.getElementById(navBullet).currentStyle.color;
    var masterColor = document.getElementById("kfLinkTable").currentStyle.color;

  } else if (browser == 'Netscape') {
    var navCellBulletColor = window.getComputedStyle(document.getElementById(navBullet),null).color;
    var masterColor = window.getComputedStyle(document.getElementById("kfLinkTable"),null).color;

  } else {
    var navCellBulletColor = document.getElementById(navBullet).currentStyle.color;
    var masterColor = document.getElementById("kfLinkTable").currentStyle.color;

  }


  if (onOff == 1) {
    document.getElementById(navCell).style.color = navCellBulletColor;

  } else if (onOff == 0) {
    document.getElementById(navCell).style.color = masterColor;
	
  }

}


function getTab(tab, scid, xmlCatch, tabName) {
  if (xmlCatch == 1) {
    document.getElementById("generalInfo").innerHTML="<div id='hubLoader'><p>The school's KeyFacts are not available at this time.<br/>We are currently working to update our database and will display the information as soon as it is available.</p></div>";
  } else {
    document.getElementById("generalInfo").innerHTML="<div id='hubLoader'><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='250' height='20'><param name='movie' value='/flash/loader.swf' /><param name='quality' value='high' /><embed src='/flash/loader.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='250' height='20'></embed></object></div>";
    loadXMLDoc(tab, "/school/"+tab+".jsp?scid="+scid);
  }

  //Set the value of hub_keyfactsTabInfo based off of tabName
  document.getElementById('hub_schoolInfo').innerHTML = tabName;

}

var req;

function loadXMLDoc(tab,url) {
  // alert("loadXMLDoc "+tab+" : "+url);
	req = false;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() { processReqChange(tab); }
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() { processReqChange(tab); }
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange(tab) {
	//alert("processReqChange " + tab);

	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"

		document.getElementById("generalInfo").innerHTML=req.responseText;

		// This determines which of the selections in the programsSelect option drop down
		// are available once the page is loaded
		if (req.status == 200 && tab == 'majorsDegrees') {
			var elOption = document.getElementById("programsSelect");

			var myOptions = new Array();
			myOptions[0] = "Undergraduate:undergraduate:1"; 
			myOptions[1] = "Graduate:graduate:2";
			myOptions[2] = "International:international:3";
			myOptions[3] = "General/Other:generalOther:4";

			for (i = 0; i < myOptions.length; i++) {
				var myOptionsData = myOptions[i].split(":");
				var text = myOptionsData[0];
				var name = myOptionsData[1];
				var value = myOptionsData[2];

				var elDiv = document.getElementById("div_" + name);
				if (elDiv != null) {
					var size = elDiv.getAttribute('size');

					if (size != 0) {
						var y = document.createElement('option');
						y.text = text;
						y.id = name + '_dropdown';
						y.name = name;
						y.value = value;
						try {
							elOption.add(y,null); // standards compliant

						} catch(ex) {
							elOption.add(y); // IE only
						} // end try-catch
					} // end if size not zero

				} // end if elDiv not null

			} // end foreach myOptions

		} // end if status is 200 and tab is majorsDegrees

	} // end if readyState is 4
	
/* these 2 lines are causing JavaScript errors as of Mar 3 2009. commenting out to avoid errors.
	//Re-register exit links after tab switch
	Behaviour.register(myrules);
	Behaviour.apply();
*/
}

function hoverHubMenu(headTab,target,state) {
  if (state == 0) {
    document.getElementById(headTab).className = 'waxOn';
    ypSlideOutMenu.showMenu(target);
  } else if (state == 1) {
    document.getElementById(headTab).className = 'waxOff';
    ypSlideOutMenu.hideMenu(target);
  }
}
