
var UrgeS_KeyN="urgeStay";

function urgePutCookie(nm,val){
	var exp="";
	var y=360*5;
		var dt=new Date(); 
		dt.setTime(dt.getTime()+(y*86400000)); 
		exp="; expires="+dt.toGMTString();
	
	document.cookie=nm+"="+escape(val)+exp+";path=/;domain=hc360.com"; 
}   
    
function urgeGetCookie(nm){ 
	var m=""; 
	if(window.RegExp){ 
		var re=new RegExp(";\\s*"+nm+"=([^;]*)","i"); 
		m=re.exec(';'+document.cookie); 
	} 
	return(m?unescape(m[1]):"");
}
function urgeStayWin(openType){
	var domain=document.location.host;
	var oType=openType.split(";");
	if(oType[0]=="1" ){
		window.open("http://www.hc360.com/index.htm?urgestay=1");
	}else if(oType[0]=="2" ){
		window.open("http://www.hc360.com/urgestay.html?urgearea=homepage",'',"width=570; height=210px");
	}else{
			var domainArry=domain.split(".");
			
			if(oType[0]=="3"){
				
				window.open("http://www.secu.hc360.com/js/index/urgestay.html?urgearea="+domainArry[domainArry.length-3],'',"width=502px; height=278px");
			}else if(oType[0]=="4"){
				window.open("http://www."+domainArry[1]+".hc360.com/index.html?urgestay=1");
			}
			
	}
}

function thisDocWin(){
	var domain=document.location.host;
	if(domain=="detail.b2b.hc360.com" || domain=="b2b.hc360.com" 
		|| domain=="www.search.hc360.com" || domain=="list.b2b.hc360.com"
		|| domain=="activity.b2b.hc360.com"
		|| domain=="info.b2b.hc360.com" || domain=="info.news.hc360.com"
		|| domain=="info.ceo.hc360.com" || domain=="info.news.hc360.com"
		|| domain=="info.biz.hc360.com" || domain=="info.finance.hc360.com" 
		|| domain=="sou.hc360.com" ){
		return "1";
	}else if(domain=="www.hc360.com" || domain=="hc360.com" ){
		return "2";
	}else{
			var domainArry=domain.split(".");

			if(domainArry.length==3 || (domainArry.length==4 && domainArry[0]=="www")){
				return "3;"+domainArry[domainArry.length-3];
			}else if(domainArry.length==4 && domainArry[0]=="info"){
				return "4;"+domainArry[1];
			
			}
			
	}
}

if(document.location.href.indexOf("http://www.search.hc360.com/adpage.cgi?w=")>-1){
	
	urgePutCookie(UrgeS_KeyN,"1");
}
	var thisOrder=0;
	var thisWin="";
if( urgeGetCookie(UrgeS_KeyN)==null || urgeGetCookie(UrgeS_KeyN)=="" || urgeGetCookie(UrgeS_KeyN)!="1"){
	

	if(urgeGetCookie(UrgeS_KeyN)==null || urgeGetCookie(UrgeS_KeyN)=="" ){
		thisOrder = 0;
		thisWin=thisDocWin();
	}else{
		thisOrder=parseInt(urgeGetCookie(UrgeS_KeyN).split(";")[0])+1;
		thisWin=urgeGetCookie(UrgeS_KeyN).split(";")[1];
		
			if(thisWin!="2" && thisWin!="3"){
				thisWin=thisDocWin();
			}else if(thisWin=="2" || thisDocWin()=="2"){
				thisWin="2";
			}else if(thisWin=="3"){
				thisWin="3;"+urgeGetCookie(UrgeS_KeyN).split(";")[2];
			}
			if(thisDocWin()=="1" && thisWin!="2"){
				thisWin="1";
			}
	}
	
	urgePutCookie(UrgeS_KeyN,thisOrder+";"+thisWin);
	 
		var thisOrder=urgeGetCookie(UrgeS_KeyN).split(";")[0];
		window.onbeforeunload = function(event)
			{
				
				event = event || window.event;
				window.status=(event.clientY+"||"+event.clientX+"||"+document.body.clientWidth);
				
	  if(urgeGetCookie(UrgeS_KeyN)!="1"  && (event.clientX>document.body.clientWidth  || event.clientY<0 ||event.altKey || event.ctrlKey) && thisOrder+""==urgeGetCookie(UrgeS_KeyN).split(";")[0]){
	  urgePutCookie(UrgeS_KeyN,"1");
	  urgeStayWin(thisWin);
		}
		}
	
}
