﻿// JScript File

//--------------- setting value for shipping as billing ---------------

// ------------------ Numeric field validation -------------------
 function numbersonly(myfield, e, dec) 
    {
 var key;
 var keychar;
 
 if (window.event)
    key = window.event.keyCode;
 else if (e)    key = e.which;
 else
    return true;
 keychar = String.fromCharCode(key);

 // control keys
 if ((key==null) || (key==0) || (key==8) || 
  (key==9) || (key==13) || (key==27) )
    return true;

 // numbers
 else if ((("0123456789").indexOf(keychar) > -1))
    return true;

 // decimal point jump
 else if (dec && (keychar == "."))
    {
    myfield.form.elements[dec].focus();
    return false;
    }
 else
    return false;
 }
 
 //-----------------  --------------------
 
  function IsEmpty1(fld,msg)
{

if((fld.value == "" || fld.value.length == 0) && (msg == ''))
{
return false;
}
var regex = /^\s*$/; 
if(regex.test(fld.value))
{
alert(msg);
fld.focus();
return false;
}
return true;
}

//------ validation userinfo.aspx page  ---------
    function validate()
{          
    var ErrMsg = '';
    var flag = true; 
if  (IsEmpty1(document.getElementById('txtFistName'),"Billing Information-Please enter first name.")==false)
return false;
if  (IsEmpty1(document.getElementById('txtLastName'),"Billing Information-Please enter last name.")==false)
return false;

if (IsEmpty1(document.getElementById('txtAddress1'),"Billing Information-Please enter Address.")==false)
return false;

if (IsEmpty1(document.getElementById('txtCity'),"Billing Information-Please re-enter E-mail address.")==false)
return false;

if (document.getElementById('txtCountries').selectedIndex!=0)
{
    if (document.getElementById('txtCountries').value=="1")
    {
        if (document.getElementById('txtState').selectedIndex==0)
        {
            alert("Billing Information-Please select option");
            document.getElementById('txtState').focus();
            return false;
        }
    }
    
 }   
 
 
if (IsEmpty1(document.getElementById('txtZip'),"Billing Information-Please enter zipcode.")==false)
return false;
/*if (document.getElementById('txtzip').value.length != 5) 
               {
                ErrMsg+="Billing Information-Invalid zipcode \n";
               }
  */           
if (document.getElementById('txtCountries').selectedIndex==0)
        {
            alert("Billing Information-Please select option");
            document.getElementById('txtCountries').focus();
            return false;
        }     
        
if (document.getElementById('txtCountries2').selectedIndex==0)
{
    alert("Billing Information-Please select option");
    document.getElementById('txtCountries2').focus();
    return false;
}        
             
             

if (document.getElementById('txtCountries2').selectedIndex!=0)
{
    if (document.getElementById('txtCountries2').value=="1")
    {
        if (document.getElementById('txtState2').selectedIndex==0)
        {
            alert("Shipping Information-Please select option");
            document.getElementById('txtState2').focus();
            return false;
        }
    }
    
 }   
 
if (IsEmpty1(document.getElementById('txtPhno'),"Billing Information-Please enter zipcode.")==false)
return false;

if (IsEmpty1(document.getElementById('txtEmail'),"Billing Information-Please enter Email address.")==false)
return false;
if ((document.getElementById('txtEmail').value.length!=0) && (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('txtEmail').value)==false))
               {
                alert("Billing Information-Invalid Email Address.");
                document.getElementById('txtEmail').focus();
                return false;
               }

if  (IsEmpty1(document.getElementById('txtFirstName2'),"Shipping Information-Please enter first name.")==false)
return false;
if  (IsEmpty1(document.getElementById('txtLastName2'),"Shipping Information-Please enter last name.")==false)
return false;
if (IsEmpty1(document.getElementById('txtBAddress'),"Shipping Information-Please enter contact no.")==false)
return false;
if (IsEmpty1(document.getElementById('txtCity2'),"Shipping Information-Please re-enter E-mail address.")==false)
return false;
   
if (IsEmpty1(document.getElementById('txtZip2'),"Shipping Information-Please enter zipcode.")==false)
return false;
 /*if (document.getElementById('txtzip2').value.length != 5) 
               {
                ErrMsg+="Shipping Information-Invalid zipcode \n";
               } 
               */

if (IsEmpty1(document.getElementById('txtPhno2'),"Shipping Information-Please enter zipcode.")==false)
return false;
if (IsEmpty1(document.getElementById('txtEmail2'),"Shipping Information-Please enter Email address.")==false)
return false;
if ((document.getElementById('txtEmail2').value.length!=0) && (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('txtEmail2').value)==false))
               {
                alert("Shipping Information-Invalid Email Address.");
                document.getElementById('txtEmail2').focus();
                return false;
               }                               
if (ErrMsg != '')
 {
     alert(ErrMsg);
     flag=false;
     return flag;
 }
//else
// {  
//     flag=true;
//     return flag;
// }

      
}
//-------- validating payment details page ------------

function validate_payment()
{          
    var ErrMsg = '';
    var flag = true; 
if (IsEmpty1(document.getElementById('txtCCName'),"Please insert name as per credit card.")==false)
return false;
if (IsEmpty1(document.getElementById('txtCCNo'),"Please insert Credit Card no.")==false)
return false;

if (IsEmpty1(document.getElementById('txtMonth'),"Please insert expiration month of credit card.")==false)
return false;
if (IsEmpty1(document.getElementById('txtYear'),"Please insert expiration year of credit card.")==false)
return false;        
}
