//****************************************************************************************
function CambiarIdioma(widioma)
{
//document.menu.FORMCARRO.value=document.cookie;
document.menu.FORMIDIOMA.value=widioma;
document.menu.FORMPROGRAMA.value='IDI';
document.menu.submit();
}
//****************************************************************************************
function EjecutarOpcion(wprograma)
{
document.menu.FORMAGRUPADOCODFAM.value = "";
document.menu.FORMAGRUPADOCODSFAM.value = "";
document.menu.FORMAGRUPADOCODART.value = "";
document.menu.FORMPROGRAMA.value=wprograma;
//document.menu.FORMCARRO.value=document.cookie;
if (wprograma=="B") 
//   { if (Trim(document.menu.FORMBUSCARPORVALOR.value) == "" && document.menu.FORMBUSCARPORTIPO.value!="C") 
   { if (Trim(document.menu.FORMBUSCARPORVALOR.value) == "") 
        { document.menu.FORMBUSCARPORVALOR.focus();
	      document.menu.FORMBUSCARPORTIPO.value="B";
          alert("La busqueda ha de tener algun valor"); 
	      return;};
     var minimo = Trim(document.menu.FORMBUSCARPORVALOR.value);
	 document.menu.FORMBUSCARPORVALOR.value=minimo
	 if (minimo.length < 4)
        { document.menu.FORMBUSCARPORVALOR.focus();
	      document.menu.FORMBUSCARPORTIPO.value="B";
          alert("El valor de la busqueda ha de tener como minimo 4 letras"); 
	      return;}	 
     if (document.menu.FORMBUSCARPORTIPO.value!="B") { document.menu.submit(); }
   }
else {
      if (wprograma=="REG")
         { if (document.getElementById("FORM-REGISTRARSE-NOMBRE").value == "PPI" && Trim(document.getElementById("FORM-REGISTRARSE-EMAIL").value) == "PPI")
		   {document.menu.submit();return}
		   if (Trim(document.getElementById("FORM-REGISTRARSE-NOMBRE").value) == "" ) 
              { document.getElementById('FORM-REGISTRARSE-NOMBRE').focus();
               alert($error_nombre); 
	           return;}
          if (Trim(document.getElementById("FORM-REGISTRARSE-EMAIL").value) == "" ) 
             { document.getElementById('FORM-REGISTRARSE-EMAIL').focus();
              alert($error_email); 
	          return;}
          var reg_exp=/^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/
          if(!reg_exp.test(document.getElementById("FORM-REGISTRARSE-EMAIL").value))
             { document.getElementById('FORM-REGISTRARSE-EMAIL').focus();
	           alert($error_email2);
	           return;} 
	     }
     document.menu.submit();
   }
}
//****************************************************************************************	   
function Trim(sString) 
    { while (sString.substring(sString.length-1, sString.length) == ' ') 
	        { sString = sString.substring(0,sString.length-1); }
    return sString;
}
//****************************************************************************************
function seleccionar(wpagina,wprograma,wcodigofamilia,wcodigosubfamilia,wcodigoarticulo)
	{
	document.menuficha.FORMPROGRAMA.value=wprograma;
    document.menuficha.FORMPAGINA.value=wpagina; 
    document.menuficha.FORMAGRUPADOCODFAM.value=wcodigofamilia;
	document.menuficha.FORMAGRUPADOCODSFAM.value=wcodigosubfamilia;
	document.menuficha.FORMAGRUPADOCODART.value=wcodigoarticulo;
	document.menuficha.submit();
}
//****************************************************************************************
//   PARA EL PEDIDO 
//****************************************************************************************
var art = new Array(99);
var $cantpendiente="";
var $elimpendiente="";
var $sucodigo=""; 
var contelim = 0;
//******************************************************************************************
function chkcp(){
var wcp = document.formped.FORMCP.value;
if (wcp.substring(0,2) < "53" && wcp.substring(0,2) > "00" && wcp.substring(2,5) > "000" && (esNumerico(wcp.substring(2,3)) == true && esNumerico(wcp.substring(3,4)) == true && esNumerico(wcp.substring(4,5)) == true)) 
     { document.formped.submit();}
else { document.formped.FORMCP.focus();
       alert($error_cp);
	   return true
     }
}
//******************************************************************************************
function esNumerico(valor)
{ 
if (valor < "0" || valor > "9") { return (false);}
else {return (true)}; 
}                 
//******************************************************************************
function enviar(valor)
{
 //   HE DE INTENTAR NO UTILIZAR LAS FUNCIONES chgelim Y chgcant PUES CREO QUE EL PROBLEMA ESTA 
 //   EN QUE NO ES COMPATIBLE EL onClick en el CHECKBOX
 //   TENDRIA QUE INTENTAR REALIZAR LO MISMO DE LAS FUNCIONES PERO PARA TODOS LOS CHECKBOX AL MISMO
 //   TIEMPO
 //  todos=document.getElementsByTagName('input');
 //  for(i=0;i<todos.length;i++)
 //     { if(todos[i].checked){art[i]=todos[i].name + ' '+ todos[i].value  + 'S';}
 //  LA FUNCION QUE TNGO QUE HACER SERIA ALGO SIMILAR A LO ANTERIOR
    document.formped.FORMPROGRAMA.value=valor;
	document.formped.FORMCARRO.value="";
	var i,mod; 
	mod = 0;
    for (i=0;i<=98;i++)	
	   { if (art[i]!=undefined) { document.formped.FORMCARRO.value=document.formped.FORMCARRO.value+art[i]; mod = 1; } } 
	if (mod == 1 && valor!="AC" ) {document.formped.FORMPROGRAMA.value="AC";}
    document.formped.submit();
}
//**************************************************************************
function padLeft(str,pad,count)
{ 
  while(str.length<count) str=pad+str;
  return str;
}
//******************************************************************************************
function chequear()
{
var checks = document.getElementsByTagName("input"); 
cont =  0;
document.formped.nada.value ="";
for ( var i = 0; i < checks.length; i++ )
{ if (checks[i].type=='checkbox' && checks[i].checked)
   {cont = cont + 1;
    codigo= checks[i].name.substring(4,14); 
  document.formped.nada.value = document.formped.nada.value + "," + getElement('cant' + codigo).name;
   }
}
}
function chgelim(codigo,cant,cont) 
{
document.formped.nada.value = 'Codigo: ' + 'elim' + codigo + ' .chequed: ' + getElement('elim' + codigo).checked ;
if (getElement('elim' + codigo).checked == true) 
     { art[cont]=codigo + ' '+ getElement('cant' + codigo).value  + 'S'; }
else { cant2=parseInt(getElement('cant' + codigo).value);
       if (cant2 != cant) {art[cont]=codigo + ' ' + getElement('cant' + codigo).value  + ' ';}
       else {art[cont]=undefined;}
     }
}
//*****************************************************************************************
function chgcant(codigo,cant,cont)
{  
    document.formped.nada.value = 'Codigo: ' + 'elim' + codigo ;
    var i='1';
    if (getElement('sus' + codigo + '1').checked) {i='1';}
	if (getElement('sus' + codigo + '2').checked) {i='2';}
    if (getElement('sus' + codigo + '3').checked) {i='3';} 
	     cantstra=String(cant);
         art[cont]=codigo + i + padLeft(cantstra, '0' , 2) + ' ';
}
//*****************************************************************************************
function chequeavalor(codigo,cont)
{
if (getElement('cant' + codigo).value > 99 || getElement('cant' + codigo).value < 1 ) 
     { getElement('cant' + codigo).value = getElement('ant' + codigo).value; }
else { chgcant(codigo,getElement('cant' + codigo).value,cont); }
}
//**************************************************************************
function getElement(aID) 
{
return (document.getElementById(aID)) ? document.getElementById(aID)
                                      : document.all[aID];
}
//**************************************************************************
