var timeoutTips = 5000;

function updateTips( t ) {
    tips = $( ".validateTips" );
    tips
    .text( t )
    .addClass( "ui-state-highlight" );

    setTimeout(function() {
        tips.text('');
        tips.removeClass( "ui-state-highlight", 0 );    
    }, timeoutTips  );
}

function clearTips() {
    tips = $( ".validateTips" );
    tips
    .text('')
    .removeClass( "ui-state-highlight" );        
}

function checkLength( o, n, min, max ) {

    o = $("#"+o);
    
    if ( o.val().length > max || o.val().length < min ) {

        o.addClass( "ui-state-error" );
        updateTips( "Comprimento de " + n + " deve estar entre " +
            min + " e " + max + " caracteres." );

        return false;
    } else {
        o.removeClass( "ui-state-error" );
        return true;
    }
}

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

/**
 * Calcula diferença entre duas data, 
 * formato de entrada
 * dd/mm/yyyy
 */
function calcDateDiff(date1, date2){
    date1 = date1.split("/");
    date2 = date2.split("/");
    var sDate = new Date(date1[1]+"/"+date1[0]+"/"+date1[2]);
    var eDate = new Date(date2[1]+"/"+date2[0]+"/"+date2[2]);
    var DiasApart = Math.abs(Math.round((sDate-eDate)/86400000));
    return DiasApart;
}
