﻿
function createQueryString()
{
    var UserRole = "2";
    var UserName = "" ; if (document.getElementById("txtUserName")!=null)  UserName = document.getElementById('txtUserName').value;
    var PassWord1 = "" ; if (document.getElementById("txtPassWord1")!=null)  PassWord1 = document.getElementById('txtPassWord1').value;
    var PassWord2 = "" ; if (document.getElementById("txtPassWord2")!=null)  PassWord2 = document.getElementById('txtPassWord2').value;
    var UserMail = "" ; if (document.getElementById("txtUserMail")!=null)  UserMail = document.getElementById('txtUserMail').value;

    if (UserName=="" && document.getElementById("txtUserName")!=null)
    {
        document.getElementById('txtUserName').focus();
        alert("请输入用户名!");
        return "false" ;
    }
    
    if (PassWord1=="" && document.getElementById("txtPassWord1")!=null)
    {
        document.getElementById('txtPassWord1').focus();
        alert("请输入用户密码!");
        return "false" ;
    }
    
    if (UserMail=="" && document.getElementById("txtUserMail")!=null)
    {
        document.getElementById('txtUserMail').focus();
        alert("请输入邮箱!");
        return "false" ;
    }

    if (PassWord2!=PassWord1 && document.getElementById("txtPassWord1")!=null && document.getElementById("lblPassWord2")!=null)
    {
        document.getElementById('txtPassWord2').focus();
        alert("你两次输入的密码不一致!");
        return "false" ;
    }
    
    if (document.getElementById("ckbIsApproval")!=null)
    {
        if (!document.getElementById("ckbIsApproval").checked)
        {
            alert("请你接受协议!"); 
            return "false" ;
        }
    }
    
    if (document.getElementById("txtCheckCode")!=null)
    {
        var CheckCode = document.getElementById("txtCheckCode").value; 
        if (GetCookie("CheckCode")!= CheckCode.toUpperCase(CheckCode) )
        {
            document.getElementById('txtCheckCode').focus();
            alert("你输入的验证码不对!"); 
            return "false" ;
        }
    }
            
    return "UserRole="+UserRole+"&UserName=" +UserName+ "&PassWord=" +PassWord1+ "&UserMail=" + UserEmail;
}

function clear()
{
    if (document.getElementById("txtUserName")!=null)  document.getElementById("txtUserName").value="";
    if (document.getElementById("txtEMail")!=null)  document.getElementById("txtEMail").value="";
    if (document.getElementById("txtPassWord1")!=null)  document.getElementById("txtPassWord1").value="";
    if (document.getElementById("txtPassWord2")!=null)  document.getElementById("txtPassWord2").value="";
    if (document.getElementById("txtUserMail")!=null)  document.getElementById("txtUserMail").value="";
    if (document.getElementById("txtMyQuestion")!=null)  document.getElementById("txtMyQuestion").value="";
    if (document.getElementById("txtMyAnswer")!=null)  document.getElementById("txtMyAnswer").value="";
 
    if (document.getElementById("txtUserCompany")!=null)  document.getElementById("txtUserCompany").value="";
    if (document.getElementById("txtUserAddress")!=null)  document.getElementById("txtUserAddress").value="";
    if (document.getElementById("txtUserPost")!=null)  document.getElementById("txtUserPost").value="";
    if (document.getElementById("txtUserMan")!=null)  document.getElementById("txtUserMan").value="";
    if (document.getElementById("txtJob")!=null)  document.getElementById("txtJob").value="";
                   
    if (document.getElementById("txtTel")!=null)  document.getElementById("txtTel").value="";
    if (document.getElementById("txtFax")!=null)  document.getElementById("txtFax").value="";
    if (document.getElementById("txtMobile")!=null)  document.getElementById("txtMobile").value="";
    if (document.getElementById("txtQQ")!=null)  document.getElementById("txtQQ").value="";
    if (document.getElementById("txtMSN")!=null)  document.getElementById("txtMSN").value="";
    if (document.getElementById("txtWebLink")!=null)  document.getElementById("txtWebLink").value="";
}

function submit()
{
    var filePath="/Common/WebServiceUser.asmx/Member_Reg";
    var data = createQueryString();
    
    if (data!="false")
    {
        var bFlag=0;

        $.ajax({async:false,type:"post",url:filePath,data:data,dataType:"xml",timeout:50000,
                success:function(xml) { bFlag = $(xml).find("int").text();  }
               });

        if (bFlag>0)
        {
            alert("欢迎你的加入，您已经注册成功！")
            window.location.href = "/App/SiteLogin.aspx";
        }
        else if (bFlag==-1)
        {
            alert("你输入的用户名已经存在!");
        }
        else if (bFlag==-2)
        {
            alert("你输入的邮箱已经存在!");
        }   
    }
}

function login()
{

    var UserName = "" ; if (document.getElementById("txtLoginUserName")!=null)  UserName = document.getElementById('txtLoginUserName').value;
    var PassWord = "" ; if (document.getElementById("txtLoginPassWord")!=null)  PassWord = document.getElementById('txtLoginPassWord').value;
    
    if (UserName=="" && document.getElementById("txtLoginUserName")!=null)
    {   
        document.getElementById('txtLoginUserName').focus();
        alert("请输入用户名!");
        return "false" ;
    }
    
    if (PassWord=="" && document.getElementById("txtLoginPassWord")!=null)
    {
        document.getElementById('txtLoginPassWord').focus();
        alert("请输入用户密码!");
        return "false" ;
    }
    
    if (document.getElementById("txtLoginCheckCode")!=null)
    {
        var CheckCode = document.getElementById("txtLoginCheckCode").value; 
        if (GetCookie("CheckCode")!= CheckCode.toUpperCase(CheckCode) )
        {
            document.getElementById('txtLoginCheckCode').focus();
            alert("你输入的验证码不对!"); 
            return "false" ;
        }
    }

    var filePath="/Common/WebServiceUser.asmx/Member_Login";
    var data = "UserMail=" +UserName+ "&PassWord=" +PassWord +"&Flag=1" ;
    var bFlag= -1 ;
    
    $.ajax({async:false,type:"post",url:filePath,data:data,dataType:"xml",timeout:50000,
            success:function(xml) { bFlag = $(xml).find("int").text();  }
           });

    if (bFlag==0)
    {
        alert("欢迎你的登入，您已经登入成功！")
        window.location.href = "/app_member/";
    }
    else if (bFlag==-1)
    {
        alert("请您输入正确的邮箱！")
    }
    else if (bFlag==-2)
    {
        alert("请您输入正确的密码！")
    }
}

function logout()
{   
    var filePath="/Common/WebServiceUser.asmx/Member_LoginOut";
    var data = "MemberName=" ;
    
    $.ajax({async:false,type:"post",url:filePath,data:data,dataType:"xml",timeout:50000,
            success:function(xml) { var strLink = window.location.href; window.location.href= strLink ;   }
           });
}

function getMemberPassWord()
{
    var filePath="/Common/WebServiceUser.asmx/Member_GetPassWord";
    var UserMail = "" ; if (document.getElementById("txtReturnUserMail")!=null)  UserMail = document.getElementById('txtReturnUserMail').value;
    
    if (UserMail=="" && document.getElementById("txtReturnUserMail")!=null)
    {
        document.getElementById('txtReturnUserMail').focus();
        alert("请输入邮箱!");
        return ;
    }
    
    var data = "UserEmail=" +UserMail ;
    var bFlag= -1 ;
    
    $.ajax({async:false,type:"post",url:filePath,data:data,dataType:"xml",timeout:50000,
            success:function(xml) { bFlag = $(xml).find("int").text();  }
           });

    if (bFlag==0)
    {
        alert("您的密码找回成功，请查收邮件！")
        window.location.href = "/App/SiteLogin.aspx";
    }
    else if (bFlag==-1)
    {
        alert("您的邮箱存在，邮件发送不成功，请尝试重试！")
    }
    else if (bFlag==-2)
    {
        alert("请您输入正确的邮箱！")
    }
}



