//<![CDATA[

//*********************************************************************
//* Javascript for COHS Information Request Form                      *
//*********************************************************************
//* $Log: cohs_ir.js,v $
//* Revision 1.5  2009-05-15 18:19:05-04  lars
//* Added verification of bot-check field
//*
//* Revision 1.4  2008-10-26 10:17:32-04  lars
//* Removed BETA from titles
//*
//* Revision 1.3  2008-10-22 00:03:40-04  lars
//* Added unHighlight email_label
//*
//* Revision 1.1  2008-10-21 23:13:42-04  lars
//* <>
//*
//* Revision 1.0  2008-10-04 22:42:44-04  lars
//* Initial revision
//*
//*********************************************************************



//*********************************************************************
//* function function enableSubject()                                 *
//*                                                                   *
//* If a subject category's radio button is checked                   *
//*   enable Subject text field that has id=radio_button.value+"_text"*
//*   Give focus to the subject text field                            *
//* Otherwise                                                         *
//*   disable the subject text field                                  *
//*                                                                   *
//*********************************************************************
function enableSubject() {
  var id;
  for (var i=0; i<document.inforequest.subject_mandatory.length; i++) {
   
    id=document.inforequest.subject_mandatory[i].value;
    
    alert("enableSubject: id="+id+" id_text="+id+"_text");
    
    if (document.inforequest.subject_mandatory[i].checked==true) {
      document.getElementById(id+"_text").disabled=false;
      document.getElementById(id+"_text").focus();
    }
    else {
      document.getElementById(id+"_text").disabled=true;
    }
    if (id=="pn") {
      document.getElementById("pt_text").disabled=document.getElementById(id+"_text").disabled;
      document.getElementById("pd_text").disabled=document.getElementById(id+"_text").disabled;
    }
  }
}



//*********************************************************************
//* function setDescriptionHint(szSubject)                            *
//*                                                                   *
//* Set the Description hint text based on the subject that has been  *
//* selected.                                                         *
//*                                                                   *
//*********************************************************************
function setDescriptionHint(szSubject) {
  var rc=0;

  var hint="&nbsp;&minus;&nbsp;";
  
  switch(szSubject) {
    case 'ls':
      hint=hint+"Class&nbsp;or&nbsp;Road&nbsp;Number&nbsp;and&nbsp;Railroad";
      break;
    case 'ld':
      hint=hint+"Class&nbsp;or&nbsp;Road&nbsp;Number&nbsp;and&nbsp;Railroad";
      break;
    case 'rp':
      hint=hint+"Type,&nbsp;Series,&nbsp;Road&nbsp;Number,&nbsp;or&nbsp;Name&nbsp;and&nbsp;Railroad";
      break;
    case 'rf':
      hint=hint+"Type,&nbsp;Series,&nbsp;or&nbsp;Road&nbsp;Number&nbsp;and&nbsp;Railroad";
      break;
    case 'rm':
      hint=hint+"Exact&nbsp;Type&nbsp;and&nbsp;Railroad";
      break;
    case 'ss':
      hint=hint+"Station Name,&nbsp;or&nbsp;City,&nbsp;and&nbsp;State&nbsp;(or&nbsp;Province)";
      break;
    case 'sb':
      hint=hint+"Structure&nbsp;Type(s)&nbsp;and&nbsp;Location";
      break;
    case 'op':
      hint=hint+"Location,&nbsp;Time&nbsp;Period";
      break;
    case 'of':
      hint=hint+"Location,&nbsp;Time&nbsp;Period";
      break;
    case 'oo':
      hint=hint+"Location,&nbsp;Time&nbsp;Period";
      break;
    case 'oa':
      hint=hint+"Location,&nbsp;Time&nbsp;Period";
      break;
    case 'pp':
      hint=hint+"Location,&nbsp;Time&nbsp;Period,&nbsp;Description";
      break;
    case 'pe':
      hint=hint+"Location,&nbsp;Time&nbsp;Period";
      break;
    case 'po':
      hint=hint+"Time&nbsp;Period";
      break;
    case 'pn':
      hint=hint+"Location,&nbsp;Time&nbsp;Period,&nbsp;Description. See Employee Records Note Below.";
      break;
    default:
      hint=hint+"Use this space to clarify your request.";
  }  
  

  
  document.getElementById("description_label").innerHTML=hint;

  return rc;
}




//*********************************************************************
//* function verifyInfoRequest(obForm)                                *
//*                                                                   *
//* Verify the InfoRequest form is filled in properly                 *
//*                                                                   *
//*********************************************************************
function verifyInfoRequest(obForm) {
  var rc=0; // Assume verification is good;
  var obNotice=document.getElementById("verify_notice");

  // Verify the Personal Data. All the fields must be filled in.
  rc=rc+verifyField("lastname");
  rc=rc+verifyField("firstname");
  rc=rc+verifyField("street1");
  rc=rc+verifyField("city");
  rc=rc+verifyField("state");
  rc=rc+verifyField("zip");
  rc=rc+verifyField("email");
  
  // Verify the Material Requested. At least one of the check boxes
  // must be checked.
  var iCounter=0;
  if (document.getElementById("files").checked==true) { iCounter=iCounter+1; }
  if (document.getElementById("drawings").checked==true) { iCounter=iCounter+1; }
  if (document.getElementById("photos").checked==true) { iCounter=iCounter+1; }
  if (document.getElementById("publications").checked==true) { iCounter=iCounter+1; }
  if (document.getElementById("general").checked==true) { iCounter=iCounter+1; }
  
  if (iCounter==0) {
    // Highlight the Materal Requested note
    highlight("materials_mandatory_label", "yellow");
    rc=rc+1;
  } else {
    // Unhighlight the Material Requested note
    unHighlight("materials_mandatory_label");
  }

  // Verify the Subject has been selected.
  rc=rc+verifyField("subject");
  
  // Verify the Description has been entered.
  rc=rc+verifyField("description");

  // Verify the bot checker.
  rc=rc+verifyField("chk");

  if (document.getElementById("chk").value!="chessie") {
    // Highlight the field's label
    highlight("chk_label", "yellow");
    rc=rc+1;
  }

  // Set the return code based on what we found
  if (rc==0)
    rc=true;
  else
    rc=false;

  // If verification passed,
  if (rc) {
    // Hide the notice that field(s) need attention
    obNotice.style["display"]="none";

    // make sure the submit button was clicked only once
    //rc=onlyOneSubmit(obForm);
  }
  else
    // The verification failed.
    // Display the notice that field(s) need attention
    obNotice.style["display"]="inline";
  
  return rc;
}




//*********************************************************************
//* function clearHighlights(obForm)                                  *
//*                                                                   *
//* Unhighlight the fields that might be highlighted                  *
//* by verifyInfoRequest                                              *
//*                                                                   *
//*********************************************************************
function clearHighlights(obForm) {
  var obNotice=document.getElementById("verify_notice");

  // Unhighlight the Personal Data
  unHighlight("firstname_label");
  unHighlight("lastname_label");
  unHighlight("street1_label");
  unHighlight("city_label");
  unHighlight("state_label");
  unHighlight("zip_label");
  unHighlight("email_label");

  // Unhighlight the Material Requested
  unHighlight("materials_mandatory_label");

  // Unhighlight the Subject Requested
  unHighlight("subject_label");

  // Unhighlight the Description
  unHighlight("description_label");

  // Unhighlight the bot check
  unHighlight("chk_label");

  // Hide the notice that field(s) need attention
  obNotice.style["display"]="none";

  // Reset the Description Hint text
  var hint="Use this space to clarify your request.";
  document.getElementById("description_label").innerHTML=hint;
  
  // Reset the "one submit" check
  obForm.value = 'Clear Fields';
}


//]]>
