var urlAjaxHandler=serverPath+'functions/ma_common_helper.php'; // percorso  del contenuto del  dialog
//lite box
$(document).ready(function(){
	
	
	  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");
		});
		
		//rollover
		$(".rolla").rollover(true);// call the function
	//  swap    
		   swapValues = [];
	       $(".swap_value").each(function(i){
		        swapValues[i] = $(this).val();
		        $(this).focus(function(){
		            if ($(this).val() == swapValues[i]) {
		                $(this).val("");
		            }
		        }).blur(function(){
		            if ($.trim($(this).val()) == "") {
		                $(this).val(swapValues[i]);
		            }
		        });
	        });
		
});


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


function  iscivitiNewsletter(isLogged){
    
	msg='';
  //Email
     if(isLogged!=1)showLogin();
	 else {
     //if($('#nome').val()=='') {msg='Inserire un nome<br>'}
     if($('#Email').val()==''){msg='Inserire un Email'}
     if(msg=='') {
     showWait();
     $.post( urlAjaxHandler, 
  		 {Email: $('#Email').val(),Firstname:$('#nome').val(),actionType:'newsletter'}
		 
		 ,function(xml){
		 	// location.href=location.href
            
		   erroreMessage(xml);
	     }
		 
     );
  }
  else erroreMessage(msg);
  }
} 




/***********************************  gestione  messaggi ***********************************/



function erroreMessage(msgContent){
   //$("#loading").remove();
   $('#msgBox').dialog('option', 'title','Sensi Contemporanei!');
   $("#msgBox").html(msgContent);
   $('#msgBox').dialog('open');
}

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

