function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
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];}
}


function ConfirmarBorrado(home)
{
	if (confirm("żEsta seguro que quiere borrar el registro?\nSeran eliminadas tambien las subcategorias asociadas")) {
		location.href=home;
	}
}

function checkCategoria(MyForm) {

        if ((MyForm.name.value == null ) || (MyForm.name.value == '')) {
                alert('Debe ingresar el nombre de la categoria');
                MyForm.name.focus();
                return false;
        }
        return true;
}

function ConfEliminar(txt)
{
        if (confirm("żEsta seguro que quiere borrar el registro?" + txt)) {
                return true;
        }
	return false;
}
function checkSearchCode(MyForm) {

        if ((MyForm.search.value == null ) || (MyForm.search.value == '')) {
               alert('Debe ingresar un texto a buscar');
                MyForm.search.focus();
                return false;
        }
        return true;
}
function checkBannerEdit(MyForm) {

        if ((MyForm.detalle.value == null ) || (MyForm.detalle.value == '')) {
               alert('Debe ingresar una Empresa');
                MyForm.detalle.focus();
                return false;
        }
        if ((MyForm.linke.value == null ) || (MyForm.linke.value == '')) {
                alert('Debe ingresar el Link');
                MyForm.linke.focus();
                return false;
        }
        return true;
}

function checkBanner(MyForm) {

        if ((MyForm.detalle.value == null ) || (MyForm.detalle.value == '')) {
               alert('Debe ingresar una Empresa');
                MyForm.detalle.focus();
                return false;
        }
        if ((MyForm.linke.value == null ) || (MyForm.linke.value == '')) {
                alert('Debe ingresar el Link');
                MyForm.linke.focus();
                return false;
        }
        if ((MyForm.banner.value == null ) || (MyForm.banner.value == '')) {
                alert('Debe ingresar el Banner');
                MyForm.banner.focus();
                return false;
        }
        return true;
}

function checkMarca(MyForm) {

        if ((MyForm.name.value == null ) || (MyForm.name.value == '')) {
                alert('Debe ingresar el nombre de la marca');
                MyForm.name.focus();
                return false;
        }
        return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function checkProducto(MyForm) {


	if ((MyForm.cleancat.value == '') || (MyForm.cleancat.value == '0')){
                alert('Debe seleccionar una Categoria');
                MyForm.cat.focus();
                return false;
        }
	if ((MyForm.cleansubcat.value == '') || (MyForm.cleansubcat.value == '0')){
		alert('Debe seleccionar una SubCategoria');
                MyForm.subcat.focus();
                return false;
	}
        if (MyForm.marca.options[MyForm.marca.selectedIndex].index == 0){
                alert('Debe seleccionar una Marca');
                MyForm.marca.focus();
                return false;
        }
        if ((MyForm.nombre.value == null) || (MyForm.nombre.value == '')) {
                alert('Debe ingresar un Nombre');
                MyForm.nombre.focus();
                return false;

        }
        if (!(IsNumeric(MyForm.precio.value))) {
                alert('Debe ingresar un precio de valor numerico');
                MyForm.precio.focus();
                return false;

        }
    	selection  = null; 
    	thisButton = MyForm.promo; 
    	for( var i=0; i<thisButton.length; i++ ) { 
        	if( thisButton[i].checked ) { 
           		selection = thisButton[i].value; 
        	} 
    	} 
    	if( selection == 1 ) { 
		if ((MyForm.desde1.value == null) || (MyForm.desde1.value == '') || (MyForm.hasta1.value == null) || (MyForm.hasta1.value == '')) {
                        alert( "Debe ingresar las fechas de vencimiento en Oferta" );
                        MyForm.desde1.focus();
                        return false;
                }

    	} 
        if( selection == 2 ) {
		if ((MyForm.desde2.value == null) || (MyForm.desde2.value == '') || (MyForm.hasta2.value == null) || (MyForm.hasta2.value == '')) {
	                alert( "Debe ingresar las fechas de vencimiento en Destacado" );
			MyForm.desde2.focus();
        	        return false;
		}
        }
	return true;
}

function AgregarCategoria (MyForm,donde) {
        if ((MyForm.newcat.value == null) || (MyForm.newcat.value == '')) {
                alert('Debe ingresar una Categoria a agregar');
                MyForm.newcat.focus();
        }
	else {
		home = "do_add_categ.php?cat=" + MyForm.newcat.value + "&home=" + donde;
		if (donde == 'edit') {
			home += "&code=" + MyForm.code.value;
		}
		window.open(home,'','toolbar=no,menubar=no,scrollbar=no,width=200,height=100');
	}

}

function AgregarSubCategoria (MyForm,donde) {
        if ((MyForm.newsubcat.value == null) || (MyForm.newsubcat.value == '') || (MyForm.cat.options[MyForm.cat.selectedIndex].index == 0)) {
                alert('Debe ingresar una SubCategoria a agregar\nY tener seleccionada una Categoria');
                MyForm.newsubcat.focus();
        }
        else {
                home = "do_add_subcateg.php?cat=" + MyForm.cleancat.value + "&subcat=" + MyForm.newsubcat.value + "&home=" + donde;
	        if (donde == 'edit') {
			home += "&code=" + MyForm.code.value;
                }

                window.open(home,'','toolbar=no,menubar=no,scrollbar=no,width=200,height=100');
        }

}

function AgregarMarca (MyForm,donde) {
        if ((MyForm.newmarca.value == null) || (MyForm.newmarca.value == '')) {
                alert('Debe ingresar una Marca a agregar');
                MyForm.newmarca.focus();
        }
        else {
                home = "do_add_marca.php?&marca=" + MyForm.newmarca.value + "&home=" + donde;
		if (MyForm.cleancat != "") {
			home += "&cat=" + MyForm.cleancat.value;
		}
                if (MyForm.cleansubcat != "") {
                        home += "&subcat=" + MyForm.cleansubcat.value;
                }
                if (donde == 'edit') {
                        home += "&code=" + MyForm.code.value;
                }
                window.open(home,'','toolbar=no,menubar=no,scrollbar=no,width=200,height=100');
        }

}

function checkMultipleEdit(MyForm) {


var MyCount = MyForm.elements.length;

	for (var i = 0; i < MyCount; i++){
		var obj = MyForm.elements[i];
		if (obj.type == "text") {
			if ((obj.value == "") || (obj.value == null) || (!(IsNumeric(obj.value)))) { 
				alert("Debe ingresar un precio para cada producto y debe ser numerico");
				return false;
			}
		}
	}
        return true; 
}

function checkUser(MyForm) {

	if ((MyForm.nombre.value == null) || (MyForm.nombre.value == '')) {
                alert('Debe ingresar un Nombre');
                MyForm.nombre.focus();
                return false;
        }
	if ((MyForm.apellido.value == null) || (MyForm.apellido.value == '')) {
                alert('Debe ingresar un Apellido');
                MyForm.apellido.focus();
                return false;
        }
	if ((MyForm.empresa.value == null) || (MyForm.empresa.value == '')) {
                alert('Debe ingresar una Empresa');
                MyForm.empresa.focus();
                return false;
        }
	if ((MyForm.usuario.value == null) || (MyForm.usuario.value == '')) {
                alert('Debe ingresar un Usuario');
                MyForm.usuario.focus();
                return false;
        }
	if ((MyForm.email.value == null) || (MyForm.email.value == '')) {
                alert('Debe ingresar un Email');
                MyForm.email.focus();
                return false;
        }
	return true
}

function checkUserE(MyForm) {

        if ((MyForm.nombre.value == null) || (MyForm.nombre.value == '')) {                                                                   alert('Debe ingresar un Nombre');
                MyForm.nombre.focus();
                return false;
        }
        if ((MyForm.apellido.value == null) || (MyForm.apellido.value == '')) {
                alert('Debe ingresar un Apellido');
                MyForm.apellido.focus();
                return false;
        }
        if ((MyForm.empresa.value == null) || (MyForm.empresa.value == '')) {
                alert('Debe ingresar una Empresa');
                MyForm.empresa.focus();
                return false;
        }
        if ((MyForm.usuario.value == null) || (MyForm.usuario.value == '')) {
                alert('Debe ingresar un Usuario');
                MyForm.usuario.focus();
                return false;
        }
        if ((MyForm.email.value == null) || (MyForm.email.value == '')) {
                alert('Debe ingresar un Email');
                MyForm.email.focus();
                return false;
        }
        return true
}

function checkLogin(MyForm) {

	if ((MyForm.usuario.value == null) || (MyForm.usuario.value == '')) {
		alert('Debe ingresar un nombre de usuario');
		MyForm.usuario.focus();
		return false;
	}
	if ((MyForm.password.value == null) || (MyForm.password.value == '')) {
                alert('Debe ingresar un password');
                MyForm.password.focus();
		return false;
        }
	return true;
}

function checkPass(MyForm) {

	if ((MyForm.usuario.value == null) || (MyForm.usuario.value == '')) {
		alert('Debe ingresar un nombre de usuario');
		MyForm.usuario.focus();
		return false;
	}
	return true;
}

function checkPopEnvio(MyForm) {

	if ((MyForm.nombreD.value == null) || (MyForm.nombreD.value == '')) {
		alert('Debe ingresar un nombre de destinatario');
		MyForm.nombreD.focus();
		return false;
	}
	if ((MyForm.mailD.value == null) || (MyForm.mailD.value == '')) {
		alert('Debe ingresar un email de destinatario');
		MyForm.mailD.focus();
		return false;
	}
	if ((MyForm.nombreR.value == null) || (MyForm.nombreR.value == '')) {
		alert('Debe ingresar un nombre de remitente');
		MyForm.nombreR.focus();
		return false;
	}
	if ((MyForm.emailR.value == null) || (MyForm.emailR.value == '')) {
		alert('Debe ingresar un email de remitente');
		MyForm.emailR.focus();
		return false;
	}
	
	return true;
}


function checkPrecio(MyForm) {

        if ((MyForm.rango.value == null) || (MyForm.rango.value == '')) {
                alert('Debe ingresar un Rango');
                MyForm.rango.focus();
                return false;
        }
        if ((MyForm.vari.value == null) || (MyForm.vari.value == '')) {
                alert('Debe ingresar una Variacion');
                MyForm.vari.focus();
                return false;
        }
        return true;
}

function checkBuscar(MyForm) {
	
	if ((MyForm.search.value == null) || (MyForm.search.value == '')) {
                alert('Debe ingresar un texto a buscar');
                MyForm.search.focus();
                return false;
        }
        return true;
}

var firstPass=0

function copy(from,to) {
 if (firstPass==0) { firstPass=1; rollup(to); }
 for (var i=0; i < from.options.length; i++) {
  if (from.options[i].selected && from.options[i].value != "") {
   var opt = new Option();
   opt.value = from.options[i].value;
   opt.text = from.options[i].text;
   to.options[to.options.length] = opt;
   from.options[i].value = "";
   from.options[i].text = "";
  }
 }
 rollup(to);
}

function rollup(box) {
 for (var i=0; i < box.options.length; i++) {
  if (box.options[i].value == "") {
   for (var j=i; j < box.options.length - 1; j++) {
    box.options[j].value = box.options[j+1].value;
    box.options[j].text = box.options[j+1].text;
   }
   var ln = i;
   break;
  }
 }
 if (ln < box.options.length) {
  box.options.length -= 1;
  rollup(box);
 }
}

function doSubmit ( Form ) {
 with (Form.toList) {
 var tx = "";
  for (var i=0; i < options.length; i++) {
   tx += options[i].value + ",";
  }
  Form.lista.value= tx;
 }
 return true;
}

