﻿/*=============================================================================================
JSFile  :   HGUpdaters
Scope   :   Useful Function to update drodownlists optionlist etc with values binded with AJAX
Author  :   Axente Adrian
==============================================================================================*/

/*==============================================================================================
Function    :   UpdateDropDown
Parameters  :   DropDown        - The DropDown to Update
                NameIdArray     - Array of NameIdObjects (each item is an object 
                                  and have Name and Id propeties)
                SelectedValue   - The value to select after drop down is populated
===============================================================================================*/
 function UpdateDropDown(DropDown,NameIdArray,SelectedValue)
 {      
        if ((!SelectedValue) && (DropDown.selectedIndex>0))
            SelectedValue = DropDown.options[DropDown.selectedIndex].value;
        ClearDropDown(DropDown);
        
        for (var i=0;i<NameIdArray.length;i++)
        {
            Item = new Option();
            Item.text=NameIdArray[i].Name;
            Item.value=NameIdArray[i].Id;
            //DropDown.add(Item);
            if (Item.value != "")
                DropDown.options[DropDown.options.length] = Item;
            if (SelectedValue==Item.value)
               DropDown.selectedIndex=DropDown.options.length-1; 
        }              
 }   


/*==============================================================================================
Function    : Clear DropDown
Scope       : Clears AllOptions from a Dropdown  
==============================================================================================*/
function ClearDropDown(DropDown)
{
        
        try        {	        for (x = DropDown.options.length; x >= 0; x --) 	        {		        DropDown.options[x] = null;	        }	    }	    catch(e){}
}

