﻿//3.0.33#electronicavicente

function AddHint(strInput) {
    window.addEvent('load', function() {
        if ($chk($(strInput))) {
            var strTexto = $(strInput).getProperty('texto');
            if (strTexto == null || strTexto == '') return;
            
            $(strInput).removeProperty('title');
            $(strInput).addEvent('focus', function() {
                ShowHint(strInput);
            }),
		    $(strInput).addEvent('mouseover', function() {
		        ShowHint(strInput);
		    }),
		     $(strInput).addEvent('blur', function() {
		         HideHint(strInput);
		     }),
	        $(strInput).addEvent('mouseout', function() {
	            HideHint(strInput);
	        });
        }
    });
}

function ShowHint(strInput) {
    var newSpan = $('hint' + strInput);
    if (!$chk(newSpan)) newSpan = new Element('span');

    var strTexto = $(strInput).getProperty('texto');
    if (strTexto == null || strTexto == '') return;

    $(document.body).setStyle('cursor', 'help');
    newSpan.setProperty('id', 'hint' + strInput);

    // estilo
    newSpan.setProperty('class', 'texto');
    newSpan.setStyle('background-color', '#ffffe1');
    newSpan.setStyle('padding', '2px');
    newSpan.setStyle('margin', '3px');
    newSpan.setStyle('border', '1px solid #000000');
    newSpan.setStyle('cursor', 'help');
    newSpan.setStyle('max-width', '250px');

    newSpan.setStyle('position', 'absolute');

    newSpan.set('html', strTexto);
    newSpan.inject($(strInput), 'after');

    SetNumHints(strInput, '+1');
}

function HideHint(strInput) {
    var intNumHits = SetNumHints(strInput, '-1');
    if ($chk($('hint' + strInput))) {
        if (intNumHits < 1) {
            $(document.body).removeProperty('style');
            $('hint' + strInput).destroy();
        }
    }
}

function GetNumHints(strInput, intAdd) {
    var intNumHits = Number($(strInput).getProperty('numHits'));

    if (intNumHits > 0) {
        intNumHits += Number(intAdd);
    } else {
        intNumHits = Number(intAdd);
    }
    return intNumHits;
}

function SetNumHints(strInput, intAdd) {
    var intNumHits = GetNumHints(strInput, intAdd);
    $(strInput).setProperty('numHits', intNumHits);
    return intNumHits;
}
