var totalMenus;
var initialMenu;

function initMenu(tMenus, iMenus, lang) {
    totalMenus = tMenus;
    initialMenu = iMenus;
    showSubmenu(iMenus, lang);
}

function selectMenu(id, lang) {

    if (document.getElementById('mIL' + id)) document.getElementById('mIL' + id).style.background = "url(images/layout/selectedMenuItemLeft.gif) no-repeat";
    if (document.getElementById('mIB' + id)) document.getElementById('mIB' + id).style.background = "url(images/layout/selectedMenuItemCenter.gif) repeat-x";
    if (document.getElementById('mIR' + id)) document.getElementById('mIR' + id).style.background = "url(images/layout/selectedMenuItemRight.gif) no-repeat";
    if (document.getElementById('menu' + id)) document.getElementById('menu' + id).className = "selectedMenuItem";
    if (document.getElementById('img' + id)) document.getElementById('img' + id).src = "images/menu/" + id + "_on_" + lang + ".gif";
}

function unSelectMenu(id, lang) {
    if (document.getElementById('mIL' + id)) document.getElementById('mIL' + id).style.background = "url(images/layout/unselectedMenuItemLeft.gif) no-repeat";
    if (document.getElementById('mIB' + id)) document.getElementById('mIB' + id).style.background = "url(images/layout/unselectedMenuItemCenter.gif) repeat-x";
    if (document.getElementById('mIR' + id)) document.getElementById('mIR' + id).style.background = "url(images/layout/unselectedMenuItemRight.gif) no-repeat";
    if (document.getElementById('menu' + id)) document.getElementById('menu' + id).className = "unselectedMenuItem";
    if (document.getElementById('img' + id)) document.getElementById('img' + id).src = "images/menu/" + id + "_off_" + lang + ".gif";
}

function showInitialSubmenu(lang) {
    showSubmenu(initialMenu, lang);
}

function showSubmenu(id, lang) {

    selectMenu(id, lang);

    if (document.getElementById('submenu' + id)) document.getElementById('submenu' + id).style.display = '';

    for (var i = 1; i <= totalMenus; i++) {
        if (i != id) {

            unSelectMenu(i, lang);
            if (document.getElementById('submenu' + i)) document.getElementById('submenu' + i).style.display = 'none';
        }
    }
}


function doSearch() {
    StripHTMLFromSearchText();

    var searchText = document.getElementById('ctl00_txtSearch').value;
    top.location = 'http://www.blueairweb.com/Cauta/' + searchText;
    return false;

}

function setSearchButtonFocus() {
    document.getElementById('ctl00_btnSearch').focus();
}

function GetEnter(e) {
    var keycode;

    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;

    if (keycode == 13) //enter
    {
        StripHTMLFromSearchText();
        doSearch();
        return false;
    }
}


function StripHTMLFromSearchText() {
    var txtSearch = document.getElementById('ctl00_txtSearch');
    txtSearch.value = txtSearch.value.stripHTML();

}

String.prototype.stripHTML = function() {
    // What a tag looks like
    var matchTag = /<(?:.|\s)*?>/g;
    // Replace the tag
    return this.replace(matchTag, "");

}


//function changeLang(langCode) {
//    //langCode = 'en-US';
//    //return;
//    if ((langCode == 'en-US') || (langCode == 'ro-RO'))
//        window.location.href = location.pathname + "?culture=" + langCode;
//      
//}