function Set_Cookie(name, value, expires, path, domain, secure) {
    var today = new Date();
    today.setTime(today.getTime());

    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}

function Get_Cookie(name) {

    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) &&
(name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function popunder() {
    if (Get_Cookie('PopUp')) {
        return false;
    } else {
	var setdomain = ".vietgiaitri.com";
	if(location.hostname.search('sieumua.com') != -1) setdomain = ".sieumua.com";
        Set_Cookie('PopUp', 'PopUp PopUnder', '1', '/', setdomain, '');
	if (location.hostname.search('www.vietgiaitri.com') == -1)
        	urls = ["http://www.vietgiaitri.com/?utm_source=popup"];
	else
        	urls = ["http://game.vietgiaitri.com/index.htm?utm_source=popup"];
        var url = urls[Math.floor(Math.random() * urls.length)]
        params = 'width=' + screen.width;
        params += ', height=' + screen.height;
        params += ', top=0, left=0,scrollbars=yes';
        params += ', toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes';
        params += ', fullscreen=yes';

        pop = window.open(url, 'window', params).blur();
        window.focus();
        return false;
    }
}
jQuery(document).ready(function($){
	$("a").click(function(){
		popunder();
	});
});
try{
	var paddings=0;
	if(padding) paddings=padding;	
} catch(err) {}
if (document.body.clientWidth >= 1230)
{
	var cpmstar_fixed = "1" ; //fix ads near top of screen: "0" to allow ads to scroll with page
	var cpmstar_leftOffset = "0px" ; //optionally adjust left ad positioning
	var cpmstar_rightOffset = "0px" ; //optionally adjust right ad positioning
	var cpmstar_zIndex = "100" ; //adjust layering of ads vs. other page elements
	var cpmstar_centerWidth;
	if (cpmstar_centerWidth == undefined) {
	cpmstar_centerWidth = "984px";
	var gamead = 0;
	}
	if(location.hostname.search('game.vietgiaitri.com') != -1)
	{
		gamead = 1;
		var cpmstar_pid = 12943; // your poolid
		var cpmstar_rnd = Math.round(Math.random() * 999999);
		document.write("\x3cscript type='text/javascript' src='http://server.cpmstar.com/view.aspx?poolid=" + cpmstar_pid + "&script=1&rnd=" + cpmstar_rnd + "'\x3e\x3c/script\x3e");
	}
	if(location.hostname.search('www.vietgiaitri.com') == -1 && gamead == 0)
	{
		var cpmstar_width = "268";
		var cpmstar_height = "768";
		document.write("<div style='display:none'>x</div>");
		var cpmstar_skinStyle;
		if (cpmstar_skinStyle != "R") {
		cpmstar_skinStyle = "B";
		}
		var cpmstar_zIndex;
		if (cpmstar_zIndex == undefined) {
		cpmstar_zIndex = "100";
		}
		var cpmstar_topPos;
		if (cpmstar_topPos == undefined) {
		cpmstar_topPos = "5px";
		}
		var cpmstar_fixed;
		if (cpmstar_fixed == undefined) {
		cpmstar_fixed = "1";
		}
		var adPos;
		if (cpmstar_fixed == "1" && !('BackCompat' == document.compatMode && /msie/i.test(navigator.userAgent)) && !/msie 6/i.test(navigator.userAgent)) {
		adPos = "fixed";
		} else {
		adPos = "absolute";
		}	
		var cpmstar_pixelUrl = "";
		if ("" != cpmstar_pixelUrl) {
		document.write('<IMG SRC="'+cpmstar_pixelUrl+'" width="0" height="0" border="0" />\n');
		}

		function dash2Camel(s){
		return s.replace(/\-(\w)/g,function (m,n){return n.toUpperCase();});
		}
		function px2Int(s){
		return 1*s.replace(/px/,'');
		}

		if(cpmstar_skinStyle == "R") {
		cpmstar_leftPos=px2Int(cpmstar_leftPos)+"px";
		} else {
		var b = document.getElementsByTagName("body")[0];
		var l = "margin-left";
		var r = "margin-right";
		if(b.currentStyle){
		l = b.currentStyle[dash2Camel(l)];
		r = b.currentStyle[dash2Camel(r)];
		} else if(document.defaultView && document.defaultView.getComputedStyle){
		l = document.defaultView.getComputedStyle(b,"").getPropertyValue(l);
		r = document.defaultView.getComputedStyle(b,"").getPropertyValue(r);
		}
		var ml = 0;
		var mr = 0;
		if (undefined != l && l.indexOf("px") != -1 ) {
		ml = px2Int(l);
		}
		if (undefined != r && r.indexOf("px") != -1 ) {
		mr = px2Int(r);
		}
		var rshift=(mr-ml)/2;
		cpmstar_centerWidth = px2Int(cpmstar_centerWidth);
		cpmstar_leftOffset = px2Int(cpmstar_leftOffset);
		cpmstar_rightOffset = px2Int(cpmstar_rightOffset);
		var cpmstar_skinLeftML = - cpmstar_centerWidth/2 - cpmstar_width + cpmstar_leftOffset - rshift;
		cpmstar_skinLeftML = cpmstar_skinLeftML + "px";
		var cpmstar_skinRightML = cpmstar_centerWidth/2 + cpmstar_rightOffset - rshift;
		cpmstar_skinRightML = cpmstar_skinRightML + "px";
		}
		if(cpmstar_skinStyle=="R"){
		document.write("<div style='position:"+adPos+";top:"+cpmstar_topPos+";left:0;z-index:"+cpmstar_zIndex+";width:100%;height:"+cpmstar_height+"px;overflow:hidden;visibility:hidden;'>");
		document.write("<div style='float:left;margin-left:"+cpmstar_leftPos+";width:"+cpmstar_width+"px;height:"+cpmstar_height+"px;visibility:visible;'>");
		} else {
		document.write("<div style='position:"+adPos+";top:"+cpmstar_topPos+";left:0;z-		index:"+cpmstar_zIndex+";width:100%;height:"+cpmstar_height+"px;overflow:hidden;visibility:hidden;'>");
		document.write("<div style='position:absolute;visibility:visible;left:50%;margin-left:"+cpmstar_skinLeftML+";margin-right:0;'>");
		document.write("<a href='http://vietgiaitri.com/ad/click/click.php?id=35' target='_blank'><img src='http://pagead2.googlesyndication.com/pagead/imgad?id=CI_Bz4i_lZmnchCMAhiABigBMggZ5sjYY6znnQ' border='0' width='"+cpmstar_width+"' height='"+cpmstar_height+"' /></a>");
		document.write("</div>");
		document.write("</div>");
		document.write("<div style='position:"+adPos+";top:"+cpmstar_topPos+";right:0;z-		index:"+cpmstar_zIndex+";width:100%;height:"+cpmstar_height+"px;overflow:hidden;visibility:hidden;'>");
		document.write("<div style='position:absolute;visibility:visible;left:50%;margin-left:"+cpmstar_skinRightML+";margin-right:0;'>");
		}
		document.write("<a href='http://vietgiaitri.com/ad/click/click.php?id=35' target='_blank'><img src='http://pagead2.googlesyndication.com/pagead/imgad?id=CMWooYLXnNq_LBCMAhiABigBMghF0esiZ6FRfA' border='0' width='"+cpmstar_width+"' height='"+cpmstar_height+"' /></a>");
		document.write("</div>");
		document.write("</div>");
	}
}
//if(document.referrer.search('yahoo.com') != -1 || document.referrer.search('google.com') != -1)
//{
	showadonion = '';
	showadonion += '<script type="text/javascript">';
	showadonion += 'var cache_buster=Math.random((new Date()).getMilliseconds())*100000000000000000;';
	showadonion += 'document.write(unescape(\'%3Cscript type="text/javascript" src="http://max.gunggo.com/show_ad.ashx?type=pop&amp;sid=2251&amp;cid=2410&amp;io_geo=US|UK|CA&amp;cb=\'+cache_buster+\'"%3E%3C/scr\'+\'ipt%3E\'));';
	showadonion += '</script>';
	document.write(showadonion);
//}
