// JavaScript Document
/*
    Useful JavaScript functions that can be used to validate form information with ColdFusion.

    Author: Scott Jibben (scott@jibben.com)
    Create: 11/01/2005 3:35 AM
    Update: 02/27/2006 5:21 PM

    2/9/2006 4:19PM
    - Added SingleSelectionRequiredEx() to module.
    
    02/27/2006 5:21 PM
    - Renamed functions to have 'jcs' prefix.

    NOTE: THIS NEEDS TO BE INCLUDED BETWEEN THE HEAD TAGS TO BE COMPATIBLE!

    example:
    <script language="JavaScript" src="jcsFormExtUtils.js" type="text/javascript"></script>

*/


// this function will verify that an item is selected in a list
function jcsSingleSelectRequired(Form, Field) {
  var itemSelected = eval('document.' + Form + '.' + Field + '.selectedIndex');
  if (itemSelected == 0) {
    return false;
  }
  else {
    return true;
  }
}

// this function will verify that there is data in a text(area) field
function jcsTextAreaRequired(Form, Field) {
  var nTALen = eval('document.' + Form + '.' + Field + '.value.length');
  if (nTALen <= 0) {
    return false;
  }
  return true;
}

// this function will verify that a text(area) does not exceed a specified length
function jcsMaxTextAreaLen(Form, Field, MaxLength) {
  var nTALen = eval('document.' + Form + '.' + Field + '.value.length');
  if (nTALen > MaxLength) {
    return false;
  }
  return true;
}

function jcsSingleSelectRequiredEx(objForm, Field) {
//  alert("type = " + objForm[Field].type.toString().substring(0,3));
//  alert("Field = " + Field);

  // bail out if the field object is not a select list
  if (objForm[Field].type.toString().substring(0,3) != "sel") {
    alert("SingleSelectRequiredEx() is designed for form select objects");
    return false;
  }

  // get the selected index value
  var itemSelected = objForm[Field].selectedIndex;
//  alert("itemSelected =" + itemSelected);

  // this function assumes that your first selection in the list is not valid
  if (itemSelected == 0) {
    // set the focus to the field with the error
    objForm[Field].focus();
    return false;
  }
  else {
    return true;
  }
}

