
/*
Campaign vars
Version 2.0 (RL)

Instuctions: 
The following variables can be set on the HTML page, before this JS file is called:

var strGEMID1 - in-page campaign code (Omniture)
var strGEMID2 - in-page internal campaign code (Omniture)
var strOFFER - in-page offer code
var strGEMIDAFF - in-page affiliate campaign code (legacy)

When one of these variables is set on the HTML page, they will overwrite any codes sent
in the URL query string (Eg ?gemid=900000000).
*/

var strDomain = ".gomastercard.com.au";	// Cookie domain
//var strDomain = ".au.money.ge.com"; // (staging)

// Check for campaign code
if (typeof(strGEMID1) != 'undefined' && strGEMID1 != "") {
	writeCookie('Src_GEMID1',60,strGEMID1);
} else {
	writeCookie('Src_GEMID1',60,getURLParam('gemid1'));
}
// Check for internal campaign code
if (typeof(strGEMID2) != 'undefined' && strGEMID2 != "") {
	writeCookie('Src_GEMID2',0,strGEMID2);
} else {
	writeCookie('Src_GEMID2',0,getURLParam('gemid2'));
}	
// Check for offer name
if (typeof(strOFFER) != 'undefined' && strOFFER != "") {
	writeCookie('Src_OFFER',0,strOFFER);
} else {
	writeCookie('Src_OFFER',0,getURLParam('offer'));
}

// Legacy???
if (typeof(strGEMIDAFF) != 'undefined' && strGEMIDAFF!="") {
	writeCookie('Src_GEMIDAFF',0,strGEMIDAFF);
} else {
	writeCookie('Src_GEMIDAFF',0,getURLParam('gemidaff'));
}

function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href.toLowerCase();
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?"));
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

	
function writeCookie(strName,strExpiry,strValue) {
	if (strValue != "") {
		if (strExpiry > 0) {
			var expdate = new Date();
			expdate.setDate(expdate.getDate()+strExpiry);
			document.cookie = strName + "=" + escape(strValue) + ";expires=" + expdate.toGMTString() + ";path=/ ;domain=" + strDomain;
		} else {
			document.cookie = strName + "=" + escape(strValue) + ";path=/ ;domain=" + strDomain;
		}
	}
}



function openApplication(params) {
	var theURL = "https://apply.gomastercard.com.au/eapps/ApplyRetail.faces?cardType=go&merchant=ge";
	var width = "622";
	var height = (screen.height && screen.width) ? (screen.height - 80) : 520;
	var screenY = screen.height;
	var screenX = screen.width;
	var topvar = 0;
	var leftvar = (screenX - width) / 2;
	// Check for additional params i.e. gem codes
	if (typeof(params) != "undefined") {
		theURL += (params.indexOf("&") !=-1) ? params : ("&"+params);
	}
 	
	if(!myWin || myWin.closed) {
		var myWin = window.open(theURL,'','resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,status=yes,top='+topvar+',left='+leftvar+',width='+width+',height='+height+'');
	} else {
		myWin.focus();
	}
}

// Legacy???
function MenuHover(Object){
document.getElementById(Object).className = document.getElementById(Object).className+" Active";
}

function MenuHoverOff(Object){
document.getElementById(Object).className = document.getElementById(Object).className.replace(" Active","");
document.getElementById(Object).className = document.getElementById(Object).className.replace(" Active","");
document.getElementById(Object).className = document.getElementById(Object).className.replace(" Active","");
document.getElementById(Object).className = document.getElementById(Object).className.replace(" Active","");
}

