var mobile = (/iphone|up.browser|up.link|mmp|smartphone|midp|wap|phone|symbian|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
if (mobile) {  
    //location.replace("http://www.hotelcaladiseta.it/m/");
}

function openMenu(n){

	$('.new-menu-nav li div').each(function(index) {
       $(".new-menu-nav #"+$(this).attr('id')).css("display","none");
	});
	$(".new-menu-nav #box-sotto-menu-"+n).css("display","block");

}

function openBox(n_box){

	for(x=1; x<=4; x++){

	  if(x==n_box){

		  if($('#desc'+x).css('display')=='block'){
			  $('#desc'+x).animate({'height':'hide'}, 'fast');
			  $('#cont-booking-offerta-'+x).removeClass().addClass('cont-booking-offerta');
			  $('#img-bottom-pre').html('<img src="'+pat_host+'/images/ico-booking/bg-list-pre.png" />');
		  }else{
			  $('#desc'+x).animate({'height':'show'}, 'fast');
			  $('#cont-booking-offerta-'+x).removeClass().addClass('cont-booking-offerta-sel');
			  $('#img-bottom-pre').html('<img src="'+pat_host+'/images/ico-booking/bg-list-pre-yellow.png" />');
		  }

	  }else{
		  $('#desc'+x).animate({'height':'hide'}, 'fast');
		  $('#cont-booking-offerta-'+x).removeClass().addClass('cont-booking-offerta');
		  $('#img-bottom-pre').html('<img src="'+pat_host+'/images/ico-booking/bg-list-pre.png" />');
	  }

	}

}

function viewNewPre(){
	$('#stat-prenotazione').animate({'height':'hide'}, 'fast');
	$('#ripeti-prenotazione').animate({'height':'show'}, 'fast');

	//$('#stat-prenotazione').slideUp('slow').css('display', 'none');
	//$('#ripeti-prenotazione').slideDown('slow').css('display', 'block');
}

function creaCamere(num_campi,testo,data_a,data_p,frame) {

	$("#contenitore_camere").bind("ajaxStart",function(){
		$("#contenitore_camere").html('<img src="'+pat_host+'/images/loading16.gif" width="16" height="16" align="absmiddle" alt="Attendere prego" style="margin-top:5px" />'); 
	});

	$.ajax({ 
	    complete : function(){ }, 
		url      : pat_host+"/include/core.php", 
		cache    : false, 
		data     : "act=crea_camere&num_campi="+num_campi+"&data_a="+data_a+"&data_p="+data_p+"&testo="+testo+"&frame="+frame, 
		success  : function (risultato,esito){
			// Mostro risultato
			$("#contenitore_camere").html(risultato);
		},
		error : function (richiesta,stato,errori) {
			alert("Attenzione, si &egrave; verificato un errore");    
	}});
}

function campiForm(idForm){

	var errore_c = 0;
	// edit_cliente

	$("#"+idForm+" input[label=ctrl]").each(function(){

		//Controllo che il campo sia pieno
			if ($("#"+this.id).val() == ''){
				$("#"+this.id).toggleClass("classFormE",true);
				errore_c++;
			} else {
				$("#"+this.id).toggleClass().toggleClass("classFormContact",true);
			}
		
	});

	$("#"+idForm+" textarea[label=ctrl]").each(function(){
		//Controllo che il campo sia pieno
			if ($("#"+this.id).val() == ''){
				$("#"+this.id).toggleClass("classFormE",true);
				errore_c++;
			} else {
				$("#"+this.id).toggleClass().toggleClass("classFormContact",true);
			}
		
	});

     if(errore_c){
		return false;
	 }else{
		return true;
	 }

}

function check_date(tipo) {

	var data_iniziale = $('#data_arrivo').val();
	var data_finale   = $('#data_partenza').val();
	var data_attuale  = $('#data_attuale').val();

	var arr1 = data_iniziale.split("/");
	var arr2 = data_finale.split("/");
	var arr3 = data_attuale.split("/");

	var d1 = new Date(arr1[2],arr1[1]-1,arr1[0]);
	var d2 = new Date(arr2[2],arr2[1]-1,arr2[0]);
	var d3 = new Date(arr3[2],arr3[1]-1,arr3[0]);

	var r1 = d1.getTime();
	var r2 = d2.getTime();
	var r3 = d3.getTime();

	if(r1<r2){

		// CONTROLLO CHE SIA SUCESSIVA A OGGI
		if(r1>r3){

			if(tipo=='comp'){

				if(confirm("Stai per inviare la tua prenotazione, continuare?")){
					return true;
				}else{
					return false;	
				}
			    
			}else{
			    return true;
			}

		}else{

			//alert("La data di check-in deve essere successiva al giorno: "+data_attuale);
			andyAlert(pat_host+"/include/errori.php?errore=1");
			$('#data_arrivo').removeClass().addClass('classFormEG');
			$('#s-errore1').attr('src', pat_host+"/images/m-icone/m-icona-e.png");
			$('#data_partenza').removeClass().addClass('classFormEG');
			$('#s-errore2').attr('src', pat_host+"/images/m-icone/m-icona-e.png");
            return false;

		}

	}else{
	    //alert("La data di check-in e' successiva o uguale a quella di check-out!");
		andyAlert(pat_host+"/include/errori.php?errore=2");
		$('#data_arrivo').removeClass().addClass('classFormEG');
		$('#s-errore1').src = pat_host+"/images/m-icone/m-icona-e.png";
		$('#data_partenza').removeClass().addClass('classFormEG');
		$('#s-errore2').src = pat_host+"/images/m-icone/m-icona-e.png";
		return false;
	}

}

function checkPrenota(tipo){

   var errore_form = 0;

	if(tipo=='comp'){

	   if($('#nome').val()=='' || $('#cognome').val()==''){
		   $('#s-errore6').html('<img src="'+pat_host+'/images/m-icone/m-icona-6.png" width="16" height="15" alt="Errore" />');
		   errore_form++;
	   }else{
		   $('#s-errore6').html('<img src="'+pat_host+'/images/m-icone/m-icona-v.png" width="16" height="15" />');
		   $('#cognome').removeClass().addClass("classFormGrey");
		   $('#nome').removeClass().addClass("classFormGrey");
	   }

		/* CONTROLLO CHE L'EMAIL SIA VALIDA */
	   reg = new RegExp('^([a-zA-Z0-9\-\.\_]+)'+'(\@)([a-zA-Z0-9\-\.]+)'+'(\.)([a-zA-Z]{2,4})$');

	   if($('#email').val()=='' || reg.test($('#email').val()) == false){
		   $('#s-errore7').html('<img src="'+pat_host+'/images/m-icone/m-icona-6.png" width="16" height="15" alt="Errore" />');
		   errore_form++;
	   }else{
		   $('#s-errore7').html('<img src="'+pat_host+'/images/m-icone/m-icona-v.png" width="16" height="15" />');
		   $('#email').removeClass().addClass("classFormGrey");
	   }

	   if($('#contatto').value==''){
		   $('#s-errore8').html('<img src="'+pat_host+'/images/m-icone/m-icona-6.png" width="16" height="15" alt="Errore" />');
		   errore_form++;
	   }else{
		   $('#s-errore8').html('<img src="'+pat_host+'/images/m-icone/m-icona-v.png" width="16" height="15" />');
		   $('#contatto').removeClass().addClass("classFormGrey");
	   }

	}

   if($('#data_arrivo').val()==''){
	   $('#s-errore1').attr('src', pat_host+"/images/m-icone/m-icona-e.png");
	   errore_form++;
   }else{
	   $('#s-errore1').attr('src', pat_host+"/images/m-icone/m-icona-7.png");
   }
   if($('#data_partenza').val()==''){
	   $('#s-errore2').attr('src', pat_host+"/images/m-icone/m-icona-e.png");
	   errore_form++;
   }else{
	   $('#s-errore2').attr('src', pat_host+"/images/m-icone/m-icona-7.png");
   }


   if(errore_form>=1){
       return false;
   }else{

	 // CONTROLLO LE DATE 
	 var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
   
	   if(!espressione.test($('#data_arrivo').val())){	
		   $('#data_arrivo').removeClass().addClass('classFormEG');
		   $('#s-errore1').attr('src', pat_host+"/images/m-icone/m-icona-e.png");
		   errore_form++;
	   }else{
		   $('#data_arrivo').removeClass().addClass('classFormGrey');
		   $('#s-errore1').attr('src', pat_host+"/images/m-icone/m-icona-7.png");
	   }
	   if(!espressione.test($('#data_partenza').val())){
		   $('#data_partenza').removeClass().addClass('classFormEG');	
		   $('#s-errore2').attr('src', pat_host+"/images/m-icone/m-icona-e.png");
		   errore_form++;
	   }else{
		   $('#data_partenza').removeClass().addClass('classFormGrey');
		   $('#s-errore2').attr('src', pat_host+"/images/m-icone/m-icona-7.png");
	   }

		   if(errore_form>=1){
			   return false;
		   }else{
			   return check_date(tipo);
		   }

		}

   }

function cambiaLingua(linkNewLingua){
	$(document.location).attr("href", linkNewLingua);
}
