﻿/* Availability Messaging Functions */
function skuSelector1_SelectedIndexChangedHandler(e) {
    var availMsg = (e.get_availabilityMessage() != null && e.get_availabilityMessage() != "") ? e.get_availabilityMessage() : "&nbsp;";
    var qtyMsg = "&nbsp;";

    //var btnAdd = document.getElementById("ctl00_master_main_FormView1_AddToCart");
    var btnAdd = $("[id$='_AddToCart']").get(0);
    //$(("#add_to_cart_div_btn_" + e._variantObjects[0].ProductId + " #ctl00_master_main_FormView1_AddToCart")).html($(("#add_to_cart_div_btn_" + e._variantObjects[0].ProductId)).html().replace("<b>See Step 2 for options</b>",""));
    var outOfStockHtml = "<img src='" + out_of_stock_btn + "' width='88px' height='31px' alt='out of stock'/>";
    var variant = e.get_selectedVariantObject();
    var available = false;
    if (variant != null && variant != 'undefined') {
        try {
            available = e.IsSkuAvailable(variant);

        }
        catch (err) { }
    }

    
    try {
        if (available) {
            btnAdd.src = availInStockBtn; //btnAdd.src.replace("OutOfStockBtn.jpg", "btn_add_cart.jpg");
            btnAdd.disabled = false;

        }
        else {
            btnAdd.src = out_of_stock_btn; //btnAdd.src.replace("btn_add_cart.jpg", "btn_add_cart_off.jpg");
            btnAdd.disabled = true;

        }
        
    }
    catch (err) { }
    try {
        var qtyAvail = "";
        
        if (
            e.get_quantityAvailable() == null ||
            e.get_quantityAvailable() == undefined ||
            e.get_quantityAvailable() == "" ||
            e.get_quantityAvailable() == "&nbsp;"
            ) {
            qtyAvail = "0 available";
        }
        else {
            qtyAvail = e.get_quantityAvailable() + " available";
        }
        var availHtml = "<b>" + availMsg +  "</b>";
        $(".prodAvailability").html(availHtml);
        
        
        
    }
    catch (err)
    { }
    if (e._selectedSkuIndex == -1) {
        btnAdd.src = seeStep2;
    }



}

/* Swatch Functions */
//this function will cause the main image to swap when a swatch is rolled over.
//you must add the following to the swatch control declaration:
//  OnClientThumbNailMouseOver="SwatchOver" 
function SwatchOver(sender, eventArgs) {
    var mainImage = GetMainImage();
    mainImage.src = "assets/images/swatches/" + sender._swatches[eventArgs.index].Image;
}

//this function will cause the main image to swap when a swatch is rolled off.
//you must add the following to the swatch control declaration:
//  OnClientThumbnailMouseOut="SwatchOut" 
function SwatchOut(sender, eventArgs) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = mainImageSrc;
}

//this function will cause the main image to swap when a swatch is clicked.
//you must add the following to the swatch control declaration:
//  OnClientSelectedIndexChanged="SwatchClick"
function SwatchClick(sender) {
    var mainImage = GetMainImage();
    mainImage.src = "assets/images/swatches/" + sender.get_selectedImage();
}

function showReviewTab() {
    var tabCont = $(".tabcontrol");
    tabCont[0].control.set_activeTabIndex(2);

}

function showReviewForm() {
    $("#divHideShowReviewForm").show();
    $("#linkShowRevForm").hide();
}


function hideReviewForm() {
    $("#divHideShowReviewForm").hide();
    $("#linkShowRevForm").show();
}

/* Alternate Functions */
var mainImageSrc = null;

$(document).ready(function() {

    //LOADING POPUP  
    //Click the button event!
    $(".enlargeImage").click(function() {
        //centering with css

        centerPopup();
        //load popup  
        loadPopup();
    });
    //CLOSING POPUP  
    //Click the x event!  
    $("#popupContactClose").click(function() {
        disablePopup();
    });
    //Click out event!  
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
    //Press Escape event!  
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
    mainImageSrc = $(".imageMainImage").attr('src');
    var i = 0;

});

function AlternateOver(imagePath) {

    var mainImage = GetMainImage();
    mainImage.attr('src', imagePath);
}

//this function will cause the main image to swap when an alternate is rolled off.
//you must add the following to the swatch control declaration:
//  OnClientThumbnailMouseOut="SwatchOut"
function AlternateOut() {
    var mainImage = GetMainImage();
    mainImage.attr('src', mainImageSrc);
}

function GetMainImage() {

    var mainImage = $(".imageMainImage");
    return mainImage;
}

/* Jumbo Functions */
var winPhoto;
function makeNewWindow(path, title) {
    winPhoto = window.open("", "AltView", "height=500,width=500,status=0,scrollbars=0,location=0,resizable=1");
    winPhoto.document.open();
    winPhoto.document.write('<html>');
    winPhoto.document.write('    <head>');
    winPhoto.document.write('        <title>');
    winPhoto.document.write(title);
    winPhoto.document.write('        </title>');
    winPhoto.document.write('<sc' + 'ript lang=javascript>');
    winPhoto.document.write('var largeimage = new Image();');
    winPhoto.document.write('largeimage.src ="' + path + '"');
    winPhoto.document.write('</s' + 'cript>');
    winPhoto.document.write('    </head>');
    winPhoto.document.write('    <body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">');
    winPhoto.document.write('    <table border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#FFFFFF">');
    winPhoto.document.write('      <tr>');
    winPhoto.document.write('        <td align="center" class="dept_products_in"><img align=center src="' + path + '" onLoad="window.resizeTo(largeimage.width+60,largeimage.height+140);" ></td>');
    winPhoto.document.write('      </tr>');
    winPhoto.document.write('      <tr>');
    winPhoto.document.write('        <td align="center"><a href="javascript:window.close();" class="large_image">Close window</a><br></td>');
    winPhoto.document.write('      </tr>');
    winPhoto.document.write('     </table>	');
    winPhoto.document.write('    </body>');
    winPhoto.document.write('</html>');
    winPhoto.document.close();
    winPhoto.focus();
    return false;
}
function alternateMainImage(lgImage) {
    $(".imageMainImage").attr("src",lgImage); 
}
function resumeMainImage() {
//.src = glblMainImageSrc;
$(".imageMainImage").attr("src",glblMainImageSrc);
}