// edited 8/8/11. D. Gafford - Websites & Publishing Team
// Changed google analytics script and had to update this to remove binding to global window object

if(!VUP) var VUP = {};

VUP.onload = function (){
    function get_url_param(name)
    { 
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
        
        var regexS = "[\\?&]"+name+"=([^&#]*)"; 
        var regex = new RegExp( regexS ); 
        var results = regex.exec( window.location.href ); 
        
        if (results == null)
            return ""; 
        else 
            return results[1];
    }
    
    function select_list_item(list,item)
    {
        for (i = 0; i < list.length; i++)
          if (item == list[i].value)
               list.selectedIndex = i;
    }
    
    //get the users option_list
    var type = get_url_param("option_list");
    
    //select the initial dropdown list from the users search
    select_list_item(document.getElementById("type"),type);
    
    //set search term from users search
    var textbox = document.getElementsByName(type+"C")[0];
    if (textbox){
       
            textbox.value = unescape(get_url_param("option_value")).replace(/\+/g," ");
       
            select_list_item(textbox,unescape(get_url_param("option_value")).replace(/\+/g," "));    
    }
    
    //set the currently selected 'type' as old but also show it, this mantains the selection after a refresh
    var old_div_id = document.getElementById('type')[document.getElementById('type').selectedIndex].value;
    show_div(old_div_id);

    function show_div(div_id) {
        var elements = document.getElementById(old_div_id).getElementsByTagName("input");
        elements[elements.length-1].disabled = "disabled";
        
        document.getElementById(old_div_id).style.display = 'none'; //hide the last selections input box
        old_div_id = div_id; //remember the current selection so we can hide it later
        document.getElementById(div_id).style.display = 'block'; //show the new selection
        
        elements = document.getElementById(div_id).getElementsByTagName("input");
        elements[elements.length-1].disabled = "";
    }
    
    document.getElementById('NOJS').style.display = 'none'; //java script is available so we can hide the simple non-js version
    document.getElementById('JS').style.display = 'block'; //show the javascript enhanced version
    
    //set the onchange for type to show the form input field for this type
    document.getElementById('type').onchange = function(){show_div(document.getElementById('type').value)}
}
