var str=window.location.host;
str=str.toLowerCase();
//if (str.indexOf('127.0.0.1')<0 && str.indexOf('localhost')<0 && str.indexOf('192.168.')<0 && str.indexOf('172.')<0 && str.indexOf('10.')<0)
//{
//	alert('对不起，测试版只能本地服务器上运行，如 http://127.0.0.1 ; http://localhost ; http://192.168.X.X ; http://172.X.X.X ; http://10.X.X.X 可以带端口号，请不要在公网上进行测试。');
//    window.location.href='http://www.tourba.com';
//}
var myurl1='/kf/kfewt_login.asp';
var myurl2='/kf/kfewt_getinfo.asp';
var webchat_timer_getinfo=0;
var webchat_newmsg_username='';
var wenchat_timer_popdiv=0;

 var xmlHttp_ask = false;
   try {
     xmlHttp_ask = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       xmlHttp_ask = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         xmlHttp_ask = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         xmlHttp_ask = false;
       }  
     }
   }

function webchat_userlogin()
{
	var myurl= myurl1;
	var MyWebSend="mytext=data";
	xmlHttp_ask.open("POST",myurl,true);
	xmlHttp_ask.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_ask.onreadystatechange = webchat_userlogin_callback;
	xmlHttp_ask.send(MyWebSend);
}
function webchat_userlogin_callback()
{
    var webtext;
    if (xmlHttp_ask.readyState == 4)
	 {
       if (xmlHttp_ask.status == 200)
	     {
		    webtext = xmlHttp_ask.responseText;
			webchat_timer_getinfo=setInterval("webchat_getinfo_update()",webchat_getinfo_everytime);
		 }
     }
}

function webchat_getinfo_update()
{
    var myurl=myurl2;
	var MyWebSend="mytext=data";
	xmlHttp_ask.open("POST",myurl,true);
	xmlHttp_ask.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_ask.onreadystatechange = webchat_getinfo_callback;
	xmlHttp_ask.send(MyWebSend);   
}
function webchat_getinfo_callback()
{
   if (xmlHttp_ask.readyState == 4)
   {
      if (xmlHttp_ask.status == 200)
	  {
	     var webtext;
		 webtext=xmlHttp_ask.responseText;
		 var info_array=webtext.split("\r\n");
		 if (info_array[0]=="newmsg")
		 {
		    if (webchat_timer_getinfo!=0)
			{
		     clearInterval(webchat_timer_getinfo);
			 webchat_timer_getinfo=0;
			}
			webchat_newmsg_username=info_array[1];
			document.getElementById("webchat_sound_newmsg").play();
		    document.getElementById("webchat_newmsg_userspan").innerHTML=webchat_newmsg_username;
			var temp_obj=document.getElementById("webchat_newmsg_popdiv");
			temp_obj.style.display="";
			var divWidth = parseInt(temp_obj.offsetWidth,10);
			temp_obj.style.top=parseInt(document.body.scrollTop,10) + document.body.clientHeight + 10;
			temp_obj.style.left=document.body.clientWidth - divWidth + parseInt(document.body.scrollLeft,10);
			if (wenchat_timer_popdiv!=0) {clearInterval(wenchat_timer_popdiv);}
			wenchat_timer_popdiv=window.setInterval("webchat_getinfo_option()",100);
		 }	  
	  }
   }
}
function webchat_getinfo_option()
{ 
   var temp_obj=document.getElementById("webchat_newmsg_popdiv");
   var docHeight = document.body.clientHeight;
   var divHeight = parseInt(temp_obj.offsetHeight,10);
   if(parseInt(temp_obj.style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
    {
    window.clearInterval(wenchat_timer_popdiv);
    wenchat_timer_popdiv = window.setInterval("webchat_getinfo_resizeDiv()",600);
    }
	else
	{
    temp_obj.style.top = parseInt(temp_obj.style.top,10) - 10;
	}
}
function webchat_getinfo_resizeDiv()
{
   var temp_obj=document.getElementById("webchat_newmsg_popdiv");
   var divHeight = parseInt(temp_obj.offsetHeight,10);
   var divWidth = parseInt(temp_obj.offsetWidth,10);
   var docWidth = document.body.clientWidth;
   var docHeight = document.body.clientHeight;
   temp_obj.style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10);
   temp_obj.style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10);
}

function webchat_showmsgctoc(openurl)
{
   var width=603,height=468;
   openurl=openurl+"?userid="+webchat_newmsg_username;
   if (wenchat_timer_popdiv!=0) 
   {
   clearInterval(wenchat_timer_popdiv);
   wenchat_timer_popdiv=0;
   }
   document.getElementById("webchat_newmsg_popdiv").style.display="none";
   webchat_timer_getinfo=setInterval("webchat_getinfo_update()",webchat_getinfo_everytime);
   window.open(openurl,"_blank",'width=' + width + ',height=' + height + ',left='+(screen.availWidth-width)/2+',top='+(screen.availHeight-height)/2+',resizable=0,scrollbars=no,menubar=no,frameborder=0,status=no');
}
function closeyq(){
document.getElementById("webchat_newmsg_popdiv").style.display="none"

}

setTimeout("webchat_userlogin()",3000); // 3 秒
