/* 
 * Written by Will Hattingh
 *
 * This file is to serve only the NeuStore/checkout module page.
 */

$(document).ready(function(){
    $("#checkoutForm").validate();
    isperson();
    samebilling();
});
$("#billSame").click(function(){
    samebilling();
});
$("#hidecompanybox").click(function(){
    isperson();
});
function isperson(){
    if ($("#hidecompanybox").attr("checked") == true){
        $('#companybox').appendTo("#hidecompany");
    }else{
        $("#companybox").appendTo("#companyboxHolder");
    }
}
function samebilling(){
    if ($("#billSame").attr("checked") == true){
        $('#billingMovable').appendTo("#hidebill");
    }else{
        $("#billingMovable").appendTo("#billingSameAsAccountCont");
    }
}
$('#faxareacode').keyup(function ()
{
    if( this.value.length == 3 )
    {
        $('#faxprefix').focus();
    }
});

$('#faxprefix').keyup(function ()
{
    if( this.value.length == 3 )
    {
        $('#faxsuffix').focus();
    }
});
$('#phoneareacode').keyup(function ()
{
    if( this.value.length == 3 )
    {
        $('#phoneprefix').focus();
    }
});

$('#phoneprefix').keyup(function ()
{
    if( this.value.length == 3 )
    {
        $('#phonesuffix').focus();
    }
});

$('.continue-shopping').bind( 'click', function(e)
{
    $('#ultraaction').val( 'continueshopping' );
    $('#continue-button').click();
});




/*$('select[name="acct_state"]').change(function () {
         var state = $("#statesList1").val();
        if(state == "OT"){
          $("#otherState1").show();
          $('input[name="acct_other_state"]').addClass("required");
          $("#phoneareacode").attr('minlength','1');
          $('input[name="acct_zip"]').attr('maxlength','7');
          $('input[name="acct_zip"]').removeClass("number");
         }
         else{
          $("#otherState1").hide();
          $('input[name="acct_other_state"]').removeClass("required");
          $("#phoneareacode").attr('minlength','3');
          $('input[name="acct_zip"]').attr('maxlength','5');
          $('input[name="acct_zip"]').addClass("number");
         }
});

$('select[name="bill_state"]').change(function (){
         var state = $("#statesList2").val();
        if(state == "OT"){
          $("#otherState2").show();
          $('input[name="bill_other_state"]').addClass("required");
         }
         else{
          $("#otherState2").hide();
          $('input[name="bill_other_state"]').removeClass("required");
         }
});

$('select[name="cc_year"]').change(function () {
     var d=new Date();
     var cc_m=$('select[name="cc_mo"]').val();
     var cc_yr=$('select[name="cc_year"]').val();

    if(cc_yr < d.getFullYear()){
       $('select[name="cc_year"]').after("<span class='error' style='margin-left: 204px; *margin-left: 10px;'>Your card is expired</span>");
     }
    if(cc_yr == d.getFullYear()){
      if(cc_m < (d.getMonth()+1)){
        $('select[name="cc_year"]').after("<span class='error' style='margin-left: 204px; *margin-left: 10px;'>Your card is expired</span>");
       }
     }
});

$('select[name="acct_country"]').change(function () {
         var country = $("#countrylist").val();
        // alert(country);
        if(country == "US" || country == "PR" || country == "CA"){
            $("#phonecountrycode").val('+1');
            $("#phonecountrycode").hide();

         }else{
         $("#phonecountrycode").val('+1');
          $("#phonecountrycode").show();
         }
}); */

