function postRequest(strURL){
	var xmlHttp;
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4){
			updatepage(xmlHttp.responseText);
		}
	}

	xmlHttp.send(strURL);
};

function updatepage(str){
	if(str.match("certify")){
		document.getElementById("profile").innerHTML = "<center>Hi " + document.getElementById("loginForm").username.value + "</center><br />";
		return;
	} else{
		alert(str);
	}
};

function call_login(){
	var username = document.getElementById("loginForm").username.value;
	var password = document.getElementById("loginForm").password.value;
	var url = "./db/login_exec.php?username=" + encodeURI(username) + "&password=" +password ;
	postRequest(url);
};

function editscene(){
	document.editsc.submit();
};

function addnew(){
	nm = document.addsc.town.value;
	if( (nm== "kotakinabalu")||(nm== "sandakan")||(nm== "tawau") ){
		document.addsc.submit();	
	}
	else {
		number = prompt("Please input district number that you decided to add item:\r\n1 -- Kota Kinabalu   2 -- Sandakan   3 -- Tawau","1");
		if(number){
			if(number=="1"){
				document.addsc.town.value = "kotakinabalu";
				document.addsc.submit();
			} else if(number=="2"){
				document.addsc.town.value = "sandakan";
				document.addsc.submit();
			} else if(number=="3"){
				document.addsc.town.value = "tawau";
				document.addsc.submit();
			} else {
				return;	
			}
		} else {
			return;	
		}
		
	}
	
};
