﻿
function ValidateLogin()
{
    var account = $('ctl00_Content_txtAccount').value;
    var pwd = $('ctl00_Content_txtPassword').value;
    if(Edward.Web.Validator.IsNullOrEmpty(account) || !Edward.Web.Validator.IsUsername(account))
    {
        $('spanError').innerHTML="请输入您的帐号!";
        $('ctl00_Content_txtAccount').focus();
        return false;
    }
    if(Edward.Web.Validator.IsNullOrEmpty(pwd) || !Edward.Web.Validator.IsPassword(pwd))
    {
        $('spanError').innerHTML="请输入您的密码!";
        $('ctl00_Content_txtPassword').focus();
        return false;
    }
    if(!Sale_ShoppingCart.ValidatePassword(account,pwd).value)
    {
        $('spanError').innerHTML="用户名或密码错误，请重新输入!";
        $('ctl00_Content_txtAccount').focus();
        return false;
    }
    return true;
}


function ValidateRegsiter()
{
    return ValidateAccount() && ValidatePassword() && ValidatePassword2() && ValidateEmail() && ValidateEmail2() && ValidateAccept();
}

function ValidateAccount()
{
    var account = $('ctl00_Content_txtAccount_Reg').value;
    if(Edward.Web.Validator.IsNullOrEmpty(account) || !Edward.Web.Validator.IsUsername(account))
    {
        $('spanAccount').className="Info_Error";
        return false;
    }
    else
    {
        $('spanAccount').className="Info_Right";
        $('spanAccount').innerHTML = " ok!填写正确!";
    }
    if(Sale_ShoppingCart.IsExist(account).value)
    {
        $('spanAccount').style.display = "none";
        $('spanAccountIsExist').className="Info_Error";
        $('spanAccountIsExist').style.display = "inline";
        return false;
    }
    else
    {
        $('spanAccount').style.display = "inline";
        $('spanAccount').className="Info_Right";
        $('spanAccount').innerHTML = " ok!填写正确!";
        $('spanAccountIsExist').style.display = "none";
    }
    return true;
}

function ValidatePassword()
{
    var pwd = $('ctl00_Content_txtPassword_Reg').value;
    if(Edward.Web.Validator.IsNullOrEmpty(pwd) || !Edward.Web.Validator.IsPassword(pwd))
    {
        $('spanPassword').className="Info_Error";
        return false;
    }
    else
    {
        $('spanPassword').className="Info_Right";
        $('spanPassword').innerHTML = " ok!填写正确!";
    }
    return true;
}

function ValidatePassword2()
{
    var pwd = $('ctl00_Content_txtPassword_Reg').value;
    var pwd2 = $('txtPassword2').value;
    if(Edward.Web.Validator.IsNullOrEmpty(pwd2) || !Edward.Web.Validator.IsPassword(pwd2) || pwd!=pwd2)
    {
        $('spanPassword2').className="Info_Error";
        return false;
    }
    else
    {
        $('spanPassword2').className="Info_Right";
        $('spanPassword2').innerHTML = " ok!填写正确!";
    }
    return true;
}

function ValidateEmail()
{
    var email = $('ctl00_Content_txtEmail').value;
    if(Edward.Web.Validator.IsNullOrEmpty(email) || !Edward.Web.Validator.IsEmail(email))
    {
        $('spanEmail').className="Info_Error";
        return false;
    }
    else
    {
        $('spanEmail').className="Info_Right";
        $('spanEmail').innerHTML = " ok!填写正确!";
    }
    if(Sale_ShoppingCart.IsExistEmail(email).value)
    {
        $('spanEmail').style.display = "none";
        $('spanEmailIsExist').className="Info_Error";
        $('spanEmailIsExist').style.display = "inline";
        return false;
    }
    else
    {
        $('spanEmail').style.display = "inline";
        $('spanEmail').className="Info_Right";
        $('spanEmail').innerHTML = " ok!填写正确!";
        $('spanEmailIsExist').style.display = "none";
    }
    return true;
}

function ValidateEmail2()
{
    var email = $('ctl00_Content_txtEmail').value;
    var email2 = $('txtEmail2').value;
    if(Edward.Web.Validator.IsNullOrEmpty(email2) || !Edward.Web.Validator.IsEmail(email2) || email!=email2)
    {
        $('spanEmail2').className="Info_Error";
        return false;
    }
    else
    {
        $('spanEmail2').className="Info_Right";
        $('spanEmail2').innerHTML = " ok!填写正确!";
    }
    return true;
}

function ValidateAccept()
{
    var accept = $('cbAccept').checked;
    if(!accept)
    {
        $('spanAccept').className="Info_Error";
        return false;
    }
    else
        $('spanAccept').className="Info_None";
    return true;
}

function goStep3()
{
    step = 3;
    validateProducts();
    displayProducts();
    cale();
    goTop();
    $('imgSv').src = "http://img.meheme.com/sv_3.jpg";
    $('step1').style.display = "block";
    $('step1_2').style.display = "block";
    $('step1_control').style.display = "none";
    $('step3_control').style.display = "block";
    $('step1_control_2').style.display = "none";
    $('step3_control_2').style.display = "block";
    $('step1_info').style.display = "none";
    $('step3_info').style.display = "block";
    $('step2').style.display = "none";
}

function backToStep2()
{
    goTop();
    $('step1').style.display = "none";
    $('step1_2').style.display = "none";
    $('step2').style.display = "block";
}

function goStep4()
{
    validateProducts();
    if(products.length==0)
    {
        alert("请您选购商品！");
        return;
    }
    displayProducts();
    goTop();
    $('step1').style.display = "none";
    $('step1_2').style.display = "none";
    $('step4').style.display = "block";
    displayDetail('divList_Step4');
    caleStep4();
}

function validateProducts()
{
    var newProducts = new Array();
    for(var index=0;index<products.length;index++)
    {
        if(products[index].BuyType==1)
            newProducts.push(products[index]);
    }
    products = newProducts;
}