function validar_pedido(){
	if (!document.pedido.CIF.value)        
	{          
		alert ("Por favor, introduzca su NIF / CIF.");
		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;        
	}else if(isNaN(document.pedido.CODIGO_POSTAL_FACTURA.value)){
		alert('El código postal debe ser un número');
		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.TELEFONO_FACTURA.value!=''){
		if(/^([0-9\+\s\+\-\+\/\+\(\+\)\+\.])+$/.test(document.pedido.TELEFONO_FACTURA.value)) {
			return true;
		}else{
			alert('El teléfono debe ser un número de teléfono válido');
			return false;
		}
	}
	//validamos los datos de envío si el check esta activado
	if (document.pedido.VER_DATOS_FACTURACION.checked){
		if (!document.pedido.NOMBRE.value)        
		{          
			alert ("Por favor, introduzca un nombre en los datos de envío.");
			document.pedido.NOMBRE.select();
			return false;        
		}
		
		if (!document.pedido.DIRECCION.value)        
		{          
			alert ("Por favor, introduzca una direccion en los datos de envío.");
			document.pedido.DIRECCION.select();
			return false;        
		}
		
		if (!document.pedido.POBLACION.value)        
		{          
			alert ("Por favor, introduzca su poblacion en los datos de envío.");
			document.pedido.POBLACION.select();
			return false;        
		}
		if (!document.pedido.CODIGO_POSTAL.value)        
		{          
			alert ("Por favor, introduzca su codigo postal en los datos de envío.");
			document.pedido.CODIGO_POSTAL.select();
			return false;        
		}else if(isNaN(document.pedido.CODIGO_POSTAL_FACTURA.value)){
			alert('El código postal debe ser un número');
			return false;
		}
		
		
	    if (!document.pedido.PROVINCIA.selectedIndex){
			alert ("Por favor, seleccione una provincia en los datos de envío.");
			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 en los datos de envío.");
				document.pedido.EMAIL.select();
				return false;        
			}        
			if (document.pedido.EMAIL.value.indexOf(".",1)==-1)
			{          
				alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta en los datos de envío.");
				document.pedido.EMAIL.select();
				return false;        
			}	
		}
		if(document.pedido.TELEFONO.value!=''){
			if(/^([0-9\+\s\+\-\+\/\+\(\+\)\+\.])+$/.test(document.pedido.TELEFONO.value)) {
				return true;
			}else{
				alert('El teléfono debe ser un número de teléfono válido');
				return false;
			}
		}
	}
	
}

function ValidaCampos(valor)
{
//comprueba campo teléfono de formulario
//usa el metodo test de expresion regular


if(/^([0-9\+\s\+\-])+$/.test(valor)) {
	alert("El número telefónico es correcto.");
return (true);
}
else
{
	alert('El número de teléfono ingresado no es válido.');
	return false; //no submit
}
}



function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser una dirección de e-mail.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' debe ser un número';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' debe ser un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
  } if (errors) alert('Han ocurrido los siguientes errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function marcarCheckbox(complemento){
 var aux;
 aux = 'complemento_nombre['+complemento+']';
 for (i=0;i<document.myForm.elements.length;i++) 
	if (document.myForm.elements[i].name == aux){
		document.myForm.elements[i].checked=1;
	}
}

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