// JavaScript Document
$(document).ready(function() {

    $('.identificati_button').click(function() {
        $('.div_login').show();
        return false;
    });

    $('.chiudi_div').click(function() {
        $('.div_login').hide();
        return false;
    });

    // COMMENTI
    $('.div_login_comm').hide();	// Nascondo il box di login
    $('.box-commento').hide();		// Nascondo il box di invio commento
    $('#feed-sent').hide();


    $('.comm_login_button').click(function() {
        $('.div_login_comm').show();
        $(this).hide();
        return false;
    });

    $('.chiudi_div_comm').click(function() {
        $('.div_login_comm').hide();
        $('.comm_login_button').show();
        return false;
    });

    $('#sendCommento').click(function() {
        sendAjax("/fe/ajaxRequest/commenta.php","","","5000","","formCommento","","","0");
        $('#form-commento').hide();
        $('#feed-sent').show();
    });
    // /COMMENTI

//    // VOTAZIONE
//    $('.sendVotazione').click(function() {
//
//        $('.star-rating').hide();
//        $('#vota-anche-tu').hide();
//
//        $.ajax({
//          url: "/ajaxRequest/vota.php",
//          type: "POST",
//          timeout: 5000,
//          data: $('#formVotazione').serialize(),
//          cache: false,
//          success: function(data){
//            $("#Results").html(data);
//          },
//          error: function(){
//            $('.star-rating').show();
//            $('#vota-anche-tu').show();
//          }
//        });
//
//    });
//    // VOTAZIONE


    $("#sendAuth").click(function () {
        sendAjax("/fe/ajaxRequest/login.php","","json","5000","","formAuth","showLoginInfo(result)","","0");
    });
 
    $("#logout").click(function () {
        sendAjax("/fe/ajaxRequest/logout.php","","json","5000","","formAuth","showLogoutInfo(result)","","0");
    });
 /*
    $("#sendAuth2").click(function () {
        sendAjax("/fe/ajaxRequest/login.php","","json","5000","","formAuth2","showLoginInfo(result)","","0");
        return false;
    });
    
    $("#sendAuth3").click(function () {
        sendAjax("/fe/ajaxRequest/login.php","","json","5000","","formAuth3","showLoginInfo(result)","","0");
        return false;
    });*/
 
});

//function ShowRateResults(result)
//{
//    if(result.esito==true)
//    {
//        $('#Results').html("pipp");
//        //document.location.replace(result.from);
//    }
//    else
//    {
//
//    }
//}
/*
function showLoginInfo(result)
{
    if(result.esito==true)
    {
        alert('Login effettuato!');
        //document.location.href='/'+result.from;
        window.location.reload();
        
        //document.location.replace('/'+result.from)
    //$('#boxAuth').html('Benvenuto <b> '+result.USERNAME+' </b> | <span id="logout" style="cursor:pointer;" onclick="logout()" >Logout</span>');
    }
    else
    {
        var errori = 'Login Fallito!\n';
        if(result.errors.length > 0)
        {
            for(i=0;i<result.errors.length;i++)
                errori = errori+result.errors[i]+'\n';
        }
        alert(errori);
    }
}*/

function login()
{
    sendAjax("/fe/ajaxRequest/login.php","","json","5000","","formAuth","showLoginInfo(result)","","0");
}

function logout()
{
    sendAjax("/fe/ajaxRequest/logout.php","","json","5000","","formAuth","showLogoutInfo(result)","","0");
}

function showLogoutInfo(result)
{
    if(result.esito==true)
    {
        alert('Logout effettuato!');
        /*var txt = '<form name="formAuth" id="formAuth" method="post" style="margin:0px;padding:0px;">'+
               '<table cellpadding="0" cellspacing="0" border="0">'+
               '<tr>'+
               '<td valign="top"><input type="text" name="user" id="user" accesskey="n" class="form" value="login"  style="margin-right:5px;">'+
               '<input type="password" name="passw" id="passw" accesskey="e" class="form" value="password"></td>'+
               '<td> &nbsp;'+
               '<input id="sendAuth" name="sendAuth" type="button" style="background:url(css/entity/entra.png); width:45px; height:20px; margin:0px; border:0px;" value="" alt="entra" onclick="login()"></td>'+
               '</td></tr><tr><td colspan="2"><span class="white_txt">Non sei registrato?</span> <a href="registrati.php">Clicca qui!</a></td></tr>'+
               '</table>'+
               '</form>';
        $('#boxAuth').html(txt);*/
        window.location.reload();
    }
}
