

var companyId = 7;
var kf_openurl="http://208.77.47.130:8080/client.jsp?flag=1&companyId=7&style=324&locate=en" +"&refer="+ escape(window.location.href)+"&username="+encodeURIComponent("");
//Â·¾¶
var route = escape(window.location.href);

var kdocTitle = document.title;//±êÌâ 
if(kdocTitle == null){ 
    var t_titles = document.getElementByTagName("title") 
    if(t_titles && t_titles.length >0) 
    { 
       kdocTitle = t_titles[0]; 
    }else{ 
       kdocTitle = ""; 
    } 
} 

function setCookie(name, value, path, domain) {
	name = "kf51_"+ name;
  var oCookie = name + "=" + escape(value) +
      "; expires=Thu, 6 Jan 2100 12:01:01 UTC" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "");
  document.cookie = oCookie;
}

function getCookie(name) {

	name = "kf51_"+ name;
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return "";
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

var  now  =  new  Date();  
var  ss  =  now.getTime() 

var temp_d = parseInt(Math.random() *10000);
var user_str = "" + ss + "_" + temp_d;

var userid = getCookie("userid");
if(userid == "" || userid == null)
{
	
	setCookie("userid",user_str);
	userid = user_str ;	
}

//alert("userid is-->" + getCookie("userid"));
var ref = document.referrer; 
var local_host = document.domain;
if(ref.indexOf(local_host) < 0)
{
	setCookie("referrer",ref);
}
kf_openurl += "&keyword="+escape(getCookie("referrer"));
function open_pic_chat()
{
	var chat_win= window.open(kf_openurl,'chat_7','height=465,width=690,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no');
	chat_win.focus();
	try{sendAndRecieve("/js/recieve.jsp?state=4&companyId="+7+"&sessionId="+userid);}catch(e){}
} 
var kftype=2;var isonline = 0;var myid="client"; var onliner_id=1;var img_hight = 0;img_width = 0;var hasOpen= false;var closeButton = true;var closeIMG ="http://208.77.47.130:8080/images/close.gif";var img_on = "http://208.77.47.130:8080/piao/1.gif";var img_off = "http://208.77.47.130:8080/piao/1.gif";var alignx = 1;var alignW =10;var  alignH =10;
		var img_src = img_off;
		if(isonline == 1)img_src=img_on;
   function initEcAd(LName,RName) { 
document.all.NowAd_left.style.posTop = -200; 
document.all.NowAd_left.style.visibility = 'visible'; 
document.all.NowAd_left.style.position = 'absolute'; 
document.all.NowAd_right.style.posTop = -200; 
document.all.NowAd_right.style.visibility = 'visible'; 
document.all.NowAd_right.style.position = 'absolute'; 
MoveLeftLayer(LName); 
MoveRightLayer(RName); 
} 
function MoveLeftLayer(LName) { 
var x = 2; 
var y = 136; 
LeftName=LName; 
eval("var diff = (document.documentElement.scrollTop + y - document.all." + LeftName + ".style.posTop)*.40"); 
var y = document.documentElement.scrollTop + y - diff; 
eval("document.all." + LeftName + ".style.posTop = y"); 
eval("document.all." + LeftName + ".style.posLeft = x"); 
setTimeout("MoveLeftLayer(LeftName);", 20);  
} 
function MoveRightLayer(RName) { 
var x = 2; 
var y = 136; 
RightName=RName; 
eval("var diff = (document.documentElement.scrollTop + y - document.all." + RightName + ".style.posTop)*0.40"); 
var y = document.documentElement.scrollTop + y - diff; 
eval("document.all." + RightName + ".style.posTop = y"); 
eval("document.all." + RightName + ".style.posRight = x"); 
setTimeout("MoveRightLayer(RightName);", 20); 

} 
document.write("<span id=NowAd_left></span>" 
+"<span id=NowAd_right><table border=0 cellpadding=0 cellspacing=0><tr><td><img src=http://208.77.47.130:8080/piao/1_en.gif onclick='open_pic_chat()' style=\"cursor: pointer;\" border=0 /></a></td></tr><tr><td><a href=msnim:chat?contact=service@thwater.net target=_blank><img src=http://208.77.47.130:8080/piao/2_en.gif border=0 /></a></td></tr><tr><td><a href=msnim:chat?contact=export@thwater.net target=_blank><img src=http://208.77.47.130:8080/piao/3_en.gif border=0 /></a></td></tr><tr><td><a href=skype:lijiqing-eric target=_blank><img src=http://208.77.47.130:8080/piao/4_en.gif border=0 /></a></td></tr><tr><td><A HREF=#top><img src=http://208.77.47.130:8080/piao/5_en.gif border=0 /></A></td></tr></table></span>"); 
initEcAd("NowAd_left","NowAd_right");



function y_gVal(iz)
{var endstr=document.cookie.indexOf(";",iz);if(endstr==-1) endstr=document.cookie.length;return document.cookie.substring(iz,endstr);}
function y_g(name)
{var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;var j;while(i<clen) {j=i+alen;if(document.cookie.substring(i,j)==arg) return y_gVal(j);i=document.cookie.indexOf(" ",i)+1;if(i==0) break;}return null;}
function cc_k()
{var y_e=new Date();var y_t=93312000;var yesvisitor=1000*36000;var yesctime=y_e.getTime();y_e.setTime(y_e.getTime()+y_t);var yesiz=document.cookie.indexOf("cck_lasttime");if(yesiz==-1){document.cookie="cck_lasttime="+yesctime+"; expires=" + y_e.toGMTString() +  "; path=/";document.cookie="cck_count=0; expires=" + y_e.toGMTString() +  "; path=/";return 0;}else{var y_c1=y_g("cck_lasttime");var y_c2=y_g("cck_count");y_c1=parseInt(y_c1);y_c2=parseInt(y_c2);y_c3=yesctime-y_c1;if(y_c3>yesvisitor){y_c2=y_c2+1;document.cookie="cck_lasttime="+yesctime+"; expires="+y_e.toGMTString()+"; path=/";document.cookie="cck_count="+y_c2+"; expires="+y_e.toGMTString()+"; path=/";}return y_c2;}}
var yesdata;
yesdata='companyId=7&userid='+userid+'&refe='+escape(document.referrer)+'&location='+escape(document.location)+'&color='+screen.colorDepth+'x&resolution='+screen.width+'x'+screen.height+'&returning='+cc_k()+'&language='+navigator.systemLanguage+'&ua='+escape(navigator.userAgent)+'&ip=';
var host_stat = document.domain;
var refe_stat = document.referrer;
if(refe_stat == null)refe_stat= "";
var pos = refe_stat.indexOf(host_stat);
if( refe_stat == "" || pos == -1 )
{
	js_src = "http://208.77.47.130:8080/stat.jsp?" +yesdata;
	
	var script=document.createElement("script");
	script.type='text/javascript';
	script.language='javascript';
	script.src=js_src;
	document.getElementsByTagName("head")[0].appendChild(script);
	
}






		var work_id=0;

		var kf_openurl_auto="http://208.77.47.130:8080/client.jsp?flag=1&companyId=7&style=324&locate=en" +"&refer="+ escape(window.location.href);
		function set51KfCookie(name, value) 
		{
			var date =new Date();
			date.setTime(date.getTime()+1*3600*1000*24);
			var oCookie = name + "=" + escape(value) + ";expires="+date.toGMTString();
			document.cookie = oCookie;
		}
		function getTime()
		{
			 var dd=new Date();
			 return Math.floor(dd.getTime()/1000);
		}
		kf_openurl_auto += "&keyword="+escape(getCookie("kf51_referrer"));
		var starttime = getTime();
		var auto_has_show = false;

	//	var auto_self_invite = "";
	//	var auto_self_invite_dialog = ""; 
		var auto_invite_type = "1"; 
		var is_auto_again = "1"; 
		var isonline=0;
	

		if(getCookie("auto_invite_type") == null || getCookie("auto_invite_type") == "")
		{
			set51KfCookie("auto_invite_type","0");
		}
		if(getCookie("is_auto_again") == null || getCookie("is_auto_again")	== "")
		{
			set51KfCookie("is_auto_again","1");
		}	
		if(  getCookie("auto_invite_type") !=  auto_invite_type  )
		{
			set51KfCookie("is_auto_again","1");
			set51KfCookie("auto_invite_type",auto_invite_type);
		}

	//	is_auto_again = getCookie("is_auto_again");
		is_auto_again = (getCookie("is_auto_again") == "")?"1":getCookie("is_auto_again");


		var time_to_show = 3000;

	//	var auto_top = ;
	//	var auto_left = ;

		var isIE = (document.all)?1:0;
		var isIE8 = window.navigator.userAgent.indexOf("MSIE 8") > 0;
		var host = "http://208.77.47.130:8080"; 
		var img_host = "http://208.77.47.130:8080";
		var is_show_source = 1;

		
		
	//	var client_source = '';
	var screen_width =  window.screen.availWidth;
	var screen_hight =  window.screen.availHeight;
	getScreenProperty();

	function getScreenProperty()
	{
		if(typeof(screen_width) == "undefined" || typeof(screen_hight) == "undefined")
		{
			var screen_width =  window.screen.availWidth;
			var screen_hight =  window.screen.availHeight;
		}
		if (self.innerHeight)
		{	// all except Explorer 
			screen_width = self.innerWidth; 
			screen_hight = self.innerHeight; 
		} 
		else if (document.documentElement && document.documentElement.clientHeight) 
		{ 	// Explorer 6 Strict Mode 
			screen_width = document.documentElement.clientWidth; 
			screen_hight = document.documentElement.clientHeight; 
		} 
		else if (document.body) { // other Explorers 
			screen_width = document.body.clientWidth; 
			screen_hight = document.body.clientHeight; 
		} 
	
	}

	function AutoClass(){
					this.property=new Array();
					this.divAlign='';
					this.top = 0;
					this.left=0;
					this.invite_bj='';
					this.show="block"; 
					this.scrollTimer=null;	
					this.autoTimer=null;
					this.configTimer = null;
					this.show_delay = 0;
			//		this.client_source = "";
					this.get_auto_str = getAutoStr;
					this.floatHtml= '';
					this.autoCssHtml = '';
					this.autoScroll = autoAutoScroll;
					this.start=auto_start;
					this.imgsInit=autoImagesInit;
					this.parsInit=autoParsInit;
					this.sizeConfiger = resizeAutoFrame;
					this.otherConfiger = autoConfiger;
		}

var auto = new AutoClass();



if(is_auto_again == "1" )
{
	auto.start();
	auto.autoTimer = window.setTimeout("auto.sizeConfiger()",auto.show_delay);
	auto.scrollTimer = window.setInterval("auto.autoScroll()", 500);
	auto.configTimer = window.setTimeout("auto.otherConfiger()",auto.show_delay+1000);
}


function getAotu_kf_css(top_css,left_css,show_css)
{
	return "cursor:move;border:0px #f00 solid;position:absolute;width:auto;height:auto;top:"+ top_css+"px;left:"+left_css+"px;z-index:8000;display:" + show_css + ";font-size:14px;"
}

function auto_start()
{
	this.imgsInit();
	this.parsInit();
	var kFiframeStr = '<iframe  class="aotu_kf_iframe" frameborder="0" id="aotu_kf_iframe"></iframe><div id="aotu_kf" style="'+getAotu_kf_css(this.top,this.left,this.show)+'" onmousedown="dragPanel(this,event, 1)" onmouseup="dragPanel(this,event, 3)" onmousemove="dragPanel(this,event, 2)"></div>\n';
	document.write(this.autoCssHtml + kFiframeStr );
	if(isIE8)
	{
		GetObjFromDoc("aotu_kf").style.position="absolute";
		GetObjFromDoc("aotu_kf_iframe").style.display="none";
	}
	
}
function getAutoStr()
{
	var auto_str = '<div style="background:url('+this.invite_bj+') no-repeat center;width:'+this.property["auto_width"]+'px;height:'+this.property["auto_height"]+'px;"><table  width="'+this.property["auto_width"]+'" height="'+(this.property["auto_height"]-4)+'" cellspacing="0"> <tr><td height="'+(this.property["auto_height"]-4)*0.7+'" >&nbsp;</td> </tr><tr><td height="'+(this.property["auto_height"]-4)*0.3+'" align="'+this.divAlign+'" valign="top"><div id="auto_buttonDiv" style="width:230px;padding-left:30px;padding-right:30px;overflow:hidden"><div style="float:left; margin-right:20px;"><img src="';
	if(isonline)
	{
		auto_str += this.property["img_recieve"];
	}
	else
	{
		auto_str += this.property["img_offline"];
	}
	auto_str +='" onclick="javascript:open_win_chat();" style="cursor:pointer"/></div><div style="float:left;"><img src="'+this.property["img_refuse"]+'" onclick="javascript:hidden_auto();" style="cursor:pointer"/></div></div></td></tr></table></div>';
	this.floatHtml = auto_str;
}
function autoParsInit()
{
	this.divAlign ='right';
	
	this.show_delay = time_to_show;
	getScreenProperty();
	
	this.left  = (screen_width-this.property["auto_width"] -20)*50/100;
	this.top  = (screen_hight-this.property["auto_height"] - 140)*50/100;//
	//this.left = Math.floor(screen_width/2  - this.property["auto_width"]/2);
	//this.top =  Math.floor(screen_hight/2  - this.property["auto_height"]/2 - 20);

	var auto_cssStr = "<style TYPE='text/css'>\n<!--\n";
	auto_cssStr += "#aotu_kf div{margin:0}\n";

	//auto_cssStr +=  ".aotu_kf{border:0px #f00 solid;position:absolute;width:auto;height:auto;top:"+ this.top+"px;left:"+this.left+"px;z-index:8000;display:"+this.show+";font-size:14px;}\n";
	auto_cssStr += ".aotu_kf_iframe{position:absolute;z-index:8000;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);}\n";
	auto_cssStr+= "-->\n</style>";

	this.autoCssHtml = auto_cssStr;

}
function autoImagesInit()
{
		this.show = 'block';

		this.invite_bj = img_host + "/auto/newAuto/right_7_en/offlineBj.jpg";
		this.property["img_offline"] =  img_host + "/auto/newAuto/right_7_en/offlineButton.gif";
		preDownImage(this.property["img_offline"]);

	this.property["img_refuse"] = img_host + "/auto/newAuto/right_7_en/cancelButton.gif";
	
	preDownImage(this.property["img_refuse"]);

	var KFco = 0;
	do{
		preDownImage(this.invite_bj);
		getImgAttribute(this.invite_bj);
		if ((this.property["auto_width"] > 100) && (this.property["auto_height"] > 50))	break;
		if(KFco > 10)
		{
			this.show = "none";break;
		}
		KFco++;
	}while(true)
}

function resizeAutoFrame()
{

	this.get_auto_str();	
	GetObjFromDoc("aotu_kf").innerHTML = this.floatHtml;
	if( GetObjFromDoc("aotu_kf") == null){
		setTimeout('resizeAutoFrame()',100);
		return;
	}
	//if(isIE)
	//GetObjFromDoc("aotu_kf").setAttribute("className","aotu_kf");
	//else
	//GetObjFromDoc("aotu_kf").setAttribute("class","aotu_kf");
	resizeDivWidth();
}
function autoAutoScroll()
{
	if(dragable)	return;
	if(this.top<= 0 || this.left<= 0)
	{
		getScreenProperty();
		this.left  = (screen_width-this.property["auto_width"] -20)*50/100;
		this.top  = (screen_hight-this.property["auto_height"] - 140)*50/100;
	}

	var diffY = document.documentElement.scrollTop;	
	var diffX = document.documentElement.scrollLeft ;
	if(diffY==0)
	{		
		diffY = document.body.scrollTop;
	}
	if(diffX==0)
	{		
		diffX = document.body.scrollLeft;
	}
	try{
			GetObjFromDoc("aotu_kf").style.top = (diffY + this.top ) + "px" ;
			GetObjFromDoc("aotu_kf").style.left = (diffX + this.left) + "px";
	}catch(e){};
}
function autoConfiger()
{
	auto_has_show = true;
	if( auto_invite_type == "1" && (getCookie("href") == window.location.href))
	{
		set51KfCookie("is_auto_again","0");
	}
	set51KfCookie("auto_invite_type",auto_invite_type);
	set51KfCookie("href",window.location.href);
}
function resizeDivWidth()
{
	var tempChildNodes = GetObjFromDoc("auto_buttonDiv").childNodes;
	if( tempChildNodes[0].offsetWidth <= 30 || tempChildNodes[1].offsetWidth <= 30 ){
		setTimeout('resizeDivWidth()',100);
		return;
	}
		//alert(tempChildNodes[0].offsetWidth + "="+tempChildNodes[1].offsetWidth);

	GetObjFromDoc("auto_buttonDiv").style.width = (tempChildNodes[0].offsetWidth + tempChildNodes[1].offsetWidth + 20)+"px";

	if(	 GetObjFromDoc("auto_buttonDiv").offsetHeight > (tempChildNodes[0].offsetHeight) + 2 )
	{
		GetObjFromDoc("auto_buttonDiv").style.width = GetObjFromDoc("auto_buttonDiv").offsetWidth + 60+"px"; //padding
	}
}
function GetObjFromDoc(id,theDoc)
{
	if(!theDoc){theDoc = document;}
	if (theDoc.getElementById){return theDoc.getElementById(id);}
	else if (document.all)
	{return theDoc.all(id);}
}
function getImgAttribute(src)
{
	var img = new Image();
	img.src = src;
	img.onerror=function(){}
	auto.property["auto_width"] = img.width;
	auto.property["auto_height"] = img.height;
}
function preDownImage(src)
{
	var imgs = new Image();
	imgs.src = src;
	imgs.onerror=function(){}
	if(!imgs.complete)
	{
		setTimeout("preDownImage('"+src+"')",500);
		return;
	}
}
function isImage(src)
{
	var imgs = new Image();
	imgs.src = src;
	if(imgs.complete)
	{
		return (imgs.height > 0 || imgs.width > 0)?true:false;
	}
	return false;
}
var dragstart = new Array();
var dragable = false;

function dragPanel(obj,e, op) {
	if(op == 1) {
		dragstart = isIE ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
		dragstart[2] = parseInt(obj.offsetLeft);
		dragstart[3] = parseInt(obj.offsetTop);
	    dragable = true;
		doane(e);
	} else if(op == 2 && dragstart[0] && dragable) {
		var dragnow = isIE ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
		obj.style.left = (dragstart[2] + dragnow[0] - dragstart[0]) + 'px';
		obj.style.top = (dragstart[3] + dragnow[1] - dragstart[1]) + 'px';
		doane(e);
	} else if(op == 3 && dragable) {
		var diff_y = document.documentElement.scrollTop;	
		var diff_x = document.documentElement.scrollLeft ;
		if(diff_y==0)diff_y = document.body.scrollTop;
		if(diff_x==0)diff_x = document.body.scrollLeft;
		auto.top = obj.offsetTop - diff_y;
		auto.left =  obj.offsetLeft -  diff_x;
		dragstart = [];
		dragable = false;
		doane(e);
	}
}
function doane(event) {
	e = event ? event : window.event;
	if(isIE) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}



var kfwin_has_show = false;
 var onloadInterval = window.setInterval(checkIfShow,10000);

function sendAndRecieve(js_src)
{
	if(auto_invite_type == "3")
	{
		set51KfCookie("is_auto_again","0");
	}
	else
	{
		if(isonline)
		{
			js_src = "http://208.77.47.130:8080" +js_src;
			var script=document.createElement("script");
			script.type='text/javascript';
			script.language='javascript';
			script.src=js_src;
			document.getElementsByTagName("head")[0].appendChild(script);
		}
	}
}
function hidden_auto()
{
	if( auto_invite_type =="2" || auto_invite_type =="3" || auto_invite_type =="4")
	{
		set51KfCookie("is_auto_again","0");
	}
	auto_has_show = false;
	var aotu=GetObjFromDoc("aotu_kf");
	aotu.style.display="none";			
	sendAndRecieve("/js/recieve.jsp?state=3&companyId="+companyId+"&sessionId="+userid);	
}
function open_win_chat()
{
	kf_openurl_auto = kf_openurl_auto+"&workId="+work_id;
	var chat_win= window.open(kf_openurl_auto,'chat_7','height=465,width=690,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no');
	chat_win.focus();

	try
	{
		if(auto_invite_type == "2" || auto_invite_type == "3")
		{
			set51KfCookie("is_auto_again","0");
		}
		kfwin_has_show = true;
		window.clearInterval(onloadInterval);
		var aotu=GetObjFromDoc("aotu_kf");
		aotu.style.display="none";
		sendAndRecieve("/js/recieve.jsp?state=4&companyId="+companyId+"&sessionId="+userid);
		
	}catch(e){}
}
var counttimes = 0;
function checkIfShow()
{
	if(kfwin_has_show) return;
	var now_time = getTime();
	if(now_time - starttime > 300)
	{
		
			window.clearInterval(onloadInterval);
			return;
		
	}
	counttimes++;
	
	//if(counttimes > 1)
	{
		sendAndRecieve("/js/autoShow.jsp?t="+counttimes+"&companyId="+companyId+"&sessionId="+userid);
	}
}

function show_kf_auto(workid){
    // nextAccept();
	work_id = workid;
	var aotu= GetObjFromDoc("aotu_kf");
	if(aotu)
	{
		aotu.style.display="block";
	}
	else
	{	
		auto.sizeConfiger();
	}
	auto_has_show = true;
}
function show_51kf_dialog(workid)
{
	work_id = workid;
	try
	{
		kfwin_has_show = true;
		window.clearInterval(onloadInterval);
		sendAndRecieve("/js/recieve.jsp?state=4&companyId="+companyId+"&sessionId="+userid);	
		//window.open(kf_openurl_auto,"chat"+companyId,"height=473,width=703,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no");
		kf_openurl_auto = kf_openurl_auto+"&workId="+work_id;
		location.href=kf_openurl_auto;

		window.focus();
	}catch(e){}
}

sendAndRecieve("/js/autoShow.jsp?t=0&companyId="+companyId+"&sessionId="+userid+"&route="+route+"&keyword="+escape(getCookie("kf51_referrer"))+"&page_title="+escape(kdocTitle));
//if(1)return;	



		