function getpedido() {
   xmon=0;
   var el=document.form1.pedido.value;
   if (el=="0") {
      var xmon="0.00";
      var b="</b>";
   }
   else {
   for (i=0;i< el.length;i++) {
       ch=el.charAt(i)
       if (ch==":") {
          xmon=el.substr(i+1);
          break;
       }
   }
   x = xmon.split('.');
   x1 = x[0];
   x2 = x.length > 1 ? ',' + x[1] : '';
   var rgx = /(\d+)(\d{3})/;
   while (rgx.test(x1)) {
     x1 = x1.replace(rgx, '$1' + '.' + '$2');
   }
   var xmon=x1 + x2;
   texto = document.createTextNode("Monto total de la compra BsF. "+xmon);
   var b="<b>";
   }
   var div=document.getElementById("montdet");
//   div.appendChild(texto);
   div.innerHTML="Monto total de la compra "+b+"BsF. "+xmon+"</b>";
}

function switchMenu(obj,disp) {
	var el = document.getElementById(obj);
	if (disp== "0" ) {
		el.style.display = 'none';
		document.getElementById("xtipopagobanco2").style.display='';
	}
	else {
		el.style.display = '';
		document.getElementById("xtipopagobanco2").style.display='none';
	}
}

function agregar(prod,noadd) {
   var el=document.getElementById("cnt"+prod)
   var en=document.getElementById("env"+prod)
   if (noadd=="1")
      location.href="agrega.php?p="+prod+"&c=1&e=3&t="+noadd;
   else
      location.href="agrega.php?p="+prod+"&c="+el.value+"&e="+en.value+"&t="+noadd;
}

function chkNumericx(obj,prod) {
    chkNumeric(obj);
    agregar(prod,"2");
}

function chkNumeric(objName) {
   var checkOK = "0123456789";
   var checkStr = objName;
   var allValid = true;
   var decPoints = 0;
   var allNum = "";
   if (checkStr.value=="") return false;
   else {
      for (i = 0;  i < checkStr.value.length;  i++) {
          ch = checkStr.value.charAt(i);
          for (j = 0;  j < checkOK.length;  j++)
              if (ch == checkOK.charAt(j))
                 break;
              if (j == checkOK.length) {
                 allValid = false;
                 break;
              }
              if (ch != ",")
                 allNum += ch;
      }
      if (!allValid)
          objName.value=objName.value.substr(0,objName.value.length-1);
   }
}

function chkNumeric2(objName) {
   var checkOK = ".0123456789";
   var checkStr = objName;
   var allValid = true;
   var decPoints = 0;
   var allNum = "";
   if (checkStr.value=="") return false;
   else {
      for (i = 0;  i < checkStr.value.length;  i++) {
          ch = checkStr.value.charAt(i);
          for (j = 0;  j < checkOK.length;  j++)
              if (ch == checkOK.charAt(j))
                 break;
              if (j == checkOK.length) {
                 allValid = false;
                 break;
              }
              if (ch != ",")
                 allNum += ch;
      }
      if (!allValid)
          objName.value=objName.value.substr(0,objName.value.length-1);
      else {  // solo pone 2 decimales
         if (objName.value.substr(objName.value.length-1,1)==".") return false;
//         n=eval(objName.value);
         n=(Math.floor(n*1000))/1000;
         objName.value=n;
      }
   }
}



function confirma(mensaje) { 
    var msg=mensaje.replace(/_br_/gi, "\n");
    return confirm('Presione Aceptar para confirmar la siguiente operación:\n'+msg);
}

function confirma_bor(msg) {
    return confirm('¿Está seguro que desea eliminar '+msg+'?');
}
function confirma_act(msg) {
    return confirm('¿Está seguro que desea activar '+msg+'?');
}
function confirma_sus(msg) {
    return confirm('¿Está seguro que desea suspender '+msg+'?');
}


function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function textCounter(field,cntfield,maxlimit) {
   if (field.value.length > maxlimit)
       field.value = field.value.substring(0, maxlimit);
   else
       cntfield.value = maxlimit - field.value.length;
}



function subcategoria(subtip) {
   var lista=document.form1.tipo;
   ClearOptions(document.form1.subtipo); 
   if (lista[lista.selectedIndex].value==1) {
      AddToOptionList(document.form1.subtipo, 1, "Marchas",subtip);
      AddToOptionList(document.form1.subtipo, 2, "Campañas",subtip);
      AddToOptionList(document.form1.subtipo, 3, "Inauguraciones",subtip);
   }
   if (lista[lista.selectedIndex].value==2) {
      AddToOptionList(document.form1.subtipo, 1, "MP3",subtip);
   }

   if (lista[lista.selectedIndex].value==3) {
      AddToOptionList(document.form1.subtipo, 1, "Videos",subtip);
   }
   if (lista[lista.selectedIndex].value==4) {
      AddToOptionList(document.form1.subtipo, 1, "Tonos",subtip);
   }
   if (lista[lista.selectedIndex].value==5) {
      AddToOptionList(document.form1.subtipo, 1, "800x600",subtip);
      AddToOptionList(document.form1.subtipo, 2, "1024x768",subtip);
      AddToOptionList(document.form1.subtipo, 3, "1280x800",subtip);
   }
   if (lista[lista.selectedIndex].value==6) {
      AddToOptionList(document.form1.subtipo, 1, "Documentos",subtip);
   }
}

function ClearOptions(OptionList) {
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}

function imprime(){
	window.print();
}


function AddToOptionList(OptionList, OptionValue, OptionText, OptionSel) {
   if (OptionSel==OptionValue)
      OptionList[OptionList.length] = new Option(OptionText, OptionValue,"defauldSelected");
   else
      OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}