﻿function ChangeImg(ImgD,FitWidth,FitHeight)
{    
    var image=new Image(); 
    image.src=ImgD.src;
    var wb=image.width/FitWidth;
    var hb=image.height/FitHeight;
    var b=wb>=hb?wb:hb;
    if(b>1)
    {
        ImgD.width=image.width/b;        
        ImgD.height=image.height/b;
    }
    else
    {
        ImgD.width=image.width;        
        ImgD.height=image.height;
    }
 }

function ImgClick(id,ddlPrice,txtNum)
{
    var num=parseInt(document.getElementById(txtNum).value);
    if(!isNaN(num))
    {
        if(num>0)
        {
            var price=document.getElementById(ddlPrice).value;
            $.post("/WebSite/Web/ShoppingCart.aspx",{action:"addToBag",q:num,s:price,p:id},
            function(data){
            if(data=="1")
             {
             alert("Sorry,The product is sold out!");
             top.updateOrderInfo();
             }
             else
             {
             alert("Has been added to cart!");
             top.updateOrderInfo();
             }
             }
             );
        }
        else
        {
            alert("Please enter an integer greater than 0!");
        }
    }
    else
    {
        alert("Please enter the figure!");
    }
}
 
function CheckForm_CustomInfo()
{
    var ok=true;
    if(form1.txtRealName.value=="")
    {
        alert("Please enter your real name!");
        form1.txtRealName.focus();
        ok=false;
    }
    else if(form1.txtAddr.value=="")
    {
        alert("Please enter your address!");
        form1.txtAddr.focus();
        ok=false;
    }
    else if(form1.txtPhone.value=="")
    {
        alert("Please enter your phone!");
        form1.txtPhone.focus();
        ok=false;
    }
    else if(form1.txtEmail.value=="")
    {
        alert("Please enter your email address!");
        form1.txtEmail.focus();
        ok=false;
    }
    else
    {
         var emailStr=document.all.form1.txtEmail.value;
         var emailPat=/^(.+)@(.+)$/;
         var matchArray=emailStr.match(emailPat);
         if (matchArray==null) 
         { 
            alert("Please enter the correct e-mail format!")
            form1.txtEmail.focus();
            ok=false;
         }
    }
    
    return ok;
}

function CheckForm_CustomPassword()
{
    var ok=true;
    if(form1.txtOldPwd.value=="")
    {
        alert("Please enter your old new password!");
        form1.txtPwd.focus();
        ok=false;
    }
    else if(form1.txtPwd.value=="")
    {
        alert("Please enter your new password!");
        form1.txtPwd.focus();
        ok=false;
    }
    else if(form1.txtPwd2.value=="")
    {
        alert("Please enter your confirm password!");
        form1.txtPwd2.focus();
        ok=false;
    }
    else if(form1.txtPwd.value != form1.txtPwd2.value)
    {
        alert("New password and Confirm Password inconsistent!");
        form1.txtPwd2.focus();
        ok=false;  
    }
    
    return ok;
}

function CheckForm_CustomReg()
{
    var ok=true;
    if(form1.txtUserName.value=="")
    {
        alert("Please enter your user name!");
        form1.txtUserName.focus();
        ok=false;
    }
    else if(form1.txtPwd.value=="")
    {
        alert("Please enter your password!");
        form1.txtPwd.focus();
        ok=false;
    }
    else if(form1.txtPwd2.value=="")
    {
        alert("Please enter your confirm password!");
        form1.txtPwd2.focus();
        ok=false;
    }
    else if(form1.txtPwd.value != form1.txtPwd2.value)
    {
        alert("Password and Confirm Password are inconsistent!");
        form1.txtPwd2.focus();
        ok=false;  
    }
    else if(form1.txtRealName.value=="")
    {
        alert("Please enter your real name!");
        form1.txtRealName.focus();
        ok=false;
    }
    else if(form1.txtAddr.value=="")
    {
        alert("Please enter your address!");
        form1.txtAddr.focus();
        ok=false;
    }
    else if(form1.txtPhone.value=="")
    {
        alert("Please enter your phone!");
        form1.txtPhone.focus();
        ok=false;
    }
    else if(form1.txtEmail.value=="")
    {
        alert("Please enter your email address!");
        form1.txtEmail.focus();
        ok=false;
    }
    else if(form1.txtCode.value=="")
    {
        alert("Verification Code Incorrect!");
        form1.txtCode.focus();
        ok=false;
    }
    else
    {
         var emailStr=document.all.form1.txtEmail.value;
         var emailPat=/^(.+)@(.+)$/;
         var matchArray=emailStr.match(emailPat);
         if (matchArray==null) 
         { 
            alert("Please enter the correct e-mail address!")
            form1.txtEmail.focus();
            ok=false;
         }
    }
    
    return ok;
}

function CheckSend()
{
    var ok=true;
    if(form1.txtSubject.value=="")
    {
        alert("Please enter the Subject!");
        form1.txtSubject.focus();
        ok=false;
    }
    else if(form1.txtContent.value=="")
    {
        alert("Please enter the Content!");
        form1.txtContent.focus();
        ok=false;
    }
    else if(form1.txtCode.value=="")
    {
        alert("Please enter the Verification Code!");
        form1.txtCode.focus();
        ok=false;
    }
    return ok;
}

function CheckForm_ShoppingAddr()
{
    var ok=true;
    if(form1.txtName.value=="")
    {
        alert("Please enter your full name!");
        form1.txtName.focus();
        ok=false;
    }
    else if(form1.txtCity.value=="")
    {
        alert("Please enter the City!");
        form1.txtCity.focus();
        ok=false;
    }
    else if(form1.txtAddr.value=="")
    {
        alert("Please enter your address!");
        form1.txtAddr.focus();
        ok=false;
    }
    else if(form1.txtPhone.value=="")
    {
        alert("Please enter your phone!");
        form1.txtPhone.focus();
        ok=false;
    }
    else if(form1.txtZip.value=="")
    {
        alert("Please enter zip!");
        form1.txtZip.focus();
        ok=false;
    }
    else if(form1.txtEmail.value=="")
    {
        alert("Please enter your email address!");
        form1.txtEmail.focus();
        ok=false;
    }
    else
    {
         var emailStr=document.all.form1.txtEmail.value;
         var emailPat=/^(.+)@(.+)$/;
         var matchArray=emailStr.match(emailPat);
         if (matchArray==null) 
         { 
            alert("Please enter the correct e-mail format!")
            form1.txtEmail.focus();
            ok=false;
         }
    }
    
    return ok;
}

function SaveSearch()
{
    var url="Search.aspx?a=1";
    if(form1.txtName.value!="")
    {
        url+="&n="+form1.txtName.value;
    }
    else if(form1.txtShape.value!="")
    {
        url+="&s="+form1.txtShape.value;
    }
    else if(form1.txtColor.value!="")
    {
        url+="&co="+form1.txtColor.value;
    }
    else if(form1.txtDim.value!="")
    {
        url+="&d="+form1.txtDim.value;
    }
    else if(form1.txtTol.value!="")
    {
        url+="&t="+form1.txtTol.value;
    }
    else if(form1.txtMat.value!="")
    {
        url+="&m="+form1.txtMat.value;
    }
    else if(form1.txtPC.value!="")
    {
        url+="&p="+form1.txtPC.value;
    }
    
    location.href=url;
} 

function WinOpen()
{
    var num=form1.txtNum.value;
    window.open("http://wwwapps.ups.com/WebTracking/processInputRequest?loc=en_US&tracknum="+num);
}

function GetDateTime()
{
    //var dateTime=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());
    var dateTime=new Date();
    var str=dateTime.getFullYear()+"-"+dateTime.getMonth()+"-"+dateTime.getDate()+"  "+dateTime.getHours()+":"+dateTime.getMinutes()+":"+dateTime.getSeconds();
    switch(dateTime.getDay())
    {
        case 0:
            str+="&nbsp;Sunday";
            break;
        case 1:
            str+="&nbsp;Monday";
            break;
        case 2:
            str+="&nbsp;Tuesday";
            break;
        case 3:
            str+="&nbsp;Wednesday";
            break;
        case 4:
            str+="&nbsp;Thursday";
            break;
        case 5:
            str+="&nbsp;Friday";
            break;
        case 6:
            str+="&nbsp;Saturday";
            break;
    }
    document.write(str);
}

function UseCashCard(id)
{
    $.post("UseCashCard.aspx",
           { card:id},
           function(data)
           {
               if(data!=null)
               {
                    var amount=data.split(',');
                    document.getElementById("lbProduct").innerHTML="$&nbsp;"+amount[0];
                    try
                    {
                    document.getElementById("lbApply").innerHTML="$&nbsp;"+amount[2];
                    }
                    catch(e)
                    {}
                    document.getElementById("lbTotal").innerHTML="$&nbsp;"+amount[1];
               }
           } 
    ); 
}

function CheckActivat()
{
    var ok=true;
    if(form1.txtNum.value=="")
    {
        alert("Please enter your Cash Coupon Number!");
        form1.txtNum.focus();
        ok=false;
    }
    else if(form1.txtPassword.value=="")
    {
        alert("Please enter the Password!");
        form1.txtPassword.focus();
        ok=false;
    }
    
    return ok;
}