﻿// JScript File

function UpdatePrice(price,qty_id,total_id)
{
    var uQty = document.getElementById(qty_id);
    var uTotal = document.getElementById(total_id);        
    if (price != null && uQty != null && uTotal != null)
    {
        var value = (uQty.value * price);
        if (isNaN(value))
        {
            uQty.value = 0;
            uTotal.value = 0;
        }
        else
            uTotal.value = formatCurrency(value);        
    } 
    else
    {
        uTotal.value = 0;    
        uQty.value = 0;
    }   
}

function jsChangeColor(id, color)
{
    var lnk = document.getElementById(id);
    if (lnk != null)
    {
        lnk.style.color = color;
    }
}

function enlargeImage(id)
{
    if (id == 1)
        $find('ctl00_uxPlaceHolder_uxProductFormView_uxProductDetails_uxCatalogImage_ModalPopupExtenderLandscape').show();    
    else if (id == 2)
        $find('ctl00_uxPlaceHolder_uxProductFormView_uxProductDetails_Invitation_uxCatalogImage_ModalPopupExtenderLandscape').show();                
    else if (id == 3)
        $find('ctl00_uxPlaceHolder_uxProductFormView_uxProductDetails_Enquiry_uxCatalogImage_ModalPopupExtenderLandscape').show();    
}

function printPartOfPage(elementId)
{
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}

function fnUpdateQuantity(id_cb, id_qty, id_total, unit_price)
{
    var cb = document.getElementById(id_cb); 
    if (cb != null)
    {
        if (cb.checked)
        {
            var qty_obj = document.getElementById(id_qty);
            var total_obj = document.getElementById(id_total);
            //total_obj.style.display = '';
            total_obj.disabled=false;
            if (qty_obj != null && total_obj != null)
            {
                var value = (qty_obj.value * unit_price);
                if (isNaN(value))
                    total_obj.value = 0;
                else
                    total_obj.value = formatCurrency(value);
            }
        }
        else
        {
            var total_obj = document.getElementById(id_total);
            //total_obj.style.display = 'none';
            total_obj.disabled = true;
            total_obj.value = 0;
        }
    }
}

function formatCurrency(num) 
{
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}
