
			/*======================================================*/
			/* Funciones de javascript que usa el login para Cac	*/
			/*======================================================*/

function submitPedidosIPForm(nombreForm){

	var msisdn = document.getElementById(nombreForm)[0].value;
	var nif = document.getElementById(nombreForm)[1].value;
	var fecha = document.getElementById(nombreForm)[2].value;

	if (msisdn=='' && nif=='' && fecha=='')
	{
		alert('Seleccione al menos un criterio de búsqueda');
		return;
	}
	else
	{
		if ((msisdn!='')&& !validarMsisdnCac(msisdn))
		{
			alert('El número de teléfono ha de comenzar por 6, y tener 9 dígitos');
			document.getElementById(nombreForm)[1].focus();
			return;
		}
		if ((nif !='')&&(!validarNIFCac(nif)))
		{
			document.getElementById(nombreForm)[1].focus();
			return;
		}
		document.getElementById(nombreForm).submit();

	}
}

function submitLoginFormCac(){
	//alert('submitLoginFormCac');
	//alert(document.getElementById("listarPedidosIPForm")[0]);
	//alert(document.getElementById("listarPedidosIPForm")[0].value);
	//alert(document.getElementById("listarPedidosIPForm")[1]);
	//alert(document.getElementById("listarPedidosIPForm")[1].value);
	var type = document.getElementById("loginForm")[0].value;
	var value = document.getElementById("loginForm")[1].value;
	if(type == ''){
		alert('Seleccione el tipo de identificacion');
		return;
	}else{
		if(value == ''){
			if(type == 'msisdn'){
				alert('Introduzca el número de teléfono');
			}else
			{
				alert('Introduzca el valor del '+ type);
			}
			return;
		}
		else{

			if(type == 'msisdn'){
				if(!validarMsisdnCac(value)){
					alert('El número de teléfono ha de comenzar por 6, y tener 9 dígitos');
					document.getElementById("loginForm")[1].focus();
				return;}
			}
			if(type == 'NIF'){
				if(!validarNIFCac(value)){
					document.getElementById("loginForm")[1].focus();
				return;}
			}
			if(type == 'NIE'){
				if(!validarNIECac(value)){
					document.getElementById("loginForm")[1].focus();
				return;}
			}
			if(validateLoginForm(document.getElementById('loginForm'))){
				document.getElementById('btn_loginenter').style.visibility='hidden';
				document.getElementById('loginForm').submit();
			}
		}
	}
}

function validarMsisdnCac(msisdn){

//	var msisdn = document.getElementById("loginForm")[1].value;
	var digits = '0123456789';
	var six = msisdn.charAt(0);
	if(9!=msisdn.length){
	return false;}
	if(six != '6'){return false;}
	for(i=1;i<msisdn.length; i++){
		if(digits.indexOf(msisdn.charAt(i),0) == -1){return false;}
	}
	return true;
}

function validarNIFCac(nif){
//	nif=document.getElementById("loginForm")[1].value;
	dni=nif.substring(0,nif.length-1);
	let=nif.charAt(nif.length-1);
	if(nif.length>9){
		alert('La longitud máxima son 9 caracteres');
		return false;
	}else{
		if (!isNaN(let)){
  			alert('Es necesario introducir la letra del NIF');
  			return false;}
		else{
  			cadena="TRWAGMYFPDXBNJZSQVHLCKET";
  			posicion = dni % 23;
  			letra = cadena.substring(posicion,posicion+1);
  			if (letra!=let.toUpperCase()){
    			alert("Letra del Nif no válida");
	    		return false;}
 			}
 		}
	return true;
}

function validarNIECac(nie){

//	nie=document.getElementById("loginForm")[1].value;
	if(nie.length<7){
	alert('NIE no valido');
	return false;
				}
				if(nie.charAt(0) != 'X' && nie.charAt(0) != 'T' && nie.charAt(0) != 'x' && nie.charAt(0) != 't'){
					alert('El NIE ha de comenzar por X o T');
					return false;
				}
				dni=nie.substring(1,nie.length-1);
				let=nie.charAt(nie.length-1);
				if(dni.lenght == 6){
					dni='0'+dni;
				}
				if (!isNaN(let))
 				{
  					alert('Es necesario introducir la letra final del NIE');
  					return false;
 				}
				else
	 			{
  					cadena="TRWAGMYFPDXBNJZSQVHLCKET";
  					posicion = dni % 23;
  					letra = cadena.substring(posicion,posicion+1);
  					if (letra!=let.toUpperCase())
   					{
    					alert("NIE no válido");
    					return false;
   					}
 				}
				return true;
			}

	function submitLoginForm(){
		if((document.getElementById('msisdn').value == '') || (document.getElementById('password').value == '')){
			alert('El campo usuario y el campo contraseña deben estar rellenos');
		}else{
			document.getElementById('loginCaCForm').submit();
		}
	}

	function vaciarMSISDN()
	{
		if (document.getElementById("loginCaCForm")[0].value=='Usuario')
			document.getElementById("loginCaCForm")[0].value="";
	}
	function cambiaPasswordLoginForm() {
	    cajaPassword = document.getElementById("loginCaCForm")[1];
	    cajaPassword2 = document.getElementById("loginCaCForm")[2];
	    cajaPassword.style.display = 'none';
	    cajaPassword2.style.display = '';
	    cajaPassword2.focus();
	}
	function nonePassword(){
		cajaPassword2 = document.getElementById("loginCaCForm")[2];
	    cajaPassword2.style.display = 'none';
	}