	/**
	 * @author Ale
	 */

	var regione = '';
	var provincia = '';
	var evento;
		
    function resizePage(){
        if($(document).width()>1000)
            $('#content').width('1000px');
        else
            $('#content').width('100%');

        if(typeof resizePagingControls == 'function') { 
            resizePagingControls(); 
        }
    }
    
    function sanitizeHtmlData(html){
        return html.replace(/>([^>.^<^\w^\/])*</g,"><");
    }

        
    function compilaCampi(){
        var now = new Date();        
        var time = now.getDate()+'.'+now.getMonth()+'-'+now.getHours()+'.'+now.getMinutes()+'.'+now.getSeconds();
        
        $('input[type=text]').each(function(){
            
            $(this).val($(this).attr('name')+' '+time);
            if($(this).attr('name')=='cellulare'){
                $(this).val('cell'+' '+time);    
            }
            if($(this).attr('name')=='telefono'){
                $(this).val('tel'+' '+time);    
            }
        });
        $('input[type=text].number').each(function(){
            $(this).val('0');
        });
        $('input[type=text].email').each(function(){
            $(this).val(time+'@test.it');
        });
        $('textarea').each(function(){
            $(this).val($(this).attr('name')+' '+time);
        });
        /*
        $('input[type=checkbox]').each(function(){
            $(this).attr('checked', true);
        });
        */
        $('select').each(function(){
            //seleziono il primo valore che trovo
            if($(this).children().length > 0)
                $('select').val('1');
        });
        
        return 'fatto!';
     }

        
	function showAddThis(){
		var pos = $('#titoloEvento').offset();	
		$("#addThis").css('position','absolute');
		$("#addThis").css('top',pos.top+110);
		$("#addThis").css('left',pos.left);				
		$("#addThis").fadeIn('fast');
	}

	function hideAddThis(){
		if($("#addThis").is(':visible'))
			$("#addThis").fadeOut('fast');
	}
		
	function showEvents(){
		hideAddThis();
		if (provincia!='')
			showProvincEvents(provincia);				
		else if (regione!='')
			showRegionEvents(regione);
		else
			showFeatured();	
	}	
	
    function showFeatured(){
        hideAddThis();
        $('#naviga').fadeOut('fast', function(){
            $('#naviga').empty();
            $.post("eventi.php", {
                speciali: "1",
				partner: $('#partner').val()
            }, function(data){
                //alert(data);				
                $('#naviga').append(data);
                $('#naviga').fadeIn('fast');
                
            });
            
        });
    }
		
    function showProvincEvents(prov){
        hideAddThis();
        provincia = prov;
        $('#naviga').fadeOut('fast', function(){
            $('#naviga').empty();
            $.post("eventi.php", {
                cod_reg: regione,
                selectProvincia: provincia,
				partner: $('#partner').val()
            }, function(data){
                //alert(data);				
                $('#naviga').append(data);
                $('#naviga').fadeIn('fast');
            });
            
        });
    }
		
    function showRegionEvents(region){
        hideAddThis();
        regione = region;
        provincia = '';
        $('#naviga').fadeOut('fast', function(){
            $('#naviga').empty();
            $.post("eventi.php", {
                cod_reg: regione,
				partner: $('#partner').val()
            }, function(data){
                //alert(data);				
                $('#naviga').append(data);
                $('#naviga').fadeIn('fast');
            });
            
        });
    }
				
	
	function showDettagli(idEvento){
		evento=idEvento;
		$('#naviga').fadeOut('fast', 
		function(){
			$('#naviga').empty();
			$.post("dettagli.php", { id_evento: evento	}, 
			function(data){
				//alert(data);				
				$('#naviga').append(data);
				$('#naviga').fadeIn('fast');
				showAddThis();
			});
			
		});				
	}
	
	function showPrenota(idEvento){
		hideAddThis();
		evento=idEvento;
		$('#naviga').fadeOut('fast', 
		function(){
			$('#naviga').empty();
			$.post("prenota.php", { id_evento: evento	}, 
			function(data){
				//alert(data);				
				$('#naviga').append(data);
				$('#naviga').fadeIn('fast');
			});
			
		});				
	}
	
    function getCurrentDate(){
        var d = new Date();
        var curr_date = d.getDate();
        var curr_month = d.getMonth();
        curr_month++;
        var curr_year = d.getFullYear();
        var curr_hour = d.getHours();
        var curr_min = d.getMinutes();
        var curr_sec =  d.getSeconds();

        var dateSeparator='-';
        var timeSeparator=':';

        var formattedData = ''+curr_year+dateSeparator+curr_month+dateSeparator+curr_date+' '+curr_hour+timeSeparator+curr_min+timeSeparator+curr_sec;
        return formattedData;
    }
	
    //funzione che sostitusce tutte le lettere accentate
    function rimuoviAccenti(s){
            //var r=s.toLowerCase();
            var r=s;
            r = r.replace(new RegExp("\\s", 'g'),"");
            r = r.replace(new RegExp("[àáâãäå]", 'g'),"a");
            r = r.replace(new RegExp("æ", 'g'),"ae");
            r = r.replace(new RegExp("ç", 'g'),"c");
            r = r.replace(new RegExp("[èéêë]", 'g'),"e");
            r = r.replace(new RegExp("[ìíîï]", 'g'),"i");
            r = r.replace(new RegExp("ñ", 'g'),"n");                            
            r = r.replace(new RegExp("[òóôõö]", 'g'),"o");
            r = r.replace(new RegExp("œ", 'g'),"oe");
            r = r.replace(new RegExp("[ùúûü]", 'g'),"u");
            r = r.replace(new RegExp("[ýÿ]", 'g'),"y");
            r = r.replace(new RegExp("\\W", 'g'),"");
            return r;
    }

    $.fn.extend({
      toggleAttr : function( attrib ) {
        if ( this.attr( attrib ) ) {
          this.removeAttr( attrib );
        } else {
          this.attr( attrib, attrib );
        }
        return this;
      }
    });
    
    
$(function(){
        

        $('input').live("keyup",function(){
            $(this).parent().find('label.error').hide()
        });

        $('input').focusout(function(){
            $(this).parent().find('label.error').show()
        });

        $('.formatEsteri').insertAfter('.hold');
        $('.formatEsteri').show();
});

