
/* var companyid = ""; */

// Please see to it that the variable called companyid is being created and initiallised before calling this script.

var convertor = new Array("referrer","channel","creative","adkey","section","adgroup");
var cookies = "";
var pos = "";
var refId = "";
var start = 0;
var end = 0;

var xExpiration = new Date();
xExpiration.setTime(xExpiration.getTime()+(30*24*60*60*1000));//days*hours*minutes*sec*milsec

function intializeCookieRead()
{
alert("intializeCookieRead");
cookies = window.document.cookie;
pos = cookies.indexOf("refererIdCookie=");

if (pos >= 0) {
    start = pos + 16;
    end = cookies.indexOf(";",start);
    if (end == -1) {
      end = cookies.length;
    }
    refId = cookies.substring(start,end);
  //  alert("refId: "+refId);
  }
}
function CustomUpdate(customValue,refId)
{
	var im = new Image();
	if(window['refId'] != undefined)
	{
		  im.src = 'http://tr.regalix.com/tracking/goaltracking.jsp?custom='+customValue+'&refId='+refId;
	}
	else 
	{
	  im.src = 'http://tr.regalix.com/tracking/goaltracking.jsp?custom='+customValue;
	}
} 

function trimSpace(x)
{
  var emptySpace = / /g;
  var trimAfter = x.replace(emptySpace,"");
  return(trimAfter);

}

function queryString(queryString) {
  var queryObject = new Object();
  queryString = queryString.replace(/^.*\?(.+)$/,'$1');

  while ((pair = queryString.match(/([^=]+)=\'?([^\&\']*)\'?\&?/)) && pair[0].length) {
    queryString = queryString.substring( pair[0].length );

    if (/^\-?\d+$/.test(pair[2])) pair[2] = parseInt(pair[2]);
 
	queryObject[pair[1].toLowerCase()] = pair[2];
	
  }

  return queryObject;
}


var queryObj = queryString( location.search );

var strAgencyCode = queryObj.agencycode;

  if(window['strRefId'] == undefined){	 

		//var strRefId = queryObj.refid;
		
		 var strRefId = "n/a";

  }
  else{
	  
	  		if((strRefId == null) || (strRefId == "undefined") ||  trimSpace(strRefId).length == 0){
		  strRefId = "n/a";
			}
	  
	  }

if ((strAgencyCode == null) || (strAgencyCode == "undefined")){
  strAgencyCode = "n/a";
}

  if(window['custom3'] != undefined){	  
//    r += "&custom3="+custom3;
	    window.document.cookie = "regPageCookie="+custom3+"; expires="+xExpiration.toGMTString()+"; path=/";
  }

var agencyCodeList = new Array("rgx");
var trackingServer = "http://tr.regalix.com/tracking";

  for(i=0;i<agencyCodeList.length;i++){
    if(strAgencyCode.toLowerCase() == agencyCodeList[i]){
		
		      document.write('<scr'+
					 'ipt language="JavaScript" type="text/JavaScript" src="http://tr.regalix.com/tracking/referrerid.jsp?companyid='+companyid+'&logname='+logname+'"></scr'+
					 'ipt>');


	  break;
  }
}



//Function to assign referrer id to the eOfferCode/reffererid field in the registration form

var eOfferCode = "";

function eOfferAssign(formName,fieldName)
{

var cookiesLP = window.document.cookie;
var posLP = cookiesLP.indexOf("refererIdCookie=");

var startLP = 0;
var endLP = 0;
if (posLP >= 0) {
    startLP = posLP + 16;
    endLP = cookiesLP.indexOf(";",startLP);
    if (endLP == -1) {
      endLP = cookiesLP.length;
    }
    eOfferCode = cookiesLP.substring(startLP,endLP);

  }

document.write('<scr'+
				'ipt language="JavaScript" type="text/JavaScript">window.document.'+formName+'.'+fieldName+'.value=eOfferCode;'+
					 '</scr'+
					 'ipt>');

}