/* MakeRequest

*/
function MakeRequest(url)
{
if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
else
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

function SplitTextIntoSelect(split_string1,split_string2,response,el_id)
{
		var combo = document.getElementById(el_id);
		combo.options.length = 0;
		var items = response.split(split_string2);
		var count = items.length;
		
		for (var i=0;i<count;i++)
		{
			var options = items[i].split(split_string1);			
			if (trim(options[0])!='' && trim(options[1])!='')
				{
					combo.options[i] =  new Option(options[0].replace("&amp;","&"),options[1].replace("&amp;","&"));
				}			
		}
}

function ClearTable(el_id)
{
var table = document.getElementById(el_id);
var len   = table.rows.length;
	for (var t = 1 ; t < len; t ++)
			{
				table.deleteRow(1);
			}
}

function LoadSplitted(url,el_id)
{
var text = MakeRequest(url);
SplitTextIntoSelect('!',';',text,el_id);
}

function LoadSplitted2(url,el_id)
{
var text = MakeRequest(url);
SplitTextIntoSelect('!','@',text,el_id);
}

function SetText(set_id,str)
{
var set_obj = document.getElementById(set_id);
set_obj.innerHTML = str;
}

function GetSelectedOptionId(get_id)
{
var get_obj = document.getElementById(get_id);
var ind 	= get_obj.selectedIndex;
return get_obj.options[ind].value;
}

function PrintOptionId(get_id,set_id)
{
var str		= '';
str = str.concat('ID:',GetSelectedOptionId(get_id));
SetText(set_id,str);
}

function trim(str, chars) 
{
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
