function ajax_login()
{ 
	document.getElementById("divLoginError").innerHTML = "";
	
	$.ajax({
	   type: "POST",
	   url: "/admin/signinDo_Client.asp",
	   data: "txtLogin=" + document.getElementById('txtLogin').value + "&txtPassword=" + document.getElementById('txtPassword').value + "&src=ajax",
	   success: function(msg){
			if(msg.substr(0,9)=="_success_")
			{
		 		document.getElementById("spanLoginTable").style.display="none";
				document.getElementById("spanLoggedIn").style.display="";
				document.getElementById("spanLoginName").innerHTML  = msg.substr(9);
				document.getElementById("spanDocumentNavigation").style.display="";
				location.href = "/documents/index.asp";
			}
			else
			{
				loginButton_errorMessage_ShowHide(0, 1, msg);
				//document.getElementById("divLoginError").innerHTML = msg;
			}
	   },
	   error: function(msg) {
		   document.getElementById("spanLoggedIn").style.display="none";
		   document.getElementById("divLoginError").innerHTML = "Unknown error occured.";
		   document.getElementById("spanDocumentNavigation").style.display="none";
	   }
	 });
}

function ajax_logout()
{ 
	document.getElementById("divLoginError").innerHTML = "";
	
	$.ajax({
	   type: "POST",
	   url: "/admin/logout_Client.asp",
	   data: "",
	   success: function(msg){
			//alert( "Logout Result: " + msg.substr(0,9) );
			if(msg.substr(0,9)=="_success_")
			{
		 		document.getElementById("spanLoginTable").style.display="";
				document.getElementById("spanLoggedIn").style.display="none";
				document.getElementById('txtLogin').value="username ...";
				document.getElementById('txtPassword').value="password ...";
				document.getElementById("spanDocumentNavigation").style.display="none";
				// Following line is to redirect to home if on decuments page
				if(location.href.lastIndexOf('documents/index.asp')!=-1) location.href='/index.asp';
			}
			
	   },
	   error: function(msg) {
		   //
	   }
	 });
}

function loginButton_errorMessage_ShowHide(btn, msg, msgtext)
{
	if(btn==1)
		document.getElementById("spanLoginButton").style.display="";
	else
		document.getElementById("spanLoginButton").style.display="none";
	
	if(msg==1)
		document.getElementById("divLoginError").style.display="";
	else
		document.getElementById("divLoginError").style.display="none";
		
	document.getElementById("divLoginError").innerHTML = msgtext;
}