/* generic JavaScript functions */

function ToggleElement(elementName)
{
	var Element = document.getElementById(elementName);
	
	if (Element.style.visibility == 'visible')
	{
		Element.style.visibility = 'hidden';
		Element.style.display    = 'none';
	}
	else
	{
		Element.style.visibility = 'visible';
		Element.style.display    = 'block';		
	}
}

function ModalBox(str_Message, str_URL)
{
	/* Displays a modal box, allowing the user to confirm an action before the
	   script transfers execution to a particular script or action */
	var answer = confirm (str_Message)
	if (answer)	
	{
		document.location = str_URL;
	}
	else return(false);
}


function Select_AddItem(lst_SelectBox, str_Name, str_Value)
{
	var list       = document.getElementById(lst_SelectBox);
	var listLength = list.options.length;
	
    addOption = new Option(str_Name, str_Value);
    list.options[listLength] = addOption;
}

function Select_Clear(lst_SelectBox)
{
	var list       = document.getElementById(lst_SelectBox);
	var x = 0;
	for (x=0; x<list.length; x++)
	{
 		list.options[x] = null;		
	}	
}

function Select_SelectAll(lst_SelectBox)
{
	var list       = document.getElementById(lst_SelectBox);
	var x = 0;

	for (x=0; x<list.length; x++)
	{
		list.options[x].selected = true;
	}	
}

function Select_Clean(lst_SelectBox)
{
	var list       = document.getElementById(lst_SelectBox);
	var x = 0;
	for (x=0; x<list.length; x++)
	{
		txt_Value   = list.options[x].value;		
		if (isNaN(txt_Value)) 
		{ 
			list.options[x] = null;		
		}		
	}	
}

function Select_RemoveSelected(lst_SelectBox)
{
	var list       = document.getElementById(lst_SelectBox);
	if (list.selectedIndex == -1) 
	return true;
	selIndex = list.selectedIndex;
	list.options[selIndex] = null;
}


function Select_MoveItems(lst_Source, lst_Dest)
{
	var list_Source        = document.getElementById(lst_Source);
	var list_Dest          = document.getElementById(lst_Dest);
	var x = 0;
	var bln_Exists = false;
	
	for (x=0;x<list_Source.length;x++)
	{
           if (list_Source.options[x].selected == true) 
		   {   
				txt_Name    = list_Source.options[x].text;
				txt_Value   = list_Source.options[x].value;
				
				bln_Exists = false;
				/* Check if item already exists */
				for (i=0;i<list_Dest.length;i++)
				{
					TempID = list_Dest.options[i].value;
					if (TempID == txt_Value)
					bln_Exists = true;
				}
				
				if (bln_Exists == false)
				{
		        	addOption = new Option(txt_Name, txt_Value);
			    	list_Dest.options[list_Dest.length] = addOption; 					
				}
           }
    }
}



function Select_MoveUp(lst_SelectBox)
{
    var list       = document.getElementById(lst_SelectBox);
    var currernt;
    var reverse;
    if(list.options[list.options.selectedIndex].index > 0)
    {
       current_txt = list.options[list.options.selectedIndex].text;
	   current_val = list.options[list.options.selectedIndex].value;	   
       reverse_txt = list.options[list.options[list.options.selectedIndex].index-1].text;
	   reverse_val = list.options[list.options[list.options.selectedIndex].index-1].value;
	   
       list.options[list.options.selectedIndex].text  = reverse_txt;
	   list.options[list.options.selectedIndex].value = reverse_val;
       list.options[list.options[list.options.selectedIndex].index-1].text  = current_txt;
	   list.options[list.options[list.options.selectedIndex].index-1].value = current_val;
       self.focus();
       list.options.selectedIndex--;
    }
}


function Select_MoveDown(lst_SelectBox)
{
	var list       = document.getElementById(lst_SelectBox);
    var current;
    var next;
    if(list.options[list.options.selectedIndex].index != list.length-1)
    {
        current_txt = list.options[list.options.selectedIndex].text;
		current_val = list.options[list.options.selectedIndex].value;
        next_txt = list.options[list.options[list.options.selectedIndex].index+1].text;
		next_val = list.options[list.options[list.options.selectedIndex].index+1].value;
        list.options[list.options.selectedIndex].text  =  next_txt;
		list.options[list.options.selectedIndex].value =  next_val;
        list.options[list.options[list.options.selectedIndex].index+1].text  = current_txt;
		list.options[list.options[list.options.selectedIndex].index+1].value = current_val;
        self.focus();
        list.options.selectedIndex++;
    }
}

