function keyDown(e,func){ 
evt=e||window.event;
var k=evt.which||evt.keyCode;
	if(k==13){
		if(func=="login"){
		  login();
		}
 	}
}

function login(){
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null){
 alert (" مطصفحك لا يدعم طلبات HTTP ")
 return
} 
var username = document.getElementById('username');
var password = document.getElementById('password');
if (username.value==null || username.value==''){
 alert ("لم تقم بكتابة اسم المستخدم!")
  username.focus();
 return
}
if(password.value==null || password.value==''){
alert ("لم تقم بكتابة كلمة المرور!")
password.focus();
return
} 
var url="users.php?action=ajaxlogin"
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("POST",url,true)
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
text="username="+encodeURIComponent(username.value)
text=text+"&password="+encodeURIComponent(password.value)
xmlHttp.send(text) 
}
 
function logout(){
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null){
alert (" مطصفحك لا يدعم طلبات HTTP ")
return
} 
var url="users.php?action=ajaxlogout&logout=yes"
xmlHttp.onreadystatechange=stateChanged1 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

/*function  getleft(str){
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null){
alert (" مطصفحك لا يدعم طلبات HTTP ")
return
}
var url="index.php?getleft="
url=url+str
xmlHttp.onreadystatechange=stateChanged2 
xmlHttp.open("GET",url,true)
xmlHttp.send(null) 
}*/
 
function stateChanged1(){ 
    if(xmlHttp.readyState!==4){ 	
    document.documentElement.style.cursor = "wait";
	document.getElementById("dologin").disabled="disabled";  
	var msg=" جاري تسجيل الدخول... ";
	document.getElementById("msg").innerHTML=msg; 
	}
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    document.documentElement.style.cursor = "default";
    document.getElementById("login").innerHTML=xmlHttp.responseText; 
    var msg="";
    document.getElementById("msg").innerHTML=msg; 
    }
} 

function stateChanged2(){ 
    if(xmlHttp.readyState!==4){
	document.documentElement.style.cursor = "wait";
    }
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    document.documentElement.style.cursor = "default";
    document.getElementById("left").innerHTML=xmlHttp.responseText; 
    }
} 

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;
}

// Stop Erorrs Function
function stopError() {
return true;
}
window.onerror = stopError;
