function getXHR()
{
	if(window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else try {
		return new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e) {
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			return false;
		}
	}
}

function updateElm(ajaxReq, divID, url) {
	if(ajaxReq)
	{
		ajaxReq.open('GET', url, true);
		ajaxReq.onreadystatechange = function()	{
			if(ajaxReq.readyState == 4) {
				if(ajaxReq.status==200)	{				
					document.getElementById(divID).innerHTML = ajaxReq.responseText;
				} else {
					document.getElementById(divID).innerHTML = 'Not Found';
				}
			}
		}
		ajaxReq.send('');
	}
	else return true;
	return false;
}

function htmlData(eleDiv, url) { 

	if (url.length==0) {
		document.getElementById(eleDiv).innerHTML = "";
		return false;
	}

	xmlHttP = getXHR();

	if (xmlHttP==false) { //null
		alert ("Browser does not support HTTP Request");
		return false;
	}
	try {
		return updateElm(xmlHttP, eleDiv, url)			
	} catch(e) {
		return 'Could not retrieve data :: '; //+e;
	}
}

function clearFocus(key, val) {
	var xVal=document.getElementById(key).value;	
	if(xVal && xVal == val) { fClear(key); }
	document.getElementById(key).select(); 
	//"if(this.value && this.value == 'Enter search keywords') { this.value = ''; } else { this.select(); }" />  
}

function fClear(fld)	{
	document.getElementById(fld).value="";
}
		
function URLEncode (clearString) {
	var output = '';
	var x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while (x < clearString.length) {
		var match = regex.exec(clearString.substr(x));
		if (match != null && match.length > 1 && match[1] != '') {
			output += match[1];
		  x += match[1].length;
		} else {
		  if (clearString[x] == ' ')
			output += '+';
		  else {
			var charCode = clearString.charCodeAt(x);
			var hexVal = charCode.toString(16);
			output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
		  }
		  x++;
		}
	}
	//printf("%s\r\n",output);
	return output;
}

function URLDecode (encodedString) {
	var output = encodedString;
	var binVal, thisString;
	var myregexp = /(%[^%]{2})/;
	while ((match = myregexp.exec(output)) != null
			&& match.length > 1
			&& match[1] != '') {
	binVal = parseInt(match[1].substr(1),16);
	thisString = String.fromCharCode(binVal);
	output = output.replace(match[1], thisString);
	}
	return output;
}	

function jumpto(url) {
	if (url != '') {
		document.location.href = url;
	}
}

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

function showMessage($msg) {
        //var files =  document.getElementById("filelist").value;
        //alert(files);
        var answer = confirm($msg);
        if (answer){
            answer=false;
            return true;
        }
        else{
            answer=false;
            return false;
        };
        /*
                $('#delitem').click(function() {
                });
         */
};

