var url_;
url_ = "";

function comprobar()
{
	var ok = 'si';
	var cadena = '';
	document.getElementById('busqueda777').setAttribute("autocomplete", "off");
	if (document.getElementById('actividad').value == '' && document.getElementById('nombre').value == '')
	{
		ok = 'no';
	}

	if (ok == 'no')
	{
		alert('Introduzca al menos una actividad o un nombre de empresa para buscar');
		return false;
	}
	else
	{
		var contador = document.getElementById('actividad').value;
		var cadena_inicial;
		if(contador.length > 0 && contador.length < 3 && document.getElementById('nombre').value == '')
		{
			cadena_inicial = 'actividad=' + document.getElementById('actividad').value;
			if(document.getElementById('provincia').value != '')
			{
				cadena_inicial = cadena_inicial + '&provincia=' + document.getElementById('provincia').value;
			}
			if(document.getElementById('poblacion').value != '')
			{
				cadena_inicial = cadena_inicial + '&poblacion=' + document.getElementById('poblacion').value;
			}
			window.location = '/resultados_inicial.asp?' + cadena_inicial;
		}
		else
		{
			if(document.getElementById('actividad').value != '')
			{
				cadena = 'actividad=' + document.getElementById('actividad').value;
			}
			if(document.getElementById('nombre').value != '')
			{
				if(document.getElementById('actividad').value != '')
				{
					cadena = cadena + '&';
				}
				cadena = cadena + 'nombre=' + document.getElementById('nombre').value;
			}
			if(document.getElementById('provincia').value != '')
			{
				cadena = cadena + '&provincia=' + document.getElementById('provincia').value;
			}
			if(document.getElementById('poblacion').value != '')
			{
				cadena = cadena + '&poblacion=' + document.getElementById('poblacion').value;
			}
			cadena = quitarAcentos(cadena)
			for(i = 0; i < cadena.length; i++)
			{
				cadena = cadena.replace("´", "%B4")
				cadena = cadena.replace("'", "%B4")
				cadena = cadena.replace("`", "%B4")
			}
			window.location = '/resultados.asp?' + cadena;
		}
	}
}

function quitarAcentos(texto)
{
	var quitarAcentos
	quitarAcentos = texto.replace("á", "a");
	quitarAcentos = quitarAcentos.replace("é", "e");
	quitarAcentos = quitarAcentos.replace("í", "i");
	quitarAcentos = quitarAcentos.replace("ó", "o");
	quitarAcentos = quitarAcentos.replace("ú", "u");
	quitarAcentos = quitarAcentos.replace("à", "a");
	quitarAcentos = quitarAcentos.replace("è", "e");
	quitarAcentos = quitarAcentos.replace("ì", "i");
	quitarAcentos = quitarAcentos.replace("ò", "o");
	quitarAcentos = quitarAcentos.replace("ù", "u");
	quitarAcentos = quitarAcentos.replace("ä", "a");
	quitarAcentos = quitarAcentos.replace("ë", "e");
	quitarAcentos = quitarAcentos.replace("ï", "i");
	quitarAcentos = quitarAcentos.replace("ö", "o");
	quitarAcentos = quitarAcentos.replace("ü", "u");
	return quitarAcentos;
}

function esEnter(ev)
{
	tecla = (document.all) ? ev.keyCode : ev.which;
 	if (tecla == 13)
 	{
		detectarLenguaje();
	}
}

function ponerIdiomaSession(idioma)
{
	if(window.XMLHttpRequest)
	{
		objXml1 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
	}
	else if(window.ActiveXObject)
	{
		objXml1 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
	}
	objXml1.open("GET", "/_idiomaSession.asp?idioma=" + idioma, true);
	objXml1.onreadystatechange = function()
	{
	}
	objXml1.send(null);
}

function quitarIdiomaSession()
{
	if(window.XMLHttpRequest)
	{
		objXml1 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
	}
	else if(window.ActiveXObject)
	{
		objXml1 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
	}
	objXml1.open("GET", "/_idiomaSessionDestroy.asp", true);
	objXml1.onreadystatechange = function()
	{
		if(objXml1.readyState == 4)
		{
			window.location = objXml1.responseText;
		}
	}
	objXml1.send(null);
}

function traducir(capa,origen,destino)
{
	var texto;
	texto = document.getElementById(capa).innerHTML;
	google.language.translate(texto, origen, destino, function(result)
	{
		if (!result.error)
		{
			var container = document.getElementById(capa);
			container.innerHTML = result.translation;
		}
	});
}

function traducir_input(capa,origen,destino)
{
	var texto;
	texto = document.getElementById(capa).value;
	google.language.translate(texto, origen, destino, function(result)
	{
		if (!result.error)
		{
			var container = document.getElementById(capa);
			container.value = result.translation;
		}
	});
}

function cambiarIdioma(language_)
{
	_language_ = "es";
	switch(language_)
	{
		case 'SPANISH':
			_language_ = "es";
			break;
		case 'CATALAN':
			_language_ = "ca";
			break;
		case 'GALICIAN':
			_language_ = 'gl';
			break;
		case 'BASQUE':
			_language_ = 'eu';
			break;
		case 'ENGLISH':
			_language_ = 'en';
			break;
		case 'ITALIAN':
			_language_ = 'it';
			break;
		case 'GERMAN':
			_language_ = 'de';
			break;
		case 'FRENCH':
			_language_ = 'fr';
			break;
	}

	ponerIdiomaSession(_language_)

	google.language.translate(document.getElementById("actividad").value, _language_, "es", function(result)
	{
		if (!result.error)
		{
			 document.getElementById("actividad").value = result.translation;
			 comprobar();
		}
	});
}

function detectarLenguaje()
{
	text = document.getElementById("actividad").value
	if(window.XMLHttpRequest)
	{
		objXml11 = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
	}
	else if(window.ActiveXObject)
	{
		objXml11 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
	}
	objXml11.open("GET", "/ajax/buscar_termino.asp?text=" + text , true);
	objXml11.onreadystatechange = function()
	{
		if (objXml11.readyState == 4)
		{
			text = objXml11.responseText.toLowerCase();
			if(text == "" || text == "aparejador" || text == "aparejadores" || text == "albañil" || text == "albañiles" || text == "albañileria" || text == "albanil" || text == "albaniles" || text == "mudanzas" || text == "sexshops" || text == "taxis" || text == "autotaxis" || text == "pavimentos" || text == "manualidades" || text == "manualidades y artes" || text == "materiales para manualidades y artes" || text == "ebanisteria" || text == "ebanisterias" || text == "agencias de viaje" || text == "agencias de viajes" || text == "hotel" || text == "hoteles" || text == "complementos" || text == "inmobiliaria" || text == "inmobiliarias" || text == "disfraces" || text == "disfraces y articulos de fiesta" || text == "disfraces y art&iacute;culos de fiesta" || text == "balneario" || text == "balnearios" || text == "fincas" || text == "pelucas" || text == "estetica" || text == "est&eacute;tica" || text == "laboratorio" || text == "magia" || text == "malabares" || text == "magia y malabares" || text == "informatica" || text == "inform&aacute;tica" || text == "carpinter&iacute;as de aluminio" || text == "renovables" || text == "alternativa" || text == "alternativas" || text == "energias alternativas y renovables" || text == "notario" || text == "notarios" || text == "gestoria" || text == "gestor&iacute;a" || text == "dietetica" || text == "diet&eacute;tica" || text == "carpinterias de aluminio" || text == "artesania" || text == "copisterias" || text == "carbon" || text == "estufas" || text == "albergues" || text == "detective" || text == "privado" || text == "privada" || text == "privados" || text == "privadas" || text == "mesas" || text == "extensible" || text == "extensibles" || text == "mesas extensibles" || text == "decoradores y diseñadores" || text == "charter" || text == "constructores" || text == "religiosos" || text == "bolsas" || text == "marketing" || text == "detectives" || text == "descenso" || text == "bicicletas" || text == "rutas" || text == "senderismo" || text == "bodegas" || text == "restaurantes" || text == "rocodromo" || text == "buggies" || text == "catering" || text == "jardin" || text == "extraescolares" || text == "gas" || text == "nautica" || text == "residencia" || text == "forja" || text == "marmoles" || text == "zoos" || text == "arquitectos" || text == "floristeria" || text == "reformas" || text == "camiserias" || text == "chalets" || text == "activo" || text == "prefabricadas" || text == "cafeteria" || text == "ingenier&iacute;a ac&uacute;stica" || text == "gr&uacute;as" || text == "acustica" || text == "arqueologia" || text == "castillos" || text == "chalet" || text == "talleres" || text == "asesor&iacute;as" || text == "automatismos" || text == "congresos" || text == "fontaneria" || text == "albergue" || text == "bocateria" || text == "fabricaci&oacute;n y bombeo de hormig&oacute;n" || text == "guarder&iacute;as" || text == "patron" || text == "patr&oacute;n")
			{
				comprobar();
			}
			else
			{
				var language = 'unknown';
				google.language.detect(text, function(result)
				{
					if(!result.error)
					{
						for(l in google.language.Languages)
						{
							if(google.language.Languages[l] == result.language)
							{
								language = l;
								break;
							}
						}
						if(language != "SPANISH")
						{
							cambiarIdioma(language);
						}
						else
						{
							comprobar();
						}
					}
				});
			}
		}
	}
	objXml11.send(null);
}

function MM_validateForm()
{
	if(document.getElementById('codPos').value == "" || document.getElementById('provi').value == "" || document.getElementById('pobla').value == "")
	{
		alert("Por favor, rellene los campos con *");
		return false;
 	}
	else
	{
		if(document.getElementById('codPos').value.length != 5)
		{
			alert("El Código Postal tiene que ser de 5 caracteres");
			return false;
		}
		else
		{
			if(isNaN(document.getElementById('codPos').value))
			{
				alert("El Código Postal tiene que ser numérico");
				return false;
			}
			else
			{
				return true;
			}
		}
  	}
}
