// JavaScript Document
function antispam(cuenta,dominio,clase)
{
	document.write("<a class='"+ clase +"' href=\"mailto:" + cuenta + "@" + dominio + "\">" + cuenta + "@" + dominio + "</a>");
}

function googlekey(keyabajo,kayarriba,domabajo,domarriba){
	var documento = self.location.href.match( /\/([^/]+)$/ )[1];
	if (document.location.href == 'http://servidor.'+ domabajo +'/'+ documento)
	{
		document.write("<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key="+ keyabajo +"' type='text/javascript'></script>");
	}
	else
	{
		if (document.location.href == 'http://'+ domarriba +'/'+ documento);
		{
			document.write("<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key="+ kayarriba +"' type='text/javascript'></script>");
		}
	}
}

function desplegar(capa){
	if (capa == 'memoria')
	{
		document.getElementById('ico_localizacion').src='./imagenes/localizacionoff.gif';
		document.getElementById('ico_memoria').src='./imagenes/memoriaon.gif';
		document.getElementById('nombre_localizacion').className='capa_ficha_seccion_off';
		document.getElementById('nombre_memoria').className='capa_ficha_seccion_on';
		document.getElementById('localizacion2').className='localizacion2off';
		document.getElementById('localizacion3').className='localizacion3off';
		document.getElementById('memoria').style.display='';
	}
	if (capa == 'planos')
	{
		document.getElementById('ico_localizacion').src='./imagenes/localizacionoff.gif';
		document.getElementById('ico_memoria').src='./imagenes/memoriaoff.gif';
		document.getElementById('nombre_localizacion').className='capa_ficha_seccion_off';
		document.getElementById('nombre_memoria').className='capa_ficha_seccion_off';
		document.getElementById('localizacion2').className='localizacion2off';
		document.getElementById('localizacion3').className='localizacion3off';
		document.getElementById('memoria').style.display='none';
	}
	if (capa == 'localizacion')
	{
		document.getElementById('ico_localizacion').src='./imagenes/localizacionon.gif';
		document.getElementById('ico_memoria').src='./imagenes/memoriaoff.gif';
		document.getElementById('nombre_localizacion').className='capa_ficha_seccion_on';
		document.getElementById('nombre_memoria').className='capa_ficha_seccion_off';
		document.getElementById('localizacion2').className='localizacion2on';
		document.getElementById('localizacion3').className='localizacion3on';
		document.getElementById('memoria').style.display='none';
	}
}

function fecha(){
	var mydate=new Date();
	var year=mydate.getYear();
	if (year < 1000)
		year+=1900;
	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();
	if (daym<10)
	daym="0"+daym;
	var dayarray=new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado");
	var montharray=new Array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
	document.write(dayarray[day] + " " + daym + " " + montharray[month] + "." + year);
}

function hora(){
	
	if (!document.layers&&!document.all&&!document.getElementById)
	return
	var Digital=new Date()
	var hours=Digital.getHours()
	var minutes=Digital.getMinutes()
	var seconds=Digital.getSeconds()
	var dn="AM" 
	if (hours>12){
	dn="PM"
	hours=hours-12
	}
	if (hours==0)
	hours=12
	if (hours<=9)
	hours="0"+hours
	if (minutes<=9)
	minutes="0"+minutes
	if (seconds<=9)
	seconds="0"+seconds
	//change font size here to your desire
	myclock=hours+":"+minutes+":"+seconds
	if (document.layers){
	document.layers.liveclock.document.write(myclock)
	document.layers.liveclock.document.close()
	}
	else if (document.all)
	liveclock.innerHTML=myclock
	else if (document.getElementById)
	document.getElementById("liveclock").innerHTML=myclock
	setTimeout("hora()",1000)
								
}

function opcionmenu(){
	if ((self.location.href == 'http://servidor.promocad/') || (self.location.href == 'http://www.promocad.com/'))
	{
		var marcado='index';
	}
	else
	{
		var documento = self.location.href.match( /\/([^/]+)$/ )[1];
		marcado = documento.replace(".aspx","");
	}
	
	if (document.getElementById(marcado)!=null)
	{
		document.getElementById(marcado).className='capa_menu_seccion_on';
		document.getElementById(marcado).onmouseout=function(){}
	}
}


//google maps
var map;
		var to_htmls = [];
	    var from_htmls = [];
		var gmarkers = [];
	    var htmls = [];
		function tohere(i) {
		   gmarkers[i].openInfoWindowHtml(to_htmls[i]);
		}
		function fromhere(i) {
		   gmarkers[i].openInfoWindowHtml(from_htmls[i]);
		}
	function onLoad(lat,long,bocadillo,lat1,long1,lat2,long2,lat3,long3,lat4,long4) {
	if (GBrowserIsCompatible()){
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(lat,long), 7);
		map.setMapType(G_NORMAL_MAP);
		
		function createMarker(point,html,icono,bsnr) {
			var marker = new GMarker(point,icono);
			to_htmls[bsnr] = html + '<br><br>Obtener indicaciones: <b>hasta aqu&iacute;</b> - <a href="javascript:fromhere(' + bsnr + ')" class="enlace_mapa">desde aqu&iacute;</a>' +
            '<br>Lugar de partida:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
            '<input type="text" class="caja_mapa" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
            '<INPUT class="boton_mapa" value="OK" TYPE="SUBMIT">' +
            '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() +
            // "(" + name + ")" +
             '"/>';
			
			from_htmls[bsnr] = html + '<br><br>Obtener indicaciones: <a href="javascript:tohere(' + bsnr + ')" class="enlace_mapa">hasta aqu&iacute;</a> - <b>desde aqu&iacute;</b>' +
             '<br>Destino:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
             '<input type="text" class="caja_mapa" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
             '<INPUT class="boton_mapa" value="OK" TYPE="SUBMIT">' +
             '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                  // "(" + name + ")" +
             '"/>';
			
			//html = "<div>"+ html +"<\/div>";			
			
			GEvent.addListener(marker, "click", function() {
				if (map.getZoom()<17){
				map.setCenter(point, 17);
				}
			});
			if (bocadillo==1)
			{
				GEvent.addListener(marker, "mouseover", function() {
					marker.openInfoWindow(html);
				});
			}
			GEvent.addListener(marker, "dblclick", function() {
				if (map.getZoom()<17){
					map.setCenter(point, 17);
				}
			});
			gmarkers[bsnr] = marker;
          	htmls[bsnr] = html;
			html = html + '<br>Obtener indicaciones: <a href="javascript:tohere('+ bsnr +')" class="enlace_mapa">hasta aqu&iacute;</a> - <a href="javascript:fromhere('+ bsnr +')" class="enlace_mapa">desde aqu&iacute;</a>';
		return marker;
		}
		var punto = new GLatLng(lat,long);
		var marca = createMarker(punto,"<strong>Promocad Inmobiliaria S.L.<\/strong><br />Paseo Juan Carlos I, 19, 4&ordm;B, 04700 El Ejido (Almer&iacute;a)<br />04700 El Ejido(Almer&iacute;a)<br />Tel.:<strong> +34 696 93 80 78<\/strong><br /><br/><a href='mailto:info@promocad.com' class='enlace_mapa'>info@promocad.com<\/a>");
		GBrowserIsCompatible(marca);
		if (bocadillo==0)
		{
		var polygon = new GPolygon([
            new GLatLng(lat1,long1),
            new GLatLng(lat2,long2),
            new GLatLng(lat3,long3),
            new GLatLng(lat4,long4),
            new GLatLng(lat1,long1)
		  ], "#007676", 2, 1, "#FF9E01", 0.6);
		  map.addOverlay(polygon);
		  map.addOverlay(marca);
		}
		else{
			map.addOverlay(marca);
		}
	}
}

//Función que permite solo meter enteros en un INPUT
function esEntero(e){
	var charCode
	
	if (navigator.appName == "Netscape") // Veo si es Netscape o Explorer (mas adelante lo explicamos)
		charCode = e.which // leo la tecla que ingreso
	else
		charCode = e.keyCode // leo la tecla que ingreso
	status = charCode 
	if (charCode > 31 && (charCode < 48 || charCode > 57)) { // Chequeamos que sea un numero comparandolo con los valores ASCII
		return false
	}
return true
}

// ----------------------------------------------------------------------------------
//Función que permite solo meter decimales en un INPUT
function esDecimal(campo,e){
	var charCode,i,decimales
	decimales = 0
	
	if (navigator.appName == "Netscape") // Veo si es Netscape o Explorer (mas adelante lo explicamos)
		charCode = e.which // leo la tecla que ingreso
	else
		charCode = e.keyCode // leo la tecla que ingreso
	status = charCode 
	//No deja escribir caracteres que no sean numeros, punto o coma
	if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 44 && charCode != 46) {
		return false;
	}
	else{
		for (i=0;i<campo.value.length;i++){
			if ((campo.value.charAt(i)==".") || (campo.value.charAt(i)==",")){
				decimales = 1;
			}
		}
		if (decimales == 1){
			if ((charCode == 44) || (charCode == 46)){
				return false;
			}
			else{
				return true;	
			}
		}
		else{
			return true;	
		}
	}
}

//----------------------------------------------------------------------------------------------
// Carga mediante AJAX 

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 cargarcuadro()
{
	var capital;
	var interes;
	var anos;
	var capa;
	
	capital=document.getElementById("capital").value;
	interes=document.getElementById("interes").value;
	anos=document.getElementById("anos").value;
	

	ajax=nuevoAjax();

	num = Math.random() * 42587; 
    num = Math.round(num);
	ajax.open("GET", "./cgi-bin/cuadro.exe/cuadro?capital="+capital+"&interes="+interes+"&anos="+anos+"&periodicidad=12", true);
	ajax.onreadystatechange=function() 
	{ 
		if (ajax.readyState==1)
		{
			// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
			capa=document.getElementById("tablacuadro");
			capa.innerHTML="Cargando...";
		}
		if (ajax.readyState==4)
		{ 
			document.getElementById("tablacuadro").innerHTML=ajax.responseText;			
		} 
	}
	ajax.send(null);
}
