function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    return false;
}
function mostrarLayer(idLayer) 
{
	document.getElementById(idLayer).style.visibility = "visible"; 
}
    
function mostrarLayerXY(idLayer) 
{
	document.getElementById(idLayer).style.visibility = "visible"; 
	document.getElementById(idLayer).style.left = xRaton;
	document.getElementById(idLayer).style.top = yRaton;
}

function ocultarLayer(idLayer) 
{
	document.getElementById(idLayer).style.visibility = "hidden"; 
}

function mostrarEtiquetaMensaje(mensaje) 
{
	document.getElementById("etqmensaje").innerHTML = mensaje;
	document.getElementById("etqmensaje").style.visibility = "visible"; 

	document.getElementById("etqmensaje").style.left = xRaton + 40;
	document.getElementById("etqmensaje").style.top = yRaton;
	mostrarLayer ("etqmensaje");
}

function mostrarEtiquetaMensaje2(mensaje, nomLayer) 
{
	document.getElementById(nomLayer).innerHTML = mensaje;
	document.getElementById(nomLayer).style.visibility = "visible"; 

	document.getElementById(nomLayer).style.left = xRaton + 40;
	document.getElementById(nomLayer).style.top = yRaton;
	mostrarLayer (nomLayer);
}

function mostrarEtiquetaMensajeLayer(mensaje, etq) 
{
	document.getElementById(etq).innerHTML = mensaje;
	document.getElementById(etq).style.visibility = "visible"; 

	//document.getElementById(etq).style.left = xRaton + 40;
	//document.getElementById(etq).style.top = yRaton;
	mostrarLayer (etq);
}

function mostrarLayerPersiana(idLayer, alto, delay, ultima)
{
	document.getElementById(idLayer).style.visibility = "visible"; 
	if (ultima < alto)
	{
		document.getElementById(idLayer).style.height = ultima;
		ultima = ultima + 25;
		setTimeout("mostrarLayerPersiana('" + idLayer + "'," + alto + "," + delay + "," + ultima + ")", delay);
		return;
	}else
	{
		return;
	}
}

function escribirHTMLenLayer(idLayer,codigo) 
{
	document.getElementById(idLayer).innerHTML = codigo;
}

function mostrarPanelSubMapa(texto)
{
	while (texto.indexOf("+") != -1){ 
		texto = texto.replace("+"," "); 
	} 
	document.getElementById("submapa").innerHTML = unescape(texto);
}
function ocultarSubMapa()
{
	ocultarLayer ("submapa");
	document.getElementById("submapa").innerHTML = '<img src="media/panel_submapa.gif" id="mapasubmapa" usemap="#mapasubmapa" border="0">';
}

function desplegarMenu(idLayer, alto, ultima)
{
	delay =1;
	document.getElementById(idLayer).style.visibility = "visible"; 
	if (ultima < alto)
	{
		document.getElementById(idLayer).style.height = ultima;
		ultima = ultima + 25;
		setTimeout("mostrarLayerPersiana('" + idLayer + "'," + alto + "," + delay + "," + ultima + ")", delay);
		return;
	}else
	{
		return;
	}
}

function recogerMenu(idLayer, alto)
{
	document.getElementById(idLayer).style.visibility = "visible"; 
	document.getElementById(idLayer).style.height = alto;
}

function enviarFormulario (formulario)
{
	document[formulario].submit(); 
	//document.getElementById(formulario).submit();
}
function ponValorObjetoComboVariosNA (objeto, valor)
{
	var combo = document.getElementById(objeto);
	var valor = valor.split(",");
	var cadena = ""
	var i
	
	for (i=0;i<count(valor);i++)
	{
		combo.options[i].value = valor[i]
	}
	return;
}
function dameValorObjeto (objeto)
{
	return document.getElementById(objeto).value;
}
function ponValorObjeto (objeto, valor)
{
	return document.getElementById(objeto).value = valor;
}

function dameValorObjetoCombo (objeto)
{
	var combo = document.getElementById(objeto);
	var cadena = ""
	var i
	
	for (i=0;i<combo.length;i++)
	{
		if (combo.options[i].selected)
		{
			cadena += combo.options[i].value + ","
		}
	}
	cadena = cadena.substring(0,(cadena.length - 1));
	return cadena;
}
	function cambiaPais(pais, form) {
		var url ="xml/XMLprovincias.php?idpais=" + pais + "&form=" + form;
		http.open("GET", url, true);
		http.onreadystatechange = handleHttpProvincias;
		http.send(null);
	}
	function handleHttpProvincias() {
		if (http.readyState == 4) {
			cadena = unescape(http.responseText).split(",");
			for (i=document.forms[cadena[0]].cbprovincia.options.length;i>=0;i--)
			{
				document.forms[cadena[0]].cbprovincia.options[i]=null;
			}
			j = 0;
			for (i=1;i<cadena.length;i++)
			{
				document.forms[cadena[0]].cbprovincia.options[j] = new Option(cadena[i+1],cadena[i]);
				j++;
				i++;
			}
			
		}
	}
function checkMail(email)
{
	var x = email
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}
function ponValorObjetoCombo (objeto, valor)
{
	var combo = document.getElementById(objeto);
	var cadena = ""
	var i
	
	for (i=0;i<combo.length;i++)
	{
		if (combo.options[i].value == valor)
		{
			combo.options[i].selected = true
			break;
		}
	}
	return;
}
function estaChekeado (objeto)
{
	return document.getElementById(objeto).checked;
}

function dameNumeroBien (numero)
{
	numero = parseInt (numero);
	buffer = numero.toString();
	manejoNumero = numero.toString();
	if (manejoNumero.length > 3){
		buffer = "";
		dec = 0;
		for (i = manejoNumero.length;i>0;i--){
			if ((dec % 3 == 0) && (dec > 0)) buffer = manejoNumero.charAt(i - 1) + "." + buffer;
			else buffer = manejoNumero.charAt(i - 1) + buffer;
			dec++;
			
			//alert (dec + "," + i + "," + buffer);
		}
	
	}
	return buffer;
}

function calculaCuota (interes, anos, importe)
{
	totalA = 1 + (interes / 100);
	totalA = Math.pow (totalA, -(anos));
	totalA = 1 - totalA;
	totalA = totalA * 100;
	totalB = importe * (interes / 100) * 100;
	total = totalB / totalA;
	return total;
}

function calculaCuotaBullet (interes, anos, importe, bullet)
{
	totalA = 1 + (interes / 100);
	totalA = Math.pow (totalA, -(anos));
	totalA = 1 - totalA;
	totalA = totalA * 100;
	totalB = importe * interes * ((100 - bullet) / 100);
	total = totalB / totalA;
	totalD = importe * (interes / 100) * (bullet / 100);
	total += totalD;
	return total;
}


function dameNumeroBienDecimales (numero)
{
	var num = new oNumero(numero);
	return num.formato(2, true);
}

//Mas en: http://javascript.espaciolatino.com/
//Objeto oNumero
function oNumero(numero)
{
//Propiedades 
this.valor = numero || 0
this.dec = -1;
//Métodos 
this.formato = numFormat;
this.ponValor = ponValor;
//Definición de los métodos 
function ponValor(cad)
{
if (cad =='-' || cad=='+') return
if (cad.length ==0) return
if (cad.indexOf('.') >=0)
    this.valor = parseFloat(cad);
else 
    this.valor = parseInt(cad);
} 
function numFormat(dec, miles)
{
var num = this.valor, signo=3, expr;
var cad = ""+this.valor;
var ceros = "", pos, pdec, i;
for (i=0; i < dec; i++)
ceros += '0';
pos = cad.indexOf('.')
if (pos < 0)
    cad = cad+"."+ceros;
else
    {
    pdec = cad.length - pos -1;
    if (pdec <= dec)
        {
        for (i=0; i< (dec-pdec); i++)
            cad += '0';
        }
    else
        {
        num = num*Math.pow(10, dec);
        num = Math.round(num);
        num = num/Math.pow(10, dec);
        cad = new String(num);
        }
    }
pos = cad.indexOf('.')
if (pos < 0) pos = cad.lentgh
if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
       signo = 4;
if (miles && pos > signo)
    do{
        expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
        cad.match(expr)
        cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
        }
while (cad.indexOf(',') > signo)
    if (dec<0) cad = cad.replace(/\./,'')
        return cad;
}
}//Fin del objeto oNumero:
