/*********************************************
* Code to support HHSBPA Deposit processing  *
*********************************************/
// Javascript to support dynamic pull downs for HHSBPA Deposits
var optionsNumber = 5;
var depositOptionsUpdated = new Array();

var baseDepositDescrList = new Array(); 
baseDepositDescrList[0] = "Final Payment";
baseDepositDescrList[1] = "Final Payment $25 Additional Fee";
baseDepositDescrList[2] = "Final Payment $10 Additional Fee";
baseDepositDescrList[3] = "Final Payment $5  Additional Fee";
baseDepositDescrList[4] = "Final Payment $1  Additional Fee";

var baseNameList = new Array();
baseNameList[0] = "Final Payment for HHS Nashville Festival";
baseNameList[1] = "Final Payment for HHS Nashville Festival with $25 Additional Fee";
baseNameList[2] = "Final Payment for HHS Nashville Festival with $10 Additional Fee";
baseNameList[3] = "Final Payment for HHS Nashville Festival with $5 Additional Fee";
baseNameList[4] = "Final Payment for HHS Nashville Festival with $1 Additional Fee";
var depositAmntList = new Array(); 
depositAmntList[0] = "225.00";
depositAmntList[1] = "375.00";
//depositAmntList[1] = "550.00";
//depositAmntList[2] = "535.00";
//depositAmntList[3] = "530.00";
//depositAmntList[4] = "526.00";

var scholarshipAmntList = new Array(); 
scholarshipAmntList[0] = "0";
scholarshipAmntList[1] = "25";
scholarshipAmntList[2] = "10";
scholarshipAmntList[3] = "5";
scholarshipAmntList[4] = "1";

function removeOptions(index)
{
	var selectbox = document.forms[index].item_selection_1;
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{		
		selectbox.remove(i);
	}
}

function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function updateAmounts(name, index) {
	//var dom = 'document.forms[' + index + '].';

  	var numberOfKids = document.getElementById('kids_selection').value;  
//alert ("numberofkids: "+numberOfKids);

	var strVolAdd = document.getElementById('VolAdd').value;
//alert ("Voluntary Additional >"+strVolAdd+"<");

	var fFirstDeposit = eval('document.forms[1].chkFirstDeposit.checked');
//alert ("Is First Checked: "+fFirstDeposit);

	var fSecondDeposit = eval('document.forms[1].chkSecond.checked');
// alert ("Is 2nd Checked: "+fSecondDeposit);

	var fMember = eval('document.forms[1].chkBandMember.checked');
//alert ("Is a member: "+fMember);

//	removeOptions(index);
  // Calculate the price owed
	var price = 350;  // Set the base price
	var description = "2nd Payment - 2010 Band Festival";

	/****** Price if membership matters ******/
	// Set the base price / child based on membership and previous payments
	/* if (fMember) {
		price = 225; }
	else {
		price = 375; }
	*/
	
	if (fFirstDeposit == false) { price = price + 150; description = "1st and 2nd Payment - 2010 Band Festival";}
//	if (fSecondDeposit == false) {price = price + 350;}

        price = price * new Number(numberOfKids);
	if (numberOfKids > 1)
	{
		description = description + " ("+numberOfKids+" Students)";
	}

	price = price + new Number(strVolAdd);
	if (strVolAdd > 0)
	{
		description = description + " - Voluntary Additional Payment "+strVolAdd+" - Thank You";
	}
// alert("Setting Button");
	
	UpdateBuyButton('BB_BuyButtonForm',description,1,price,description);	
}


function setHiddenValues(index, price, formIndex, numberOfKids) {	
	var hiddenField = eval("document.forms[" + formIndex + "].item_option_price_" + index);
	hiddenField.value = price;
}

function setHiddenDescription(index, formIndex,strRootText, nKidCount) {
	// alert ("In");
	var hiddenField = eval("document.forms[" + formIndex + "].item_option_description_" + index);
	// alert (hiddenField.value);
	hiddenField.value = strRootText + " ("+nKidCount+" ";
	if (nKidCount == 1) {
	   hiddenField.value = hiddenField.value + "Child)";}
	else {
	   hiddenField.value = hiddenField.value + "Children)";
	}	
}

function showValues() {
	for (var i =1; i <= 5; i++) {
		var hiddenField = eval("document.forms[0].item_option_price_" + i);
		alert(hiddenField.value);
	}
}

function loadMyPage () {
      updateAmounts('kids_selection', '1');
}

function NashvilleUpdateQty() {
  var oQty = document.getElementById("NVQTY");
  var strQty = oQty.value;

  // Set the value of the button
  UpdateBuyButton('BB_BuyButtonForm1','*',strQty,'*','*');
}
function DisneyUpdateQty() {
  var oQty = document.getElementById("DSQTY");
  var strQty = oQty.value;

  // Set the value of the button
  UpdateBuyButton('BB_BuyButtonFormDS','*',strQty,'*','*');
}


/********************* End of HHSBPA Processing Code *************************/

/***************************************
*  Remove Pop Up Windows on mouseover  *
***************************************/
function delHover() {
    oLst = YD.getElementsBy(function(el) {return (YD.hasClass(el,'imgBorder') || YD.hasClass(el,'imgBorderOn'))},'img');
    for (i=0; i < oLst.length ; i++) {
        if (oLst[i].title && oLst[i].title != '') oLst[i].title = '';
        if (oLst[i].alt && oLst[i].alt != '') oLst[i].alt = '';
    }
}
YE.onContentReady('bodyWrapper', function() {if (!YD.hasClass(document.body, 'smugmug_ajax')) delHover()});
onPhotoShow.subscribe(function(){YE.onAvailable('mainImage', delHover)});

/***************************************
* Establish right-click warning msg    *
***************************************/
rightClickWarning ="All images are © 2007 - "+ new Date().getFullYear()+" - Gary Morgen Photography and should not be copied without permission.  If you would like to obtain a copy, please contact me by clicking on the inquiry link in the 'About Us' section - Thanks: Gary"

/***************************************
* Put in code to automatically link my *
* referral information to the footer   *
***************************************/
function AddReferralCode()  {
   var footerDiv = YD.get("footer");
   if (footerDiv)  {
     var links = footerDiv.getElementsByTagName("A");
     if (links && (links.length != 0)) {
       var smugLink = links.item(0);
       smugLink.href = "http://www.smugmug.com/?referrer=Vrp4CbqxqgZvc";
     }
  }
}
YE.onAvailable('footer', AddReferralCode);

/****************************************
* Redirect logic                        *
****************************************/

function redirectPath() { 
  re = /((www.)?garymorgenphotography.smugmug.com)/; 
  tmp = window.location.href; 
  if (re.test(tmp)) { 
    tmp = tmp.replace(re, 'www.garymorgenphotography.com'); 
    window.location.href = tmp; 
  } 
}
redirectPath();  

/*****************************************
* Allow left and right arrows to control *
* gallery movement                       *
*****************************************/
YE.addListener(document, "keyup", pageNav);

function pageNav(e) {
  if (!e) 
    e = window.event;

  if (!YD.hasClass(document.body, "galleryPage"))
    return;

  switch (e.keyCode) {
    case 37:
      chk = "&lt;";
      break;

    case 39:
      chk = "&gt;";
      break;

    default:
      return;
  }
  
  oList = YD.getElementsByClassName("nav", "a", YD.get("albumNav_top"));
  for (var i=0; i < oList.length ; i++) {
    if (oList[i].innerHTML == chk) {
      window.location = oList[i].href;
      break;
    }
  }
}

/**************************************
* Get rid of the pesky pipes          *
**************************************/
// Remove Footer Pipes
addEvent(window, "load", rem_pipes);

function rem_pipes () {
   for (var i = 0; i<3; i++) {
      var objElement = document.getElementById("footer")
      if (objElement != null) 
      {
         var str = new String(objElement.innerHTML);
         str = str.replace('|', '')
         objElement.innerHTML = str;
      }
   }
}

/**********************************************
* Functions for Ad Hoc Payment screens        *
*    will only work for these screens as the  *
*    variables are hardcoded.                 *
**********************************************/
function AdHocClearFields() {
//alert("Set Fields");
var oAmt = document.getElementById("Amount");
var oReason = document.getElementById("Reason");
oAmt.value = "0.00";
oReason.value = "";
}

function AdHocUpdateAmount() {
  var oAmt = document.getElementById("Amount");
  var oReason = document.getElementById("Reason");
  var strAmount = oAmt.value;
  var strReason = oReason.value;
  if (new Number(strAmount) > 0 && strReason != "") {
  	// Set the value of the button
  	var oDescr = document.getElementById("item_description_1");
	oDescr.value = strReason;
	var oAmount = document.getElementById("item_price_1");
	oAmount.value = strAmount;

	// Make the button visible
	setElementVisibility("btnPayment",true);
	setElementVisibility("Prompt", false);
  }
  else
  { 
	// Hide the button
	setElementVisibility("btnPayment",false);
	setElementVisibility("Prompt", true);
  }
}



/*************************************************************
*   Slide Show Functions - Modified by GJM to allow multiple *
*   Gallery Display                                          *
*************************************************************/
// Put in slide show functions
function gjmcreateSWF( w, h, params) {
 var args = "";
 for (var i in params) {
     args += i + "=" + params[i] + "&amp;";
 }
// Get the album id from the argument string of theURL (?myID=)
var gjmLoc = document.location;
var gjmAlbumID=gjmLoc.search.substring(6,gjmLoc.search.length);
// set any variables you're interested in setting based on the album ID - you can add conditional logic if you like
args += "AlbumID="+gjmAlbumID+"&amp;";
args += "clickUrl=http://www.garymorgenphotography.com/gallery/"+gjmAlbumID+"&amp;";
// Continue on with the rest of the Shizam code...
 document.writeln('<object width="100%" height="100%" align="middle">'+
'<param name="movie" value="http://www.smugmug.com/ria/ShizamSlides-2007091201.swf?'+args+'"/>'+
'<param name="wmode" value="transparent" />'+
'<embed src="http://www.smugmug.com/ria/ShizamSlides-2007091201.swf?'+args+'" wmode="transparent" width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" allowScriptAccess="always" allowNetworking="all"/></object>');
return 1;
}

// Open the slide show window... Replace the gallery with the screenshow gallery you create
function gjmOpenSlideShow() {
// This AlbumID is a standard Smugmug variable - We're building a URL with the parameter of the calling AlbumID - 3761240 is my reusable gallery with the call to the slideshow
var gjmDummy = "http://www.garymorgenphotography.com/gallery/3761240?myID="+AlbumID;
location.href = gjmDummy;
}

/******************** End Slideshow Code ****************************************/

/******************************
* Some nice functions         *
******************************/

/***************************************
* Toggle a display object's visibility *
***************************************/
function swapElementVisibility(elementID,btnID,strShow, strHide) {
 var swapButton= document.getElementById(btnID);
 var element = document.getElementById(elementID);
	if (element.style.visibility == "visible") {
		element.style.display ="none";
		swapButton.value= strShow;
                setElementVisibility(elementID,false);
	} else {
		element.style.display ="block";
		swapButton.value = strHide;
                setElementVisibility(elementID,true);
	}
}
function setElementVisibility(elementID, condition) {
       var element = document.getElementById(elementID);
       if (condition == false) {
         element.style.visibility ="hidden";
         element.style.display = "none";
       } else {
         element.style.visibility ="visible";
         element.style.display = "block";
       }
}
/**********************************************
* Check a string to see if it's a valid Email *
**********************************************/
function IsValidEmail(s) 
{
	var patrn=/^([0-9a-zA-Z]([-.\w\+]*[0-9a-zA-Z_-])*@([0-9a-zA-Z][-.\w]*\.)+[a-zA-Z]{2,9})$/;
	return patrn.test(s);
}
/******************************************************************************
* UpdateBuyButton:           						      *
*	Dynamically updates the inner variables of a Google Buy Now Button    *
*	Parms:								      *
*		strFormID: The form ID of the Google Button (Required)	      *
*		Optional Parms - Use '*' to indicate no change		      *
*		strDesc: Item Description				      *
*		strQty:  Quantity of Item to be set			      *
*		strPrice: Price of the item				      *
*		strProdName: Name of the product			      *
******************************************************************************/
function UpdateBuyButton(strFormID, strDesc, strQty, strPrice, strProdName) {
   // Set the values of the button
   // 
  if (strFormID != "") // FormID is required...we ignore this if it isn't there
  {	
	if (strDesc != "*")
	{
		var oItemDesc  = document.forms[strFormID].item_description_1;
		oItemDesc.value = strDesc;
	}
	if (strQty != "*")
	{
		var oItemQty  = document.forms[strFormID].item_quantity_1;
		oItemQty.value = strQty;
	}
	if (strPrice != "*")
	{
		var oItemPrice  = document.forms[strFormID].item_price_1;
		oItemPrice.value = strPrice;
	}
	if (strProdName != "*")
	{
		var oItemName  = document.forms[strFormID].item_name_1;
		oItemName.value = strProdName;
	}
  }
}

/************ IS this a valid number? **********/
function isValidNumber(inpString) {
   return /^[-+]?\d+(\.\d+)?$/.test(inpString);
}

 

