// This (group of) function(s) ensures that something was entered or 
// selected in a textbox, selectbox, or radiogroup.
//
// Params:
//    inBox:      html text, radio, or select-one.
//    isRequired: Boolean determines if this box is required (if error
//                messages should be used).
//
// Returns: Flase, if box has something in it.  Nothing happens.
//          If box is blank...
//             If 'isRequired':
//                 True - error message appears, text (HERE!) appears in
//                 the box, and focus is reset to the box.  User may not
//                 continue (may not submit form while box is blank).
//             Not 'isRequired':
//                 False - nothing happens.
//
// This function is not fooled by [Blank]s.  The text of the passed in
// object is BoxIsBlank_Trim, and if it's blank, it is caught.
//
// When False (the box is not blank and all is successful), the text of
// the box is not changed; it is submitted AS-IS.
//
// If 'isRequired' is true, then ERROR boxes will appear if the box is
// blank.  'isRequired' should be true only in cases where it is truly
// REQUIRED.  If a box SHOULD BE filled, but is not required, then
// 'isRequired' should be set to false, and the 'warning message' (not
// error message) events should be handled by the calling function.

// VARIABLES...
var BoxHasNoText_TEXT       = '';
var BoxHasNoText_FlashCount = 0;
var BoxHasNoText_MAX_FLASH  = 6;
var BoxHasNoText_Obj;

var RadioIsSet_FlashCount = -1;
var RadioIsSet_FlashEach = 4;
var RadioIsSet_RadioOb;
var RadioIsSet_Which = -1;

var SelectionIsMade_TEXT = 'HERE!';
var SelectionIsMade_FlashCount   = 0;
var SelectionIsMade_MaxFlash = 10;
var SelectionIsMade_Obj;
var SelectionIsMade_OrigText = '';

//----------------------------------------------------------------------
//MAIN FUNCTION...
//----------------------------------------------------------------------
function BoxIsBlank(inObj, isRequired) {
   //DETERMINE INPUT TYPE...
   //alert(inObj.type);
   if (inObj == null) return false;
   inObj.className = '';
   switch (inObj.type) {
   case 'text':
   case 'textarea':
      return BoxHasNoText(inObj, isRequired);
      //alert('here');
      break;
   case 'select-one':
      return !SelectionIsMade(inObj, isRequired);
      break;
   case 'password':
      return BoxHasNoText(inObj, isRequired);
      break;
   default:
      if (inObj.length > 0) { // is a radio button
         return !RadioIsSet(inObj, isRequired);
      }
      break;

      //return (!confirm('ERROR:\n\nThe "' + inObj.type + '" (' + inObj.value + ') object is not recognized by the BoxIsBlank function.  Unable to confirm this objects data value.\n\nPlease notify technical support.\n\nContinue with process?'));
   }
}


//----------------------------------------------------------------------
//TEXTBOX FUNCTIONS...
//----------------------------------------------------------------------
function BoxHasNoText(inBox, isRequired) {
   str1 = new String;
   str1 = BoxHasNoText_Trim(inBox.value);
   BoxHasNoText_FlashCount = 0;
   if (str1 == '') {
      if (isRequired) {
         alert('A Required field has been left blank.\n\nPlease try again.');
         BoxHasNoText_Obj = inBox;
         if (BoxHasNoText_Obj.type != "text" && BoxHasNoText_Obj.type != "textarea" ) { 
				BoxHasNoText_Obj.focus(); 
         } else {
            BoxHasNoText_FlashIt();
         }
      }
      return true;
   } //else if (str1.indexOf(BoxHasNoText_TEXT) > -1) {
    //  alert('Remove the text: ' + BoxHasNoText_TEXT + ' from this field.');
      //BoxHasNoText_Obj = inBox;
      //BoxHasNoText_FlashIt();
      //return true;
   //}
   return false;
}

function BoxHasNoText_Trim(inStr) {
   while (inStr.substring(0, 1) == ' ') {
      inStr = inStr.substring(1, inStr.length);
   }
   while (inStr.substring(inStr.length - 1, 1) == ' ') {
      inStr = inStr.substring(0, inStr.length - 2);
   }
   return inStr;
}

function BoxHasNoText_FlashIt() {
   var Delayed = 200;
   BoxHasNoText_FlashCount++;
   if (BoxHasNoText_Obj.value == BoxHasNoText_TEXT) {
      BoxHasNoText_Obj.value = '';
   } else {
      BoxHasNoText_Obj.value = BoxHasNoText_TEXT;
   }
   if ((BoxHasNoText_FlashCount <= BoxHasNoText_MAX_FLASH) || (BoxHasNoText_Obj.value == '')) {
      //setTimeout("BoxHasNoText_FlashIt()", Delayed);
      BoxHasNoText_Obj.className = 'alert';
  // } else {
      // DONE FLASHING...
      BoxHasNoText_FlashCount = 0;
      //BoxHasNoText_Obj.value = '';//                 ';
      BoxHasNoText_Obj.focus();
      BoxHasNoText_Obj.select();
   }
   return;
}


//----------------------------------------------------------------------
//RADIOGROUP FUNCTIONS...
//----------------------------------------------------------------------
function RadioIsSet_Flash() {
   var Delayed = 80;
   var MaxFlash = RadioIsSet_FlashEach * RadioIsSet_RadioOb.length;
   RadioIsSet_FlashCount++;
   RadioIsSet_Which = RadioIsSet_FlashCount % RadioIsSet_RadioOb.length;
   RadioIsSet_RadioOb[RadioIsSet_Which].checked = true;
   RadioIsSet_RadioOb[RadioIsSet_Which].focus();
   if (RadioIsSet_FlashCount <= MaxFlash - 1) {
      setTimeout("RadioIsSet_Flash()", Delayed);
   } else {
      RadioIsSet_FlashCount = 0;
      for (var xx = 0; xx < RadioIsSet_RadioOb.length; xx++) {
         RadioIsSet_RadioOb[xx].checked = false;
      }
   }
   return;
}


function RadioIsSet(inObj, isRequired) {
   var ErrMsg = ErrIfRadioNotSet(inObj)
   if (ErrMsg) {
      if (isRequired) {
         alert(ErrMsg);
         RadioIsSet_RadioOb = inObj;
         RadioIsSet_Flash();
      }
   }
   return !ErrMsg;
}

function ErrIfRadioNotSet(inObj) {
   var ii = 0;
   while (ii < inObj.length) {
      if (inObj[ii].checked) {
         return false;
      }
      ii++;
   }
   return 'Invalid.\n\nNothing has been selected.';
}


//----------------------------------------------------------------------
//SELECTBOX FUNCTIONS...
//----------------------------------------------------------------------
function SelectionIsMade_Flash() {
   var Delayed = 150;
   //*******************************************
   // WE ARE CURRENTLY NOT USING THIS FEATURE...
   return;
   //*******************************************
   if (SelectionIsMade_FlashCount == 0) {
      SelectionIsMade_OrigText = SelectionIsMade_Obj.options[SelectionIsMade_Obj.selectedIndex].text;
   }
   SelectionIsMade_FlashCount++;
   if (SelectionIsMade_Obj.options[SelectionIsMade_Obj.selectedIndex].text == SelectionIsMade_TEXT) {
      SelectionIsMade_Obj.options[SelectionIsMade_Obj.selectedIndex].text = '';
   } else {
      SelectionIsMade_Obj.options[SelectionIsMade_Obj.selectedIndex].text = SelectionIsMade_TEXT;
   }
   if ((SelectionIsMade_FlashCount <= SelectionIsMade_MaxFlash) || (SelectionIsMade_Obj.options[SelectionIsMade_Obj.selectedIndex].text == SelectionIsMade_TEXT)) {
      setTimeout("SelectionIsMade_Flash()", Delayed);
   } else {
      SelectionIsMade_FlashCount = 0;
      SelectionIsMade_Obj.options[SelectionIsMade_Obj.selectedIndex].text = SelectionIsMade_OrigText;
   }
   return;
}

function SelectionIsMade(inObj, isRequired) {
   var ErrMsg = ErrIfSelectionNotMade(inObj);
   if (ErrMsg) {
      if (isRequired) {
         alert(ErrMsg);
         SelectionIsMade_Obj = inObj;
         SelectionIsMade_Flash();
         try{
           inObj.focus();
         }catch(e){
         ;
         }
      }
   }
   return !ErrMsg;
}

function ErrIfSelectionNotMade(inObj) {
   if (inObj.selectedIndex == -1) {
      return 'A Required field has been left blank.';//This field may not be blank.';
   }
   var Value = inObj.options[inObj.selectedIndex].value;
   if ((Value < 0) || (Value == '')) {
      return 'A Required field has been left blank.';//This field requires a selection.';
   }
   return false;
}

function BoxIsRequiredOfGrid(strCriterionName, strName)
{
   var theForm = CleverForm;
   var len = theForm.elements.length;
   for(var i=0 ; i<len ; i++) 
   {
      var e = theForm.elements[i];
      
      
      if (e.name.indexOf(strName) != -1 && document.all(e.name.replace(strName,strCriterionName)).value != "")
      {
         if (BoxIsBlank(e, true))
         {
            return false;
         }
      }
   }
   return true;
}