
function PromotionPopup() {
	OpenWindow('/promotion_pages/current_promotions.aspx', 'promotion', '586', '244', 'no');
	return true;
}

function PerSessionPopup(url, name, width, height, props) {
	OpenWindow(url, name, width, height, props);
	return true;
}

function OpenDetailsWindow (sUrl) {	
	OpenWindow(sUrl, 'Details', 635, 490, 'yes');
}

function OpenPerformanceAnalyzerWindow (sUrl, bSubmit) {
	OpenWindow (sUrl, 'MadOnionWindow', 594, 505, 'yes');
	if (bSubmit) {
		var SystemSelectionObj = GetObjRef(document.PageControlForm, ":SystemSelection");				
		SystemSelectionObj.value = GetSystemSelection();		 
		document.forms[0].submit ();
	}	
}

function OpenWindow(sUrl, sWinName, dWidth, dHeight, bShowScroll, winResize)
{   	   
   var winl = (screen.width - dWidth) / 2;
   var wint = (screen.height - dHeight) / 2;
   var winprops = 'height=' + dHeight + ',width=' + dWidth + ',top=' + wint + ',left=' + winl + ',scrollbars=' + bShowScroll + ', resizable=' + winResize;
   var win = window.open(sUrl, sWinName, winprops);   
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function Round (dPrice, nDecimal)
{	
	var dPowerOfTen = Math.pow(10, nDecimal);

	var dTempPrice = dPrice * dPowerOfTen;
	var dRoundedPrice = Math.floor (dTempPrice);
	var dFloorRemainder = dTempPrice - dRoundedPrice;

	if (dFloorRemainder > 0.5 || (dFloorRemainder == 0.5 && dRoundedPrice % 2 != 0))
		dRoundedPrice += 1;

	return dRoundedPrice / dPowerOfTen;
}

function RoundPrice (dPrice, nDecimal)
{		
	dPrice = Round (dPrice, nDecimal);
	var sDig = "000000000";
	var sTempValue = dPrice.toString();	
	if (nDecimal > 0) {
		var nPos = sTempValue.indexOf(".");
		if (nPos == -1) {
			sTempValue += ".";
			nPos = sTempValue.length - 1;
		}		
		var nDec = sTempValue.length - nPos - 1;	
		sTempValue += sDig.substr(0, nDecimal - nDec);
	}					
	return sTempValue;	
}

function FormatCurrency (nValue, sCurrencyFormat)
{	
	var sTempValue = RoundPrice (Math.abs (nValue), 2);	
	var sRemainder = "";
	if (sTempValue.match (/\./) != null) {
		sRemainder = sTempValue.replace (/^.*\./, '');
		sTempValue = sTempValue.replace (/\..*$/, '');
	}		

	var sThousands = "";	
	if (sTempValue.length > 3)
		sThousands = sTempValue.replace (/^(\d+)(\d\d\d)$/, '$1');		
	var sHundreds = sTempValue.substr (sThousands.length, sTempValue.length);		
	if (!sThousands.length)
		sCurrencyFormat = sCurrencyFormat.replace (/XXX.*YYY/, "YYY");
				
	sCurrencyFormat = sCurrencyFormat.replace (/XXX/, sThousands);			
	sCurrencyFormat = sCurrencyFormat.replace (/YYY/, sHundreds);			
	sCurrencyFormat = sCurrencyFormat.replace (/ZZ/,  sRemainder);
	
	if (nValue < 0)
		sCurrencyFormat = "-" + sCurrencyFormat;		
	return sCurrencyFormat;			
}

function GetObjRef(form, objname) 
{
	var objref = null;	
	for (i=0; i < form.elements.length; i++) {
		if (form.elements[i].name.indexOf(objname) != -1) {
			objref = form.elements[i];
			break;
		}		
	}
	return objref;
}

function GetDocumentObject (sId) {       
    var statement = '';	
    
    if (document.all) 
	  statement = "var obj = document.all['" + sId + "']";	     
    else if (document.getElementById)           
	  statement = "var obj = document.getElementById('" + sId + "')"; 
    
	try {
	    eval(statement); 
	    return obj;
	} catch(e) {
	} 
	
    return null;	
}

function CalculateFinancePrice (dPrice, dAPR, nMonths) {
	var nMinValue = Round (dPrice * 3 / 100, 0);
    //var nMonthlyAmount = Math.round (dPrice * ((dAPR / 1200) / (1 - (1 / (Math.pow (1 + (dAPR / 1200), nMonths))))));                          	        
    //nMonthlyAmount = Math.max (nMonthlyAmount, nMinValue);
    //return nMonthlyAmount.toString();
    return nMinValue.toString();
}

function SetLayerText (sLayerId, sText) 
{       		
	sText = sText.replace (/\n/g, "<BR>");
	sText = sText.replace (/\'/g, "\\\'");
			
    var sStatement;
    if (document.all) 
	  sStatement = "document.all['" + sLayerId + "'].innerHTML = '" + sText + "';";	     
    else if (document.getElementById)           
	  sStatement = "document.getElementById('" + sLayerId + "').innerHTML = '" + sText + "';"; 
                        
	try {	    
	    eval (sStatement); 	    	    
	} catch (e) {	
	}
}

/*********************************************************************************/
/* NETSCAPE FIX RESIZE BUG NS4 */
/*********************************************************************************/
function WM_netscapeCssFix() {
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth ||
        document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
     document.location = document.location;
    }
}

function WM_netscapeCssFixCheckIn() {
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
       document.WM = new Object;
       }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
       document.WM.WM_netscapeCssFix = new Object;
       document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
       document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
       }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn();


/*********************************************************************************/
/* COOKIE CODE */
/*********************************************************************************/
function setCookie(szName, szValue, szExpires, szPath, szDomain, bSecure)
{
 	var szCookieText = 	   escape(szName) + '=' + escape(szValue);
	szCookieText +=	 	   (szExpires ? '; EXPIRES=' + szExpires.toGMTString() : '');
	szCookieText += 	   (szPath ? '; PATH=' + szPath : '');
	szCookieText += 	   (szDomain ? '; DOMAIN=' + szDomain : '');
	szCookieText += 	   (bSecure ? '; SECURE' : '');
	
	document.cookie = szCookieText;
}

function getCookie(szName)
{
 	var szValue =	  null;
	if(document.cookie)	   //only if exists
	{
       	var arr = 		  document.cookie.split((escape(szName) + '=')); 
       	if(2 <= arr.length)
       	{
           	var arr2 = 	   arr[1].split(';');
       		szValue  = 	   unescape(arr2[0]);
       	}
	}
	return szValue;
}

function deleteCookie(szName)
{
 	var tmp = 	  			 	 getCookie(szName);
	if(tmp) 
	{ setCookie(szName,tmp,(new Date(1))); }
}

function stopError() {return true;}
window.onerror=stopError;
/*********************************************************************************/
