var _isIE = !!document.all ? true : false;
var _isXHTML = document.compatMode == "CSS1Compat" ? true :false;
var _jsDir = "http://public.7lk.cn/js/"
function _$(arg)
{
	if(typeof(arg).toLowerCase() == "object")
	{
		return arg;
	}
	return document.getElementById(arg);
}

function getNodes(pNode)
{
	if(pNode.nodeType == 3)
	{
		return null;
	}
	var node,nodes = new Array();
	for(var i=0;node= pNode.childNodes[i];i++)
	{
		if(node.nodeType == 1)
		nodes.push(node);
	}
	return nodes;
}




var FFextraHeight = 0;
 if(window.navigator.userAgent.indexOf("Firefox")>=1)
 {
  FFextraHeight = 16;
  }
 function reSetCWinHeight(iframe)
 {
   if(iframe && !window.opera)
   {
     iframe.style.display = "block";
      if(iframe.contentDocument && iframe.contentDocument.body.offsetHeight)
      {
        //iframe.height = iframe.contentDocument.body.offsetHeight + FFextraHeight;
      }
      else if (iframe.Document && iframe.Document.body.scrollHeight)
      {
        iframe.height = iframe.Document.body.scrollHeight;
      }
   }
 }

function AddFav(name,url)
{
	url = url == undefined? 'http:\/\/' + window.location.host : url;
	if(window.sidebar)
	{
		window.sidebar.addPanel(name, url, "");
	}
	else if(document.all)
	{
		window.external.addFavorite(url,name);
	}
	return false;
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate);
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1)
			{
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
function getRef()
{
	if(document.referrer != "" && document.referrer != null && document.referrer != undefined)
	{
		var refHost = document.referrer.replace(/^(.+?\/\/)([^\/\\]+)(.*)/gi,"$2");
		var refUrl = RegExp.$1 + RegExp.$2 + RegExp.$3;
		if(!/7lk\.cn/i.test(refHost))
		{
			var oldRef = getCookie("ref");
			oldRef = oldRef.replace(/^([^\n]+\n[^\n]+\n)[\s\S]*/i,"$1");
			refUrl = (new Date().getTime() + "|" + refUrl + "\n" + oldRef).replace(/\n\n/g,"\n").replace(/(.+\n)\1/gi,"$1").replace(/\n$/g,"");
			setCookie("ref",refUrl,365);
			return refUrl;
		}
	}
	return getCookie("ref");
}

function kfObj(_type,id,name,key)
{
	this.id = id;
	this.type = _type.toLowerCase();
	this.key = key;
	name = name==undefined? '' : name;
	this.getHref=function()
	{
		if(this.type == "qq")
		{
			return 'http://sighttp.qq.com/cgi-bin/check?sigkey='+key+'" onclick="return _clickQQ(\''+key+'\')';
		}
		else if(this.type == "bqq")
		{
			return 'http://b3.qq.com/webc.htm?new=0&sid='+id+'&o=&q=7" onclick="return_cbQQ(\''+id+'\',this)';
		}
		return _jsDir +'/kf/rtc.html#'+_type+'='+id;
	}
	this.getLink= function()
	{
		switch(this.type)
		{
			case "bqq" : return '<a href="http://b3.qq.com/webc.htm?new=0&sid='+id+'&o=&q=7" onclick="return_cbQQ(\''+id+'\',this)" target="_blank"><img src="http://wpa.qq.com/pa?p=1:'+id+':4" />'+(name==''?'QQ客服':name)+'</a>';
				break;
			case "qq" : return '<a href="http://sighttp.qq.com/cgi-bin/check?sigkey='+key+'" onclick="return _clickQQ(\''+key+'\')" target="_blank"><img src="http://wpa.qq.com/pa?p=1:'+id+':4" />'+(name==''?'QQ客服':name)+'</a>';
				break;
			case "msn" : return '<a href="'+_jsDir+'/kf/rtc.html#'+_type+'='+id+'" target="_blank"><img src="'+_jsDir+'/kf/msn.gif" />'+(name==''?'MSN客服':name)+'</a>';
				break;
			case "ww" : return '<a href="'+_jsDir+'/kf/rtc.html#'+_type+'='+id+'" target="_blank"><img src="http://amos1.taobao.com/online.ww?v=2&uid='+id+'&s=2" />'+(name==''?'旺旺客服':name)+'</a>';
				break;
		}
	}
}

var _kf;
function kf(pkf,delay,popTime,locationStr,popText,kfs,kfText)
{
	_kf = this;
	var _self = this;
	
	pkf = new kfObj("bqq","800010133","在线客服","");
	locationStr = '来自$location$的朋友,欢迎您的到来!很高兴为您服务!';
	popText = '欢迎您的光临,请问有什么可以帮到您吗?';
	kfText='工作时间<br/>周一至周五<br/>8:30~23:30<br/>周六至周日<br/>10:00~16:30';

	kflist='<a href="'+pkf.getHref()+'" target="_blank" title="'+pkf.name+'"><img src="'+_jsDir+'/kf/outkf.png" /></a>';
	if(pkf.type.toLowerCase() == "qq")
	{
		document.write('<div id="kfBox" style="display:none;position:absolute;top:200px;height:214px;z-index:999999;width:98%;left:0;"><div style="background:url('+_jsDir+'/kf/kf.png) no-repeat;position:relative;width:436px;height:214px;margin:0 auto;"><div style="position:absolute;top:110px;left:235px;padding-right:10px;">'+popText+'</div><div style="fontSize:12px;padding:75px 5px 0 130px;" id="kfText"></div><a style="position:absolute;display:block;width:80px;height:25px;text-align:center;color:#FFF;line-height:25px;font-size:16px;top:165px;left:240px;" target="_blank" href="http://sighttp.qq.com/cgi-bin/check?sigkey='+pkf.key+'" onclick="this.close();return _clickQQ(\''+pkf.key+'\')" id="kfClickObj">开始交谈</a><span id="kfCloseObj" style="position:absolute;cursor:pointer;display:block;width:80px;height:25px;text-align:center;color:#FFF;line-height:25px;font-size:16px;top:165px;left:335px;" onclick="this.close()">待会再说</span></div></div>');
	}
	else if(pkf.type.toLowerCase() == "bqq")
	{
		document.write('<div id="kfBox" style="display:none;position:absolute;top:200px;height:214px;z-index:999999;width:98%;left:0;"><div style="background:url('+_jsDir+'/kf/kf.png) no-repeat;position:relative;width:436px;height:214px;margin:0 auto;"><div style="position:absolute;top:110px;left:235px;padding-right:10px;">'+popText+'</div><div style="fontSize:12px;padding:75px 5px 0 130px;" id="kfText"></div><a style="position:absolute;display:block;width:80px;height:25px;text-align:center;color:#FFF;line-height:25px;font-size:16px;top:165px;left:240px;" target="_blank" href="http://b3.qq.com/webc.htm?new=0&sid='+pkf.id+'&o=&q=7" onclick="this.close();return_cbQQ(\''+pkf.id+'\',this)" id="kfClickObj">开始交谈</a><span id="kfCloseObj" style="position:absolute;cursor:pointer;display:block;width:80px;height:25px;text-align:center;color:#FFF;line-height:25px;font-size:16px;top:165px;left:335px;" onclick="this.close()">待会再说</span></div></div>');
	}
	else
	{
		document.write('<div id="kfBox" style="display:none;position:absolute;top:200px;height:214px;z-index:999999;width:98%;left:0;"><div style="background:url('+_jsDir+'/kf/kf.png) no-repeat;position:relative;width:436px;height:214px;margin:0 auto;"><div style="position:absolute;top:110px;left:235px;padding-right:10px;">'+popText+'</div><div style="fontSize:12px;padding:75px 5px 0 130px;" id="kfText"></div><a style="position:absolute;display:block;width:80px;height:25px;text-align:center;color:#FFF;line-height:25px;font-size:16px;top:165px;left:240px;" target="_blank" href="'+_jsDir+'/kf/rtc.html#'+pkf.type+'='+pkf.key+'" onclick="this.close();" id="kfClickObj">开始交谈</a><span id="kfCloseObj" style="position:absolute;cursor:pointer;display:block;width:80px;height:25px;text-align:center;color:#FFF;line-height:25px;font-size:16px;top:165px;left:335px;" onclick="this.close()">待会再说</span></div></div>');
	}
	document.write('<div id="kfLBox" style="display:none;position:absolute;top:200px;right:20px;">'+kflist+'<p style="padding:5px;margin:10px 0 0 0;border:1px solid #81d3bd;text-align:center;background:#FFF;">'+kfText+'</p></div>');
	this.kfBox = document.getElementById("kfBox");
	this.kfLbox = document.getElementById("kfLBox");
	this.tarBox = this.kfBox;
	document.getElementById("kfCloseObj").close = function()
	{
		_self.close();
	}
	document.getElementById("kfClickObj").close = function()
	{
		_self.close();
	}
	this.close = function()
	{
		_self.tarBox = _self.kfLBox;
		_self.kfBox.style.display = "none";
		_self.kfLBox.style.display = "block";
		_self.tarBox.style.top = (parseInt(document.documentElement.scrollTop) + 200) + "px";
	}
	this.show = function()
	{
		_self.tarBox = _self.kfBox;
		_self.kfBox.style.display = "block";
		_self.kfLBox.style.display = "none";
		_self.tarBox.style.top = (parseInt(document.documentElement.scrollTop) + 200) + "px";
	}
	delay = delay == undefined ? 0 : delay;
	setTimeout(function()
	{
		_self.show();
		if(popTime != undefined)
		{
			setInterval(_self.show,popTime*1000);
		}
	},delay*1000);
	if(_isIE)
	{
		window.attachEvent("onscroll",function()
		{
			_self.tarBox.style.top = (parseInt(document.documentElement.scrollTop) + 200) + "px";
		});
	}
	else
	{
		document.addEventListener("scroll",function()
		{
			_self.tarBox.style.top = (parseInt(document.documentElement.scrollTop) + 200) + "px";
		},false);
	}	
	this.ipArea = function(str)
	{
		document.getElementById("kfText").innerHTML = locationStr.replace("$location$",str.replace(/ADSL|电信|网通/gi,"").replace(/CZ88\.NET/gi,"未知地区"));
	}
	document.write("<script charset='utf-8' src='http://ip.7lk.cn/iplocation.js.aspx?t="+new Date().getTime()+"'></script>")
}

function ipArea(str)
{
	_kf.ipArea(str.replace(/ $/,""));
}
function _clickQQ(skey)
{
	var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()+'&sigkey='+skey;
	var oldscript=document.getElementById('testJs');
	var newscript=document.createElement('script');
	newscript.setAttribute('type','text/javascript');
	newscript.setAttribute('id', 'testJs');
	newscript.setAttribute('src',tempSrc);
	if(oldscript == null)
	{
		document.body.appendChild(newscript);
	}
	else
	{
		oldscript.parentNode.replaceChild(newscript, oldscript);
	}
	return false;
}

var IsInstallQQ = false;
try
{
	var xmlhttp=new ActiveXObject("TimwpDll.TimwpCheck");    
	IsInstallQQ = true;            
}catch(e){}
function return_cbQQ(id,obj)
{
	if(IsInstallQQ)
	{
		obj.target="_self";
		obj.href = 'tencent://message/?uin='+ id + '&Site=&Menu=yes&crm=1';
		return false;
	}
	window.open('http://b3.qq.com/webc.htm?new=0&sid='+id+'&o=&q=7', '_blank', 'height=544, width=644,toolbar=no,scrollbars=no,menubar=no,status=no','_blank');
	return false;
}
