// ################################################################
// Campaign Scripts
// 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 = ".gemoney.com.au";	// Enter top level domain here
//var strDomain = ".au.money.ge.com"; // Staging

if (typeof(strGEMID1) != 'undefined' && strGEMID1 != "") {
	writeCookie('Src_GEMID1',60,strGEMID1);
} else {
	writeCookie('Src_GEMID1',60,getURLParam('gemid1'));
}

if (typeof(strGEMID2) != 'undefined' && strGEMID2 != "") {
	writeCookie('Src_GEMID2',0,strGEMID2);
}else {
	writeCookie('Src_GEMID2',0,getURLParam('gemid2'));
}	

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;
		}
	}
}



// End Campaign Scrripts
// ###########################################################################

function openApplication(product) {
	var url = "";
	var width = "622";
	var screenY = screen.height;
	var screenX = screen.width;
	var topvar = 0;
	var leftvar = (screenX - width) / 2;
	
	if (screen.height && screen.width) {
		height = screen.height - 80;
	} else {
		height = 520;
	}
	
	switch(product) {
		case "lowrate":
			url = "https://apply.gemoney.com.au/eapps/Apply.faces?cardType=lowrate";
		break;
	    case "source":
			url = "https://apply.gemoney.com.au/eapps/Apply.faces?cardType=source";
		break;
		case  "myercard":
			url = "https://apply.gemoney.com.au/eapps/Apply.faces?cardType=myer"; 
		break;
		case "myervisa":
			url = "https://apply.gemoney.com.au/eapps/Apply.faces?cardType=myervisa";
		break;
		case "eco":
			url = "https://apply.gemoney.com.au/eapps/Apply.faces?cardType=eco"; 
		break;
		case "wizard":
			url = "https://apply.gemoney.com.au/eapps/Apply.faces?cardType=wizard";
		break;
		case "go":
			url = "https://apply.gomastercard.com.au/eapps/ApplyRetail.faces?cardType=go";
		break;
		case "gobusiness":
			url = "https://apply.gomastercard.com.au/eapps/ApplyRetail.faces?cardType=gobusiness"; 
		break;
		case "carecredit":
			url = "https://apply.gemoney.com.au/eapps/ApplyRetail.faces?cardType=carecredit";
		break;
		case "creditline":
			url = "https://apply.gemoney.com.au/eapps/ApplyRetail.faces?cardType=creditline";
		break;
		default:
		break;
	}
	var appWin = window.open(url,'','resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,status=yes,top='+topvar+',left='+leftvar+',width='+width+',height='+height+'');
	if(window.focus) {
		appWin.focus();
	}
	
}


function openPopup(pageName) {
	
	var url = "";
	var width = "800";
	var screenY = screen.height;
	var screenX = screen.width;
	var topvar = 0;
	var leftvar = (screenX - width) / 2;
	
	if (screen.height && screen.width) {
		height = screen.height - 80;
	} else {
		height = 520;
	}
		
	switch(pageName){
		case "tellafriend":
			url = "https://eform.gemoney.com.au/eform/Page.do?eFormName=gemoneyau_eco_tellfriend_eco";
		break;
		case "treetellafriend":
			url = "https://eform.gemoney.com.au/eform/Page.do?eFormName=gemoneyau_eco_tellfriend_tree";
		break;
		case "treeform":
			url = "https://eform.gemoney.com.au/eform/Page.do?eFormName=gemoneyau_eco_registration"; 
		break;
		default:
		break;
	}
	
 	var popWin = window.open(url,'','resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,status=yes,top='+topvar+',left='+leftvar+',width='+width+',height='+height+'');
	if (window.focus) {
		popWin.focus();
	}
	
}
