﻿/* Availability Messaging Functions */
function skuSelector1_SelectedIndexChangedHandler(e) {
    var availMsg = (e.get_availabilityMessage() != null && e.get_availabilityMessage() != "") ? e.get_availabilityMessage() : "&nbsp;";
    $get("divAvailability").innerHTML = availMsg;

    var qtyMsg = "&nbsp;";

    var btnAdd = $get("addToCartDiv");

    if (e.get_quantityAvailable() != null && e.get_quantityAvailable() != "") {
        if (e.get_quantityAvailable() < 25) {
            qtyMsg = "There are " + e.get_quantityAvailable() + " in stock";
        } else {
            qtyMsg = "Plenty in stock";
        }

        //if  out of stock
        if (e.get_quantityAvailable() == 0) {
            //hide add to cart button
            btnAdd.style.visibility = "hidden";
        } else {
            //show add to cart button
            btnAdd.style.visibility = "visible";
        }
    } else {
        //hide add to cart button
        btnAdd.style.visibility = "hidden";
    }
    $get("spanNumAvail").innerHTML = qtyMsg;

}


/* 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 = document.getElementById("MainImage");
    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 = document.getElementById("MainImage");
    mainImage.src = "assets/images/swatches/" + sender.get_selectedImage();
}


/* Alternate Functions */
//this function will cause the main image to swap when an alternate is rolled over.
//you must add the following to the swatch control declaration:
//  OnClientThumbNailMouseOver="SwatchOver" 
function AlternateOver(imageName) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = "assets/images/alternates/" + imageName;
}

//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 = document.getElementById("MainImage");
    mainImage.src = mainImageSrc;
}

//this function will cause the main image to swap when an alternate is clicked.
//you must add the following to the swatch control declaration:
//  OnClientSelectedIndexChanged="SwatchClick"
function AlternateClick(imageName) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = "assets/images/alternates/" + imageName;

}

/* 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;
}