/*'---------------------------------------------------------------------------------------------------------
'Function No   	: 01
'---------------------------------------------------------------------------------------------------------
'Purpose 	  	: Clear Items of a ListBox.
'---------------------------------------------------------------------------------------------------------
'Parameter		:Takes name of the listbox to clear.
'---------------------------------------------------------------------------------------------------------
'Author  	  	: Naznin
'---------------------------------------------------------------------------------------------------------
'Created On 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------
'Last Modified 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------*/	

function ClearListBox(lst)
	{
	var len=document.getElementById(lst).length ;
	
	for (i=0; i<=len; i++)
	
		{
		document.getElementById(lst).remove(0)
		}
	}
/*---------------------------------------------------------------------------------------------------------
'Function No   	: 02
'---------------------------------------------------------------------------------------------------------
'Purpose 	  	: Add items from one listbox to another listbox.
'---------------------------------------------------------------------------------------------------------
'Parameter		:Takes two parameter.
	    fromSel :source listbox. where items to be select.
		 theSel :destination listbox. where items to be added.
'---------------------------------------------------------------------------------------------------------
'Author  	  	: Naznin
'---------------------------------------------------------------------------------------------------------
'Created On 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------
'Last Modified 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------*/	

function append(fromSel,theSel,hID,maxSize,msg)
 {
   var selIndex;
   var IDCollection;
   var TempID;
		FSel=document.getElementById(fromSel);
		TSel=document.getElementById(theSel);

		selIndex = FSel.selectedIndex;
		
		if (TSel.length >=parseInt(maxSize))
			{
				alert(msg);
				return false;
			}
				if (selIndex>=0)
		{
			newValue=FSel.options[selIndex].value;
			newText=FSel.options[selIndex].text;
		
			for(i = 0 ; i < TSel.length ; i++)// find duplicate
				{									
					if (newValue==TSel.options[i].value) 
						{
							return false;
						}
				}//end for
						
			var newOpt1 = new Option(newText, newValue);
				
			TSel.options[TSel.length] = newOpt1;
				
			TSel.selectedIndex =TSel.length-1;
			IDCollection=ListBox_IDCollection(theSel);
			document.getElementById(hID).value=IDCollection;
			
		}
			
}
/*---------------------------------------------------------------------------------------------------------
'Function No   	: 03
'---------------------------------------------------------------------------------------------------------
'Purpose 	  	: Remove item from a listbox.
'---------------------------------------------------------------------------------------------------------
'Parameter		:Takes one parameter.
	       tSel : Id of the Listbox where selected item remove. 
'---------------------------------------------------------------------------------------------------------
'Author  	  	: Naznin
'---------------------------------------------------------------------------------------------------------
'Created On 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------
'Last Modified 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------*/	

function remove(tSel,hID)
{
  theSel=document.getElementById(tSel);
  var selIndex = theSel.selectedIndex;
  if (selIndex != -1)
	 { 
		  if(theSel.options[selIndex].selected)
				  {
					theSel.options[selIndex] = null;//alert(selIndex)
				  }
					
			if (theSel.length > 0)
			{
			  theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
			}	
			document.getElementById(hID).value=ListBox_IDCollection(tSel);
									
  }//outer if
 }
/*---------------------------------------------------------------------------------------------------------
'Function No   	: 04
'---------------------------------------------------------------------------------------------------------
'Purpose 	  	: Collect all IDs of a listbox
'---------------------------------------------------------------------------------------------------------
'Parameter		:Takes one parameter.
	     theSel : Id of the Listbox. 
'---------------------------------------------------------------------------------------------------------
'Author  	  	: Naznin
'---------------------------------------------------------------------------------------------------------
'Created On 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------
'Last Modified 	: 15 Oct 2005 
'---------------------------------------------------------------------------------------------------------*/	

function ListBox_IDCollection(theSel)
	{
	var TempID;	
	var TSel;
	TempID="";
	TSel=document.getElementById(theSel);	
		if (TSel.length>0)
		{				
			for(i=0; i<TSel.length; i++)
			{
				if(TempID != "") //add new id to temp id
					{ 
					TempID = TempID  + "," + TSel.options[i].value;
					}	
				else
					{ 
					TempID = TSel.options[i].value;
					}
			}//end for
			
			TempID="," + TempID + ",";
		}//outer if
		
		return TempID;
			}//end function
