﻿function GetXmlHttpObject()
 {
   var objXMLHttp=null;
   
   if (window.XMLHttpRequest)
      objXMLHttp=new XMLHttpRequest();
   else if (window.ActiveXObject)
      objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
   
   return objXMLHttp
 }
function LogInUser(username,password,div)
{
var uname=document.getElementById(username).value;
var password=document.getElementById(password).value;
var divMsg = document.getElementById(div);
	//document.getElementById(divcontent).innerHTML ="";
if(uname=="" && password=="")
{	divMsg.style.border="1px solid red";
	divMsg.style.backgroundColor = "white";
	divMsg.style.color = "red";
	divMsg.innerHTML='<b style=color:red;font-size:11px;>Please specify At Least A Username.</b>';
}
else if(uname=="")
{
	divMsg.style.border="1px solid red";
	divMsg.style.backgroundColor = "white";
	divMsg.style.color = "red";
	divMsg.innerHTML='<b style=color:red;font-size:11px;>Please Specify your Username.</b>';
}

else
{
	//tabdropdown.init(even, index);
	var http=GetXmlHttpObject()
	if (http==null)
     {
		alert ("Browser does not support HTTP Request")
		return false;
     }
	
var url ="php/query/session_login.php";
url = url+"?username="+uname+"&password="+password;

	http.open("GET",url,true);
	
    http.onreadystatechange = 
	 function()
	  {
		if (http.readyState == 4)
		 {
			if(http.status==200) 
			{
				var response = http.responseText;
		
			
				if(response==1)
				{	divMsg.style.border="1px solid green";
					divMsg.style.backgroundColor = "white";
					divMsg.style.color = "green";
					divMsg.innerHTML='<b style=color:green;font-size:11px;>Access Granted.Please Wait While Redirecting . . .</b>';
					setTimeout(function(){window.location='admin/'},1500);
					//";
				}
			 else if(response==0)
				{	
					divMsg.style.border="1px solid green";
					divMsg.style.backgroundColor = "white";
					divMsg.style.color = "green";
					divMsg.innerHTML='<b style=color:green;font-size:11px;>Access Granted.Please Wait While Redirecting . . .</b>';
					setTimeout(function(){window.location='index.php'},1500);
				}
				else if(response==2)
				{	
					divMsg.style.border="1px solid green";
					divMsg.style.backgroundColor = "white";
					divMsg.style.color = "green";
					divMsg.innerHTML='<b style=color:green;font-size:11px;>Access Granted.Please Wait While Redirecting . . .</b>';
					setTimeout(function(){window.location='index.php'},1500);
				}
				else if(response==3)
				{
					divMsg.style.border="1px solid red";
					divMsg.style.backgroundColor = "white";
					divMsg.style.color = "red";
					divMsg.innerHTML='<b style=color:red;font-size:11px;>Your Username or Password is Incorrect.</b>';
				}
					
		
			}
		 }
	  }
    http.send(null);
	return false;
}

}
function Logclear(username,password)
{

document.getElementById(username).value="";
document.getElementById(password).value="";

}
function logOut()
{
	
	var http=GetXmlHttpObject()
	if (http==null)
     {
		alert ("Browser does not support HTTP Request")
		return false;
     }
	
var url ="../php/query/session_logout.php";
url = url+"?page=LogOut";
	http.open("GET",url,true);
	
    http.onreadystatechange = 
	 function()
	  {
		if (http.readyState == 4)
		 {
			
			if(http.status==200) 
			{
			
				var response = http.responseText;
		
		
				if(response==1)
				{

				window.location='../';
				}
				else 
				{
				}
					
		
			}
			
		 }
	  }
    http.send(null);
	return false;


}




function logOutUser()
{
	
	var http=GetXmlHttpObject()
	if (http==null)
     {
		alert ("Browser does not support HTTP Request")
		return false;
     }
var url ="php/query/session_logout.php";
url = url+"?page=LogOut";
	http.open("GET",url,true);
	
    http.onreadystatechange = 
	 function()
	  {
		if (http.readyState == 4)
		 {
			
			if(http.status==200) 
			{
		
				var response = http.responseText;
		
		
				if(response==1)
				{

				window.location='index.php';
				}
				else 
				{
					alert(response);
				}
					
		
			}
			
		 }
	  }
    http.send(null);
	return false;


}
