﻿// JScript File

var bHasFocus = false;
function authenticate()
{
	document.getElementById("btnAuth").style.cursor = "wait";
	document.body.style.cursor = "wait";
	var sEmail = document.getElementById("txtUserName").value;
	var sPassword = document.getElementById("txtPassword").value;
	progress(-1);
	ret = AdminLogin.authenticate(sEmail, sPassword, OnComplete, OnTimeOut, OnError);
}
var timeout = null;
function progress(nTimer)
{
	if(nTimer == -1)
	{
		timeout = setTimeout("progress("+(nTimer+1)+");", 500);
	}
	else
	{
		document.body.className = "processing";
		var oProgress = document.getElementById("divProgress");
		oProgress.style.left = '50%';
		oProgress.style.display = 'block';
		var sOutput = "<h3>Processing";
		for(var nIndex = 0; nIndex < nTimer%4; nIndex++)
			sOutput += ".";
		sOutput += "</h3>";
		oProgress.innerHTML = sOutput;
		timeout = setTimeout("progress("+(nTimer+1)+");", 500);
	}
}
function endProgress()
{
	document.body.className = "";
	document.getElementById("divProgress").style.display = 'none';
	clearTimeout(timeout);
}
function OnComplete(arg) {
	var sLocation = window.location.toString();
	sLocation = sLocation.substring(sLocation.indexOf('//')+2);
	sLocation = "http://"+sLocation.substring(0,sLocation.lastIndexOf('/'));
	if(arg)
	{
		window.location = sLocation+"/adminreport.aspx";
	}
	else
	{
		endProgress();
		alert("Incorrect User Name or Password");
		document.getElementById("btnAuth").style.cursor = "pointer";
		document.body.style.cursor = "";
	}
}
function OnTimeOut(arg) {
	endProgress();
	alert("TimeOut encountered.");
}
function OnError(arg) {
	endProgress();
	alert("Error encountered.");
}
function submitEnter(evt)
{
	var code;
	if (evt.keyCode) code = evt.keyCode;
	else if (evt.which) code = evt.which;
	if(code == 13 && bHasFocus)
	{
		authenticate();
		return false;
	}
}