//<![CDATA[

//*********************************************************************
//* Common Javascript for COHS web pages                              *
//*                                                                   *
//* $Log: cohs.js,v $
//* Revision 1.2  2009-05-15 18:10:28-04  lars
//* W3C Transitional Compliant
//*
//* Revision 1.1  2008-10-21 23:13:32-04  lars
//* <>
//*
//* Revision 1.0  2008-10-04 22:41:08-04  lars
//* Initial revision
//*
//*********************************************************************



//*********************************************************************
//* function clickclear(obField, szDefaultText)                       *
//*                                                                   *
//* Clear obField if it contains szDefaultText                        *
//*                                                                   *
//*********************************************************************
function clickclear(obField, szDefaultText) {
  if (obField.value == szDefaultText) {
    obField.value = "";
  }
}



//*********************************************************************
//* function clickrecall(obField, szDefaultText)                      *
//*                                                                   *
//* Put szDefaultText into obField if obField is blank                *
//*                                                                   *
//*********************************************************************
function clickrecall(obField, szDefaultText) {
  if (obField.value == "") {
    obField.value = szDefaultText;
  }
}




//*********************************************************************
//* function onlyOneSubmit (obForm)                                   *
//*                                                                   *
//* Prevent multiple entries from double clicks of the obForm         *
//* Submit button                                                     *
//*                                                                   *
//*********************************************************************
function onlyOneSubmit (obForm) {
  if(obForm.value == 'Processing...') {
    alert("Request was previously submitted.\nClear or Reload the form before submitting.");
    return false;
  } else {
  obForm.value = 'Processing...';
  return true;
  }
}



//*********************************************************************
//* function verifyField (szFieldId)                                  *
//*                                                                   *
//* Verify the field with id szFieldId                                *
//* Highlight field label if it fails verification                    *
//* Unhighlight field label if it passes verification                 *
//*                                                                   *
//*********************************************************************

function verifyField (szFieldId) {
  var rc=0;
  var obField=document.getElementById(szFieldId);
  var obNotice=document.getElementById("verify_notice");
  var label="";

  // We are going to highlight or unhighlight the label
  // associated with the field. That label is
  // obField.id+"_label"
  label = obField.id+"_label";
  
  // alert("verifyField: szFieldId = "+szFieldId+"\n obField.id = "+obField.id+"\n obField.name = "+obField.name+"\n obField.value = "+obField.value+"\n label = "+label);
  
  if (obField.value==null||obField.value=="") {
    // Field is empty, verification failed
    rc=1;

    // Highlight the field's label
    highlight(label, "yellow");
  }
  else {
    // Verification passed, unhighlight the field
    // unHighlight(szFieldId+"_label");
    unHighlight(label);
  }
  
  return rc;
}




//*********************************************************************
//* function highlight(szElementId, szBackgroundColor)                *
//*                                                                   *
//* Set the background of szElementId to szBackgroundColor            *
//*                                                                   *
//*********************************************************************
function highlight(szElementId, szBackgroundColor) {
//  alert("highlight: szElementId = "+szElementId);
  document.getElementById(szElementId).style["backgroundColor"]=szBackgroundColor;
}




//*********************************************************************
//* function unHighlight(szElementId)                                 *
//*                                                                   *
//* Set the background of szElementId to its parent's background color*
//*                                                                   *
//*********************************************************************
function unHighlight(szElementId) {
//  alert("unHighlight "+szElementId);
  
  var obElement=document.getElementById(szElementId);
  
//  alert("unHighlight: szElementId="+szElementId+" obElement="+obElement);
  
  var obParent=obElement.parentNode;

  obElement.style["backgroundColor"]=obParent.style["backgroundColor"];
}





//]]>

