var nextFocus = true;
var frm = null;
var compIndex = -1;

function getForm( comp ){
	for ( i = 0; i < document.forms.length; i++ ){
    	for ( i2 = 0; i2 < document.forms[i].elements.length; i2++ ){
       		if ( comp.name == document.forms[i].elements[i2].name ){
          		frm = document.forms[i];
          		compIndex = i2;
          		return;
        	}
      	}
	}
}

function gotoNextFocus( source, maxLength ){
	getForm( source );
	if (( !nextFocus ) || ( frm == null ) || ( compIndex == -1 ) ){
		return;
  	}

	var ix = compIndex + 1;

	var size = source.value.length;
	var canFocus = false;

	while ( !canFocus ) {
		if ( ( frm.elements[ix].type == "hidden" ) && ( ix < frm.elements.length )){
			ix++;
	  	} else {
	  		canFocus = true;
	  	}
	}

	if ( (canFocus) && ( size == maxLength ) ){
	 	frm.elements[ix].focus();
		frm.elements[ix].select();
	}
}

function offNextFocus(){
	nextFocus = false;
}

function onNextFocus(){
	nextFocus = true;
}

