var xmlhttp;
var data = "";
function checkAJAXuser(){	
	//if(arg=="") return;
	//var url = "checklogin.php";
	var user = document.getElementById('username').value;
	var pass = document.getElementById('password').value;
	var sendvalue = "user="+user+"&pass="+pass;
	//Check Browser
	if(window.ActiveXObject){ //IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else{ //NS, FF
		xmlhttp = new XMLHttpRequest();
	}
	if(xmlhttp != null){
		//url += sendvalue;
		xmlhttp.onreadystatechange=stateChangeuser;
		xmlhttp.open("POST","checklogin.php",true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		xmlhttp.send(sendvalue);//'id='+arg

	}else{
		alert("Not support AJAX.");
	}
}

function stateChangeuser(){
	var LOAD = 4;
	var SUCCESS = 200;
	if(xmlhttp.readyState == LOAD){
		if(xmlhttp.status == SUCCESS){
			var result = xmlhttp.responseText;	
			if(result != ""){
				if(result == "yes"){
					window.location = "newspapers.php?cid=72";
				}
				else{
					alert("Your Username or Password is incorrect");
					document.getElementById("username").value = "";
					document.getElementById("password").value = "";
				}
			}
		}
	}
}

function checkAJAXlogin(){	
	//if(arg=="") return;
	//var url = "checklogin.php";
	var sendvalue = "";
	//Check Browser
	if(window.ActiveXObject){ //IE
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else{ //NS, FF
		xmlhttp = new XMLHttpRequest();
	}
	if(xmlhttp != null){
		//url += sendvalue;
		xmlhttp.onreadystatechange=stateChangelogin;
		xmlhttp.open("POST","checklogin_button.php",true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		xmlhttp.send(sendvalue);//'id='+arg

	}else{
		alert("Not support AJAX.");
	}
}

function stateChangelogin(){
	var LOAD = 4;
	var SUCCESS = 200;
	if(xmlhttp.readyState == LOAD){
		if(xmlhttp.status == SUCCESS){
			var result = xmlhttp.responseText;	
			if(result != ""){
				var arrData = result.split("||");
				if(arrData[0] == "yes"){
					document.getElementById('menu_logout').style.display = '';
					document.getElementById('menu_login').style.display = 'none';
					document.getElementById('tr_wellcome').style.display = '';
					document.getElementById('well_user').innerHTML = arrData[1];

				}
				else{
					document.getElementById('menu_logout').style.display = 'none';
					document.getElementById('menu_login').style.display = '';
					document.getElementById('tr_wellcome').style.display = 'none';
				}
			}
		}
	}
}