// $Revision: 10738 $ $Date: 2009-07-27 15:26:13 -0300 (Mon, 27 Jul 2009) $
	function LumisDouiValidateSelection(strSelectionType, strFormName, strControlName, strNoItemMsg, strOneItemMsg)
	{
		var pForm = document.forms[strFormName];
		var pElement, pElements;
		var bFoundOne = false;
		var bFoundMoreThanOne = false;
		
		if(strSelectionType == "selectedOne" || strSelectionType == "selectedMany")
		{
			pElements = pForm.elements[strControlName];
	
			if(pElements && !pElements.length)
			{
				if(pElements.checked)
					bFoundOne = true;
			}
			else if(pElements)
			{
				for(var i=0; i<pElements.length; i++)
				{
					if(pElements[i].checked)
					{
						if(bFoundOne)
						{
							bFoundMoreThanOne = true;
							break;
						}
	
						bFoundOne = true;
					}
				}
			}
	
			if(!bFoundOne)
			{
				if(strNoItemMsg)
					alert(strNoItemMsg);
					
				return false;
			}
	
			if(strSelectionType == "selectedOne" && bFoundMoreThanOne)
			{
				if(strOneItemMsg)
				{
					alert(strOneItemMsg); 
					return false;
				}
			}
		}
		
		return true;
	}
	
	function LumisDouiGetSelectedItems(strFormName, strControlName)
	{
		var elementValues = "";
		var pForm = document.forms[strFormName];
		var bFoundOne = false;
	
		pElements = pForm.elements[strControlName];
		
		if(pElements && !pElements.length)
		{
			if(pElements.checked)
				elementValues += pElements.value;
		}
		else if(pElements)
		{
			for(var i=0; i<pElements.length; i++)
			{
				if(pElements[i].checked)
				{
					if(bFoundOne)
						elementValues += ";";
					elementValues += pElements[i].value;
					
					bFoundOne = true;
				}
			}
		}
		
		return elementValues;
	}

	// TODO: Kishnan either this or the same function in LumisDouiClientSideReadable.js must GO
	function LumisDouiGetValueByName(strFormName, strControlName)
	{
		var pForm = document.forms[strFormName];
		var strValue = null;
	
		for(var i=0; i<pForm.elements.length; i++)
		{
			var pElement = pForm.elements[i];
			
			if(!pElement.name || !pElement.name.length || pElement.name != strControlName)
				continue;
	
			if(pElement.type == "select-one" && pElement.selectedIndex != -1)
			{
				strValue = pElement.options[pElement.selectedIndex].value;
			}
			else if(pElement.type == "select-multiple")
			{
				var strValue = "";
				for(var j=0; j<pElement.options.length; j++)
				{
					if(pElement.options[j].selected && strValue.length)
					{
						if(strValue && strValue.length)
							strValue += ",";
						strValue = pElement.options[j].value;
					}
				}
			}
			else
			{
				strValue = pElement.value;
			}
		}
	
		return strValue;
	}
	
	function LumisDouiToggleSelection(formId, checkBoxName, checked)
	{
		var form = document.forms[formId];
		var items = form.getElementsByTagName("input");
		for(var i=0; i<items.length; i++)
		{
			if (items[i].name == checkBoxName && items[i].type == 'checkbox')
				items[i].checked = checked;
		}
	}
	
	function escapeString(value, charToEscape, charEscaped)
	{
		var strPattern = new RegExp(charToEscape, "gi");
		return value.replace(strPattern, charEscaped);
	}
	
	function LumisDouiOnInlineEdit(primaryKeyValue, sourceId, serviceInterfaceInstanceId)
	{
		var strMethod = "<method name=\"getOnInlineEditScript\">";
		strMethod += "<primaryKeyValue>"+primaryKeyValue+"</primaryKeyValue>";
		strMethod += "<sourceId>"+sourceId+"</sourceId>";
		strMethod += "<serviceInterfaceInstanceId>"+serviceInterfaceInstanceId+"</serviceInterfaceInstanceId>";
		strMethod += "</method>";
		
		var responseXml = LumisPortalUtil.makeHttpRequest("lumis/doui/controller/xml/DouiControllerXml.jsp", strMethod, null, true, null);
		
		try
		{
			LumisPortalUtil.validateResponse(responseXml);
			eval(responseXml.selectSingleNode("response/script").text);
		}
		catch(e)
		{
			alert(e.description);
			return false;
		}
		
		return false;
	}
