function submit_ricerca(tipo_ricerca, lingua)
{
	document.getElementById('response_ricerca').innerHTML="";
	var p;
	switch(tipo_ricerca)
	{
		case 1:
			var p = document.forms['ric_codice'];
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca; 
			JSONObject.lingua=lingua; 
			JSONObject.start_page=0; 
			JSONObject.codice = p['codice'].value;
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
			break;
		case 2:
			var p = document.forms['affitti_brevi'];
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca;
			JSONObject.lingua=lingua; 
			JSONObject.start_page=0; 
			JSONObject.data_da = p['data_da'].value;
			JSONObject.data_a = p['data_a'].value;
			JSONObject.zona = p['zona'].value;
			JSONObject.tipologia = p['tipologia'].value;
			JSONObject.posti_letto = p['posti_letto'].value;
			JSONObject.prezzo = p['prezzo'].value;
			if (p['solo_disponibili'].checked)
				JSONObject.solo_disp = p['solo_disponibili'].value;
			else
				JSONObject.solo_disp = 0;
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
			break;
		case 3:
			var p = document.forms['affitti_lunghi'];
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca;
			JSONObject.lingua=lingua; 
			JSONObject.start_page=0; 
			JSONObject.contratti = p['contratti'].value;
			JSONObject.zona = p['zona'].value;
			JSONObject.tipologia = p['tipologia'].value;
			JSONObject.vani = p['vani'].value;
			JSONObject.superficie = p['superficie'].value;
			JSONObject.prezzo = p['prezzo'].value;
			if (p['solo_arredati'].checked)
				JSONObject.solo_arr = p['solo_arredati'].value;
			else
				JSONObject.solo_arr = 0;
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
			break;
		default:
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca;
			JSONObject.lingua=lingua; 
			JSONObject.start_page=0; 
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
	}
}

function ricerca_pag(tipo_ricerca, codice, data_da, data_a, tipologia, zona, posti_letto, vani, superficie, prezzo, contratti, start_page, lingua, disp, arr)
{
	document.getElementById('response_ricerca').innerHTML="";
	var p;
	switch(tipo_ricerca)
	{
		case 1:
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca; 
			JSONObject.lingua=lingua; 
			JSONObject.start_page=start_page; 
			JSONObject.codice = codice;
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
			break;
		case 2:
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca;
			JSONObject.lingua=lingua; 
			JSONObject.start_page=start_page; 
			JSONObject.data_da = data_da;
			JSONObject.data_a = data_a;
			JSONObject.zona = zona;
			JSONObject.tipologia = tipologia;
			JSONObject.posti_letto = posti_letto;
			JSONObject.prezzo = prezzo;
			JSONObject.solo_disp = disp;
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
			break;
		case 3:
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca;
			JSONObject.lingua=lingua; 
			JSONObject.start_page=start_page; 
			JSONObject.contratti = contratti;
			JSONObject.zona = zona;
			JSONObject.tipologia = tipologia;
			JSONObject.vani = vani;
			JSONObject.superficie = superficie;
			JSONObject.prezzo = prezzo;
			JSONObject.solo_arr = arr;
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
			break;
		default:
			var JSONObject = new Object;
			JSONObject.tipo_ricerca=tipo_ricerca;
			JSONObject.lingua=lingua; 
			JSONObject.start_page=start_page; 
			JSONstring = JSON.stringify(JSONObject);
    		getMessageResponse_ricerca(JSONstring);
	}
}

function getMessageResponse_ricerca(str)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('wait_ricerca').style.visibility = "hidden";
			document.getElementById('response_ricerca').innerHTML=xmlHttp.responseText;
		}
		else
		{
			document.getElementById('wait_ricerca').style.visibility = "visible";
		}

	}

	var url="php_script/ricerca_index.php";
	var content = "data="+str;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", content.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(content);
}

