//function setCheckbox(box,txt)
//{
//	if(txt!=null && txt!="false")
//		box.checked=true;
//	else box.checked=false;
//}
function HtmlEncode(text)
{
    return text.replace(/&/g, '&amp').replace(/'/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
function initNumberList(lst,start,end, offset)
{
	lst.options.length = 0
	lst.options[0]= new Option(" ")
	for(var t = start;t<= end;t++)
	lst.options[t]= new Option(t)
	lst.options[1].selected = true
}
function addToListBox(lst,txt)
{
	if(lst!=null && lst.length!=null)
		lst.options[lst.length]= new Option(txt)
	
}
function addToList(lst,txt,val)
{
	if(lst!=null && lst.length!=null)
		lst.options[lst.length]= new Option(txt,val);
	
}
function removeFromListBox(lst,txt)
{
	if(lst!=null && lst.length!=null)
	{
		for(var t = 0;t< lst.options.length;t++)
		{
			if(lst.options[t].text==txt)
			lst.options[t].text="  "
		}
	}
}
function clearListBox(lst)
{
	if(lst!=null && lst.length!=null)
	{
		for(var t = 0;t< lst.options.length;t++)
		{
			if(lst.options[t].text==" ")
				lst.options[t].selected=true;
		}
	}
}
function addArrayToListBox(lst,arr)
{
	if(lst!=null && lst.length!=null)
	{
		for(var t = 0; t<arr.length;t++)
		{
			lst.options[t] = new Option(arr[t])
		
		}
	}
}
function validateData(arr)
{
	for(var t = 0 ;t<arr.length;t++)
	{
		if(arr[t]=="")
		{
			if(DEBUG)
			alert("Invalid Data")
			return false
		}
	}
	return true
}
function getValue(lst)
{
	return lst.options[lst.selectedIndex].value;
}
function getText(lst)
{
	if(lst!=null && lst.selectedIndex!=null && lst.options[lst.selectedIndex]!=null)
	{
		if(lst.options[lst.selectedIndex]!=null)
			return lst.options[lst.selectedIndex].text;
		else
			alert("list has no option at " +  lst.selectedIndex);
		return "";	
	}
	else 
		return "";	
}
// Get the index of the corresponding option in the field's list
function getIndex (val, field) {
	var i;
	for (i = 0; i < field.length; i++) {
		if (val == field.options[i].text) {
			return i;
		}
	}
	return -1;
}
// Set the selected index to the option matching the text
function setIndex (txt, lst) {
	var i;
	for (i = 0; i < lst.options.length; i++) {
		if (txt == lst.options[i].text) {
			lst.options[i].selected=true;
			return;
		}
	}
}
// Set the selected index to the option matching the value
function setIndexByValue (val, lst) {
	var i;
	for (i = 0; i < lst.options.length; i++) {
		if (val == lst.options[i].value) {
			lst.options[i].selected=true;
			return;
		}
	}
}
function checkDupes(lst)
{
	for (i = 0; i < lst.options.length; i++) 
	{
		for (t = 0; t < lst.options.length; t++) 
		{
			if ((lst.options[t].text == lst.options[i].text) && (t!=i)) 
			{
				lst.options[t]=null;
			}
		}
	}
}
function getListArray(lst)
{
	var retval = new Array(lst.options.length);
	for (i = 0; i < lst.options.length; i++) 
	{
		retval[i] = lst.options[i].text;
	}
	return retval;
}
function addTextBoxToQueryString(queryString,objectName)
{
	if(document.getElementById(objectName)!=null && document.getElementById(objectName).value!="")
	{
		if(queryString==null ||queryString=="")
			return "?" + objectName + "=" + document.getElementById(objectName).value;
		else
			return "&" + objectName + "=" + document.getElementById(objectName).value;
	}
	return "";
}
function addCheckBoxToQueryString(queryString,objectName)
{
	if(document.getElementById(objectName)!=null && document.getElementById(objectName).checked==true)
	{
		if(queryString==null ||queryString=="")
			return "?" + objectName + "=on";
	}
	return "";
}
				
