function JoinSubmit(){
    if(CheckFormValidate()){
        DisableOtherSubmit();
        AllSubmit();
    }
}

function AllSubmit(){
    var NewsLetterTemp;
    if($("#chkNewsletter").attr("checked")){
        NewsLetterTemp = "1";
    }else{
        NewsLetterTemp = "0";
    }
    if($("#HiddenDetailTable").css("display") == 'none'){
        $.ajax({
            url: "../Ajax/ProcessJoinUs.ashx",
            type: 'POST',
            data: {Email: $("#txtCurrentEmail").val(),Password:$("#txtPwd").val(),Country:$("#ddlCountry").val().split('!')[0],NewsLetter:NewsLetterTemp,Advanced:false, time: (new Date()).getTime() },
            error: function(){
                location.href = $("#HomeLink").val() + "/Error/GenericErrorpage.aspx";
            },
            beforeSend: function(XMLHttpRequest){
//               ShowBackground();
            },
            complete: function(){
//                RemoveBackground();
            },
            success: function(data){
                if(data == "true"){
                    $("#CustomerLogin").html("Welcome! <span style=\"color:#E3D11E;\">" + $("#txtCurrentEmail").val() + "</span>, <a href=\"javascript:void(null);\" onclick=\"javascript:SignOut();\" style=\"text-decoration:none;\">Sign Out!</a>");
                    $("#ProcessingMessage").css("display","none");
                    $("#CustomerForm").html("");
                    $("#BackgroundDiv").fadeOut("slow");
                    $("#JoinusTitle").css("display","none");
                    $("#SuccessTitle").fadeIn("fast");
                    $("#SuccessContent").fadeIn("fast");
                    EnableOtherSubmit()
                    pageTracker._trackPageview("/JoinUs/JoinUsRegisterSuccess.aspx");
                }else if(data == "false"){
                    $("#ProcessingMessage").fadeOut("fast");
                    $("#ErrorMessage").fadeIn("fast");
                    EnableOtherSubmit();
                    pageTracker._trackPageview("/JoinUs/JoinUsRegisterError.aspx");
                }else if(data == "Cookie Error"){
                    $("#ProcessingMessage").fadeOut("fast");
                    $("#CookieErrorMessage").fadeIn("fast");
                    EnableOtherSubmit();
                    pageTracker._trackPageview("/JoinUs/JoinUsRegisterError.aspx");
                }
            }
        });
    }else{
        var GenderTemp;
        if($("#rbnMale").attr("checked")){
            GenderTemp = 1;
        }else{
            GenderTemp = 0;
        }
        var BirthdayTemp;
        if($("#SelMonth").val() != "Select Month"){
            BirthdayTemp = $("#SelMonth").val() + "-" + $("#SelDate").val();
        }else{
            BirthdayTemp = "-";
        }
        var PhoneTemp = $("#txtTelephoneCountry").val() + "-" + $("#txtTelephoneArea").val() + "-" + $("#txtTelephoneNumber").val();
        var FaxTemp = $("#txtFaxCountry").val() + "-" + $("#txtFaxArea").val() + "-" + $("#txtFaxNumber").val();
        $.ajax({
            url: "../Ajax/ProcessJoinUs.ashx",
            type: 'POST',
            data: {Fax:FaxTemp,Phone:PhoneTemp,Answer:$("#txtAnswer").val(),Question:$("#txtQuestion").val(),Msn:$("#txtMsn").val(),BackEmail:$("#txtBackEmail").val(),StateProvince:$("#txtStateProvince").val(),City:$("#txtCity").val(),PostCode:$("#txtPostCode").val(),Suburb:$("#txtSuburb").val(),StreetAddress:$("#txtStreetAddress").val(),CompanyName:$("#txtCompanyName").val(),Birthday:BirthdayTemp,Gender:GenderTemp,LastName:$("#txtLastName").val(),FirstName:$("#txtFirstName").val(),Email: $("#txtCurrentEmail").val(),Password:$("#txtPwd").val(),Country:$("#ddlCountry").val().split('!')[0],NewsLetter:NewsLetterTemp,Advanced:true, time: (new Date()).getTime() },
            error: function(){
                location.href = $("#HomeLink").val() + "/Error/GenericErrorpage.aspx";
            },
            beforeSend: function(XMLHttpRequest){
               ShowBackground();
            },
            complete: function(){
                RemoveBackground();
            },
            success: function(data){
                if(data == "true"){
                    $("#CustomerLogin").html("Welcome! <span style=\"color:#E3D11E;\">" + $("#txtCurrentEmail").val() + "</span>, <a href=\"javascript:void(null);\" onclick=\"javascript:SignOut();\" style=\"text-decoration:none;\">Sign Out!</a>");
                    $("#ProcessingMessage").css("display","none");
                    $("#CustomerForm").html("");
                    $("#BackgroundDiv").fadeOut("slow");
                    $("#JoinusTitle").css("display","none");
                    $("#SuccessTitle").fadeIn("fast");
                    $("#SuccessContent").fadeIn("fast");
                    EnableOtherSubmit()
                }else if(data == "false"){
                    $("#ProcessingMessage").fadeOut("fast");
                    $("#ErrorMessage").fadeIn("fast");
                    EnableOtherSubmit();
                }else if(data == "Cookie Error"){
                    $("#ProcessingMessage").fadeOut("fast");
                    $("#CookieErrorMessage").fadeIn("fast");
                    EnableOtherSubmit();
                }
            }
        });
    }
}

function CancelSubmit(){
    $("#BackgroundDiv").fadeOut("fast");
    $("#ErrorMessage").fadeOut("fast");
    $("#CookieErrorMessage").fadeOut("fast");
}

function HideOverSels(objID){
    var sels = document.getElementsByTagName('select');
    for (var i = 0; i < sels.length; i++){
        if (Obj1OverObj2(document.getElementById(objID), sels[i])){
            sels[i].style.visibility = 'hidden';
        }else{
            sels[i].style.visibility = 'visible';
        }
    }
}





function ShowErrorSubmitMessage()
{
    alert("Some information are not completed properly,please check again.");
}

//验证表单
function CheckFormValidate(){
    $("#Submit_btn").focus();
    if(EmailIsok == 0)
    {
        ShowErrorSubmitMessage();
        $("#txtCurrentEmail").focus();
        return false;
    }
    if(PasswordCheck() == 0)
    {
        ShowErrorSubmitMessage();
        $("#txtPwd").focus();
        return false;
    }
    if(ConfirmationPassword() == 0)
    {
        ShowErrorSubmitMessage();
        $("#txtPwdConfirmation").focus();
        return false;
    }
    var chkShowadv = $("#ChkShowadv");
    if(!chkShowadv.attr("checked")){
        return true;
    }else{
        var firstName = $("#txtFirstName");
        if(FirstNameCheck() == 0)
        {
            ShowErrorSubmitMessage();
            firstName.focus();
            return false;
        }
        var lastName = $("#txtLastName");
        if(LastNameCheck() == 0)
        {
            ShowErrorSubmitMessage();
            lastName.focus();
            return false;
        }
        var companyName = $("#txtCompanyName");
        if(CompanyNameCheck() == 0)
        {
            ShowErrorSubmitMessage();
            companyName.focus();
            return false;
        }
        var streetAddress = $("#txtStreetAddress");
        if(StreetAddressCheck() == 0)
        {
            ShowErrorSubmitMessage();
            streetAddress.focus();
            return false;
        }
        var postCode = $("#txtPostCode");
        if(PostCodeCheck() == 0)
        {
            ShowErrorSubmitMessage();
            postCode.focus();
            return false;
        }
        var city = $("#txtCity");
        if(CityCheck() == 0)
        {
            ShowErrorSubmitMessage();
            city.focus();
            return false;
        }
        var sp = $("#txtStateProvince");
        if(SPCheck() == 0)
        {
            ShowErrorSubmitMessage();
            sp.focus();
            return false;
        }
        var phoneCountry = $("#txtTelephoneCountry");
        if(PhoneCountryCheck() == 0)
        {
            ShowErrorSubmitMessage();
            phoneCountry.focus();
            return false;
        }
        var phoneArea = $("#txtTelephoneArea");
        if(PhoneAreaCheck() == 0)
        {
            ShowErrorSubmitMessage();
            phoneArea.focus();
            return false;
        }
        var phoneNumber = $("#txtTelephoneNumber");
        if(PhoneNumberCheck() == 0)
        {
            ShowErrorSubmitMessage();
            phoneNumber.focus();
            return false;
        }
        var backEmail = $("#txtBackEmail");
        if(BackEmailCheck() == 0)
        {
            ShowErrorSubmitMessage();
            backEmail.focus();
            return false;
        }
        var txtMsn = $("#txtMsn");
        if(MsnCheck() == 0)
        {
            ShowErrorSubmitMessage();
            txtMsn.focus();
            return false;
        }
        var question = $("#txtQuestion");
        if(QuestionCheck() == 0)
        {
            ShowErrorSubmitMessage();
            question.focus();
            return false;
        }
        var answer = $("#txtAnswer");
        if(AnswerCheck() == 0)
        {
            ShowErrorSubmitMessage();
            answer.focus();
            return false;
        }
        return true;
    }
}

////IE和火狐浏览器提交
//function IeAndFireFoxSubmit(){
//    GetItem("Email").value = $("txtCurrentEmail").value;
//    GetItem("Password").value = $("txtPwd").value;
//    GetItem("Country").value = $("ddlCountry").value.split(',')[0];
//    if($("txtPwd").checked){
//        GetItem("Newsletter").value = "1";
//    }else{
//        GetItem("Newsletter").value = "0";
//    }
//    if($("HiddenDetailTable").style.display == 'none'){
//        AddSimpleCustomer();
//    }else{
//        AddFullCustomer();
//    }
//    GetItem("form1").submit();
//}

//其他浏览器提交
function OtherBrowserSubmit(){
    $(CustomerForm).submit();
}

//增加简单的客户
function AddSimpleCustomer(){
    
}

//增加完整的客户
function AddFullCustomer(){
    
}

//得到IFrame的子节点
//function GetItem(ItemName){
//    return top.frames["Submitform"].document.getElementById(ItemName);
//}

//显示注册成功
function SubmitSuccess(){
    
}

//显示注册失败
function SubmitError(){
    
}

//显示客户端不支持Cookie
function NotSupportCookie(){
    
}

function cancelPopupPage(){
    document.body.removeChild($('down_popup_background'));
}


function ContinueShopping(){
    location.href = "../Index.aspx";
}