function mopst_readCookie(name) {
	var cookieValue = "";
	var search = name + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}  
	}
	return cookieValue;
}
 
function mopst_writeCookie(name, value, hours) {
	var expire = "";
	  if(hours != null)
	  {
	    expire = new Date((new Date()).getTime() + hours * 3600000);
	    expire = "; expires=" + expire.toGMTString();
	  }
	  document.cookie = name + "=" + escape(value) + expire + ";domain=mop.com;" + "path=/;";
}

var mopst_servurl = "http://dc.mop.com/stat.php";
var mopst_data = "";


function mopst(url_param) {
	var mopst_url = "";
	var mopst_referrer = "";
	if(!url_param) {
		try {
			mopst_url = escape(top.location.href);
			mopst_referrer = escape(top.document.referrer);
		} catch (e) {
			mopst_url = escape(location.href);
			mopst_referrer = escape(document.referrer);
		}
		if(location.href.indexOf("http://dzh.mop.com") == 0) {
			try {
				mopst_url = escape(location.href);
				mopst_referrer = escape(document.referrer);
			} catch (e) {
				mopst_url = escape(top.location.href);
				mopst_referrer = escape(top.document.referrer);
			}
		}
	} else {
		mopst_url = escape(url_param);
		try {
			mopst_referrer = escape(top.location.href);
		} catch (e) {
			mopst_referrer = escape(location.href);
		}
	}
	
	var mopst_language = (navigator.systemLanguage ? navigator.systemLanguage : navigator.language);
	var mopst_screen = screen.width + 'x' + screen.height;
	var mopst_mopid = 0;
	try {
		var mopst_logonCookie = mopst_readCookie("mop_logon");
		if(mopst_logonCookie != null && mopst_logonCookie != "") {
			var tmp = mopst_logonCookie.split("|");
			mopst_mopid = parseInt(tmp[0]);
		}
	} catch(e){}

	var mopst_uniqueCookie = mopst_readCookie("mopst_unique");
	if(mopst_uniqueCookie == null || mopst_uniqueCookie == "" || mopst_uniqueCookie.length < 14 || (!/^\d+$/.test(mopst_uniqueCookie))) {
		var randInt = Math.floor(Math.random()*10000);
		if(randInt < 1000) randInt = randInt + 1000;
		mopst_uniqueCookie = new Date().getTime() + "" + randInt;
		mopst_writeCookie("mopst_unique", mopst_uniqueCookie, 365*24);
	}
	
	var mopst_rnd = Math.floor(Math.random()*10000);
	mopst_data = "url=" + mopst_url + "&ref=" + mopst_referrer + "&lan=" + mopst_language + "&screen=" + mopst_screen + "&uid=" + mopst_mopid + "&uc=" + mopst_uniqueCookie + "&rd=" + mopst_rnd;
	
	if(!url_param) {
		document.write("<script src='" + mopst_servurl + '?' + mopst_data + "'></sc"+"ript>");
	} else {
		var i = new Image();
		i.src = mopst_servurl + '?' + mopst_data;
	}
	
}

function localecookie() {
	var mopst_localeCookie = mopst_readCookie("mop_locale");
	if(!mopst_localeCookie || mopst_localeCookie == "") {
		var i = new Image();
		i.src = "http://dc.mop.com/lc/locale.php";
	}
}

mopst();
localecookie();

