function GetCookieVal(offset)
//获得Cookie解码后的值
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie(name, value)
//设定Cookie值
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
		+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "; domain=.hc360.com" : ("; domain=.hc360.com"))
		+((secure == true) ? "; secure" : "");
}

function DelCookie(name)
//删除Cookie
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=0; expires="+ exp.toGMTString();
}

function GetCookie(name)
//获得Cookie的原始值
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

cleanCookie();
var d = new Date();
var l1 = d.getTime();
var isIE = navigator.userAgent.toLowerCase().indexOf("msie")>0;
var isGecko = navigator.userAgent.toLowerCase().indexOf("gecko")>0;
var popupReady = false;
var wwVersion = '5.10.09';

function showWWPopup() {
	var wp = document.getElementById('WWPopup');
	var anim = function(){
		n += 9;
		if(n >= 45){
			wp.style.marginTop = '0';
			window.clearInterval(tt);
			popupReady = true;
		}else{
			wp.style.marginTop = "-"+(45 - n)+"px";
		}
	},n=0;
	var tt = window.setInterval(anim, 10);
}
function hideWWPopup() {
	if (!popupReady) return;
	SetCookie('_tb_aliww_popup', "1");
	var wp = document.getElementById('WWPopup');
	var anim = function(){
		n += 9;
		if(n >= 45){
			wp.style.marginTop = '-52px';
			window.clearInterval(tt);
		}else{
			wp.style.marginTop = "-"+n+"px";
		}
	},n=0;
	var tt = window.setInterval(anim,10);
	return false;
}
function initWWPopup() {
	if (!checkPopup()) return;
	var wp = document.createElement('div');
	wp.id = 'WWPopup';
	wp.style.marginTop = '-45px';
	document.body.insertBefore(wp, document.getElementById('Head'));
	wp.innerHTML = '<div id="WWPopupBody"><a id="WWPopupDown" href="cnc.php" title="CNC俱乐部">兰生数控机床超市CNC俱乐部</a><a id="WWPopupClose" href="#" onclick="return hideWWPopup();">关闭</a></div>';
	showWWPopup();
	//register ESC 
	document.body.onkeydown = function(e) {
		var ev = !e ? window.event : e;
		if (ev.keyCode == 27) hideWWPopup();
	};
}

function checkPopup() {
	var c = GetCookie("_tb_aliww_popup");
	if (isIE) { //for ie;
		try {
			var obj = new ActiveXObject("WangWangX.WangWangObj");
			if (obj) {
				if (obj.GetVersionStr().indexOf(wwVersion) == -1) {
					delete obj;
					return (c==null || c=='');
				} else {
					delete obj;
					return false;
				}
			}
		} catch(e) {}
	} else if (isGecko) { //for firefox
		try {
			var mimetype = navigator.mimeTypes["application/ww-plugin"];
			if (mimetype) {
				if (mimetype.enabledPlugin) {
					return false;
				}
			}
		} catch(e) {}
	}
	return (c==null || c=='');
}

