﻿﻿setPanelHeight = function(panelClass) {
    $(panelClass).equalizeHeights();
};

$.fn.equalizeHeights = function() {
    var maxHeight = this.map(function(i,e) {

        var retVal = $(e).height();
  
        if ($(e).find('img').height() > $(e).height())
            retVal = $(e).find('img').height();

        return retVal;

    }).get();

    return this.height( Math.max.apply(this, maxHeight) );
};

displayBuyButton = function() {
    if (myBasket != null) {
        $('img.imgBuy').fadeIn(200);
    } else {
        setInterval(displayBuyButton(), 100);
    }
};

zoomProductImage = function(productId) {
    return openIframe('/_common/iframes/imgZoom.aspx?productId=' + productId, 650, 470);
};

zoomChassisImage = function(chassisId) {
    return openIframe('/_common/iframes/imgZoom.aspx?chassisId=' + chassisId, 650, 470);
};

showProductVideo = function(productId) {
    return openIframe('/_common/iframes/video.aspx?productId=' + productId, 500, 430);
};

showChassisVideo = function(chassisId) {
    return openIframe('/_common/iframes/video.aspx?chassisId=' + chassisId, 600, 450);
};

openIframe = function(content, width, height) {
    Shadowbox.open({
        player: 'iframe',
        content: content,
        height: height,
        width: width
    });

    return false;
};

showHTML = function(content, width, height) {
    Shadowbox.open({
        player: 'html',
        content: content,
        height: height,
        width: width
    });

    return false;
}

showTooltip = function(btn, title, value) {
    var t;
    var btn = $(btn);
    var btnPos = btn.offset();
    var box = $('#tooltip');

    box.find('.title').text(title.replace('<br />', ' '));
    box.find('.text').text(value);

    box
        .css('left', btnPos.left - 75)
        .css('top', btnPos.top - 25)
        .fadeIn(300);

    //clearInterval(t);

    t = setTimeout(function() {
        box.fadeOut(600);
    }, 3500);

    box.mouseenter(function() {
        clearInterval(t);
    }).mouseleave(function() {
        t = setTimeout(function() {
            box.fadeOut(600);
        }, 1000);
    });

    return false;
};

closeTooltip = function() {    
    $('#tooltip').fadeOut(300); 

    return false;
};

enterKeyPress = function(input, btn) {
    $(input).keypress(function(event) {
        if (event.which == '13' || event.keyCode == '13') {
            $(btn).click();
        }
    });
};

//http://www.webcredible.co.uk/user-friendly-resources/css/css-round-corners-borders.shtml

swapImg = function(thumb, normal, zoom, isZoomPnl) {

    var imgUrl = $(thumb).attr('src');

    $('#thumbs img').css('border', '1px solid #cccccc');

    $(normal)
        .fadeOut(200, function() {
            $(this).attr('src', imgUrl.replace('thumbs', 'zoom'))
        })
        .fadeIn(200);

    if (zoom != null)
        $(zoom).attr('href', imgUrl.replace('thumbs', 'zoom-details'));

    $(thumb).css('border', '1px solid #c53543');

    return false;
};

function DDLToTextBox(list, textbox) {
    textbox.value = list.options[list.selectedIndex].innerHTML;
}

function CheckDDLSelection(list) {
  
    if (list.options[list.selectedIndex].value == "None") {
        alert("Please select an option before submitting");
        return false;
    }
}

clearHelperText = function(tb) {
    var txt = $(tb);

    if (txt.val().toLowerCase() == 'enter product code')
        txt.val('');
};

restoreHelperText = function(tb) {
    var txt = $(tb);

    if (txt.val()== '')
        txt.val('Enter Product Code');
};

sendErrorAlert = function(error) {
    try {
        $.ajax({
            url: '/JSAppErrorAlerter.ashx',
            cache: false,
            data: {
                method: 'sendAlert',
                emails: 'simone%40intuitiv.net',
                content: error
            },
            success: function(data) {
                //alert('success');
            }
        });
    }
    catch (error) { }
};


