function ValidateLoginData() {
   var CanSubmit = false;
   var errormessage = "Please make sure that you have filled in the following fields before clicking Login:\n\n"
   CanSubmit = ForceEntry(document.forms[0].TopUsername);
   if (CanSubmit == false) 
	{
		errormessage += "Your Username.\n";
	}
	CanSubmit = ForceEntry(document.forms[0].TopPassword);
	 if (CanSubmit == false) 
	{
		errormessage += "Your Password.\n";
	}
   if (errormessage == 'Please make sure that you have filled in the following fields before clicking Login:\n\n')
   {
	return true;
   }
   else 
   {
	alert(errormessage)
	return false;
   }
}

function CallLogin(result)
{
	var ReturnURL = new String();
	ReturnURL = Request.QueryString("ReturnURL")
	
	if(result.value == "Inactive")
	{
		hide("LoginMain");
		show("LoginInactive");
		hide("LoginIncorrect");
		hide("LoginLoading");
		setTimeout("ShowLogin()", 5000);
	}else if(result.value == "Incorrect")
	{
		hide("LoginMain");
		hide("LoginInactive");
		show("LoginIncorrect");
		hide("LoginLoading");
		setTimeout("ShowLogin()", 5000);
	}
	else if(result.value == "Users")
	{
		if (ReturnURL == "undefined" || ReturnURL == "")
		{
			location.replace("Users/index.aspx")
		}else {
			location.replace(ReturnURL)
		}
	}
	else if(result.value == "Administrator")
	{
		if (ReturnURL == "undefined" || ReturnURL == "")
		{
			location.replace("Admin/Index.aspx")
		}else {
			location.replace(ReturnURL)
		}
	}
	else {
		ShowLogin() 
	}
}

function Login() 
{	
	hide("LoginMain");
	hide("LoginInactive");
	hide("LoginIncorrect");
	show("LoginLoading");
	Nortech.LoginPage.Login(document.getElementById("TopUsername").value, document.getElementById("TopPassword").value, CallLogin);
}

function ShowLogin() 
{	
	show("LoginMain");
	hide("LoginInactive");
	hide("LoginIncorrect");
	hide("LoginLoading");
}

function CheckReason() 
{	
	msg = Request.QueryString("Msg");
	if (msg == "Maintain") {
		alert("We are sorry, either you were logged out due to your account remaining inactive for longer than 20 minutes, or you were logged out due to site maintenance.  Please login again.")
	}
	
	CheckLogged()
}

function CheckLogged() 
{	
	scroll(0,0);
	show("LoginLoading");
	Nortech.LoginPage.CheckLogin(CallCheckLogged);
}

function CallCheckLogged(result)
{
	hide("LoginLoading");
	if(result.value == "Administrator")
	{
		LoginLink.href = './Admin/Index.aspx'
		document.getElementById("Area").innerHTML = "Site Administrator";
		show("LoggedIn");
		
	}else if(result.value == "Users")
	{
		document.getElementById("LoginLink").href = './Seekers/Index.aspx'
		document.getElementById("Area").innerHTML = "Job Seekers section";
		show("LoggedIn");
	}
	else if(result.value == "Not Logged")
	{
		returnURL = Request.QueryString("ReturnURL");
		if (returnURL == "undefined") {
			hide('NoAccess');
			show('LoginMain')
		} else {
			show('NoAccess');
			hide('LoginMain');
		}
	} else {
		alert(result.value)
		show("LoginMain");
	}
}