﻿/* Miscelanea ------------------------------------------------------------------------------ */
function replace(strTexto, strTextoOld, strTextoNew) {
    return strTexto.split(strTextoOld).join(strTextoNew);
}
function impresionPagina() {
    setTimeout("window.print()", 1000);
}
function cambiaColorFondoObjetoHTML(objHTML, strColor) {
    objHTML.style.background = strColor;
}
function articuloSinFoto(objImagen) {
    objImagen.src = "/img/imagenArtSinFoto354x354.jpg";
}
function articuloSinFoto85(objImagen) {
    objImagen.src = "/img/imagenArtSinFoto85x85.jpg";
}
function articuloSinFoto200(objImagen) {
    objImagen.src = "/img/imagenArtSinFoto200x200.jpg";
}
function cabeceraSinFlash(objImagen) {
    objImagen.src = "/img/FotoSinFlash.jpg";
}
function verPoliticasPrivacidad(strSeccion) {
    var intAnchura = 700;
    var intAltura = 700;
    var strUrl = "/politicasPrivacidad.aspx" + strSeccion;
    var intPosIzquierda, intPosTop;
    if (screen) {
        intPosIzquierda = (screen.width - intAnchura) / 2;
        intPosTop = (screen.height - intAltura) / 2;
    } else {
        intPosIzquierda = 0;
        intPosTop = 0;
    }
    var strAtributos = "width=" + intAnchura + ", height=" + intAltura + ", scrollbars=yes," +
					   "left=" + intPosIzquierda + ",top=" + intPosTop;
    objVentanaPoliticasPrivacidad = window.open(strUrl, "VentanaPoliticasPrivacidad", strAtributos);
    objVentanaPoliticasPrivacidad.focus();
}
function verMapaLocalizacion() {
    var intAnchura = 840; var intAltura = 670; var intPosIzquierda = 0; var intPosTop = 0;
    var strUrl = "/mapa-localizacion.aspx";
    if (screen) {
        intPosIzquierda = (screen.width - intAnchura) / 2;
        intPosTop = (screen.height - intAltura) / 2;
    };
    var strAtributos = "width=" + intAnchura + ", height=" + intAltura + ", scrollbars=yes, resizable=yes," +
						"left=" + intPosIzquierda + ",top=" + intPosTop;
    objVentanaMapaLocalizacion = window.open(strUrl, "VentanaMapaLocalizacion", strAtributos);
    objVentanaMapaLocalizacion.focus();
}
function hazPostBackUpdatePanel(strUpdatePanel) {
    var objPRM = Sys.WebForms.PageRequestManager.getInstance();
    objPRM._doPostBack(strUpdatePanel, "");
}
function posicionaScrollPagina() {
    $('html, body').animate({
        scrollTop: $(document).height()
    }, 1500);
}
function validarLongitudTextArea(objTextArea, intMaxLength) {
    if (objTextArea.value.length > intMaxLength) {
        objTextArea.value = objTextArea.value.substring(0, intMaxLength);
    }
    try {
        document.getElementById("CaracteresRestantes").innerHTML = intMaxLength - objTextArea.value.length;
    } catch (e) {/*Si no existe no da error y continua con el proceso*/
    }
}
function CurrencyFormatted(amount) {
    amount = amount.toString().replace(/\$|\./g,'').replace(/\$|\,/g,'.');
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if (s.indexOf('.') < 0) { s += '.00'; }
    if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s.replace(",", "/").replace(".", ",").replace("/", ",") + " &#8364;";
}

/* ------------------------------------------------------------------------------------------ */
function sumarRestarCantidadInput(strQueFaig, strIdInput) {
    var objInputCantArt = document.getElementById(strIdInput);
    var intCanArt = parseInt(objInputCantArt.value, 10);
    /*Si no es un número*/
    if (isNaN(intCanArt) == true) {
        /*Asignamos valor por defecto*/
        intCanArt = 0;
    }
    if (strQueFaig == "+") {
        intCanArt += 1;
    } else {
        intCanArt -= 1;
    }
    if (intCanArt < 0) {
        intCanArt = 0;
    }
    objInputCantArt.value = intCanArt;
}
function ConfirmarPedidoIdentificacion_activaOpcion2(strIdObjopcion) {
    var objOpcionPorId = document.getElementById(strIdObjopcion);
    var objOpcionPorName = document.getElementsByName(objOpcionPorId.name);
    objOpcionPorName[1].checked = true;
}
function ConfirmarPedidoDirecciones_ActivarDesactivarCajaTexto(strIdCheckBox, strIdTextBox) {
    var objCheckBox = document.getElementById(strIdCheckBox);
    var objTextBox = document.getElementById(strIdTextBox);
    if (objCheckBox.checked) {
        objTextBox.disabled = "";
    } else {
        objTextBox.disabled = "disabled";
    }
}
function imprimirPedido(intIdCliente, intIdPedido) {
    alert("Cliente: " + intIdCliente.toString() + " Pedido: " + intIdPedido.toString());
}
function onKeyDownCajaTextoBuscador(e, objTB, strTexto) {
    if (e.which || e.keyCode) {
        if ((e.which == 13) || (e.keyCode == 13)) {
            if (objTB.value == strTexto || objTB.value == "" || objTB.value == "") {
                return false;
            } else {
                irCatalogoBuscador(objTB.value);
            }
        }
    }
    return true;
}
function onClickBotonBuscador(strTexto) {
    var strContTB = document.getElementById("htmlTbBuscadorCabecera").value;
    if (strContTB != strTexto && strContTB != "" && strContTB != "") {
        irCatalogoBuscador(strContTB);
    }
}
function irCatalogoBuscador(strTexto) {
    window.location = "/catalogo.aspx?modo=2&txt=" + strTexto;
}
function onKeyDownCajaTextoCantidad(e, objTB, blnVengoModal, intIdArt) {
    if (e.which || e.keyCode) {
        if ((e.which == 13) || (e.keyCode == 13)) {
            var strContTB = objTB.value;
            if (isNaN(strContTB) == true || parseInt(strContTB) < 0 || parseInt(strContTB) > 999) {
                objTB.value = 0;
                return false;
            } else {
                if (blnVengoModal == true) {
                    intIdArt = parseInt(document.getElementById("htmlHiddenIdArtModalDetalleArt").value);
                }
                addArtCestaPedido(intIdArt, parseInt(strContTB));
            }
        }
    }
    return true;
}
function onClickBotonAddCestaDetalleArt(strIdInput, intIdArt) {
    var strContTB = document.getElementById(strIdInput).value;
    if (isNaN(strContTB) == true || parseInt(strContTB) < 0 || parseInt(strContTB) > 999) {
        document.getElementById(strIdInput).value = 0;
    } else {
        addArtCestaPedido(intIdArt, parseInt(strContTB));
    }
}
function onClickBotonAddCesta(strPrefijoId, intIdArt) {
    var strContTB = document.getElementById(strPrefijoId + intIdArt.toString()).value;
    if (isNaN(strContTB) == true || parseInt(strContTB) < 0 || parseInt(strContTB) > 999) {
        document.getElementById(strPrefijoId + intIdArt.toString()).value = 0;
    } else {
        addArtCestaPedido(intIdArt, parseInt(strContTB));
    }
}
function onClickBotonAddCestaModal(strIdTB) {
    var strContTB = document.getElementById(strIdTB).value;
    if (isNaN(strContTB) == true || parseInt(strContTB) < 0 || parseInt(strContTB) > 999) {
        document.getElementById(strIdTB).value = 0;
    } else {
        addArtCestaPedido(parseInt(document.getElementById("htmlHiddenIdArtModalDetalleArt").value), parseInt(strContTB));
    }
}
function addArtCestaPedido(intIdArt, intCant) {
    if (intCant == 0) {
        intCant = 1;
    }
    window.location = "/cesta-pedido.aspx?modo=1&Id=" + intIdArt.toString() + "&Can=" + intCant.toString();
    return false;
}
function ocultarModalDetalleArticulos() {
    document.getElementById("htmlDivModalDetalleArt").style.display = "none";
    document.getElementById("htmlDivModalDetalleArtBackground").style.display = "none";
}
function General_VerModalDetalleArticulo(intIdArt) {
    var strDivDatosArt = document.getElementById("htmlDivDatosArt_" + intIdArt.toString()).innerHTML;
    var aDatos = new Array();
    aDatos = strDivDatosArt.split("^");

    document.getElementById("htmlHiddenIdArtModalDetalleArt").value = intIdArt;
    document.getElementById("htmlImgModalDetalleArtFotoArt").src = "/fotos/" + parseInt(intIdArt).toString() + ".jpg";
    document.getElementById("htmlSpanModalDetalleArtUniMin").innerHTML = "x" + aDatos[1];
    document.getElementById("htmlSpanModalDetalleArtUniCaja").innerHTML = "x" + aDatos[2] + " ud.";
    document.getElementById("htmlSpanModalDetalleArtPreMin").innerHTML = CurrencyFormatted(aDatos[3]);
    document.getElementById("htmlSpanModalDetalleArtPreCaja").innerHTML = CurrencyFormatted(aDatos[4]);
    /*Si hay datos para mostrar y el precio de tarifa es mayor al precio del cliente*/
    if (aDatos[14].length > 0 && CurrencyFormatted(aDatos[14]) > CurrencyFormatted(aDatos[3])) {
        document.getElementById("htmlSpanModalDetalleArtPreMinTarifa").innerHTML = CurrencyFormatted(aDatos[14]);
        document.getElementById("htmlSpanModalDetalleArtPreMinTarifa").style.display = "block";
    } else {
        document.getElementById("htmlSpanModalDetalleArtPreMinTarifa").style.display = "none";
    }
    /*Si hay datos para mostrar y el precio de tarifa es mayor al precio del cliente*/
    if (aDatos[15].length > 0 && CurrencyFormatted(aDatos[15]) > CurrencyFormatted(aDatos[4])) {
        document.getElementById("htmlSpanModalDetalleArtPreCajaTarifa").innerHTML = CurrencyFormatted(aDatos[15]);
        document.getElementById("htmlSpanModalDetalleArtPreCajaTarifa").style.display = "block";
    } else {
        document.getElementById("htmlSpanModalDetalleArtPreCajaTarifa").style.display = "none";
    }

    if (aDatos[1] == aDatos[2]) {
        document.getElementById("htmlDivModalDetalleArtDatosCaja").style.display = "none";
    } else {
        document.getElementById("htmlDivModalDetalleArtDatosCaja").style.display = "block";
    }

    document.getElementById("htmlDivModalDetalleArtDes1").innerHTML = aDatos[5];
    document.getElementById("htmlDivModalDetalleArtDes3").innerHTML = aDatos[7];

    if (aDatos[13] == "False") {
        if (aDatos[9] == "True" || aDatos[10] == "True") {
            document.getElementById("htmlDivModalDetalleArtDatosCestaPedido").style.display = "none";
            document.getElementById("htmlDivModalDetalleArtDatosEstadoEspecial").style.display = "block";
            /*No Disponible*/
            if (aDatos[10] == "True") {
                document.getElementById("htmlDivModalDetalleArtDatosEstadoEspecial").innerHTML = "<span class='NoDisponible'>" + aDatos[12] + "</span>"
            }
            /*Agotado*/
            if (aDatos[9] == "True") {
                document.getElementById("htmlDivModalDetalleArtDatosEstadoEspecial").innerHTML = "<span class='Agotado'>" + aDatos[11] + "</span>"
            }
        } else {
            document.getElementById("htmlDivModalDetalleArtDatosCestaPedido").style.display = "block";
            document.getElementById("htmlDivModalDetalleArtDatosEstadoEspecial").style.display = "none";
        }
    } else {
        document.getElementById("htmlDivModalDetalleArtDatosCestaPedido").style.display = "none";
        document.getElementById("htmlDivModalDetalleArtDatosEstadoEspecial").style.display = "none";
    }

    $("#htmlDivModalDetalleArtBackground").css({
        display: "block",
        width: screen.width,
        height: screen.height 
    });

    $("#htmlDivModalDetalleArt").css({
        display: "block",
        left: ($(window).width() - $("#htmlDivModalDetalleArt").outerWidth()) / 2,
        top: $(window).scrollTop() + (($(window).height() - $("#htmlDivModalDetalleArt").outerHeight()) / 2)
    });

}
function borrarAgregarFavorito(strQueHago, intIdArt, strMsg) {
    if (strQueHago == "B") {
        if (confirm(strMsg) == true) {
            window.location = "/catalogo.aspx?modo=9&IdArt=" + intIdArt.toString();
        }
    } else if (strQueHago == "M") {
        window.location = "/catalogo.aspx?modo=7&IdArt=" + document.getElementById("htmlHiddenIdArtModalDetalleArt").value;
    } else {
        window.location = "/catalogo.aspx?modo=7&IdArt=" + intIdArt.toString();
    }
    return false;
}
function abrirVentanaImpPedido(intIdPedido0) {
    var intAnchura = 930;
    var intAltura = 600;
    var strUrl = "/impPedidoPDF.aspx?Id=" + intIdPedido0;
    var intPosIzquierda, intPosTop;
    if (screen) {
        intPosIzquierda = (screen.width - intAnchura) / 2;
        intPosTop = (screen.height - intAltura) / 2;
    } else {
        intPosIzquierda = 0;
        intPosTop = 0;
    }
    var strAtributos = "width=" + intAnchura + ", height=" + intAltura + ", scrollbars=yes,resizable=yes,menubar=no,toolbar=no," +
						"left=" + intPosIzquierda + ",top=" + intPosTop;
    objVentana = window.open(strUrl, "PedidoPDF", strAtributos);
    objVentana.focus();
}
function sumarRestarCantidadInput(strQueFaig, strIdInput) {
    var objInputCantArt = document.getElementById(strIdInput);
    var intCanArt = parseInt(objInputCantArt.value, 10);
    /*Si no es un número*/
    if (isNaN(intCanArt) == true) {
        /*Asignamos valor por defecto*/
        intCanArt = 0;
    }
    if (strQueFaig == "+") {
        intCanArt += 1;
    } else {
        intCanArt -= 1;
    }
    if (intCanArt <= 0) {
        intCanArt = 1;
    }
    if (intCanArt > 50) {
        intCanArt = 50;
    }
    objInputCantArt.value = intCanArt;
}
function cancelarContratacion(strTexto) {
    if (confirm(strTexto) == true) {
        location.replace('/cesta-pedido.aspx');
    } else {
        posicionaScrollPagina();
    }
}

