//TABS
$(function () {
			var tabContainers = $('div.tabs-light > div');
			tabContainers.hide().filter(':first').show();
			$('div.tabs-light ul.tabNavigation-light a').click(function () {
					//alert(this.hash);
					tabContainers.hide();
					tabContainers.filter(this.hash).show();
					$('div.tabs-light ul.tabNavigation-light a').removeClass('selected');
					$(this).addClass('selected');
					return false;
			}).filter(':first').click();
  
		});

$("#bshowp").click( function(){
	
	$("#privacy_p").show()
	
})

$(document).ready(function() {
	valutazione_immobile.initEventHandlers();
	
});

var domIdButtonSend  = "send_vi"; //id del pulsante invia del form
var domIdLoader      = "loader_vi"; //id dell'elemento di loading/attesa
var domIdForm        = "form_valutazione_immobile";//id del form
var domIdSuccessMess = "success_message_vi";//id dello spazio messaggio di successo
var domIdErrorMess   = "error_message_vi";//id dello spazio messaggio di successo
var domIdEnvelope    = "envelope_vi";//id del contenitore della immagine ad effetto
var className        = "valutazione_immobile";


var valutazione_immobile = {
	initEventHandlers    : function() {
		/* clicking the submit form */
		$('#'+domIdButtonSend).bind('click',function(event){
			$('#'+domIdLoader).show();
			setTimeout(className+'.ContactFormSubmit()',500);
		});
		/* remove messages when user wants to correct (focus on the input) */
		$('.input',$('#'+domIdForm)).bind('focus',function(){
			var $this        = $(this);
			var $error_elem  = $this.next();
			if($error_elem.length)
				$error_elem.fadeOut(function(){$(this).empty()});
			$('#'+domIdSuccessMess).empty();    
		});
		
		
		/* user presses enter - submits form */
		$('#'+domIdForm+' input,#'+domIdForm+' textarea').keypress(function (e) {
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
				$("#"+domIdButtonSend).click();
				return false;  
			} 
			else  
				return true;  
		});
	},
	ContactFormSubmit    : function() {
			
		   $.ajax({
							   type        : 'GET',
							   url         : 'index.php?',//'mod='+serverModule,
							   dataType    : 'json',
							   data        : $('#'+domIdForm).serialize(),
							   success     : function(data,textStatus){
											  
											  $("#"+domIdLoader).hide();  //hide the ajax loader
											  
											  if(data.result == '1'){
												  $('#error_message_vi').hide();
												  //show success message
												  $('#'+domIdSuccessMess).empty().html(data.data).show();
												  //reset all form fields
												  $('#'+domIdForm)[0].reset();    
												  //envelope animation
												  $('#'+domIdEnvelope).stop().show().animate({'marginTop':'-175px','marginLeft':'-246px','width':'492px','height':'350px','opacity':'0'},function(){
													  $(this).css({'width':'246px','height':'175px','margin-left':'-123px','margin-top':'-88px','opacity':'1','display':'none'});
												  });
												  //hide error message
												  $('#'+domIdErrorMess).empty().hide();
											  }
											  else if(data.result == '-1'){
												  for(var i=0; i < data.errors.length; ++i ){
													  if(data.errors[i].value!='')
														  $("#"+data.errors[i].name).next().html(data.errors[i].value).fadeIn();
												  }
												  $('#error_message_vi').show().html("Ricontrolla attentamente tutti i dati del form");
											  }                                 
										  },
								 error    : function(data,textStatus){}               
					
						});
		
		
	}  
};										 
								  
								
