function UpdateOrderForm() {
	var dom = 'document.forms[0].';

	var Total = 0;
	var Extended = 0;
	var strOrder = "";
	//alert ("Hi!  I'm In!");
 	for (var i = 0; i<7 ; i++)
	{
		//alert ("Inside the loop");
		var oLineQty= document.getElementById("Quantities"+i);
		var LineQty = new Number(oLineQty.value);
		if (LineQty > 0)
		{
			//alert("Quantities: "+LineQty);
			var oLineProduct = document.getElementById("Products"+i);
			var LineProduct = oLineProduct.value;
			//alert("LineProduct: "+ LineProduct);
			var oItemSize= document.getElementById("Sizes"+i);
			var ItemSize = oItemSize.value;
			if (LineProduct == 'Maroon Blanket' || LineProduct == 'Black Blanket')
			{
				Extended = LineQty * 25;
			}
			else
			{
				if (ItemSize == "-")
				{
					alert("You must select a size for pants.  Quantity reset to zero to avoid confusion.  Please re-enter your quantity");
					oLineQty.value = 0;
					LineQty = 0;
				}
				Extended = LineQty * 20;
			}
			//alert("Extended: "+Extended);
			Total = Total + Extended;
			var oLineTotal = document.getElementById("Total"+i);
			oLineTotal.value = "$"+Extended+".00";
			if (Extended > 0)
			{
				strOrder = strOrder + "| "+LineProduct + "("+ItemSize+")-" + LineQty;
			}
		}
		else
		{
			var oLineTotal = document.getElementById("Total"+i);
			oLineTotal.value = "$0.00";
		}
	}    
	//alert ("Total: "+Total);
	//alert ("StrOrder: "+strOrder);
	UpdateBuyButton("BB_BuyButtonForm1",strOrder,1,Total,"Huskies Merchandise");
}
function CalculateDMBuyButton() 
{
	var TotalAmt = 0;
	var TotalQty = 0;
	var strOrder = "";
 	
	var AdultQty = new Number(document.getElementById("txtAdultQty").value);
	var SeniorQty = new Number(document.getElementById("txtSeniorQty").value);	
	TotalAmt = (AdultQty * 25) + (SeniorQty * 20);
	var AdultSubtotal = AdultQty * 25;
	var SeniorSubtotal = SeniorQty * 20;
	TotalQty = AdultQty + SeniorQty;
	TotalAmt = AdultSubtotal + SeniorSubtotal;
	strOrder = "Adult Entry: "+ AdultQty + " | Sr Entry: "+ SeniorQty;
        document.getElementById("txtAdultTotal").value = AdultSubtotal;
        document.getElementById("txtSeniorTotal").value = SeniorSubtotal;
        document.getElementById("txtTotalQty").value = TotalQty;
        document.getElementById("txtTotalAmt").value = TotalAmt;

	UpdateBuyButton("BB_BuyButtonForm1",strOrder,1,TotalAmt,"Doug Munro Event");
}

function GetBalance()
{
    var element = document.getElementById("YesNo");
    if (element.value == "Y")
    {
       setElementVisibility("NoBalance",false);
       setElementVisibility("BalanceEntry",true);
       txtBalance.focus();
    } else {
       setElementVisibility("BalanceEntry",false);
       setElementVisibility("NoBalance",true);
    }
}

function ApplyFinalBalance()
{
      if (! isValidNumber(document.getElementById("txtBalance").value))
      {
          alert ("Invalid amount entered");
          return;
      }
      var nBalance = new Number(document.getElementById("txtBalance").value);
      if (nBalance <=0)
      {
          alert("Amount must be greater than zero");
          return;
      }

      UpdateBuyButton("BB_BuyButtonForm1", "Final Disney Payment", 1, nBalance, "Final Disney Payment");
}


// ------------------------------------------------------------------------
// Code to insert a download button 
// 
// Works for any gallery that has originals enabled
// And right-click protection off
// And gallery is in smugmug or smugmug small view
// ------------------------------------------------------------------------

function IsAnySmugmugView()
{
    return(YD.hasClass(document.body, "smugmug") || YD.hasClass(document.body, "smugmug_small"));
}

function IsGalleryPage()
{
	return(YD.hasClass(document.body, "galleryPage"));
}

onPhotoShow.subscribe(ProcessDownloadButton);

function ProcessDownloadButton()
{
	// set onlyInGalleries to true if you only want a download button in gallery views
	// set onlyInGalleries to false if you want a download button in other views too like (search, keywords, date, etc...)
	var onlyInGalleries = false;
	if (IsAnySmugmugView() && (IsGalleryPage() || !onlyInGalleries))
	{
		if (photoInfo[ImageID].albumOriginals && !photoInfo[ImageID]['protected'] && (photoInfo[ImageID].Format !== "MP4"))
		{
			var downloadParent = "cartButtonsWrapper";
			if (!document.getElementById("cartButtonsWrapper"))
			{
				downloadParent = "altViews";
			}
			InsertDownloadButton(downloadParent);
		}
		else
		{
			// disable the button
			var downloadButton = YAHOO.widget.Button.getButton("downloadButtonId");
			if (downloadButton)
			{
				downloadButton.set("disabled", true);
			}
		}
	}
}

function InsertDownloadButton(parentId)
{
	// now add the download button
	var parentDiv = document.getElementById(parentId);
	var downloadButton = document.getElementById("downloadButtonId");
	if (downloadButton)
	{
		// make sure it is enabled
		YAHOO.widget.Button.getButton("downloadButtonId").set("disabled", false);
	}
	else if (parentDiv)
	{
		var downloadButtonInfo =
		{
			id: "downloadButtonId",
			label: "Download Image...",
			container: parentDiv,
			type: "button",
			className: "sm-button sm-button-small themesButton glyphButton",
			onclick: { fn: InitiateDownloadImage }
		};
		
		var dButtonObj = new YAHOO.widget.Button(downloadButtonInfo);
	}
}

function InitiateDownloadImage()
{
	// construct the download URL
	window.location = "/photos/" + ImageID + "_" + ImageKey + "-D.jpg";
}

/*****************************/
YE.onDOMReady(AddItemsToBuyButton);

function AddItemsToBuyButton()
{
    var buyButton = YAHOO.widget.Button.getButton("buyButton");
    if (buyButton)
    {
        var newBuyItem = { text: "View Merchandise Catalog", url: "http://www.garymorgenphotography.com/Other/Product-Detail/Products-2009/9197146_wfMNH", target: "_blank"};
        buyButton.getMenu().addItem(newBuyItem);
    } 
}