﻿//////////////////////////////
///// VARIABLES GLOBALES /////
//////////////////////////////
var CodCliente = '';
var IdNoteolvides = '';
var Path_Imagenes = 'Imagenes/';
var IDDivPintarResultdos = '';
var NumeroDeFichasAbiertas = 1;
var moz = document.getElementById && !document.all;
var estoyArrastrando = false;
var dobj;
var DIVMover = "nachito"
var DIVMovido = "";
var IdPnl = '';
var Idlbl = '';
var Codcliente = '';

document.onmousedown = presionarBoton;
document.onmousemove = arrastrarRaton;
document.onmouseup = soltarBoton;

document.onkeypress = function(e) {
    var esIE = (document.all);
    var esNS = (document.layers);
    tecla = (esIE) ? event.keyCode : e.which;
    if (tecla == 13) {
        //DMI : VALIDAR USER/PWD
        try {
            if (($get('ctl00_txtuser').value != '') && ($get('ctl00_txtpass').value != '')) {
                $get('ctl00_btnlogin').click();
                return false;
            }


        } catch (Error) { }
        try {
            //DMI : BUSCANDOR DE PRODUCTOS
            if ($get('H_searchbox_input').value != '') {

                try {
                    if ($get('ctl00_ContentPlaceHolder1_EstoyEnBusqueda').value == "true") {
                        Codcliente = $get('ctl00_CodClienteJS').value;
                        PintarResultados_Texto(6, $get('H_searchbox_input').value, Codcliente, $get('ctl00_CodAlmacen').value, '', $get('ctl00_UserId').value);
                        $get("searchbox_resultados").style.display = 'none';
                        $get("H_searchbox_input").value = ''
                        ActivarGoSw = false;
                    }
                }
                catch (Error) {
                    document.location.href = 'FrmBusquedaAvanzada.aspx?Texto=' + $get('H_searchbox_input').value;
                    return false;
                }
            }
        }
        catch (Error) {
        }


        //MR.MICRO (VALIDA USUARIO PASSWORD-MASTER)
        try {
            if (($get('TxtLogin').value != '') && ($get('TxtPwd').value != '')) {
                Val();
                return false;
            }


        } catch (Error) { }

        //MR.MICRO (busca productos por texto)
        try {
            if (($get('header_buscador_caja').value != '') && ($get('header_buscador_caja').value != 'Buscar...')) {
                PintarResultadosBASleep();
                return false;
            }
        } catch (Error) { }

        try {
            // MR.MICRO (BUSCANDO PUNTO MAS CERCANO)
            if ($get('ST_input').value != '') {
                EscribeTuCP($get('ST_input').value);
                return false;
            }
        }
        catch (Error) {
        }

        try {
            // MR.MICRO (TRAZA RUTA ENTRE MI CASA Y EL PUNTO MR)
            if ($get('ST_input_Route').value != '') {
                TrazarMapa();
                return false;
            }
        }
        catch (Error) {
        }

        return false;
    }
}

function Lanzar347() {
    Codcliente = $get('ctl00_CodClienteJS').value;
    FichasDeProducto.Lanzar347(Codcliente,EnviaFacturasDeUnRango_Ok);
}

function EnviaFacturasDeUnRango() {
    if ($get('input_fechaIni').value == '') { alert('Debe especificar la fecha de inicio, Formato : 01/01/2001'); return ''; }
    if ($get('input_fechaIFin').value == '') { alert('Debe especificar la fecha de fin, Formato : 31/12/2001'); return ''; }
    Codcliente = $get('ctl00_CodClienteJS').value;
    FichasDeProducto.EnviaFacturasDeUnRango(Codcliente, $get('input_fechaIni').value, $get('input_fechaIFin').value, EnviaFacturasDeUnRango_Ok)
}

function EnviaFacturasDeUnRango_Ok(resultado) {alert('El informe llegara en unos minutos en la cuenta ' + $get('ctl00_EmailCliente').value);}
function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}

function DescargaExcel() {
    if ($get('ctl00_Registrado').value == 'True') {
        Codcliente = $get('ctl00_CodClienteJS').value;
        var Email = $get('ctl00_EmailCliente').value;
        FichasDeProducto.DescargaExcel(Codcliente, Email)
        alert('En unos instantes le envieremos nuestro catalogo de productos en excel, a ' + Email);
    }
    else { alert('Debe introducir sus claves de cliente, para poder obtener nuestro catalogo en excel'); }
}

function redondea(sVal, nDec) {
    var n = parseFloat(sVal);
    var s;
    n = Math.round(n * Math.pow(10, nDec)) / Math.pow(10, nDec);
    s = String(n) + "." + String(Math.pow(10, nDec)).substr(1);
    s = s.substr(0, s.indexOf(".") + nDec + 1);
    if (Right(s, 1) == '.') {
        return s.substring(0, s.length - 1);
    } else {
        return s;
    }
}

function MuestraSubCatID_AutoCompletar(SubCatID) { 

            try {
                    if ($get('ctl00_ContentPlaceHolder1_EstoyEnBusqueda').value == "true") {
                        GuardarCatid(SubCatID);
                        Filtrar('');
                        $get("searchbox_resultados").style.display = 'none';
                        $get("H_searchbox_input").value = ''
                        ActivarGoSw = false;
                    }
                }
                catch (Error) {
                    document.location.href = 'http://www.dmi.es/FRMBusquedaAvanzada.aspx?Subcatid=' + SubCatID;
                }

}

function presionarBoton(e) {
    if (DIVMovido == '') { } else {
        var fobj = moz ? e.target : event.srcElement;
        while (fobj.tagName.toLowerCase() != "html" && fobj.id != DIVMover) {
            fobj = moz ? fobj.parentNode : fobj.parentElement;
        }

        if (fobj.id == DIVMover) {
            estoyArrastrando = true;
            dobj = fobj;
            return false;
        } 
    }
}

function RolloverBackground(obj, color) {
    $get(obj).style.backgroundColor = color;
}

function arrastrarRaton(e) {
    if (estoyArrastrando) {
        newLeft = moz ? e.clientX : event.clientX;
        newTop = moz ? e.clientY : event.clientY;
        document.getElementById(DIVMovido).style.left = newLeft + "px";
        document.getElementById(DIVMovido).style.top = newTop + 200 + "px";
        return false;
    }
}
function soltarBoton() {
    estoyArrastrando = false;
}


function LimpiarInput(obj) {
    $get(obj).value = '';
}

function HacerInvisible(obj) {
    $get(obj).style.visibility = 'hidden';
}

function HacerVisible(obj) {
    $get(obj).style.visibility = 'visible';
}

function PonerBlock(obj) {
    $get(obj).style.display = 'block';
}

function PonerOculto(obj) {
    $get(obj).style.display = 'none';
}

function MostraryOcultarRetardo(obj) { $get(obj).style.display = 'block'; setTimeout("PonerOculto('" + obj + "')", 5000); }

function RolloverImagen(imagen, nuevaimagen) { $get(imagen).src = nuevaimagen; }

function bajar(oj) { window.scrollTo(0, oj); }
function MostrarPanel(Panel) { $get(Panel).style.display = 'block'; }

function MostrarCapa_y_OcultarOtra(capavisible, capaoculta) {
    try { $get(capaoculta).style.display = 'none'; } catch (Error) { }
    try { $get(capavisible).style.display = 'block'; } catch (Error) { }
}

function LLamarAlCargador(txt) {$get('MPCapaCargando_div').style.visibility = 'visible';$get('MPCapaCargando_label').innerHTML = txt;}
function QuitarCargador() {$get('MPCapaCargando_div').style.visibility = 'hidden';}
function ComprobarElNavegador() {
    if (typeof document.body.style.maxHeight != "undefined") {
        
    } else {
    if (document.URL != "http://www.dmi.es/FRMLectorHTML.aspx?Pagina=Recomendaciones.htm") {
        document.location.href = "FRMLectorHTML.aspx?Pagina=Recomendaciones.htm";
    }
  }

}
function CambiarImagen(obj,ruta) {$get(obj).src = ruta;}
function IluminarTexto(Span, color) {try {$get(Span).style.color = color;} catch (Error) { }}
function GuardarEncuesta() {$get('ctl00_ContentPlaceHolder1_Encuesta').value = $get('TableEncuesta').innerHTML;}
function MostrarOcultar3Objetos(obj1, obj2, obj3) {
    if ($get(obj1).style.display == 'block')
    { $get(obj1).style.display = 'none'; }
    else
    { $get(obj1).style.display = 'block'; }

    if ($get(obj2).style.display == 'block')
    { $get(obj2).style.display = 'none'; }
    else
    { $get(obj2).style.display = 'block'; }

    if ($get(obj3).style.display == 'block')
    { $get(obj3).style.display = 'none'; }
    else
    { $get(obj3).style.display = 'block'; }
}

function Mostrar3Objetos(obj1, obj2, obj3, estado) {$get(obj1).style.display = estado;$get(obj2).style.display = estado;$get(obj3).style.display = estado;}
function EnviarFichaPorEmail(TuNombre, TuEmail, EmailDestinatario, Asunto, Body, MiImg, Porcen, Producto) {
    try {
        var TuNombreC = $get(TuNombre).value;
        var TuEmailC = $get(TuEmail).value;
        var EmailDestC = $get(EmailDestinatario).value;
        var AsuntoC = $get(Asunto).value;
        var BosyC = $get(Body).value;
        var MiImgC; try { MiImgC = $get(MiImg).checked; }

        catch (Error) 
        { MiImgC = false; }
        var PorcenC;
        try {
            PorcenC = $get(Porcen).value;
         }
         catch (Error) { PorcenC = '0'; }
         //alert('Ficha de Producto enviada correctamente');
        document.forms[0].hidTDClickID.value = 'Envio_Send#' + TuNombreC + '#' + TuEmailC + '#' + EmailDestC + '#' + AsuntoC + '#' + BosyC + '#' + MiImgC + '#' + PorcenC + '#' + Producto; document.forms[0].btnTDClicked.click(); alert(TuNombreC + ', Su ficha se ha enviado correctamente a ' + EmailDestC);
    }
    catch (Error) { }
}

function ROver_BackgroundPosition(obj, alto, ancho) {
    document.getElementById(obj).style.backgroundPosition = alto + ' ' + ancho;
}

function LimpiarSearchbox(obj) {
    if (document.getElementById(obj).value == 'B\u00fasqueda r\u00e1pida') {
        document.getElementById(obj).value = '';
    }
}

function Mid(s, n, c) {
    var numargs = Mid.arguments.length; if (numargs < 3)
        c = s.length - n + 1; if (c < 1)
        c = s.length - n + 1; if (n + c > s.length)
        c = s.length - n + 1; if (n > s.length)
        return ""; return s.substring(n - 1, n + c - 1);
}
function makeAJAXPostback(Cnt, TDClickID) {
    if (TDClickID == 'Dinamico') {
        var cnt = $get(Cnt).value;
        var CodProd = $get('ctl00_ContentPlaceHolder1_CampoOculto').value;
        document.forms[0].hidTDClickID.value = CodProd + '#' + cnt; document.forms[0].btnTDClicked.click();
        alert("El Producto se agrego correctamente a su cesta de la compra");
    }
    else {
        var cnt = $get(Cnt).value;
        document.forms[0].hidTDClickID.value = TDClickID + '#' + cnt; 
        document.forms[0].btnTDClicked.click();
    }
}
function Redirect(Pagina) { location.href = Pagina; }
function ValidarCIF(cajadetexto, boton) {var text1 = $get(cajadetexto).value; var longitud = text1.length; var primeraletra = text1.charAt(0); if (longitud < 9) { $get(boton).disabled = true; } else { $get(boton).disabled = false; }}
function PonerImaSubCategoria(Img) {$get('IMGRecomendacionBA').src = Img;}
function MostrarImgSubCat(Img) {
    if (parseInt($get('CapaImgSubCategoria').style.left = event.clientX) >= parseInt('700')) { $get('CapaImgSubCategoria').style.left = event.clientX - 20; }
    else { $get('CapaImgSubCategoria').style.left = event.clientX + 30; }
    $get('CapaImgSubCategoria').style.top = (event.clientY + document.documentElement.scrollTop + document.body.scrollTop + 7); $get('CapaImgSubCategoria').style.display = 'block'; $get('ImgSubCategoriaProducto').src = Img;
}
function HabilitarBoton(Boton) {BTNEnviar = $get(Boton); if (BTNEnviar.disable == false) { BTNEnviar.disabled = true; } else { BTNEnviar.disabled = false; }}
function CapturarResolucionDePantalla() {try { $get('ctl00_Resolucion').value = screen.width + " x " + screen.height; }catch (err) { }}
function MostrarNoticiasYPrensa(Obj1, Obj2) { $get(Obj1).style.display = 'block'; $get(Obj2).style.display = 'none'; }
function Mostrar1Ocultar2(Obj1, Obj2, Obj3) { $get(Obj1).style.display = 'block'; $get(Obj2).style.display = 'none'; $get(Obj3).style.display = 'none'; }
function CambiarCssEnDiv(objeto, nuevocss) {$get(objeto).className = nuevocss;}
function ExpandireNoticias(Estado) {
    if (Estado == "True") {
        for (i = 0; i < 200; i++) {
            try { $get('ctl00_ContentPlaceHolder1_noticia_' + String(i)).style.display = 'block'; } catch (err) {
                return
            }
        }
    }
    else {
        for (i = 0; i < 200; i++) {
            try { $get('ctl00_ContentPlaceHolder1_noticia_' + String(i)).style.display = 'none'; }
            catch (err) {
                return
            }
        }
    }
}
function openPanel() { try { $find("Feles")._doOpen(); } catch (err) { } }
function CerrarFichaDeProducto() { $get('ctl00_PNLarrastrado').style.display = 'none';}
function MostrarCargando() {try { $get('CapaCargando').style.visibility = 'visible'; } catch (error) { }}
function MostrarCaracteristicasTecnicas(Caracteristicas) {
    if (parseInt($get('DivVistaPrevia').style.left = event.clientX) >= parseInt('700')) { $get('DivVistaPrevia').style.left = event.clientX - 20; }
    else { $get('DivVistaPrevia').style.left = event.clientX + 30; }
    $get('DivVistaPrevia').style.top = (event.clientY + document.documentElement.scrollTop + document.body.scrollTop + 7);$get('DivVistaPrevia').innerHTML = Caracteristicas;  $get('DivVistaPrevia').style.display = 'block';
}
function OcultarCaracteristicasTecnicas() { $get('DivVistaPrevia').style.display = 'none'; }
function OcultarPanel(panel) {$get(panel).style.display = 'none';}
function capLock(e) {
    kc = e.keyCode ? e.keyCode : e.which; sk = e.shiftKey ? e.shiftKey : ((kc == 16) ? true : false); $get('bloqueo').style.position = "absolute"; var LEFT = $get('ctl00_imginfouser1').getBoundingClientRect().left
    $get('bloqueo').style.left = LEFT + 5; if (((kc >= 65 && kc <= 90) && !sk) || ((kc >= 97 && kc <= 122) && sk))
        $get('bloqueo').style.display = 'block'; else
        $get('bloqueo').style.display = 'none';
}
function MostrarDownload() { document.all.DivGeneradorDescargas.style.display = 'none'; document.all.DivDescargando.style.display = 'block'; }
function MostraruOcultarunPanel(Panel, Visibilidad) { $get(Panel).style.display = Visibilidad; }
function MostraruOcultarunPanelTESTING() { $get('DIVInfo0').className = "FondoColumnaPedidoImplantacion"; }
function MostrarOcultarPanel(Panel) {
    if ($get(Panel).style.display == 'block') { $get(Panel).style.display = 'none'; } else { $get(Panel).style.display = 'block'; }
}
function MostrarPanelconCambiodeImagen(Panel, Boton, RutaON, RutaOFF) {
    if ($get(Panel).style.display == 'block') {
        try
{ $get(Panel).style.display = 'none'; $get(Boton).src = RutaOFF; }
        catch (Err)
{ }
    }
    else {
        try
{ $get(Panel).style.display = 'block'; $get(Boton).src = RutaON; }
        catch (Err)
{ }
    }
}
function MostrarCapa(capa) {
    if ($get(capa).style.display == 'block') {
        $get(capa).style.display = 'none';
    } else {
        $get(capa).style.display = 'block';
    }
}
function MostrarOcultarPanelconCambiodeImagen(PanelVisible, PanelOculto, BotonVisible, BotonOculto, RutaON, RutaOFF)
{ $get(PanelVisible).style.display = 'block'; $get(PanelOculto).style.display = 'none'; $get(BotonVisible).src = RutaON; $get(BotonOculto).src = RutaOFF; }
function MostrarPaneles(Panel, Panel2, Boton, RutaON, RutaOFF) {
    if (($get(Panel).style.display == 'block') || ($get(Panel2).style.display == 'block')) {
        try
{ $get(Panel).style.display = 'none'; $get(Panel2).style.display = 'none'; $get(Boton).src = RutaOFF; }
        catch (Err) { }
    }
    else {
        try { $get(Panel).style.display = 'block'; $get(Boton).src = RutaON; }
        catch (Err) { }
    }
}
function MostrarNoticia(Obj) {
    if ($get(Obj).style.display == 'block')
    { $get(Obj).style.display = 'none'; }
    else
    { $get(Obj).style.display = 'block'; }
}
function PonerFoco(obj) { obj.style.background = "#e3efff"; }function QuitarFoco(obj) { obj.style.background = "#ffffff";}

function PintarFecha(obj) {
    var dt = new Date()
    var Hora = dt.getHours()
    var Minutos = dt.getMinutes()
    var Segundos = dt.getSeconds()
    $get('HoraSistema').innerHTML = " (" + Formatear(Hora) + ":" + Formatear(Minutos) + ":" + Formatear(Segundos) + ")"; setTimeout("PintarFecha(this)", 1000)

    var fecha=new Date();
    var diames=fecha.getDate();
    var diasemana=fecha.getDay();
    var mes=fecha.getMonth() +1 ;
    var ano=fecha.getFullYear();

    var textosemana = new Array (7); 
      textosemana[0]="Domingo";
      textosemana[1]="Lunes";
      textosemana[2]="Martes";
      textosemana[3]="Miércoles";
      textosemana[4]="Jueves";
      textosemana[5]="Viernes";
      textosemana[6]="Sábado";

    var textomes = new Array (12);
      textomes[1]="Enero";
      textomes[2]="Febrero";
      textomes[3]="Marzo";
      textomes[4]="Abril";
      textomes[5]="Mayo";
      textomes[6]="Junio";
      textomes[7]="Julio";
      textomes[7]="Agosto";
      textomes[9]="Septiembre";
      textomes[10]="Octubre";
      textomes[11]="Noviembre";
      textomes[12]="Diciembre";

      try { $get(obj).innerHTML = "Fecha: " + textosemana[diasemana] + ", " + diames + " de " + textomes[mes] + " de " + ano; } catch (Error) { }
}

function cambiaFoco(cajadestino){var key = window.event.keyCode; if (key == 13)$get(cajadestino).focus();}
function Formatear(Obj) { if (Obj == 0) { return '00' } if (Obj == 1) { return '01' } if (Obj == 2) { return '02' } if (Obj == 3) { return '03' } if (Obj == 4) { return '04' } if (Obj == 5) { return '05' } if (Obj == 6) { return '06' } if (Obj == 7) { return '07' } if (Obj == 8) { return '08' } if (Obj == 9) { return '09' } return Obj; }

function GuardarValorEncuestaCalidad(Columna, Valor) {
    if (IsNumeric(Valor.value) == true && (Valor.value <= 6)) {

        var Codcliente = $get('ctl00_CodClienteJS').value;
        FichasDeProducto.ModificaValorEncuestaCalidad(Codcliente, Columna, Valor.value, Ok_Encuesta);
    }
    else {
        Valor.value = '0';
        alert('La Puntuacion debe estar entre 1-6');
    }


}

function GuardarValorEncuestaCalidad2(Columna, Valor) {
        var Codcliente = $get('ctl00_CodClienteJS').value;
        FichasDeProducto.ModificaTextoEncuestaCalidad(Codcliente,Valor.value, Ok_Encuesta);
    }

function Ok_Encuesta() { }

function CambiarBGPosition(obj, nuevapos) {
    $get(obj).style.backgroundPosition = nuevapos;
}

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 Start() {
    var Codcliente = $get('ctl00_CodClienteJS').value;
}

function CountDown(year, m, d, obj) {

    var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    var today = new Date()
    var todayy = today.getYear()
    var todaym = today.getMonth()
    var todayd = today.getDate()
    var todayh = today.getHours()
    var todaymin = today.getMinutes()
    var todaysec = today.getSeconds()
    var todaystring = montharray[todaym] + " " + todayd + ", " + todayy
    var paststring = montharray[m - 1] + " " + d + ", " + year
    var difference = (Math.round((Date.parse(paststring) - Date.parse(todaystring)) / (24 * 60 * 60 * 1000)) * 1)

    var Dias = difference - 1;
    var Horas = difference * 24;
    var Minutos = Horas * 60;
    var Segundos = Minutos * 60;
    var TiempoHoras = Horas - todayh;
    var TiempoHorasRestantes = (Horas - todayh) % 24;
    var TiempoMinutos = (Minutos - todaymin) % 60;
    var TiempoSegundos = (Segundos - todaysec) % 60;
    
    try {
        if (Dias == 0) {
            document.getElementById(obj).innerHTML = "<span class='hot'>"+TiempoHorasRestantes + ":" + TiempoMinutos + ":" + TiempoSegundos+"</span>";
        } else {
            if (Dias == 1) {
                document.getElementById(obj).innerHTML = "<span class='near'>"+Dias + "D " + TiempoHorasRestantes + ":" + TiempoMinutos + ":" + TiempoSegundos+"</span>";
            } else {
            document.getElementById(obj).innerHTML = "<span class='cold'>" + Dias + " Días</span>";
            }
        }
    } catch (Error) { }
    
    CountDown_Restante(year, m, d, obj);
}

function CountDown_Restante(year, m, d, obj) {
    setTimeout("CountDown(" + year + "," + m + "," + d + ",'" + obj + "')", 1000);
}

/************** FUNCIONES PARA LA CESTA *********************/
function LimpiarMetodosPagoCesta() { try { $get('C_pago_transferencia_info').style.display = 'none';$get('C_confirmarPagoTarjeta').style.display = 'none'; } catch (Error) { } }
function OcultarCuentasBancarias() {
    for (i = 0; i < 20; i++) {
        try {$get('cbanc_' + i).style.display = 'none';}
        catch(Error){break;}
    }
}

/****************/
/***** HOME *****/
/****************/

function iShow(obj) {
    $(obj).fade('in');
}

function iHideFabricantes(modo) {
    for (i = 0; i < 200; i++) {
        try {
            $('H_Fabricantediv_' + i).fade(modo);
        } catch (Error) { break; }
    }
}

//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////          COMPARADOR DE PRODUCTOS          /////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
shortcut.add("Esc", function() { $get("searchbox_resultados").style.display = 'none'; $get("H_searchbox_input").value = ''; ActivarGoSw = false; });

function VerComparador() {
    Codcliente = $get('ctl00_CodClienteJS').value;
    var Productos = ProductosParaComparar('comparar', '');
    if (Productos == false) {
    } else {
        FichasDeProducto.VerComparador(Codcliente, CodigoUltimaSubcategoriaPinchada, Productos, Path_Imagenes, VerComparador_OK, VerComparador_FAIL);
    }
}

function VerComparadorRequest(Productos, CodSubCat) {
    Codcliente = $get('ctl00_CodClienteJS').value;
    if (Productos == false) {
    } else {
        FichasDeProducto.VerComparador(Codcliente, CodSubCat, Productos, Path_Imagenes, VerComparador_OK, VerComparador_FAIL);
    }
}

function VerComparador_OK(resultado) {
    PonerBlock('DIV_Comparador');
    $get('DIV_Comparador').innerHTML = resultado;
}

function VerComparador_FAIL(Error) {
}

function ProductosParaComparar(accion, quality) {

    var ProductIDCheckado = '';
    ProductsIDParaComparar = '';
    var CuantosSeleccionados = 0;

    //1º) Recorro los checks
    //2º) Si esta checkado, entro
    //3º) Si es el primero, lo inserto sin ;
    //4º) Si es el cuarto, le impido que coga mas
    //5º) Control si no hay ninguno o solo 1 checkados

    //º1)
    for (i = 1; i < 1000; i++) {
        //2º)
        try {

            if ($get('CompararProducto' + i).checked == true) {

                if (quality == 'manuales' || quality == 'dmi') {
                    alert('Este producto no tiene habilitada la comparativa. Lamentamos las molestias.');
                    $get('CompararProducto' + i).checked = false;
                    return false;
                }

                ProductIDCheckado = $get('CompararProducto' + i).value;
                CuantosSeleccionados = ProductsIDParaComparar.split(";");
                //3º)
                if (ProductsIDParaComparar == '') {
                    ProductsIDParaComparar = ProductIDCheckado;
                } else {
                    //4º)
                    if (CuantosSeleccionados.length == 4) {
                        alert('Solo puedes seleccionar 4 productos para comparar');
                        $get('CompararProducto' + i).checked = false;
                        return false;
                    } else {
                        ProductsIDParaComparar = ProductsIDParaComparar + ';' + ProductIDCheckado;
                    }
                }
            } //Fin del if

        } catch (Error) { break; }

    } //Fin del for

    if (accion == 'comparar') {
        //5º)
        if (CuantosSeleccionados == 0 || CuantosSeleccionados.length < 1) {
            alert('Debes seleccionar al menos 2 productos para comparar');
            return false;
        } else {
            return ProductsIDParaComparar;
        }
    }
}

function SearchBoxObtenerProductos(NCat, catid) {
    var Cuantos = 0;
    var ProductosAcomparar = '';

    for (i = 0; i < 1000; i++) {
        try {
            if ($get('SB_chkcomparar_' + NCat + '_' + i).checked == true) {

                if (Cuantos > 4) {
                    alert('Solo puedes comparar 4 productos a la vez.');
                    break;
                } else {
                    Cuantos = Cuantos + 1;

                    if (ProductosAcomparar == '') {
                        ProductosAcomparar = $get('SB_chkcomparar_' + NCat + '_' + i).value;
                    } else {
                        ProductosAcomparar = ProductosAcomparar + ';' + $get('SB_chkcomparar_' + NCat + '_' + i).value;
                    }
                }
            }
        }
        catch (Error) { break; }
    }

    if (Cuantos == 0 || Cuantos == 1) {
        alert('Debes seleccionar al menos 2 productos para comparar.');
    } else {
        if (Cuantos > 4) {
            alert('Solo puedes comparar 4 productos a la vez.');
        } else {
            VerComparadorRequest(ProductosAcomparar, catid);
        }
    }

}