	
//-------------------------------------------------
function Puntos_euros(campo, tecla)
{
	// Quitamos las teclas que no nos molan	
	if (
		(tecla == 8) || 
			((tecla >= 48) && (tecla <= 57)) ||
			((tecla >= 96) && (tecla <= 105)) ||
		(tecla == 17) || (tecla == 18) || (tecla == 16) || (tecla == 32) ||
		(tecla == 37) || (tecla == 38) || (tecla == 39) || (tecla == 40) || (tecla == 93) || (tecla == 91) || (tecla == 92) ||
		(tecla == 186) || (tecla == 222) || (tecla == 20) || (tecla == 145) || (tecla == 19) || (tecla == 45) ||
		(tecla == 36)  || (tecla == 33) || (tecla == 35) || (tecla == 34) || (tecla == 113) || (tecla == 114) ||
		(tecla == 118) || (tecla == 119)  || (tecla == 120)  || (tecla == 121) || (tecla == 122) || (tecla == 123)
		)
	{
		if (
			(tecla == 37) || (tecla == 38) || (tecla == 39) || (tecla == 40) || (tecla == 17) || (tecla == 18) || (tecla == 16) || 
			(tecla == 93) || (tecla == 91) || (tecla == 92) || (tecla == 186) || (tecla == 222) || (tecla == 20) || (tecla == 145) ||
			(tecla == 19) || (tecla == 45) || (tecla == 36) || (tecla == 33) || (tecla == 35) || (tecla == 34) || (tecla == 113) ||
			(tecla == 114) || (tecla == 118) || (tecla == 119) || (tecla == 120)  || (tecla == 121) || (tecla == 122)  || (tecla == 123)
			)
		{
			return;
		}
	
	if ((tecla == 9) && (campo.value == ''))
	{		
			campo.value = '';
	}	
	
	if ((tecla == 188) && (campo.value.indexOf(',') != -1) && (campo.value.substring(campo.value.indexOf(',') + 1, campo.value.length)))
	{	
		// Borramos todas las comas que haya menos 1
		while (campo.value.indexOf(',') != campo.value.lastIndexOf(','))
			campo.value = campo.value.substring(0, campo.value.length - 1);
			
		// Si la coma que dejamos es el primer caracter o si antes hay un punto la borramos tb y dejamos sólo el punto
		if (
			(campo.value.indexOf(',') == 0) || 
			(campo.value.indexOf('.') == (campo.value.indexOf(',') - 1))
			)
			campo.value = campo.value.substring(0, campo.value.length - 1);
			return;
	}
	else if (tecla == 188)
		{
			return;
		}
	
	// El tratamiento de los puntos es igual que el de las comas
	if ((tecla == 190) && (campo.value.indexOf('.') != -1) && (campo.value.substring(campo.value.indexOf('.') + 1, campo.value.length)))
	{
		while (campo.value.indexOf('.') != campo.value.lastIndexOf('.'))		
			campo.value = campo.value.substring(0, campo.value.length - 1);
			
		if (
			(campo.value.indexOf('.') == 0) || 
			(campo.value.indexOf(',') == (campo.value.indexOf('.') - 1))
			)
			campo.value = campo.value.substring(0, campo.value.length - 1);
		return;
	}
	else if (tecla == 190)
		{
			return;
		}
	
	if ((campo.value.length == 0) && ((tecla == 46) || (tecla == 8)))
	{		
		campo.value = '0';
		return;
	}
	numero = campo.value;

	// Quitamos los puntos
	var punto = numero.indexOf('.');
	while (punto != -1)
	{
		numero = numero.substring(0, punto) + numero.substring(punto + 1, numero.length);
		punto = numero.indexOf('.');
	}
	var coma = numero.indexOf(',');
	if (coma == 0)
	{
		return ('0' + numero);		
	}
	//alert(numero);
	var num = "";
	var decimal = "";	
				
		var coma = numero.indexOf(',');
		
		if (coma != -1)
		{		
			decimal = ',' + numero.substring(coma + 1, coma + 3);
			numero = numero.substring(0, coma);
		}
		else decimal = '';
		if (numero != '')
		{
	
			var str = "";
			while (numero > 999){
		
				n1 = Math.floor(numero/1000);
				n2 = numero - 1000 * n1;
				
				if (n2 < 10){
				   n2 = "00" + n2;
		        	}   
				else{
				   if (n2 < 100)
		       		      n2 = "0" + n2;
		                }
				str = "." + n2 + str;
				numero = n1;		
			}
			str = numero + str;		
		}	
		campo.value = str + decimal;
	}
	else campo.value = campo.value.substring(0, campo.value.length - 1);
}

function Formato_numero(numero)
{
var nombre = "";
var num = numero;
if (num != ""){
var str = "";
while (num > 999){
	n1 = Math.floor(num/1000);
	n2 = num - 1000 * n1;
	if (n2 < 10){n2 = "00" + n2;}   
	else{if (n2 < 100)
       	      	n2 = "0" + n2;}
	str = "." + n2 + str;
	num = n1;}
	str = num + str;}
return (str);}
//-------------------------------------------------
function Delete_miles(numero_puntos){
var num_p;
num_p = numero_puntos;longitud = 0;
longitud = num_p.length;n = 0;
var num_sp = "";
while (n<longitud){
     	var car = ' ';
      	var car = num_p.charAt(n);
      	if (car != '.')
		num_sp += num_p.charAt(n);
       	n++;}
var sin_puntos = parseInt(num_sp,10);
return sin_puntos;
}
//-------------------------------------------------	
function isEmpty(s){return ((s == null) || (s.length == 0))}
//-------------------------------------------------
function CleanThis(Tipo){
if (Tipo=="dinero")
	document.formu.importeh.value="";
else if(Tipo=="Apertura")
	document.hipoteca.MinApert.value="";}

//-------------------------------------------------
function PonPuntos(obj, sign, imaxlength)
{
var snumero; 
snumero = obj.value + 1; 
 
if (snumero.length > imaxlength)
	{  
	event.returnValue = false;
     	return false;  
   	}
if (isEmpty(obj.value) && (event.keyCode == 48)) 
  	{
     	Event.returnValue = false;
}
else
	if (sign == "positive")
  		{	
    		if ((event.keyCode < 48) || (event.keyCode > 57))
    			{
      			event.returnValue = false;
    			}
    		else 
    			{
      			var s_pre = obj.value;
      			var s_inter = "";
      			var s_post = "";
      			var single_character = "";
      			var poner_punto = 1;
      			for (var i = 0; i < s_pre.length; i++)
      				{
        			single_character = s_pre.substring(i,i+1);
        			if (single_character != ".")
        				{
          				s_inter = s_inter + single_character;
        				}
      				}
			s_inter = s_inter + String.fromCharCode(event.keyCode);
			for (var j = s_inter.length; j > 0; j--, poner_punto++)
      				{
        			s_post = s_inter.substring(j-1,j) + s_post;
        			if ((poner_punto == 3) && (j != 1))
        				{
          				poner_punto = 0;
          				s_post = "." + s_post;
        				}
      				}
      			obj.value = s_post;
      			event.returnValue = false;
    			}
  		}
  	else
  		{
    		if ((isEmpty(obj.value) && ((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 43) && (event.keyCode != 45)) || ((obj.value.length > 0) && ((event.keyCode < 48) || (event.keyCode > 57))))
    			{
    			event.returnValue = false;
    			}
    		else if (obj.value != "+" && obj.value != "-")
    			{
      			var s_pre = obj.value;
      			var s_inter = "";
      			var s_post = "";
      			var single_character = "";
      			var poner_punto = 1;
      			var sign_character = "";
			if ((s_pre.substring(0, 1) == "+") || (s_pre.substring(0, 1) == "-"))
      				{
        			sign_character = s_pre.substring(0, 1);
        			s_pre = s_pre.substring(1, s_pre.length);
      				}
			for (var i = 0; i < s_pre.length; i++)
      				{
        			single_character = s_pre.substring(i,i+1);
			        if (single_character != ".")
        				{
          				s_inter = s_inter + single_character;
        				}
      				}
			s_inter = s_inter + String.fromCharCode(event.keyCode);
			for (var j = s_inter.length; j > 0; j--, poner_punto++)
      				{
        			s_post = s_inter.substring(j-1,j) + s_post;
			        if ((poner_punto == 3) && (j != 1))
        				{
          				poner_punto = 0;
          				s_post = "." + s_post;
        				}
      				}
				obj.value = sign_character + s_post;
				event.returnValue = false;
    			}
  		}
	}
//-------------------------------------------------	
function EsNumerico(dato){
var i;var longitud;var caracter;var sumo = 0;longitud = dato.length;valido = "0123456789.";
for ( i=0; i <= longitud; i++){
	caracter = dato.substring(i,i+1)
	if (valido.indexOf(caracter) == -1)
		return false;}return true;}
//-------------------------------------------------
function borrar(obj){obj.value = "";}
//-------------------------------------------------
function cerrar(){Window.close();}
//-------------------------------------------------
function abrirPouUp(PopUp)
	{
	var pouup = window.open("http://www.metrocuadrado.com/hagamoscuentas/popups/" + PopUp,'PopUp','top=0,left=0,scrollbars=yes,width=420,height=500');
	}