/* config */
/* NOTE: in html, there is a 'rel' in a trigger, and 
    the id of corresponding tip box must be 'tip_'+ the id of trigger. */
var TIP_CSS = 'form_tips';
var FORM_ID = 'myForm';
var REL_NAME = 'ztip';

/* funcs; Required: mootools.js */
function hide_all_tips() {
    $('.' + TIP_CSS).each(function(i) { 
        this.style.display = 'none' } );
}

function reset_ul_css() {
    $('#' + FORM_ID + ' > ul').each(function(i) {
        this.className = this.CLASS_NAME_OLD;
    });
}

function focus_form_selected() {
/*
    $('#' + FORM_ID + ' > ul').each(function(i) {
        this.CLASS_NAME_OLD = this.className;
        $(this).bind('click', function() {
            reset_ul_css();
            this.className = 'ul_current';
        });
    });
*/
    
    $('li > :input[rel=' + REL_NAME +']').each(function(i) {
        $(this).bind('focus', function() {
            hide_all_tips();
            var tip_box = $('#tip_' + this.id);
            if (tip_box && tip_box.text()) {
                
                // for jQuery validate
                var error_tip_box = $(".verror[for='" + this.id + "']");
                if (error_tip_box) error_tip_box.hide();
                
                error_tip_box = $(".form_tips_erro[for='" + this.id + "']");
                if (error_tip_box) error_tip_box.hide();
                
                // Firefox 3.5
                error_tip_box = $(".form_tips_erro[htmlfor='" + this.id + "']");
                if (error_tip_box) error_tip_box.hide();
                
                tip_box.css( 'display', 'block' );
            }
        } );
        $(this).bind('blur', function() { 
            var tip_box = $('#tip_' + this.id);
            if(tip_box) tip_box.css( 'display', 'none' );
        } );
    });
}
