﻿
var g_CookieName;
if(g_CookieName == "undefined"){ g_CookieName = "Forbes"};

//CALL ONLOAD OF ALL PAGES EXCEPT REG PAGE
function window_onload_default(){
	GetUrlParameters();
}


//CALL ONLOAD OF REG PAGE
function window_onload_reg(){
	GetCookie(g_CookieName);
	GetUrlParameters();	
}

function GetUrlParameters() { 
	var cAffiliateKey = GetURLParamValue("AffiliateKey");
	var cAffiliateData = GetURLParamValue("AffiliateData");
		var cLog = cAffiliateKey + "^" + cAffiliateData.toString();
		SetCookie(g_CookieName,cLog, 2009, 12, 31);
	
} 

function GetURLParamValue(cParamName) 
{
  var cHRef = window.location.href;
  var iPos = cHRef.indexOf("?");
  if (iPos > -1)
    {
      cHRef = cHRef.substr(iPos+1);
      
      var aValues = cHRef.split("&");
      var aParamInfo;
      
      for (var iLup = 0; iLup < aValues.length; iLup++)
        {
          aParamInfo = aValues[iLup].split("=");
          if (aParamInfo && aParamInfo[0] == cParamName)
            return aParamInfo[1]; 
        }
    }
  
  return "";
}

function SetCookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var results = document.cookie.match ( name + '=(.*?)(;|$)' );
  if ( results ){
	 }else{
		  var cookie_string = name + "="+ value;
		  if ( exp_y )
		  {
			var expires = new Date ( exp_y, exp_m, exp_d );
			cookie_string += "; expires=" + expires.toGMTString();
		  }
 		 document.cookie = cookie_string; 
	 }
}

function GetCookie ( cookie_name )
{	
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results ){
  	var aLog = results[1].split("^");
		document.forms[0].AffiliateKey.value = aLog[0];
		document.forms[0].AffiliateData.value = aLog[1];
	}
}