﻿




function clearList(oSelect)
{
	if( oSelect == null ) return;
	while(oSelect.options.length > 0 )
		oSelect.remove(0);
}

function clearGrid(oGrid)
{
	if( oGrid == null ) return;
	while(oGrid.rows.length>0)
		oGrid.rows[0].removeNode(true);
}

function AddSelectOption(oSelect,text,value)
{
	if( oSelect == null ) return;
	var oOption = document.createElement("OPTION");
	oOption.text = text;
	oOption.value = value;
	oSelect.add(oOption);
}

function loadXML(url)
{
	
	try
	{
		var xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');

		xmlhttp.open('GET', url, false);
		xmlhttp.send();

		if(xmlhttp.status != 200 )
		{
			alert(xmlhttp.responseText + " " + url);
			return null;
		}
		var xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
		xmlDoc.loadXML(xmlhttp.responseText);

		return xmlDoc;
	}
	catch(e)
	{
		alert(e.description);
		return null;
	}	
	/*try
	{
		var xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
		xmlDoc.async = false;
		xmlDoc.load(url);
		if( xmlDoc.parseError.errorCode != 0 ) 
		{
			alert(xmlDoc.parseError.reason);
			return null;
		}
		return xmlDoc;
	}
	catch(e)
	{
		alert(e.description);
		return null;
	}*/

}

/*function DisplayCalendar(dt)
{
	return showModalDialog( "Calendar.asp", dt,"dialogWidth:110px; dialogHeight:189px; Scroll: No; help:No; resizable:No; status:No;" );

}*/

function sendXML(url)
{
	try
	{
		var xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
		
		xmlhttp.open('GET', url, false);
		xmlhttp.send();

		if(xmlhttp.status != 200 )
		{
			alert(xmlhttp.responseText);
			return null;
		}
		var xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
		xmlDoc.loadXML(xmlhttp.responseText);

		return xmlDoc;
	}
	catch(e)
	{
		alert(e.description);
		return null;
	}

}	

function GetProps(node,propertyName)
{
	try
	{
		return node.selectSingleNode(propertyName).text;
	}
	catch(e)
	{
		return '';
	}
}

function EncodeString(str)
{
	if( str == null ) return ""; 
	str = str.replace(new RegExp("&","ig"),"&amp;");
	str = str.replace(new RegExp("\"","ig"),"&quot;");
	str = str.replace(new RegExp("<","ig"),"&lt;");
	str = str.replace(new RegExp(">","ig"),"&gt;");
	return str;
	
}


function URLEncodeJS(strURL)
{
	var strSpecialUrl = " <>\"#%{}|^~[]`'&?+\n\r";
	var strEncode="";
	var i;
	var chUrl;
	var iCode;
	var num;
	var iCodeBin;
	var tempBin;
	var j, leadingzeros;

	strURL+="";
	for (i=0; i<strURL.length; i++) {
		chUrl = strURL.charAt(i);
		iCode = chUrl.charCodeAt(0);
		if (iCode<=parseInt("0x7F")) {
			if (strSpecialUrl.indexOf(chUrl)!=-1) {
				if (iCode<=parseInt("0x0F")) {
					strEncode+="%0"+iCode.toString(16).toUpperCase();
				}
				else {
					strEncode+="%"+iCode.toString(16).toUpperCase();
				}
			} else {
				//otherwise chrUrl is normal
				strEncode+=chUrl;
			}
		} 
		else
			strEncode+=chUrl;
		
	}
	return strEncode;
}