﻿var serverPath="http://www.chinasinobi.com";
var chatLayer;
var divstate=true;
var scrollPos=0;
var chatlaystate=true;
var url;

var cssob=document.createElement("link");
cssob.setAttribute("href",serverPath+"/c/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 chatpage=document.createElement("div");
chatpage.setAttribute("id","chatpage");
bodybox[0].appendChild(chatpage);
function showchatpage()
{
chatpage.innerHTML="<div class='chat_left'><a href='' onclick='openwindow();return false;'><img src="+serverPath+"/i/left.jpg /></a></div><div class='chat_right'><a href='#' onclick='closewindow();return false;'><img src="+serverPath+"/i/right.jpg /></a></div>";
}
showchatpage();
function hiddenchatpage()
{
chatpage.innerHTML="<div id='chatpagetop'><div class='chat_left'><a href='#'><img src="+serverPath+"/i/left.jpg /></a></div><div class='chat_right'><a href='#'><img src="+serverPath+"/i/right.jpg /></a></div></div>";
	}

function closewindow()
{chatpage.innerHTML="";chatpage.style.cssText="background:none;border:none;height:0px;width:0px;display:none;";divstate=false;}


var scrollPos;
var nowheight;
var xScroll;
xScroll=document.documentElement.clientWidth-200;
yScroll=document.documentElement.clientHeight-50;
chatpage.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;
		chatpage.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:1px solid #999;filter:alpha(opacity=100);-moz-opacity:1;";
			}
	}
}

function closechatpage()
{
	chatlaystate=true;
	chatLayer.innerHTML="";
	chatLayer.style.cssText="width:0px;height:0px;";
	showchatpage();
}

function openwindow(ob)
{
	var tempurl;
	tempurl=serverPath+"/feedback.php?"+ob+"&lidgenurl="+top.location.href;
	chatlaystate=false;
	openwindow_x=(xScroll/2)-100;
	nowheight=scrollPos+40;
	chatLayer=document.createElement("div");
	chatLayer.style.cssText="height:410px;width:450px;position:absolute; top:"+nowheight+"px;left:"+openwindow_x+"px; background:#fff;text-align:center;border:1px solid #999;filter:alpha(opacity=100);-moz-opacity:1;";
	var getframe=document.createElement("iframe");
	getframe.setAttribute("width","450");
	getframe.setAttribute("id","chatiframe");
	getframe.setAttribute("height","380");
	getframe.setAttribute("scrolling","no");
	getframe.setAttribute("frameBorder","0");
	getframe.setAttribute("src",tempurl);
	var closewindow=document.createElement("div");
	closewindow.innerHTML="<div id='lidgenchat' style='width:400px; margin-left:50px; margin-top:5px; text-align:left;'><strong>我们会尽快联系您,谢谢!</strong><div style='position:absolute; right:10px; top:5px;'><a href='' onclick='closechatpage();return false;'><img src="+serverPath+"/i/close.jpg /></a></div></div>";
	chatLayer.appendChild(closewindow);
	chatLayer.appendChild(getframe);
	document.body.appendChild(chatLayer);
	hiddenchatpage();
}
function sendmail(email)
{
	window.open (email, 'sendmail', 'height=430, width=600, top=0, left=0, toolbar=no, menubar=no, scrollbars=no,resizable=no,location=no, statu s=no');
}

if(window.ActiveXObject){}
else
{
	var etw_a=document.getElementsByTagName("a");
	for(i=0;i<etw_a.length;i++)
	{
		if(etw_a[i].getAttribute("href").indexOf(".pdf")>=0)
		{
			etw_a[i].setAttribute("href","#");
			etw_a[i].setAttribute("target","");
		}
	}
}

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);
}	
var script=document.createElement("script");
script.setAttribute("src",serverPath+"/j/"+url+".js");
script.setAttribute("title",url);
script.setAttribute("id","lidgen_urlid");
document.body.appendChild(script);