/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){



});


function orderStep3Submit(){
    if (vatFormIsempty()){
        copyFormInputs();
    }

    $('#addressForm').submit();
    
}

function vatFormIsempty(){

    var inputCollection = $('table#vat_data_table').find('input');
    var inputsValsCollection = $(inputCollection).filter(function(index){

       if ($(this).val() != ''){
           return true;
       }
       else{
           return false;
       }

    });
    
    return (inputsValsCollection.length == 0) ? true : false;
}

function copyFormInputs(){

    var inputs = $('table#vat_data_table').find('input');

    inputs.each(function(){
       $(this).val($('#'+$(this).attr('name')).val());
    });

    var selCountry = $('#vat_id_country').children('option').filter(function(index){

       if ($(this).val() == $('#id_country option:selected').val()){
           return true;
       }
       else{
           return false;
       }

    });
    $(selCountry).attr('selected','selected');

}