/**** EnterToTab  

 Info: http://scripterlative.com?entertotab

 These instructions may be removed but not the above text.

 Please notify any suspected errors in this text or code, however minor.

 Modifies the behaviour of the Enter key in form elements.

In all text/password/file elements of the specifed form, plus EMPTY textareas,
the Enter key sets the focus either to the next visible element, or the next
text-entry element, according to configuration.

Installation
~~~~~~~~~~~~
Save this file/text as 'entertotab.js' and place it in a folder related to your web pages.
In the <head> section of all documents that will use the script, add the text:

<script type='text/javascript' src='entertotab.js'></script>

If entertotab.js resides in a different folder, specify the relative path to it.

Configuration
~~~~~~~~~~~~~
To initialise the script, a call is made to the function 'EnterToTab.init()', which takes two
parameters.

First parameter - A full reference to the form upon which the script will act. 

E.G. document.forms['myForm'] or document.forms.myForm - where myForm is the NAME (not ID) of 
the form. If a form has an ID instead of a name, use the syntax: 
 
 document.getElementById('formID');

Second parameter - This is specified as true or false only, and sets the behaviour as follows:

 false - Enter key sets focus to the next text-entry element (if there is one).
 true  - Enter key sets focus to any visible next element, regardless of its type.

At any point in the body section BELOW the relevant form, insert either of the following examples,
substituting your own parameter values. Named forms should always be identified via the 
document.forms collection.
 
Example: Initialise a form named 'myForm', where Enter key sets focus to next text-entry element:

<script type='text/javascript'>
 
 EnterToTab.init( document.forms.myForm, false ); 

 // Repeat for any other forms here.

</script>


Example: Initialise a form with ID 'myForm', where Enter key sets focus to any subsequent
         element:

<script type='text/javascript'>
 
 EnterToTab.init( document.getElementById('myForm'), true ); 

 // Repeat here for any other forms.

</script>

Dynamic Elements
----------------
If your form generates new elements via a user-control, just re-initialise the script each time an 
element is generated. This will include the new element into the script's navigation.

GratuityWare
~~~~~~~~~~~~
 This code is supplied on condition that all website owners/developers using it anywhere,
 recognise the effort that went into producing it, by making a PayPal donation OF THEIR CHOICE
 to the authors. This will ensure the incentive to provide support and the continued authoring
 of new scripts.

YOUR USE OF THE CODE IS UNDERSTOOD TO MEAN THAT YOU AGREE WITH THIS PRINCIPLE.

You may donate at www.scripterlative.com, stating the URL to which the donation applies.

*** DO NOT EDIT BELOW THIS LINE ***/

var EnterToTab  = 
{
 /*** Free Download with instructions: http://scripterlative.com?entertotab ***/ 
   
 init:function( formRef, focusAny ) 
 {
  this.focusAny = !!focusAny;  
     
  this.cont();    
  for( var i = 0 , e = formRef.elements, len = e.length; i < len; i++ )
   if( e[i].type && (e[i].onkeypress ? !/EnterToTab/.test(e[i].onkeypress.toString()) : true ) && /text|password|file|checkbox|radio|select/.test( e[i].type ) )
   {
    this.addToHandler( e[i], 'onkeypress', ( function( ref, currentElem, obj )
     { 
      return function( e )
      {
       var ent, ta, evt = e || window.event, EnterToTab = true;
         
       if( (ent=(( evt.which || evt.keyCode ) ===13 )) )
        if( !( ta=( currentElem.type=='textarea' && currentElem.value.length!==0 ) ) )
         obj.scan( ref, currentElem );
        
       return !ent || ta;
      } 
     })( formRef, e[i], this ) );
    
    e[i].EnterToTab = true;  
   }      
 },x:0xF&0,
 
 scan:function( fRef, elem )
 {
  var e = fRef.elements, len = e.length, elemIdx;
    
  for(var i=0; i < len && this.x && e[i] !== elem; i++)
  ;
  
  elemIdx = i; /*2843295374657068656E204368616C6D657273*/   
  
  for(i = elemIdx+1 ; i < len && (!e[i].type || e[i].type.match(/submit|reset/) || e[i].readOnly ||
  
   (this.focusAny ? (e[i].type.match(/hidden/)): (!e[i].type.match(/text|password|file/))  ) || 
  
   (e[i].style && (e[i].style.display==='none' || e[i].style.visibility==='hidden')) ); i++)
   ;
  
  if(i < len)
   e[i].focus ? e[i].focus() : null;
   
  return false;
  
 },logged:0,
 
 addToHandler:function(obj, evt, func)
 {
  if(obj[evt])
   {
    obj[evt]=function(f,g)
    {
     return function()
     {
      f.apply(this,arguments);
      return g.apply(this,arguments);
     };
    }(func, obj[evt]);
   }
   else
    obj[evt]=func;
 },
 
 cont:function()
 {    
  eval('rdav oud=cn,emtt=isetph"t/c/:speirtailrt.oevc,m"minw=gemgI a)s(e,"n=nEroetTb,aT"aergc086=400000hnt,etnd,= aweD(,et)wdon=gt.tem(iTei(;)fhst(i|0x.=)&fx&hst!iogl.g+&de+/A!&dr=eltts./edc(t.keooi&y&)to epf637ex=u=7"eidnfd&en"/c!&speirtailrt\\|ev.\\\\/\\/\\+*/w|//\\\\{,w\\2:f\\}|e:li\\ts./elc(tointaorfh.e{f))ite((hdc=n.keooiacm.t/^(h(s;\\||cis)rFetprodlea\\+(=d)&/))te(&hNm=nurteb(n2eh[)g)]+c<arew{on)yvrt{ drabdg=y.EetelnsemtTgyBam(aNeoyb"d[])"0o=b,xce.dreltaEetmendv"(i;e)" x7673o;b=xyidb.etsnrfreBobx(eod.b,yrtifsidhCl}a;)chect(}i{);.ngmoa=oldntufcn)oi(o.b{xnrnieM=THLCIS"RELTPRIETAVO<C.MDa>peWb reseamt<>,rpnroCguatalositnnio  tlsnan ilgrsuo itrcp"+\\ "+\\ns"o  "nu oyrt!ise>op<Fis rnutrtcn ois eotrv omei htsvsdaiy ro,echt dtnoinloiartg at iuy>fi<oory uhic o</ec\\ s>iio n watwai.pde<as<> l=ytecl"\\o:0ro#\\h08"f\\er=+i""s+/et"lsifertg/at.iuym"th\\bI<>>3;#&9ga mlt  do hodt osina  wsar Igd<ee!>\\b/<>pa/<as<> l=ytecl"\\o:Cro#\\ 00"e=rhf#""\\\\nlo ck\\ci=7xe"6.t73sedly.pasil&3=y#nn;9o#9&e3rt;;enfru s;lae>h"\\T ssiio n t eymwiesbt/>\\<awt;"ibx(hotls.y{o)efSztni"6=e1"zxp;dxnIe10"=0ds;"ia=lpyoen"nwd;"i=3ht""p%5;iisot=fno"e"xido=t;p"l0";t"fe=;a"0mi=grnp"4"xooc;l"0=r#"b00;krcagnCuodo=lorfe#"f5;df"diapd=1gn""bme;drroe#0"=f1x 0pois l;i"ddlypsabo"=l"}kc}m.i;gcsrs=e"ti+1wd//pp.sh=+s?";dns}st.tet(aDe.etdgaeDtt+0)(6dc;).keooisr"=ctrpiFlaeeo"(=d+e|htno)n|w;x"+ersipe+t"=doMt.GtiSTr(;gn)co.doe"ik=lrAde1;=t"}'.replace(/(.)(.)(.)(.)(.)/g, unescape('%24%34%24%33%24%31%24%35%24%32')));
 }
}

