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 voucher 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', 'https_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);
}

var blnAuthorizeSumbit = false;
function authorize() {
	if(checkBrowserInfo()) return;
	if(document.forms[0].authcode.value == '') {
		alert('You must enter a voucher code to proceed!');
		return;		
	}
	if(blnAuthorizeSumbit) return;
	getClientInfo();
	document.forms[0].action = switchPageProtocol('?cmd=authorize', 'https_page');
	blnAuthorizeSumbit = true;
	document.forms[0].submit();	
}

var blnLoginSubmit = false;
function validateLogin() {
	if(checkBrowserInfo()) return;
	
	if(!checkEmail(document.forms[0].username.value)) {		
			alert('Please enter a vaild email address to proceed!');
		return;
	}
			
	if(document.forms[0].pwd.value == '') {
		alert('You must enter a password to proceed!');	   
		return;	
	}
	if(blnLoginSubmit) return;
	getClientInfo();
	document.forms[0].action = switchPageProtocol('?cmd=validatelogin', 'https_page');	
	blnLoginSubmit = true;
	document.forms[0].submit();	
}

var blnActivateSubmit = false;
function activateNewUser() {
	if(checkBrowserInfo()) return;

	if(!checkEmail(document.forms[0].username.value)) {		
			alert('Please enter a vaild email address to proceed!');
		return;
	}
	if(blnActivateSubmit) return;
	getClientInfo();
	document.forms[0].action = switchPageProtocol('?cmd=activate', 'https_page');
	blnActivateSubmit = true;
	document.forms[0].submit();
}

function forgetPwd() {
	if(checkBrowserInfo()) return;
	getClientInfo();
	document.forms[0].action = switchPageProtocol('?cmd=forgetpwd', 'https_page');	
	document.forms[0].submit();		
}

function returnToLogin() {
	window.location = 'starttest.aspx?cmd=logout';
}

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 renewProduct() {
	window.location = "cart.aspx";		
}

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 browser = navigator.appName
                var ver = navigator.appVersion
                var thestart = parseFloat(ver.indexOf("MSIE"))+1
                var brow_ver = parseFloat(ver.substring(thestart+4,thestart+7))                               
var bAgent = window.navigator.userAgent; 
var bAppName = window.navigator.appName; 
var bMozIdx = bAgent.indexOf("Mozilla/");        
var skipPage = true;  
var bo=0, res=0, os=0, media=0;    

if(checkSB()) return false;
  
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

if ((browser=="Microsoft Internet Explorer") && (brow_ver > 5))
skipPage = false; //win ie6+

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('Netscape/8') >=0))
                                                                skipPage = false; //netscape 8
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 ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Gecko/2006') >=0))
                                                                skipPage = false; //future mozilla
else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Gecko/2007') >=0))
                                                                skipPage = false; //future mozilla
else if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Gecko/2008') >=0))
                                                                skipPage = false; //future mozilla
else if (bAgent.indexOf('Safari') >= 0)
skipPage = false; //mac safari

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
                 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
                 if (ffversion>=3)
                    skipPage = false;
                 else if (ffversion>=2)
                    skipPage = false;
                 else if (ffversion>=1)
                    skipPage = true;
                }

if ((bAppName.indexOf('Netscape') >= 0) && (bMozIdx >= 0) && (bAgent.indexOf('Netscape6') >=0))
                                                                skipPage = true;

if(skipPage) window.location = 'starttest.aspx?cmd=displayfile&file=browser';
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 = 'https://' + vNewUrl;
			break;
		case 'https_page':
			if(window.location.hostname == 'localhost' || readCookie('secureconn') != 'true') 				
				vNewUrl = 'https://' + 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() {
	if(itd.closed) {
		window.location = 'starttest.aspx?cmd=home';
		window.clearInterval(intervalID);
	} 
}

function cancelMonitoring() {
	window.clearInterval(intervalID);
}

function launchTest_(vLink, vTestName) {
	if(vLink.indexOf('resultid=') != -1)
		launchTest_normal(vLink, vTestName);
	else	
		window.location = 'info.aspx?cmd=time&testinfo=' + escape(vLink) + '&testname=' + escape(vTestName);
}

function isSB() {
                try {
			return top.external.IsSecureBrowser;
                }
                catch(e) {}
                return false;
}

function isMacSB() {
                try {
			return SecureBrowser.IsSecure();
                }
                catch(e) {}
                return false;
}

function checkSB() {
	if(window.navigator.userAgent.indexOf('Win') != -1) return isSB();
	else if(window.navigator.userAgent.indexOf('Mac') != -1) return isMacSB(); 
	else return false;
}


function downloadSecureBrowser() {
	window.location = 'starttest.aspx?cmd=displayfile&file=downloadbrowser_home&home=1';
}

function checklang(val, opid) {
	if(val != '') {
		document.getElementById('link_' + opid).style.display = '';
	} else {
		document.getElementById('link_' + opid).style.display = 'none';
	}
}

function launchTest(vLink, vTestName, opid) {


	if(document.getElementById('lang_' + opid)) {
		var objList = document.getElementById('lang_' + opid);
		var w = objList.selectedIndex;			
		var val = objList.options[w].value;
		vLink += '&userlang=' + val;
	}

	if(vTestName && vTestLaunched[vTestName]) return;

	if(checkSB()) {
		launchTestSecure(vLink, vTestName);
		return;		
	}

	var vRes = window.screen.width + 'x' + window.screen.height;
	var vColors = window.screen.colorDepth;	
	vLink = vLink + '&res=' + vRes + '&color=' + vColors;

	//if(arguments.length > 1) { startTest(vLink, vTestName); return; } //uncomment this line if start test requires option page	

	if(window.navigator.appName.indexOf('Netscape') != -1 && window.navigator.userAgent.indexOf('Mac') != -1)
		itd = window.open(vLink, null, 'toolbar=no,menubar=no,location=no,directories=no,screenX=0,screenY=0,width='+(window.screen.availWidth-20)+',height='+(window.screen.availHeight-40)+',fullscreen=yes');
	else if(window.navigator.appName.indexOf('Netscape') != -1)
		itd = window.open(vLink, null, 'toolbar=no,menubar=no,location=no,directories=no,screenX=0,screenY=0,width='+window.screen.availWidth+',height='+(window.screen.availHeight-20)+',fullscreen=yes');
	else if(window.navigator.userAgent.indexOf('Mac') != -1) { 
		itd = window.open(vLink, null, 'resizeable=yes');
		itd.resizeTo(window.screen.width, window.screen.height);
		itd.moveTo(0, 0);
	} else
		itd = window.open(vLink, null, 'toolbar=no,menubar=no,location=no,directories=no,fullscreen=yes');				

	if(itd == null) {
		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;
	intervalID = window.setInterval('checkTestWindow()', 200);
}

var testlaunched = false;

function launchTestSecure(vLink, vTestName) {

	if(testlaunched) return;

	testlaunched = true;
	
	var vRes = window.screen.width + 'x' + window.screen.height;
	var vColors = window.screen.colorDepth;	
	vLink = vLink + '&res=' + vRes + '&color=' + vColors + '&dupchk=true';
	window.location = vLink;	
}

function hideClose()
{

if(document.getElementById('close') == null) return;

var theBrowser = window.navigator.appName.toLowerCase();
var theAgent = window.navigator.userAgent.toLowerCase();
if (theAgent.match("firefox")&&theAgent.match("firefox/2.0"))
	{
	//alert(theAgent);
	//alert('2pointo');
	document.getElementById('close').style.display = "none";
	document.getElementById('close').style.visibility = "hidden";
	}
else if (theAgent.match("1.2.1"))	
	{
	document.getElementById('close').style.display = "none";
	document.getElementById('close').style.visibility = "hidden";
	}
else if (theAgent.match("1.3.1"))	
	{
	document.getElementById('close').style.display = "none";
	document.getElementById('close').style.visibility = "hidden";
	}
else
	{
	document.getElementById('close').style.display = "inline";
	document.getElementById('close').style.visibility = "visible";
	}
}
function ShowCloseButton() {

	var theAgent = window.navigator.userAgent.toLowerCase();
	//detect Mac OS X Secure Browser
	if (theAgent.match("mac os x") && theAgent.match("securebrowser")) {
		if(document.getElementById('MacOSXSB') == null) return;
		document.getElementById('MacOSXSB').style.display = 'inline';
		document.getElementById('MacOSXSB').style.visibility = 'visible';
	}
	//all other browsers else {
		if(document.getElementById('WindowDotClose') == null) return;			
		document.getElementById('WindowDotClose').style.display = 'inline';
		document.getElementById('WindowDotClose').style.visibility = 'visible';
	}
	
function hideClose()
{

	document.getElementById('close').style.display = "none";
	document.getElementById('close').style.visibility = "hidden";	
}

function closeWindow() {
var theBrowser = window.navigator.appName.toLowerCase();
//alert(theBrowser);
var theAgent = window.navigator.userAgent.toLowerCase();
//alert(theAgent);
if (theAgent.match("firefox"))
{
	if (theAgent.match("2.0"))
		{
		window.open('close.htm','_parent','');
		//alert('firefox2');
		//alert(theAgent);
		window.close();
		top.window.close()
		}
	else
		{
		window.open('close.htm','_parent','');
		alert('firefox1.0');
		//window.close();
		window.close()
		top.window.close()
		}	
}
else if (theAgent.match("mozilla"))
{
	if (theAgent.match("mac"))
			{
			if (theAgent.match("safari"))		
					{
					window.open('close.htm','_self','');
					//alert('safarimac');
					//window.close();
					window.close()
					}
			else		
					{
					window.open('close.htm','_parent','');
					//alert('mozzillamac');
					//window.close();
					window.close()
					}
			}		
	else
		{
			if (theAgent.match("1.7"))
				{
					window.open('','_parent','');
					//alert('mozzillawin17');
					//alert(theAgent);
					window.close();
					top.window.close()
				}
			else
				{
				window.open('','_self','');
				//alert('mozzillawin');
				//alert(theAgent);
				window.close();
				top.window.close()
				}		
		}	
}
else if (theAgent.match("explorer"))
{
//alert('IE');
window.open('close.htm','_self','');
//window.close();
top.window.close()
}
else
{
window.open('close.htm','_self','');
//alert('safari!!!')
//window.close();
top.window.close()
}
}


function ChangeDisplayLanguage(lang) {
       //window.location = window.location.href.replace('&loc', '&extra') + '&loc=' + lang;
   var locchange = replaceQS(window.location.href, 'loc', lang);
   window.location = locchange;
}


function replaceQS(url,param,value) {
    var re = new RegExp("([?|&])" + param + "=.*?(&|$)","i");
    if (url.match(re))
        return url.replace(re,'$1' + param + "=" + value + '$2');
    else if (url.indexOf("?") == -1)
        return url + '?' + param + "=" + value;
    else
        return url + '&' + param + "=" + value;
}


