function RObj(ea){var LS="";var QS=new Object();var un="undefined";var f="function";var n="number";var r="string";var e1="ERROR:Index out of range in\r\nRequest.QueryString";var e2="ERROR:Wrong number of arguments or invalid property assignment\r\nRequest.QueryString";var e3="ERROR:Object doesn't support this property or method\r\nRequest.QueryString.Key";function Err(arg){if(ea)alert("Request Object:\r\n"+arg)};function URID(t){var d="";if(t){for(var i=0;i<t.length;++i){var c=t.charAt(i);d+=(c=="+"?" ":c);};};return unescape(d);};function OL(o){var l=0;for(var i in o){if(typeof(o[i])!=f) l++;};return l;};function AK(key){var auk=true;for(var u in QS){if(typeof(QS[u])!=f&&u.toString().toLowerCase()==key.toLowerCase()){auk=false;return u;}};if(auk){QS[key]=new Object();QS[key].toString=function(){return TS(QS[key])};QS[key].Count=function(){return OL(QS[key])};QS[key].Count.toString=function(){return OL(QS[key]).toString()};QS[key].Item=function(e){if(typeof(e)==un) return QS[key];else {if(typeof(e)==n){var a=QS[key][Math.ceil(e)];if(typeof(a)==un) Err(e1+"(\""+key+"\").Item("+e+")");return a;}else Err("ERROR:Expecting numeric input in\r\nRequest.QueryString(\""+key+"\").Item(\""+e+"\")");}};QS[key].Item.toString=function(e){if(typeof(e)==un) return QS[key].toString();else {var a=QS[key][e];if(typeof(a)==un) Err(e1+"(\""+key+"\").Item("+e+")");return a.toString();};};QS[key].Key=function(e){var t=typeof(e);if(t==r){var a=QS[key][e];return(typeof(a)!=un&&a&&a.toString()?e:"");}else Err(e3+"("+(e?e:"")+")");};QS[key].Key.toString=function(){return un};};return key};function AVTK(key,val){if(key!=""){var key=AK(key);var l=OL(QS[key]);QS[key][l+1]=val;}};function TS(o){var s="";for(var i in o){var ty=typeof(o[i]);if(ty=="object") s+=TS(o[i]);else if(ty!=f) s+=o[i]+", ";};var l=s.length;if(l>1)return(s.substring(0,l-2));return(s==""?un:s);};function KM(k,o){var k=k.toLowerCase();for(var u in o){if(typeof(o[u])!=f&&u.toString().toLowerCase()==k) return u;};}if(window.location&&window.location.search){LS=window.location.search;var l=LS.length;if(l>0){LS=LS.substring(1,l);var preAmpAt=0;var ampAt=-1;var eqAt=-1;var k=0;var skip=false;for(var i=0;i<l;++i){var c=LS.charAt(i);if(LS.charAt(preAmpAt)=="="||(preAmpAt==0&&i==0&&c=="=")) skip=true;if(c=="="&&eqAt==-1&&!skip) eqAt=i;if(c=="&"&&ampAt==-1){if(eqAt!=-1) ampAt=i;if(skip) preAmpAt=i+1;skip=false;};if(ampAt>eqAt){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,ampAt)));preAmpAt=ampAt+1;eqAt=ampAt=-1;++k;};};if(LS.charAt(preAmpAt)!="="&&(preAmpAt!=0||i!=0||c!="=")){if(preAmpAt!=l){if(eqAt!=-1) AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,l)));else if(preAmpAt!=l-1) AVTK(URID(LS.substring(preAmpAt,l)),"");};if(l==1) AVTK(LS.substring(0,1),"");};};};var TC=OL(QS);if(!TC) TC=0;QS.toString=function(){return LS.toString()};QS.Count=function(){return(TC?TC:0)};QS.Count.toString=function(){return(TC?TC.toString():"0")};QS.Item=function(e){if(typeof(e)==un) return LS;else {if(typeof(e)==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])!=f&&++c==e) return QS[i];};Err(e1+"().Item("+e+")");}else return QS[KM(e,QS)];};return un;};QS.Item.toString=function(){return LS.toString()};QS.Key=function(e){var t=typeof(e);if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])!=f&&++c==e) return i;}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof(a)!=un&&a&&a.toString()?e:"");}else Err(e2+"().Key("+(e?e:"")+")");Err(e1+"().Item("+e+")");};QS.Key.toString=function(){Err(e2+"().Key");};this.QueryString=function(k){if(typeof(k)==un) return QS;else {var k=KM(k,QS);if(typeof(QS[k])==un){t=new Object();t.Count=function(){return 0};t.Count.toString=function(){return "0"};t.toString=function(){return un};t.Item=function(e){return un};t.Item.toString=function(){return un};t.Key=function(e){Err(e3+"("+(e?e:"")+")");};t.Key.toString=function(){return un};return t;}if(typeof(k)==n) return QS.Item(k);else return QS[k];}};this.QueryString.toString=function(){return LS.toString();};this.QueryString.Count=function(){return(TC?TC:0)};this.QueryString.Count.toString=function(){return(TC?TC.toString():"0")};this.QueryString.Item=function(e){if(typeof(e)==un) return LS.toString();else {if(typeof(e)==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])!=f&&++c==e) return QS[i];};Err(e1+".Item("+e+")");}else return QS[KM(e,QS)];}if(typeof(e)==(n)) Err(e1+".Item("+e+")");return un;};this.QueryString.Item.toString=function(){return LS.toString()};this.QueryString.Key=function(e){var t=typeof(e);if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])=="object"&&(++c==e)){return i;}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof(a)!=un&&a&&a.toString()?e:"");}else Err(e2+".Key("+(e?e:"")+")");Err(e1+".Item("+e+")");};this.QueryString.Key.toString=function(){Err(e2+".Key");};this.Version=1.2;this.Author="Andrew Urquhart (www.andrewu.co.uk)";};var Request=new RObj(false);

function Left(str, n){
 if (n <= 0)
     return "";
 else if (n > String(str).length)
     return str;
 else
     return String(str).substring(0,n);
     }
     
function tracking(){
	
var nbs_t = " border='0' height='1' width='1' alt=''>";
refer = escape(document.referrer.toLowerCase());
if (refer.length != 0) {
	var ComingFrom	= Request.QueryString("ls");
	if (ComingFrom == 'undefined') ComingFrom = '';
		var ComingFrom2	= Request.QueryString("gemid1");
	if (ComingFrom2 == 'undefined') ComingFrom2 = '';	
		if ((refer.indexOf("127.0.0.1") < 0) && (ComingFrom =='') && (ComingFrom2 ==''))  {

			var testrefer = new Array(34);
			var lengthrefer = new Array(34);

			testrefer[0] = 'http://www.google';
			testrefer[1] = 'http://rds.yahoo.com';
			testrefer[2] = 'http://search.msn';
			testrefer[3] = 'http://www.qualigo';
			testrefer[4] = 'http://av.rds.yahoo.com';
			testrefer[5] = 'http://www.exalead';
			testrefer[6] = 'http://www.ask.com';
			testrefer[7] = 'http://www.mozbot';
			testrefer[8] = 'http://www.accoona';
			testrefer[9] = 'http://www.noxtrum.com';
			testrefer[10] = 'http://noxtrum.com';
			testrefer[11] = 'http://search.yahoo.com';
			testrefer[12] = 'http://search.live.com';
			testrefer[13] = 'http://www.excite';
			testrefer[14] = 'http://search-dyn.tiscali';
			
			testrefer[15] = 'http://fr.wrs.yahoo.com';
			testrefer[16] = 'http://vachercher.lycos.fr';
			testrefer[17] = 'http://www.recherche.aol.fr';
			testrefer[18] = 'http://dh.search.ke.voila.fr';
			testrefer[19] = 'http://recherche.club-internet.fr';
			testrefer[20] = 'http://fr.ask.com';
			testrefer[21] = 'http://fr.search.yahoo.com';
			testrefer[22] = 'http://search.ke.voila.fr';


			lengthrefer[0] = '17';
			lengthrefer[1] = '20';
			lengthrefer[2] = '17';
			lengthrefer[3] = '18';
			lengthrefer[4] = '23';
			lengthrefer[5] = '18';
			lengthrefer[6] = '18';
			lengthrefer[7] = '17';
			lengthrefer[8] = '18';
			lengthrefer[9] = '22';
			lengthrefer[10] = '18';
			lengthrefer[11] = '23';
			lengthrefer[12] = '22';
			lengthrefer[13] = '17';
			lengthrefer[14] = '25';
			
			lengthrefer[15] = '23';
			lengthrefer[16] = '26';
			lengthrefer[17] = '27';
			lengthrefer[18] = '28';
			lengthrefer[19] = '33';
			lengthrefer[20] = '17';
			lengthrefer[21] = '26';
			lengthrefer[22] = '25';

			
			for (i=0; (i<testrefer.length)&&(testrefer[i]!=null); i++)
			{
				if (Left(document.referrer, lengthrefer[i]) == testrefer[i])
					{									
									var ima = document.location.protocol + '//stats.searchtrack.net/rec.aspx?PU=CLIC&CLI_ID=101271&SIT_ID=13749&ZONE_ID=1&NREF='+refer;
									document.write('<IMG SRC='+ima+nbs_t);
					}
			}
		}
	}
}


/****************************/
/*****      cookie tracking    *****/                                                            
/****************************/
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
	var date = new Date();
	fixDate(date);
	date.setTime(date.getTime()+(3*60*60*1000));		
	var curCookie = name + "=" + escape(value) +
      ("; expires=" + date.toGMTString()) +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
//  alert(curCookie)
  document.cookie=curCookie+";path=/;domain=.gemoneybank.fr;";
 // document.cookie=curCookie+";expires=Monday, 04-Apr-2010 05:00:00 GMT;domain=172.20.69.97;";
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


function showCookie_origine()
{
	alert(getCookie("origine"));
}

function showCookie_ref()
{
	alert(getCookie("ref"));
}

function showCookie_refLibre()
{
	alert(getCookie("RefLibre"));
}

function redirectURL(url)
{
	//change this depending on staging or production destination
	var formURL = 'https://www.gemoneybank.fr';
	var origine = getCookie("origine");
	var ref = getCookie("ref");
	var RefLibre = getCookie("RefLibre");
	var finalURL =formURL+url+"&Origine="+origine+"&Ref="+ref+"&RefLibre="+RefLibre;
	//alert("redirecting to " + finalURL);
	window.location = finalURL;
}

function redirectParamURL(param1,param2,url)
{
 var origine = getCookie("origine");
 var ref = getCookie("ref");
// alert(origine+" >> "+ref+" >>  "+url);
 if(param1 != '' && param2 != '')
 {
	var finalURL =url+"?"+param1+"="+origine+"&"+param2+"="+ref;
 }
 else
 {
	var finalURL =url+"?"+param1+"="+origine;
 }
//alert("redirecting to " + finalURL);


 window.location = finalURL;
}


//Grab Values and set cookies
var pageUrl = document.location.href; 

 
    if(pageUrl.indexOf("?") != -1) 
    { 
    	var strPagePara = pageUrl.split("?")[1]; 
    	var strMerchantCode = strPagePara.split("&")[0];
    	var strBannerCode = strPagePara.split("&")[1];
		var strRefLibreCode = strPagePara.split("&")[2];
    	//alert("Route:"+strMerchantCode+"\nBanner Code:"+strBannerCode);
    	setCookie('origine', strMerchantCode); 
    	setCookie('ref', strBannerCode); 
		setCookie('RefLibre', strRefLibreCode); // Change default value if needed
    	
    } 
    else // if no referrer is set, set default referrers
    { 
    	if(getCookie('origine')=="" || getCookie('ref')== null) 
    	{ 
    		setCookie('origine', 'wu2Dq_sfGlw'); // Change default value if needed
    		setCookie('ref', 'GEMB1S'); // Change default value if needed
			setCookie('RefLibre', 'none'); // Change default value if needed
			
			
    		//alert("Route: 1000"+"\nBanner Code:"+strBannerCode);
    	} 
    }
