//  useful form handling functions

function  set_field_by_id( id, val ) {
  o = new Element_From_Id(id);
  if  ( o.obj ) {
    o.obj.value = val;
  }
}

function  clear_field_by_id( id, val ) {
  o = new Element_From_Id(id);
  if  ( o.obj.value == val ) {
    return  set_field_by_id(id,'');
  }
  else  {
    o.obj.select();
  }
}

function  reset_field_by_id( id, val )  {
  o = new Element_From_Id(id);
  if  ( o.obj.value == '' ) {
    return  set_field_by_id(id,val);
  }
}


function check_form( frm ) {

if (frm.email.value != frm.confirmemail.value)
{
	alert("The two email addresses are not the same.");
	return (false);
}

   if ( !frm.IO_REQUIRED_FIELDS || frm.IO_REQUIRED_FIELDS.value == "" )   {
      return true;
   }
   
   fields_to_check   =  frm.IO_REQUIRED_FIELDS.value.split(",");
   
   e  =  "";
   fs =  new Array();
   for   ( i in fields_to_check )   {
      a  =  i;
      fn =  "mail"+uc_words(fields_to_check[i]);
      f  =  frm[fn];
      if ( !f || f.value == "" ) {
         if ( e == "" ) {
            e  =  a;
            f.focus();
         }
         fs[a] =  uc_words(fields_to_check[a]);
         f.className +=  " error";
      }
   }
   
   if ( e != "" )  {
      e_msg =  "Please ensure that the following (highlighted) fields are correctly completed:\n";
      for   ( i in fs ) {
         e_msg += fs[i]+"\n";
      }
      alert(e_msg);
      return   false;
   }
   return   true;
}
