var timeOutId;
var timeOutBasketPopUp;
function ShowPopup(mainLinkID) {
    if (timeOutId != '')
        window.clearTimeout(timeOutId);



    var link = $('#' + mainLinkID);
    link.blur();
    var popup = $('#PopupLanguages');
    var linkOffset = link.offset();

    popup.css('left', linkOffset.left + link.width() - popup.width() - 18);
    popup.css('top', linkOffset.top - 5);

    popup.stop(true, true);

    popup.slideDown(0);
    timeOutId = window.setTimeout(function() {
        popup.slideUp(0);
    }, 3000);
}

function CheckComponentSelection(controlId) {
    var listObject = document.getElementById(controlId);
    var toReturn = false;

    if (listObject != null) {
        var selectedIndex = listObject.selectedIndex;
        var selectedText = listObject.options[selectedIndex].value;
        if (selectedText != null && selectedText != '')
            toReturn = true;
    }
    return toReturn;
}
/************************** Basket PopUp *******************************/
function ShowBasketPopUp() {
    if (timeOutBasketPopUp != '') window.clearTimeout(timeOutBasketPopUp);

    var popup = $(".shoppingCart");

    popup.slideDown(0);
    $('.greyBlock').addClass('Hover');

    timeOutId = window.setTimeout(function() {
        popup.slideUp(0); $('.greyBlock').removeClass('Hover');
    }, 3000);

}
function FillVariation(hfImg, pTitle, hfTitle, hfProducLink, hfProductPrice) {

    document.getElementById('imgSmall').src = document.getElementById(hfImg).value;
    document.getElementById(pTitle).href = document.getElementById(hfProducLink).value;
    document.getElementById(pTitle).innerHTML = document.getElementById(hfTitle).value;
    document.getElementById('PopUpPrice').innerHTML = document.getElementById(hfProductPrice).value;

}
function PopUpClose() {
    var popup = $(".shoppingCart");
    popup.slideUp(0);
    $('.greyBlock').removeClass('Hover');
}
/************************** END Basket PopUp *******************************/
/************************** Wish List PopUp *******************************/
function ShowWishListPopUp() {
    if (timeOutBasketPopUp != '') window.clearTimeout(timeOutBasketPopUp);

    var popup = $(".wishListPopUp");

    if (typeof (Page_ClientValidate) == "function") {
        if (Page_IsValid) PopUp(popup);
    }
    else PopUp(popup);
}

function PopUp(popup) {

    popup.slideDown(0);

    timeOutId = window.setTimeout(function() {
        popup.slideUp(0);
    }, 1500);
}

/************************** END Wish List PopUp *******************************/
/************************** Adjust height product items *******************************/
$(document).ready(function() {
    //AdjustPricePosition();
    // AdjustPricePositionPL();
    //   AdjustPricePositionrRelProd();
    AdjustHeader_OrderOverviewCheckOutStep();
});
/*Category Page*/
function AdjustHeader_OrderOverviewCheckOutStep() {
    var stepCount = 4;
    for (var i = 1; i <= stepCount; i++) {
        if (($('div.wizardHeading div:nth-child(' + i + ') h2').height()) > 20) {
            $('div.wizardHeading div:nth-child(' + i + ') h2').css('letter-spacing', '-1px');
        }
    }
}

function AdjustPricePosition() {
    var prdCount, sumH, fullRow, mod, i;
    prdCount = $('div.productItem').size();
    
    fullRow = prdCount / 3;
    mod = prdCount % 3;

    for (var i = 1; i <= fullRow; i++) {

        sumH = ($('div.ProductsSet div:nth-child(' + (3 * i - 2) + ') a.productName').height()) +
                           ($('div.ProductsSet div:nth-child(' + (3 * i - 1) + ') a.productName').height()) +
                           ($('div.ProductsSet div:nth-child(' + (3 * i) + ') a.productName').height());

        if (sumH > 60) {
            ($('div.ProductsSet div:nth-child(' + (3 * i - 2) + ') a.productName').css('height', '38px'));
            ($('div.ProductsSet div:nth-child(' + (3 * i - 1) + ') a.productName').css('height', '38px'));
            ($('div.ProductsSet div:nth-child(' + (3 * i) + ') a.productName').css('height', '38px'));
        }        
    }

    switch (mod) {
        case 1:
            sumH = ($('div.ProductsSet div:nth-child(' + (3 * i - 2) + ') a.productName').height());
            if (sumH > 20) $('div.ProductsSet div:nth-child(' + (3 * i - 2) + ') a.productName').css('height', '38px');
            break;        
        case 2:
            sumH = $('div.ProductsSet div:nth-child(' + (3 * i - 2) + ') a.productName').height() +
                   $('div.ProductsSet div:nth-child(' + (3 * i - 1) + ') a.productName').height();
            if (sumH > 40) {
                $('div.ProductsSet div:nth-child(' + (3 * i - 2) + ') a.productName').css('height', '38px');
                $('div.ProductsSet div:nth-child(' + (3 * i - 1) + ') a.productName').css('height', '38px');
            }
            break;
    }
}
/*Shop default page*/
function AdjustPricePositionPL() {
    var s = 0;
    $('h2.newProductsLabel').each(function() {
        $(this).next().find('a.productName').each(function() {
            s += $(this).height();
        });
        $('h2.newProductsLabel').each(function() {
            if (s > 48) {
                $(this).next().find('.productInfoContainer').css('height', '32px')
            }
        });
    });
    s = 0;
    $('h2.PopularProductsLabel').each(function() {
        $(this).next().find('a.productName').each(function() {
            s += $(this).height();
        });

        $('h2.PopularProductsLabel').each(function() {
            if (s > 48) {
                $(this).next().find('.productInfoContainer').css('height', '32px')
            }
        });
    });
}
/*Releted and Complementary product*/
function AdjustPricePositionrRelProd() {    

     var maxH = 0;
    $('div.relatedTop + div.productFlowContainer .row_first_last div.cntMiddle').each(function() {
        var h = $(this).find('a.productName').height();
        if (maxH < h) maxH = h;
    });
    if (maxH > 30) {
        $('div.relatedTop + div.productFlowContainer .row_first_last div.cntMiddle div.productInfoContainer').css('height', '34px');
    }        
    
    $('div.additionalHeader + div.productFlowContainer .row_first_last div.cntMiddle').each(function() {
        var h = $(this).find('a.productName').height();
        if (maxH < h) maxH = h;
    });
    if (maxH > 30) {
        $('div.additionalHeader + div.productFlowContainer .row_first_last div.cntMiddle div.productInfoContainer').css('height', '34px');
    }
}
/************************** END Adjust height product items *******************************/
/******************** DEFAULT BUTTON Functionality*******************************/
function clickButton(e, buttonid) {
    //debugger;
    var bt = document.getElementById(buttonid);
    if (typeof (bt) == 'object') {
        if (navigator.appName.indexOf("Netscape") > -1) {
            if (e.keyCode == 13) {
                if (bt && typeof (bt.click) == 'undefined') {
                    bt.click = addClickFunction1(bt);
                }
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > -1) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
}

function addClickFunction1(bt) {
    //debugger;
    var result = true;
    if (bt.onclick) result = bt.onclick();
    if (typeof (result) == 'undefined' || result) {
        eval(bt.href);
    }
}
/********************************** Zoom Tool ****************************************/
function MagicZoomPlusRefresh() {
    $(document).ready(function() {
        MagicZoomPlus.refresh();
    });
}

/************************** Maz Lenght MultiLine TextBox *****************************/
function checkTextAreaMaxLength(textBox, e, length) {

    var maxLength = parseInt(length);
    if (!checkSpecialKeys(e)) {
        if (textBox.value.length > maxLength - 1) {
            if (window.event)//IE
                e.returnValue = false;
            else//Firefox
                e.preventDefault();
        }
    }
}
function checkSpecialKeys(e) {
    if (e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40)
        return false;
    else
        return true;
}
/*************************************************************************************/  

