var loginType="new";
var reloginConfig = new Object();
	reloginConfig.resizable=false;
	reloginConfig.height=241;
	//reloginConfig.width=420;
	reloginConfig.modal=true;
	reloginConfig.closable=false;
	reloginConfig.draggable=true;
	reloginConfig.initshow=true;
	reloginConfig.center=true;
	reloginConfig.bodyStyle="background-color:#000000;"	

var reloginURL='index.cfm?strEvent=admin/relogin';
var reloginName='loginWindow';


function CountDown() 
{

	clearTimeout('timerLoop');
	reLoginSeconds -= 10;
	reStartSeconds -= 10;

	document.getElementById("testText").value = reLoginSeconds + " : " + reStartSeconds;
	if (reStartSeconds <= 0) {
		closeLogin();
		document.location="index.cfm";
	} else if (reLoginSeconds <= 0 && !gotWindow) {
				showLogin("re");
				gotWindow = true;
				//alert('Your session has been idle for more than ' + reLoginMinutes + " minutes. You must re-login to continue.')
	}
	 timerLoop = setTimeout('CountDown()', 10000);

}

function resetTimeout(){

	reLoginSeconds = (reLoginMinutes * 60)+10;
	reStartSeconds = (reStartMinutes * 60)+10;
	gotWindow = false;

	//CountDown();
}

function showLogin(type){
	ColdFusion.Window.create(reloginName, reloginTitle, reloginURL, reloginConfig);
	loginType=type;
}

function doLogin(){
	// Create the ajax proxy instance. AJAX for proxy is in login form page. 
	var auth = new userManager();
	var validated = "invalid";
		
	// setForm() implicitly passes the form fields to the CFC function.
	auth.setForm("loginForm");
	
	//Call the CFC validateCredentials function.
	validated = auth.validateLogin();
	
	if ( validated ) {
		if ( loginType=="new" ){
			document.location="index.cfm";
		} else {
			closeLogin();
			resetTimeout();
		}
		
	}
	else {
	    var msg = document.getElementById("loginMsg");
		// If user needs to contact the help desk, the login button is disabled.
		//if (validated.indexOf("Help Desk") > 0 ){
		//	document.getElementById("btnLogin").className = "failed_login";		
		//	document.getElementById("btnLogin").disabled = true;
		//}
		document.getElementById("username").value = "";
		document.getElementById("password").value = ""; 
		alert("The Username and/or Password are invalid. Please try again.");
	}
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode // literal character code will be stored in this variable
	if (e && e.which) { //if which property of event object is supported (NN4)
	    e = e
	    characterCode = e.which //character code is contained in NN4's which property
	}
	else {
	    e = event
	    characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if (characterCode == 13) { //if generated character code is equal to ascii 13 (enter key)
	    doLogin(); //submit the form
	    return false
	}
	else {
	    return true
	}
} 

function closeLogin() {
		try {
		ColdFusion.Window.destroy(reloginName);
		} 
		catch (e) { alert("Error trying to close" + reloginName);	
		} 
		return false;
}
