window.addEvent('load',function(){
    if( $('InputCountry') ){
        /*/////////////////////////////////////////////////////////////////////////////////////////////
        // Dynamic Country / Province Toggling
        /*/////////////////////////////////////////////////////////////////////////////////////////////
        $('InputCountry').addEvent('change',function(){
            var pars = $('InputCountry').name+'='+$('InputCountry').options[$('InputCountry').selectedIndex].value;
            if ($('InputCountry').options[$('InputCountry').selectedIndex].value != ""){
                new Ajax( '/ajax/select_province.php', {
                    method: 'post',
                    postBody: pars,
                    update: $('InputProvinceDiv')
                } ).request();
            }
        });
    }

    if( $('Country') ){
        /*/////////////////////////////////////////////////////////////////////////////////////////////
        // Dynamic Country / Province Toggling
        /*/////////////////////////////////////////////////////////////////////////////////////////////
        $('Country').addEvent('change',function(){
            var pars = $('Country').name+'='+$('Country').options[$('Country').selectedIndex].value;
            if ($('Country').options[$('Country').selectedIndex].value != ""){
                new Ajax( '/ajax/select_province.php', {
                    method: 'post',
                    postBody: pars,
                    update: $('InputProvinceDiv')
                    /*,
                    onComplete: function(){
                    if ( !$('same_as_billing') ){
                    if ( $('shipping_InputProvince') && $('InputProvince') ){
                    UpdateProvince($('InputProvince'), $('shipping_InputProvince'));
                    }
                    if ( $('province_code') && $('shipping_province_code')){
                    UpdateProvince($('province_code'), $('shipping_province_code'));
                    }
                    }
                    }*/
                } ).request();
            }
        });
    }

    if( $('shipping_Country') ){
        /*/////////////////////////////////////////////////////////////////////////////////////////////
        // Dynamic Country / Province Toggling
        /*/////////////////////////////////////////////////////////////////////////////////////////////
        $('shipping_Country').addEvent('change',function(){
            var pars = 'country_code='+$('shipping_Country').options[$('shipping_Country').selectedIndex].value+'&field_id=shipping_InputProvince&field_name=shipping_province_code';
            if ($('shipping_Country').options[$('shipping_Country').selectedIndex].value != ""){
                new Ajax( '/ajax/select_province.php', {
                    method: 'post',
                    postBody: pars,
                    update: $('shipping_InputProvinceDiv')
                    /*,
                    onComplete: function(){
                    if ( !$('same_as_billing') ){
                    if ( $('shipping_InputProvince') && $('InputProvince') ){
                    UpdateProvince( $('InputProvince'), $('shipping_InputProvince'));
                    }
                    if ( $('province_code') && $('shipping_province_code')){
                    UpdateProvince($('province_code'), $('shipping_province_code'));
                    }
                    }
                    }*/
                } ).request();
            }
        });
    }
});

window.addEvent('domready',function(){
    if ( $('secondary-menu') ){
        $$('#secondary-menu img').each(function(img){
            var rel = (img.getProperty('rel') || 11);
            if (rel!=12){
                img.addEvent('mouseenter',function(){img.src=img.src.replace(/s=[0-9]{2}/i,'s=12')});
                img.addEvent('mouseleave',function(){img.src=img.src.replace(/s=[0-9]{2}/i,'s=11')});
            }
        });
    }
});

function UpdateProvince(src, dest){
    src.addEvent('change', function(){ dest.value = src.value;});
}