﻿var serverPath="";
var serverImg=serverPath+"/images/Consulting.jpg";
var sserverImg=serverPath+"/images/sConsulting.jpg";
var titlemessage="We will deal with your message in 24 hours";
var chatLayer;
var divstate=true;
var scrollPos=0;
var chatlaystate=true;
var url;
var cssob=document.createElement("link");
cssob.setAttribute("href",serverPath+"/chat/chat.css");
cssob.setAttribute("rel","stylesheet");
cssob.setAttribute("type","text/css");
var myhead=document.getElementsByTagName("head");
myhead[0].appendChild(cssob);
var bodybox=document.getElementsByTagName("body");
var chatbox=document.createElement("div");
chatbox.setAttribute("id","chatbox");
bodybox[0].appendChild(chatbox);
url=top.location.href;
var url_start=url.indexOf("http://")+7;
if(url.indexOf("www.")>=1){
	url_start=url_start+4;
}
url=url.substr(url_start);
url_end=url.indexOf("/")+url_start;
if(url_end>url_start){
	url=top.location.href.substring(url_start,url_end);
}
else{
	url=top.location.href.substr(url_start);
}

function showchatbox()
{
		chatbox.innerHTML="<div class='etw_chat_left'><a href='' onclick='openwindow();return false;'><img src=http://www."+url+"/chat/left.jpg /></a></div><div class='etw_chat_right'><a href='#' onclick='closewindow();return false;'><img src=http://www."+url+"/chat/right.jpg /></a></div>";
}
showchatbox();


function hiddenchatbox(){chatbox.innerHTML="<div id='chatboxtop'><div class='etw_chat_left'><a href='#'><img src=http://www."+url+"/chat/left.jpg /></a></div><div class='etw_chat_right'><a href='#'><img src=http://www."+url+"/chat/right.jpg /></a></div></div>";

}
//关闭窗口
function closewindow(){
	chatbox.innerHTML="";
	chatbox.style.cssText="background:none;border:none;height:0px;width:0px;";
	divstate=false;
}
var scrollPos;
var nowheight;
var xScroll;
xScroll=document.documentElement.clientWidth-200;
yScroll=document.documentElement.clientHeight-50;
chatbox.style.cssText="position:absolute; top:"+yScroll+"px; left:"+xScroll+"px;";

window.onscroll = function(){
	xScroll=document.documentElement.clientWidth-200;
	yScroll=document.documentElement.clientHeight-50;
	if(divstate==true){
		if (typeof window.pageYOffset != 'undefined') {
			scrollPos = window.pageYOffset;
		}
		else if (typeof document.compatMode != 'undefined' &&document.compatMode != 'BackCompat') {
			scrollPos = document.documentElement.scrollTop;
		}else if (typeof document.body != 'undefined') {
			scrollPos = document.body.scrollTop;
		}
		
		nowheight=scrollPos+yScroll;
		chatbox.style.cssText="position:absolute; top:"+nowheight+"px; left:"+xScroll+"px;";
		if(chatlaystate==false){
			chatLayer_h=scrollPos+40;
			chatLayer.style.cssText="height:440px;width:500px;position:absolute; top:"+chatLayer_h+"px;left:"+openwindow_x+"px; background:#fff;text-align:center;border:10px solid #aaa; filter:alpha(opacity=90);opacity:0.9;";
		}
	}
}
function closechatbox(){chatlaystate=true;
chatLayer.innerHTML="";
chatLayer.style.cssText="width:0px;height:0px;";
showchatbox();
}

var state=true;
function showmsg(parentob,text,width,height){
	if(width==undefined){
		width=460;
	}
	if(height==undefined){
		height=410;
	}
	tempurl=serverPath+"/chat/feedback.html?"+text+"&etwurl="+top.location.href;
	var parentob=document.getElementById(parentob);
	if(state){
		var i=0;
		var j=0;
		var div=document.createElement("div");
		var rollstartHeight=document.documentElement.scrollTop;
		var rollendHeight=parentob.getBoundingClientRect().top+document.documentElement.scrollTop;
		div.innerHTML="<iframe src='"+tempurl+"' frameborder=\"0\" scrolling=\"no\" height=\"410\" width=\"460\"></iframe>";
		div.style.cssText="display:none;height:0px; width:460px;overflow:hidden;";
		div.setAttribute("id","etwchat2009");
		parentob.appendChild(div);
		var showdiv=setInterval(show,1);
		showdiv;
		state=false;
		var tempimg=parentob.getElementsByTagName("img");
		tempimg[0].setAttribute("src",sserverImg);
	}
	else{
		i=410;
		j=0;
		var div=document.getElementById("etwchat2009");
		var hiddendiv=setInterval(hidden,1);
		hiddendiv;
		state=true;
		var tempimg=parentob.getElementsByTagName("img");
		tempimg[0].setAttribute("src",serverImg);
	}
	function show(){
		j=j+1;
		i=i+j;
		if(document.documentElement.scrollTop<=rollendHeight){
			document.documentElement.scrollTop=rollstartHeight+i;
		}
		if(i<=410){
			div.style.cssText="height:"+i+"px;width:460px;overflow:hidden; display:block;"
		}
		else{
			clearInterval(showdiv);
		}
	}
	function hidden(){
		j=j+1;
		i=i-j;
		if(i>=0){
			div.style.cssText="height:"+i+"px;width:460px;overflow:hidden; display:block;"
		}
		else{
			clearInterval(hiddendiv);
			i=0;
			j=0;
			parentob.removeChild(div);
		}
	}
}

function openwindow(ob){var tempurl;
tempurl=serverPath+"/chat/feedback.html?"+ob+"&etwurl="+top.location.href;
chatlaystate=false;
openwindow_x=(xScroll/2)-100;
nowheight=scrollPos+40;
chatLayer=document.createElement("div");
chatLayer.style.cssText="height:440px;width:500px;position:absolute; top:"+nowheight+"px;left:"+openwindow_x+"px; background:#fff;text-align:center;border:10px solid #aaa; filter:alpha(opacity=90);opacity:0.9;";
var getframe=document.createElement("iframe");
getframe.setAttribute("width","460");
getframe.setAttribute("id","chatiframe");
getframe.setAttribute("height","410");
getframe.setAttribute("scrolling","no");
getframe.setAttribute("frameBorder","0");
getframe.setAttribute("src",tempurl);
var closewindow=document.createElement("div");
closewindow.innerHTML="<div id='etwchatbox_style'><div class='textstyle'>"+titlemessage+"</div><div class='etwchatboxclosebox'><a href='' onclick='closechatbox();return false;'><img src="+serverPath+"/chat/close.jpg /></a></div></div>";
chatLayer.appendChild(closewindow);
chatLayer.appendChild(getframe);
document.body.appendChild(chatLayer);
hiddenchatbox();
}
