		var unionstore = "0" //是否联合登陆商家,1:是，0：否  
		var loginResult = false;
		var currUserName = "";
		var gourl = "";
		//Interval事件id
	 	var timerID = 0;
	 	var eventEle = null;
	 	
	 	
		function createCoverDiv(){
			var bgObj0=document.createElement("div"); 
			bgObj0.setAttribute("id","divScreenBg");
	        bgObj0.style.position="absolute"; 
	        bgObj0.style.backgroundColor="#000000";
	        if(document.all){
	            bgObj0.style.filter = "alpha(opacity=40)";
	        }else{
	            bgObj0.style.MozOpacity = 0.4;
	            bgObj0.style.opacity = 0.4;
	        }
	        bgObj0.style.top = "0px";   
	        bgObj0.style.left = "0px"; 
	        bgObj0.style.width = "100%"  
	        var s_height = document.body.scrollHeight; 
			if(s_height < window.screen.availHeight){
				s_height=window.screen.availHeight;
			} 
			bgObj0.style.height=s_height+"px"//设置高度 
	        bgObj0.style.zIndex = 1000;
	        document.body.appendChild(bgObj0);
		}		
		
		function showCachLogin(divname){
		   showLoginDiv(divname,650,320);
		}
		
		
		function showLoginDiv(divname,width,height){
		   
	        var cashObj=document.getElementById(divname); 
	       	var w = 0; 
	       	var h = 0;
	       	       	
	       	var ua = navigator.userAgent.toLowerCase();
			var os = new Object();
			os.isFirefox = ua.indexOf ("gecko") != -1;
			os.isOpera = ua.indexOf ("opera") != -1;
			os.isIE = !os.isOpera && ua.indexOf ("msie") != -1;
			os.isSafa = !os.isOpera && ua.indexOf ("safari") != -1;
	      	if(os.isOpera){
	      		w = document.body.clientWidth;
	      		h = document.body.clientHeight;
	      	}else if(os.isFirefox){
	      		w = document.documentElement.clientWidth;
	      		h = document.documentElement.clientHeight;
	      	}else if(os.isIE){
	      		w = document.documentElement.clientWidth;
	      		h = document.documentElement.clientHeight;
	      	}else if(os.isSafa){
	      		w = document.body.clientWidth;
	      		h = document.body.clientHeight;
	      	}
	      	
	        cashObj.style.position="absolute";  
	        if(width == "-1"){ //特殊处理
		       	 cashObj.style.left =  (w-600)/2 + "px"; 
		       	 cashObj.style.width = "auto";  
		         cashObj.style.height ="auto";  
	         }else{
	         	cashObj.style.left =  (w-width)/2 + "px"; 
		       	 cashObj.style.width = width+"";  
		         cashObj.style.height = height + "";
	         }
	        
	        cashObj.style.zIndex = 1001;
	        
	        clearInterval(timerID);
	        
	        timerID = setInterval(function(){moveCachLogin(cashObj,h,os,height);},10);
	        cashObj.style.display="";
	        /*
	        //启用后，将滚动到层所在区域
	        var loginname = document.getElementById("loginname");
			try{
				if(loginname != null){
					loginname.focus();
				}
			}catch(e){}
			*/
		}		
		
		function hiddenCashDiv(){
			var divScreenBg = document.getElementById("divScreenBg");
			if(divScreenBg != null){
				var cashObj = document.getElementById("cashLogin"); 
				clearInterval(timerID);
				cashObj.style.display = "none";
				document.body.removeChild(divScreenBg);
			}
		}

		function moveCachLogin(obj,h,os,oh){
	        if(obj){
	        	var st = 0;
	        	if(os.isOpera || os.isSafa){
	        		st = document.body.scrollTop;
	        	}else{
	        		st = document.documentElement.scrollTop;
	        	}
	        	if(oh != null && oh > 0)
	        	 	obj.style.top = st+((h-oh)/2)+ "px";
	        	else 
	            	obj.style.top = st+((h-320)/2)+ "px";
	        }
    	}
    	
    	
		function changeMarkForDetail(){
			var cm = document.getElementById("logincm");
			cm.src = contextPath+ "/verifyCode.ok?dt="+new Date();
		}

	  
	  var gotoUrl = "";
	  //跳转到相应url时，提示返现登录
	  function goCashBackUrl(url,isunionstore){
	 	 gourl = url;
	 	 gotoUrl = url;
	 	 unionstore  = isunionstore;
	 	 //productOnload.getViewSiteProductWayFromCookie(getGotoUrlMode);
	 	 var viewSpeUrlway = getCookie("viewSpeUrlway");	
		 if(viewSpeUrlway == null)
			viewSpeUrlway= "";
		 getGotoUrlMode(viewSpeUrlway);
	  }  
	  
	  function getGotoUrlMode(result){
	  		if(loginResult)
	  			gotourlWithNewWindow();
			else if(result == ""){
				productOnload.findMaxCashbackByUrl(gotoUrl,generateCommonCashBackDiv);
			}else if(result == "0"){
				gotourlWithNewWindow();
			}else if(result == "1"){
				gotourlWithNewWindow();
			}
	}
	
	function gotourlWithNewWindow(){
		//document.cashredirect.link.value = gotoUrl;
		//document.cashredirect.submit();
		window.open(gotoUrl);
	}
		
		
	function generateCommonCashBackDiv(result){
		createCoverDiv();
		setCashBackInfo(result);
		showCachLogin("cashLogin");
	}
	
	function setCashBackInfo(result){
		var siteinfos = result.split(",,");
		/*
		var picobj = document.getElementById("sl"+siteinfos[2]);
		if(picobj != null)
			document.getElementById("sitelogodiv").innerHTML = "<img width='95' src='"+picobj.src+"' />";
		else
			document.getElementById("sitelogodiv").innerHTML = siteinfos[1];
			*/
		if(siteinfos.length == 3)		
			document.getElementById("maxcashdiv").innerHTML	= "<span style='color:red;font-weight:bold;font-size:14px'>"+siteinfos[0]+"</span>";
		else
			document.getElementById("maxcashdiv").innerHTML	= "<span style='color:red;font-weight:bold;font-size:14px'>"+siteinfos[0]+"</span>";
		document.getElementById("cashsitename").innerHTML = "<a target='_blank' href='"+contextPath+"/s_"+siteinfos[2]+"/'>"+siteinfos[1]+"</a>";
		document.getElementById("cashUrl").value = gotoUrl;
	}
	
	//关闭返现登录提示
		function closeCommonCachLogin(){
			productOnload.setViewSiteProductWayToCookie(closeCommonCachLoginCallBack);
		}
		
		function closeCommonCachLoginCallBack(){
			hiddenCashDiv();
			gotourlWithNewWindow();
		}
		
		
				
	function generateLoginDiv(logdiv,width,height,flag){
		if(flag != null && flag.length > 0){
			loginflag = flag;
			regtype = flag;
		}
		createCoverDiv();
		showLoginDiv(logdiv,width,height);
	}
	
	function closeLoginDiv(logdiv){
		var divScreenBg = document.getElementById("divScreenBg");
		document.body.removeChild(divScreenBg);
		document.getElementById(logdiv).style.display='none';
	}
		
		var loginflag = null;
		var regtype = null;
		function doLoginForCommLogin(){
			var loginname = document.form1.loginname.value.trim();
			if(loginname == ""){
				alert("请输入用户名称或邮箱。");
				document.form1.loginname.focus();
				return false;
			}
			var password = document.form1.password.value.trim();
			if(password == ""){
				alert("请输入密码。");
				document.form1.password.focus();
				return false;
			}
			
			var checkMark = "";
			/*
			checkMark = document.form1.checkMark.value.trim();
			if( checkMark == ""){
				alert("请输入验证码。");
				document.form1.checkMark.focus();
				return false;
			}
			*/
			var checkedflag = "0";
			if(document.getElementById("cookieflag").checked)
				checkedflag = "1";
				
			if(unionstore == "1")
				productOnload.checkLoginForUnionLogin(loginname,password,checkMark,checkedflag,unionsid,checkCommonLoginCallBack);
			else	
				productOnload.checkLogin(loginname,password,checkMark,checkedflag,checkCommonLoginCallBack);
	
	  }	
	  /*
		function doLoginForDetail(){
			var loginname = document.form1.loginname.value.trim();
			if(loginname == ""){
				alert("请输入用户名称或邮箱。");
				document.form1.loginname.focus();
				return false;
			}
			var password = document.form1.password.value.trim();
			if(password == ""){
				alert("请输入密码。");
				document.form1.password.focus();
				return false;
			}
			var checkMark = "";
			
			//checkMark = document.form1.checkMark.value.trim();
			//if( checkMark == ""){
			//	alert("请输入验证码。");
			//	document.form1.checkMark.focus();
			//	return false;
			//}
			var checkedflag = "0";
			if(document.getElementById("cookieflag").checked)
				checkedflag = "1";
			productOnload.checkLogin(loginname,password,checkMark,checkedflag,checkLoginCallBack);
	
	  }	  
	  
	  function checkLoginCallBack(a){
	  	if(a != "2" && a!="3"){
	  			hiddenCashDiv();
		  		sessUser = "yes";
		  		document.productform.action=contextPath + "/redirect.html";	
		  		document.productform.target= "_blank";
		  		document.productform.submit();
	  	}else if(a == "2"){
	  		document.getElementById("longError").innerHTML = "验证码不正确。";
	  	}else if(a == "3"){
	  		document.getElementById("longError").innerHTML = "用户名或密码不正确。";
	  	}
	  }
	  */
	  
	 function checkCommonLoginCallBack(a){
	
	  	if(a != "2" && a!="3"){
	  		var infos = a.split(",,,");
	  		if(loginflag == "replayThread")
	  			document.replyform.submit();
	  		else if(loginflag == "productdetail"){
	  			hiddenCashDiv();
		  		sessUser = "yes";
		  		document.productform.action=contextPath + "/redirect.html";	
		  		document.productform.target= "_blank";
		  		
		  		//是否联合登陆商家
		  		if(unionstore == "1"){
		  			if(infos[2] == "nt"){
		  				var unionstorename = document.getElementById("unionstorename");
						if(unionstorename != null)
							unionstorename.innerHTML=document.getElementsByName("scname")[siteIndexValue].value;
		  				generateUnionLoginDiv(eventEle);
		  			}else if(infos[2] == "use"){
		  				document.productform.action= contextPath + "/redirect.html?unionflag=1";
		  				document.productform.submit();
		  			}else{
		  				document.productform.submit();
		  			}
		  		}else
	  				document.productform.submit();
		  		
		  		
		  		setUserLoginInfo(infos);
	  		}else if(loginflag == "union"){
	  			location.reload();
	  			//closeLoginDiv("cashLogin");
	  		}else if(loginflag == "storeindex"){
	  			
	  			//是否联合登陆商家
		  		if(unionstore == "1"){
		  			if(infos[2] == "nt"){
		  				hiddenCashDiv();
		  				generateUnionLoginDiv(eventEle);
		  			}else if(infos[2] == "use"){
		  				if(gotoUrl.indexOf("&unionflag=1") == -1)
		  					gotoUrl = gotoUrl + "&unionflag=1";
		  				closeCommonCachLoginCallBack();
		  			}else{
		  				closeCommonCachLoginCallBack();
		  			}
		  		}else
	  				closeCommonCachLoginCallBack();
	  			setUserLoginInfo(infos);
	  			
	  		}else if(loginflag == "close"){
	  			hiddenCashDiv();
	  			setUserLoginInfo(infos);
	  		}else if(regtype == "gourl"){
	  			hiddenCashDiv();
	  			setUserLoginInfo(infos);	  		
	  			window.open(gourl);
	  		}else if(regtype == "gourlrefresh"){
	  			//hiddenCashDiv();
	  			//setUserLoginInfo(infos);	  		
	  			//window.open(gourl);
	  			location.reload();
	  		}else if(loginflag == "frilink" || loginflag == "sms"){
	  			try{
		  			var frilink = document.getElementById("frilink");
		  			frilink.value = frilink.value + encodeURI(infos[1]);
		  			frilink.onclick=function(){
		  				var frilink = document.getElementById("frilink");
		  				frilink.select();
		  			};
	  			}catch(e){}
	  			hiddenCashDiv();
	  			setUserLoginInfo(infos);
	  		}else if(loginflag == "newline"){
	  		 getJoinedResult();
	  		 hiddenCashDiv();
	  		}
	  		loginResult = true;
	  		

	  	}else if(a == "2"){
	  		document.getElementById("longError").innerHTML = "验证码不正确。";
	  	}else if(a == "3"){
	  		document.getElementById("longError").innerHTML = "用户名或密码不正确。";
	  	}
	  }	
	   
	  
	  function doLoginForCommLoginWithFlag(flag){
	  		if(flag != null && flag.length >0){
		  	  loginflag = flag;
		  	 }
			doLoginForCommLogin();
	  }
	  
	   function doLoginForCommLoginOnkey(e,flag){
	  	 	var keyc;
			if(window.event){
				keyc=e.keyCode;
			}else if(e.which){
				keyc=e.which;
			}
			if(keyc == 13){	
				doLoginForCommLoginWithFlag(flag);
		 	}
	  }
	  
	 function  doRegForCommLoginWithFlag(type){
	 	if(type != null && type.length >0){
			regtype = type;
		}
	  	doRegisterForCommLogin();
	  }
	  
	  	  
	   function doRegForCommLoginOnkey(e,type){
	  	 	var keyc;
			if(window.event){
				keyc=e.keyCode;
			}else if(e.which){
				keyc=e.which;
			}
			if(keyc == 13){	
				doRegForCommLoginWithFlag(type);
		 	}
	  }
	  
	  
	  
	  
	  function doRegisterForCommLogin(){
			var loginname = document.regform.reg_loginname.value.trim();
			if(loginname == ""){
				alert("请输入邮箱。");
				document.regform.reg_loginname.focus();
				return false;
			}else{
				var re =/^[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+@[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+(\.[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+)+$/;
			    if(!re.test(loginname)){
			    	alert("邮箱格式不正确。");
			    	document.regform.reg_loginname.select();
			    	return false;
				}
						
			}
			var password = document.regform.reg_password.value.trim();
			if(password == ""){
				alert("请输入密码。");
				document.regform.reg_password.focus();
				return false;
			}else{
				if(password.length < 6){
					alert("密码长度不能小于6个字符。");
					document.regform.reg_password.select();
					return false;
				}
			}
			
			var rePassword = document.regform.rePassword.value.trim();
			if(rePassword == ""){
				alert("请输入确认密码。");
				document.regform.rePassword.focus();
				return false;
			}else{
				if(password != rePassword){
					alert("确认密码填写不正确。");
					document.regform.rePassword.select();
					return false;
				}
			}
		
			productOnload.register(loginname,password,regtype,checkCommonRegisterCallBack);
	
	  }	
	  
	 function checkCommonRegisterCallBack(a){
	  	if(a !="email" && a !="error"){
	  		var infos = a.split(",,,");
	  		if(regtype == "productdetail"){
		  		hiddenCashDiv();
		  		sessUser = "yes";
		  		document.productform.action=contextPath + "/redirect.html";	
		  		document.productform.target= "_blank";
		  		
		  		//是否联合登陆商家
		  		if(unionstore == "1"){
		  			var unionstorename = document.getElementById("unionstorename");
					if(unionstorename != null)
						unionstorename.innerHTML=document.getElementsByName("scname")[siteIndexValue].value;
		  			generateUnionLoginDiv(eventEle);
		  		}else
		  			document.productform.submit();
		  		setUserLoginInfo(infos);
	  		}else if(regtype == "storeindex"){
	  				  		
		  		//是否联合登陆商家
		  		if(unionstore == "1"){
		  			hiddenCashDiv();
		  			generateUnionLoginDiv(eventEle);
		  		}else
		  			closeCommonCachLoginCallBack();
	  			setUserLoginInfo(infos);
	  		}else if(regtype == "union"){
	  			location.reload();
	  		}else if(regtype=="replayThread"){
	  			document.replyform.submit();
	  		}else if(regtype == "close"){
	  			hiddenCashDiv();
	  			setUserLoginInfo(infos);
	  		}else if(regtype == "sms"){
	  			var curl = location.href;
	  			location.href=contextPath + "/space/biuser/phoneBind.jsp?currentUrl="+encodeURI(curl);
	  		}else if(regtype == "gourl"){
	  			hiddenCashDiv();
	  			setUserLoginInfo(infos);
	  			window.open(gourl);
	  		}else if(regtype == "gourlrefresh"){
	  			//hiddenCashDiv();
	  			//setUserLoginInfo(infos);
	  			//window.open(gourl);
	  			location.reload();
	  		}else if(regtype == "frilink"){
	  			var frilink = document.getElementById("frilink");
	  			frilink.value = frilink.value +encodeURI(infos[1]);
	  			frilink.onclick=function(){
	  				var frilink = document.getElementById("frilink");
	  				frilink.select();
	  			};
	  			hiddenCashDiv();
	  			setUserLoginInfo(infos);
	  		}else if(loginflag == "newline"){
	  		 getJoinedResult();
	  		 hiddenCashDiv();
	  		}
	  		loginResult = true;
	  	
	  	}else if(a =="email"){
	  		document.getElementById("longError_reg").innerHTML = "该邮箱已经被人使用，换一个试试。";	
	  	}else
	  		document.getElementById("longError_reg").innerHTML = "注册失败，请重试。";	
	  }		  
	
	
	function setUserLoginInfo(infos){
		var prefix = "http://www.51bi.com";
		if(contextPath != null && contextPath+"" != "undefined"){
			prefix = contextPath;
		}
		var regcontainer = document.getElementById("regcontainer");
		try{
			currUserName  = infos[1];
			var logincontainer = document.getElementById("logincontainer");
			if(regcontainer != null){
				logincontainer.style.display = "none";
				regcontainer.innerHTML = "您好，<a target=\"_blank\" href=\""+prefix+"/space/u_"+infos[0]+"/\">"+infos[1]+"</a> <span class=\"toout\"><a href=\""+prefix+"/space/user/logout.html\">退出</a></span>";
			}
		}catch(e){}
	}		
	
	//显示登录框，登录后点击进入对应url
	function generateLoginDivToUrl(logdiv,width,height,flag,hrefobj){
		if(!loginResult){
			gourl = hrefobj.href;//本站链接，不提示登录
			if(decodeURIComponent(gourl).indexOf("link=http://www.51bi.com") != -1)
				return true;
				
			var viewSpeUrlway = getCookie("viewSpeUrlway");	
			if(viewSpeUrlway == "0")
				return true;
			if(flag != null && flag.length > 0){
				loginflag = flag;
				regtype = flag;
			}
			createCoverDiv();
			showLoginDiv(logdiv,width,height);
			return false;
		}
		return true;
	}
	
	function viewSpeUrl(closediv){
	
		if(gourl != null && gourl.length > 5){
			if(closediv != "unionlogindiv")
				SetCookieWitnMinute('viewSpeUrlway','0',5);
			window.open(gourl);
		}else{
			if(loginflag == "productdetail" || loginflag == "IEproductdetail"){
				SetCookieWitnMinute('viewSpeUrlway','0',5);
				gotoSpecifySite(siteIndexValue);
			}else if(loginflag == "storeindex"){
				if(gotoUrl != null && gotoUrl.length > 5){
					SetCookieWitnMinute('viewSpeUrlway','0',5);
					window.open(gotoUrl);
				}
			}
		}
		closeLoginDiv(closediv);
	}
	
	function hintCashback(obj,type,isunionstore){
		eventEle = obj;
		var url = obj.href;
		var checkHintCashback = getCookie('hintCashback');
		var goBugremind = document.getElementById('goBugremind');
		if(checkHintCashback != 'true'){
			generateLoginDiv('goBugremind',550,160);
			goBugremind.style.display = "block";
			if(type == "1"){//is login
				if(isunionstore == "1"){//union store
					document.getElementById('hintclosebtn').onclick=function(){
						generateUnionLoginDiv(obj);
						return false;
					};
					document.getElementById('hintknowbtn').onclick=function(){
						generateUnionLoginDiv(obj);
						return false;
					};
				}else{
					document.getElementById('hintclosebtn').href=url;
					document.getElementById('hintknowbtn').href=url;
				}
			}else{
				document.getElementById('hintclosebtn').target="";
				document.getElementById('hintknowbtn').target="";
				document.getElementById('hintclosebtn').onclick=function(){
					goCashBackUrl(url,isunionstore);
					return false;
				};
				document.getElementById('hintknowbtn').onclick=function(){
					goCashBackUrl(url,isunionstore);
					return false;
				};
			}
			
			setTimeout("closeLoginDiv('goBugremind');",50000);
		}else{
			if(type == "1"){
				local.href = url;
			}else{
				goCashBackUrl(url,isunionstore);
			}
		}
	}
	
	
	function generateUnionLoginDiv(obj){
		//只做产品明细页及商家页
		if(regtype != "productdetail" && regtype != "storeindex")
			return;
	
		if( regtype == "storeindex"){
			if(obj == null){
				obj  = document.getElementById("cashbackBtn");
				if(obj == null)
					return;
			}
			if(gourl == null || gourl.length < 5)
				gourl = obj.href;
		}
			
		createCoverDiv();
		var cashObj=document.getElementById("unionlogindiv"); 
	    var w = 0; 
	    var h = 0;
	       	       	
       	var ua = navigator.userAgent.toLowerCase();
		var os = new Object();
		os.isFirefox = ua.indexOf ("gecko") != -1;
		os.isOpera = ua.indexOf ("opera") != -1;
		os.isIE = !os.isOpera && ua.indexOf ("msie") != -1;
		os.isSafa = !os.isOpera && ua.indexOf ("safari") != -1;
      	if(os.isOpera){
      		w = document.body.clientWidth;
      		h = document.body.clientHeight;
      	}else if(os.isFirefox){
      		w = document.documentElement.clientWidth;
      		h = document.documentElement.clientHeight;
      	}else if(os.isIE){
      		w = document.documentElement.clientWidth;
      		h = document.documentElement.clientHeight;
      	}else if(os.isSafa){
      		w = document.body.clientWidth;
      		h = document.body.clientHeight;
      	}
      	
        cashObj.style.position="absolute";  

	    cashObj.style.left =  (w-500)/2 + "px";  
        cashObj.style.zIndex = 1001;
        clearInterval(timerID);
        timerID = setInterval(function(){moveCachLogin(cashObj,h,os,250);},10);
        cashObj.style.display="";
	}
	
	function saveUnionSetting(storeid){
		if(storeid == null || storeid == "")
			storeid = unionsid + "";
		var flag = "0";
		var unionset = document.getElementsByName("seleLogin");
		for(var i=0;i<unionset.length;i++){
			if(unionset[i].checked){
				flag = unionset[i].value;
				break;
			}	
		}
		if(gourl != null && gourl.length > 5){

			if(gourl.indexOf("&unionflag="+flag) == -1)		
				gourl = gourl + "&unionflag="+flag;
		}
		if(regtype == "productdetail" || regtype == "IEproductdetail"){
			unionLoginflag =flag=="1"?"use":"";
		}
		var saveSet = document.getElementById("saveSet");
		if(saveSet.checked)
			productOnload.updateUnionSettingParam(storeid,flag,saveUnionSettingCallBack);
		else
			viewSpeUrl("unionlogindiv");
	}
	
	function saveUnionSettingCallBack(a){
		viewSpeUrl("unionlogindiv");
	}
