function getFirstField() {

    var form ;
    var field ;

    for( var formIndex = 0; formIndex < document.forms.length; formIndex++ ) {
        form = document.forms[ formIndex ] ;
       
        for( var fieldIndex = 0; fieldIndex < form.elements.length; fieldIndex++ ) {
            field = form.elements[ fieldIndex ] ;
            
            if( isFocusable( field ) ) {
                return( field ) ;
            }
        }
    }
}

function isFocusable( field ) {
    if( field.disabled == true ) {
        return( false ) ;
    }
    
    if( field.type == 'hidden' ) {
        return( false ) ;
    }
    
    if( field.type == 'button' ) {
        return( false ) ;
    }
    
    if( field.className ) {
        if( field.className.indexOf( "ignoreFocus" ) > 0 ) {
            return( false ) ;
        }
    }
    
    return( true ) ;

}


function focusOn( elementId ) {

    var toFocus ;
   
    if( elementId ) {
        toFocus = document.getElementById( elementId ) ;
    }
    else {
        toFocus = getFirstField() ;
    }
    

    if( toFocus ) {
        toFocus.focus() ;
    }
}