
function verify_continue(text){
    if( window.confirm(text) ){
        return true;
    }
    else{
        return false;
    }
}

function verify_continue_submit(text, form_id){
    if(verify_continue(text)){
        form_ref = document.getElementById(form_id);
        form_ref.submit();
    }

}

function verify_continue_link(url, text){
    if(verify_continue(text)){
        document.location = url;
    }

}

function get_next_url_delimitter(sString){
    var str = sString.toString();
    if(str.indexOf('?', 0) > -1){
        return '&';
    }
    
    return '?';

}


function copy_shipping_address_to_billing(checkbox_name){
    var field_names = new Array('first_name','last_name','company','address1','address2','city','state','country','zip','phone');

    for(i = 0; i < field_names.length; i++){
        ship_ref = document.getElementById('ship_' + field_names[i]);
        bill_ref = document.getElementById(field_names[i]);
        ship_ref.value = bill_ref.value ;
    }
}

function initCopyAddress(){
    var field_names = new Array('first_name','last_name','company','address1','address2','city','state','country','zip','phone');

    for(i = 0; i < field_names.length; i++){
        
        if(document.getElementById("ship_same_as_bill")){
            field_name = field_names[i];
        }
        else{
            field_name = 'ship_' . field_names[i];            
        }
        
        var from_ref = document.getElementById(field_name);
        addAnEvent(from_ref,'change',copyField);      
    }
}

function copyField(){
    var do_copy;
    
    if(document.getElementById("ship_same_as_bill")){
        do_copy = document.getElementById("ship_same_as_bill");
        to_name = 'ship_' + this.name;
    }
    else{
        document.getElementById("bill_same_as_ship");
        to_name = this.name.replace(/ship_/,"");

    }

    if(do_copy.checked){
        
        to_ref = document.getElementById(to_name);
        to_ref.value = this.value;
               
    }    
}