var msgWinTop,msgWinLeft,msgWinWidth,msgWinHeight,mainWinHeight,mainWinWidth;
var oTimer;
var isFF = (navigator.userAgent.indexOf("Firefox")>0);

var DEFAULT_MSGTITLE = "提示";
var DEFAULT_MSGICON  = "images/chnren_29.gif";
var DEFAULT_MSGCONTENT  = "";
var DEFAULT_MSGTIME  = 3000;

var tipTime;

var dW;		// dest window object
var dWDoc;	// dest window's document object

/*
Method:	popUpMsg(frameName, title, icon, content, msgtime)
Input:
	frameName	String		悬浮窗所属Frame窗口
	msgtitle	String		标题
	msgicon		String		Icon链接地址, 空串表示使用默认Icon
	msgcontent	String		内容
	msgTime		Int		悬停时间
Output:	none
*/

function popUpMsg(dstWin, msgTitle, msgIcon, msgContent, msgTime) {

	try {
	
		var objWin = dstWin;
		
		if (isFF) {
			if (objWin.document.body==null) {
				oTimer = window.setTimeout("popUpMsg(\"" + dstWin + "\", \"" + msgTitle + "\", \"" + msgIcon + "\", \"" + msgContent + "\", " + msgTime + ")", 5);
				return;
			}
		} else {
		
			if (objWin.document.readyState!="complete") {
			
				oTimer = window.setTimeout("popUpMsg(\"" + dstWin + "\", \"" + msgTitle + "\", \"" + msgIcon + "\", \"" + msgContent + "\", " + msgTime + ")", 5);
				return;
			}
		}

		if(oTimer) window.clearTimeout(oTimer);

		dstWin = eval(dstWin);
		if (dstWin==null) return;

		dW = dstWin.window;
		dWDoc = dW.document;
		closeMsgWin();

		dWDoc.body.onresize = resizeMainWin;

		if (msgTitle=="") 	msgTitle = DEFAULT_MSGTITLE;
		if (msgIcon=="") 	msgIcon  = DEFAULT_MSGICON;
		if (msgContent=="") 	msgContent = DEFAULT_MSGCONTENT;			
		tipTime = (msgTime==null)?DEFAULT_MSGTIME:msgTime;

		var mw = dWDoc.createElement("div");
		mw.id = "msgWin";
		mw.style.position = "absolute";
		mw.style.visibility = "hidden";
		mw.style.zIndex = "99999";
		mw.style.top = "0px";
		mw.style.left = "0px";
		mw.style.width = "153";
		mw.style.height = "100px";

		var ostr = "<table border=0 cellpadding=0 cellspacing=0 width=153>";
		ostr += "<tr>";
		ostr += "<td background=images/chnren_n1.gif align=center height=25>";
		ostr += "<table border=0 cellpadding=0 cellspacing=0 width=135>";
		ostr += "<tr><td style='font-size:12px;color:#035c80;'><b>" + msgTitle + "</b></td>";
		ostr += "<td width=17 valign=bottom><a href='javascript:top." + window.name + ".closeMsgWin()' title='关闭'><img src=images/close.gif onmouseover=\"javascript:{this.src='images/close_o.gif'}\" onmouseout=\"javascript:{this.src='images/close.gif'}\" width=17 height=17 border=0></a></td>";
		ostr += "</tr>";
		ostr += "</table>";
		ostr += "</td>";
		ostr += "</tr>";
		ostr += "<tr>";
		ostr += "<td align=center background=images/chnren_n3.gif height=65>";
		ostr += "<br>";
		ostr += "<table border=0 cellpadding=0 cellspacing=0 width=135>";
		ostr += "<tr>";
		ostr += "<td width=30 valign=top><img src=" + msgIcon + " width=20 height=35></td>";
		ostr += "<td valign=top style='font-size:12px;color:#035c80;'><a href='search.aspx?re=2' target='mainFrame' onclick='top." + window.name + ".closeMsgWin();'>" + msgContent + "</a></td>";
		ostr += "</tr>";
		ostr += "</table>";
		ostr += "</td>";
		ostr += "</tr>";
		ostr += "<tr><td><img src=images/chnren_n2.gif width=153 height=8></td></tr>";
		ostr += "</table>";
		

		mw.innerHTML = ostr;

		dWDoc.body.appendChild(mw);

		msgWinTop = parseInt(mw.style.top,10);
		msgWinLeft = parseInt(mw.style.left,10);
		msgWinHeight = parseInt(mw.offsetHeight,10);
		msgWinWidth = parseInt(mw.offsetWidth,10);

		mainWinWidth = dWDoc.body.clientWidth;
		mainWinHeight = dWDoc.body.clientHeight;

		mw.style.top = parseInt(dWDoc.body.scrollTop,10) + mainWinHeight;
		mw.style.left = parseInt(dWDoc.body.scrollLeft,10) + mainWinWidth - msgWinWidth - (isFF?21:0);
		mw.style.visibility="visible";
		oTimer = window.setInterval("moveUpMsgWin()",1);
	} catch(e){}
}

function resizeMainWin() {
	try{
		msgWinHeight = parseInt(dWDoc.getElementById("msgWin").offsetHeight,10);
		msgWinWidth = parseInt(dWDoc.getElementById("msgWin").offsetWidth,10);
		mainWinWidth = dWDoc.body.clientWidth;
		mainWinHeight = dWDoc.body.clientHeight;
		dWDoc.getElementById("msgWin").style.top = mainWinHeight - msgWinHeight + parseInt(dWDoc.body.scrollTop,10);
		dWDoc.getElementById("msgWin").style.left = mainWinWidth - msgWinWidth + parseInt(dWDoc.body.scrollLeft,10);
	} catch(e){}
}

function moveUpMsgWin() {
	try {
		if(parseInt(dWDoc.getElementById("msgWin").style.top,10) <= (mainWinHeight - msgWinHeight + parseInt(dWDoc.body.scrollTop,10))) {
			window.clearInterval(oTimer);
			oTimer = window.setTimeout("holdOnMsgWin()", tipTime);  
		}
		msgWinTop = parseInt(dWDoc.getElementById("msgWin").style.top,10);
		dWDoc.getElementById("msgWin").style.top = msgWinTop - 2;
}catch(e){}
}

function moveDownMsgWin() {		
	try {
		if(parseInt(dWDoc.getElementById("msgWin").style.top,10) >= (mainWinHeight + parseInt(dWDoc.body.scrollTop,10))) {     	
			closeMsgWin();
		}
		msgWinTop = parseInt(dWDoc.getElementById("msgWin").style.top,10);
		dWDoc.getElementById("msgWin").style.top = msgWinTop + 2;
	} catch(e){}
}

function holdOnMsgWin() {
	window.clearInterval(oTimer);
	oTimer = window.setInterval("moveDownMsgWin()",1);
}

function closeMsgWin() {		
	try {
		if(oTimer) window.clearInterval(oTimer);
		dWDoc.body.removeChild(dWDoc.getElementById('msgWin'));
	} catch(e) {}
}
