function searchhouse(tipo,form)
{	
	if (tipo==3) where=" where evidenza=1 ";
	else where=" where tipo="+tipo+" ";
	if (form.dove.selectedIndex!=0) where=where+" and dove="+(form.dove.selectedIndex-1);
	orderby=form.orderby.options[form.orderby.selectedIndex].value;

	if (tipo==2) {
		c=new Array();
		for (i=0;i<form.elements['periodi[]'].length;i++){
			if (form.elements['periodi[]'][i].checked) c.push(form.elements['periodi[]'][i].value);
		}
		if (c.length>0){
			where=where + " and (periodi LIKE \"%,"+c[0]+",%\" ";
			 for (i=1;i<c.length;i++){
				 where=where+" or periodi LIKE \"%,"+c[i]+",%\" ";
			 }
			where=where + " )";
		}
		
	}
	if (form.mare.selectedIndex!=0){
		 where=where+form.mare.options[form.mare.selectedIndex].value;
	}
	if (form.camere.selectedIndex!=0){
		 where=where+" and camere="+form.camere.options[form.camere.selectedIndex].value+" ";
	}
	if (form.mq.selectedIndex!=0){
		 where=where+form.mq.options[form.mq.selectedIndex].value;
	}
	obj=document.getElementById("listacase");
	obj.src="listacase.php?op=find&where="+where+"&orderby="+orderby+"&tipo="+tipo;
	return false;
}
		function validate(form)
		{	
			if (form.nome.value=="")
			{
				alert("Il campo Nome non puņ essere vuoto!");
				return false;
			}
			if (form.cognome.value=="")
			{
				alert("Il campo Cognome non puņ essere vuoto!");
				return false;
			}
			if (form.CAP.value=="")
			{
				alert("Il campo CAP non puņ essere vuoto!");
				return false;
			}
			if (form.email.value=="" || !checkemail(form.email.value))
			{
				alert("L'indirizzo E-mail inserito non č valido!");
				return false;
			}
			
			cliccato=0;

			for (i=0; i<form.elements['interessi[]'].length; i++){
				if (form.elements['interessi[]'][i].checked) {
					cliccato++;
				}
			}
			
			if (cliccato<1)
			{
				alert("Devi selezionare almeno un interesse!");
				return false;
			}
			
			if (form.richiesta.value=="")
			{
				alert("Il campo richiesta non puņ essere vuoto!");
				return false;
			}
			if (!form.elements['privacy'].checked)
			{
				alert("Per inviare la richiesta č necessario dare il consenso al trattamento dei propri dati personali!");
				return false;
			}
			form.submit();
			
		}
function checkemail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)) return true
	else return false
}
function checkdate(data)
{
	var my_date = new Date();
	var myArray = data.split('/'); 
	if(myArray.length!=3) {
		return false;
	} else {
		d=myArray[0];
		m=myArray[1];
		y=myArray[2];
	}
	
	if (isNaN(myArray[0]) || isNaN(myArray[1]) || isNaN(myArray[2])){
		return false;
	}
	
	var yl=my_date.getYear(); // least year to consider
	var ym=my_date.getYear()+2; // most year to consider
	if (m<1 || m>12) return(false);
	if (d<1 || d>31) return(false);
	if (y<yl || y>ym) return(false);
	if (m==4 || m==6 || m==9 || m==11)
	if (d==31) return(false);
	if (m==2)
	{
		var b=parseInt(y/4);
		if (isNaN(b)) return(false);
		if (d>29) return(false);
		if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
	}
	return(true);
}

function limite(inferiore,superiore)
{
	var inf = inferiore.split('/'); 
	var sup = superiore.split('/'); 

	if (parseInt(inf[2])>parseInt(sup[2])) {
		return false;
	} else{
		if (parseInt(inf[2])==parseInt(sup[2])){
			if (parseInt(inf[1])>parseInt(sup[1])) {
				return false;
			} else {
				if (parseInt(inf[1])==parseInt(sup[1])){
					if (parseInt(inf[0])>=parseInt(sup[0])) {
						return false;
					}
				}
			}
		}
	}
	return true;
}
