﻿var pop = window.createPopup();
pop.hide();
var timex = 159;
var ctimeout=0;
var tox;

String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
		document.write('<div id="msg" style="display:none">');
		document.write('<div style="height:150px;font-size:14px;cursor:pointer;" onclick="parent.hidemsg(1)">');
		document.write('<div style="vertical-align:middle;background:#009900;color:#ffffff;padding:4px;">');
		document.write('<b> 7仔提示</b>');
		document.write('</div>');
		document.write('<div style="text-align:center;padding:5px;">');
		document.write("<div><a href=\"http://"+document.location.host+"/msg/msg_box.jsp\" target=\"_blank\">您有 --cnt-- 条新短消息</a></div>");
		document.write('</div>');
		document.write('</div>');
		document.write('</div>');

function showmsg(cnt)
{
	var popbody = pop.document.body;
	popbody.style.border="1px solid #A4ABC1";
	popbody.innerHTML = document.getElementById("msg").innerHTML.replace(/\-\-cnt\-\-/gi, cnt);
	pop.show(screen.width-260,screen.height-timex-28, 255, timex);
	if (ctimeout==0)
	{
		tox = setTimeout("showmsg("+cnt+")", 1000);
	}
}
function hidemsg(openwin)
{
	clearTimeout(tox);
	ctimeout = 1;
	pop.hide();
	try{document.getElementById("bgx").parentNode.removeChild(document.getElementById("bgx"));}catch(e){}
	if (openwin == 1)
	{
		window.open("http://"+document.location.host+"/msg/msg_box.jsp");
	}
	//pop.hide();
}
function checkMsg()
{
	if (clogin())
	{
		var url = "/msg/checkmsg.jsp?"+Math.random();
		try
		{
			http = new XMLHttpRequest();
		}
		catch(e)
		{
			http = new ActiveXObject( "Microsoft.XMLHTTP" );
		}
		http.open("POST", url, true);
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.onreadystatechange = function () 
		{
			if (http.readyState == 4)
			{
				if(http.status==200)
				{
					var text = http.responseText.trim();
					text-=1;
					if (text>=0)
					{
						showmsg(text-(-1));
					}
					else
					{
						hidemsg(0);
					}
				}
			}
		}
		http.send("ayou=ayou");
	}
}
function msg_getCookie(namex)
{
	var cookies = document.cookie;
	var cookieHeader = namex + "=";
	var beginPosition = cookies.indexOf(cookieHeader);
	if (beginPosition != -1) 
	{
		var acookie = cookies.substring(beginPosition + cookieHeader.length);
		if (acookie.indexOf(";")>-1)
		{
			acookie = acookie.substring(0, acookie.indexOf(";"));
		}
		return acookie;
	}
	return "";
}
function clogin()
{
	if (msg_getCookie("x_username")!="" && msg_getCookie("x_password")!="")
	{
		return true;
	}
	return false;
}
