String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}

function setDealerPrivate(whichToSet) {
    var onlyCheckBox = document.forms['searchform'].elements['adtype'];
    var onlyDealerCheckBoxState = onlyCheckBox[0].checked;
    var onlyPrivateCheckBoxState = onlyCheckBox[1].checked;

    onlyCheckBox[0].checked = false;
    onlyCheckBox[1].checked = false;

    if (whichToSet == 'D') {
        onlyCheckBox[0].checked = onlyDealerCheckBoxState;
    }
    else {
        onlyCheckBox[1].checked = onlyPrivateCheckBoxState;
    }
}

function deselectRadios(radioName) {
    var radios = document.getElementsByName(radioName);
    if (radios.value == -1) return;
    if (radios != null) {
        for (var i = 0; i < radios.length; i++) {
            radios[i].checked = false;
        }
    }
}

var lastSelectedRadio = null;
function deselectIfSelected(radio) {
    if (lastSelectedRadio == null) {
        lastSelectedRadio = radio;
        return;
    }
    if (lastSelectedRadio == radio) {
        radio.checked = false;
        lastSelectedRadio = null;
    }
    else {
        lastSelectedRadio = radio;
    }
}

function addCaptchaHiddenField(doc, hiddenId, firstExpr, secondExpr, thirdExpr) {
    var form = doc.getElementById('aspnetForm');
    if (!form)
        return;
    var span = doc.createElement('span');
    form.appendChild(span);
    span.innerHTML =
        '<input type="hidden" id="' + hiddenId + '" name="' + hiddenId + '" />';
    var input = doc.getElementById(hiddenId);
    if (!input)
        return;
    input.value = (firstExpr + secondExpr) * thirdExpr;
    var scroll = document.getElementById('__SCROLLPOSITIONY');
    if (scroll) scroll.value = '0';
}

function selectFinanceSorting(selectName, boxControl) {
    if (boxControl.selectedIndex > 0) {
        var listBox = document.getElementById(selectName);

        if (listBox != null) {
            listBox.selectedIndex = 1;
        }
    }
}

/* Deselect "all europe" checkbox if one of the  
country checkboxes is unchecked */
function countryCheckBoxClicked(cb, europeId, otherCountriesId) {
    if (cb.checked == false) {
        gE(europeId).checked = false;
    }

    checkRadiusSearchPossible(europeId, otherCountriesId)
    setCurrentCountry();
}


function europeCheckBoxClicked(parentId, europe, defaultCbId) {
    var children = gE(parentId).getElementsByTagName("input");

    if (europe.checked == true) {
        enableCountryCheckboxes(true, europe, children);
        disableRadiusSearchAvailability(true);
    }
    else {
        enableCountryCheckboxes(false, europe, children);
        var defaultCb = gE(defaultCbId);
        if (defaultCb != null) {
            defaultCb.checked = true;
            disableRadiusSearchAvailability(false);
        }
        else {
            disableRadiusSearchAvailability(true);
        }
    }
    setCurrentCountry();
}

function enableCountryCheckboxes(enable, europe, children) {
    for (var i = 0; i < children.length; i++) {
        if (children[i].type == 'checkbox') {
            if (children[i] != europe) {
                children[i].checked = enable;
            }
        }
    }
}

/* Enables or disables the radius search input controls */
function disableRadiusSearchAvailability(disabled) {
    var textBox = gE('radiusDiv').getElementsByTagName('input');
    var dropDown = gE('radiusDiv').getElementsByTagName('select');

    if (typeof (defaultRadiusIndex) != "undefined") {
        dropDown[0].selectedIndex = defaultRadiusIndex;
    }
    else {
        dropDown[0].selectedIndex = 0;
    }
    if (disabled == true) {
        textBox[0].value = textBox[0].defaultText;
        //textBox[0].blur();

    }
    textBox[0].disabled = disabled;
    dropDown[0].disabled = disabled;

    if (dropDown[0].disabled) {
        AddCssClassToItem(inputDisabled, textBox[0]);
        AddCssClassToItem(selectDisabled, dropDown[0]);
    }
    else {
        RemoveCssClassFromItem(inputDisabled, textBox[0]);
        RemoveCssClassFromItem(selectDisabled, dropDown[0]);
    }
    radiusSelect.disabled = !isZipCodeValid(zipTxt.value, ctry);
}

function checkRadiusSearchPossible(europeId, otherCountriesId) {
    var countryCheckboxes = gE('countryTable').getElementsByTagName("input");
    var otherCountries = gE(otherCountriesId);
    var europe = gE(europeId)
    var checkedOnes = 0;
    if (otherCountries.checked == true || europe.checked == true) {
        disableRadiusSearchAvailability(true);
    }
    else {
        for (var i = 0; i < countryCheckboxes.length; i++) {
            if (countryCheckboxes[i].id != europeId && countryCheckboxes[i].id != otherCountriesId) {
                if (countryCheckboxes[i].checked) {
                    checkedOnes++;
                }
            }
        }
        (checkedOnes == 1) ? disableRadiusSearchAvailability(false) : disableRadiusSearchAvailability(true);
    }
}

// Input Type:
// 1 = Textbox
// 2 = Multiline Textbox
// 3 = Button
// 4 = CheckBox
// 5 = Dropdown
function FormElement(id, inputType) {
    this.Id = id;
    this.InputType = inputType;
}

var activeForm = null;
function hideModalLayer() {
    gE('modalLayer').style.display = 'none';
}

function showModalLayer(mlHeight) {
    gE('modalLayer').style.display = 'block';
    activeForm = gE('feedback-form');
    var hei = (mlHeight == 0 ? 295 : 0);
    centerForm(activeForm, hei);
    attachKeyDown();
}

function centerForm(fElem, centerHeight) {
    var wid = window.innerWidth ? window.innerWidth : document.body.clientWidth;
    var sm = gE('ctl00_ctl00_decoratedArea_scoutMenu');
    var widMenu = sm ? sm.clientWidth : 910; // for TT
    if (widMenu < wid) wid = widMenu;
    fElem.style.left = ((wid - fElem.clientWidth) / 2) + 'px';
    var hei = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight;
    var top = (hei - (centerHeight == 0 ? fElem.clientHeight : centerHeight)) / 2 - 20;
    if (top <= 10) {
        fElem.style.top = '10px';
        fElem.style.height = (hei - 60) + 'px';
        fElem.style.width = (fElem.clientWidth + 11) + 'px';
        fElem.style.overflowY = 'scroll';
    }
    else {
        fElem.style.height = '';
        fElem.style.width = '';
        fElem.style.overflowY = 'visible';
        fElem.style.top = top + 'px';
    }
}

function centerFormIE6(fElem, centerHeight) {
    if ($.browser.msie && parseInt($.browser.version) <= 6) {
        var wid = window.innerWidth ? window.innerWidth : document.body.clientWidth;
        var sm = gE('ctl00_ctl00_decoratedArea_scoutMenu');
        var widMenu = sm ? sm.clientWidth : 910; // for TT
        if (widMenu < wid) wid = widMenu;
        fElem.style.left = ((wid - fElem.clientWidth) / 2) + 'px';
        var hei = window.innerHeight ? window.innerHeight : document.documentElement.offsetHeight;
        var top = (hei - (centerHeight == 0 ? fElem.clientHeight : centerHeight)) / 2 - 20;
        if (top <= 10) {
            fElem.style.top = '10px';
            fElem.style.height = (hei - 60) + 'px';
            fElem.style.width = (fElem.clientWidth + 11) + 'px';
            fElem.style.overflowY = 'scroll';
        }
        else {
            fElem.style.height = '';
            fElem.style.width = '';
            fElem.style.overflowY = 'visible';
            fElem.style.top = top + document.body.parentElement.scrollTop + 'px';
        }
    }
}

function hideFeedbackForm() {
    hideModalLayer()
    if (activeForm != null) activeForm.style.display = 'none';
    activeForm = null;
    detachKeyDown();
}

var tabs;
function showHideForm(f, dis, pn, elemList) {
    gE('modalLayer').style.display = dis;
    var fElem = gE(f);
    fElem.style.display = dis;
    activeForm = fElem;
    if (dis != 'none') centerForm(fElem, 0);
    tabs = (dis == 'none' ? null : elemList);
    if (elemList) {
        if (dis != 'none') {
            gE(elemList[0].Id).focus();
            attachKeyDown();
        }
        else {
            detachKeyDown();
        }
    }
    // omniture
    if (pn) {
        if (typeof (CheckPageName) == 'function') pn = CheckPageName(pn);
        try {
            s.pageName = pn;
            s.events = '';
            var s_code = s.t();
            if (s_code) document.write(s_code);
        }
        catch (e) { }
    }
    if ($.browser.msie && parseInt($.browser.version) <= 6) {
        var sel = document.getElementsByTagName('select');
        for (var i = 0; i < sel.length; i++)
            if (sel[i].id.indexOf('insertionBugType') == -1) sel[i].style.display = (dis == 'block' ? 'none' : '');
    }
}
var shf = showHideForm;

function attachKeyDown() {
    var ml = gE('modalLayer');
    if (document.addEventListener) {
        document.addEventListener('keydown', handleKeyDown, false);
        if (ml) ml.addEventListener('mousedown', hideFeedbackForm, false);
    }
    else {
        document.attachEvent('onkeydown', handleKeyDown);
        if (ml) ml.attachEvent('onmousedown', hideFeedbackForm);
    }
}

function detachKeyDown() {
    var ml = gE('modalLayer');
    if (document.removeEventListener) {
        document.removeEventListener('keydown', handleKeyDown, false);
        if (ml) ml.removeEventListener('mousedown', hideFeedbackForm, false);
    }
    else {
        document.detachEvent('onkeydown', handleKeyDown);
        if (ml) document.detachEvent('onmousedown', hideFeedbackForm);
    }
}

var formOpened = false;
function startupContact() {
    if (formOpened) return;
    showHideForm('contact-form', 'block', s.pageName + '-Email', contactFormElements);
    formOpened = true;
}

/*Validate all fields of the contact form at once*/
function ValidateAllContactFormFields(source, args) {
    var cfFieldIds = getFieldIds();
    if (!cfFieldIds) {
        args.IsValid = true;
        return;
    }

    /*name required*/
    var userName = gE(cfFieldIds.usernameId);
    var nameIsValid = true;

    if (userName.value.length == 0) {
        nameIsValid = false;
    }
    else {
        userName.value = trim(userName.value);
        if (userName.attributes.defaultText && userName.attributes.defaultText.value == userName.value) {
            nameIsValid = false;
        }
        else {
            var rx = new RegExp(cfFieldIds.nameRx);
            var matches = rx.exec(userName.value);
            var matchName = (userName.value.length == 0 ? true : (matches != null && matches[0] == userName.value))
            if (!matchName) {
                nameIsValid = false;
            }
        }
    }

    nameIsValid ? RemoveClassName(userName, source.errorcssclass) : AddClassName(userName, source.errorcssclass)


    /*email & phone - one required*/
    var email = gE(cfFieldIds.emailId);
    var phone = gE(cfFieldIds.phoneId);
    var mailOrPhoneValid;

    var phoneSet = phone.value.length > 0;
    var emailSet = email.value.length > 0;
    if (email.value.length + phone.value.length == 0) {
        AddClassName(email, source.errorcssclass);
        AddClassName(phone, source.errorcssclass);
        mailOrPhoneValid = false;
    } else {
        RemoveClassName(email, source.errorcssclass);
        RemoveClassName(phone, source.errorcssclass);
        mailOrPhoneValid = true;

        var rx = new RegExp(cfFieldIds.emailRx);
        var matches = rx.exec(email.value);
        var matchEmail = (email.value.length == 0 ? true : (matches != null && matches[0] == email.value));
        if (emailSet && (!matchEmail)) {
            AddClassName(email, source.errorcssclass);
        }
        rx = new RegExp(cfFieldIds.phoneRx);
        matches = rx.exec(phone.value);
        var matchPhone = (phone.value.length == 0 ? true : (matches != null && matches[0] == phone.value));
        if (phoneSet && (!matchPhone)) {
            AddClassName(phone, source.errorcssclass);
        }

        mailOrPhoneValid = (emailSet && matchEmail && !phoneSet) || (phoneSet && matchPhone && !emailSet) || (emailSet && matchEmail && phoneSet && matchPhone);
    }

    /*message - required*/
    var messageIsValid = true;
    var message = gE(cfFieldIds.messageId);

    if (message.value.length == 0) {
        messageIsValid = false;
    }
    else {
        message.value = trim(message.value);
        if (message.attributes.defaultText && message.attributes.defaultText.value == message.value) {
            messageIsValid = false;
        }
        else {
            rx = new RegExp(cfFieldIds.msgRx);
            var matches = rx.exec(message.value);
            var matchMessage = (message.value.length == 0 ? true : (matches != null && matches[0] == message.value))
            if (!matchMessage) {
                messageIsValid = false;
            }
        }
    }

    messageIsValid ? RemoveClassName(message, source.errorcssclass) : AddClassName(message, source.errorcssclass);


    /*all*/
    if (nameIsValid && mailOrPhoneValid && messageIsValid) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function handleKeyDown(e) {
    // get current event
    var evt = (window.event ? window.event : e);
    if (evt) {
        // get current key code
        var code = (evt.keyCode ? evt.keyCode : evt.which);
        if (code == 27 && activeForm != null) {
            hideModalLayer();
            activeForm.style.display = 'none';
            activeForm = null;
        }
        if (code == 9 || code == 13) {
            // get current sender and find it's id in the tabs collection
            var curId = (evt.srcElement ? evt.srcElement.id : evt.target.id);
            var shift = evt.shiftKey;
            var curElement = -1;
            for (var i = 0; i < tabs.length; i++) {
                if (tabs[i].Id == curId) {
                    curElement = i;
                    break;
                }
            }
            if (code == 9) {
                // handle tab
                if (shift) {
                    // shift key is pressed
                    curElement--;
                    if (curElement < 0) curElement = tabs.length - 1;
                }
                else {
                    // only tab is pressed
                    curElement++;
                    if (curElement >= tabs.length) curElement = 0;
                }
                gE(tabs[curElement].Id).focus();
                // prevent event bubbling
                if (evt.preventDefault)
                    evt.preventDefault();
                else
                    evt.returnValue = false;
                return false;
            }
            if (code == 13) {
                // handle enter
                if (tabs[curElement].InputType == 3) {
                    // submit on single line and button
                    document.submit();
                }
                if (tabs[curElement].InputType != 2) {
                    // prevent event bubbling when not an multiline box
                    if (evt.preventDefault)
                        evt.preventDefault();
                    else
                        evt.returnValue = false;
                    return false;
                }
            }
        }
    }
}

function HidePhonePrefix(idCountry, idPrefix, idNumber, maintainClass) {
    var elemCountry = gE(idCountry);
    var text = elemCountry.options[elemCountry.selectedIndex].text;
    if (text == '+33' || text == '+34' || text == '+352') {
        gE(idPrefix).value = '';
        gE(idPrefix).style.display = 'none';
        gE(idPrefix).style.position = 'absolute';
        gE(idNumber).className = 'input-2col';
    }
    else {
        gE(idPrefix).style.display = '';
        gE(idPrefix).style.position = '';
        if (!maintainClass) {
            gE(idNumber).className = 'phone';
        }
    }
}

function ValidateString(idInput, source, regEx) {
    var ret;
    var elem = gE(idInput);
    var v = new RegExp(regEx);
    var m = v.exec(elem.value.trim());
    ret = (m != null && elem.value.trim() == m[0].trim());
    return ret;
}

function ValidateZip(idInput, idCountry, source, zipInfos) {
    var ret;
    var countryElem = gE(idCountry);
    var zipCodeElem = gE(idInput);
    var countryVal = countryElem.value;
    var zipCodeVal = zipCodeElem.value;

    var zipRegEx = zipInfos[0].zipRegEx;

    for (var i = 1; i < zipInfos.length; i++) {
        if (countryVal == zipInfos[i].country && zipInfos[i].zipRegEx != undefined) {
            zipRegEx = zipInfos[i].zipRegEx;
            break;
        }
    }

    var v = new RegExp(zipRegEx);
    var m = v.exec(zipCodeElem.value);
    ret = (m != null);

    return ret;
}

function getPhoneInfo(country) {
    var ret = new phoneInfo(phoneInfos[0].country, phoneInfos[0].hasPrefix, phoneInfos[0].prefixRegEx, phoneInfos[0].numberRegEx, phoneInfos[0].prefixMobileRegEx, phoneInfos[0].numberMobileRegEx);
    for (var i = 1; i < phoneInfos.length; i++) {
        if (country == phoneInfos[i].country) {
            ret.country = phoneInfos[i].country;
            ret.hasPrefix = phoneInfos[i].hasPrefix;
            if (phoneInfos[i].prefixRegEx != '')
                ret.prefixRegEx = phoneInfos[i].prefixRegEx;
            if (phoneInfos[i].numberRegEx != '')
                ret.numberRegEx = phoneInfos[i].numberRegEx;
            if (phoneInfos[i].prefixMobileRegEx != '')
                ret.prefixMobileRegEx = phoneInfos[i].prefixMobileRegEx;
            if (phoneInfos[i].numberMobileRegEx != '')
                ret.numberMobileRegEx = phoneInfos[i].numberMobileRegEx;
            break;
        }
    }
    return ret;
}

function ValidatePhonePrefix(idInput, idPhoneType, idCountry, source, phoneInfos, validateToTrueIfEmpty, validateToFalseIfHasNoPrefix, defaultText) {
    return ValidatePhonePrefixType(idInput, gE(idPhoneType).value, idCountry, source, phoneInfos, validateToTrueIfEmpty, validateToFalseIfHasNoPrefix, defaultText);
}

function ValidatePhonePrefixType(idInput, phoneTypeVal, idCountry, source, phoneInfos, validateToTrueIfEmpty, validateToFalseIfHasNoPrefix, defaultText) {
    var ret = true;
    var regEx;
    var countryElem = gE(idCountry);
    var inputElem = gE(idInput);

    var countryVal = countryElem.value;
    var inputVal = inputElem.value;

    var phoneInfo = getPhoneInfo(countryVal);

    if (!defaultText) {
        defaultText = '';
    }

    if (validateToFalseIfHasNoPrefix && !(phoneInfo.hasPrefix)) {
        ret = false;
    }
    else {
        if (!(validateToTrueIfEmpty) || (trim(inputVal) != '' && trim(inputVal) != defaultText)) {
            if (phoneInfo.hasPrefix) {
                if (phoneTypeVal == 'M') {
                    regEx = phoneInfo.prefixMobileRegEx;
                }
                else {
                    regEx = phoneInfo.prefixRegEx;
                }
                var v = new RegExp(regEx);
                var m = v.exec(inputVal);
                ret = (m != null);
            }
        }
    }

    return ret;
}

function ValidatePhoneNumber(idInput, idPhoneType, idCountry, source, phoneInfos, validateToTrueIfEmpty, defaultText) {
    return ValidatePhoneNumberType(idInput, gE(idPhoneType).value, idCountry, source, phoneInfos, validateToTrueIfEmpty, defaultText)
}

function ValidatePhoneNumberType(idInput, phoneTypeVal, idCountry, source, phoneInfos, validateToTrueIfEmpty, defaultText) {
    var ret = true;
    var regEx;
    var countryElem = gE(idCountry);
    var inputElem = gE(idInput);

    var countryVal = countryElem.value;
    var inputVal = inputElem.value;

    if (!(validateToTrueIfEmpty) || (trim(inputVal) != '' && trim(inputVal) != defaultText)) {
        var phoneInfo = getPhoneInfo(countryVal)
        if (phoneTypeVal == 'M') {
            regEx = phoneInfo.numberMobileRegEx;
        }
        else {
            regEx = phoneInfo.numberRegEx;
        }
        var v = new RegExp(regEx);
        var m = v.exec(inputVal);
        ret = (m != null);
    }
    return ret;
}

function CompareTextBoxEntries(id1, id2, source, required) {
    var ret;
    var elem1 = gE(id1);
    var elem2 = gE(id2);
    var val1 = elem1.value.trim();
    var val2 = elem2.value.trim();
    if (val1 == '' && val2 == '') {
        ret = !required;
    }
    else {
        ret = (val1 == val2);
    }
    return ret;
}

function OpenFormAndHideMe(formId, meId, anchor) {
    var f = gE(formId);
    f.style.display = 'block';
    gE(meId).style.display = 'none';
    var ot = f.offsetTop;
    if ($.browser.msie) ot += 200;
    if (anchor) window.scrollTo(0, ot);
    var inputs = f.getElementsByTagName('input');
    if (inputs.length > 0) {
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'text') {
                inputs[i].focus();
                break;
            }
        }
    }
}

function DisplayFurtherPhones() {
    var pl;
    for (pl = 2; pl < 5; pl++) {
        var elem = gE('phoneline' + pl);
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            break;
        }
    }
    if (pl == 4) gE('furtherPhonesText').style.display = 'none';
}

function DisplayCharsLeft(obj, dispElem, text, maxlen) {
    var counterHilightCss = 'redtext';
    var len = (maxlen ? maxlen : (obj.attributes.maxLength ? obj.attributes.maxLength.value : 0));
    if (len && len > 0) {
        var elem = $('#' + dispElem);
        var charsLeft = len - obj.value.length;
        elem.html(text.replace('{0}', charsLeft));
        if (charsLeft < 0) {
            elem.addClass(counterHilightCss);
        }
        else {
            elem.removeClass(counterHilightCss);
        }
    }
}

function SetHiddenFieldValue(sender, hiddenFieldId, hiddenFieldValue) {
    var hiddenField = gE(hiddenFieldId);
    if (typeof (hiddenField) != 'undefined') {
        if (hiddenField.value == hiddenFieldValue) {
            hiddenFieldValue = '0';
            sender.checked = false;
        }
        hiddenField.value = hiddenFieldValue;
    }
}

var ConvertKwToHp =
{
    startUp: function(kwId, hpId) {
        kw = $('#' + kwId);
        hp = $('#' + hpId);
        kw.bind('keydown', this.CheckNumEntry).bind('keyup blur', this.ConvertToHp);
        hp.bind('keydown', this.CheckNumEntry).bind('keyup blur', this.ConvertToKw);
        kwToHp = 1.35962162; // from wikipedia
        hpToKw = 0.73549875; // from wikipedia
        if (kw.val() != '')
            this.ConvertToHp();
        else if (hp.val() != '')
            this.ConvertToKw();
    },

    CheckNumEntry: function(event) {
        var ret = ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)
			|| event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 46 || event.keyCode == 37 || event.keyCode == 39);
        if (!ret) event.stopPropagation();
        return ret;
    },

    ConvertToHp: function() {
        if (kw.val() == '') {
            hp[0].disabled = '';
            hp.removeClass('disabled').val('');
        }
        else {
            var valueHp = Math.round(parseInt(kw.val()) * kwToHp);
            if (!isNaN(valueHp)) {
                hp.val(valueHp);
            }
            hp[0].disabled = 'disabled';
            hp.addClass('disabled');
        }
        return true;
    },

    ConvertToKw: function() {
        if (hp.val() == '') {
            kw[0].disabled = '';
            kw.removeClass('disabled');
            kw.val('');
        }
        else {
            var valueKw = Math.round(parseInt(hp.val()) * hpToKw);
            if (!isNaN(valueKw)) {
                kw.val(valueKw);
            }
            kw[0].disabled = 'disabled';
            kw.addClass('disabled');
        }
        return true;
    }
};

var DecisionCheckElements =
{
    startUp: function(_makeId, _monthId1, _yearId1, _hsnId, _tsnId, _monthId2, _yearId2, _hiddenId) {
        makeId = '#' + _makeId;
        monthId1 = '#' + _monthId1;
        yearId1 = '#' + _yearId1;
        hsnId = '#' + _hsnId;
        tsnId = '#' + _tsnId;
        monthId2 = '#' + _monthId2;
        yearId2 = '#' + _yearId2;
        decisionField = '#' + _hiddenId;
        $('#decision-form input').bind('blur', function(e) { DecisionCheckElements.Check(false); });
        $('#decision-form select').bind('click', function(e) { DecisionCheckElements.Check(false); });
        this.Check(true);
    },

    Check: function(firstCall) {
        var leftSideSet = $(makeId).val() != '0' || $(monthId1).val() != '0' || $(yearId1).val() != '0' || (firstCall && $(decisionField).val() == 'l');
        var rightSideSet = false;
        if (leftSideSet) {
            $(hsnId).val($(hsnId).attr('defaultText'));
            $(tsnId).val($(tsnId).attr('defaultText'));
            $(monthId2).val('0');
            $(yearId2).val('0');
        }
        else {
            rightSideSet = $(hsnId).val() != $(hsnId).attr('defaultText') || $(tsnId).val() != $(tsnId).attr('defaultText') || $(monthId2).val() != '0' || $(yearId2).val() != '0' || (firstCall && $(decisionField).val() == 'r');
        }
        $(decisionField).val(leftSideSet ? 'l' : (rightSideSet ? 'r' : ''));
        DecisionCheckElements.Enable(makeId, rightSideSet);
        DecisionCheckElements.Enable(monthId1, rightSideSet);
        DecisionCheckElements.Enable(yearId1, rightSideSet);
        DecisionCheckElements.Enable(hsnId, leftSideSet);
        DecisionCheckElements.Enable(tsnId, leftSideSet);
        DecisionCheckElements.Enable(monthId2, leftSideSet);
        DecisionCheckElements.Enable(yearId2, leftSideSet);
    },

    Enable: function(elem, state) {
        $(elem).disabled = !state;
        if (state) {
            $(elem).addClass('disabled');
        }
        else {
            $(elem).removeClass('disabled');
        }
    }
};

/*- begin ConfirmMessage2 - */

function SetConfirmKey(key) {
    $('#' + confirmKey).val(key);
    var t = $('#' + confirmText);
    t.html(t.attr(key == 'all' ? 'pluralCaption' : 'singularCaption'));
    gE('modalLayer').style.display = 'block';
    activeForm = gE('confirmArea');
    activeForm.style.display = 'block';
    var hei = activeForm.offsetHeight ? activeForm.offsetHeight : 150;
    if ($.browser.msie && parseInt($.browser.version) <= 6) {
        centerFormIE6(activeForm, hei);
    }
    else {
        centerForm(activeForm, hei);
    }
    attachKeyDown();

    comboboxForModal(false);
}
function ConfirmAreaEnter() {
    $('#modalLayer').hide();
    $('#confirmArea').hide();
}
function ConfirmAreaClose() {
    ConfirmAreaEnter();
    gE(confirmKey).value = '';
    comboboxForModal(true);
}
function comboboxForModal(enable) {
    if ($.browser.msie && parseInt($.browser.version) <= 6) {
        var sel = document.getElementsByTagName('select');
        for (var i = 0; i < sel.length; i++) {
            sel[i].style.display = enable ? 'block' : 'none';
        }
    }
}

/*- end ConfirmMessage2 - */

function ActivateMassuploaderId(listBoxObj, externalIdTextBoxId, currentInterfaceHiddenFieldId) {
    var massObj = gE('externalId');
    var usesExternalId = false;
    var externalIdTextBox = gE(externalIdTextBoxId);
    var currentInterfaceHiddenField = gE(currentInterfaceHiddenFieldId);
    var currentIndex = -1;
    var currentExtID = 0;

    if (listBoxObj.selectedIndex >= 0) {
        var elem = listBoxObj.options[listBoxObj.selectedIndex].value.split('|');
        if (elem.length == 2) usesExternalId = (elem[1] == '1');
    }
    if (usesExternalId) {
        massObj.style.display = 'block';

        if (currentInterfaceHiddenField) {
            var currentElem = currentInterfaceHiddenField.value.split('|');
            if (currentElem.length == 2) {
                currentIndex = currentElem[0];
                currentExtID = currentElem[1];
            }
        }
        if (listBoxObj.selectedIndex == currentIndex && currentExtID > 0) {
            if (externalIdTextBox) {
                externalIdTextBox.value = currentExtID;
            }
        }
        else {
            if (externalIdTextBox) {
                externalIdTextBox.value = '';
            }
        }
    }
    else {
        massObj.style.display = 'none';
        externalIdTextBox.value = '';
        listBoxObj.focus();
    }

}

function CheckExternalIdField(listBoxObjId, externalIdTextBoxId, classname) {
    var massObj = gE('externalId');
    var listBoxObj = gE(listBoxObjId);
    var externalIdTextBox = gE(externalIdTextBoxId);
    var usesExternalId = false;
    if (listBoxObj.selectedIndex >= 0) {
        var elem = listBoxObj.options[listBoxObj.selectedIndex].value.split('|');
        if (elem.length == 2) usesExternalId = (elem[1] == '1');
    }
    if (usesExternalId) {
        if (externalIdTextBox) {
            if (externalIdTextBox.value.length == 0) {
                AddClassName(externalIdTextBox, classname);
                return false;
            }
        }

        return true;
    }
    else {
        RemoveClassName(externalIdTextBox, classname);
        externalIdTextBox.value = '';
        return true;
    }
}

function showWebupload() {
    gE('modalLayer').style.display = 'block';
    var ww = gE('modalWait');
    ww.style.display = 'block';
    centerForm(ww, 0);
}
function deltaUploadDone() {
    ToggleTwoDivs('uploadDone', 'doUpload', 'none');
    gE('btns').style.display = 'block';
}

function CheckEmptyEnabledField(id, classname) {
    var obj = gE(id);
    if (obj && !obj.disabled) {
        if (obj.value.length == 0) {
            AddClassName(obj, classname);
            return false;
        }
        RemoveClassName(obj, classname);
    }
    return true;
}


var zipTxt = null;
var radiusSelect = null;

initZipControls = function() {
zipTxt = $('.zip-radius-ctrls input')[0];
radiusSelect = $('.zip-radius-ctrls select')[0];
    zipTxt.onkeyup = function() {
        radiusSelect.disabled = !isZipCodeValid(zipTxt.value, ctry);
    }
    if (!isZipCodeValid(zipTxt.value, ctry)) {
        radiusSelect.disabled = "disabled";
    }
}

setCurrentCountry = function() {
    if (!zipTxt.disabled) {
    	for(i=0;i<countries.length;i++)
    	{
    		var countryInfo = countries[i];
    		var inputElm = $("#" + countryInfo.InputId)[0];
    		if(inputElm != null && inputElm.checked)
    		{
    			ctry = countryInfo.CountryCode;
    			return;
    		}
    	}
    }
    else {
        ctry = '';
    }
}

createCountryInfo = function(inputId, countryCode)
{
	var countryInfo = new Object();
	countryInfo.InputId = inputId;
	countryInfo.CountryCode = countryCode;
	return countryInfo;
}