function loadlogin()
{
	if(document.getElementById("fanlilogin"))
	{
	$.ajax({
		   url:"fanlilogin.asp"
		   ,success: function(data){
				document.getElementById("fanlilogin").innerHTML=data;
		   	}
		   });
	}
}

function checkulogin()
{
	var go_url=new String(window.location);
	if(go_url.toLowerCase().indexOf("index.asp")==-1&&go_url.toLowerCase().indexOf("login.asp")==-1){document.uloginfo.go_url.value=window.location;}
	if(document.uloginfo.username.value == "") {
	alert("用户名不能为空！");
	document.uloginfo.username.focus();
	return false;
	}
	if(document.uloginfo.UserPassword.value == "") {
	alert("密码不能为空！");
	document.uloginfo.UserPassword.focus();
	return false;
	}
//document.getElementById("loginbutton").disabled   =   "true";
}
function checkelogin()
{
	var go_url=new String(window.location);
	if(go_url.toLowerCase().indexOf("index.asp")==-1&&go_url.toLowerCase().indexOf("login.asp")==-1){document.eloginfo.go_url.value=window.location;}
	if(document.eloginfo.username.value == "") {
	alert("E_mail不能为空！");
	document.eloginfo.username.focus();
	return false;
	}
	if(document.eloginfo.UserPassword.value == "") {
	alert("密码不能为空！");
	document.euloginfo.UserPassword.focus();
	return false;
	}
//document.getElementById("loginbutton").disabled   =   "true";
}
function chglogf(u)
{
	if(u=='elogin'){
		document.getElementById('elogin').style.display='block';
		document.getElementById('ulogin').style.display='none';
	}
	else{
		document.getElementById('ulogin').style.display='block';
		document.getElementById('elogin').style.display='none';
	}
}
//-->

function qlog(golink,status)
{
	var qlogname=document.getElementById("qlogname").value;
	qlogname=logreplace(qlogname);
	var qloginfo=document.getElementById("qloginfo");
	if(qlogname==""||qlogname=="请输入您的Email和用户名"){qloginfo.innerHTML="<span style='color:red; font-size:13px;'>请输入您的Email和用户名。</span>";if(status=='false'){return false;}else return; }
	qloginfo.innerHTML="<span style='color:green; font-size:13px;'>登录中...</span>";
	$.ajax({
		   url:"qlog.asp?qlogname="+encodeURIComponent(qlogname)+"&"+(new Date()).getTime()
		   ,success: function(data){
			   var result=data;
				if(result=="0"){qloginfo.innerHTML="<span style='color:red;font-size:13px'>该用户尚未注册。</span>";}
				if(result!="0"){
					uids=result.split(',');
					if(uids.length==1){gotofl();time(2,golink.replace('$uid$',uids[0]));}
					if(uids.length==2){qloginfo.innerHTML="<input type=\"checkbox\" value=\"\" onclick=\"gotofl();time(2,'"+golink.replace('$uid$',uids[0])+"');\">是我的Email&nbsp;&nbsp;<input type=\"checkbox\" value=\"\" onclick=\"gotofl();time(2,'"+golink.replace('$uid$',uids[0])+"');\">是我的用户名";}
				}
		   	}
		   });
	if(status=='false'){return false;}
}

function qreg(golink,status)
{
	var qregname=document.getElementById("qregname").value;
	var qreginfo=document.getElementById("qreginfo");
	if(qregname==""||qregname=="请输入您的Email快速注册"){qreginfo.innerHTML="<span style='color:red; font-size:13px;'>请输入您的Email快速注册。</span>";if(status=='false'){return false;}else return;}
	if(!isValidEmail(qregname)){qreginfo.innerHTML="<span style='color:red; font-size:13px;'>Email格式不正确。</span>";if(status=='false'){return false;}else return;}
	qreginfo.innerHTML="";
	$('#qregbt').html("<span style='color:green; font-size:13px; '>注册中...</span>");
	$.ajax({
		   url:"qreg.asp?qregname="+encodeURIComponent(qregname)+"&"+(new Date()).getTime()
		   ,success: function(data){
			   var result=data;
				if(result=="rereg"){
					qreginfo.innerHTML="<span style='color:red;font-size:13px'>该Email已被注册，<a href=\"javascript:closeflbox();'"+golink.replace('$uid$',6)+"';\" class=\"col_green\">不想注册去看看</a>。</span>";
					$('#qregbt').html('<a href="javascript:qreg(\''+golink+'\')"><img style="border:0;" src="http://imagefile.51fanli.com/images/imagesnew/jump0811_5.gif"/></a>');
				}
				if(result!="rereg"&&!isNaN(result)){
					uid=result;
					gotofl();
					time(2,golink.replace('$uid$',uid));
				}
		   	}
		   });
	if(status=='false'){return false;}
}
function closeflbox()
{
	parent.document.getElementById("flbox").style.visibility="hidden";
}
function gotofl(shopname)
{
	document.getElementById("flboxshow").style.display="none";
	document.getElementById("flboxhidden").style.display="block";
}
//email检查
function isValidEmail(inEmail)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(inEmail)) return true;
	else return false;
}
function logreplace(str)
{
	str=str.replace(/ /g,"");	
	str=str.replace(/'/g,"");
	str=str.replace(/"/g,"");
	str=str.replace(/;/g,"");
	return str;
}

function time(i,golink)
{ 
	var parselimit=i;
	if (parselimit==0){parent.location=golink;} 
	else{
		i=parselimit-1;
		setTimeout("time("+i+",'"+golink+"')",1000);
	}
} 

var CurrentWebHost;
CurrentWebHost = window.location.host;
if (CurrentWebHost.indexOf("tg.51fanli.com")>-1||CurrentWebHost.indexOf("search.51fanli.com")>-1||CurrentWebHost.indexOf("taobao.51fanli.com")>-1){CurrentWebHost = "www.51fanli.com";}

function verc()
{
	document.getElementById('codeimg').src='http://'+CurrentWebHost+'/logincode.asp?t='+(new Date()).getTime();
}

function fanlilogin(p_gourl)
{
	var go_url=p_gourl;
	if (p_gourl){
		//document.ueloginfo.go_url.value = p_gourl;
	}else{
		go_url=new String(window.location);
		if(go_url.toLowerCase().indexOf("index.asp")==-1&&go_url.toLowerCase().indexOf("login.asp")==-1)
		{
			go_url=window.location;
		}
	}
	
	if(document.getElementById("loadsuc"))
	{
		$(document.body).append('<div id="fanlilogin" style="display:none;background:#FFF;" ></div>');
		$('#fanlilogin').html('<img src="http://imagefile.51fanli.com/images/loadingAnimation.gif">')
		ShowMessageBox({control:'fanlilogin',width:'208',height:'13',title:'',parent:null});
		$.ajax({
			dataType:'jsonp',
			jsonp:'callback',
			url:'http://'+CurrentWebHost+'/action/fanlilogin.asp?t='+(new Date()).getTime(),
			success:function(data)
			{
				$.each(data,function(i,v){
					$('#fanlilogin').html(v["re"]);
					document.ueloginfo.go_url.value=go_url;
					if(p_gourl){$('#regalink').attr( 'href','http://'+CurrentWebHost+'/reg.asp?action=yes&go_url='+encodeURIComponent(p_gourl) );}
					ShowMessageBox({control:'fanlilogin',width:'378',height:'281',title:'',parent:null});
				});

				//verc();
				//ShowMessageBox({control:'fanlilogin',width:'507',height:'326',title:'',parent:null});
			}
			})
	}
	else{window.location='http://'+CurrentWebHost+'/login.asp?go_url='+go_url;}
}

function checkuelogin()
{	
	if(document.ueloginfo.username.value == "") {
		document.getElementById("uelogerinfo").innerHTML="请填写用户名或Email";
		document.ueloginfo.username.focus();
		return false;
	}
	if(document.ueloginfo.userpassword.value == "") {
		document.getElementById("uelogerinfo").innerHTML="请填写密码";
		document.ueloginfo.userpassword.focus();
		return false;
	}
	if(document.ueloginfo.passcode.value == "") {
		document.getElementById("uelogerinfo").innerHTML="请填写验证码";
		document.ueloginfo.passcode.focus();
		return false;
	}
//	$.ajax({
//		   url:'/chkcode.asp?passcode='+document.ueloginfo.passcode.value,
//		   success:function(data){
//			if(data=="0"){
//				document.getElementById("uelogerinfo").innerHTML="验证码错误";
//				document.ueloginfo.passcode.focus();
//				return false;
//				}
//			else{
//				document.getElementById("uelogerinfo").innerHTML="";
//				if(isValidEmail(document.ueloginfo.username.value)){
//					document.getElementById("ueloginfo").action="echkuser.asp"
//					}
//				else{
//					document.getElementById("ueloginfo").action="chkuser.asp"
//					}
//				}
				//return;
				document.ueloginfo.submit();
//		   }
//		   })
	return false;
}

//登陆优化函数
function F_checkuelogin()
{	
	if (document.ueloginfo.saveusername.checked)
	{setCookie("51fanli_login_username",document.ueloginfo.username.value,14);}
	else
	{setCookie("51fanli_login_username","",14);}
	
	if(document.ueloginfo.username.value == "" || document.ueloginfo.username.value =='请输入您注册时填写的用户名或Email') {		
		$('#msg_login').html('请输入您的用户名/Email');
		$('#msg_login').slideDown();
		document.ueloginfo.username.focus();
		return false;
	}
	if(document.ueloginfo.userpassword.value == "") {
		$('#msg_login').html('请输入您的密码或者您<a href="getpwd.asp">忘记了密码?</a>');
		$('#msg_login').slideDown();
		document.ueloginfo.userpassword.focus();
		return false;
	}
	if(document.ueloginfo.passcode.value == "") {
		$('#msg_login').html('请输入验证码！');
		$('#msg_login').slideDown();
		document.ueloginfo.passcode.focus();
		return false;
	}
	var data="actlogin=check&username="+escape(document.ueloginfo.username.value)+"&UserPassword="+document.ueloginfo.userpassword.value+"&passcode="+document.ueloginfo.passcode.value+'&t='+(new Date()).getTime();
    var url="http://www.51fanli.com/chkuser.asp";
	$.ajax({
            url: url,
            data: data,
            type: 'POST',
            error: function(){},
            success: function(data)
            {
				//alert(data)
                if (data == '1')
				{
					//alert(result[1]);
					$('#msg_login').html('您输入的用户名/Email和密码不匹配，请重新输入。或者您<a href="getpwd.asp" >忘记了密码?</a>');
					$('#msg_login').slideDown();
					$('#passcode').attr('value', '');
					$('#login_yzm').css('display', '');
					verc();
					return false;
				}
				if (data == '2')
				{
					//alert(result[1]);
					$('#msg_login').html('用户名/Email不存在');
					$('#msg_login').slideDown();
					$('#passcode').attr('value', '');
					$('#login_yzm').css('display', '');	
					verc();	
					return false;
				}
				if (data == '3')
				{				
					//alert(result[1]);
					$('#msg_login').html('验证码输入错误');
					$('#msg_login').slideDown();
					return false;
				}
				document.ueloginfo.submit();
            }
            });	
	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.toGMTString())
}
