/*  
   *****Mitch Rogers
        Rogers Consulting LLC
        Knoxville TN*****
*/

var SHOWHIDE_ELEMENTS = {"records" : [
                                          {"id" : "s_con", "status" : "off", "callback" : ""},
                                          {"id" : "ss_con", "status" : "on", "callback" : ""}
                                      ]};
var _MPRODUCT_CONTAINER = false;

function hideEle(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'none';
        }
        else { // IE 4
            document.all.id.style.display = 'none';
        }
    }
}

function showEle(id) {
    //safe function to show an element with a specified id
          
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'block';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'block';
        }
        else { // IE 4
            document.all.id.style.display = 'block';
        }
    }
}


function init_SHOWHIDE()
{
    var ele;
    var eff;
    var opt;
    var title;
    for(var i in SHOWHIDE_ELEMENTS.records)
    {
        if(SHOWHIDE_ELEMENTS.records[i].status == "off")
        {
            hideEle(SHOWHIDE_ELEMENTS.records[i].id);
            document.getElementById(SHOWHIDE_ELEMENTS.records[i].id + '_title').className = 'stitle_off';
            SHOWHIDE_ELEMENTS.records[i].status = "on";
        }
        else
        {
            showEle(SHOWHIDE_ELEMENTS.records[i].id);
            document.getElementById(SHOWHIDE_ELEMENTS.records[i].id + '_title').className = 'stitle_on'; 
            SHOWHIDE_ELEMENTS.records[i].status = "off";
        }
        
    } 
}

function showHide(id)
{
    var ele = '';
    var callback = false;
    for(var i in SHOWHIDE_ELEMENTS.records)
    {
        if(id == SHOWHIDE_ELEMENTS.records[i].id)
        {
            if(SHOWHIDE_ELEMENTS.records[i].status == "off")
            {
                hideEle(SHOWHIDE_ELEMENTS.records[i].id);
                document.getElementById(SHOWHIDE_ELEMENTS.records[i].id + '_title').className = 'stitle_off';
                SHOWHIDE_ELEMENTS.records[i].status = "on";
            }
            else
            {
                showEle(SHOWHIDE_ELEMENTS.records[i].id);
                document.getElementById(SHOWHIDE_ELEMENTS.records[i].id + '_title').className = 'stitle_on';
                SHOWHIDE_ELEMENTS.records[i].status = "off";
            }
        }
        
    }
}

function build_radio_button(nObj,variant)
{
    var oButton;
    oButton = new YAHOO.widget.ButtonGroup({
                                id: variant + nObj.key + '_button', 
                                name:variant + nObj.key + '_button', 
                                container: "search_option_con_" + variant + nObj.key });
    oButton.addButtons(nObj.options);
    
    function onButtonClick(e) {

        document.getElementById('search_option_' + variant + nObj.key).value = oButton.get("value");

    }
    
    oButton.addListener("click", onButtonClick);
}

function build_menu_button(nObj,variant)
{
    var oButton;
    oButton = new YAHOO.widget.Button({ 
                                    type: "menu", 
                                    id: variant + nObj.key + '_button', 
                                    label: nObj.label, 
                                    menu: nObj.options, 
                                    container: "search_option_con_" + variant + nObj.key });
                                    
             function onMenuClick(p_sType, p_aArgs) {
                        
                        var oMenuItem = p_aArgs[1];
                        var myItems = oButton.getMenu().getItems();
                        var myValue = '';
                        var nItem;
                        if (oMenuItem) {
                            oButton.set("label", ("<em>" + oMenuItem.cfg.getProperty("text") + "</em>"));
                            
                            for(var i in myItems)
                            {
                                if(myItems[i].cfg.getProperty("text") == oMenuItem.cfg.getProperty("text"))
                                {
                                    myValue = myItems[i].value;    
                                }
                            }
                            
                            document.getElementById('search_option_' + variant + nObj.key).value = myValue;
                            //alert(document.getElementById('search_option_' + nObj.key).value);
                        }

                    }
                    
            oButton.on("appendTo", function () {
                oButton.getMenu().subscribe("click", onMenuClick);
            });
    

}
function load_simple_search_options()
{
    var oButton;
                    
    for (var i=0;i<=5;i++)
    {
        if(_SEARCH_ELEMENTS[i].type == 'menu')
        {
          build_menu_button(_SEARCH_ELEMENTS[i],'simple_');  
        }
        
        if(_SEARCH_ELEMENTS[i].type == 'radio')
        {
            build_radio_button(_SEARCH_ELEMENTS[i],'simple_');
        }
    }

}

function load_search_options()
{
    var oButton;
                    
    for(var i in _SEARCH_ELEMENTS)
    {
        if(_SEARCH_ELEMENTS[i].type == 'menu')
        {
          build_menu_button(_SEARCH_ELEMENTS[i],'');  
        }
        
        if(_SEARCH_ELEMENTS[i].type == 'radio')
        {
         build_radio_button(_SEARCH_ELEMENTS[i],'');
        }
    }

}

function init()
{
    load_search_options();
    load_simple_search_options();
    
    var SubmitButton_simple = new YAHOO.widget.Button({ 
                                type: "submit", 
                                label: "Search", 
                                id: "submit_simple", 
                                name: "submit_simple", 
                                value: "Search", 
                                container: "submit_simple_con" });
    var SubmitButton_advanced = new YAHOO.widget.Button({ 
                                type: "submit", 
                                label: "Search", 
                                id: "submit_advanced", 
                                name: "submit_advanced", 
                                value: "Search", 
                                container: "submit_advanced_con" });
    
    init_SHOWHIDE();
}