// <!-- Version=3.00 Date=07/19/06 Name=Common.js -->
// <!-- Contains common JS functions -------------->
// <!-- Copyright Learn It Solutions 2006 -------------->

//***************************************************************
// get cookie value. return null if not found
function getCookie (name) {
  var dc=unescape(document.cookie);
  var arg = name + "=";
  var alen = arg.length; 
  var clen = dc.length; 
  var i = 0; 
  while (i < clen) {
    var j = i + alen; 
      if (dc.substring(i, j) == arg) 
        return getVal (dc, j, ";"); 
      i = dc.indexOf(" ", i) + 1; 
      if (i == 0) break; 
    }
  return null; 
}
// Used in getCookie
function getVal (passedstring, offset, delim) {	
  var endstr = passedstring.indexOf(delim, offset); 
  if (endstr == -1) 
    endstr = passedstring.length; 
  return unescape(passedstring.substring(offset, endstr)); 
}

// Create a session cookie in JS
function setCookie (name, value, path, domain) {
  var today = new Date();
  var expires;
  document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "");
}

// Read querystrings in JS
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
  return null;
}

//check for cookie - if not present, redirect to LearnItCampus home
function CheckForCookie()
{
	if (getCookie('company')==null)
	{
		document.location='http://www.learnitcampus.com';	
	}
}

function disp(url, dwidth, dheight) 
{
	qpopBox = window.open(url,'Help', 'width='+dwidth+',height='+dheight+',resizable,scrollbars');
}


function StudentRegistration(hostLocation, CompanyName)
{	  
	//forward to correct registration page, based on Campus version (default is V2)
	switch(CompanyName)
	{
	
	//Delaware Safety Campus
	case "delawaresafety":
		gotosecure('PortalSystem/Education/campus_registration.asp?HostLoc='+hostLocation+'&company='+ CompanyName);
		break;    
		
	//AMIG Campus
	case "amig":
		gotosecure('PortalSystem/Education/campus_registration.asp?HostLoc='+hostLocation+'&company='+ CompanyName);
		break;
		
	//NSC Campus
	//case "nsc":
	//	gotosecure('PortalSystem/Education/campus_registration.asp?HostLoc='+hostLocation+'&company='+ CompanyName);
	//	break;
		
	//WZ Campus
	//case "wz":
	//	gotosecure('PortalSystem/Education/campus_registration.asp?HostLoc='+hostLocation+'&company='+ CompanyName);
	//	break;
		
	//LP University
	case "lpuniversity":
		gotosecure('PortalSystem/Education/campus_registration.asp?HostLoc='+hostLocation+'&company='+ CompanyName);
		break;			
				
	
	//All others (new campus version) forward to Authorization Key page first							    			
	default:

		gotosecure('PortalSystem/Education/campus_validate_key.asp?HostLoc='+hostLocation+'&company='+ CompanyName);
		
	} 		
}   