//////////////////////////////////////////////////////////////
// login

var sPath;

function successFn(result, request )
{
	var sError;
	var sResponse = result.responseText;
	
	sError = sResponse.substr(0,3);
	sResponse = sResponse.substr(4);
	if (sError == "000")
	{
		if (sPath != null)
			window.location = sPath + "desktop.php";
		else
			window.location = "desktop.php";
	}
	else
	{
	    Ext.MessageBox.alert('Warning', sResponse, null);
	}
}

function failedFn(result, request )
{
	alert("AJAX Command Failed");
}

function DoLogin(vPath)
{
 	var sUserid = document.getElementById("userid").value;
 	var sPassword = document.getElementById("password").value;
	var sWidth = document.body.clientWidth;
	var sHeight = document.body.clientHeight;
	
	sPath = "system/";
	Ext.Ajax.request({
   		url: 'ajax.php',
   		method: 'POST',
   		success: successFn,
   		failure: failedFn,
   		params: { command: 'login', userid: sUserid, password: sPassword, width: sWidth, height: sHeight }
	});
}

function entsub(evt)
{
	if (evt != null)
	{
		if (evt.which == 13)
		{
			DoLogin();
			return false;
		}
		else if (window.event.keyCode == 13)
		{
			DoLogin();
			return false;
		}
	}
	else
	{
		 if (window.event.keyCode == 13)
		 {
			DoLogin();
			return false;
		 }
	}
}

Ext.onReady(function()
{	
 	var panel = document.getElementById("login-panel");
 	
 	if (panel)
 	{
		panel.style.marginTop = (document.body.clientHeight - 480)/2;
		panel.style.marginLeft = (document.body.clientWidth - 665)/2;
		document.getElementById("userid").focus();
 	}
});
