
String.prototype.startsWith = function (str) {
    return (this.toLowerCase().indexOf(str) === 0);
}
var constUnableToChange = "We are unable to change your language setting within the Quote Cart.";
var constCartItemWarning = "Please Note:  You have added items to your quote cart in the current\r\nlanguage setting. To continue adding items to your quote cart or to\r\ncomplete your session, please return to this language setting.";

function Translate(arg) {
    //only translate if the cart is empty
    var isCartLoaded = document.getElementById('cartloaded');

    var processFRtranslation = true;

    if (window.location.pathname.startsWith('/tek/')) {
        processFRtranslation = false;
        alert('We are unable to change language on this Web page.');
    }

    if (arg == 'fr' && !window.location.pathname.startsWith('/fr/') && processFRtranslation) {
        var pname = window.location.pathname.toLowerCase();
        if (pname == '/rentlease.aspx')
            pname = '/rentlease_fr.aspx';

        if (pname == '/specials.aspx')
            pname = '/specials_fr.aspx';

        //shopping cart pages can not be translated
        if (pname == '/products/search/scquantity.aspx' || pname == '/products/search/terms.aspx' || pname == '/products/search/info.aspx' || pname == '/products/search/checkout.aspx') {
            alert(constUnableToChange);
        }
        else {
            if (isCartLoaded != null)
                alert(constCartItemWarning);
            window.location.href = "http://" + window.location.hostname + "/fr" + pname + window.location.search;
        }
    }

    if (arg == 'uk' && window.location.pathname.startsWith('/fr/')) {
        var pname = window.location.pathname.replace('/fr/', '/').toLowerCase();
        if (pname == '/rentlease_fr.aspx')
            pname = '/rentlease.aspx';

        if (pname == '/specials_fr.aspx')
            pname = '/specials.aspx';

        //shopping cart pages can not be translated
        if (pname == '/fr/products/search/scquantity.aspx' || pname == '/fr/products/search/terms.aspx' || pname == '/fr/products/search/info.aspx' || pname == '/fr/products/search/checkout.aspx') {
            alert(constUnableToChange);
        }
        else {
            if (isCartLoaded != null)
                alert(constCartItemWarning);
            window.location.href = "http://" + window.location.hostname + pname + window.location.search;
        }
    }

}

