/** Chequea la letra del DNI
*
*/

	function RevisaDNI(cadena) {		
		numero=cadena;

		if (cadena.length==9){ 			
			numero=cadena.substr(0,8);
			letra=cadena.substr(8,1);			
		}
		else
		{	
			if (cadena.length==8) {
				numero=cadena.substr(0,7);
				letra=cadena.substr(7,1);				
			}			
		}
		
    var ok = "si";
    var temp;	
	
	if (cadena.length<8){		
		ok="no";		
		letra='';		
	}	

	if ((numero > 999) && (numero <= 99999999)) {			

					tmp = numero - 23 *((numero/23) - (numero/23)%1);										
					
					if (tmp == 0) tmp2 = "T";
							
					if (tmp == 1) tmp2 = "R";
		
					if (tmp == 2) tmp2 = "W";
		
					if (tmp == 3) tmp2 = "A";
		
					if (tmp == 4) tmp2 = "G";
		
					if (tmp == 5) tmp2 = "M";
		
					if (tmp == 6) tmp2 = "Y";
		
					if (tmp == 7) tmp2 = "F";
		
					if (tmp == 8) tmp2 = "P";
		
					if (tmp == 9) tmp2 = "D";
		
					if (tmp == 10) tmp2 = "X";
		
					if (tmp == 11) tmp2 = "B";
		
					if (tmp == 12) tmp2 = "N";
		
					if (tmp == 13) tmp2 = "J";
		
					if (tmp == 14) tmp2 = "Z";
		
					if (tmp == 15) tmp2 = "S";
		
					if (tmp == 16) tmp2 = "Q";
		
					if (tmp == 17) tmp2 = "V";
		
					if (tmp == 18) tmp2 = "H";
		
					if (tmp == 19) tmp2 = "L";
		
					if (tmp == 20) tmp2 = "C";
		
					if (tmp == 21) tmp2 = "K";
		
					if (tmp == 22) tmp2 = "E";								 
	}	
	
	if (ok=='si'){			
		if (isNaN(numero) || (letra.toUpperCase()!=tmp2) ){			
			ok="no";   
			return false;
		}
		else
			return true;
	}
	
	if (ok=='no')
		return false;
  }  
  
    function validarCIF(texto){ 
         
        var pares = 0; 
        var impares = 0; 
        var suma; 
        var ultima; 
        var unumero; 
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I"); 
        var xxx; 
         
        texto = texto.toUpperCase(); 
         
        var regular =/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g; 
         if (!regular.exec(texto)) return false; 
              
         ultima = texto.substr(8,1); 

         for (var cont = 1 ; cont < 7 ; cont ++){ 
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + 0; 
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1)); 
             pares += parseInt(texto.substr(cont,1)); 
         } 
         xxx = (2 * parseInt(texto.substr(cont,1))).toString(); 
         impares += parseInt(xxx.substr(0,1)) + parseInt(0 + xxx.substr(1,1)); 
          
         suma = (pares + impares).toString(); 
         unumero = parseInt(suma.substr(suma.length - 1, 1)); 
         unumero = (10 - unumero).toString(); 
         if(unumero == 10) unumero = 0; 
          
         if ((ultima == unumero) || (ultima == uletra[unumero])) 
             return true; 
         else 
             return false; 

    } 


function validar_pedido(){

    
	if (!document.pedido.CIF.value)        
	{          
		alert ("Por favor, introduzca su NIF/CIF .");
		document.pedido.CIF.select();
		return false;        
	}	
	/*else
	{
		if ((! RevisaDNI(document.pedido.CIF.value)) && (! validarCIF(document.pedido.CIF.value))){
			alert ("Por favor, introduzca un NIF/CIF válido.");
			document.pedido.CIF.select();
			return false;  			
		}		
	}*/
	
	if (!document.pedido.NOMBRE_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su nombre .");
		document.pedido.NOMBRE_FACTURA.select();
		return false;        
	}
	
	if (!document.pedido.DIRECCION_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su direccion .");
		document.pedido.DIRECCION_FACTURA.select();
		return false;        
	}
	
	if (!document.pedido.POBLACION_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su poblacion .");
		document.pedido.POBLACION_FACTURA.select();
		return false;        
	}
	if (!document.pedido.CODIGO_POSTAL_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su codigo postal .");
		document.pedido.CODIGO_POSTAL_FACTURA.select();
		return false;        
	}	
	
    if (!document.pedido.PROVINCIA_FACTURA.selectedIndex){
		alert ("Por favor, seleccione una provincia .");
		document.pedido.PROVINCIA_FACTURA.focus();
		return false;                   
    }			
	
	if (document.pedido.EMAIL_FACTURA.value)        
	{ 	
		if (document.pedido.EMAIL_FACTURA.value.indexOf("@",1)==-1)        
		{          
			alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta.");
			document.pedido.EMAIL_FACTURA.select();
			return false;        
		}        
		if (document.pedido.EMAIL_FACTURA.value.indexOf(".",1)==-1)
		{          
			alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta.");
			document.pedido.EMAIL_FACTURA.select();
			return false;        
		}	
	}

	if (document.pedido.VER_DATOS_FACTURACION.checked){
	
		if (!document.pedido.NOMBRE.value)        
		{          
			alert ("Por favor, introduzca su nombre .");
			document.pedido.NOMBRE.select();
			return false;        
		}
		
		if (!document.pedido.DIRECCION.value)        
		{          
			alert ("Por favor, introduzca su direccion .");
			document.pedido.DIRECCION.select();
			return false;        
		}
		
		if (!document.pedido.POBLACION.value)        
		{          
			alert ("Por favor, introduzca su poblacion .");
			document.pedido.POBLACION.select();
			return false;        
		}
		if (!document.pedido.CODIGO_POSTAL.value)        
		{          
			alert ("Por favor, introduzca su codigo postal .");
			document.pedido.CODIGO_POSTAL.select();
			return false;        
		}	
		
	    if (!document.pedido.PROVINCIA.selectedIndex){
			alert ("Por favor, seleccione una provincia .");
			document.pedido.PROVINCIA.focus();
			return false;                   
	    }			
		
		if (document.pedido.EMAIL.value)        
		{ 	
			if (document.pedido.EMAIL.value.indexOf("@",1)==-1)        
			{          
				alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta.");
				document.pedido.EMAIL.select();
				return false;        
			}        
			if (document.pedido.EMAIL.value.indexOf(".",1)==-1)
			{          
				alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta.");
				document.pedido.EMAIL.select();
				return false;        
			}	
		}
	}
}


	function expandir_formulario(objeto){		
		 if (objeto.checked){
			xDisplay('capaexpansion', 'block')
		 }else{
			xDisplay('capaexpansion', 'none')
		 }
	}