


  

/// XML Parser & Effect Functions



// SWAP CSS FILE ON PAGE
function makeCSS(theSheet) {

	  var styles = "@import url('"+theSheet+"');"; 
	  var newCSS=document.createElement('link'); 
	  newCSS.rel='stylesheet'; 
	  newCSS.href=theSheet; 
	  document.getElementsByTagName("head")[0].appendChild(newCSS); 
	 }

// SWAP CLASS OF OBJECT
function toggleClass(id, value){var theElement=document.getElementById(id); theElement.className=value;} 

// SHOW / HIDE FUNCTION - controls multiple "zones" & may "activate" the selected link
var currentToggles = {};
var lastId = {};
var lastClass = {};
var activeClass = {};

function toggle(set, id, event, srcid) {
// reset class of last nav item selected
if (lastClass[set]) {
document.getElementById(lastId[set]).className = lastClass[set];
	}	

// set current selected nav item class to 'active' state
if (srcid){
	lastId[set]=srcid;
	lastClass[set]=document.getElementById(srcid).className;
	activeClass[set]=lastClass[set]+"-active"
	document.getElementById(srcid).className = activeClass[set];
}	
//start toggle display //
if (set in currentToggles) {
	document.getElementById(currentToggles[set]).style.display = "none";
	}
	if (document.getElementById(id)) {
	document.getElementById(id).style.display = "block";
	currentToggles[set] = id;
    }
}


// SHOW / HIDE FUNCTION - controls the SAME div container

function toggleSame(id) {
var o = document.getElementById(id);
if (o.style.display == 'block') {
hideElement(id);
} else {
showElement(id);
}
}
function showElement(id) {
var o = document.getElementById(id);
o.style.display = 'block';
}
function hideElement(id) {
var o = document.getElementById(id);
o.style.display = 'none';
}


// Select a specific program by VALUE from Select drop-down
function changeProgram(paramValue) {
window.opener.document.getElementById('program').value=paramValue;
window.opener=self;
window.close();
}

// Returns the tab/fp hash from the url, empty string if none, null if unknown
function getHashFromUrl() {
	if (document.location.hash) {
		if (document.location.hash.indexOf("#tab") == 0 || document.location.hash.indexOf("#fp") == 0) {
			return document.location.hash.substring(1).replace("_", "");
		}
		return null;
	}
	return "";
}



function switchToTab(tab) {
	// check for a bad value

	if (!tab || document.getElementById(tab) == null) {
		tab = defaultHash;
		if (document.getElementById(tab) == null) {
			// screw you guys, i'm going home
			return;
		}
	}
	
	var nav = "nav"+tab.substring(3, 4);
	if (nav=="nav") {nav="nav1";}
	toggle("menu", tab);
	
	// for extra tab-related things, like changing title or image
	if (typeof switchTabExtras != "undefined") {
		switchTabExtras(tab);
	}
}



//set up page instance and look for pre-set or pre-selected tabs
toggle("fp", "fp0"); toggle("menu", "tab1"); toggle("menu", "tab1");
var currentHash = getHashFromUrl();
var defaultHash = ("" || "tab1") + "";
switchToTab(currentHash);

// Timer script to see if tab# has changed as a result of browser back / forward button clicks
setInterval(function() {
	var newHash = getHashFromUrl();
	if (newHash != null && newHash != currentHash) {
		switchToTab(newHash);
		currentHash = newHash;
	}
}, 100);

// NMS search form asset materials



function killGadget() {
	return;
}
// trimming a value
function trim(value) {
  var tmpstr = ltrim(value);

  return rtrim(tmpstr);
}

// left trim
function ltrim(value) {

  while (1) {
    if (value.substring(0,1) != " ")
      break;
    value = value.substring(1, value.length);
  }

  return value;
}

// right trim
function rtrim(value) {

  while (1) {
    if (value.substring(value.length - 1, value.length) != " ")
      break;
    value = value.substring(0, value.length - 1);
  }

  return value;
}
function submit_cuscom_search()
{
	
	killGadget();

	var allowedzipchars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ";
		for(i=0; i<document.frm.zipcode.value.length; i++)
		{
			charone =document.frm.zipcode.value.charAt(i);
			if(allowedzipchars.indexOf(charone) =="-1")
			{
				alert("Please enter Valid ZIP code.")
				document.frm.zipcode.focus();
				return;
			}
		}
		if(trim(document.frm.zipcode.value) == "")
		{
			alert("Please enter ZIP code");
			document.frm.zipcode.focus();
			return;
		}
		if(document.frm.zipcode.value.length < 5 || document.frm.zipcode.value.length > 7)
		{
			alert("Please enter valid ZIP code");
			document.frm.zipcode.focus();
			return;
		}

		if(document.frm.subject.options[document.frm.subject.selectedIndex].value == "-1")
		{
		alert("Please Select Subject");
		document.frm.subject.focus();
		return;
		}

			document.frm.subprogramid.value="";
			document.frm.location.value="";
			document.frm.showzip.value="";

	if(document.frm.subject.options[document.frm.subject.selectedIndex].value == "online")
	{
		document.frm.subject.options[document.frm.subject.selectedIndex].value = "";
		document.frm.subject.options[document.frm.subject.selectedIndex].text = "All Subjects";
		var flagonline = "online";
		var postto = "http://college.us.com/indexo.php";
	}else{
		var postto = "http://college.us.com/index.php";
	}
			document.frm.action = postto;
			document.frm.method="post";
			document.frm.target = "new";
			document.frm.submit();
if(flagonline == "online")
	{
	document.frm.subject.options[document.frm.subject.selectedIndex].value = "online";
	document.frm.subject.options[document.frm.subject.selectedIndex].text = "Online Schools";
	}
	
}

function autoTab(id,count,nextid){
	if (id.value.length==count){
		if (nextid!="end") {
			document.getElementById(nextid).focus();
		}
	}
}	


// REWRITE THIS BIT 

function copyValue(triggerId,targetId,idFrom,idTo) {
	if (document.getElementById(triggerId).checked){
		document.getElementById(idTo).value = document.getElementById(idFrom).value;
	} else {
		document.getElementById(idTo).value = "";
		//setText(idto);
	}
}

function copyValue(triggerId,targetId,idAreaCodeFrom,idExchangeFrom,idLineFrom,idAreaCodeTo,idExchangeTo,idLineTo) {
	if (document.getElementById(triggerId).checked){
		document.getElementById(idAreaCodeTo).value = document.getElementById(idAreaCodeFrom).value;
		document.getElementById(idExchangeTo).value = document.getElementById(idExchangeFrom).value;
		document.getElementById(idLineTo).value = document.getElementById(idLineFrom).value;
	} else {
		document.getElementById(idAreaCodeTo).value = "";
		document.getElementById(idExchangeTo).value = "";
		document.getElementById(idLineTo).value = "";
		//setText(idto);
	}
}

