function conferma(valore,loc){
	        if(confirm("Vuoi cancellare id "+valore+" ?")){
	          	location.href=loc+'&canc='+valore;
	    }
}


function ajxUpdater(vi,ut){
	$.ajax({
  		url: "ajax/regione.php?utente="+ut+"&company="+vi,
  		cache: false,
  		success: function(html){
			$("#regionidiv").empty();
			$("#regionidiv").append(html);		
  		}
	});
}

function ajxStoca(prom,val){
	if(val){
		$.ajax({
			url: "ajax/regione.php?promozione="+prom,
			cache: false,
			success: function(html){
				if(html==''){
					html='<b>Non sono presenti regioni,province o punti vendita <br/> in cui questa offerta &egrave; visibile</b>';
				}
				$("#frocas").empty();
				$("#frocas").append(html);
				$("#frocas").show(1000);
			}
		});
		$("#btnVisa").hide({
			success:function(){$("#frocas").empty()}
		});
		$("#btnVisa").hide();
		$("#btnClose").show();
		$("#btnCambio").show();
	}
	else{
		$("#frocas").hide(500);
		$("#btnVisa").show();
		$("#btnClose").hide();
		
	}	
}

function changePdf(){
	$('#contUp').show();
	$('#chgButton').hide();
	$('#enneNasc').hide();
	$('#chgButton').append('<input type="hidden" name="AggioYes" value="1" />');
	
}


function ajxUpdatertwo(vi,ut){//da provincia ricavo la select della regione
	
	if(vi==''){
		$("#pov").empty();
		$("#pov").hide();
	}
	$.ajax({	 
		url: "ajax/regione.php?regione="+vi,
	  	cache: false,
	  	success: function(html){	
		$("#procas").empty();	
		$("#procas").append(html);
		$("#trocas").empty();
		$("#pov").show();
	  	}
	});
}

function ajxUpdatertree(vi,ut){
	$.ajax({	 
  		url: "ajax/regione.php?provincia="+vi,
  		cache: false,
  		success: function(html){
		$("#trocas").empty();	
		$("#trocas").append(html);
  		}
	});
}

function ajxUpdaterfour(vi,ut){
	$("#btnVisa").hide();
	$("#btnClose").show();
	if(!ut){
		$("#frocas").show();
		$.ajax({	 
			url: "ajax/regione.php?utenteSa="+vi,
			cache: false,
			success: function(html){
			$("#frocas").empty();	
			$("#frocas").append(html);
  			}
		});
	}
	else{
		$("#frocas").hide();
	}	
}

function ajxUpdaterlst(vi,ut){
	$.ajax({	 
  		url: "ajax/regione.php?lst="+vi,
  		cache: false,
  		success: function(html){
		if(vi=='00'){
			$("#yota").empty();	
		}
		$("#yota").append(html);
		
  		}
	});
}

function users(){
    $.ajax({
  		url: "ajax/clienti.php?cst=all",
  		cache: false,
  		success: function(html){
                $("#clienti").empty();
                $("#clienti").append(html);
                $("#clienti").slideToggle("slow");
                    
                }

	});
}

function usersOrd(key){
        $.ajax({
  		url: "ajax/clienti.php?cst="+key,
  		cache: false,
  		success: function(html){
                $("#clienti").empty();
                $("#clienti").append(html);
                $("#clienti").slideToggle("slow");
  		}
	});

}

function slctUtente(id){
    $.ajax({
  		url: "ajax/clienti.php?user="+id,
  		cache: false,
  		success: function(html){
                $("#clienti").empty();
                $("#clienti").append(html);
                $("#clients").empty();
                $("#clients").append('<input type="button" value="Cambia cliente" onclick="javascript:users();">');
                var s=$("#sol").val();
                if(s){
                    $("#salva").show();
                    $("#clcp").show();
                }
            }
	});
}

function clacpre(){
    var fine=$('#periodoAl').val();
    var inizio=$('#periodoDal').val();
    var camera=$('.ca_mera').val();
    var pensione=$('.pensione').val();
    var persone=$('.persone').val();
    var bmbzt=$('.bambini_0_3').val();
    var bmbts=$('.bambini_3_6').val();
    var bmbsd=$('.bambini_6_12').val();
    var cas=$('input:checked');
    var opt='';
    for(var i=0;i<cas.length;i++){
        opt+=cas[i].id+',';
    }
    $.ajax({
  		url: "ajax/prezzo_ajax.php?periodoDal="+inizio+"&periodoAl="+fine+"&camera="+camera+"&pensione="+pensione+"&numero_persone="+persone+"&bambini_0_3="+bmbzt+"&bambini_3_6="+bmbts+"&bambini_6_12="+bmbsd+"&opt="+opt,
  		cache: false,
  		success: function(html){
                    $("#price").empty();
                    $("#price").append('<div style="text-algin:center;color:red;"><b>'+html+' &euro;</b></div>');
  		}
	});
}

if(!capienza){
	var capienza=5;
}


var msg= new Array();
msg[0]=new Array("Inserire una data di check-in ","Enter a check-in date","Geben sie ihr Ankunftsdatum ein");
msg[1]=new Array("Inserire una data di check-out","Enter a check-out date","Geben Sie ihr Abreisedatum ein");
msg[2]=new Array("Selezionare un tipo di camera","Select a room type","Geben Sie dem Zimmertyp ein");
msg[3]=new Array("Inserire un nome","Enter a name","Geben Sie einen Namen");
msg[4]=new Array("Inserire un cognome","Enter a last name","Geben Sie einen Nachname an");
msg[5]=new Array("Inserire un indirizzo","Enter an address","Geben Sie eine Adresse an");
msg[6]=new Array("Inserire un email","Enter an email","Geben Sie eine E-Mail-Adresse an");
msg[7]=new Array("Inserire un codice postale","Enter postal code","Geben Sie eine Postleitzahl an");
msg[8]=new Array("Inserire un a citta","Enter a city","Geben Sie eine Stadt an");
msg[9]=new Array("Inserire un numero civico","Enter a house number","Geben Sie eine Hausnummer an");
msg[10]=new Array("Inserire un numero di telefono","Enter a telefone number","Geben Sie eine Telefonnummer");
msg[11]=new Array("Assicurarsi che la data di partenza non sia precedente a quella di arrivo","Make sure the date of departure is earlier than arrival date","Vergewissern Sie sich, das Datum der Abreise ist vor dem Anreisedatum");
msg[12]=new Array("Inserire uno stato","Enter a country","Geben Sie eine Staat");
msg[13]=new Array("Le persone selezionate superano la capienza della camera (capienza max:"+capienza+" persone)","The persons selected exceed the capacity of the room (max capacity:"+capienza+")","Die ausgewählten Personen übersteigt die Kapazität des Raumes (max Kapazität:"+capienza+")");
msg[14]=new Array("Le persone non raggiungono il numero minimo per la camera scelta (numero minimo:"+capienza+" persone)","People do not reach the minimum number for room selection(min number:"+capienza+")","Menschen erreichen nicht die Mindestzahl für Raumauswahl (Mindestteilnehmerzahl:"+capienza+")");


function VisAlert(idMessaggio,lingua) {
    alert(msg[idMessaggio][lingua]);
}

$(document).ready(function() {
		var today=new Date();

             	$("#nexta").hide();


		var year=today.getYear();
		var yy;
                
		if(year==110){
			yy=2010;		
		}
		if(year==111){
			yy=2011;		
		}
		if(year==112){
			yy=2012;		
		}
		if(year==113){
			yy=2013;		
		}
		if(year==114){
			yy=2014;		
		}
		if(year==115){
			yy=2015;		
		}
		else if(navigator.appName!="Netscape"){
			yy=today.getYear();

		}		
		//alert(navigator.appName);

                $('#dataDa').datepicker({
			inline: true,
			dateFormat: 'dd-mm-yy',
			gotoCurrent: true,
			minDate: new Date(yy,today.getMonth(),today.getDate()+1)
                });


                var dataDas=$('#dataDa').val();
                if(dataDas!=''){
                   var expo=dataDas.split();
                }
                else{
                   var expo=new Array();
                   expo[0]=today.getDate()+1;
                   expo[1]=today.getMonth();
                }

                $('#dataA').datepicker({
                        inline: true,
			dateFormat: 'dd-mm-yy',
			gotoCurrent: true,
			minDate: new Date(yy,expo[1],expo[0])

                });

                $('.ca_mera').hide();
                $('#controlla').hide();

                $('#periodoDal').datepicker({
			inline: true,
			dateFormat: 'yy-mm-dd'
		});
                $('#periodoAl').datepicker({
			inline: true,
			dateFormat: 'yy-mm-dd'
		});

                $('.ca_mera').change(function(){
                    $('#controlla').show();
                });
                $('.camara').change(function(){
                    $('#controlla').show();
                });

		

                $("#selecta").change(function(){
                    
                    $.ajax({
                        url: "ajax.php?changhe="+$("#selecta").val(),
                        cache: false,
                        success: function(html){
                              var ind=html;
                              location.href=ind;
                        }
                    });
                });

		

		$("#btncerca").click(function(){
                   if(!$('#dataDa').val()){
                        VisAlert(0,$("#lang").val());
                        $('#dataDa').focus();
                        return(false);
                    }
                    if(!$('#dataA').val()){
                        VisAlert(1,$("#lang").val());
                        $('#dataA').focus();
                        return(false);
                    }
                    if($('#dataDa').val() && $('#dataA').val() ){
                      var inizio=$.datepicker.parseDate('dd-mm-yy', $('#dataDa').val());
                      var fine=$.datepicker.parseDate('dd-mm-yy', $('#dataA').val());
                      if(inizio>fine){
                          VisAlert(11,$("#lang").val());
                          return(false);
                      }
                    }
                    if($('#selectcam').val()==''){
                        VisAlert(2,$("#lang").val());
                        $('#selectcam').focus();
                        return(false);
                    }
                    
                });

		$('#bonifico').click(function(){
			
			$("#nascbanca").fadeIn("1000");
			$("#temporaneo").fadeIn("1000");
			$("#nascwestern").hide();
		});

		$('#western').click(function(){
			$("#temporaneo").fadeIn("1000");
			$("#nascwestern").fadeIn("1000");
				$("#nascbanca").hide();
		});

		//$("#nexta").hide();

                
                $("#nexto").click(function(){
                       
                       var adu=parseInt($('#adulti').val());
                       var bam3=parseInt($('#bambini3').val());
                       var bam6=parseInt($('#bambini6').val());
                       var bam12=parseInt($('#bambini12').val());

                       

                      if(!$('#nome').val()){
                        VisAlert(3,$("#lang").val());
                        $('#nome').focus();
                        return(false);
                    }
                    if(!$('#cognome').val()){
                        VisAlert(4,$("#lang").val());
                        $('#cognome').focus();
                        return(false);
                    }
                    if($('#indirizzo').val()==''){
                        VisAlert(5,$("#lang").val());
                        $('#indirizzo').focus();
                        return(false);
                    }
                    if($('#numero').val()==''){
                        VisAlert(9,$("#lang").val());
                        $('#numero').focus();
                        return(false);
                    }
                    if($('#zip').val()==''){
                        VisAlert(7,$("#lang").val());
                        $('#zip').focus();
                        return(false);
                    }
                     if($('#citta').val()==''){
                        VisAlert(8,$("#lang").val());
                        $('#citta').focus();
                        return(false);
                    }
                    if($('#telefono').val()==''){
                        VisAlert(10,$("#lang").val());
                        $('#telefono').focus();
                        return(false);
                    }
		    if($('#stato').val()=='0'){
                        VisAlert(12,$("#lang").val());
                        $('#stato').focus();
                        return(false);
                    }
                    if($('#email').val()==''){
                        VisAlert(6,$("#lang").val());
                        $('#email').focus();
                        return(false);
                    }
                    if(adu+bam3+bam6+bam12>capienza){
                        VisAlert(13,$("#lang").val());
                        $('#adulti').focus();
                        return(false);
                    }
                    if(adu+bam3+bam6+bam12<capienza){
                        VisAlert(14,$("#lang").val());
                        $('#adulti').focus();
                        return(false);
                    }
                    
                })
});


function ctrlDisp(){
     var inizio=$('#periodoAl').val();
     var fine=$('#periodoDal').val();
     var camera=$('.ca_mera').val();
     if(!camera){
        var camera=$('.camara').val();
     }
     $.ajax({
  		url: "ajax/clienti.php?inizio="+inizio+"&fine="+fine+"&camera="+camera,
  		cache: false,
  		success: function(html){
                    if(html==''){
                        $('#sino').empty();
                        $('#sino').append('<div style="width:90%;margin-left:5px;margin-top:5px;text-align:center;background-color:#FF2312;">CAMERA NON DISPONIBILE PER IL PERIODO SELEZIONATO</div>');
                        $('#salva').hide();
                        $('#clcp').hide();
                    }
                    else{
                        $('#sino').empty();
                        $('#sino').append('<div style="width:90%;margin-left:5px;margin-top:5px;text-align:center;background-color:#B5CC4B;" ><input type="hidden" value="1" id="sol"> CAMERA DISPONIBILE PER IL PERIODO SELEZIONATO</div>');
                        var s= $('#idCliente').val();
                        if(s){
                            $('#salva').show();
                            $('#clcp').show();
                        }
                    }
  		}
	});
}



function seeBasta(val,sal){
	$('#'+val).show(500);
	sa=document.formOne;
	for (i=0 ; i<sa.elements.length ; i++){
		if(sa.elements[i].id == sal){
			if(sa.elements[i].checked==false){
				sa.elements[i].checked = true;	
			}
		}
	}
	
}


function confermaAll(){
	jConfirm('Sei sicuro di voler cancellare le categorie selezionate?', 'Cancellazione categorie/a', function(r) {
						if(r==true){
							document.formOne.submit();
						}
	});
}

function confermaAll2(){
	jConfirm('Sei sicuro di voler cancellare i lavori selezionati?', 'Cancellazione categorie/a', function(r) {
						if(r==true){
							document.formOne.submit();
						}
	});
}
    
function confermaAll3(er,rop){
	var s=rop;
	jConfirm('Sei sicuro di voler cancellare '+s+'?', 'Cancellazione categorie/a', function(r) {
						if(r==true){
							document.formOne.submit();
						}
	});
}


var tabberOptions = {manualStartup:true};
function TabberInit() { 
	tabberAutomatic(tabberOptions); 
}
window.setTimeout('TabberInit()', 200);


function SelectAll( form_name, obj_id, val )
{	
	f = document.forms[form_name] ;
	for (i=0 ; i<f.elements.length ; i++)
	{	
		if(f.elements[i].id == obj_id)
			f.elements[i].checked = val;
	}
}


function slctRight(reg,val){
	f = document.formOne;
	for (i=0 ; i<f.elements.length ; i++)
	{if(f.elements[i].id == reg)
				f.elements[i].checked = val;
			
	}
}



function openSelect(val,reg){
	var div='#'+reg;
	if(val){
		$(div).show(300);
	}
	else{
		$(div).hide(300);
	}
}

function confermaAll4(er,rop){
	var s=rop;
	jConfirm('Inviare la mail agli utenti selezionati?','Invio Mail', function(r) {
		if(r==true){
			$.ajax({
				url: "ajax/set.php?flaggo="+s,
				cache: false,
				success: function(html){
					document.formOne.submit();
				}
			});
		}
	});
}










