function closeUserBar() {

	var url="user.jsp?close=bar&time="+new Date().getTime();

	//proper browser
	if (window.XMLHttpRequest)
		req=new XMLHttpRequest();

	//internet explorer 6 or earlier
	else if (window.ActiveXObject)
		req=new ActiveXObject("Microsoft.XMLHTTP");

	req.onreadystatechange=processCloseUserBarRequest;
	req.open("GET",url,true);
	req.send(null);

}

function processCloseUserBarRequest() {

	//loaded
	if (req.readyState==4) {

		//ok
		if (req.status==200) {

			//hide user bar
			document.getElementById("user").style.display="none";

		}
		
	}
	
}

function registerUser(minLength) {

	var emailAddress=document.getElementById("emailAddress");
	var newPassword=document.getElementById("newPassword");
	var repeatPassword=document.getElementById("repeatPassword");
	
	//email address is blank
	if (emailAddress.value=="") {
	
		//alert the user
		alert("You must enter your email address");
		
		//highlight email address
		emailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		emailAddress.focus();
		emailAddress.select();
		
		return false;
		
	//email address is invalid
	} else if (emailAddressIsValid(emailAddress.value)!=true) {
	
		//alert the user
		alert("You must a valid email address");
		
		//highlight email address
		emailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		emailAddress.focus();
		emailAddress.select();
		
		return false;
	
	//new password is blank
	} else if (newPassword.value=="") {
	
		//alert the user
		alert("You must enter your password");
		
		//highlight new password
		newPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newPassword.focus();
		newPassword.select();
		
		return false;

	//repeat password is blank
	} else if (repeatPassword.value=="") {
	
		//alert the user
		alert("You must enter your password twice");
		
		//highlight repeat password
		repeatPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		repeatPassword.focus();
		repeatPassword.select();
		
		return false;

	//new passwords don't match
	} else if (newPassword.value!=repeatPassword.value) {
	
		//alert the user
		alert("Your passwords must match");
		
		//highlight new password and repeat password
		newPassword.style.backgroundColor="#ffffcc";
		repeatPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newPassword.focus();
		newPassword.select();
		
		return false;
	
	//new password is too short
	} else if (newPassword.value.length<minLength) {
	
		//alert the user
		alert("Your password must be a minimum of "+minLength+" characters");
		
		//highlight new password and repeat password
		newPassword.style.backgroundColor="#ffffcc";
		repeatPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newPassword.focus();
		newPassword.select();
		
		return false;

	//no problems found
	} else
		return true;

}

function resetPassword() {

	var emailAddress=document.getElementById("emailAddress");
	
	//email address is blank
	if (emailAddress.value=="") {
	
		//alert the user
		alert("You must enter your email address");
		
		//highlight email address
		emailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		emailAddress.focus();
		emailAddress.select();
		
		return false;
		
	//email address is invalid
	} else if (emailAddressIsValid(emailAddress.value)!=true) {
	
		//alert the user
		alert("You must a valid email address");
		
		//highlight email address
		emailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		emailAddress.focus();
		emailAddress.select();
		
		return false;
	
	//no problems found
	} else
		return true;

}

function changeEmailAddress() {

	var newEmailAddress=document.getElementById("newEmailAddress");
	var repeatEmailAddress=document.getElementById("repeatEmailAddress");
	
	//new email address is blank
	if (newEmailAddress.value=="") {
	
		//alert the user
		alert("You must enter your new email address");
		
		//highlight new email address
		newEmailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newEmailAddress.focus();
		newEmailAddress.select();
		
		return false;

	//repeat email address is blank
	} else if (repeatEmailAddress.value=="") {
	
		//alert the user
		alert("You must enter your new email address twice");
		
		//highlight repeat email address
		repeatEmailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		repeatEmailAddress.focus();
		repeatEmailAddress.select();
		
		return false;

	//new email addresses don't match
	} else if (newEmailAddress.value!=repeatEmailAddress.value) {
	
		//alert the user
		alert("Your new email addresses must match");
		
		//highlight new email address and repeat email address
		newEmailAddress.style.backgroundColor="#ffffcc";
		repeatEmailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newEmailAddress.focus();
		newEmailAddress.select();
		
		return false;
	
	//new email address is invalid
	} else if (emailAddressIsValid(newEmailAddress.value)!=true) {
	
		//alert the user
		alert("You must a valid email address");
		
		//highlight email address
		newEmailAddress.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newEmailAddress.focus();
		newEmailAddress.select();
		
		return false;

	//no problems found
	} else
		return true;

}

function changePasswordFromReset(minLength) {
	return changePassword(false,minLength);
}

function changePasswordFromAccount(minLength) {
	return changePassword(true,minLength);
}

function changePassword(fromAccount,minLength) {

	var newPassword=document.getElementById("newPassword");
	var repeatPassword=document.getElementById("repeatPassword");
	
	//new password is blank
	if (newPassword.value=="") {
	
		//alert the user
		alert("You must enter your "+(fromAccount?"new ":"")+"password");
		
		//highlight new password
		newPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newPassword.focus();
		newPassword.select();
		
		return false;

	//repeat password is blank
	} else if (repeatPassword.value=="") {
	
		//alert the user
		alert("You must enter your "+(fromAccount?"new ":"")+"password twice");
		
		//highlight repeat password
		repeatPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		repeatPassword.focus();
		repeatPassword.select();
		
		return false;

	//new passwords don't match
	} else if (newPassword.value!=repeatPassword.value) {
	
		//alert the user
		alert("Your "+(fromAccount?"new ":"")+"passwords must match");
		
		//highlight new password and repeat password
		newPassword.style.backgroundColor="#ffffcc";
		repeatPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newPassword.focus();
		newPassword.select();
		
		return false;
	
	//new password is too short
	} else if (newPassword.value.length<minLength) {
	
		//alert the user
		alert("Your "+(fromAccount?"new ":"")+"password must be a minimum of "+minLength+" characters");
		
		//highlight new password and repeat password
		newPassword.style.backgroundColor="#ffffcc";
		repeatPassword.style.backgroundColor="#ffffcc";
		
		//move focus and select
		newPassword.focus();
		newPassword.select();
		
		return false;

	//no problems found
	} else
		return true;

}

function emailAddressIsValid(emailAddress) {

	return ((emailAddress.indexOf("@")>0)&&(emailAddress.indexOf("@")<(emailAddress.length-1))&&(emailAddress.indexOf(".")>0)&&(emailAddress.indexOf(".")<(emailAddress.length-1))&&(emailAddress.lastIndexOf(".")>emailAddress.indexOf("@")));

}

function signIn() {

	var width=480;
	var height=226;

	//get the overlay
	var overlay=document.getElementById("overlay");

	//size the overlay
	overlay.style.height=getDocHeight()+"px";
	overlay.style.width=getDocWidth()+"px";

	//style the overlay
	overlay.style.filter="alpha(opacity=70)";
	overlay.style.opacity="0.7";

	//display the overlay
	overlay.style.display="";

	//get the sign in
	var signIn=document.getElementById("signIn");

	//position the sign in
	signIn.style.left=(((getClientWidth()-width)/2)-5)+"px";
	signIn.style.top=(((getClientHeight()-height)/2)-5)+"px";

	//display the sign in
	signIn.style.display="";
	
	//email address is empty
	if (document.getElementById("userEmailAddress").value=="") {
	
		//give focus to email address
		document.getElementById("userEmailAddress").focus();
		
	//password is empty
	} else if (document.getElementById("userPassword").value=="") {
	
		//give focus to password
		document.getElementById("userPassword").focus();

	}
	
	return false;

}

function cancelSignIn() {

	//get the sign in
	var signIn=document.getElementById("signIn");

	//hide the sign in
	signIn.style.display="none";

	//get the overlay
	var overlay=document.getElementById("overlay");

	//hide the overlay
	overlay.style.display="none";

	return false;
	
}

function signOut() {

	var url="user.jsp?sign=out&time="+new Date().getTime();

	//proper browser
	if (window.XMLHttpRequest)
		req=new XMLHttpRequest();

	//internet explorer 6 or earlier
	else if (window.ActiveXObject)
		req=new ActiveXObject("Microsoft.XMLHTTP");

	req.onreadystatechange=processSignOutRequest;
	req.open("GET",url,true);
	req.send(null);
	
	return false;

}

function processSignOutRequest() {

	//loaded
	if (req.readyState==4) {

		//ok
		if (req.status==200) {

			//hide sign out
			document.getElementById("userSignOut").style.display="none";
			
			//show sign in
			document.getElementById("userSignIn").style.display="";
			
		}
		
	}
	
}

function showEmailHelp() {

	var width=480;
	var height=494;

	//get the overlay
	var overlay=document.getElementById("overlay");

	//size the overlay
	overlay.style.height=getDocHeight()+"px";
	overlay.style.width=getDocWidth()+"px";

	//style the overlay
	overlay.style.filter="alpha(opacity=70)";
	overlay.style.opacity="0.7";

	//display the overlay
	overlay.style.display="";

	//get the email help
	var emailHelp=document.getElementById("emailHelp");

	//position the email help
	emailHelp.style.left=(((getClientWidth()-width)/2)-5)+"px";
	emailHelp.style.top=(((getClientHeight()-height)/2)-5)+"px";

	//display the email help
	emailHelp.style.display="";

}

function hideEmailHelp() {

	//hide the email help
	document.getElementById("emailHelp").style.display="none";
	
	//hide the overlay
	document.getElementById("overlay").style.display="none";
	
	return false;

}

//from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
//and http://james.padolsey.com/javascript/get-document-height-cross-browser/
function getClientWidth() {
	return filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function getClientHeight() {
	return filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function getDocHeight() {
    return Math.max(
        Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
        Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
        Math.max(document.body.clientHeight, document.documentElement.clientHeight)
    );
}

function getDocWidth() {
    return Math.max(
        Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
        Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
        Math.max(document.body.clientWidth, document.documentElement.clientWidth)
    );
}

function filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}