﻿/* 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 = "Order now – only " + e.get_quantityAvailable() + " left";
		} 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"

//var swatchUrl = '<%# ResolveUrl("~/assets/images") %>';

function SwatchOver(sender, eventArgs) {
	var mainImage = document.getElementById("MainImage");
	swatchPath = sender.get_swatchImagePath();
	mainImage.src = swatchPath + 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");
	swatchPath = sender.get_swatchImagePath();
	mainImage.src = swatchPath + sender.get_selectedImage();
}

/* Alternates */
//this function will cause the main image to swap when an alternate is rolled over.
//typically used in onmouseover and onmouseout to show the alternate and then change 
//back to the main image
   function AlternateOver(imagePath) {

   	var mainImage = $("#MainImage");
   	mainImage.attr('src', imagePath);
   }

