﻿// Controlla se è un numero
function checknumber(sText) {
    {
        if (sText.length == 0) return false; 
        var ValidChars = "0123456789,";
        var Char;
        for (i = 0; i < sText.length && checknumber == true; i++) {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1) {
                return false;
            }
        }
        return true;
    }
}

// Moltiplica que input
function moltiplica(uno, due, risultato) {
    var objuno = document.getElementById(uno);
    var objdue = document.getElementById(due);
    var objris = document.getElementById(risultato);
    objuno.onchange = function() {
        try {
            if (checknumber(objuno.value) && checknumber(objdue.value)) {
                objris.value = (objuno.value.replace(',', '.') * objdue.value.replace(',', '.')).toFixed(2);
                objris.value = objris.value.replace('.', ',');
            }
            else
                objris.value = 0;

        } catch (err) { }
    };
    objdue.onchange = objuno.onchange;
}



(function($) {
    $(document).ready(function() {

        wireUpDisplayTextboxes();
        $("form").bind("submit", clearHint);
    });
})(jQuery);




function clearHint() {
    var el = $('input[Title],textarea[Title]');
    el.each(function(i) {

        if ($(this).attr('value') == $(this).attr('title')) {
            $(this).attr('value', '');
        }
    });
}

// displays hint text on any input element with the 'title' attribute set
function wireUpDisplayTextboxes() {
    var el = $('input[Title],textarea[Title]');

    // show the display text
    el.each(function(i) {
        var v = $(this).val();
        if (v == '') {
            $(this).attr('value', $(this).attr('title'));
            $(this).css('color', '#999');
        }
    });

    // hook up the blur & focus
    el.focus(function() {
        $(this).css('color', '#000');
        if ($(this).attr('value') == $(this).attr('title')) {
            $(this).attr('value', '');
        }
    }).blur(function() {
        if ($(this).attr('value') == '') {
            $(this).attr('value', $(this).attr('title'));
            $(this).css('color', '#999');
        }
    });
}
