
function ValidarDecimal(campo) {
fieldValue=campo.value;
decallowed = 2;  // how many decimals are allowed?

if (isNaN(fieldValue) || fieldValue == "") {


return false;
}
else {
if (fieldValue.indexOf('.') == -1) fieldValue += ".";
dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

if (dectext.length > decallowed)
{

return false;
      }
else {
return true;
      }
   }
}


function LineaVacia( Ref,Refb,Cantidad,precio)
{
	if ( (EstaVacio(Ref.value))  && 
	  (EstaVacio(Refb.value)) && 
	   (EstaVacio(precio.value)) && 
	    (EstaVacio(Cantidad.value))  )
		 return true;
	else return false;
}

function LineaCorrecta( Ref,Refb,Cantidad,precio)

{

if (!LineaVacia(Ref,Refb,Cantidad,precio))
{
	if  (EstaVacio(Ref.value))
	{
	alert("No se ha indicado la referencia en el  pedido");
	MostrarDatosPedido();
	Ref.focus();
	return false;
	}
	
	if (Ref.value.length < 5)
	{
	alert("La referencia  debe tener 5 digitos ");
	MostrarDatosPedido();
	Ref.focus();
	return false;
	}
	if  (EstaVacio(Refb.value))
	{
	alert("No se ha indicado la referencia en el  pedido");
	MostrarDatosPedido();
	Refb.focus();
	return false;
	}
	
	if  (EstaVacio(Cantidad.value))
	{
	alert("No se ha indicado las unidades en el  pedido");
	MostrarDatosPedido();
	Cantidad.focus();
	return false;
	}
	
	 if  (EstaVacio(precio.value))
	 {
	alert("No se ha indicado el precio en el  pedido");
	MostrarDatosPedido();
	precio.focus();
	return false;
	}
	
	if (!(EsEntero(Ref.value)))
		{
		alert("La referencia contiene caracteres no válidos");
		MostrarDatosPedido();
		Ref.focus();
		return false;
		} 
		
		if (!(EsEntero(Refb.value)))
		{
		alert("La referencia contiene caracteres no válidos");
		MostrarDatosPedido();
		Refb.focus();
		return false;
		} 
	if (!ValidarDecimal(Cantidad))
	{
	alert("Las unidades no son correctas. En caso de utilizar decimales  utilizar el caracter '.' ");
		MostrarDatosPedido();
		Cantidad.focus();
		return false;
	}
	if (!ValidarDecimal(precio))
	{
	alert("El precio no es correcto. En caso de utilizar decimales  utilizar el caracter '.' ");
		MostrarDatosPedido();
		precio.focus();
		return false;
	}
		
		
}
	 return true;
}
function printLinea1Pedido(ventana, Ref,Refb,Medidas,Calidad,Cantidad,precio,obs,linea)
{

	if (LineaVacia( Ref,Refb,Cantidad,precio))
		 return;
		 
	ventana.document.writeln(' <tr>'); 
    ventana.document.writeln('<td><div align="left"><font size="1">' + Ref.value + '-' + Refb.value  +'</font></div></td>');

    ventana.document.writeln('<td><div align="left"><font size="1">' + Medidas.value +'</font></div></td>');

    ventana.document.writeln('<td><div align="left"><font size="1">' + Calidad.value +'</font></div></td>');
	
   
    ventana.document.writeln('<td><div align="right"><font size="1">' + Cantidad.value +'</font></div></td>');
	 ventana.document.writeln('<td><div align="right"><font size="1">' + precio.value +'</font></div></td>');
	 ventana.document.writeln('<td><div align="left"><font size="1">-' + obs.value +'</font></div></td>');
	
   
  ventana.document.writeln('</tr>');
 
  
  linea.value="Referencia: " + Ref.value + "-" + Refb.value + "\n  " + "Medidas: " + Medidas.value   + "\n  " + "Calidad: " + Calidad.value 
  + "\n  " +"Cantidad: " + Cantidad.value   ;
  


}	


function EstaVacio(campo)
{
var patron=/^\s*$/;

if (!(patron.exec(campo)))
	return false;
else
	return true;

}

function EsEntero(campo)
{
var patron=/^\d+$/;

if (!(patron.exec(campo)))
	return false;
else
	return true;

}

function EsMailCorrecto(mail)
{
var patron=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

if (!(patron.exec(mail)))
	return false;
else
	return true;

}

function validarLogin(pedido)
{
if (EstaVacio(pedido.codigo.value))
	{
	alert("No se ha indicado el  código del cliente en el  pedido");
	MostrarDatosEnvio();
	pedido.codigo.focus();
	return false;
	}
	if (pedido.codigo.value.length < 5)
	{
	alert("El  código del cliente debe tener 5 digitos");
	MostrarDatosEnvio();
	pedido.codigo.focus();
	return false;
	}
	if (!(EsEntero(pedido.codigo.value)))
		{
		alert("El código del cliente contiene caracteres no válidos");
		MostrarDatosEnvio();
		pedido.codigo.focus();
		return false;
		} 
if (EstaVacio(pedido.contrasena.value))
	{
	alert("No se ha indicado la contraseña del cliente en el  pedido");
	MostrarDatosEnvio();
	pedido.contrasena.focus();
	return false;
	}
return true;	
}





function ComprobarDatosPedido(pedido)
{
if (EstaVacio(pedido.codigo.value))
	{
	alert("No se ha indicado el  código del cliente en el  pedido");
	MostrarDatosEnvio();
	pedido.codigo.focus();
	return false;
	}
	
if (pedido.codigo.value.length < 5)
	{
	alert("El  código del cliente debe tener 5 digitos");
	MostrarDatosEnvio();
	pedido.codigo.focus();
	return false;
	}
	if (!(EsEntero(pedido.codigo.value)))
		{
		alert("El código del cliente contiene caracteres no válidos");
		MostrarDatosEnvio();
		pedido.codigo.focus();
		return false;
		} 
if (EstaVacio(pedido.contrasena.value))
	{
	alert("No se ha indicado la contraseña del cliente en el  pedido");
	MostrarDatosEnvio();
	pedido.contrasena.focus();
	return false;
	}


if (!LineaCorrecta(pedido.Ref1,pedido.Ref1b,pedido.Cantidad1,pedido.precio1))
{ return false
}

if (!LineaCorrecta(pedido.Ref12,pedido.Ref1b2,pedido.Cantidad12,pedido.precio12))
{ return false
}

if (!LineaCorrecta(pedido.Ref13,pedido.Ref1b3,pedido.Cantidad13,pedido.precio13))
{ return false
}

if (!LineaCorrecta(pedido.Ref14,pedido.Ref1b4,pedido.Cantidad14,pedido.precio14))
{ return false
}

if (!LineaCorrecta(pedido.Ref15,pedido.Ref1b5,pedido.Cantidad15,pedido.precio15))
{ return false
}

if (!LineaCorrecta(pedido.Ref16,pedido.Ref1b6,pedido.Cantidad16,pedido.precio16))
{ return false
}



return true;		
}

function printPedido( pedido, fecha ){

if (!(ComprobarDatosPedido(pedido)))
 return ;
 

var posx=(screen.width - 450)/2;
var posy=(screen.height - 250)/2;


 total=0;


		var win;
		
		win = window.open("","PEDIDO","top="+posy+",left="+posx+"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=800,height=400");
		win.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
win.document.writeln('<html>');
win.document.writeln('<head>');
win.document.writeln('<title>Cartonajes Bolram s.l.  ----  Ver Pedido  ----</title>');
win.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');


win.document.writeln('<style type="text/css">');
win.document.writeln('<!--');




win.document.writeln('.estiloBoton');
win.document.writeln('{');
	
	win.document.writeln('background-color: #FF9966;');
win.document.writeln('face-color:#FF9966;');
win.document.writeln('shadow-color:#FF9966;');
win.document.writeln('highlight-color:#FF9966;');
win.document.writeln('3dlight-color:#FF9966;');
win.document.writeln('darkshadow-color:#ffffff;');
win.document.writeln('color:#ffffff;');
win.document.writeln('arrow-color:#ffffff;');

win.document.writeln('}');
win.document.writeln('-->');

win.document.writeln('</style>');
win.document.writeln('</head>');

win.document.writeln('<body   >');
win.document.writeln('<table width="100%" border="0">');
 win.document.writeln('<tr>');
    win.document.writeln('<td width="44%"  colspan="2"><img src="./IMAGENES/fondoCabecera.gif" width="750" height="80"></td>');
	 win.document.writeln('</tr>');
  win.document.writeln('<tr>');
    win.document.writeln('<td width="44%" ><font color="#660066" size="2"><div align="center">' + fecha +'</font> </div></td>');
    win.document.writeln('<td width="56%">');
	win.document.writeln('<table width="80%" border="0" align="right">');
	 win.document.writeln('<tr>');
           win.document.writeln(' <td><font color="#660066" size="2">CODIGO CLIENTE: ' + pedido.codigo.value + '</font></td>');
          win.document.writeln('</tr>');
         
        win.document.writeln('</table></div></font></td>');
  win.document.writeln('</tr>');
win.document.writeln('</table>');
win.document.writeln('<br><table width="100%" border="1" bordercolor="#FF9966">');
  win.document.writeln('<tr bgcolor="#FF9966">'); 
    win.document.writeln('<td width="16%">'); 
      win.document.writeln('<div align="center"><strong><font color="#e9ddcf" face="Verdana, Arial, Helvetica, sans-serif">Referencia</font></strong></div></td>');
    win.document.writeln('<td width="16%">'); 
      win.document.writeln('<div align="center"><strong><font color="#e9ddcf" face="Verdana, Arial, Helvetica, sans-serif">Medidas</font></strong></div></td>');
       win.document.writeln('<td width="16%">'); 
      win.document.writeln('<div align="center"><strong><font color="#e9ddcf" face="Verdana, Arial, Helvetica, sans-serif">Calidad</font></strong></div></td>');
     win.document.writeln('<td width="16%">'); 
      win.document.writeln('<div align="center"><strong><font color="#e9ddcf" face="Verdana, Arial, Helvetica, sans-serif">Uds.</font></strong></div></td>');
     win.document.writeln('<td width="16%">'); 
      win.document.writeln('<div align="center"><strong><font color="#e9ddcf" face="Verdana, Arial, Helvetica, sans-serif">€/ud.</font></strong></div></td>');
     win.document.writeln('<td width="20%">'); 
      win.document.writeln('<div align="center"><strong><font color="#e9ddcf" face="Verdana, Arial, Helvetica, sans-serif">Observaciones</font></strong></div></td>');
   
  win.document.writeln('</tr>');
  

  printLinea1Pedido(win, pedido.Ref1,pedido.Ref1b,pedido.Medidas1,pedido.Calidad1,pedido.Cantidad1,pedido.precio1,pedido.obs1,pedido.linea1);
  printLinea1Pedido(win, pedido.Ref12,pedido.Ref1b2,pedido.Medidas12,pedido.Calidad12,pedido.Cantidad12,pedido.precio12,pedido.obs12,pedido.linea2);
   printLinea1Pedido(win, pedido.Ref13,pedido.Ref1b3,pedido.Medidas13,pedido.Calidad13,pedido.Cantidad13,pedido.precio13,pedido.obs13,pedido.linea3);
   printLinea1Pedido(win, pedido.Ref14,pedido.Ref1b4,pedido.Medidas14,pedido.Calidad14,pedido.Cantidad14,pedido.precio14,pedido.obs14,pedido.linea4);
   printLinea1Pedido(win, pedido.Ref15,pedido.Ref1b5,pedido.Medidas15,pedido.Calidad15,pedido.Cantidad15,pedido.precio15,pedido.obs15,pedido.linea15);
   printLinea1Pedido(win, pedido.Ref16,pedido.Ref1b6,pedido.Medidas16,pedido.Calidad16,pedido.Cantidad16,pedido.precio16,pedido.obs16,pedido.linea6);
  
  
	
	  
				  
  
  win.document.writeln('</table>');
   win.document.writeln('<br><br>');
     win.document.writeln('OBSERVACIONES: ' + pedido.observaciones.value);
   win.document.writeln('<br><br>');
  win.document.writeln('<table align="center"><tr><td>');
  win.document.writeln('<form name="imprimir" method="post" action="">');
  win.document.writeln('<table align="center">');
    win.document.writeln('<tr> ');
      win.document.writeln('<td> <div align="center"> ');
          win.document.writeln('<input name="Submit" class="estiloBoton" type="button" onClick="javascript:window.print();" value="Imprimir">');
        win.document.writeln('</div></td>');
    win.document.writeln('</tr>');
  win.document.writeln('</table>');
win.document.writeln('</form></td><td>');
 
win.document.writeln('<form name="enviarmail" method="post" action="">');
  win.document.writeln('<table align="center">');
    win.document.writeln('<tr> ');
      win.document.writeln('<td> <div align="center"> ');
          win.document.writeln('<input name="Submit" class="estiloBoton" type="button" onClick="javascript:window.opener.submitir();window.close()" value="EnviarMail">');
        win.document.writeln('</div></td>');
    win.document.writeln('</tr>');
  win.document.writeln('</table>');
win.document.writeln('</form></td></tr');
  win.document.writeln('</table>');
  
win.document.writeln('</body>');
win.document.writeln('</html>');

		win.document.close();
		win.focus();


}
