// JavaScript Document
/*=====================================================================
'代码版权说明
'=====================================================================
' 文件名: MailPrompt.js
' 版本:	  1.0
' 日期:   2006-8-8
' 作者:	  ..
' 说明:	  
' 修改记录: 
' 版权所有：....
'=====================================================================
' Copyright (C) 2006 yonovo.com.cn All rights reserved.
' Web: http://www.yonovo.com.cn
' Need help? Contact: Hermit_Dragon@163.com
'=====================================================================*/
	if(!window.XMLHttpRequest) {
		window.XMLHttpRequest = function() {
			var sArrXMLHTTP=new Array("MSXML3.XMLHTTP","MSXML2.XMLHTTP","Microsoft.XMLHTTP","MSXML.XMLHTTP","MSXML2.ServerXMLHTTP");
			var oXMLHTTP=null;
			for(var i=0;i<sArrXMLHTTP.length;i++){
				try{
					oXMLHTTP=new ActiveXObject(sArrXMLHTTP[i]);
					break;
				}catch(Exception){}
			}
			return oXMLHTTP;
		}
	}
	
	var InspectTime = 40000;					//每隔两分种检查一次	240000
	
	function MailPrompt()
	{
		this.ProBox=window.createPopup();
		window.document.body.setAttribute("MailPrompt",this);
		this.ProBoxWidth=245;
		this.ProBoxHeight=132;
		this.Move=null;
		this.PageY=0;
		this.PageX=0;
		this.IsXp=(navigator.userAgent.toUpperCase().indexOf("NT 5.1")>-1)?true:false;
		this.Close=null;
		
		this.Show=function()
		{
			this.PageY=window.screen.Height;
			if(this.IsXp) this.PageY-=180;
			this.PageX=parseInt(window.screen.Width-280);
			try{
				this.ProBox.show(this.PageX,this.PageY,this.ProBoxWidth,this.ProBoxHeight);
				this.Close=setInterval("window.document.body.getAttribute(\"MailPrompt\").Hidden();",12000);
			}catch(e) {
				
			}
		}
		
		this.Hidden=function(){
			this.ProBox.hide();
			var doc=this.ProBox.document;
			doc.open();
			doc.writeln("<html>");
			doc.writeln("<head>");
			doc.writeln("</head>");
			doc.writeln("<body>");
			doc.writeln("</body>");
			doc.writeln("</html>");
			doc.close();
		}
			
		this.Update=function(Stream)
		{
			var doc=this.ProBox.document;
			doc.open();
			doc.writeln("<html>");
			doc.writeln("<head>");
			doc.writeln("</head>");
			doc.writeln("<body>");
			doc.writeln(Stream);
			doc.writeln("</body>");
			doc.writeln("</html>");
			doc.close();
		}
	}
	
	
	function GetMail(InspectPath)
	{
		var AjaxHttp=null;
		var Stream="";
		AjaxHttp = new window.XMLHttpRequest();
		try{
			if(AjaxHttp!=null){
				AjaxHttp.open("GET",InspectPath,false);
				AjaxHttp.setRequestHeader("Content-Length",InspectPath.length); 
				AjaxHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				AjaxHttp.send();
				return AjaxHttp;
			}else{
				clearInterval(InspectTimer);
				return "";
			}
		}catch(Exception){
				clearInterval(InspectTimer);
				return "";
		}
	}
	
	function getDocumentSize() {
		var resultSize = {width:0,height:0};
		if (window.innerWidth) { 
			resultSize.width = window.innerWidth 
			resultSize.height = window.innerHeight 
		} 
		else if (document.compatMode=="CSS1Compat") { 
			resultSize.width = document.documentElement.clientWidth 
			resultSize.height = document.documentElement.clientHeight 
		} 
		else if (document.body) { 
			resultSize.width = document.body.clientWidth 
			resultSize.height = document.body.clientHeight 
		} 
		return resultSize;
	}
	function getScrollTop() {
		if (document.compatMode=="CSS1Compat") { 
			return document.documentElement.scrollTop; 
		} 
		else if (document.body) { 
			return document.body.scrollTop;
		} 
		return 0;
	}
	
	function InspectMail()
	{
		var oRequest=GetMail(InspectPath);
		var sHtml = oRequest.responseText;
		if(oRequest.getResponseHeader("WebChat") === "1") {
			showChatPrompt(sHtml,oRequest.getResponseHeader("InspectUrl"));
			oRequest = null;
			return ;
		}
		oRequest = null;
		if(sHtml!="")
		{
			PromptPanel.Update(sHtml);
			PromptPanel.Show();
		}
	}
	
	function chatToScroll() {
		var docSize = getDocumentSize();
		chatElement.style.top =  getScrollTop() + parseInt(docSize.height/2) - parseInt(chatElement.offsetHeight/2) + "px";
	}
	
	function showChatPrompt(sHtml,sPath) {
		chatElement = document.getElementById("ID_ChatPrompt");
		if(!chatElement) return ;
		chatElement.innerHTML = sHtml;
		chatElement.style.display = "block";
		var docSize = getDocumentSize();
		chatElement.style.left = parseInt(docSize.width/2) - parseInt(chatElement.offsetWidth/2) + "px";
		chatElement.style.top =  getScrollTop() + parseInt(docSize.height/2) - parseInt(chatElement.offsetHeight/2) + "px";
		if(chatScrollTimer == null)
			chatScrollTimer = setInterval("chatToScroll();",200);
		var AjaxHttp=null;
		AjaxHttp = new window.XMLHttpRequest();
		try{
			if(AjaxHttp!=null){
				AjaxHttp.open("GET",sPath,true);
				AjaxHttp.setRequestHeader("Content-Length",sPath.length); 
				AjaxHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				AjaxHttp.send();
			}
		}catch(Exception){
			
		}
	}
	
	function closeChatPrompt() {
		if(!chatElement) return ;
		chatElement.style.display = "none";
		if(chatScrollTimer != null) {
			clearInterval(chatScrollTimer);	
			chatScrollTimer = null;
		}
	}
	
	window.attachEvent("onload",function(){InspectMail();})
	
	var PromptPanel=new MailPrompt();
	var InspectTimer=setInterval("InspectMail();",InspectTime);
	var chatScrollTimer = null,chatElement = null;
	document.writeln("<div id=\"ID_ChatPrompt\" style=\"position:absolute;left:0px;top:0px;display:none;\"></div>");
	document.writeln("<a href=\"\" style=\"display:none;\" id=\"ClickMail\" target=\"_blank\"></a>");
