
function messageWindow(title, msg)
{
  var width="300", height="125";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title></head>';
  var body = '<center>'+msg+'<br><p><form><input type="button" value="   Done   " onClick="self.close()"></form>';
  msgWindow.document.write(head + body);
}

function printPage() { print(document); }


function CheckEmail(theForm){
	// call the other email method instead of duplicating the code here, then CheckPassword
	return checkEmailSyntax(theForm.Email) && CheckPassword(theForm);
}

function CheckPassword(theForm){
	if (theForm.newPassword.value==""){
		alert('Please enter your password.');
		theForm.newPassword.focus();
		return false;
	}
	
	if (theForm.newPasswordConfirmation.value==""){
		alert('Please confirm your password.');
		theForm.newPasswordConfirmation.focus();
		return false;
	}
	if (!(theForm.newPasswordConfirmation.value.match(theForm.newPassword.value))) {
		alert('Your confirmation password did not match your password.');
		theForm.newPasswordConfirmation.focus();
		return false;
	}
		
	return true;
}

function checkEmailSyntax(theInput) {
	if (theInput.value == "") {
		alert('Please enter an email address. \n\nA properly formatted email address looks like this: jpublic@publicCSD.org');
		theInput.focus();
		theInput.select();
		return false;
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(theInput.value))) { 
		alert('Please enter a valid email address.\n\nA properly formatted email address looks like this: jpublic@publicCSD.org');
		theInput.focus();
		theInput.select();
		return false;
	} else {
		//test email for illegal characters
		var illegalChars= /[\ \\(\)\<\>\,\;\:\\\"\[\]]/;
		if (theInput.value.match(illegalChars)) {
			alert('The email address contains illegal characters. \n\nA properly formatted email address looks like this: jpublic@publicCSD.org');
			theInput.focus();
			theInput.select();
			return false;
		}
	}
	return true;
}
		
function CheckChangedEmail(){
	if (document.form.currentEmail.value==""){
		alert('Please enter your current password.');
		document.form.currentPassword.focus();
		return false;
	}
	if (document.form.newEmail.value==""){
		alert('Please enter your new password.');
		document.form.newPassword.focus();
		return false;
	}
	if (document.form.newEmailConfirmation.value==""){
		alert('Please confirm your new password.');
		document.form.newPasswordConfirmation.focus();
		return false;
	}
	if (!(document.form.newEmailConfirmation.value.match(document.form.newPassword.value))) {
		alert('Your confirmation password did not match your new password.');
		document.form.newPasswordConfirmation.focus();
		return false;
	}
}

function CheckValues(){
	if (document.form.Email.value==""){
		alert('Please enter an email address. \n\nA properly formatted email address looks like this: jpublic@publicCSD.org');
		document.form.Email.focus();
		document.form.Email.select();
		return false;
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(document.form.Email.value))) { 
		alert('Please enter a valid email address.\n\nA properly formatted email address looks like this: jpublic@publicCSD.org');
		document.form.Email.focus();
		document.form.Email.select();
		return false;
	}
	else {
		//test email for illegal characters
		var illegalChars= /[\ \\(\)\<\>\,\;\:\\\"\[\]]/;
		if (document.form.Email.value.match(illegalChars)) {
			alert('The email address contains illegal characters. \n\nA properly formatted email address looks like this: jpublic@publicCSD.org');
			document.form.Email.focus();
			document.form.Email.select();
			return false;
		}
	}
}

function trimAll( strValue ) {
/************************************************
AUTHOR: Karen Gayda (http://www.rgagnon.com/jsdetails/js-0063.html)

DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
	var objRegExp = /^(\s*)$/;

	//check for all spaces
	if(objRegExp.test(strValue)) {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0)
			return strValue;
	}

	//check for leading & trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue)) {
		//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	}
	return strValue;
}
