String.prototype.endWith=function(oString){  
  var   reg=new   RegExp(oString+"$");  
  return   reg.test(this);  
}
var domain = "http://www.qihuatong.com/";  
var topUrl = [	
		"com","net","com.cn","net.cn","org.cn","gov.cn","ac.cn","bj.cn","sh.cn","tj.cn","cq.cn",
		"jl.cn","hl.cn","js.cn","zj.cn","ah.cn","fj.cn","jx.cn","sd.cn","ha.cn","hb.cn","gd.cn","gx.cn","hi.cn","sc.cn",
		"gz.cn","yn.cn","xz.cn","sn.cn","gs.cn","qh.cn","nx.cn","xj.cn","tw.cn","hk.cn","mo.cn",
		"he.cn","sx.cn","nm.cn","ln.cn","cn","cc","org","biz","info","mobi", "com.tw", "com.hk",	 
		"hk","tw", "io","ac","name","pro","ws","sh","hn","edu","gov","eu","jp","travel","tv","im"];
var opening = 0;
function openEptone(u_id,s_id,typeId,lang,chatstyle){
	if (opening == 1) return ;
	opening = 1;
	var ept_localadd =  encodeURI(document.location);
	ept_localadd = singleEncode(ept_localadd);
	var ept_referUrl = encodeURI(document.referrer);
	ept_referUrl = singleEncode(ept_referUrl);
	if(ept_referUrl ==null){
		ept_referUrl = '';
	}
	var cvalue = "";
	var sstt = "";
for(i=0;i<5;i++){
	var vNum = Math.random();
	vNum = Math.round(vNum*10);
	sstt+=vNum;
}
	var objDate=new Date();
	cvalue = objDate.getMilliseconds()+sstt;
	var cookievalue = getCookie("chatOnlyCookies");
	if(cookievalue == null || cookievalue == ""){
		setCookie("chatOnlyCookies",cvalue);
		cookievalue = cvalue;
	}
	var ept_cookieValue = cookievalue;
	var ept_url = domain+"chat/webChat?u_i="+u_id+"&lang="+lang+"&r_u="+ept_referUrl+"&v_u="+ept_localadd+"&cookie="+ept_cookieValue+"&skin="+chatstyle+"&target=chat";
	
	var newurl = ept_url;
	newurl += "&free=1&s_i="+s_id+"&t_i="+typeId;
	window.open(newurl, "", "width=520,height=442,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no");
	opening = 0;
	
}
function singleEncode(str){ 
	var tempStr = ""; 
	for(i=0;i<str.length;i++){
		var tempSub = str.substr(i,1);
		if(str.charCodeAt(i)>256)
			tempStr += tempSub;
		else
			tempStr += encodeURIComponent(tempSub);
	}
  	return tempStr;   
}
function getCookie(sName) {
	var aCookie = document.cookie.split('; ');
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split('=');
		if (sName == aCrumb[0])
		return unescape(aCrumb[1]);
	}
	return '';
}
function setCookie(name, value, time){
    var nameString = name + '=' + value;
    var expdate = new Date();
    if(time == null || isNaN(time)) time = 60*60*24*365;
    expdate.setTime(expdate.getTime() +  time);
	var expiryString = ' ;expires = '+ expdate.toGMTString();
	var path = " ;path =/";
	
	var domain = "; domain = "+getDomain(""+document.location);
	document.cookie = nameString + expiryString + path + domain;
}
function getDomain(url){ 
	si = 7;
	if (url.indexOf("https://")!=-1){
		si = 8;
	}
	url = url.substring(si, url.length);
	if (url.indexOf("/")==-1){
		url += "/";
	}
	url = url.substring(0, url.indexOf("/"));
	if(url.indexOf(":")!=-1){
		url = url.substring(0, url.indexOf(":"));
	}
	if (isIP(url)){return url;}

	for (i=0; i < topUrl.length; i++){
		
		if (url.endWith(topUrl[i])){
			
			//  eg  sdfsdf.com
			point = 1;
			if (topUrl[i].indexOf(".")){
				point = 2;
			}
			if(url.split(".").length == point)
				return url;
		
			url = url.substring(0, url.indexOf(topUrl[i])-1);
			index = url.lastIndexOf("\.");
			if (index != -1){
				url = url.substring(index+1, url.length);
				return url+"."+topUrl[i];
			}else
				return url;
		}
	}
	return url;
}
function isIP(url){
  var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/;

  if (reg.test(url))
	return true;
  else
	return false;
}