// JavaScript Document

	function objAjax()
	{ 
		/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
		lo que se puede copiar tal como esta aqui */
		var xmlhttp=false; 
		try 
		{ 
			// Creacion del objeto AJAX para navegadores no IE
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch(e)
		{ 
			try
			{ 
				// Creacion del objet AJAX para IE 
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
			} 
			catch(E) { xmlhttp=false; }
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 
	
		return xmlhttp; 
	}
/*
	function setData(titulo, x, y, estado, ultimoId) {		
		ajax=objAjax();
		ajax.open("GET", "setData.php?titulo="+titulo+"&posx="+x+"&posy="+y+"&estado="+estado+"&ultimoId="+ultimoId, true);
		ajax.onreadystatechange = function() { 
			if (ajax.readyState==1) {
				retorno = document.getElementById("textoX");
				retorno.innerHTML = '<img src="images/bigrotation2.gif" alt="Cargando..." width="32" height="32" title="Cargando..." />';
			}
			if (ajax.readyState==4) { 
				retorno = document.getElementById("textoX");
				retorno.innerHTML = ajax.responseText;								
			} 
		}
		ajax.send(null);
		return 0;
	}
*/	
	function getValorModelo() {		
		var idModelo = document.form1a1.modelo.value;
		var enganche;
		if (idModelo != -1) {
			ajax=objAjax();				
			ajax.open("GET", "getValorVivienda.php?idModelo="+idModelo, true);
			ajax.onreadystatechange = function() { 
				if (ajax.readyState==1) {
					document.getElementById("xPreciosx").value = "Cargando datos..";
				}
				if (ajax.readyState==4) { 		
					document.getElementById("xPreciosx").value = "Q." + ajax.responseText;
					enganche = ajax.responseText * 0.10;
					document.getElementById("enganche5").value = "Q." + enganche;
					document.getElementById("xval5x").value = ajax.responseText * 0.010;
					
					document.getElementById("xpreciox").value = ajax.responseText;
					document.getElementById("xenganchex").value = enganche;
				} 
			}
			ajax.send(null);
		} else {
			document.getElementById("xPreciosx").value = "...";
			document.getElementById("enganche5").value = "...";
			document.getElementById("xval5x").value = "";
		}
		return 0;
	}
	
	
	function getValorModelo2() {		
		var idModelo = document.form2a1.modelo2.value;
		var enganche;
		if (idModelo != -1) {
			ajax=objAjax();				
			ajax.open("GET", "getValorVivienda.php?idModelo="+idModelo, true);
			ajax.onreadystatechange = function() { 
				if (ajax.readyState==1) {
					document.getElementById("xPreciosPortadax").value = "Cargando datos..";
				}
				if (ajax.readyState==4) { 		
					document.getElementById("xPreciosPortadax").value = "Q." + ajax.responseText;
					enganche = ajax.responseText * 0.10;
					document.getElementById("enganchePortada").value = "Q." + enganche;
					document.getElementById("xvalPortadax").value = ajax.responseText * 0.010;
					
					document.getElementById("xPreciosPortadax2").value = ajax.responseText;
					document.getElementById("xenganchePortadax").value = enganche;
				} 
			}
			ajax.send(null);
		} else {
			document.getElementById("xPreciosx").value = "...";
			document.getElementById("enganche5").value = "...";
			document.getElementById("xvalPortadax").value = "";
		}
		return 0;
	}


	//FUNCIONES PARA PORTADA
	function getModelosPortada() {		
		var idModelo = document.formport.proyectos.value;
		var enganche;
		if (idModelo != -1) {
			ajax=objAjax();				
			ajax.open("GET", "getModeloVivienda.php?idProyecto="+idModelo, true);
			ajax.onreadystatechange = function() { 
				if (ajax.readyState==1) {
					//document.getElementById("modeloSelect").value = "Cargando datos..";
				}
				if (ajax.readyState==4) { 		
					document.getElementById("modelosProyecto").innerHTML =ajax.responseText;				} 
			}
			ajax.send(null);
		} else {
			//document.getElementById("xPreciosx2").value = "...";
			//document.getElementById("enganche52").value = "...";
			//document.getElementById("xval5x2").value = "";
		}
		return 0;
	}

	function   getValorModeloPortada() {		
		var idModelo = document.formport.modeloSelectPortada.value;
		var enganche;
		if (idModelo != -1) {
			ajax=objAjax();				
			ajax.open("GET", "getValorViviendaPortada.php?idModelo="+idModelo, true);
			ajax.onreadystatechange = function() { 
				if (ajax.readyState==1) {
					document.getElementById("xPreciosPortadax").value = "Cargando datos..";
				}
				if (ajax.readyState==4) { 		
					document.getElementById("xPreciosPortadax").value = "Q." + ajax.responseText;
					enganche = ajax.responseText * 0.10;
					document.getElementById("enganchePortada").value = "Q." + enganche;
					document.getElementById("xvalPortadax").value = ajax.responseText * 0.010;
					
					document.getElementById("xPreciosPortadax").value = ajax.responseText;
					document.getElementById("xPreciosPortadax2").value = enganche;
				} 
			}
			ajax.send(null);
		} else {
			document.getElementById("xPreciosPortadax").value = "...";
			document.getElementById("enganchePortada").value = "...";
			document.getElementById("xvalPortadax").value = "";
		}
		return 0;
	}
///-------------\\\
	function getValorModeloVillaVermont() {		
		var idModelo = document.form3a1.modelo.value;
		var enganche;
		if (idModelo != -1) {
			ajax=objAjax();				
			ajax.open("GET", "getValorVivienda.php?idModelo="+idModelo, true);
			ajax.onreadystatechange = function() { 
				if (ajax.readyState==1) {
					document.getElementById("xPreciosx").value = "Cargando datos..";
				}
				if (ajax.readyState==4) { 		
					document.getElementById("xPreciosx").value = "Q." + ajax.responseText;
					enganche = ajax.responseText * 0.2;
					document.getElementById("enganche5").value = "Q." + enganche;
					document.getElementById("xval5x").value = (ajax.responseText * 0.02);
					
					document.getElementById("xpreciox").value = ajax.responseText;
					document.getElementById("xenganchex").value = enganche;
				} 
			}
			ajax.send(null);
		} else {
			document.getElementById("xPreciosx").value = "...";
			document.getElementById("enganche5").value = "...";
			document.getElementById("xval5x").value = "";
		}
		return 0;
	}


function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function ReloadModeloItem(id_modelo, opcion)
{
	ajax=nuevoAjax();
	ajax.open("GET", "reload_modeloItem.php?id="+id_modelo+"&opcion="+opcion, true);
	
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
		}
		if (ajax.readyState==4)
		{ 
			document.getElementById('ModeloDescription').style.visibility='visible';
			document.getElementById('ModeloDescription').innerHTML=ajax.responseText;
		} 
	}
		ajax.send(null);
}
