﻿//written by Mark Savage for MidwayUSA.com
//this requires jQuery
//www.jQuery.com

$j(document).ready(function() {
    $j("a[id^='productTabLink']")
        .click(function() {
            changeTab(this);
        })
        .mouseover(function() {
            this.style.cursor = "pointer";
        });

    $j("#productTabLinkProductInformation").click();    
});

function openPackageSizeWindow(saleItemId) {
    window.open("http://www.midwayusa.com/eproductpage.exe/productstats?saleitemid=" + saleItemId, 'PackageSizeWindow', 'statusbar=false,toolbar=false,scrollbars=yes,resizable=no,width=420,height=327');
}

function submitReviewFeedback(reviewId, isHelpful) {
    var dataString = "contextKey=" + reviewId + "_" + isHelpful;

    $j.ajax({
        type: "POST",
        url: "http://www.midwayusa.com/ProductReviews/ProductReviewsWS.asmx/AddHelpfulReview",
        data: dataString,
        dataType: "xml",
        success: function(result) {
            $j("#reviewFeedbackBlock" + reviewId).html("Thank you for your opinion. We, as well as our other Customers, appreciate your input!");
        }
    });
}

function addSaleItemToCart(saleItemId) {
    var quantity = $j("#quantityBox").val();    
    document.location = "http://www.midwayusa.com/eshoppingcart.exe/quickcat?SaleItemID=" + saleItemId + "&quantity=" + quantity;
}

function openFriendWindow(saleItemId) {
    window.open("http://www.midwayusa.com/esendfriend.exe/friendpage?SaleItemID=" + saleItemId, 'SendToAFriendPage', 'statusbar=false,toolbar=false,scrollbars=yes,resizable=no,width=400,height=300');
}

function openProdPageWindow(url) {
    prodPageWindow = window.open(url, "prodPageWin", "width=400,height=300,resizable=no,scrollbars=yes");
    prodPageWindow.location.replace(url);
    prodPageWindow.focus();

    if (prodPageWindow.opener == null)
        prodPageWindow.opener = window; 
}

function changeTab(tab) {
    var activeTabName = tab.id.substring(14, tab.id.length);
    var activeTab = $j("#productTab" + activeTabName);

    //change the tab appearance    
    $j("a[id^='productTabLink'] > span").css("background-position", "100% 0px").css("color", "").css("font-weight", "normal");
    $j("a[id^='productTabLink']").css("background-position", "0% 0px").css("color", "");

    $j("#" + tab.id + " > span").css("background-position", "100% -42px").css("color", "#000").css("font-weight", "bold");
    $j("#" + tab.id + "").css("background-position", "0% -42px").css("color", "#000");
    
    //hide all content blocks
    $j("div[id^='productTab'], div[id^='placeholder']").css("display", "none");    

    if (activeTab.attr("usePlaceholder") == "true") {
        activeTab.css("display", "inline-block");
        $j("#placeholder" + activeTabName).css("display", "inline");
    }
    else {
        activeTab.css("display", "inline");
    }         
}