function mst_createCookie(httpReferer, affId) {
	// referral
	var mst_referral=mst_getCookie('mst_referral');	
	if(mst_referral.length==0){
		mst_setCookie('mst_referral', httpReferer, 7);
	}
	
	// affiliate
	if (affId > 0) {
		var mst_affiliate=mst_getCookie('mst_affiliate');	
		if(mst_affiliate.length==0){
			mst_setCookie('mst_affiliate', affId, 365);
		}
	}
}

function mst_trackConversion(userId) {
	var mst_referral=mst_getCookie('mst_referral');
	var mst_affiliate=mst_getCookie('mst_affiliate');
	if(mst_referral.length!=0 || mst_affiliate!=0){
		$.ajax({
			type: "POST",
			url: "index.php",
			data: "controller=menu&action=logConversion&userId="+userId+"&referer="+mst_referral+"&affiliate="+mst_affiliate,
			success: function(response){
			}
		});
	}
}

function mst_setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString())+
	";domain=.myseotool.com;";
}

function mst_getCookie(c_name){
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1){
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}
