var thisLocation = document.location.href;
if((thisLocation.indexOf("http:")>=0)||(thisLocation.indexOf("y.org")>=0)){
	document.location.href = thisLocation.replace("http:", "https:").replace("y.org", "y.com");
}

function forgotLogin(theForm){
	var URL = "/tlc/lmsloginforgot.asp?UserName=" + theForm.username.value;
	document.location.href = URL;
}

function noSubmit(theForm){
	doLogin(theForm);
	return false;
}

function doLogin(theForm){
	Set_Cookie( 'test', 'none', '', '/', '', '' );
	if(xmlHttp){
		if((theForm.username.value.length > 0)&&(theForm.password.value.length > 0)){
			var theUser, thePass;
			theUser = escape(theForm.username.value);
			thePass = escape(theForm.password.value);
			var theURL = "/tlc/lmslogin.asp?myName=" + theForm.myName.value + "&exitPage=" + theForm.exitPage.value + "&username=" + theUser + "&password=" + thePass;
			if(theForm.AdminLogin!=null)
				theURL += "&AdminLogin=1";
			xmlHttp.open("GET", theURL, true);
			xmlHttp.onreadystatechange = commitLogin;
			xmlHttp.send(null);
		}else{
			alert("You must provide a username and password.");}}}

function commitLogin(){
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			var theResponse = xmlHttp.responseText.toLowerCase();
			if(theResponse.indexOf(".asp") > 1){
				detectPopupBlocker();
				document.location.href=theResponse;
			}else{
				var theMessage = "";
				switch(theResponse){
					case "backuptime":
						theMessage = "The system is currently undergoing maintenance.     \nPlease try again later.";
						break;    
					case "nosubscription":
						theMessage = "No Subscription could be found.\nPlease contact your system administrator for assistance.     ";
						break;    
					case "attachfailed":
						theMessage = "Unable to attach an access record.\nPlease contact Technical Support for assistance.     ";
						break;    
					case "subscriptionexpired":
						theMessage = "Your organization subscription has expired.\nPlease contact your system administrator for assistance.     ";
						break;    
					case "nosuchuser":
						theMessage = "The user information provided does not match any user in the system.     \nPlease try again.";
						break;    
					case "inactiveuser":
						theMessage = "Your account has been deactivated.\nPlease contact your system administrator for assistance.     ";
						break;    
					case "adminonly":
						theMessage = "Only ortganization Admins are allowed entry at this time.\nPlease contact your system administrator for assistance.     ";
						break;    
					case "nocookies":
						theMessage = "Cookies MUST be enabled to use The Learning Community.     \nPlease enable cookies and try again.";
						break;    
					default:
						theMessage = "An unrecognized error has ocurred.\nPlease contact Technical Support for assistance.     \n";
						break;}
				alert(theMessage);}
		}else{
			alert("Error connecting to resource");}}}

function detectPopupBlocker(){
	var myTest = window.open("about:blank","","directories=no,height=100,width=100,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
	if (!myTest) {
		alert("A popup blocker was detected running in your browser.     \r\nPlease disable your popup blocker to access course content.     ");
	} else {
		myTest.close();}}

function Set_Cookie(name, value, expires, path, domain, secure){
	var today = new Date();
	today.setTime( today.getTime());
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape(value) + ((expires) ? ";expires=" + expires_date.toGMTString() : "") +  ((path) ? ";path=" + path : "") +  ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : "");}

nn=(document.layers)?true:false; 
ie=(document.all)?true:false; 
function keyDown(e) { 
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt){
        var key=(evt.charCode)?evt.charCode:((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
        if(key==13){
        	document.loginForm.Submit.click();
        }
    }
}
document.onkeydown=keyDown; 
if(nn) document.captureEvents(Event.KEYDOWN); 
