// JavaScript Document

function focusCampoBusqueda(){
	//Función para borrar el campo de búsqueda al entrar en él.
	campo = document.getElementById('empresaPoligono');
	campo.style.color = "#000";
	if(campo.value == "Introduzca Empresa o Poligono"){
		campo.value = "";
	}
	return true;
}
function blurCampoBusqueda(tp){
	//Función para poner texto en el campo de búsqueda si al salir de él está vacío.
	campo = document.getElementById('empresaPoligono');
	busqueda_ag = document.getElementById('tipo_busqueda_ag');
	if(busqueda_ag.checked == true || tp == 1){
		if(campo.value == ""){
			campo.value = "Introduzca Empresa o Poligono";
			campo.style.color = "#CCC";
		}else if(campo.value == "Introduzca Empresa o Poligono"){
			campo.value = "";
			campo.style.color = "#000";
		}else{
			campo.style.color = "#000";	
		}
	}else{
		if(campo.value == "Introduzca Empresa o Poligono"){
			campo.value = "";
		}
		campo.style.color = "#000";
	}
	return true;
}
function copyBusqueda(dato){
	var empPol = document.getElementById('empresaPoligono');
	empPol.value = dato;
	return true;
}
function hideResultado(){
	var divResultados = document.getElementById('resultadoBusqueda');
	divResultados.style.display = 'none';
	return true;
}
function searchResult(){
	var campo = document.getElementById('empresaPoligono');
	var tp_ag = document.getElementById('tipo_busqueda_ag');
	var tp_go = document.getElementById('tipo_busqueda_go');
	var tp_all = document.getElementById('tipo_busqueda_all');
	if(campo.value == "Introduzca Empresa o Pol&iacute;gono" || campo.value == "Introduzca Empresa o Polígono" || campo.value == ""){
		alert("Indique la búsqueda que desee realizar");
		campo.focus();
		return false;
	}
	
	if(tp_ag.checked){
		document.location.href='b_rapida.php?nombre='+escape(campo.value);
	}else if(tp_go.checked){
		window.open("http://www.google.es/search?hl=es&q="+escape(campo.value));
	}else if(tp_all.checked){
		document.location.href='b_rapida_all.php?nombre='+escape(campo.value);
	}
	return true;
}
function checkKey(event)
{
	// if (moz) else ie
	if(event.which)
	mykey = event.which;
	else
	mykey = event.keyCode;
	// if chr(13) a.k.a ENTER is pressed
	if(mykey == 13)
	{
	// show me that it's trying to stop it
	searchResult();	
	
	// stop event propagation, keep the KEYPRESS from continuing?
	if(event.stopPropagation)
	event.stopPropagation();
	
	// prevent default action, is this SUBMIT?
	if(event.preventDefault)
	event.preventDefault();
	
	// for IE: cancel event bubble and clear return value
	event.cancelBubble = true;
	event.returnValue = false;
	}
}

function sendKey(){
	var tp = document.getElementById('tipo_busqueda_ag');
	if(tp.checked){
		buscarDato('ep');
	}		
	return true;
}
