function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) { xmlhttp = false; }
		}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	}
	catch (e) { xmlhttp = false; }
	}
	return xmlhttp;
}

function showisLoading() {
	document.getElementById("isLoading").style.display = "";
}

function hideisLoading() {
	document.getElementById("isLoading").style.display = "none";
}

function hideError() {
	document.getElementById("ErrorMsg").style.display = "none";
}

function displayError(strError) {
	var pResult;
	pResult = "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n";
	pResult += "	<tr>\n";
	pResult += "		<td style=\"font-weight: normal; font-size: 8.5pt; color: #ff0000; font-family: verdana,arial;\" width=\"100%\" align=\"left\">" + strError + "</td>\n";
	pResult += "		<td valign=\"top\" style=\"padding-right: 6px;\"><a href=\"javascript:hideError();\" style=\"font-weight: bold; font-size: 8.5pt; color: #ff0000; font-family: verdana,arial;\">x</a></td>\n";
	pResult += "	</tr>\n";
	pResult += "</table>\n";
	document.getElementById("ErrorMsg").innerHTML = pResult;
	document.getElementById("ErrorMsg").style.display = "";
}

function LogOut() {
	window.open("Home.asp","_self");
}

var inProcess = false; 
var http = getHTTPObject(); 


//---------------------------------- Session Expired ----------------------------------------------//

var inProcessLogin = false; 
var httpLogin = getHTTPObject(); 

function doAltLogin() {
	var LoginName = document.getElementById("AltLoginName").value;
	var LoginPassword = document.getElementById("AltLoginPassword").value;
	if((LoginName!="")&&(LoginPassword!="")) UserAltLogin(LoginName,LoginPassword);
}

function afterUserAltLogin() { 
	if(httpLogin.readyState == 4) { 
		if(httpLogin.status == 200) { 
			if(httpLogin.responseText.indexOf("invalid") == -1) {
				hideisLoading();
				ProcessAltLogin(httpLogin.responseText); 
				inProcessLogin = false;
			}
		}
	}
}

function UserAltLogin(LoginName,LoginPassword) {
	if(!inProcessLogin && httpLogin) {
		showisLoading();
		var url = "Functions/LoginAlt.asp?"+nosame();
		httpLogin.open("POST", url, true);
		httpLogin.onreadystatechange = afterUserAltLogin;
		inProcessLogin = true;
		httpLogin.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		httpLogin.send("LoginName=" + LoginName + "&LoginPassword=" + LoginPassword + nosame());
		document.getElementById("submitbtn").value = "Login in...";
		document.getElementById("submitbtn").disabled = true;
	}
}

function ProcessAltLogin(strLoginResponse) {
	if((strLoginResponse.indexOf("true")==-1)&&(strLoginResponse!="false")) { //if an error has ocurred, display it
		document.getElementById("loginMessage").innerHTML = strLoginResponse
		document.getElementById("submitbtn").value = "    login    ";
		document.getElementById("submitbtn").disabled = false;
		}
	else {
		if(strLoginResponse.indexOf("true")!=-1)  { 
			document.getElementById("loginMessage").innerHTML = "You're now logged in..."
			setTimeout("hideError();",1500)
		}
		else {
			document.getElementById("submitbtn").value = "    login    ";
			document.getElementById("submitbtn").disabled = false;
		}
	}

}

var inProcessTestSession = false; 
var httpTestSession = getHTTPObject(); 

function TestSession(strFunction) {
	if(!inProcessTestSession && httpTestSession) {
//		showisLoading();
		var url = "Functions/TestSession.asp?"+nosame();
		httpTestSession.open("POST", url, true);
		httpTestSession.onreadystatechange = afterTestSession;
		inProcessTestSession = true;
		httpTestSession.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		httpTestSession.send("Function=" + strFunction + nosame());
	}
}

function afterTestSession() { 
	if(httpTestSession.readyState == 4) { 
		if(httpTestSession.status == 200) { 
			if(httpTestSession.responseText.indexOf("invalid") == -1) {
				if(httpTestSession.responseText.indexOf(errorCode)==-1) eval(httpTestSession.responseText); 
				else displayError(httpTestSession.responseText.replace(errorCode,"error"));
//				hideisLoading();
				inProcessTestSession = false;
			}
		}
	}
}

//---------------------------------- End Session Expired ------------------------------------------//

