// JavaScript Document
function cargalineas(categoria)
{
	location.href="producto.php?frm_categoria="+categoria+"";
}
function cargamarcas(categoria,linea)
{
	location.href="producto.php?frm_categoria="+categoria+"&frm_linea="+categoria+"";
}

function validaEnv(form,stock){

	if(form.Cpedir.value == '' || form.Cpedir.value == '0'){

		alert("Agregue un valor valido.");

		return false;

	}else{

		if(form.Cpedir.value > stock){

			alert("Valor pedido mayor que existencia.");

			return false;

		}

		return true;

	}

}



function validaBusqueda(frm){

	if(frm.criterio.value == ''){

		alert("Agregue un valor a buscar.");

		return false;

	}else{

		return true;

	}			   

}



function unmaskPassword(id) {

  var pw = document.getElementById(id);

  var chb = document.getElementById(id+'unmask');



  try {

    // first try IE way - it can not set name attribute later

    if (chb.checked) {

      var newpw = document.createElement('<input type="text" name="'+pw.name+'">');

    } else {

      var newpw = document.createElement('<input type="password" name="'+pw.name+'">');

    }

    newpw.attributes['class'].nodeValue = pw.attributes['class'].nodeValue;

  } catch (e) {

    var newpw = document.createElement('input');

    newpw.setAttribute('name', pw.name);

    if (chb.checked) {

      newpw.setAttribute('type', 'text');

    } else {

      newpw.setAttribute('type', 'password');

    }

    newpw.setAttribute('class', pw.getAttribute('class'));

  }

  newpw.id = pw.id;

  newpw.size = pw.size;

  newpw.onblur = pw.onblur;

  newpw.onchange = pw.onchange;

  newpw.value = pw.value;

  pw.parentNode.replaceChild(newpw, pw);

}





function abre_ventana(nombre,ancho,alto,linka,menu,scrol,status){

	window.open(linka,nombre,"top=1 left=1 width="+ancho+",height="+alto+",status="+status+",resizable=no,scrollbars="+scrol+",menubar="+menu)

}



function validaProducto(form){

	var alerta="Errores:\n";

	if (form.combo1.value == "0") {alerta+="-La categoria no puede estar vacia\n";}

	if (form.combo2.value == "" || form.combo2.value == "0") {alerta+="-La linea no puede estar vacia\n";}

	if (form.frm_marca.value == "" || form.frm_marca.value == "0") {alerta+="-La marca no puede estar vacia\n";}

	if (form.combo3.value == "" || form.combo3.value == "0") {alerta+="-La clase no puede estar vacia\n";}

	if (form.nombre.value == "") {alerta+="-El nombre no puede estar vacio\n";}

	if (form.referencia.value == "") {alerta+="-La referencia no puede estar vacia\n";}

	if (form.precio1.value == "") {alerta+="-El precio del cliente no puede estar vacia\n";}

	if (form.precio2.value == "") {alerta+="-El precio del proveedor no puede estar vacio\n";}

	if (alerta!="Errores:\n"){

		alert(alerta);	

		return false;

	}else{

		updateRTEs();

		return true;

	}	

}



function Vnumero(e) { // 1

// onkeypress="return Vnumero(event)"

	tecla = (document.all) ? e.keyCode : e.which; // 2

	if (tecla==8) return true; // 3

	patron =/[0-9]/; // Valido que solo sean Numeros lo que se teclee

	te = String.fromCharCode(tecla); // 5

	return patron.test(te); // 6

}



function getDataServer(url, vars){

     var xml = null;

     try{

         xml = new ActiveXObject("Microsoft.XMLHTTP");

     }catch(expeption){

         xml = new XMLHttpRequest();

     }

     xml.open("GET",url + vars, false);

     xml.send(null);

     if(xml.status == 404) alert("Url no valida");

     return xml.responseText;

}



function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_findObj(n, d) { //v4.01

  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 && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

