// Prep the emailForm email field for signing up for Emails
var emailCleared = 0;
function prepareEmailForm(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm")) return false;
	var el = document.getElementById("email");
	el.onfocus = function(){
		if(emailCleared==0)	{
			el.value = "";
			emailCleared = 1;
		}
	}
	el.onblur = function(){
		if(el.value == "") {
			el.value = "Email";
			emailCleared = 0;
		}
	}
}
addLoadEvent(prepareEmailForm);
var email2Cleared = 0;
function prepareEmail2Form(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm2")) return false;
	var el = document.getElementById("email2");
	el.onfocus = function(){
		if(email2Cleared==0) {
			el.value = "";
			email2Cleared = 1;
		}
	}
	el.onblur = function(){
		if(el.value == "") {
			el.value = "Email";
			email2Cleared = 0;
		}
	}
}
addLoadEvent(prepareEmail2Form);

function prepareEmailSubmit(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm")) return false;
	var el = document.getElementById("emailSubmit");
	el.onclick = function(){
		document.getElementById("emailForm").submit();
		return false;
	}
}
addLoadEvent(prepareEmailSubmit);

function prepareEmail2Submit(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm2")) return false;
	var el = document.getElementById("email2Submit");
	el.onclick = function(){
		document.getElementById("emailForm2").submit();
		return false;
	}
}
addLoadEvent(prepareEmail2Submit);

//Submit order on checkout
function submitOrder() {
	if (!document.getElementById) return false;
	if (!document.getElementById("submitLinkWrapper")) return false;
	if (!document.getElementById("submitLink")) return false;
	var link=document.getElementById("submitLink");
	link.onclick=function(){
		document.getElementById("submitLinkWrapper").innerHTML="<span>Processing Order...</span>";
		document.shop3.submit();
	}
}
addLoadEvent(submitOrder);


// Clear the Search field
var searchCleared = 0;
function prepareSearchForm(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("searchForm")) return false;
	var el = document.getElementById("search");
	el.onfocus = function(){
		if(searchCleared==0)	el.value = "";
		searchCleared = 1;
	}
	el.onblur = function(){
		if(el.value == "") el.value = "Search";
		searchCleared = 0;
	}
}
addLoadEvent(prepareSearchForm);

// Adds functions to onload event
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Setup Enter/Return to trigger function in Shop's pagination
function shopPagination(){
	if (!document.getElementsByTagName) return false;
	var el = document.getElementsByTagName("input");
	for(i=0; i<el.length; i++){
		if(el[i].className == "pageOf"){
			el[i].onkeypress = function(e){
				var evt = (e) ? e : window.event;
				if(evt.keyCode==13){
					jumpToPage(this.name)
				}
			}
		}
	}
}
addLoadEvent(shopPagination);










// !!!!!!!!! DISABLED AND REPLACED WITH LIGHTBOX 2 !!!!!!!!!!!!!!!
// Preps the photos on Scene@23 section for launching popup window
/*function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("imagegallery")) return false;
  var gallery = document.getElementById("imagegallery");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
	}
    links[i].onkeypress = links[i].onclick;
  }
}
//addLoadEvent(prepareGallery);
// Launches largeImage page for Scene@23 section
function showPic(whichpic) {
  var source = whichpic.getAttribute("href");
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  window.open('joannesEye_gallery_largeImage.cfm?img='+source+'&title='+text,'sceneAt','width=670,height=630,location=0,toolbars=0')
  return false;
}*/
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

