function loader(id){
	$("#"+id).addClass("block");
	$("#"+id).addClass("visible");
	$("#"+id).html("<img alt=loader' src='images/prenotarsi-loader.gif' />");
}


function result(id,data){
	document.getElementById(id).innerHTML = data;
}

function search(id,action,e){
  loader(id);
  var e = document.getElementById(e);
  var scelta = $("input:checked[name='categoria']").val();

	setTimeout("$.get('search.php?evento="+action+"&scelta="+scelta+"&provincia="+escape(e.value)+"',{}, function(data){ result('"+id+"',data) });", 1000);
	$("#ricerca-dx, #ricerca-sx").addClass("postsearch");
	$.get('banner-1.php?provincia='+escape(e.value),{}, function(data){ result('banner-1',data) });
} 
function searchis(id,action,e){
  loader(id);	
  var e = document.getElementById(e);
  setTimeout("$.get('search.php?evento="+action+"&provincia="+escape(e.value)+"',{}, function(data){ result('"+id+"',data) });", 1000);
  
} 
function callpren(id,giorno,mese,anno){
  loader(id);
  setTimeout("$.get('search.php?evento=ddp&g="+giorno+"&m="+mese+"&a="+anno+"',{}, function(data){ result('"+id+"',data) });", 1000);
} 
function reset(id,id2){
	$("#"+id).html("");
	$("#"+id2).val("");
} 


function chiudi(id){
 document.getElementById(id).style.display = 'none';
 document.getElementById(id).style.visibility = 'hidden';
}

function toggle () {
	var control = 0;
	for (i = 0; i < document.getElementById('pre_form').length; i++) {
		Element = document.getElementById('pre_form').elements[i];
		if (Element.type == 'radio' && Element.checked) {
			control=1;
		}else if(Element.type == 'radio' && !Element.checked){
			control=0;
		}
		if (Element.type == 'checkbox') {
			if(control==1){
				Element.disabled = false; 
			}else{
				Element.disabled = true; 
			}
			Element.checked = false;
		}
	}
}
function check(){
var controlradio = 0;
var controlcheckbox = 0;
var orari=0;
//var nposti = document.form.nposti.value;
	for (i = 0; i < document.getElementById('pre_form').length; i++) {
		Element = document.getElementById('pre_form').elements[i];
		if (Element.type == 'radio' && Element.checked){
			controlradio=1;
		}
		if (Element.type == 'checkbox' && Element.checked) {
			controlcheckbox=1;
			orari=orari+1;
		}	
	}

	if((controlradio == 0 && controlcheckbox == 0) || (controlradio == 1 && controlcheckbox == 0) ){ // controllo incrociato
		alert('Scegli la fascia oraria! / Choose the time');
	}else if(document.getElementById('nposti').value=="" || isNaN(document.getElementById('nposti').value)){
		alert('Inserisci il numero dei posti! / Insert no. of places!');
	}else if(orari > 1){
		alert('Non č possibile prenotare 2 orari differenti per lo stesso giorno!');
	}else{
		$("#pre_form").attr("action",'prenotalocale.php?op=conferma'); 
		$("#pre_form").submit();
	}
}

function confirmAction(testo)
{
  action = confirm(testo)
  if (action==true)
    parent.self.location.href = 'index.php';
}


function comuni() {
	var count=0;
	//var test = $("input:checked[name='categoria']").val();
	var cat = $("#cat").val();
	
	count = $("input:checked[name='comuni[]']").length;
	if(count > 3){
		alert("Puoi selezionare non pių di 3 comuni");
	}else if(count == 0){
		alert("Devi selezionare almeno 1 comune");
	}else{
		for (i = 0; i < document.getElementById('form_1').length; i++) {
			Element = document.getElementById('form_1').elements[i];
			if (!Element.checked) {
				Element.disabled = true; 
			}
		}
		$("#form_1").attr("action",'lista.php?cat='+cat); 
		$("#form_1").submit();
		/*document.getElementById('form_1').action = "lista.php?cat="+cat;
		document.getElementById('form_1').submit();*/
		//document.form.action = "lista.php?cat="+cat;
		//document.form.submit();
	}
}


