var urlAjaxHandler=serverPath+'functions/ma_common_helper.php';; // percorso  del contenuto del  dialog
//lite box
$(document).ready(function(){
	$("a.lightbox").lightBox({
	   overlayBgColor: '#000',
	   overlayOpacity: 0.7,
	   txtImage: '',
	   txtOf: 'of',
	  imageLoading:	serverPath+'images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
	   imageBtnPrev:	serverPath+'images/lightbox-btn-prev.png',			// (string) Path and the name of the prev button image
	   imageBtnNext:	serverPath+'images/lightbox-btn-next.png',			// (string) Path and the name of the next button image
	   imageBtnClose:	serverPath+'images/lightbox-btn-close.png',		// (string) Path and the name of the close btn
	  imageBlank:		serverPath+'images/lightbox-blank.gif'

       }

	
	);
	$("a.lightboxambiente").lightBox({
	   overlayBgColor: '#000',
	   overlayOpacity: 0.7,
	   txtImage: '',
	   txtOf: 'of'
       }
	);
	
	  var dialogLongOpts = {
			modal: true,
			autoOpen: false,
			width: 645,
			position:[10,10],
			closeOnEscape:true,
		    draggable: true,
			resizable: false,
			height:500,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.9
			},
      
			open: function() {
			    //display correct dialog content
				//$("#dialogLongBox").load(url);
			},
			close: function() {
			
			$("#dialogLongBox").html('');
			//display correct dialog content
				//$("#dialogBox").dialog( 'destroy' );
			}
			
		};
		$("#dialogLongBox").dialog(dialogLongOpts);	//end dialog
		
		
		var msgOpts = {
			modal: true,
			autoOpen: false,
			width: 300,
			height:150,
			closeOnEscape:true,
		    draggable: true,
			resizable: false,
			
			overlay: {
				backgroundColor: '#000',
				opacity: 0.7
			}		
		};
	
		$("#msgBox").dialog(msgOpts);	//end dialog
		
		$("#loginDimenticato a").click(function(){
	  			$("#loginDimenticatoForm").slideToggle("slow");
	  			$(this).toggleClass("active");
		});
		
		
		 $("div.accordion").each(function(i){
		      $(this).click(function(){
		    	 curObj = this.id.split('_')
		    	
		      //$('#desc_' + curObj).toggleClass("su");
              $('#descrizione_' + curObj[1]).slideToggle('slow');
				  return false;
         });
     });
		
});


function  logout(){
    $.post( urlAjaxHandler, 
  		 {actionType:'logout'}
		 
		 ,function(xml){
		 	if (xml.match('OK')) {
                location.href='index.php'
            }
            else erroreMessage('Error');
		   //alert(xml);
	     }
		 
     );
}

function  authUser(){

    if($('#username').val()!='' && $('#password').val()!='') {
           $.getJSON( urlAjaxHandler, 
           {username: $('#username').val(),password:$('#password').val() ,actionType:'auth',isModal:$('#isModal').val()}
            ,function(xml){
               if (xml.status != 'KO') {
                   if(xml.message!=''){
                            erroreMessage(xml.message);
                   }
                   else  location.href=serverPath+'reserved.php';
                   }             
              else alert(xml.message)
             
           }   
       );
    }
    else alert('\n Prego inserire Username e Password ');
} 
function  ma_ajax_updater(nome_form,actionTypeName,updateItem){
    $.ajax({
        url: urlAjaxHandler+'?actionType='+actionTypeName, 
        data:$('#'+nome_form).serialize(),
        type: 'POST',
        dataType: 'json',
        cache: false,
         success: function(risposta){
         if (risposta.status == 'OK') {
         
           $("#" + updateItem).html(risposta.message);
           
         }
         else alert(risposta.message);
       } 
      }
      );
 } 
/***********************************  gestione  messaggi ***********************************/
function erroreMessage(msgContent){
   //$("#loading").remove();
   $('#msgBox').dialog('option', 'title','Warning !!!!');
   $("#msgBox").html(msgContent);
   $('#msgBox').dialog('open');
}

function showWait(){
   $("#msgBox").html('<div id="loading"></div>');
   $('#msgBox').dialog('option', 'title','....Wait loading.....');
   $('#msgBox').dialog('open');
}
    

//ricerca  avanzata  categorie
function ricercaAvanzata(nome_form){
    
    msg='';
    
    if ($('#sword').length > 0) {
        if($('#sword').val()=='Ricerca rapida' || $('#sword').val()=='') msg="Prego inserire un  parola"
    }
    
   
   

    if(msg!=''){
        erroreMessage(msg)
    }
    else {
        showWait()
        document.forms[nome_form].submit()
    }
    
}

