﻿var xmlHttp

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function ampChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById('txtAmp').innerHTML = xmlHttp.responseText;
	} else {
	document.getElementById('txtAmp').innerHTML = "Processing...";
	}
}

function admChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById('txtAdm').innerHTML = xmlHttp.responseText;
	} else {
	document.getElementById('txtAdm').innerHTML = "Processing...";
	}
}

function showProv(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../getAmp.asp";
url=url+"?p="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged("txtAmp");
xmlHttp.open("GET",url,true);
//xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');   
xmlHttp.send(null);
}

function showAmp(str, type)
{ 
modifyHidden("province", str);
modifyHidden("ampoe", "");
modifyHidden("admin", "");
modifyInner("txtAdm", "");
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getAmp.asp";
url=url+"?p="+str;
url=url+"&sid="+Math.random();
url=url+"&type="+type;
//alert(url);
xmlHttp.responseHeader;
xmlHttp.onreadystatechange=ampChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function showAdm(str)
{ 
modifyHidden("ampoe", str);
modifyHidden("admin", "");
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getAdm.asp";
url=url+"?pa="+str;
url=url+"&p="+locateElement("P").value;
url=url+"&sid="+Math.random();
//alert(url);
//xmlHttp.Encode=
xmlHttp.onreadystatechange=admChanged;
xmlHttp.open("GET",url,true);
//xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');   
xmlHttp.send(null);
}

function jumpProv(str) {
//		document.getElementById("where").innerHTML = "P" ;
//		document.getElementById("what").innerHTML = str ;
	var prov = locateElement("P").value;
	modifyHidden("province", str);
//	alert(str);
	modifyHidden("where", "PROV_CODE");
	modifyHidden("what", str);
	modifyHidden("command", "find");
	if (prov != "" && prov != "0") 	reload();
}

function jumpAmp(str, type) {
//	if (str != "") {
//		document.getElementById("where").innerHTML = "PA" ;
//		document.getElementById("what").innerHTML = str ;
//	}
	var amp = locateElement("PA").value;
	modifyHidden("province", locateElement("P").value);
	modifyHidden("ampoe", str);
//	alert(type);
	if (type = 1) {
		if (str != "00") {
			modifyHidden("where", "PA");
			modifyHidden("what", str);
			modifyHidden("command", "find");
//			alert("PA = " + locateElement("PA").value);
		} else {
			modifyHidden("where", "PROV_CODE");
			modifyHidden("what", locateElement("province").value);
			modifyHidden("command", "find");
//			alert("P = " + locateElement("P").value);
		}
	} 
	if (amp != "" && amp != "0") 	reload();		
}

function jumpAdm(str) {
	var adm = locateElement("PAT").value;
	modifyHidden("admin", str);
	if (str != "000") {
		modifyHidden("where", "PAT");
		modifyHidden("what", str);
		modifyHidden("command", "find");
//		alert("P = " + locateElement("P").value);
	} else {
		modifyHidden("where", "PA");
		modifyHidden("what", locateElement("PA").value);
		modifyHidden("command", "find");
//		alert("P = " + locateElement("P").value);
	}
	if (adm != "" && adm != "0") 	reload();
}

function login() {

	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var usr = encodeURI(document.getElementById('Login').value); //alert(usr);
	var psw = encodeURI(document.getElementById('Psw').value); //alert(psw);
	var FormAction = document.getElementById('FormAction').value;
	var FormName = document.getElementById('FormName').value; 
			
	// Optional: Show a waiting message in the layer with ID ajax_response
	document.getElementById('tblLogin').innerHTML = "<font size='2' class='login'>"+FormAction+"...</font>";
	
	psw = hex_md5(hex_md5(psw) + usr);
 	//alert ('id = ' + usr + ',  psw = ' + psw);
	
	
	// Set te random number to add to URL request
	nocache = Math.random();
	
	// Pass the login variables like URL variable
	http.open('get', 'doLogin.asp?id='+usr+'&psw='+psw+'&FormAction='+FormAction+'&FormName='+FormName+'&nocache='+nocache);
	http.onreadystatechange = loginReply;
	http.send(null);
	if (FormAction != "") {
		if (FormAction == "Login" && url_in != "") {window.open(url_in,'_self');}
		if (FormAction == "Logout" && url_out != "") {window.open(url_out,'_self');}
	}	
}

function loginReply() {
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById('tblLogin').innerHTML = response;
	}
}
