//Desarrollo realizado por Asesores Bancarios y Financieros www.abanfin.com
//Prohibida la reproducción total o parcial por cualquier medio salvo autorización expresa de Asesores Bancarios y //Financieros
//-------------------------------------------------------------------------------------------
// funciones de comprobación de los campos del formulario
function tieneDatos(Valor) { 
 for (var i=0; i<Valor.length; i++) { 
   if ((" \t\n\r").indexOf(Valor.charAt(i))==-1) return true; 
   } 
 return false; 
}
 
 
function esNumero(valor)
{ 
  var valores = "0123456789.";
  var comprobado = valor;
  seanumero="true"
  for (i = 0;  i < comprobado.length;  i++)
  {
    ch = comprobado.charAt(i);
    for (j = 0;  j < valores.length;  j++)
      if (ch == valores.charAt(j))
        break;
    if (j == valores.length) {seanumero="false";break;}
  }

  return seanumero;
}

function esNumero2(valor,variable)
{ 
  var valores = variable;
  var comprobado = valor;
  seanumero="true"
  for (i = 0;  i < comprobado.length;  i++)
  {
    ch = comprobado.charAt(i);
    for (j = 0;  j < valores.length;  j++)
      if (ch == valores.charAt(j))
        break;
    if (j == valores.length) {seanumero="false";break;}
  }

  return seanumero;
}


function esFecha(Valor) { 
 seafecha="false";
 if(Valor.indexOf("/")!= -1)
 {
	seanumero = esNumero2(Valor,"0123456789/");
 	if (seanumero == "true")
 	{	
		var DatosFecha = Valor.split("/"); 
 		var Fecha = new Date(); 
	 	Fecha.setFullYear(DatosFecha[2],DatosFecha[1]-1,DatosFecha[0]); 
		if(Fecha.getMonth()==DatosFecha[1]-1 && DatosFecha[2].length==4){seafecha="true";}
 	}
 }
 else if(Valor.indexOf("-")!= -1)
 { 
    seanumero = esNumero2(Valor,"0123456789-");
 	if (seanumero == "true")
 	{	
		var DatosFecha = Valor.split("-"); 
 		var Fecha = new Date(); 
	 	Fecha.setFullYear(DatosFecha[2],DatosFecha[1]-1,DatosFecha[0]); 
		if(Fecha.getMonth()==DatosFecha[1]-1 && DatosFecha[2].length==4){seafecha="true";}
 	}
 }
return seafecha;
}
//---------------------------------------------------------------------------------
// Obtención de la fecha en si mísma

function valorfecha(Valor) 
{
 	if(Valor.indexOf("/")!=-1)
	{	
		var DatosFecha = Valor.split("/"); 
 		var Fecha = new Date(); 
	 	Fecha.setFullYear(DatosFecha[2],DatosFecha[1]-1,DatosFecha[0]); 	
 	}
	else if(Valor.indexOf("-")!=-1)
 	{	
		var DatosFecha = Valor.split("-"); 
	 	var Fecha = new Date(); 
 		Fecha.setFullYear(DatosFecha[2],DatosFecha[1]-1,DatosFecha[0]); 
 	}
	return Fecha; 
}


//--------------------------------------------------------------------------------------
// Formato de números sin decimales
function formato(numero) {
	numero = String(Math.round(numero))
	contador = 1
	for (pos = (numero.length - 1); pos > 0; pos--) {
		contador++
		if (contador > 3) {
			numero = numero.substring(0,pos) + "." + numero.substr(pos)
			contador = 1
		}
	}
	return(numero)
}

//-------------------------------------------------------------------------------------
// Formato de número con decimales

function formatodec(numero,moneda) 
{
var entero;
var decimal;
var coma;
var final1;

if(moneda==0){final1=".- Ptas.";}else{final1=".- Euros";}
numero=String(Math.round(numero*100)/100);


var negativo=numero.indexOf("-");
if(negativo!=-1){numero=numero.substring(1,numero.length);}

var pos=numero.indexOf(".");
if(pos==-1){decimal=0;coma="";}else{decimal=numero.substr(pos,3);coma=","+decimal.substr(1,2);};
if (pos==-1){entero=numero;}else{entero=numero.substring(0,pos);};

	contador = 1
	for (pos = (entero.length - 1); pos > 0; pos--) {
		contador++
		if (contador > 3) {
			entero = entero.substring(0,pos) + "." + entero.substr(pos)
			contador = 1
		}
	}

	if (moneda==0){numero=entero+final1;}else{numero=entero+coma+final1;}
	if (negativo!=-1)
	{
		if (entero!==0 || decimal!==0)
		{numero= "-" + numero;}
		else
		{
			if (entero==0 && decimal==0)
			{}
			else
			{numero="-" + numero;}
	
		}
		
		
	}
	return (numero)
}

//---------------------------------------------------------------------------------------
// Cambia la moneda de la operación
<!--
function cambiar(form)
{
var importe;
var informa;
importe=form.importe.value*1;

if(form.moneda[0].checked){form.moneda[0].checked=0;informa=1;}
if(form.moneda[1].checked){form.moneda[1].checked=0;informa=0;}
if (informa==1){form.importe.value=Math.round((importe/166.386)*100)/100;form.moneda[1].checked=1;}
if (informa==0){form.importe.value=Math.round(importe*166.386);form.moneda[0].checked=1;}
calculos(form)
}
//-->
//---------------------------------------------------------------------------------------
// Cambia la moneda de la operación con tres campos, recálculos de cuota
<!--
function cambiartres(form)
{
var cpendiente;
var amortizacion;
var cuotainicial;
var informa;

cpendiente=form.cpendiente.value*1;
amortizacion=form.amortizacion.value*1;
cuotainicial=form.cuotainicial.value*1;

if(form.moneda[0].checked){form.moneda[0].checked=0;informa=1;}
if(form.moneda[1].checked){form.moneda[1].checked=0;informa=0;}

if (informa==1)
{
form.cpendiente.value=Math.round((cpendiente/166.386)*100)/100;
form.amortizacion.value=Math.round((amortizacion/166.386)*100)/100;
form.cuotainicial.value=Math.round((cuotainicial/166.386)*100)/100;
form.moneda[1].checked=1;
}
else
{
form.cpendiente.value=Math.round(cpendiente*166.386);
form.amortizacion.value=Math.round(amortizacion*166.386);
form.cuotainicial.value=Math.round(cuotainicial*166.386);
form.moneda[0].checked=1;
}
calculos(form)
}
//-->

