function imgOver(theName) {
	document.getElementById(theName).src="programs/" + vPPath + "/images/" + theName + "_over.gif";
}

function imgOrig(theName) {
	document.getElementById(theName).src="programs/" + vPPath + "/images/" + theName + ".gif";
}

function imgDown(theName) {
	document.getElementById(theName).src="programs/" + vPPath + "/images/" + theName + "_down.gif";
}

function imgUp(theName) {
	document.getElementById(theName).src="programs/" + vPPath + "/images/" + theName + "_over.gif";
}

function arrowOver(theName) {
	document.getElementById(theName).src="programs/" + vPPath + "/images/arrow_over.gif";
}

function arrowOrig(theName) {
	document.getElementById(theName).src="programs/" + vPPath + "/images/arrow.gif";
}

function authCodeUsedMsg() {
	document.getElementById('msg').innerHTML = '<b>Your authorization number (' + readCookie('authcode') + ') was activated while you were entering your profile. Please check your number, and try again. If you believe your number is correct, please contact tech support.</b>';		
}

function multiUserMsg() {
	document.getElementById('msg').innerHTML = '<b>Another login was detected to this account. Only one user can log into an account at the same time. This typically happens when a person logs into from a different machine without logging out of the original machine. It can also happen if another user has the same login information. If you are not sure why you got this message, please notify tech support.</b>';
}

function supportEmail() {
	window.location = switchPageProtocol('?cmd=supportemail', 'http_page');
}

function setTextInputFocus() {
	for(var i=0; i < document.forms[0].elements.length; i++) {
		var objElement = document.forms[0].elements[i];
		if(objElement.type == "text" || objElement.type == "password") {
			objElement.focus();
			break;	
		}
	}
}

function popWin() {
	var url_page, x, y, window_width, window_height;
	if(arguments.length == 1) {
		url_page = arguments[0];
		window_width = window.screen.width * 0.7;
		window_height = window.screen.height * 0.6;
	} else if(arguments.length == 3) {
		url_page = arguments[0];
		window_width = arguments[1];
		window_height = arguments[2];		
	} else {
		alert('Invalid parameters!');
		return;
	}	
	x = (window.screen.width - window_width) / 2 
	y = (window.screen.height - window_height) / 2;			
	var pWin = window.open(url_page, null, 'toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,resizable=1,width=' + window_width + ',height=' + window_height + ',top=' + y + ',left=' + x);
	if(window.navigator.userAgent.indexOf('Mac') != -1) pWin.resizeTo(window_width, window_height);
}

function forgetPwd() {
	if(checkBrowserInfo()) return;
	getClientInfo();
	document.forms[0].action = switchPageProtocol('?cmd=forgetpwd', 'http_page');	
	document.forms[0].submit();		
}

function returnToLogin() {
	window.location = switchPageProtocol('?cmd=sessionlogout', 'http_page');	
}

function checkEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

function getClientInfo() {
	var vRes = window.screen.width + 'x' + window.screen.height;
	var vColors = window.screen.colorDepth;	
	document.forms[0].sysinfo.value = escape('<VideoResolution>' + vRes + '</VideoResolution><NumberofColors>' + vColors + '</NumberofColors>');
	var now = new Date(); 
	document.forms[0].timeoffset.value = now.getTimezoneOffset();
}

function checkBrowserInfo() {			
	var bAgent = window.navigator.userAgent; 
	var bAppName = window.navigator.appName; 
	var bMozIdx = bAgent.indexOf("Mozilla/");	
	var skipPage = true;	
	if ((bAppName.indexOf('Explorer') >= 0) && (bAgent.indexOf('MSIE 5') >= 0) && (bAgent.indexOf('Win') >= 0))
		skipPage = false; //win ie5 
	else if ((bAppName.indexOf('Explorer') >= 0) && (bAgent.indexOf('MSIE 6') >= 0) && (bAgent.indexOf('Win') >= 0))
		skipPage = false; //win ie6
	else if ((bAppName.indexOf('Explorer') >= 0) && (bAgent.indexOf('MSIE 7') >= 0) && (bAgent.indexOf('Win') >= 0))
		skipPage = false; //win ie7
	else if ((bAppName.indexOf('Explorer') >= 0) && (bAgent.indexOf('MSIE 5') >= 0) && (bAgent.indexOf('Mac') >= 0))
		skipPage = false; //mac ie5
	else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Netscape/7') >=0))
		skipPage = false; //netscape 7
	else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Netscape6') >=0))
		skipPage = true;  //netscape 6
	else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Gecko/2002') >=0))
		skipPage = false; //mozilla 1.0
	else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Gecko/2003') >=0))
		skipPage = false; //mozilla 1.0 or above
	else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Gecko/2004') >=0))
		skipPage = false; //future mozilla
	else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Gecko/2005') >=0))
		skipPage = false; //future mozilla
	else if (bAgent.indexOf('Safari') >= 0)
		skipPage = false; //mac safari
	
	if(skipPage) window.location = 'templates_starttest/browser.htm';
	return skipPage;		
}

function switchPageProtocol(vNextCmd, vHttpType) {
	var vNewUrl = window.location.host + window.location.pathname;
	vNewUrl = vNewUrl.replace('setuptest.aspx', 'starttest.aspx');
	switch(vHttpType) 
	{
		case 'http_page':
			vNewUrl = 'http://' + vNewUrl;
			break;
		case 'https_page':
			if(window.location.hostname == 'localhost' || readCookie('secureconn') != 'true') 				
				vNewUrl = 'http://' + vNewUrl;
			else
				vNewUrl = 'https://' + vNewUrl;
			break;
	}
	return vNewUrl + vNextCmd;
}

function readCookie(CookieName) {
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
  var CookiePieces
  var ReturnValue = "";
  var x = 0;

  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {

    CookiePieces = CookieSet[x].split ('=');

    if (CookiePieces[0].substring (0,1) == ' ') {
      CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
    }

    if (CookiePieces[0] == CookieName) {
      ReturnValue = CookiePieces[1];
    }

  }
   return ReturnValue;
}

var itd;
var intervalID; 
var vTestLaunched = new Array(); 
function checkTestWindow() {
try {
	if(itd.closed) {
		window.clearInterval(intervalID);	
		if(!blnSessionTestLaunched)
			window.location = 'starttest.aspx?cmd=sessionhome';
		else
			window.location = 'starttest.aspx?cmd=sessionlogout';		
	} 
} catch(e) {
		window.clearInterval(intervalID);	
		if(!blnSessionTestLaunched)
			window.location = 'starttest.aspx?cmd=sessionhome';
		else
			window.location = 'starttest.aspx?cmd=sessionlogout';	
}
}

function cancelMonitoring() {
	window.clearInterval(intervalID);
}

function runTestLocal( testUrl, installServer, mimeType )
{
    var minVersion = 1;
    var installName = '';
    var confirmMessage = '';

    // Get optional variables    
    if( arguments.length > 3 )
	    minVersion = arguments[3];
    if( arguments.length > 4 )
	    installName = arguments[4];
    if( arguments.length > 5 )
	    confirmMessage = arguments[5];

	if( !isDriverLoaded( mimeType, minVersion ) )
	{
		//installDriver( installServer, mimeType, installName, confirmMessage );
		alert('The Secure Browser is not currently installed on your system or does not meet the minimum version required. \n\n Please contact your test administrator for installing the secure browser.');
		return false;
	}
	else 
	{
		window.location.replace( testUrl );
		return true;
	}
    
    return false;
}

function isSBHybrid()

{
                try {
                                return top.external.IsHybridSecureBrowser;
                }
                catch(e) {}
                return false;
}

var blnSessionTestLaunched = false;
function launchTest(vLink, vTestName) {

	if(vTestName && vTestLaunched[vTestName]) return;
	if(blnSessionTestLaunched) return;

	var vRes = window.screen.width + 'x' + window.screen.height;
	var vColors = window.screen.colorDepth;	
	vLink = vLink + '&res=' + vRes + '&color=' + vColors + '&dupchk=true';

	//if(arguments.length > 1) { startTest(vLink, vTestName); return; } //uncomment this line if start test requires option page	

	var dr_version = 11;
	if(vTestName && vTestName.indexOf("2008") != -1) dr_version = 1;
	else if(vTestName && vTestName.indexOf("2009") != -1) dr_version = 12;
	else if(vTestName) dr_version = 11;
	else { 
		if(dr11) dr_version = 11; 
		else if(dr12) dr_version = 12; 
		else dr_version = 1;
	}

	var pos = vLink.indexOf("DR=");
	if(pos > 0) {
		var DR = parseInt(vLink.substr(pos+3));
		if(DR > 0) {
			vLink += '&ext=' + escape(findExt(DR)) + '&mim=' + escape(findMimType(DR));
			runTestLocal(vLink, 'http://driverinstalls.testsys.com', findMimType(DR), dr_version, findInstallName(DR));	
			return;
		}
	}

	if(isSBHybrid()) {
		window.location = vLink;			
		return;
	}

	var vExtraOption = ',resizable=1';

	itd = window.open(vLink, null, 'top=0,left=0,width=' + (window.screen.width-100) + ',height=' + (window.screen.height-100) + ',toolbar=no,menubar=no,location=no,directories=no'+vExtraOption);				
			
	if(itd == null) {
		blnSessionTestLaunched = false;	
		alert("Your browser has pop-up blocker enabled, this can prevent the test window from opening properly. If your test did not launch, disable your pop-up blocker and try again.");
		return;
	}
	
	if(vTestName) vTestLaunched[vTestName] = true;
	blnSessionTestLaunched = true;
	intervalID = window.setInterval('checkTestWindow()', 200);
}


function findMimType(DR) {
	if(drlist && mimlist) {
		var tmpDrlist = drlist.split("|");
		var tmpMimlist = mimlist.split("|");
		for(var i=0; i < tmpDrlist.length; i++) {
			if(tmpDrlist[i] == DR) return tmpMimlist[i];
		}
	}
	return '';	
}

function findInstallName(DR) {
	if(drlist && instlist) {
		var tmpDrlist = drlist.split("|");
		var tmpInstlist = instlist.split("|");
		for(var i=0; i < tmpDrlist.length; i++) {
			if(tmpDrlist[i] == DR) return tmpInstlist[i];
		}
	}
	return '';
}

function findExt(DR) {
	if(drlist && instlist) {
		var tmpDrlist = drlist.split("|");
		var tmpExtlist = extlist.split("|");
		for(var i=0; i < tmpDrlist.length; i++) {
			if(tmpDrlist[i] == DR) return tmpExtlist[i];
		}
	}
	return '';
}

function deleteTest(vLink) {
	var msg = 'Are you sure you want to delete this in-progress test? This is a permanent delete, and all answers will be lost.';
	if(confirm(msg)) window.location = vLink;
}

function startTest(vLink, vTestName) {
	vLink = vLink.replace('setuptest.aspx?', '&');
	window.location = 'examoptions.aspx?test=' + escape(vTestName) + vLink;
}