function pulsateTips (t,n) {
    var tips = $( ".validateTips" );
    tips.html( t ).addClass( "ui-state-highlight" );
    tips.stop(true,true);
    tips.effect("pulsate", { times:n }, 'normal');
   setTimeout(function() {
            tips.removeClass( "ui-state-highlight");
    }, 5000 );
}

function initTips (t) {
    var tips = $( ".validateTips" );
    tips.stop(true,true);
    tips.removeClass( "ui-state-highlight");	
    tips.html( t )
}

function updateTips( t ) {
    var tips = $( ".validateTips" );
    tips.html( t ).addClass( "ui-state-highlight" );
    setTimeout(function() {
            tips.removeClass( "ui-state-highlight", 1500 );
    }, 500 );
}

function showErrors(dialog_id) {
        var dialogPrefix = "#" + dialog_id + "_"
        var test = $(dialogPrefix + "failure li")
         test.each(function(index) {
                 var oid = $(this).attr('id')
                 var o = $(dialogPrefix + oid)
                 o.addClass( "ui-state-error" );
        });
}

function updateClass( baseClass, classToAdd, remove ) {
    var el = $( "." + baseClass );
    if (remove) el.removeClass( classToAdd );
    else el.addClass( classToAdd );    
}

function checkLength( o, n, min, max ) {
        if ( o.val().length > max || o.val().length < min ) {
                o.addClass( "ui-state-error" );
                updateTips( "Length of " + n + " must be between " +
                        min + " and " + max + "." );
                return false;
        } else {
                return true;
        }
}

function checkRegexp( o, regexp, n ) {
        if ( !( regexp.test( o.val() ) ) ) {
                o.addClass( "ui-state-error" );
                updateTips( n );
                return false;
        } else {
                return true;
        }
}

function checkValue( o, n, min, max ) {
        if ( o.val() > max || o.val() < min ) {
                o.addClass( "ui-state-error" );
                updateTips( "Value " + n + " must be between " +
                        min + " and " + max + "." );
                return false;
        } else {
                return true;
        }
}

