//xmlhttp.js

//Function to create an XMLHttp Object.
function getxmlhttp (){
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

//Function to process an XMLHttpRequest.
function submit_ajax (serverPage, obj, getOrPost, str){
	//alert(serverPage+' - '+obj+' - '+getOrPost+' - '+str);
	//alert(obj);
	//alert(str);
	xmlhttp = getxmlhttp ();
	if (getOrPost == "get"){
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				//alert(xmlhttp.responseText);
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
			}

			if (xmlhttp.readyState == 1) {
				//document.getElementById(obj).innerHTML = "Loading...";
				document.getElementById(obj).innerHTML = "<div align=\"center\" class=\"StyleLoad\">Loading...<br /><img src=\"images/indicator.gif\" width=\"16\" height=\"16\" /></div>";
			}

		}
		xmlhttp.send(null);
	} else {
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				//alert(xmlhttp.responseText);
				//alert(obj);
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
			}

			if (xmlhttp.readyState == 1) {
				//document.getElementById(obj).innerHTML = "Loading...";
				document.getElementById(obj).innerHTML = "<div align=\"center\" class=\"StyleLoad\">Loading...<br /><img src=\"images/indicator.gif\" width=\"16\" height=\"16\" /></div>";
			}
			
		}
		xmlhttp.send(str);
	}
}

function submit_ajaxredierct (serverPage,obj,getOrPost,responAjax,responLength,actionFile, str){
	xmlhttp = getxmlhttp ();
	var varstr;
	if (getOrPost == "get"){
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				varstr = ""+xmlhttp.responseText+"";
				if (varstr.substring(0,responLength) == responAjax){
					window.location=actionFile;
				}
				else{
					document.getElementById(obj).innerHTML = xmlhttp.responseText;	
				}
			}
			if (xmlhttp.readyState == 1) {
				//document.getElementById(obj).innerHTML = "please wait";
				document.getElementById(obj).innerHTML = "<div align=\"center\" class=\"StyleLoad\">Loading...<br /><img src=\"images/indicator.gif\" width=\"16\" height=\"16\" /></div>";
			}
		}
		xmlhttp.send(null);
	} else {
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				varstr = ""+xmlhttp.responseText+"";
				//alert(varstr);
				if (varstr.substring(0,responLength) == responAjax){
					//alert(responAjax);
					//alert(actionFile);
					//var actionnya = "http://10.1.5.215/index.php?action=home";
					//alert(actionnya);
					//window.location = actionnya;
					window.location=actionFile;
				}
				else{
					
					//alert(xmlhttp.responseText);
					alert("Unauthorized Access Warning: \nAccess to this computer is prohibited unless authorized. Accessing programs or data unrelated to your job is prohibited ");
					document.getElementById(obj).innerHTML = xmlhttp.responseText;	
				}
			}

			if (xmlhttp.readyState == 1) {
				//document.getElementById(obj).innerHTML = "please wait";
				document.getElementById(obj).innerHTML = "<div align=\"center\" class=\"StyleLoad\">Loading...<br /><img src=\"images/indicator.gif\" width=\"16\" height=\"16\" /></div>";
			}
			
		}
		xmlhttp.send(str);
	}
}