

// initialize lists with state and province codes
var USStates = "AA|AE|AK|AL|AP|AR|AS|AZ|CA|CO|CT|DC|DE|FL|FM|GA|GU|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MH|MI|MN|MO|MP|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|PR|PW|RI|SC|SD|TN|TX|UT|VA|VI|VT|WA|WI|WV|WY";
var CAProvnc = "AB|BC|MB|NB|NL|NS|NT|NU|ON|PE|QC|SK|YT";

var shipCost =  0.00;

var shipSTID = "AK & HI";
var shipUSID = "Cont. US";
var shipCAID = "Canada";
var shipUKID = "UK Express";

var shipToAK = "AK";
var shipToHI = "HI";
var shipToCA = "Canada";
var shipToUS = "United States";
var shipToUK = "United Kingdom";

var skipShip = "user_country";
var shipStat = "shippingState";
var shipCtry = "shippingCountry";
var shipType = "shippingType";
var shipMthd = "shippingMethod";

function setCountry(stateSelector, countrySelectorID)
{
    var state = stateSelector.options[stateSelector.selectedIndex].value;
    var check = 0;
    var cntry = shipToUS;

    if (USStates.search(state) != -1) {
        check = 1;
    } else if (CAProvnc.search(state) != -1) {
        check = 2;
        cntry = shipToCA;
    } else if (myCountry == "UK") {
        check = 3;
        cntry = shipToUK;
    }

    document.getElementById(countrySelectorID).selectedIndex = check;

    if (countrySelectorID == shipCtry) {
        setShippingRate(cntry);
    }

    return;
}

function setShippingRate(selector)
{
    var country = document.getElementById(shipCtry);

    if (typeof(selector) == 'object') {

        country = country.options[country.selectedIndex].value;

    } else {

        country = selector;
    }

    var shippingType = document.getElementById(shipType);
    var shippingMthd = document.getElementById(shipMthd);
    var shippingStat = document.getElementById(shipStat);

    if (country == shipToCA) {
        shippingMthd.value = shipCAID;
        shippingType.selectedIndex = 2;
    }

    if (country == shipToUK) {
        shippingMthd.value = shipUKID;
        shippingType.selectedIndex = 3;
    }

    if (country == shipToUS) {

        var stateName = shippingStat.options[shippingStat.selectedIndex].value;

        if (stateName == shipToAK || stateName == shipToHI) {
            shippingMthd.value = shipSTID;
            shippingType.selectedIndex = 1;
        } else {
            shippingMthd.value = shipUSID;
            shippingType.selectedIndex = 0;
        }
    }

    updateThisOrder(shippingType);
}


/* END */
