function DisplayBlank() {
    return '';
}


function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt * 100)) / 100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00'
              : ((mnt * 10 == Math.floor(mnt * 10)) ?
                       mnt + '0' : mnt);
}


function printitem(sel) {
    var code, arr;
    code = eval("document.Form1.sel" + sel + ".options[document.Form1.sel" + sel + ".selectedIndex].value");
    arr = code.split("_");
    if (arr[1] != "-1")
        window.open("print_page.aspx?product_ID=" + arr[1], "winPrint", "toolbar,height=400,width=550,scrollbars,resizable");
    //document.frmAdd.TEST2.value == arr[0];

    else
        alert("No Component Selected.");
}

function display_item(sel) {
    var code, arr;
    code = eval("document.Form1.sel" + sel + ".options[document.Form1.sel" + sel + ".selectedIndex].value");
    arr = code.split("_");
    if (arr[1] != "-1")
        return GetInfo(arr[1]);
    //document.frmAdd.TEST2.value == arr[0];

    else
        return "Sorry, No Component Selected.";
}


function CalculatePriceN() {
    var form = document.forms[0];
    var elems = form.elements;
    var num = parseInt(elems["NumOptions"].value);
    var percent = parseFloat(elems["percent"].value.replace(",", "."));
    var orig_price = 0, cost = 0, weight = 0, strValue = 0.00, arrProducts = "NONE", arrQty = "NONE";
    for (var idx = 0; idx < num + 1; idx++) {
        var qty = elems['qty' + idx].value;
        var code = elems['sel' + idx].options[elems['sel' + idx].selectedIndex].value;
        var arr = code.split('_');
        arrProducts += ',' + arr[1];
        var arrQty = arrQty + ',' + qty;
        weight += parseFloat(arr[2].replace(',', '.')) * qty;
        cost += parseFloat(arr[3].replace(',', '.')) * qty;
        strValue += parseFloat(arr[0].replace(',', '.')) * qty;
    }
    strValue = strValue * percent + strValue;
    //txtSelectedItems
    elems['txtPrice'].value = strValue;
    elems['Price'].value = formatAsMoney(strValue);
    elems['Price2'].value = formatAsMoney(strValue);
    elems['Price3'].value = '$ ' + formatAsMoney(strValue);
    elems['txtSelectedItems'].value = arrProducts;
    elems['ArrQty'].value = arrQty;
    elems['txtWeight'].value = weight;
    elems['txtCost'].value = cost;
    $('#btnAdd1').removeAttr('disabled').removeClass('invis');
    $('#btnCart1').removeAttr('disabled').removeClass('invis');
}
function CalculatePriceN_old() {
    var code, arr, strValue, qty, num, orig_price, arrProducts, weight, cost, arrQty, percent;

    num = eval(document.Form1.NumOptions.value);
    //orig_price=eval(document.Form1.orig_price.value);
    //weight=eval(document.Form1.orig_weight.value);
    //cost=eval(document.Form1.orig_cost.value);
    percent = eval(document.Form1.percent.value);
    orig_price = 0;
    cost = 0;
    weight = 0;
    //strValue=orig_price;
    strValue = 0.00;
    arrProducts = 'NONE';
    arrQty = 'NONE';
    for (var i = 0; i < eval(num + 1); i++) {

        qty = eval('document.Form1.qty' + i + '.value');
        code = eval("document.Form1.sel" + i + ".options[document.Form1.sel" + i + ".selectedIndex].value");
        arr = code.split("_");
        arrProducts = arrProducts + ',' + arr[1];
        arrQty = arrQty + ',' + qty;
        weight = eval((arr[2]) * (qty)) + eval(weight);
        cost = eval((arr[3]) * (qty)) + eval(cost);
        strValue = eval((arr[0]) * (qty)) + eval(strValue);

    }

    strValue = eval((eval(strValue) * eval(percent)) + eval(strValue));
    //txtSelectedItems
    document.Form1.Price.value = formatAsMoney(strValue);
    document.Form1.Price2.value = formatAsMoney(strValue);
    document.Form1.Price3.value = '$ ' + formatAsMoney(strValue);
    document.Form1.txtSelectedItems.value = arrProducts;
    document.Form1.ArrQty.value = arrQty;
    document.Form1.txtWeight.value = weight;
    document.Form1.txtCost.value = cost;
    // End of the function printitem(sel)
}

$(document).ready(function () {
    tryToLoadImages();
});

function tryToLoadImages() {
    if (typeof (window.configImages) == 'undefined') {
        window.setTimeout('tryToLoadImages()', 1000);
        return;
    }
    $('.PullList').each(function () {
        applyImage(this);
        $(this).change(function () { applyImage(this); });
    });
}

function applyImage(item) {
    var $this = $(item);
    var val = $this.val().split("_");
    if (val.length > 1) {
        var imgUrl = window.configImages[val[1]];
        var img = $this.parents("table.config-one-item").find("img.config_change_image");
        if (imgUrl && imgUrl.length > 0) {
            img.css("visibility", "visible");
            img.attr("src", 'image_resize.aspx?image=' + imgUrl + '&width=80');
        } else {
            img.css("visibility", "hidden");
        }
    }
}
