﻿
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 fnSwap(myimg) {
    var newimg = myimg.src;
    if (newimg.indexOf("_off") > 0) {
        newimg = newimg.replace("_off", "_on");
    } else {
        newimg = newimg.replace("_on", "_off");
    }
    myimg.src = newimg;
}

MM_preloadImages('images/btn_busquedas_off.jpg', 'images/btn_busquedas_on.jpg', 'images/btn_bibliografia_off.png', 'images/btn_bibliografia_on.png', 'images/btn_fasciculos_off.png', 'images/btn_fasciculos_on.png', 'images/btn_canasta_off.png', 'images/btn_canasta_on.png', 'images/btn_contactenos_off.png', 'images/btn_contactenos_on.png', 'images/btn_home_off.jpg', 'images/btn_home_on.jpg', 'images/btn_tienda_off.jpg', 'images/btn_tienda_on.jpg');


// onMouseOver="fnSwap(this);" onMouseOut="fnSwap(this);" 


function updateItem(obj) {
    //alert(obj);
    document.getElementById("PartNumber").value = obj.split("|")[0];
    document.getElementById("qty").value = obj.split("|")[1];
    document.getElementById("item").value = obj.split("|")[2];
    document.productForm.submit();
}

function fnOrden() {
    self.location.href="Orden.aspx";

}

function fnGoTo(page) {
    self.location.href = page;
}

function fnShow(divid) {
    document.getElementById('div_bancolombia').style.display = "none";
    document.getElementById('div_paypal').style.display = "none";
    document.getElementById(divid).style.display = "block";
}

function fnShow2(divid) {
    if (!document.getElementById("amount").value) {
        alert("Por favor seleccione la opcion deseada!");
        return;
    }
    document.getElementById('div_bancolombia').style.display = "none";
    document.getElementById('div_paypal').style.display = "none";
    document.getElementById(divid).style.display = "block";
}

function fnSelect(opt) {
    var MyCaption = "";
    var item_name = ""
    var item_number = ""
    var amount=""
    switch  (opt.value) {
        case "10":
            MyCaption = "10 Búsquedas más al día por $10.000 pesos"
            item_name = "10 Busquedas mas al dia"
            item_number = "10B"
            break;
        case "20":
            MyCaption = "20 Búsquedas más al día por $20.000 pesos"
            item_name = "20 Busquedas mas al dia"
            item_number = "20B"
            break;
        case "30":
            MyCaption = "50 Búsquedas más al día por $30.000 pesos"
            item_name = "50 Busquedas mas al dia"
            item_number = "50B"
            break;
        case "50":
            MyCaption = "500 Búsquedas más al día por $50.000 pesos"
            item_name = "500 Busquedas al dia"
            item_number = "500B"
            break;
        default:
            MyCaption = ""
    }
    amount = FormatNumber(1000 * opt.value / document.getElementById("ustrm").value,2)
    var us = FormatCurrency(1000 * opt.value / document.getElementById("ustrm").value);
    document.getElementById("divMSG").innerHTML = "<br />Opción seleccionada: " + MyCaption + " (" + us + " dólares de cambio a $" + document.getElementById("ustrm").value + " pesos)";
    document.getElementById("spnValorAPagar").innerHTML = us;
    document.getElementById("item_name").value = item_name;
    document.getElementById("item_number").value = item_number;
    document.getElementById("amount").value = amount;
}


function FormatCurrency(Expression) {
    var iNumDecimals = 2;
    var dbInVal = Expression;
    var bNegative = false;
    var iInVal = 0;
    var strInVal
    var strWhole = "", strDec = "";
    var strTemp = "", strOut = "";
    var iLen = 0;

    if (dbInVal < 0) {
        bNegative = true;
        dbInVal *= -1;
    }

    dbInVal = dbInVal * Math.pow(10, iNumDecimals)
    iInVal = parseInt(dbInVal);
    if ((dbInVal - iInVal) >= .5) {
        iInVal++;
    }
    strInVal = iInVal + "";
    strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
    strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
    while (strDec.length < iNumDecimals) {
        strDec = "0" + strDec;
    }
    iLen = strWhole.length;
    if (iLen >= 3) {
        while (iLen > 0) {
            strTemp = strWhole.substring(iLen - 3, iLen);
            if (strTemp.length == 3) {
                strOut = "," + strTemp + strOut;
                iLen -= 3;
            }
            else {
                strOut = strTemp + strOut;
                iLen = 0;
            }
        }
        if (strOut.substring(0, 1) == ",") {
            strWhole = strOut.substring(1, strOut.length);
        }
        else {
            strWhole = strOut;
        }
    }
    if (bNegative) {
        return "-$" + strWhole + "." + strDec;
    }
    else {
        return "$" + strWhole + "." + strDec;
    }
}

function FormatNumber(Expression, NumDigitsAfterDecimal) {
    var iNumDecimals = NumDigitsAfterDecimal;
    var dbInVal = Expression;
    var bNegative = false;
    var iInVal = 0;
    var strInVal
    var strWhole = "", strDec = "";
    var strTemp = "", strOut = "";
    var iLen = 0;

    if (dbInVal < 0) {
        bNegative = true;
        dbInVal *= -1;
    }

    dbInVal = dbInVal * Math.pow(10, iNumDecimals)
    iInVal = parseInt(dbInVal);
    if ((dbInVal - iInVal) >= .5) {
        iInVal++;
    }
    strInVal = iInVal + "";
    strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
    strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
    while (strDec.length < iNumDecimals) {
        strDec = "0" + strDec;
    }
    iLen = strWhole.length;
    if (iLen >= 3) {
        while (iLen > 0) {
            strTemp = strWhole.substring(iLen - 3, iLen);
            if (strTemp.length == 3) {
                strOut = "," + strTemp + strOut;
                iLen -= 3;
            }
            else {
                strOut = strTemp + strOut;
                iLen = 0;
            }
        }
        if (strOut.substring(0, 1) == ",") {
            strWhole = strOut.substring(1, strOut.length);
        }
        else {
            strWhole = strOut;
        }
    }
    if (bNegative) {
        return "-" + strWhole + "." + strDec;
    }
    else {
        return strWhole + "." + strDec;
    }
}
