﻿// ---------------   LOGIN BOX ---------------------  //
function loginBox(show){
    if(show){
        $('#hp_header_links').hide();
        $('#hp_header_login').fadeIn('fast');
    } else {
        $('#hp_header_login').hide();
        $('#hp_header_links').fadeIn('fast');    
    } //if 
    
}//end

function searchBox(show){
    if(show){
        $('#hp_header_links').hide();
        $('#hp_header_search').fadeIn('fast');
    } else {
        $('#hp_header_search').hide();
        $('#hp_header_links').fadeIn('fast');    
    } //if 
    
}//end



function rememberMe(){
    $('#remember').val('0');
    if($('#chkRemember').attr('checked')){
        $('#remember').val('1');
    }
}//end


// ---------------   UPLOAD VIDEO - SALVATAGGIO ---------------------  //

function UploadUpdate(){
    //var
    var actError = 0;
    
    var msgError = '';
    var rxPrice = /\d+/;
    var rxYear = /(19|20)\d{2}/;
	
    if($('#wdVideoOrigin1').length==0)
    actError=1;
    
    if(actError==1){
        msgError = '<ul>' + msgError + '</ul>';         
        $('#msgErrorTitle').html(msgError);
        $('#msgErrorText').html('Devi selezionare un video da caricare');
        $('#btnClose').show();
        $('#btnHome').hide();
		$('#saveERROR').modal({
						close:false,
						closeHTML:false,
						escClose:false
						});

    } else {   
        var obj = {}
        
        // VIDEO //
         if($('#wdVideoOrigin1').length>0){
            obj.wdVideoFull1 = $('#wdVideoFull1').val();
            obj.wdVideoThumb1 = $('#wdVideoThumb1').val();
            obj.wdVideoOrigin1 = $('#wdVideoOrigin1').val();
        }

        
        $.getJSON(
          '/web/post/UploadUpdate.aspx?output=JSON',
          obj,
          function(data) {
            if(data.Table[0].actSave==='1'){
                var okTitle =   '';
                var okText =    'Il video e\' stato inviato correttamente!';
                $('#msgOkTitle').html(okTitle);
                $('#msgOkText').html(okText);
                $('#btnClose').show();
                $('#btnHome').show();
                $('#saveOK').modal({
    				close:false,
    				closeHTML:false,
    				escClose:false
    				});
    		} else {
                var errTitle =  '';
                var errText =   'Si e\' verificato un errore durante il salvataggio';
                $('#msgErrorTitle').html(errTitle);
                $('#msgErrorText').html(errText);
                $('#btnClose').show();
                $('#btnHome').show();
				$('#saveERROR').modal({
								close:false,
								closeHTML:false,
								escClose:false
								});
           }
         }
        )
    } //if
}//end

// ---------------   APERTURA  PROFILO ---------------------  //

function userOpen(){
	
	var tsr = Math.random();
	
	//recupero informazioni di registrazione utente collegato
	$.getJSON(
		'/web/get/userSelect.aspx?output=JSON&tsr='+tsr.toString(),
		function(data) {
			if(data.Table[0]){
                /*  STEP 1 */
                $('#tbFirstName').val(data.Table[0].usrName);
				$('#tbLastName').val(data.Table[0].usrSurname);
                $('#tbBornDate').datepicker( "setDate" , data.Table[0].usrBornDate.substr(0,2) + '-' + data.Table[0].usrBornDate.substr(3,2)+'-'+ data.Table[0].usrBornDate.substr(6,4))

                if(data.Table[0].usrSexGender='M')
                    $('#tbSexGenderM').attr('checked', true); 
                if(data.Table[0].usrSexGender='F')
                    $('#tbSexGenderF').attr('checked', true); 
                //$('input:radio[name=\'tbSexGender\']').filter('\'[value='+ data.Table[0].usrSexGender +']\'').attr('checked', true); 
                
                $('#tbNickname').val(data.Table[0].usrNickname);
                $('#tbNickname').attr("disabled", true);                
                $('#tbEmail').val(data.Table[0].usrEmail);
                $('#tbPassword1').val(data.Table[0].usrPassword);
                $('#tbPassword2').val(data.Table[0].usrPassword);
                $('#tbCity').val(data.Table[0].usrCity);
                $('#ddlProv').val(data.Table[0].usrProvId);
                
                if(data.Table[0].usrPrivacyAccepted='1')
                    $('#chkPrivacy').attr('checked', true);

                /*  STEP 2 */
                $('#tbPhone').val(data.Table[0].usrPhone);
                $('#tbMobile').val(data.Table[0].usrMobile);
                $('#tbDanceStyle').val(data.Table[0].usrDanceStyle);
                $('#tbMusicStyle').val(data.Table[0].usrMusicStyle);
                $('#tbHowLongDance').val(data.Table[0].usrHowLongDancing);

                if(data.Table[0].usrDancingLessons='1')
                    $('#rbDancingLessonY').attr('checked', true); 
                if(data.Table[0].usrDancingLessons='0')
                    $('#rbDancingLessonN').attr('checked', true); 

                $('#tbDancingReason').val(data.Table[0].usrDancingReason);
                $('#tbHobby').val(data.Table[0].usrHobbies);
                $('#ddlSuperdancer').val(data.Table[0].usrDancer);
                $('#tbSuperDancerReason').val(data.Table[0].usrDancerReason);
                $('#tbMovieTitle').val(data.Table[0].usrMovieTitle);
                $('#tbTVShow').val(data.Table[0].usrTVShow);
                $('#tbWearBrand').val(data.Table[0].usrWearingBrand);
                $('#ddlVideoGame').val(data.Table[0].usrVideogame);
                $('#tbPersonalDescription').val(data.Table[0].usrPersonalNotes);

                $('#tbFacebook').val(data.Table[0].usrFacebookLink);
                $('#tbNetlog').val(data.Table[0].usrNetlogLink);
        
                /*  STEP 3 */
                $('input:radio[name=\'rbAvatarId\']').filter('\'[value='+ data.Table[0].usrAvatarId +']\'').attr('checked', true); 
                
			}
		}
	)

}//end


// ---------------   REGISTRAZIONE PROFILO ---------------------  //

function userSave(){
    //var
    
	var tsr = Math.random();
	var dataf = $.datepicker.formatDate('yy-mm-dd',$('#tbBornDate').datepicker('getDate'));
	var datatoday = $.datepicker.formatDate('yy-mm-dd',new Date());

    var actError = 0;

    var msgError = '';
    //var rxMail = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
    var rxMail = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
    /*var rxBornDate = /^(19|20)\d{2}-(0|1)\d-[0|1|2|3]\d$/;*/
    var rxBornDate = /^(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[012])-(19|20)\d{2}$/;
	
    // actForm
    //$('#actSave').val('0');
    //$('#actError').val('0');
    
    // Controllo campi obbligatori //
    if($('#tbFirstName').val()==''){
        msgError += '<li>Il campo NOME &egrave; obbligatorio</li>';
        actError = 1;
    }//if
    
    if($('#tbLastName').val()==''){
        msgError += '<li>Il campo COGNOME &egrave; obbligatorio</li>';
        actError = 1;
    }//if

    if($('#tbBornDate').val()==''){
		msgError += '<li>L\' ANNO DI NASCITA &egrave; vuoto</li>';
		actError = 1;	
	}

	if ( dataf === datatoday || $('#tbBornDate').val().match(rxBornDate) == null) {
		msgError += '<li>La DATA DI NASCITA inserita non &egrave; corretta</li>';
		actError = 1;
	}

	/*if ($('#tbBornDate').val().charAt(2) != '-' || $('#tbBornDate').val().charAt(5) != '-' ) {
		msgError += '<li>L\' <b>ANNO DI NASCITA</b> inserito non &egrave; corretto</li>';
		actError = 1;
	}
	else
	if ($('#tbBornDate').val().match(rxBornDate) == null || $('#tbBornDate').length > 10) {
		msgError += '<li>L\' ANNO DI NASCITA inserito non &egrave; corretto</li>';
		actError = 1;
	}
	}*/

    if($('input[name=\'tbSexGender\']:checked').val()==''){
        msgError += '<li>Il campo SESSO &egrave; obbligatorio</li>';
        actError = 1;
    }//if

    if($('#tbNickname').val()==''){
        msgError += '<li>Il campo NICKNAME &egrave; obbligatorio</li>';
        actError = 1;
    }//if

    if($('#tbEmail').val()==''){
        msgError += '<li>Il campo E-MAIL &egrave; obbligatorio</li>';
        $('#actError').val('1');
	}else{
		if(!$('#tbEmail').val().match(rxMail)){
			msgError += '<li>L\'indirizzo E-MAIL inserito non &egrave; valido</li>';
			actError = 1;
		}
    }//if

    if($('#tbPassword1').val()==''){
        msgError += '<li>Inserire il campo PASSWORD</li>';
        $('#actError').val('1');
    } else {
        if($('#tbPassword1').val() != $('#tbPassword2').val()){
                msgError += '<li>Le due PASSWORD non coincidono</li>';
                $('#actError').val('1');
        }//if
        if($('#tbPassword1').val().length <6 ){
                msgError += '<li>La PASSWORD deve essere di almeno 6 caratteri</li>';
                actError = 1;
        }//if
	}//if

    if($('#ddlProv').val()==''){
        msgError += '<li>Il campo PROVINCIA &egrave; obbligatorio</li>';
        actError = 1;
    }//if

    /*
    if($('#chkDisclaimer:checked').val()!='1'){
        msgError += '<li>Necessario dare il consenso alla lettera di malleva</li>';
        actError = 1;
    }//if
    */
    
    if($('#chkPrivacy:checked').val()!='1'){
        msgError += '<li>Necessario dare il consenso alla legge sulla privacy</li>';
        actError = 1;
    }//if

    /*
    if($('input[name=\'rbLegge696\']:checked').val()==''){
        msgError += '<li>Necessario dare il consenso alla legge 696</li>';
        actError = 1;
    }//if
    */


    if(actError==1){
        msgError = '<ul>' + msgError + '</ul>';         
        $('#msgErrorTitle').html('Sono state riscontrate delle imperfezioni nella compilazione<BR/>Ricontrolla i dati e riprova!');
        $('#msgErrorText').html(msgError);
        $('#btnClose').show();
        $('#btnHome').hide();
        $('#btnRememberPassword').hide();
		$('#saveERROR').modal({
						close:false,
						closeHTML:false,
						escClose:false
						});
    } else {   
        var obj = {}

        /*  STEP 1 */
        obj.usrname = $('#tbFirstName').val();
        obj.usrsurname = $('#tbLastName').val();
        //obj.usrborndate = $('#tbBornDate').val().substr(6,4) + '-' + $('#tbBornDate').val().substr(3,2) + '-' + $('#tbBornDate').val().substr(0,2);
		obj.usrborndate = dataf;
        obj.usrsexgender = $('input[name=\'tbSexGender\']:checked').val();
        obj.usrnickname = $('#tbNickname').val();
        obj.usremail = $('#tbEmail').val();
        obj.usrpassword = $('#tbPassword1').val();
        obj.usrcity = $('#tbCity').val();
        obj.usrprovId = $('#ddlProv').val();
        obj.usrphone = $('#tbPhone').val();
        obj.usrmobile = $('#tbMobile').val();
        obj.usrprivacy = $('#chkPrivacy').val();


        /*  STEP 2 */
        obj.usrdancestyle = $('#tbDanceStyle').val();
        obj.usrmusicstyle = $('#tbMusicStyle').val();
        obj.usrhowlongdance = $('#tbHowLongDance').val();
        if($('input[name=\'rbDancingLesson\']:checked').size() > 0){
            obj.usrdancinglesson = $('input[name=\'rbDancingLesson\']:checked').val()
        }
        obj.usrdancingreason = $('#tbDancingReason').val();
        obj.usrhobby = $('#tbHobby').val();
		if($('#ddlSuperdancer').val()!=null)
			obj.usrsuperdancer = $('#ddlSuperdancer').val();
        obj.usrsuperdancerreason = $('#tbSuperDancerReason').val();
        obj.usrmovietitle = $('#tbMovieTitle').val();
        obj.usrtvshow = $('#tbTVShow').val();
        obj.usrwearbrand = $('#tbWearBrand').val();
		if($('#ddlVideoGame').val()!=null)
			obj.usrvideogame = $('#ddlVideoGame').val();
        obj.usrnotes = $('#tbPersonalDescription').val();
        obj.usrfacebook = $('#tbFacebook').val();
        obj.usrnetlog = $('#tbNetlog').val();


        /*  STEP 3 */
        if($('#tbAvatarFull1').size()>0){
            obj.usravatarcustom = '1';
            obj.usravatarimageorigin = $('#tbAvatarOrigin1').val();
            obj.usravatarimagefull= $('#tbAvatarFull1').val();
            obj.usravatarimagethumb = $('#tbAvatarThumb1').val();
        } else{
            obj.usravatarcustom = '0';
            if($('input[name=\'rbAvatarId\']:checked').size() > 0){
                obj.usravatarid = $('input[name=\'rbAvatarId\']:checked').val();
            }//if
        } //if


        /*  STEP 4 */
        /*        
        obj.usrdisclaimer = $('#chkDisclaimer').val();
        obj.usrlegge696 = $('input[name=\'rbLegge696\']:checked').val();
        */
        
        $.getJSON(
          '/web/post/userUpdate.aspx?output=JSON&tsr='+tsr.toString(),
          obj,
          function(data) {
            if(data.Table[0].errorNumber=='0')
                $('#saveOK').modal({
    				close:false,
    				closeHTML:false,
    				escClose:false
    				});
            else {
                $('#msgErrorTitle').text('Dati non corretti !');
                if(data.Table[0].errorSeverity=='14'){
                    $('#msgErrorText').html('Il <b>nickname</b> &egrave gi&agrave; utilizzato da un altro utente.<BR/>Cambiali oppure clicca il pulsante "Recupera password"');
                    $('#btnRememberPassword').show();
                    $('#btnClose').show();
                }else if(data.Table[0].errorNumber=='50000'){
                    $('#msgErrorText').html(data.Table[0].errorMessage);
                    $('#btnClose').show();
                    $('#btnHome').show();                
                } else {
                    $('#msgErrorText').html('Non &egrave; stato possibile completare la registrazione a causa di un errore.<BR/>Riprova pi tardi !');
                    $('#btnClose').show();
                    $('#btnHome').show();
                }
    			$('#saveERROR').modal({
    							close:false,
    							closeHTML:false,
    							escClose:false
    							});

             }//if
          }//function       
        )
    } //if
 } //end

// ---------------   REGISTRAZIONE UTENTI ---------------------  //

function subscriptionTVShow(){
    //var
    
    var actError = 0;
    var msgError = '';
	
    
    // Controllo campi obbligatori //
    if($('#tbHowLongDance').val()==''){
        msgError += '<li>Il campo <b>Da quanto tempo balli?</b> &egrave; obbligatorio</li>';
        actError = 1;
    }//if
    
    if($('input[name=\'rbDancingLesson\']:checked').val()==''){
        msgError += '<li>Il campo <b>Frequenti un corso di ballo?</b> &egrave; obbligatorio</li>';
        actError = 1;
    }//if
    
    if($('#tbDancingReason').val()==''){
        msgError += '<li>Il campo <b>Com\'e\' nata la tua passione per la danza?</b> &egrave; obbligatorio</li>';
        actError = 1;
    }//if

    if($('#tbHobby').val()==''){
        msgError += '<li>Il campo <b>Quali sono i tuoi hobbies?</b> &egrave; obbligatorio</li>';
        actError = 1;
    }//if

    if($('#ddlSuperDancer').val()==''){
        msgError += '<li>Il campo <b>Il tuo superdancer preferito?</b> &egrave; obbbligatorio</li>';
        actError = 1;
    }//if

    if($('#tbSuperDancerReason').val()==''){
        msgError += '<li>Il campo <b>Il tuo superdancer preferito - Perch ?</b> &egrave; obbligatorio</li>';
        actError = 1;
    }//if
    
    if($('#tbPhone').val()==''){
        msgError += '<li>Il campo <b>Telefono</b> &egrave; obbligatorio</li>';
        actError = 1;
    }//if


    if(actError==1){
        msgError = 'Per poter partecipare alla trasmissione devi compilare correttamente alcune informazioni:<BR/><BR/>' + 
                    '<ul>' + msgError + '</ul>';         
        $('#msgErrorTitle').html('Mancano alcune informazioni');
        $('#msgErrorText').html(msgError);
        $('#btnClose').show();
        $('#btnHome').hide();
        $('#btnRememberPassword').hide();
		$('#saveERROR').modal({
						close:false,
						closeHTML:false,
						escClose:false
						});

    } else {   
        var obj = {}

        obj.usrhowlongdance = $('#tbHowLongDance').val();
        if($('input[name=\'rbDancingLesson\']:checked').size() > 0){
            obj.usrdancinglesson = $('input[name=\'rbDancingLesson\']:checked').val()
        }
        obj.usrdancingreason = $('#tbDancingReason').val();
        obj.usrhobby = $('#tbHobby').val();
        obj.usrsuperdancer = $('#ddlSuperdancer').val();
        obj.usrsuperdancerreason = $('#tbSuperDancerReason').val();
        obj.usrphone = $('#tbPhone').val();

        $.getJSON(
          '/web/post/userTVShow.aspx?output=JSON',
          obj,
          function(data) {
            if(data.Table[0].errorNumber=='0'){
                    $('#actionOK_title').text('Richiesta inoltrata correttamente');
                    $('#actionOK_title').text('La tua richiesta &egrave; stata inviata alla redazione di Wannadance.<BR/>'+
                                              'A breve sarai richiamato al numero di telefono che ci hai fornito.<BR/>' +
                                              'Grazie !');

                    $('#actionOK').modal({
        				close:false,
        				closeHTML:false,
        				escClose:false
    				});
            }else{
                    $('#msgErrorTitle').text('Richiesta gi inoltrata !');
                    $('#msgErrorText').text('Hai gi inviato una richiesta di partecipazione alla redazione di Wannadance.<BR/>'+
                                            'Se non lo abbiamo gi&agrave; fatto, a breve sarai richiamato al numero di telefono indicato');
                    $('#btnClose').show();
                    $('#btnHome').hide();

    				$('#saveERROR').modal({
								close:false,
								closeHTML:false,
								escClose:false
					 });
                }//if
            }//function       
        )
    } //if
 } //end


// ---------------   ATTIVAZIONE UTENZE ---------------------  //
function userActivation(hash){
    var msg;
    var obj = {};
    obj.hash = hash;
    
    $.getJSON(
      '/web/post/userActivation.aspx?output=JSON',
      obj,
      function(data) {
        	 if(data.Table[0].errorNumber=='0')
                msg = 'Grazie ' + data.Table[0].usrName + ' ' + data.Table[0].usrSurname + ' !<BR/>' + 
                      'L\'attivazione della tua utenta con nickname <b>' + data.Table[0].usrNickname + '</b> &egrave; avvenuta con successo.'; 
        	else
                msg = 'Siamo spiacenti...<BR/>' + 
                      'L\'attivazione della tua utenta con codice <b>' + hash + '</b> non &egrave; andata a buon fine<BR/>' + 
                      'a causa del seguente errore:<BR/><BR/><I>' + data.Table[0].errorMessage; + '</I>'                       
        	   
        	   $('#profile_content_open_text').html(msg)
       	   }
    )
}//end


// ---------------   FLOATING DIALOG -------------------  //

function initDialog(){
    $('#dialog').dialog({
                        autoOpen: false,
                        minWidth: 150,
                        minHidth: 50,
                        width: 250,
                        height: 180,
                        title: 'Cosa desideri fare ?',
                        show: 'highlight',
                        hide: 'highlight',
                        position: ['center','center'],
                        modal: true,
                        buttons: { "Chiudi": function() { $(this).dialog("close"); } }
    });                      
}//end

function showDialog(e, elementID, usrId, usrName, usrProfile){
    $('#dialog').html('');
    $.getJSON("/web/get/BlacklistCheck.aspx?usrId=" + usrId + "&output=JSON&r="+ Math.random(),
                function(data) {
					var to = 'staff@wannadance.tv';
					var subject = 'Segnalazione di abuso dell\'utente '+ usrName;
					var body_message = 'Segnalo allo staff di WannaDance un abuso dell\'utente ' + usrName + ' con la seguente motivazione:\n';
					$('#dialog').append('<div><a onclick="showChatMessage('+ usrId +','+ '\''+ usrName +'\'' + ');hideDialog();" style="cursor: pointer;">Chatta con ' + usrName + '</a></div>');
                    $('#dialog').append('<div><a href="/mywannadance/profilo/'+usrProfile+'/index.html">Leggi il profilo di '+ usrName +'</a></div>');
                    if(data.Table[0].usrBlocked==0)
            			$('#dialog').append('<div><a onclick="blackListInsert('+ usrId +');" style="cursor: pointer;">Metti ' + usrName +' in blacklist</a></div>');
                    $('#dialog').append('<div><a href="mailto:' + to + '?subject=' + subject + '&body='+body_message+'" style="text-decoration: none;">Segnala abuso di ' + usrName + '</a></div>');
                }
    );
    $('#dialog').dialog('open');            
}//end

function hideDialog(e){
    $('#dialog').dialog('close');
}//end

function blackListInsert(usrId){
    $.getJSON("/web/post/BlacklistInsert.aspx?usrId=" + usrId + "&output=JSON&r="+ Math.random(),
                function(data) {
                    if(data.Table[0].errorNumber=='0'){
                       $('#dialog').dialog('close');
                       commenti.loadCount();
                       commenti.loadList(true);
                    } else {
                        alert("Si  verificato un errore durante l'inserimento")
                    }//if
                }
    );
}//end


function blackListRemove(usrId){
    $.getJSON("/web/post/BlacklistRemove.aspx?usrId=" + usrId + "&output=JSON&r="+ Math.random(),
                function(data) {
                    if(data.Table[0].errorNumber=='0'){
                       $('#dialog').dialog('close');
                       window.location.reload( false ); 
                    } else {
                        alert("Si  verificato un errore durante l'inserimento")
                    }//if
                }
    );
}//end



// ---------------   CHATROOM ----------------------------- //

function getChatMessages(sChat){
    var chatBox = '#'+ sChat;
    var chatList = 'chatList'
    $(chatBox).html('');
    $.getJSON(  "/web/get/getChatMessage.aspx?" + "output=JSON&r="+ Math.random(),
            function(data) {
                $(chatBox).append('<ul id="' + chatList + '">');
                for (var i = 0; i < data.Table.length; i++) {
                    if(data.Table[i].chaText!=''){
                        $('#'+chatList).append(
                           "<li>" + 
                                "<div class=\"chatList_item_sender\">" + 
                                    "<a style=\"cursor: pointer;\" onclick=\"showDialog(event,'" + "chat-" + data.Table[i].chaId + "'," + data.Table[i].chaFrom +  ",'" + data.Table[i].chaName + "','" + data.Table[i].chaName_encoded + "');\">" + 
                                        "<cite>" + data.Table[i].chaName + "</cite><span> - " + data.Table[i].chaDate + "</span>" +
                                    "</a>" +
                                "</div>" + 
                                "<div class=\"chatList_item_text\">" + data.Table[i].chaText + "</div>" + 
                            "</li>"
                        );
                    }                       
                }
                $(chatBox).append('</ul>');       
            }//function
    );            
}//end

function showChatMessage(usrId, usrName){
    $('#chatBox_write_tbChaTo').val(usrId);
    $('#chatBox_write_tbChaText').val('');
    $('#chatBox_write_name').html('Scrivi a ' + usrName);
    $('#chatBox_read').hide('highlight','fast');
    $('#chatBox_write').show('highlight','slow');
}//end

function postChatMessage(){
    $.getJSON("/web/post/postChatMessage.aspx?chaTo=" + $('#chatBox_write_tbChaTo').val() + "&chaText=" + $('#chatBox_write_tbChaText').val() + "&output=JSON&r="+ Math.random(),
                function(data) {
                    if(data.Table[0].errorNumber=='0'){
                        $('#chatBox_write_tbChaTo').val('');
                        $('#chatBox_write_tbChaText').val('');
                        getChatMessages('chatBox_read_list');
                        $('#chatBox_write').hide('highlight','fast');
                        $('#chatBox_read').show('highlight','slow');
                    } else {
                        alert("Si  verificato un errore durante l'inserimento")
                    }//if
                }
    );    
}//end

function cancelChatMessage(){
    $('#chatBox_write_tbChaTo').val('');
    $('#chatBox_write_tbChaText').val('');
    //getChatMessages('chatBox_read_list');
    $('#chatBox_write').hide('highlight');
    $('#chatBox_read').show('highlight','slow');
}//end

function showWebuserSearch(){
    $('#chatBox_search_tbChaText').val('');
    $('#chatBox_search_name').html('Scrivi qui il nickname di chi stai cercando ');
    $('#chatBox_read').hide('fast');
    $('#chatBox_search').show('slow');
}//end

function cancelWebuserSearch(){
    $('#chatBox_search').hide();
    $('#chatBox_read').show('slow');
}//end


function activateWebuserSearch(){
	var url = '/mywannadance/profili/index.html?nickname=' + $('#chatBox_search_tbChaText').val();
	window.location = url;
}//end


// ---------------   RATING  ---------------------  //
function initRating(objId, cntId, idWebuser){
    var sObj = '#' + objId;
    var obj = {}
    obj.idContent = cntId;

    $.getJSON(
      '/web/get/getContentRate.aspx?output=JSON&r='+ Math.random(),
      obj,

      function(data) {
            $('input.auto-submit-star:eq(' + ((data.Table[0].cntRateAvg)-1) + ')',sObj).attr('checked','checked');
            $('.contentRatingMessage',sObj).html('(Voti:'+ data.Table[0].cntRateCount +' / Media:' + data.Table[0].cntRateAvg +')');
        	/*  --- importante ---
        		Non utilizzare la funzione callback quando si utilizza la funzione rating.('select',index) come documentato poich dopo la select
        		viene scatenata sempre la callback come se si cliccasse su una delle stelline
        	*/
            $('.auto-submit-star',sObj).rating();
            if(idWebuser==0){
                $('.auto-submit-star',sObj).rating('readOnly',true);
            } else {
            	$('div.auto-submit-star').bind('click',function(){postContentRate(objId,cntId,$('a',$(this)).attr('title'));})
            }               
        }
    );    
}

function getContentRate(objId,cntId){
    var sObj = '#' + objId;
    var obj = {}
    obj.idContent = cntId;

    $.getJSON(
      '/web/get/getContentRate.aspx?output=JSON&r='+ Math.random(),
      obj,
      function(data) {
        $('.contentRatingMessage',sObj).hide();
        $('.contentRatingLoading',sObj).show('fast');
        $('.contentRatingMessage',sObj).html();
        $('.contentRatingMessage',sObj).html('(Voti:'+ data.Table[0].cntRateCount +' / Media:' + data.Table[0].cntRateAvg +')');
        $('input.auto-submit-star',sObj).rating('select',(data.Table[0].cntRateAvg)-1);
        $('.contentRatingLoading',sObj).hide('fast');
        $('.contentRatingMessage',sObj).show('slow');
      }   
    )      
}//end


function postContentRate(objId, cntId, rate){
    var obj = {}
    obj.idContent = cntId;
    obj.cntRate = rate;
   
    $.getJSON(
      '/web/post/postContentRate.aspx?output=JSON&r='+ Math.random(),
      obj,
      function(data) {
        if(data.Table[0].errorNumber==='0'){
            getContentRate(objId, cntId);
    	} else {
    	   $('.contentRatingMessage').hide('slow');
    	   $('.contentRatingError').html('Hai gi&agrave; votato!')
    	   $('.contentRatingError').show('slow');
            setTimeout(function(){
            	   $('.contentRatingError').hide('slow');
            	   $('.contentRatingMessage').show('slow');
            }, 5000);    	   
    	   //alert(data.Table[0].errorMessage)
    	}     	    
      })
 }//end

function shareThis()
{
shlk = encodeURIComponent(document.location.toString());
shtl = document.title.replace(" - Wannadance.tv","");

document.write("<a id='social_1' href=\"javascript:void(window.open('http://www.facebook.com/sharer.php?u="+shlk+"&t="+shtl+"','Condividi su Facebook','height=450,width=440').focus())\" title=\"Condividi su Facebook\"></a>");
	document.write("&nbsp;");
document.write("<a id='social_2' href=\"javascript:void(window.open('http://twitter.com/home?status=Sto leggendo "+shlk+" su Nonsprecare','Condividi su Twitter','height=440,width=900').focus())\" title=\"Condividi su Twitter\"></a>");
	document.write("&nbsp;");
document.write("<a id='social_3' href='http://oknotizie.alice.it/post?url="+shlk+"&title="+shtl+"' target='_blank' title=\"Condividi su OKNo\"></a>");
	document.write("&nbsp;");
document.write("<a id='social_4' href=\"javascript:void(window.open('http://del.icio.us/post?url="+shlk+"','Condividi su Delicious','height=450,width=440').focus())\" title=\"Condividi su Delicious\"></a>");
}



/*-----------------   MP3-OGG player   --------------------- */
function jPlayerSlim(objId, musicFile){
       
    //$("#"+objId+"_ControlBar").show('fast');
    
    $("#"+objId).jPlayer( {
         ready: function () {
            this.setFile(musicFile);  // Defines the mp3
            //this.play();
        },        
        //oggSupport: true,
        //customCssIds: true,
        nativeSupport: true, 
        swfPath: "/includes/swf"      
    });
    
    $("#"+objId).jPlayer("onSoundComplete",function(){
            $('#'+objId).jPlayer('clearFile');
            $("#"+objId+"_ControlBar").hide('fast');             
    });

}//end

function jPlayerFull(objId, musicFile){

   $("#"+objId).jPlayer( {
         ready: function () {
            this.setFile(musicFile);  // Defines the mp3
        },        
        //oggSupport: true,
        nativeSupport: true, 
        swfPath: "/includes/swf"      
    });
}//end

function showPlayer(objId, autoPlay){
    $(".jp-player").jPlayer('stop');
    $(".jp-interface").hide('fast');
    $("#"+objId+"_ControlBar").show('fast');
    if(autoPlay)
        $("#"+objId).jPlayer('play');
}//end


function jPlayerPlay(objId){
     $('#'+objId).jPlayer('play');
     return false;
}//end


function jPlayerPause(objId){
     $('#'+objId).jPlayer('pause');
     return false;
}//end


function jPlayerStop(objId,hide){
     $('#'+objId).jPlayer('stop');
     if(hide)
        $("#"+objId+"_ControlBar").hide('fast');
     return false;
}//end


function serchForm(objform){
	var bRtn=true;
	var ERR='';
	if(objform.q){
		if(objform.q.value==''){
			ERR += 'Specificare una stringa di ricerca!!';
			bRtn=false;
		}else if(String(objform.q.value).length < 2) {
			ERR += 'La stringa di ricerca deve contenere piu\' di un carattere!!';
			bRtn=false;
		}
	}
	if(ERR!='') alert(ERR);
	return bRtn;
}
