$j(document).ready(function(){
    // Your code here

    $j('#frmLavora').attr("action","/func/lavora-con-noi.php");
    $j('#frmPreventivo').attr("action","/func/preventivo-porte.php");
    $j('#frmStampa').attr("action","/func/press-kit.php");
    $j('#frmContatto').attr("action","/func/richiesta-contatto.php");
    $j('#frmCatalogo').attr("action","/func/catalogo-porte.php");

    $j(".checkbox_prodotto").click(tracciaClick);

    $j("#buttonForm").click(function(){
        var error = false;
        jQuery.each($j("input.required"), function(){
            if ($j(this).attr("type") == "text"){
                if ($j(this).hasClass("email")){
                    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                    if (!filter.test($j(this).attr("value")) || jQuery.trim($j(this).attr("value"))==""){
                        error = true;
                        $j(this).css('background','#ffe5e5');
                        $j(this).css('border-color','#ff5050');
                    }
                    else {
                        $j(this).css('background','#FFFFFF');
                        $j(this).css('border-color','');
                    }
                }
                else {
                    if (!jQuery.trim($j(this).attr("value"))){
                        error = true;
                        $j(this).css('background','#ffe5e5');
                        $j(this).css('border-color','#ff5050');
                    }
                    else {
                        $j(this).css('background','');
                        $j(this).css('border-color','');
                    }
                }
            }
            else if ($j(this).attr("type") == "checkbox"){
                if (!$j(this).attr("checked")){
                    error = true;
                    $j("#chk_"+$j(this).attr("name")).css('background','#ffe5e5');
                }
                else $j("#chk_"+$j(this).attr("name")).css('background','');
            }
            else {
                if (!jQuery.trim($j(this).attr("value"))){
                    error = true;
                    $j("#tr_"+$j(this).attr("name")).css('background','#ffe5e5');
                }
            }
        });
       if (error){
           $j("#error").css('display','');
           return false;
       }
       else return true;
    });
});


tracciaClick = function(){


    if  ($j("#"+$j(this).attr("id")+":checked").val() != null){

        $j(this).unbind("click"); //Traccio solo il primo click

        pageTracker._trackEvent('Informazioni', 'Prodotto', $j(this).attr("id"));

    }



}




