// This method trims white space off both ends of this string and returns the result.
String.prototype.trim = function() 
{return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );}

function validEmail( email )
{   
   var reEmail = /^[0-9A-Za-z\._-]+\@[0-9A-Za-z\._-]+\.[A-Za-z]+$/;
   return reEmail.test( email );
}
function checkEmailField( field )
{
   if( !checkField( field, "Email address" ) )
      return false;
   if( !validEmail( field.value ) )
   {
      alert( "Email address is not properly formatted" );
      field.form.email.focus();
      return false;
   }
   return true;
}
function checkField( field, msg, withFocus )
{
   field.value = field.value.trim();
   if( field.value == "" )
   {
      alert( msg + " is a required field." );
      if( withFocus != false )
         field.focus();
      return false;
   }
   return true;
}
function checkSelect( field, msg )
{
   // To make it easier, just check to see if the index is 0
   // First item should be "Select <the item type>"
   if( field.selectedIndex == 0 )
   {
      alert( msg + " is a required field." );
      field.focus();
      return false;
   }
   return true;
}

function confirmDelete(msg)
{
   return confirm("This action will delete " + msg + ".\nAre you sure?");
}

function CheckAllBoxes(obj)
{
   var form = obj.form;
   for( i=0;i<form.elements.length;i++ )
   {
      var thisObj = form.elements[i];
      if( (thisObj != obj) && (thisObj.type=='checkbox') )
         thisObj.checked = obj.checked;
   }
}
