var oForm;
var oTimeout;
var oThankYou;
var oTooManyLogins;
var vTimeoutID;
var dStartDate;
var iTimeLimit;
var iInterval;

//attachEvent('onload', PageLoad);

//if(window.addEventListener){ // Mozilla, Netscape, Firefox
//	addEventListener('load', PageLoad, false);
//} else { // IE
//	attachEvent('onload', PageLoad);
//}
function LoginFormOnload() {
	if(typeof window.addEventListener != 'undefined') {
		//.. gecko, safari, konqueror and standard
		window.addEventListener('load', PageLoad, false);
	} else if(typeof document.addEventListener != 'undefined') {
		//.. opera 7
		document.addEventListener('load', PageLoad, false);
	} else if(typeof window.attachEvent != 'undefined') {
		//.. win/ie
		window.attachEvent('onload', PageLoad);
	}
}

function PageLoad() {
	oForm = document.getElementById('LoginFormContainer');
	oTimeout = document.getElementById('TimeoutMessageContainer');
//	oThankYou = document.getElementById(LoginThankYouContainer);
//	oTooManyLogins = document.getElementById(LoginTooManyContainer);

	dStartDate = new Date();
	iTimeLimit = Number(document.getElementById('TimeLimit').value) * 1000;
	iInterval = Number(document.getElementById('CountInterval').value) * 1000;
//	document.getElementById('LoginUserName').focus();
	UpdateCountdown(dStartDate);
}
                
function LoginCountdown() {
	var dNow = new Date();
	if((dNow-dStartDate)<iTimeLimit) {
		UpdateCountdown(dNow);
	} else {
		if(oForm != null) {
			oForm.style.display='none';
		}
		if(oTimeout != null) {
			oTimeout.style.display='';
		}
		if(oThankYou != null) {
			oThankYou.style.display='none';
		}
		if(oTooManyLogins != null) {
			oTooManyLogins.style.display='none';
		}		
	}
}
 
function UpdateCountdown(dNow) {
	var oCountdown = document.getElementById('LoginCountDown');

	if(oCountdown != null) {
		document.getElementById('CountdownMessage').innerHTML = document.getElementById('LoginCountDown').value.replace('%s', Math.round(((dStartDate-dNow)+iTimeLimit)/1000));
	}
	vTimeoutID = window.setTimeout('LoginCountdown();', iInterval);
}

function PreLogin() {
	var dNow = new Date();
	if ((dNow-dStartDate)<iTimeLimit) {
		var sPartResponse;

		document.getElementById('LoginResponse').value = b64_sha1(document.getElementById('LoginChallenge').value+':'+b64_sha1(document.getElementById('LoginUserName').value.toLowerCase()+':'+document.getElementById('LoginPassword').value.toLowerCase()));
		document.getElementById('LoginUserName').value = document.getElementById('LoginUserName').value.substr(0,2); //''; //give us the first two characters to speed up searching in the DB
		document.getElementById('LoginPassword').value = '';
		document.getElementById('LoginChallenge').value = '';
		
		if(oForm != null) {
			oForm.style.display='none';
		}
		if(oTimeout != null) {
			oTimeout.style.display='none';
		}
		if(oThankYou != null) {
			oThankYou.style.display='';
		}
		if(oTooManyLogins != null) {
			oTooManyLogins.style.display='none';
		}		
		return document.getElementById('LoginPassword').value.length==0;
	} else {
		return false;
	}
}


