﻿// JScript File
function LimitText(control,e) 
{
  maxLength = control.attributes["maxLength"].value;;

  if(window.event)
      key = window.event.keyCode;     //IE
  else
      key = e.which;     //firefox
      
  //alert(key);
  
  if (key != 8 && key != 9 && key != 45 && key != 46 && 
        key != 37 && key != 38 && key != 39 && key != 40 && key != 0)
  {
    if(control.value.length >= maxLength) {return false;} 
  }                                     
}

// Cancel default behavior
function doBeforePaste(control,e){
    maxLength = control.attributes["maxLength"].value;
     if(maxLength)
     {
          //evnt.returnValue = false;
          if(window.event)
            event.returnValue = false;     //IE
          else
            e.preventDefault();   //firefox  
     }
}

// Cancel default behavior and create a new paste routine
function doPaste(control,e){
    maxLength = control.attributes["maxLength"].value;

    if (!window.event) //For FireFox
    {
        if (control.value.length > maxLength)        
            control.value = control.value.substr(0,maxLength);        
    }
    else //For IE
    {   
        value = control.value;
         if(maxLength){              
              event.returnValue = false;     //IE
              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;
         }
     }
}

