//Gestione PNG con JS
//Attivazione CufOn
//OnFocus input

$(function(){
    Cufon.replace(".title, #navigations ul li a", {
        fontFamily: 'Grandesign Neue Serif',
        hover : true
    });
    $(".delme").focus(function(){
        if ($(this).is('input')) {
            var orival = $(this).val();
            $(this).val("");
        }else{
            var orival = $(this).html();
            $(this).html("");
        }

        $(this).blur(function(){
            if($(this).is('input')){
                if ($(this).val() != "" && $(this).val() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else{
                    $(this).val(orival);
                }
            }else{
                if ($(this).html() != "" && $(this).html() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else if ($.browser.safari && $(this).val() != "" && $(this).val() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else{
                    $(this).html(orival);
                }
            }

        });
    });
	$(".request form").submit(function(){
		var res = {
			correct : true,
			fields : []
		};
		$("form div input:not(input:hidden)").each(function(){
			if($(this).val() == '' || isNaN( $(this).val() ) ){
				if($(this).attr('name') == 'data di arrivo' && $(this).val() != ''){
					
				}else{
					res.correct = false;
					res.fields.push( ($(this).attr('name')).replace('tot_', '').replace('_1', '') );	
				}				
			}
		});
		if(!res.correct){
			alert('Non hai compilato correttamente i seguenti campi: \n'+res.fields.join(', '));
			return false;
		}else{
			$("form div.data input").remove();			
			return true;
		}
	});
	$(".data input, .data a").live('click', function(){
		if($(this).hasClass('jdata')){
			var input = $(this).parents('.data').find('input');
		}else{
			var input = $(this);
		}
        input.datepicker({
            minDate : 0,
            maxDate : '+8M',
			onClose : function(dateText, inst){
				var thedate = dateText.split('/');
				$('input[name=giorno]').val(thedate[0]);
				$('input[name=mese]').val(thedate[1]);
				$('input[name=anno]').val(thedate[2]);
			}
        }, $.datepicker.regional['it']).datepicker('show');
		return false;
    });
});

