﻿// JScript File
// JScript File for TextArea

// Keep user from entering more than maxLength characters

function doKeypress(control){

    maxLength = control.attributes["maxLength"].value;

    value = control.value;

     if(maxLength && value.length > maxLength-1){

          event.returnValue = false;

          maxLength = parseInt(maxLength);

     }

}

// Cancel default behavior

function doBeforePaste(control){

    maxLength = control.attributes["maxLength"].value;

     if(maxLength)

     {

          event.returnValue = false;

     }

}

// Cancel default behavior and create a new paste routine

function doPaste(control){

    maxLength = control.attributes["maxLength"].value;

    value = control.value;

     if(maxLength){

          event.returnValue = false;

          maxLength = parseInt(maxLength);

          var oTR = control.document.selection.createRange();

          var iInsertLength = maxLength - value.length + oTR.text.length;

          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);

          oTR.text = sData;
     }
}

// This function will set focus to the first element in a form.
function doFocusToFirstElement()
{
     var bFound = false;

  // for each form
  for (f=0; f < document.forms.length; f++)
  {
    // for each element in each form
    for(i=0; i < document.forms[f].length; i++)
    {
      // if it's not a hidden element
      if (document.forms[f][i].type != "hidden")
      {
        // and it's not disabled
        if (document.forms[f][i].disabled != true)
        {
            // set the focus to it
            document.forms[f][i].focus();
            var bFound = true;
        }
      }
      // if found in this element, stop looking
      if (bFound == true)
        break;
    }
    // if found in this form, stop looking
    if (bFound == true)
      break;
  }
}