/**********************
单坐席浮动图标
调用例子:
<script>
var host="http://192.168.1.23:10054";
var position='left';//浮动位置(左/右)
var adcallno='9001001001';//号码
var adurl='ad.adcall.com.cn';//网址
var imgselect=0;//是否自定义图标
var img="1.jpg";//图标
var imgtxt='admin';//图标提示
var top=120;//图标距离顶部位置
</script>
<script src='http://code.adcall.com.cn/service/float_1.js' charset='gb2312'></script>
********************/

function GetQueryString(name)   
{   
	var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
	if (reg.test(document.getElementById("adcallfloat").src)) return RegExp.$2; return null; 
}
var lib = {
	loadCss: function (url) {
		var css = document.createElement('link');
		css.setAttribute('rel', 'stylesheet');
		css.setAttribute('type', 'text/css');
		css.setAttribute('href', url);
		document.getElementsByTagName('head')[0].appendChild(css);
	},
	
	getElement: function (id) {
		return document.getElementById(id);
	}
}
var adcall_browser = {};
adcall_browser.ieVersion = /msie (\d+)/.exec(navigator.userAgent.toLowerCase());
adcall_browser.higherThanIE6 = adcall_browser.ieVersion && parseInt(adcall_browser.ieVersion[1]) > 6;
adcall_browser.onQuirkMode = document.compatMode && document.compatMode.indexOf('Back') == 0;

if(adcall_browser.ieVersion && !(adcall_browser.higherThanIE6)) {
	document.execCommand("BackgroundImageCache", false, true);
}

//getPageSize function
function getPageSize(){    
    var xScroll, yScroll;    
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth;    
        yScroll = window.innerHeight + window.scrollMaxY;    
    } else if (document.body.scrollHeight > document.body.offsetHeight){    
        xScroll = document.body.scrollWidth;    
        yScroll = document.body.scrollHeight;    
    } else {    
        xScroll = document.body.offsetWidth;    
        yScroll = document.body.offsetHeight;    
    } 
 var windowWidth, windowHeight;    
    if (self.innerHeight) {    
        windowWidth = self.innerWidth;    
        windowHeight = self.innerHeight;    
    } else if (document.documentElement && document.documentElement.clientHeight) {    
        windowWidth = document.documentElement.clientWidth;    
        windowHeight = document.documentElement.clientHeight;    
    } else if (document.body) {    
        windowWidth = document.body.clientWidth;    
        windowHeight = document.body.clientHeight;    
    }    
   
    if(yScroll < windowHeight){    
        pageHeight = yScroll;    
    } else {    
        pageHeight = windowHeight;    
    }    
   
    if(xScroll < windowWidth){    
        pageWidth = xScroll;    
    } else {    
        pageWidth = windowWidth;    
    }    
   
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)    
    return arrayPageSize;    
} 

//init
var host = GetQueryString("host");
if(typeof(host) == "undefined" || host=="" || host==null)
	host = "http://code.adcall.com.cn";
//host = "http://192.168.1.23:10054";
var adcall_no = GetQueryString("wid");//ADCALL号码
var adcall_ud = decodeURI(GetQueryString("ud"));//描述

var adcall_lr = GetQueryString("lr");
var adcall_y = GetQueryString("y");
var adcall_fs = parseInt(GetQueryString("fs"));
var adcall_ws = parseInt(GetQueryString("ws"));
var adcall_ft = decodeURI(GetQueryString("ft"));
var adcall_wt = decodeURI(GetQueryString("wt"));
var adcall_url = GetQueryString("url");
var adcall_side = GetQueryString("side");
var adcall_un = GetQueryString("un");

var adcall_name = GetQueryString("name");


//var adcall_css = GetQueryString("css");//"style1";
var adcall_img = host + "/images/13/";
var adcall_css1 = host + "/css/";

var ad_pagesize = getPageSize();
var f_w_t = parseInt(ad_pagesize[3]/2 - 100);
var f_w_l = parseInt(ad_pagesize[0]/2 - 200);

var adcall_cn = decodeURI(GetQueryString("cn"));

if(adcall_no=='9001006551')
{
	var stat="WebCall.jsp";
}
else
{
	var stat="TM43.inc.jsp";
}

if(typeof(adcall_no) != "undefined" && adcall_no!='' && adcall_no!=null)
{
	adcall_no=adcall_no.split("/");
}

if(typeof(adcall_ud) != "undefined" && adcall_ud!='' && adcall_ud!=null)
{
	adcall_ud=adcall_ud.split("/");
}

if(typeof(adcall_side) != "undefined" && adcall_side!='' && adcall_side!=null)
{
	adcall_side=parseInt(adcall_side);
}
else
{
	adcall_side=5;
}
//move function
var adcall_drag_=false;
var adcall_D=new Function('obj','return document.getElementById(obj);');
var adcall_IE=new Function('','if(navigator.appName.indexOf("Explorer")>=0)return 1;if(navigator.appName.indexOf("Netscape")>=0)return 2');
function adcall_move_bar(obj){
	adcall_D(obj).onmousedown=function(e){
		adcall_drag_=true
		with(this){
			style.position="absolute";temp1=offsetLeft;temp2=offsetTop;
		    if(adcall_IE()==1){
			  adcall_x=event.clientX;adcall_y=event.clientY
			  document.onmousemove=function(e){
			   if(adcall_drag_==false)return false 
				 with(this){style.left=temp1+event.clientX-adcall_x+"px";style.top=temp2+event.clientY-adcall_y+"px"} 
				 }
		  } 
		  if(adcall_IE()==2){adcall_x=e.pageX;adcall_y=e.pageY;
			  document.onmousemove=function(e){ 
					if(adcall_drag_==false)return false 
				 with(this){style.left=temp1+e.pageX-adcall_x+"px";style.top=temp2+e.pageY-adcall_y+"px"} 
				 }
		  }
	}
	document.onmouseup=new Function("adcall_drag_=false") 
	}
}
// float functon
var adcall_lastScrollY_1=0;
var adcall_lastScrollY_2=0;
function adcall_floatbar(floaObj,floaType){
 var diffY;
 if (document.documentElement && document.documentElement.scrollTop) {
  diffY = document.documentElement.scrollTop;
 } else if (document.body) {
  diffY = document.body.scrollTop;
 } else {/*Netscape stuff*/}
 if(floaType == 0){
     percent = 0.2*(diffY-adcall_lastScrollY_1);
 }else{
	 percent = 0.2*(diffY-adcall_lastScrollY_2); 
 }

	if(percent>0) {
	    percent=Math.ceil(percent);
	} else {
	    percent=Math.floor(percent);
	}
	if(document.getElementById(floaObj)){
	    document.getElementById(floaObj).style.top=parseInt(document.getElementById(floaObj).style.top)+percent+"px";
	}

	if(floaType==0){
	    adcall_lastScrollY_1=adcall_lastScrollY_1+percent;
	}else{
	    adcall_lastScrollY_2=adcall_lastScrollY_2+percent;
	}

}
//浮动窗口
suspendcode="<DIV id=\"master_call\"style='POSITION:absolute;z-index:9999;";
if(parseInt(adcall_lr)==1)
	suspendcode +="right:"+adcall_side+"px;";
else 
	suspendcode +="left:"+adcall_side+"px;";
suspendcode +="TOP:"+adcall_y+"px;cursor:hand;'>";
document.write(suspendcode);
//document.write(suspendcode);
document.write('<table border=0 width=130 height=230 cellspacing=0 cellpadding=0><a href="http://manage.adcall.com.cn/WebCall/'+stat+'?wid='+adcall_no+'" target=\"_blank\"><img src="'+adcall_img+'/5.gif" border=0 target=\"_blank\"/></a>');

document.write('</table></a></div>');


function show_adcall_win()
{
	var msg="请输入您自己的电话号码";
	if(getCookie("cbnum")!=null)
	{
		msg=getCookie("cbnum");
	}
	
	var adcall_show_win_code = "<div style=\" width:335px; height:141px; background:url("+adcall_img+"kefu_zdyq.gif) no-repeat;\"><div class=\"zdyq_x\"><table style=\"width:334px; height:141px; background:url("+adcall_img+"/yaoqingbg.gif) no-repeat; overflow:hidden;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" name=\"sf\"><tr><td width=\"13\" height=\"32\">&nbsp;</td> <td width=\"209\">&nbsp;</td> <td width=\"112\"><a href='javascript:;;' onclick=\"adcall_closeDiv('adcall_show_win');\"><img src="+host + "/images/gaunbi.gif width=21 height=20 style=\"float:right; border:0px;\"/></a>&nbsp;</td></tr> <tr><td height=\"14\">&nbsp;</td> <td align=\"left\" colspan=\"2\" style=\"font-size:14px;float:left; color:#090; font-weight:bold;\">"+adcall_name+"<br /></td> </tr> <tr> <td height=\"14\">&nbsp;</td><td style=\"font-size:14px; color:#000; font-weight:bold;\">&nbsp;&nbsp;&nbsp;&nbsp;邀请与您免费电话沟通！</td> <td>&nbsp;</td></tr><tr><td>&nbsp;</td> <td colspan=\"2\" align=\"left\" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"http://manage.adcall.com.cn/WebCall/"+stat+"?wid="+adcall_no+"\" target=\"_blank\"><img src=\""+adcall_img+"/jsyaoqing.jpg\" border=\"0\" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=\"javascript:;;\"><img src=\""+adcall_img+"/fanqin.jpg\" onclick=\"adcall_closeDivcenter('adcall_show_win')\" border=\"0\" /></a></td></tr></table></div></div>";

	var bar_div ;
	if(document.getElementById('adcall_show_win')!=null)
	{
		bar_div = document.getElementById("adcall_show_win");
	}
	else
		bar_div = document.createElement("div");
	bar_div.id = "adcall_show_win";
	
	bar_div.style.cssText = "position:absolute;top:"+f_w_t+"px;left:"+f_w_l+"px;width:409px;height:200px;overflow:hidden;text-align:center;line-height:22px;z-index:9999;cursor:move;";

	bar_div.innerHTML = adcall_show_win_code;

	document.body.appendChild(bar_div);
	window.setInterval("adcall_floatbar('adcall_show_win',1)",1);
}		
function adcall_closeDiv(Divobj){   
	adcall_D(Divobj).style.display = "none";   //删除
}
function clear_num(i)
{
	if(i.value=="请输入您自己的电话号码")
		i.value="";
	i.style.color="#cb3c2d";
}
//check form
function adcall_checkCB()
{
	if (document.cb.cb_num.value==""){alert("请输入您的电话号码");return false;}
	if (isNaN(document.cb.cb_num.value) && document.cb.cb_num.value.indexOf("-")==-1){alert("电话号码只能输入数字");return false;}
	setTimeout("document.cb.cb_sub.disabled=false;",8000);
	setTimeout("document.cb.cb_num.disabled=false;",8000);
}

function adcall_closeDivcenter(Divobj)
{
//adcall_D(Divobj).style.display = "none";
	adcall_D(Divobj).style.display = "none"; 
//setTimeout("adcall_D('adcall_show_win').style.display ='';",15000);
	}

function adcall_init()
{
	//if(typeof(adcall_fs)!="undefined" && adcall_fs > 0){
	//	 window.setTimeout("show_adcall_bar();",adcall_fs);
	//}
	if(typeof(adcall_ws)!="undefined" && adcall_ws > 0){
		 window.setTimeout("show_adcall_win();",adcall_ws);
	}
}


//页面加载完后再执行
document.onreadystatechange = function(){   
	if(document.readyState=="complete")   
    {   
        //alert('加载完毕'); 
		adcall_init();
    }
}

//页面尺寸更改
window.onresize = function(){
	if(document.getElementById('adcall_show_win')!=null && adcall_D("adcall_show_win").style.display != "none")
	{
		
		ad_pagesize = getPageSize();
	
		f_w_t = parseInt(ad_pagesize[3]/2 -100);
		f_w_l = parseInt(ad_pagesize[0]/2 -200);
		
		show_adcall_win();
	}
}
function setCookie(name,value){ 
	var Days = 60; //cookie 将被保存两个月 
	var exp = new Date(); //获得当前时间 
	exp.setTime(exp.getTime() + Days*24*60*60*1000); //换成毫秒 
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
} 

function getCookie(name){ 
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); 
	if(arr != null) 
	return unescape(arr[2]); 
	return null; 

} 

function delCookie(name){ 
	var exp = new Date(); //当前时间 
	exp.setTime(exp.getTime() - 1); 
	var cval=getCookie(name); 
	if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString(); 
}


//关闭
function CloseAdCall()
{
	document.getElementById("master_call").style.display='none';
}
lastScrollY=0;
function heartBeat()
{
	var diffY;
	if (document.documentElement && document.documentElement.scrollTop)
		diffY = document.documentElement.scrollTop;
	else if (document.body)
	diffY = document.body.scrollTop;
	else{/*Netscape stuff*/}
	percent=.1*(diffY-lastScrollY); 
	if(percent>0)percent=Math.ceil(percent); 
	else percent=Math.floor(percent); 
	document.getElementById("master_call").style.top=parseInt(document.getElementById("master_call").style.top)+percent+"px";
	lastScrollY=lastScrollY+percent;
}


window.setInterval("heartBeat()",1);
heartBeat();
