
function errorLetraNIF (nifL)
{
	var d, letrasNIF, nif, letraTecleada;
	
	if (nifL.length < 7 || nifL.length > 9)	return true;
	
	if (nifL.substring (0, 1) < '0' || nifL.substring (0, 1) > '9')	return false;

	letraTecleada = nifL.substring (nifL.length-1, nifL.length);
	
	nif = nifL.substring (0, nifL.length-1);
	d = (nif/23)
	d = Math.floor(d);
	d = d*23;
	d = nif-d;
	letrasNIF = 'TRWAGMYFPDXBNJZSQVHLCKEO';
	
	return ! (letraTecleada == letrasNIF.substring (d, d+1));
}

function errorEnEmail(email) 
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
   return false;
  else 
   return true;
}


function obtenerDigito(valor)
{
	valores = new Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);

	control = 0;
	for (i=0; i<=9; i++)
		control += parseInt(valor.charAt(i)) * valores[i];
	control = 11 - (control % 11);
	if (control == 11) control = 0;
	else if (control == 10) control = 1;

  return control;
}

function errorCCCBanco(entidad, sucursal, dc, cuenta)
{
	if (/^[0-9]{4}$/.test(entidad) == false) return true;
	if (/^[0-9]{4}$/.test(sucursal) == false) return true;
	if (/^[0-9]{2}$/.test(dc) == false) return true;
	if (/^[0-9]{10}$/.test(cuenta) == false) return true;

	if (!(obtenerDigito("00" + entidad + sucursal) == parseInt(dc.charAt(0))) || !(obtenerDigito(cuenta) == parseInt(dc.charAt(1))))
          return true;

	return false;
}
