// JavaScript Document
/*
	Created By		-	Kamala Kannan.D
	Created On		-	July 07,2008
	@description	-	To parse a string and create options for combo from the string
	@param			-	String data		-	Data to be parsed.
						
												Example		id-name,id-name	here - is inner sep and , is the outer sep
						Object	Combo	The options are created for a this combo
						Int 	SelectedOptionId to make as selected	-	This function normally makes the current
																			option as selected but we can force them to 
																			select a specific option box
						String	First Option name 	Example	--Select--,---ALL--- etc
						String	First option value
*/
function optionsFromXml(pmData,pmCombo,pmSelectedOption,pmInitialOptionText,pmInitialOptionValue)
{
	var vData				=	pmData;
	var oCombo				=	pmCombo;
	var vSelected			=	pmSelectedOption;
	var vInitialOpt			=	pmInitialOptionText;
	var vInitialOptValue	=	pmInitialOptionValue;

	//--To hold the lenght of the combo
	var comboLength	=	oCombo.length;

	//--To remove all options from the combo box.
	for(var selLoop=0;selLoop<comboLength;selLoop++)
	{
		oCombo.remove(oCombo.options[selLoop])
	}
	
	//--To add initial option at the first
	var optElem 		= document.createElement("Option");
	optElem.text 		= vInitialOpt;
	optElem.value 		= vInitialOptValue;
	oCombo.options.add(optElem);
	
	vXmlLen		=	vData.getElementsByTagName("record").length;
	var oDataPair	=	vData.getElementsByTagName("record");
	if(vXmlLen		!=	0)
	{
		for(var vLoop=0;vLoop<vXmlLen;vLoop++)
		{
			var vOptionValue	=	oDataPair[vLoop].getElementsByTagName("key")[0].childNodes[0].nodeValue;
			var vOptionText		=	oDataPair[vLoop].getElementsByTagName("value")[0].childNodes[0].nodeValue;
			var optElem = document.createElement("Option");
			optElem.text = vOptionText;
			optElem.value = vOptionValue;
			optElem.title = vOptionText;
			oCombo.options.add(optElem);
		}
	}	
	if(vSelected	!= null)
		oCombo.value	=	vSelected;
}
