// Cookie tracker
// Cookie stays valid for 30 days.
// Partner id supplied via a URL parameter within these 30 days to be overriden by the value stored in the cookie


var cookiePartnerID = getCookie('partID@cmcmarkets.co.jp');
var urlPartnerID = getURLParam('partner');			

if (cookiePartnerID =="") { // cookie doesn't exist. Check if there's partner parameter in the URL. If yes, create cookie. If no, do nothing.
	if (urlPartnerID != "") {
		setCookie('partID@cmcmarkets.co.jp',urlPartnerID, '30'); // Create cookie. JSP will populate session variable.			
	}	
	
} else { // Cookie exists update session variable from cookie wether the URL param exists or not. 
	var url = window.location.protocol+"//"+ window.location.host + "/jp/includes/common.jsp" + "?URLPartID=" + cookiePartnerID;			

	try{
		// Opera 8.0+, Firefox, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Ajax is not supported
				alert("Your browser does not support Ajax");
			}
		}
	 }
	
	
	xmlHttp.open("POST", url, true);			
	xmlHttp.send(null);
	setPartID = true;
} 


