﻿var flagToCheckIfQueryVariableExist = false;
function FillBoxes() {
    FillListsFaster(1, Categories);
    FillListsFaster(2, Groups);
    FillListsFaster(3, Brands);
    if (document.getElementById('Search') != null) {
        var TextToBesearched = getQueryVariable('SearchText')
        document.getElementById('Search').value = TextToBesearched == false ? '' : TextToBesearched;
    }
    var rbStockState = document.forms[2].elements['rb_productStockState'];
    if (rbStockState != null) {
        var isOnlyOnStockOrOnWayQueryVariableExist = getQueryVariable('OnlyOnStockOrOnWay');
        var isOnlyOnStockQueryVariableExist = getQueryVariable('OnlyOnStock');
        var isAllProductsQueryVariableExist = getQueryVariable('AllProducts');
        if (isOnlyOnStockOrOnWayQueryVariableExist != false)
            rbStockState[0].checked = true;
        else if (isOnlyOnStockQueryVariableExist != false)
            rbStockState[1].checked = true;
        else if (isAllProductsQueryVariableExist != false)
            rbStockState[2].checked = true;
        else
            rbStockState[0].checked = true;
    }

    var oAllProductCheckBox = document.getElementById('cb_allProducts');
    var oNewProductCheckBox = document.getElementById('cb_newProduct');
    var oCampaignProductCheckBox = document.getElementById('cb_campaignProduct');
    var oFleaMarketProductCheckBox = document.getElementById('cb_fleaMarketProduct');
    var oRecentlyDiscountedProductCheckBox = document.getElementById('cb_recentlyDiscountedProduct');

    var isOnlyNewProductQueryVariableExist = getQueryVariable('OnlyNewProducts');
    var isOnlyCampaignProductQueryVariableExist = getQueryVariable('OnlyCampaignProducts');
    var isOnlyFleaMarketProductQueryVariableExist = getQueryVariable('OnlyFleaMarketProducts');
    var isOnlyRecentlyDiscountedProductQueryVariableExist = getQueryVariable('OnlyRecentlyDiscountedProducts');

    if (isOnlyNewProductQueryVariableExist == false && isOnlyCampaignProductQueryVariableExist == false && isOnlyFleaMarketProductQueryVariableExist == false && isOnlyRecentlyDiscountedProductQueryVariableExist == false) {
        if (oAllProductCheckBox != null)
            oAllProductCheckBox.checked = true;
        if (oNewProductCheckBox != null)
            oNewProductCheckBox.checked = true;
        if (oCampaignProductCheckBox != null)
            oCampaignProductCheckBox.checked = true;
        if (oFleaMarketProductCheckBox != null)
            oFleaMarketProductCheckBox.checked = true;
        if (oRecentlyDiscountedProductCheckBox != null)
            oRecentlyDiscountedProductCheckBox.checked = true;
    }
    else {
        if (isOnlyNewProductQueryVariableExist != false)
            oNewProductCheckBox.checked = true;
        if (isOnlyCampaignProductQueryVariableExist != false)
            oCampaignProductCheckBox.checked = true;
        if (isOnlyFleaMarketProductQueryVariableExist != false)
            oFleaMarketProductCheckBox.checked = true;
        if (isOnlyRecentlyDiscountedProductQueryVariableExist != false)
            oRecentlyDiscountedProductCheckBox.checked = true;
    }
    if (document.getElementById('txtMinPrice') != null) {
        var TextToBesearched = getQueryVariable('MinPrice');
        document.getElementById('txtMinPrice').value = TextToBesearched == false ? '' : TextToBesearched;
    }
    if (document.getElementById('txtMaxPrice') != null) {
        var TextToBesearched = getQueryVariable('MaxPrice');
        document.getElementById('txtMaxPrice').value = TextToBesearched == false ? '' : TextToBesearched;
    }
}

function GetReleatedGroups(ListObj) {
    var CatID = getList(ListObj);
    if (CatID == "0") {
        FillListsFaster(2, Groups);
    }
    else {
        var GroupIndex = 0;
        var newGroupList = new Array();
        for (Index = 0; Index < Groups.length; Index++) {
            if (Groups[Index][1] == CatID) {
                newGroupList[GroupIndex] = new Array(Groups[Index][0].toString(), Groups[Index][1].toString(), Groups[Index][2].toString())
                GroupIndex += 1;
            }
        }
        FillListsFaster(2, newGroupList);
    }
}
function GetReleatedBrandByCategory(ListObj) {
    var CatID = getList(ListObj);
    if (CatID == "0") {
        FillListsFaster(3, Brands);
    }
    else {
        var BrandByCategoryIndex = 0;
        var newBrandListByCat = new Array();
        for (Index = 0; Index < Brands.length; Index++) {
            if (Brands[Index][1] == CatID) {
                newBrandListByCat[BrandByCategoryIndex] = new Array(Brands[Index][0].toString(), Brands[Index][1].toString(), Brands[Index][2].toString(), Brands[Index][3].toString())
                BrandByCategoryIndex += 1;
            }
        }
        FillListsFaster(3, newBrandListByCat);
    }
}
function GetReleatedBrands(ListObj) {
    var CatID = getList(document.getElementById("lst_Category"));
    var GroupID = getList(ListObj);
    if (GroupID == "0" && CatID != "0") {
        var newBrandListByCat = new Array();
        var BrandIndex = 0;
        for (Index = 0; Index < Brands.length; Index++) {
            if (Brands[Index][1] == CatID) {
                newBrandListByCat[BrandIndex] = new Array(Brands[Index][0].toString(), Brands[Index][1].toString(), Brands[Index][2].toString(), Brands[Index][3].toString())
                BrandIndex += 1;
            }
        }
        FillListsFaster(3, newBrandListByCat);
    }
    else if (GroupID != "0" && CatID != "0") {
        var BrandIndex = 0;
        var newBrandList = new Array();
        for (Index = 0; Index < Brands.length; Index++) {
            if (GroupID.indexOf(Brands[Index][2]) > -1 && CatID == Brands[Index][1]) {
                newBrandList[BrandIndex] = new Array(Brands[Index][0].toString(), Brands[Index][1].toString(), Brands[Index][2].toString(), Brands[Index][3].toString());
                BrandIndex += 1;
            }
        }
        FillListsFaster(3, newBrandList);
    }
    else if (CatID == "0" && GroupID != "0") {
        var SelectedGroups = GroupID.split(",");
        for (Index = 0; Index < SelectedGroups.length; Index++) {
            for (GroupIndex = 0; GroupIndex < Groups.length; GroupIndex++) {
                if (SelectedGroups[Index] == Groups[GroupIndex][2])
                    CatID = CatID + ',' + Groups[GroupIndex][1];
            }
        }
        var BrandIndex = 0;
        var newBrandList = new Array();

        for (Index = 0; Index < Brands.length; Index++) {
            if (GroupID.indexOf(Brands[Index][2]) > -1 && CatID.indexOf(Brands[Index][1])) {
                newBrandList[BrandIndex] = new Array(Brands[Index][0].toString(), Brands[Index][1].toString(), Brands[Index][2].toString(), Brands[Index][3].toString());
                BrandIndex += 1;
            }
        }
        FillListsFaster(3, newBrandList);
    }
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            flagToCheckIfQueryVariableExist = true;
            return pair[1];
        }
    }
    flagToCheckIfQueryVariableExist = false;
    return false;
}


function FillListsFaster(ListObject, ItemCollection) {
    var searchIds = getQueryVariable('Search');
    if (flagToCheckIfQueryVariableExist == true)
        var splittedSearchIds = searchIds.split("%7c");
    switch (ListObject) {
        case 1:
            document.getElementById("lst_Category").innerHTML = "";
            document.getElementById("lst_Category").options[0] = new Option("--Tüm Kategoriler--", "0");
            document.getElementById("lst_Category").options[0].selected = true;
            for (var Index = 0; Index < ItemCollection.length; Index++) {
                document.getElementById("lst_Category").options[Index + 1] = new Option(ItemCollection[Index][0], ItemCollection[Index][1]);
            }
            if (flagToCheckIfQueryVariableExist == true) {
                //var categoryId = parseInt(splittedSearchIds[0])+1;                        
                //var strCategoryId = categoryId + "";
                //if(strCategoryId.length == 1)
                //    strCategoryId = 0 + strCategoryId;
                for (var i = 0; i < ItemCollection.length; i++) {
                    if (document.getElementById("lst_Category")[i + 1].value == splittedSearchIds[0])
                        document.getElementById("lst_Category").options[i + 1].selected = true;
                }
            }
            break;
        case 2:
            document.getElementById("lst_Group").innerHTML = "";
            document.getElementById("lst_Group").options[0] = new Option("--Tüm Gruplar--", "0");
            document.getElementById("lst_Group").options[0].selected = true;
            for (var Index = 0; Index < ItemCollection.length; Index++) {
                document.getElementById("lst_Group").options[Index + 1] = new Option(ItemCollection[Index][0], ItemCollection[Index][2]);
            }
            if (flagToCheckIfQueryVariableExist == true) {
                for (var Index = 0; Index < ItemCollection.length; Index++) {
                    if (document.getElementById("lst_Group").options[Index + 1].value == splittedSearchIds[1] && ItemCollection[Index][1] == splittedSearchIds[0])
                        document.getElementById("lst_Group").options[Index + 1].selected = true;
                }
            }
            break;
        case 3:
            document.getElementById("lst_Brand").innerHTML = "";
            document.getElementById("lst_Brand").options[0] = new Option("--Tüm Markalar--", "0");
            document.getElementById("lst_Brand").options[0].selected = true;
            var indexOfNewOption = 1;
            for (var Index = 0; Index < ItemCollection.length; Index++) {
                if ((Index == 0) || (ItemCollection[Index][3] != ItemCollection[Index - 1][3])) {
                    document.getElementById("lst_Brand").options[indexOfNewOption] = new Option(ItemCollection[Index][3], ItemCollection[Index][0]);
                    if (flagToCheckIfQueryVariableExist == true && document.getElementById("lst_Brand")[indexOfNewOption].value == splittedSearchIds[2])
                        document.getElementById("lst_Brand").options[indexOfNewOption].selected = true;
                    indexOfNewOption++;
                }
            }
            break;
    }
}


function getList(obj) {
    var selectedItemList;
    var index = 0;
    for (var j = 0; j < obj.length; j++) {
        if (obj[j].selected) {
            if (index == 0) {
                selectedItemList = obj[j].value;
                index = 1;
            }
            else
                selectedItemList = selectedItemList + ',' + obj[j].value;
        }
    }
    return (selectedItemList);
}



function hideMenuIFrameIfVisible(event) {
    if (event.srcElement.id != 'menuIcon_Layer_1') {
        var controlClientID = document.getElementById('frmMenu');
        if (controlClientID != null) {
            if (controlClientID.style.display == "inline")
                controlClientID.style.display = "none";
        }
    }

}


function arrangeMenuVisibility(controlId) {
    var controlClientID = document.getElementById(controlId);
    if (controlClientID.style.display == "none")
        controlClientID.style.display = "inline";
    else
        controlClientID.style.display = "none";
    controlClientID.style.zIndex = "5";
    //controlClientID.style.filter = "progid: DXImageTransform.Microsoft.Alpha(style = 0, opacity = 0)";
    /*popup.document.body.style.border = "double aliceblue 5px";
    popup.document.body.style.fontFamily = "Tahoma";
    popup.document.body.style.fontSize = "smaller";
    popup.document.body.style.color = "Black";
    popup.document.body.style.overflow = "auto";
    popup.document.body.innerHTML = controlClientID.innerHTML;
    popup.show(0, 62, 600, 200, document.body);
    */
}

function PopupHelp(HelpMessageToBeDisplayed) {
    var myPopup = window.createPopup();
    var myPopBody = myPopup.document.body;
    var myPopupDiv = document.createElement('DIV');
    var myPopupWidth = 0;
    var myPopupHeight = 0;
    var myPopupOffSet = 20;
    var MarginBuffer = 4;
    var modifiedtextMessage = HelpMessageToBeDisplayed;

    with (myPopBody) {
        style.textAlign = 'left';
        style.verticalAlign = 'middle';
        style.backgroundImage = 'url(../../App_Themes/Theme_default/images/login_bg.png)';
        style.border = 'solid #BFBEC3 1px';
        style.fontFamily = 'Arial';
        style.fontStyle = 'normal';
        style.fontSize = '8pt';
        style.color = 'black';
        style.margin = MarginBuffer + 'px';
    }
    with (myPopupDiv) {
        id = 'myPopupDiv';
        style.position = 'absolute';
        style.visibility = 'hidden';
        style.fontFamily = myPopBody.style.fontFamily;
        style.fontWeight = myPopBody.style.fontWeight;
        style.fontSize = myPopBody.style.fontSize;
        style.fontStyle = myPopBody.style.fontStyle;
        style.width = '150px';
        innerHTML = modifiedtextMessage;
    }
    this.document.body.appendChild(myPopupDiv);
    myPopupWidth = (myPopupDiv.clientWidth + MarginBuffer * 2 + 5)
    myPopupHeight = (myPopupDiv.clientHeight + MarginBuffer * 2 + 5);
    myPopBody.innerHTML = modifiedtextMessage;
    myPopup.show(window.event.offsetX - 150, window.event.offsetY - 25, myPopupWidth, myPopupHeight, event.srcElement);
}

function numberOnly(evt, Obj) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (elem) {
            var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
            if ((charCode == 13) || (charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105) || (charCode == 8 || charCode == 9 || charCode == 46 || charCode == 144 || charCode == 37 || charCode == 39)) //46: Delete, 8: Backspace, 9: Tab, 144: NumLock, 37: LefArrow, 39: RightArrow, 48~57: Numbers, 96~105: NumLock Numbers
            {
                evt.returnValue = true;
            }
            else {
                document.getElementById(Obj.id).style.backgroundColor = "red";
                alert("Yanlış formatta giriş yaptınız.");
                document.getElementById(Obj.id).style.backgroundColor = "white";
                //Obj.value = "";
                evt.returnValue = false;
            }
        }
    }
}

function CharacterControl(obj) {
    if (obj.value.indexOf('<') > -1 || obj.value.indexOf('>') > -1) {
        alert(" Lütfen \'<\' ve \'>\' karakterlerini kullanmayınız.");
        obj.value = "";
    }
}

function FindProduct(SearchText, CatObj, GrpObj, BrndObj, AllProducts, IsNew, IsInCampaign, IsInBazaar, IsInDumping, MinPrice, MaxPrice, ProductStockState)//,IsNew,IsInCampaign,IsInBazaar,IsInDumping,MinPrice,MaxPrice)
{
    if (SearchText.length == 0 && getList(CatObj) == 0) {
        alert('Tüm kategorilerde arama yapılamaz! Anahtar kelime ile arama yapmak için bir anahtar kelime giriniz.')
    }
    else if (SearchText.length < 3 && getList(CatObj) == 0) {
        alert('Anahtar kelime ile arama yapmak için lütfen en az üç karakter uzunluğunda bir anahtar kelime giriniz.')
    }
    else if (SearchText.length >= 3 || getList(CatObj) != 0) {
        QueryStringToBeSearched = "SearchResult.aspx?Search=" + getList(CatObj) + '%7c' + getList(GrpObj) + '%7c' + getList(BrndObj); //+ '|' + IsNew + '|' + IsInCampaign + '|' + IsInBazaar + '|' + IsInDumping + '|' + MinPrice + '|' +  MaxPrice;
        if (SearchText != "")
            QueryStringToBeSearched += "&SearchText=" + SearchText;
        if (IsNew != null && AllProducts.checked == false && IsNew.checked == true)
            QueryStringToBeSearched += "&OnlyNewProducts=1";
        if (IsInCampaign != null && AllProducts.checked == false && IsInCampaign.checked == true)
            QueryStringToBeSearched += "&OnlyCampaignProducts=1";
        if (IsInBazaar != null && AllProducts.checked == false && IsInBazaar.checked == true)
            QueryStringToBeSearched += "&OnlyFleaMarketProducts=1";
        if (IsInDumping != null && AllProducts.checked == false && IsInDumping.checked == true)
            QueryStringToBeSearched += "&OnlyRecentlyDiscountedProducts=1";
        if (MinPrice != null && MinPrice.value != "")
            QueryStringToBeSearched += "&MinPrice=" + MinPrice.value;
        if (MaxPrice != null && MaxPrice.value != "")
            QueryStringToBeSearched += "&MaxPrice=" + MaxPrice.value;
        if (ProductStockState != null) {
            var oRadio = document.forms[2].elements[ProductStockState];
            if (oRadio != null) {
                for (var i = 0; i < oRadio.length; i++) {
                    if (oRadio[i].checked) {
                        QueryStringToBeSearched += "&" + oRadio[i].value + "=1";
                    }
                }
            }
            else
                QueryStringToBeSearched += "&AllProducts=1";
        }
        if (document.getElementById("spanIleriSecenekler")!= null)
            document.getElementById("spanIleriSecenekler").style.display = "none";
        if (document.getElementById("imgProgressBar") != null)
            document.getElementById("imgProgressBar").style.visibility = "visible";
        window.location.href = QueryStringToBeSearched;
    }
}

function ArrangeAllProductSituationCheckBox(oAllSituations, oNewProduct, oCampaignProduct, oRecentlyDiscountedProduct, oFleaMarketProduct) {
    if (oAllSituations.checked == true) {
        oNewProduct.checked = true;
        oCampaignProduct.checked = true;
        oRecentlyDiscountedProduct.checked = true;
        oFleaMarketProduct.checked = true;
    }
    else {
        oNewProduct.checked = false;
        oCampaignProduct.checked = false;
        oRecentlyDiscountedProduct.checked = false;
        oFleaMarketProduct.checked = false;
    }
}

function ArrangeProductSituationCheckBoxes() {
    _ArrangeProductSituationCheckBoxes(document.getElementById('cb_allProducts'), document.getElementById('cb_newProduct'), document.getElementById('cb_campaignProduct'), document.getElementById('cb_recentlyDiscountedProduct'), document.getElementById('cb_fleaMarketProduct'));
}    

function _ArrangeProductSituationCheckBoxes(oAllSituations, oNewProduct, oCampaignProduct, oRecentlyDiscountedProduct, oFleaMarketProduct) {
    if (oNewProduct.checked == true && oCampaignProduct.checked == true && oRecentlyDiscountedProduct.checked == true && oFleaMarketProduct.checked == true)
        oAllSituations.checked = true;

    if (oNewProduct.checked == false)
        oAllSituations.checked = false;
    if (oCampaignProduct.checked == false)
        oAllSituations.checked = false;
    if (oRecentlyDiscountedProduct.checked == false)
        oAllSituations.checked = false;
    if (oFleaMarketProduct.checked == false)
        oAllSituations.checked = false;
}

function popUp_UpdateBasketProperties(basketId) {
    myleft = (screen.availwidth) ? (screen.availwidth - 250) / 2 : 100; mytop = (screen.availheight) ? (screen.availheight - 165) / 2 : 100;
    settings = 'top=' + mytop + ',left=' + myleft + ',width=360,height=165,menubar=no, resizable=no'
    Bakorada = window.open('../../PopUpWindows/basket_newName.aspx', 'Avnet', settings);
    Bakorada.focus();
}

function popUp_DeleteBasket(basketId) {
    myleft = (screen.availwidth) ? (screen.availwidth - 300) / 2 : 100; mytop = (screen.availheight) ? (screen.availheight - 300) / 2 : 100;
    settings = 'top=' + mytop + ',left=' + myleft + ',width=200,height=10,menubar=no, resizable=no'
    Bakorada = window.open('../../PopUpWindows/basket_delete.aspx', 'Avnet', settings);
    Bakorada.focus();
}

function ProductDetails(productId) {
    var Width = 800;
    var Height = 600;
    var Left = screen.availWidth / 2 - (Width / 2);
    var Top = screen.availHeight / 2 - (Height / 2);
    window.open(
        'ProductDetails.aspx?ProductId=' + encodeURIComponent(productId),
        'Avnet',
        'top=' + Top + ', left=' + Left + ', width=' + Width + ', height=' + Height + ', menubar=no, scrollbars=yes, resizable=yes');
}

function DisplayInvoice(invoiceId) {
    var Width = 600;
    var Height = 600;
    var Left = screen.availWidth / 2 - (Width / 2);
    var Top = screen.availHeight / 2 - (Height / 2);
    window.open(
        '../../Modules/Home/DisplayInvoice.aspx?OrderId=' + invoiceId,
        'Avnet',
        'top=' + Top + ', left=' + Left + ', width=' + Width + ', height=' + Height + ', menubar=no, scrollbars=yes, resizable=no');
}

function DisplayFinancialTransaction(FinancialTransactionId) {
    var Width = 600;
    var Height = 400;
    var Left = screen.availWidth / 2 - (Width / 2);
    var Top = screen.availHeight / 2 - (Height / 2);
    window.open(
        '../../Modules/Home/DisplayFinancialTransaction.aspx?FinancialTransactionId=' + FinancialTransactionId,
        'Avnet',
        'top=' + Top + ', left=' + Left + ', width=' + Width + ', height=' + Height + ', menubar=no, scrollbars=yes, resizable=yes');
}

function NewBasket() {
    var Width = 360;
    var Height = 150;
    var Left = screen.availWidth / 2 - (Width / 2);
    var Top = screen.availHeight / 2 - (Height / 2);
    window.open(
        '../../PopUpWindows/basket_newBasket.aspx',
        'Avnet',
        'top=' + Top + ', left=' + Left + ', width=' + Width + ', height=' + Height + ', menubar=no, resizable=no');
}

function DiscountsByPaymentType() {
    var Width = 710;
    var Height = 700;
    var Left = screen.availWidth / 2 - (Width / 2);
    var Top = screen.availHeight / 2 - (Height / 2);
    window.open(
        '../../Modules/Home/DiscountsByPaymentType.aspx',
        'Avnet',
        'top=' + Top + ', left=' + Left + ', width=' + Width + ', height=' + Height + ', menubar=no, scrollbars=yes, resizable=yes');
}

function ConfirmationOfBid(BidPrice) {
    var Width = 600;
    var Height = 230;
    var Left = screen.availWidth / 2 - (Width / 2);
    var Top = screen.availHeight / 2 - (Height / 2);
    window.open(
                '../../../Modules/Home/ConfirmationOfBid.aspx?BidPrice=' + BidPrice,
                'Avnet',
                'top=' + Top + ', left=' + Left + ', width=' + Width + ', height=' + Height + ', menubar=no, scrollbars=yes, resizable=no');
}

function ReturnConfirmationOfBid(BidPrice) {
    window.opener.location.href('../../../Modules/Home/Default.aspx?BidPrice=' + BidPrice);
}

function arrangeDetailedBasketOptionsVisibility(controlId) {
    var controlClientID = document.getElementById(controlId);
    if (controlClientID.style.display == "inline" || controlClientID.style.display == "")
        controlClientID.style.display = "none";
    else
        controlClientID.style.display = "inline";
}

function newImage(arg) {
    if (document.images) {
        rslt = new Image(1000, 1000);
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i = 0; i < changeImages.arguments.length; i += 2) {
            document[changeImages.arguments[0]].src = changeImages.arguments[1];
        }
    }
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
        menuIcon_Layer_1_over = newImage("../../App_Themes/Theme_default/images/menu_over.png");
        preloadFlag = true;
    }
}

function addOnloadHandler(func) {
    if (window.onload) {
        var windowOnload = window.onload;
        window.onload = function(evt) {
            windowOnload(evt);
            func(evt);
        }
    } else {
        window.onload = function(evt) {
            func(evt);
        }
    }
}

function ImgResize(ImgObj, TargetWidth, TargetHeight) {
    ImgObj.style.display = "none";
    var TempW = 0;
    var TempH = 0;
    var SourceW = ImgObj.width;
    var SourceH = ImgObj.height;
    if (SourceW != 1 && SourceH != 1) {
        TempH = SourceH * TargetWidth / SourceW;
        TempW = TargetWidth
        if (TempH > TargetHeight)
            TempW = SourceW * TargetHeight / SourceH;
    }
    if (SourceW < TargetWidth)
        TempW = SourceW;
    if (SourceH < TargetHeight)
        TempH = SourceH;
    ImgObj.width = TempW;
    ImgObj.height = TempH;
    ImgObj.style.display = "inline";
}

function doClick(buttonName, e) {
    //the purpose of this function is to allow the enter key to
    //point to the correct button to click.        
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null) {
            btn.click();
            event.keyCode = 0
        }
    }
}




