var debug = false;
var CS_countrylist = { "US": 0, "WW": 1, "CA": 2, "FR": 3, "DE": 4, "UK": 5 };
var CS_countrydetails = new Array("http://www.cumminsallison.com","http://www.cumminsallison.com/worldwide/default.htm","http://www.cumminsallison.ca","http://www.cumminsallison.fr","http://www.cumminsallison.de","http://www.cumminsallison.co.uk");
var CS_eCurrentCountry = null;var CS_ddCountries = null;var CS_btnGo = null;var CS_chkRemember = null;

function CS_DetectCookie(eCurrentSite) {
    if (!debug) {
        var prefSite = $.cookie("prefSite");
        if (prefSite != null) {
            if (prefSite != eCurrentSite) {
                CS_GotoSite(prefSite);
            }
        }
    }
}

function CS_Initialize(e, dd, btn, chk) {
    CS_eCurrentCountry = e; CS_ddCountries = dd; CS_btnGo = btn; CS_chkRemember = chk;
    CS_btnGo.click(function () { CS_Navigate(); });
}

function CS_Navigate() {
    var eSite = CS_ddCountries.val();
    var bRemember = CS_chkRemember.attr('checked');
    if (bRemember) { 
        $.cookie("prefSite", eSite, { expires: 730 });
    }
    CS_GotoSite(eSite);
}

function CS_GotoSite(eSite) {
    var nIndex = CS_Enum(eSite);
    var sUrl = CS_countrydetails[nIndex];
    parent.window.location.href = sUrl;
}

function CS_GetValues(eSite) {
    return aValues;
}

function CS_WriteCookie(cname, cvalue, cexpire) {
    document.cookie = cname + '=' + escape(cvalue) + (typeof cexpire == 'date' ? 'expires=' + cexpire.toGMTString() : '') + ',path=/;domain=cumminsallison.com';
}

function CS_Enum(e) {
    var nIndex;
    switch(e) {
        case "US":
            nIndex = 0;
            break;
        case "WW":
            nIndex = 1;
            break;
        case "CA":
            nIndex = 2;
            break;
        case "FR":
            nIndex = 3;
            break;
        case "DE":
            nIndex = 4;
            break;
        case "UK":
            nIndex = 5;
            break;
        default:
            nIndex = -1;
            break;
    }
    return nIndex;
}
