/* ---------------------------- */
/* XMLHTTPRequest Enable 		*/
/* ---------------------------- */
function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
	request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_type = new XMLHttpRequest();
	}
		return request_type;
}

var http = createObject();

/* -------------------------- */
/* SEARCH					 */
/* -------------------------- */
function autosuggest() {
q = document.getElementById('campo').value;
// Set te random number to add to URL request
nocache = Math.random();
http.open('get','../buscador/search.php?q='+q+'&nocache = '+nocache);
http.onreadystatechange = autosuggestReply;
http.send(null);
}
function autosuggestReply() {
if(http.readyState == 4){
	var response = http.responseText;
	e = document.getElementById('results');
	if(response!=""){
		e.innerHTML=response;
		e.style.display="block";
	} else {
		e.style.display="none";
	}
}
}

//per poder usar 2 a l'hora
function autosuggest2() {
q = document.getElementById('campo2').value;
// Set te random number to add to URL request
nocache = Math.random();
http.open('get','../buscador/search2.php?q='+q+'&nocache = '+nocache);
http.onreadystatechange = autosuggestReply2;
http.send(null);
}
function autosuggestReply2() {
if(http.readyState == 4){
	var response = http.responseText;
	e = document.getElementById('results2');
	if(response!=""){
		e.innerHTML=response;
		e.style.display="block";
	} else {
		e.style.display="none";
	}
}
}
//PER EDITOR
function autosuggest3() {
q = document.getElementById('campo').value;
// Set te random number to add to URL request
nocache = Math.random();
http.open('get','../buscador/search3.php?q='+q+'&nocache = '+nocache);
http.onreadystatechange = autosuggestReply3;
http.send(null);
}
function autosuggestReply3() {
if(http.readyState == 4){
	var response = http.responseText;
	e = document.getElementById('results');
	if(response!=""){
		e.innerHTML=response;
		e.style.display="block";
	} else {
		e.style.display="none";
	}
}
}
//fi per poder usar 2 a l'hora (cerca de aqui)
/* FUNCION PARA IR DIRECTAMENTE AL PRODUCTO EN LA SECCION DE CERCA DE AQUI
function salta2(i) {
location.href='http://<?=$?>/index.php?form=cerca&rest='+i;
}

/* FUNCION PARA IR DIRECTAMENTE AL PRODUCTO 
function salta(i) {
location.href='http://test.tramadigital.com/barcelona.asp?restaurante='+i;
}

/* 

PARA RELLENAR EL CAMPO DEL FURMULARIO AL CLICAR EN LUGAR DE IR DIRECTAMENTE
1.- CAMBIAR EN EL LINK DEL DESPLEGABLE
salta('<?php echo $row['link'];  ?>');
POR
fill('<?php echo htmlentities($row['nom']);?>')
2.- DESCOMENTAR LA SIGUIENTE FUNCION fill

function fill(i) {
document.getElementById('campo').value=i;
document.getElementById('results').style.display='none';
}

*/


