
function cambiaImagen(imagen) {
	document.getElementById("cargador").src = imagen;
	imagen_nueva = new Image();
	imagen_nueva.src = imagen;
}

function avisar() {
	document.getElementById("envioFoto").style.display="block";
	degradado(0);
}

function convierteHexadecimal(num) {
    hexadecimal = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
    var hexaDec = Math.floor(num/16);
    var hexaUni = num - (hexaDec * 16);
    return hexadecimal[hexaDec] + hexadecimal[hexaUni];
}

function degradado(color_decimal, vuelta) {
    color_decimal=color_decimal+3;
    color_hexadecimal = convierteHexadecimal(color_decimal);
    var color = '#'+color_hexadecimal+color_hexadecimal+color_hexadecimal;
    document.getElementById("envioFoto").style.backgroundColor = color;
    if (color_decimal >= 255)
      color_decimal = 0;
    setTimeout("degradado("+color_decimal+")",0);
}

function ayuda(identificador, ver) {
	elemento = document.getElementById("formato_"+identificador);
	if (ver)
		elemento.style.display = "block";
	else
		elemento.style.display = "none";
}

function abre(direccion) {
	enviaFrame(direccion,'_self');
}

function envia(direccion, tipo, valor) {
	if (tipo==1) // Provincia
		enviaFrame(direccion+"/includes/anuncio/creacion/seleccion_provincia.php?pais="+valor ,"frmProvincia");
}

function devuelve(direccion, tipo, valor) {
	if (tipo==1) // Provincia, devuelve y abre población
	{
		enviaPrincipal(valor, "provincia");
		enviaFrame(direccion+"/includes/anuncio/creacion/seleccion_poblacion.php?provincia="+valor,"frmPoblacion");
	}
	if (tipo==2) // Población, devuelve y abre barrio
	{
		enviaPrincipal(valor, "poblacion");
		enviaFrame(direccion+"/includes/anuncio/creacion/seleccion_barrio.php?poblacion="+valor,"frmBarrio");
	}
	if (tipo==3) // Barrio, devuelve
	{
		enviaPrincipal(valor, "barrio");
	}
}

function enviaFrame(direccion, frame) {
	window.open(direccion,frame);
}

function enviaPrincipal(valor, id) {
	documento = window.parent;
	documento.document.getElementById(id).value=valor;
}

function addEvent(obj, evType, fn){ 
	 if (obj.addEventListener){ 
	   obj.addEventListener(evType, fn, false); 
	   return true; 
	 } else if (obj.attachEvent){ 
	   var r = obj.attachEvent("on"+evType, fn); 
	   return r; 
	 } else { 
	   return false; 
	 } 
}

addEvent(window, 'load', funciones);

function funciones() {
	if (document.getElementById("pais") && document.getElementById("tipoBuscador")) {
		addEvent(document.getElementById("pais"), 'change', cambiaPais);
	}
	if (document.getElementById("provincia") && document.getElementById("tipoBuscador")) {
		addEvent(document.getElementById("provincia"), 'change', cambiaProvincia);
	}
	if (document.getElementById("poblacion") && document.getElementById("tipoBuscador")) {
		addEvent(document.getElementById("poblacion"), 'change', cambiaPoblacion);
	}
}

function cambiaPais() {
	window.open("http://www.kuadrats.com/index.php?buscador="+document.getElementById("tipo").value+"&pais="+document.getElementById("pais").value,"_self");
}

function cambiaProvincia() {
	window.open("http://www.kuadrats.com/index.php?buscador="+document.getElementById("tipo").value+"&pais="+document.getElementById("pais").value+"&provincia="+document.getElementById("provincia").value,"_self");
}

function cambiaPoblacion() {
	window.open("http://www.kuadrats.com/index.php?buscador="+document.getElementById("tipo").value+"&pais="+document.getElementById("pais").value+"&provincia="+document.getElementById("provincia").value+"&poblacion="+document.getElementById("poblacion").value,"_self");
}
