var _isIE = !!document.all ? true : false;
function _$(arg)
{
	if(typeof(arg).toLowerCase() == "object")
	{
		return arg;
	}
	return document.getElementById(arg);
}
function selectPro(objs,i)
{
	document.getElementById("orderFrame").contentWindow.selectPro(objs,i);
}
function pro(_id,_name,_price,_mprice)
{
	this.id = _id;
	this.name = _name;
	this.price = _price;
	this.mprice = _mprice;
}
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;
}
function scrollBox(arg)
{
	var _self = this;
	this.speed = 1;
	this.time = 10;
	this.stop = false;
	this.box = _$(arg);
	this.box.style.overflow = "hidden";
	this.dir = "left";
	this.nowStep = 0;
	this.tarStep = 0;
	this.init = function()
	{
		var tmpNodes = this.box.innerHTML;
		if(this.dir == "left" || this.dir == "right")
		{
			var _tns = getNodes(this.box);
			this.tarStep = (parseInt(_tns[0].offsetWidth) * _tns.length);
			this.box.innerHTML = "";
			var longBox = document.createElement("ul");
			this.box.appendChild(longBox);
			longBox.innerHTML = tmpNodes + tmpNodes;
			longBox.style.width = (this.tarStep+10+parseInt(this.box.offsetWidth)) + "px";
			longBox.style.height = this.box.offsetHeight + "px";
		}
		else
		{
			var _tns = getNodes(this.box);
			this.tarStep = (parseInt(_tns[0].offsetHeight) * _tns.length);
			this.box.innerHTML = this.box.innerHTML + this.box.innerHTML;
		}
		if(this.dir == "left")
		{
			setInterval(function()
			{
				if(!_self.stop)
				{
					if(_self.nowStep >= _self.tarStep)
					{
						_self.nowStep = 0;
					}
					else
					{
						_self.nowStep = _self.nowStep + _self.speed;
					}
					_self.box.scrollLeft = _self.nowStep;
				}
			},this.time);
		}
		else
		{
			setInterval(function()
			{
				if(!_self.stop)
				{
					if(_self.nowStep >= _self.tarStep)
					{
						_self.nowStep = 0;
					}
					else
					{
						_self.nowStep = _self.nowStep + _self.speed;
					}
					_self.box.scrollTop = _self.nowStep;
				}
			},this.time);
		}
		this.box.onmouseover = function()
		{
			_self.stop = true;
		}
		this.box.onmouseout = function()
		{
			_self.stop = false;
		}
	}
}

function kfObj(_type,key)
{
	this.type = _type.toLowerCase();
	this.key = key;
	this.getHref=function()
	{
		if(this.type == "qq")
		{
			return 'http://sighttp.qq.com/cgi-bin/check?sigkey='+key+'" onclick="return _clickQQ(\''+key+'\')';
		}
		return '/rtc.html#'+_type+'='+key;
	}
	this.getLink= function()
	{
		switch(this.type)
		{
			case "qq" : return '<a href="http://sighttp.qq.com/cgi-bin/check?sigkey='+key+'" onclick="return _clickQQ(\''+key+'\')" target="_blank"><img src="http://www.51scp.com/public/qq.gif" />QQ客服</a>';
				break;
			case "msn" : return '<a href="http://www.51scp.com/public/rtc.html#'+_type+'='+key+'" target="_blank"><img src="http://www.51scp.com/public/msn.gif" />MSN客服</a>';
				break;
			case "ww" : return '<a href="http://www.51scp.com/public/rtc.html#'+_type+'='+key+'" target="_blank"><img src="http://www.51scp.com/public/ww.gif" />旺旺客服</a>';
				break;
		}
	}
}

var _kf;
function kf(pkf,delay,popTime,locationStr,popText,kfs,kfText)
{
	_kf = this;
	var _self = this;
	
	kflist='<li style="margin:0 5px;border-bottom:1px dashed #CCC;line-height:30px;height:30px;padding:7px 0 0 0">'+pkf.getLink()+'</li>';
	if(kfs != undefined)
	{
		for(var i=0,j=kfs.length;i<j;i++)
		{
			kflist+='<li style="margin:0 5px;border-bottom:1px dashed #CCC;line-height:30px;height:30px;padding:7px 0 0 0">'+kfs[i].getLink()+'</li>';
		}
	}
	if(pkf.type.toLowerCase() == "qq")
	{
		document.write('<div id="kfBox" style="display:none;position:absolute;left:0;top:200px;height:214px;z-index:999999;width:98%;"><div style="background:url(http://www.51scp.com/public/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
	{
		document.write('<div id="kfBox" style="display:none;position:absolute;left:0;top:200px;height:214px;z-index:999999;width:98%;"><div style="background:url(http://www.51scp.com/public/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="/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;background:url(http://www.51scp.com/public/kflbox.png) no-repeat;width:100px;height:22px;position:absolute;top:200px;right:20px;padding-top:22px;"><ul style="background:#FFF;padding:5px 0;text-align:center;border-left:1px solid #81d3bd;border-right:1px solid #81d3bd;">'+kflist+'</ul><p style="padding:5px;margin:0;border:1px solid #81d3bd;border-top:none;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.kfBox.style.width = document.documentElement.clientWidth;+"px";
		_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.body.scrollTop) + 200) + "px";
		});
	}
	else
	{
		document.addEventListener("scroll",function()
		{
			_self.tarBox.style.top = (parseInt(document.body.scrollTop) + 200) + "px";
		},false);
	}	
	this.ipArea = function(str)
	{
		document.getElementById("kfText").innerHTML = locationStr.replace("$location$",str.replace(/ADSL|电信|网通|联通|铁通|中国移动|移动|.+省/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 WarningBox(tit,arg,closeFun)
{
	var _self = this;
	this.isRun = false;
	this.box;
	document.write('<div id="warningBox" style="position:absolute;bottom:-1000px;width:150px;height:200px;right:0;height:200px;z-index:999999;"><h3><span id="closeWarningObj" onclick="this.close()" style="float:right;cursor:pointer;">关闭<\/span>'+tit+'<\/h3><div>'+arg+'<\/div><\/div>');
	window.setTimeout(function()
	{
		_self.box = _$("warningBox");
		_self.init();
		_$("closeWarningObj").close = function()
		{
			_self.isRun = false;
			_self.box.style.display="none";
			if(closeFun != undefined)
			{
				(closeFun)();
			}
		}
	},1000);
	this.init = function()
	{
		this.goI = this.box.offsetHeight;
		this.box.style.bottom = "-" + this.goI + "px";
		this.box.style.display = "block";
		this.set = window.setInterval(function()
		{
			if(_self.goI > 1)
			{
				_self.box.style.bottom = "-" + (--_self.goI) + "px";
			}
			else
			{
				window.clearInterval(_self.set);
				_self.isRun = true;
			}
		},20);
		this.tmpHeight = (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight) - this.box.offsetHeight;
		if(_isIE)
		{
			window.attachEvent("onscroll",function()
			{
				if(_self.isRun)
				{
					_self.box.style.top = (parseInt(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + _self.tmpHeight) + "px";
				}
			});
		}
		else
		{
			document.addEventListener("scroll",function()
			{
				if(_self.isRun)
				{
					_self.box.style.top = (parseInt(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + _self.tmpHeight) + "px";
				}
			},false);
		}
	}
	this.reload = function(t)
	{
		setInterval(function()
		{
			_self.isRun = false;
			_self.init();
		},t*1000);
	}
}

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 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 unloadPop(name,url)
{
	var _self = this;
	this.lastClickTime = 0;
	this.AddFav = function()
	{
		AddFav(name,url);
	}
	this.unload = function()
	{
		if(true)
		{
			if(new Date().getTime()-_self.lastClickTime > 200)
			{
				_self.AddFav();
			}
		}
	}
	document.onclick = function()
	{
		_self.lastClickTime = new Date().getTime();
	}
	document.body.onbeforeunload = function(){_self.unload()};
}

var _favPop;
function FavPop(name,title,intro,url)
{
	_favPop = this;
	var _self = this;
	document.write('<div id="favBox" style="display:none;position:absolute;top:200px;height:214px;z-index:999999;width:98%;"><div style="background:url(http://www.51scp.com/public/kf.png) no-repeat;position:relative;width:436px;height:214px;margin:0 auto;"><div style="position:absolute;top:110px;left:235px;padding-right:10px;">'+intro+'</div><div style="fontSize:12px;padding:75px 5px 0 130px;">'+title+'</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;" href="#" onclick="this.close();return AddFav(\''+name+'\',\''+url+'\');" id="favAddObj">是</a><span id="favCloseObj" 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>');
	this.favBox = document.getElementById("favBox");
	document.getElementById("favCloseObj").close = function()
	{
		_self.close();
	}
	document.getElementById("favAddObj").close = function()
	{
		_self.close();
	}
	if(_isIE)
	{
		window.attachEvent("onscroll",function()
		{
			_self.favBox.style.top = (parseInt(document.documentElement.scrollTop) + 200) + "px";
		});
	}
	else
	{
		document.addEventListener("scroll",function()
		{
			_self.favBox.style.top = (parseInt(document.documentElement.scrollTop) + 200) + "px";
		},false);
	}
	this.show = function()
	{
		_self.favBox.style.display = "block";
		_kf.close();
	}
	this.close = function()
	{
		_self.favBox.style.display = "none";
	}
}

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 scrollBox2(arg)
{
	var _self = this;
	this.stopTime = 0;
	this.speed = 1;
	this.time = 10;
	this.stop = false;
	this.box = _$(arg);
	this.box.style.overflow = "hidden";
	this.dir = "left";
	this.nowStep = 0;
	this.tarStep = 0;
	this.oneLeng = 0;
	this.maxShowLeng = 0;
	this.init = function()
	{
		var tmpNodes = this.box.innerHTML;
		if(this.dir == "left" || this.dir == "right")
		{
			var _tns = getNodes(this.box);
			this.oneLeng = parseInt(_tns[0].offsetWidth);
			this.tarStep = this.oneLeng * _tns.length;
			this.box.innerHTML = "";
			var longBox = document.createElement("ul");
			this.box.appendChild(longBox);
			longBox.innerHTML = tmpNodes + tmpNodes;
			longBox.style.width = (this.tarStep+10+parseInt(this.box.offsetWidth)) + "px";
			longBox.style.height = this.box.offsetHeight + "px";
			this.maxShowLeng = this.box.offsetWidth;
		}
		else
		{
			var _tns = getNodes(this.box);
			this.oneLeng = parseInt(_tns[0].offsetHeight);
			this.tarStep = this.oneLeng* _tns.length;
			this.box.innerHTML = this.box.innerHTML + this.box.innerHTML;
			this.maxShowLeng = this.box.offsetHeight;
		}
		var _stop = false;
		var _stopTime = 0;
		if(this.dir == "left")
		{
			setInterval(function()
			{
				if(!_self.stop)
				{
					if(!_stop)
					{
						if(_self.nowStep >= _self.tarStep)
						{
							_self.nowStep = 0;
						}
						else
						{
							_self.nowStep = _self.nowStep + _self.speed;
						}
						_self.box.scrollLeft = _self.nowStep;
						//计长度
						if(_self.nowStep % _self.maxShowLeng == 0)
						{
							_stop = true;
						}
					}
					else
					{
						//计时;
						_stopTime += _self.time;
						if(_stopTime >= _self.stopTime)
						{
							_stopTime = 0;
							_stop = false;
						}
					}
				}
			},this.time);
		}
		else
		{
 			setInterval(function()
			{
				if(!_self.stop)
				{
					if(!_stop)
					{
						if(_self.nowStep >= _self.tarStep)
						{
							_self.nowStep = 0;
						}
						else
						{
							_self.nowStep = _self.nowStep + _self.speed;
						}
						_self.box.scrollTop = _self.nowStep;
						//计长度
						if(_self.nowStep % _self.maxShowLeng == 0)
						{
							_stop = true;
						}
					}
					else
					{
						//计时;
						_stopTime += _self.time;
						if(_stopTime >= _self.stopTime)
						{
							_stopTime = 0;
							_stop = false;
						}
					}
				}
			},this.time);
		}
		this.box.onmouseover = function()
		{
			_self.stop = true;
		}
		this.box.onmouseout = function()
		{
			_self.stop = false;
		}
	}
}
function ajax()
{
	var xmlObj = false;
	var ObjSelf = this;
	if(document.all)
	{
		try
		{
			xmlObj=new ActiveXObject("MSXML2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlObj=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e2)
			{
				xmlObj=false;
			}
		}
	}
	else
	{
		try
		{
			xmlObj = new XMLHttpRequest;
		}
		catch(e3)
		{
			xmlObj=false;
		}
	}	
	if(!xmlObj)
	{
		throw new Error("无法创建XMLHTTP对象!");
		return false;
	}
	this.method="GET";
	this.url;
	if(arguments.length > 0)
	{
		this.url = arguments[0];
	}	
	this.cache = true;
	this.async = true;
	this.content = "";
	this.callBackObj = null;
	this.callBack;
	this.send = function()
	{
		if(!this.method||!this.url||!this.async)
		{
			throw new Error("Ajax arguments Error!");
			return false;
		}
		if(!this.cache)
		{
			if(this.url.indexOf("?")>0)
			{
				var t=new Date().getTime();
				this.url += "&ct="+t;
			}
			else
			{
				var t=new Date().getTime();
				this.url += "?ct="+t;
			}
		}
		xmlObj.open(this.method, this.url, this.async);
		if(this.method=="POST")
		{
			xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}
		xmlObj.onreadystatechange = function()
		{
			if(xmlObj.readyState==4)
			{
				if(xmlObj.status==200)
				{
					if(ObjSelf.callBackObj != null)
					{
						ObjSelf.callBack(xmlObj,ObjSelf.callBackObj);
					}
					else
					{
						ObjSelf.callBack(xmlObj);
					}
				}
				else if(xmlObj.status==204 || xmlObj.status==205)
				{
					ObjSelf.callBack("HTTP status" + xmlObj.status);
				}
				else
				{
					throw new Error("HTTP ERROR : " + xmlObj.status);
					return false;
				}
			}
		}
		if(this.method == "POST")
		{
			xmlObj.send(this.content);
		}
		else
		{
			xmlObj.send(null);
		}
	}
}