function fillinshipping() {
    // this function will fill in the shipping fields with the values from the billing fields
    var customer = document.getElementById("contactinfo");
    customer.ship_fname.value=customer.fname.value;
    customer.ship_lname.value=customer.lname.value;

    customer.ship_address.value=customer.address.value;
    customer.ship_address2.value=customer.address2.value;
    customer.ship_city.value=customer.city.value;

    customer.ship_zip.value=$('zip').value;

    customer.ship_ph1.value=customer.ph1.value;
    customer.ship_ph2.value=customer.ph2.value;
    customer.ship_ph3.value=customer.ph3.value;

    customer.ship_country.value=customer.country.value;

    customer.ship_state.value=customer.state.value;
    customer.ship_province.value=customer.province.value;

    // now we need to make sure the appropriate states or provinces are shown...
    changecountry('ship')
    return false;
}

function gotoreview() {
    if (!validateaddress()) {
        return false;
    } else {

    }
}

function validateaddress() {
    var errors = "Please fix the following fields: \n\n";
    var e = "";
    var customer = document.getElementById("contactinfo");
    var fld="";
    var eship = "";
    var ebill = "";

    if (customer.fname.value=='') {
        e+= "First Name\n";
        if (fld=="") fld=customer.fname;
    }

    if (customer.lname.value=='') {
        e+= "Last Name\n";
        if (fld=="") fld=customer.lname;
    }
    if (customer.address.value=='') {
        e+= "Address\n";
        if (fld=="") fld=customer.address;
    }
    if (customer.city.value=='') {
        e+= "City\n";
        if (fld=="") fld=customer.city;
    }
    if (customer.zip.value=='') {
        e+= "Zip Code\n";
        if (fld=="") fld=customer.zip;
    }
    if (customer.email.value==''){
        e+= "Email\n";
        if (fld=="") fld=customer.email;
    }

    if (e != "") ebill = "Billing Address\n" + e;

    e="";
    if (customer.ship_fname.value=='') {
        e+= "First Name\n";
        if (fld=="") fld=customer.ship_fname;
    }

    if (customer.ship_lname.value=='') {
        e+= "Last Name\n";
        if (fld=="") fld=customer.ship_lname;
    }
    if (customer.ship_address.value=='') {
        e+= "Address\n";
        if (fld=="") fld=customer.ship_address;
    }
    if (customer.ship_city.value=='') {
        e+= "City\n";
        if (fld=="") fld=customer.ship_city;
    }
    if (customer.ship_zip.value=='') {
        e+= "Zip Code\n";
        if (fld=="") fld=customer.ship_zip;
    }

    if (e != "") eship = "Shipping Address\n" + e;

    if ( (eship != "") || (ebill != "") ) {
        alert (errors + ebill + '\n' + eship);
        $(fld).focus();
        return false;
    } else {
        return true;
    }

}



function finalcheckout() {
    var fm=document.getElementById("shoppingcart");
    fm.action="checkout.php";
    fm.todo.value="checkout";
    return true;
}

function clearcart() {
    var c = confirm("Are you sure?");
    if (c) {
        var fm=document.getElementById("shoppingcart");
        fm.action="cart.php";
        fm.todo.value="emptycart";
    } else {
        return false;
    }

}

function updatequanties() {
    var fm=document.getElementById("shoppingcart");
    fm.action="cart.php";
    fm.todo.value="updatecart";
}

function changecountry(billship) {
    // alert("change: " + billship);
    var fm=document.getElementById("contactinfo");
    // var fm=document.forms['contactinfo'];
    if (billship=='ship') {
        var fldval = document.getElementById("ship_country").value;
        if (fldval =="Canada") {
            document.getElementById("ship_usa").style.display="none";
            document.getElementById("ship_canada").style.display="block";
        } else {
            document.getElementById("ship_canada").style.display="none";
            document.getElementById("ship_usa").style.display="block";
        }
    } else {
        var fldval = document.getElementById("country").value;
        if (fldval =="Canada") {
            document.getElementById("usa").style.display="none";
            document.getElementById("canada").style.display="block";
        } else {
            document.getElementById("canada").style.display="none";
            document.getElementById("usa").style.display="block";
        }
    }
}
