var xh;
function getDataURL(url,async,funcName){
	//Get Http object
	if(window.XMLHttpRequest){
		xh=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		xh=new ActiveXObject("Microsoft.XMLHTTP")
	}
	//Set async function
	if(async){
		xh.onreadystatechange=function() {
			if (xh.readyState == 4) {
				switch (xh.status) {
					case 200:
						if(funcName){
							eval(funcName);
						}else{
						    xmlhttpChange();
						}
						break;
						// Page-not-found error
					case 404:
						alert('Error: Not Found. The requested URL ' + 
						url + ' could not be found.');
						location.href="login.aspx";
						break;
					// Display results in a full window for server-side errors
					case 500:
						handleErrFullPage(xh.responseText);
						location.href="login.aspx";
						break;
					default:
						// Call JS alert for custom error or debug messages
						if (xh.responseText.indexOf('Error:') > -1 || 
							xh.responseText.indexOf('Debug:') > -1) {
								alert(xh.responseText);
						}
						//location.href="login.aspx";
						break;
				}
			}
		}
	}
	xh.open("GET",url,async);
	xh.send("");
	if(!async){
		return xh.responseText;
	}
}
//Display xmlHTTP error
function handleErrFullPage(strIn) {
        var errorWin;

        // Create new window and display error
        try {
                errorWin = window.open('', 'errorWin');
                errorWin.document.body.innerHTML = strIn;
        }
        // If pop-up gets blocked, inform user
        catch(e) {
                alert('An error occurred, but the error message cannot be' +
                        ' displayed because of your browser\'s pop-up blocker.\n' +
                        'Please allow pop-ups from this Web site.');
        }
}
function getData(ntype,parm,async){
	var dt=new Date();
	var url="data.aspx?dt="+dt+"&n="+ntype+parm;
	if(window.XMLHttpRequest){
		xh=new XMLHttpRequest();
		if(async)
		{
			xh.onreadystatechange=xmlhttpChange;
		}
		xh.open("GET",url,async);
		xh.send("");
	}
	else if(window.ActiveXObject){
		xh=new ActiveXObject("Microsoft.XMLHTTP")
		if(xh){
			if(async)
				xh.onreadystatechange=xmlhttpChange;
			xh.open("GET",url,async);
			xh.send();
		}
	}
	if(!async)
		return xh.responseText;
}

function HttpPopulateCbo(cbo,s){
	var i=0,item,s,p;
	cbo.options.length=0;
	if(s=="")
		return;
	p=s.split("\t");
	for(i=0;i<p.length;i++){
		item=document.createElement("Option");
		item.innerHTML=p[i].substr(p[i].indexOf("|")+1);
		item.value=p[i].substr(0,p[i].indexOf("|"));
		//cbo.add(item);
		cbo.appendChild(item);
	}
}
function HttpPopulateCbo2(cbo,s,value){
	var i=0,item,s,p,doc=cbo.ownerDocument;
	cbo.options.length=0;
	p=s.split("\t");
	for(i=0;i<p.length;i++){
		item=doc.createElement("Option");
		item.innerHTML=p[i].substr(p[i].indexOf("|")+1);
		item.value=p[i].substr(0,p[i].indexOf("|"));
		if(item.value == value){
			item.selected = true;
		}
		cbo.appendChild(item);
	}
}
