function myCountryIs (countryID) {

    var uriCourant = document.location.pathname;

    if (uriCourant=="/PBSCOrderForm.asp") {
        var States = [
        {
            id:196,
            names: ['Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware',
            'Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland',
            'Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire',
            'New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania',
            'Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington',
            'West Virginia','Wisconsin','Wyoming'],
            codes: [ 'AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME',
            'MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN',
            'TX','UT','VT','VA','WA','WV','WI','WY']
        }
        /*put other countries here*/
        ];

        detectCountry ('BillingCountryItem', 'BillingState', 'FirstName');
        detectCountry ('ShippingCountryItem', 'ShippingState', 'ShippingFirstName');
    }

    function onEvent(domNode, evt, fn){
        if (domNode.attachEvent) {
            domNode.attachEvent('on' + evt, fn);
        } else {
            domNode.addEventListener(evt, fn, false);
        }
    }

    function detectCountry (countryNode, stateNode, checkNode) {
        var testNodeZone = document.getElementsByName(checkNode)[0];
        if (testNodeZone) {
            var stateZone=document.getElementsByName(stateNode),
            stateZoneValue,
            stateZoneOriginalHTML = stateZone[0].parentNode.innerHTML,
            stateZoneOriginalText = stateZone[0].parentNode.getElementsByTagName("font")[0].innerHTML,
            countryZone=document.getElementsByName (countryNode),
            alreadyModified=false;

            onEvent (countryZone[0], 'change', transformState);

            if (countryID) {
                setDefaultCountry ();
            }

            transformState();
        }

        function setDefaultCountry () {
            if (!testNodeZone.value) {
                var countryList = countryZone[0].options;

                for(var i=0; i<countryList.length; i++) {
                    var countryListValue=countryList[i].value;

                    if (countryListValue.substr(0,countryListValue.indexOf("]",0))==countryID) {
                        countryList[i].selected=true;
                    }
                }
            }
        }

        function transformState () {
            var selectedCountry = document.getElementsByName(countryNode)[0],
            selectedCountryValue = selectedCountry.options[selectedCountry.selectedIndex].value,
            inTheList=false;

            for (var j=0; j<States.length; j++) {
                if (selectedCountryValue.substr(0,selectedCountryValue.indexOf("]",0))==States[j].id) {
                    stateZoneValue=stateZone[0].value;
                    var listState = '<font class="PBStatic">' + stateZoneOriginalText + '<span class="PBRequired">&nbsp;*</span></font>\n\
                                    <br><select size="1" name="' +stateNode + '" class="PB">';

                    for (var i=0; i<States[j].codes.length; i++) {
                        listState +='<option value="' + States[j].codes[i] + '"';
                        if ( States[j].codes[i]==stateZoneValue) {
                            listState += ' selected="selected"';
                        }
                        listState +='>' + States[j].names[i] + '</option>';
                    }

                    listState += '</select>';
                    alreadyModified=true;
                    inTheList=true;
                    stateZone[0].parentNode.innerHTML=listState;

                }
            }
            if (alreadyModified && !inTheList) {
                stateZoneValue=stateZone[0].options[stateZone[0].selectedIndex].value;
                stateZone[0].parentNode.innerHTML=stateZoneOriginalHTML;
                stateZone[0].value=stateZoneValue;
                alreadyModified=false;
            }
        }
    }
}
