// JavaScript Document


function selectSearchType(action, menuItem) {
    hideAllSearchModules();
    resetSearchTabStyle();
    switch (action) {
        case "dimension":
            document.getElementById('dimensionSearch').style.display = "block";
            focusSearchTab(menuItem);
            break;
        case "model":
            document.getElementById('modelSearch').style.display = "block";
            focusSearchTab(menuItem);
            break;
        case "full":
            document.getElementById('fullSearch').style.display = "block";
            focusSearchTab(menuItem);
            break;
        case "quick":
        default:
            document.getElementById('quickSearch').style.display = "block";
            focusSearchTab(menuItem);
            break;
    }
}

function linkSelectSearchType(action) {

    // save searchtype
    //
    var stype;
    var obj;
    stype = document.getElementById("searchtype");
    if (stype) {
        stype.value = action;
    }

    //alert(action);

    hideAllSearchModules();
    resetSearchLinkStyle();
    switch (action) {
        case "dimension":
            obj = document.getElementById('dimensionSearch');
            if (obj) {
                obj.style.display = "block";
                obj = document.getElementById('dimensionSearchLink');
                obj.style.color = "#CB6132";
            }
            break;
        case "model":
            obj = document.getElementById('modelSearch');
            if (obj) {
                obj.style.display = "block";
                obj = document.getElementById('mfgModelSearchLink');
                obj.style.color = "#CB6132";
            }
            break;
        case "full":
            obj = document.getElementById('fullSearch');
            if (obj) {
                obj.style.display = "block";
                obj = document.getElementById('fullSearchLink');
                obj.style.color = "#CB6132";
            }
            break;
        case "quick":
            obj = document.getElementById('quickSearch');
            if (obj) {
                obj.style.display = "block";
                obj = document.getElementById('quickSearchLink');
                obj.style.color = "#CB6132";
            } else {
                //alert('quickSearch not found.');
            }
            break;
    }

}




function resetSearchLinkStyle() {

    document.getElementById('quickSearchLink').style.color = null;
    document.getElementById('dimensionSearchLink').style.color = null;
    document.getElementById('mfgModelSearchLink').style.color = null;
    document.getElementById('fullSearchLink').style.color = null;

}

function focusSearchTab(el) {
    el.style.backgroundImage = "url(images/buttons/searchTabs/up.png)";
    el.style.color = "#FFFFFF";
    el.style.padding = "15px 0px 0px 0px";
    delete el;
}
function hideAllSearchModules() {
    var modules = getElementsByClassName('searchModules', document.getElementById('searchContent')); // view in js/common.js
    for (var i = 0; i < modules.length; i++) {
        //alert(modules[i].id);
        modules[i].style.display = "none";
    }
    delete modules;
}


function resetSearchTabStyle() {
    var navs = getElementsByClassName('mainSearchTab', document.getElementById('searchTabContainer'));
    for (var i = 0; i < navs.length; i++) {
        navs[i].style.padding = "20px 0px 0px 0px";
        navs[i].style.backgroundImage = "url(images/buttons/searchTabs/down.png)";
        navs[i].style.color = "";
    }
    delete navs;
}


function contactTheseSearchOptions(el) {
    var p = el.parentNode;
    while (p.className.indexOf('Expandable_Search_Container') == -1) {
        p = p.parentNode;
    }
    var container = getElementsByClassName('Container', p)[0];
    if (container.style.display == "none") {
        el.setAttribute('src', 'images/buttons/contract.gif');
        container.style.display = "block";
    } else {
        el.setAttribute('src', 'images/buttons/expand.gif');
        container.style.display = "none";
    }
    delete p, el, container;
}


function changeSearchFilterVisibility(button) {
    // action = block/none
    var target = button;
    while (target.className.indexOf('filter') == -1) {
        target = target.parentNode;
    }

    target = getElementsByClassName('body', target)[0];

    if (target.style.display == "none") {
        target.style.display = "block";
        button.setAttribute('src', 'images/buttons/contract.gif');
    } else {
        button.setAttribute('src', 'images/buttons/expand.gif');
        target.style.display = "none";
    }

    delete button, target;
}




function linkSelectSearchType2(action, ProductGroupID) {

    // save searchtype (dimension, full, model, quick)
    //
    var stype;
    stype = document.getElementById("searchtype");
    if (stype) {
        stype.value = action;
    }

    //alert("linkSelectSearchType : action=" + action);

    hideAllSearchModules();
    resetSearchLinkStyle();
    switch (action) {
        case "dimension":
            document.getElementById('dimensionSearch').style.display = "block";
            document.getElementById('dimensionSearchLink').style.color = "#CB6132";
            break;
        case "model":
            document.getElementById('modelSearch').style.display = "block";
            document.getElementById('mfgModelSearchLink').style.color = "#CB6132";

            // also select the incoming ProductGroupID

            break;
        case "full":
            document.getElementById('fullSearch').style.display = "block";
            document.getElementById('fullSearchLink').style.color = "#CB6132";
            break;
        case "quick":
        default:
            action = "quick";
            document.getElementById('quickSearch').style.display = "block";
            document.getElementById('quickSearchLink').style.color = "#CB6132";
            break;
    }

}

