// JavaScript Document
/////////////////////////////////////////////////////////////////////////////////////////////////// PRELOAD IMAGES
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
MM_preloadImages("images/category_bkgnd_ov_long.gif");


/// REMOVE SPECIAL CHARACTERS
function filterCharText(str) {
			 var holdString = str.replace("&", "and");
			 var holdStringCont = holdString.replace("™", " TM");
          re = /\$|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\"|\<|\>|\?|\||\\|\!|\$|\./g;
          // remove special characters like "$" and "," etc...
          return holdStringCont.replace(re, "");
}

/////////// START WINDOW ADD EVENT
window.addEvent("domready", function() {

//$$("body").each(function(container){
//});

//////////////////////////////////////////////////////////////////////////////////////////////////// DEFINE CONTAINERS
hidediv("enlargeBox");

var enlargeBoxSwitch = new Fx.Styles($("enlargeBox"), {duration: 300, wait:false});
enlargeBoxSwitch.set({"opacity": 1});

/////////////////////////////////////////////////////////////////////////////////////////////////// TOOL TIPS

var toolTips = new Tips($$(".Tip"), {
	initialize:function(){
		this.fx = new Fx.Style(this.toolTip, "opacity", {duration: 100, wait: false}).set(0);
	},
	onShow: function(toolTip) {
		this.fx.start(1);
	},
	onHide: function(toolTip) {
		this.fx.start(0);
	}

});

var toolTips = new Tips($$(".liteTip"), {
	className: "liteTip",
	//fixed: true,
	initialize:function(){
		this.fx = new Fx.Style(this.toolTip, "opacity", {duration: 600, wait: false}).set(0);
	},
	onShow: function(toolTip) {
		this.fx.start(1);
	},
	onHide: function(toolTip) {
		this.fx.start(0);
	}

});

/////////////////////////////////////////////////////////////////////////////////////////////////// DRAG

var dragContainer = $("body");
new Drag.Move("enlargeBox", {"container": dragContainer});


/////////////////////////////////////////////////////////////////////////////////////////////////// PAGE BUTTONS
$$(".itemContainer").addEvent("mouseover", function(e){
	e = new Event(e);
	e.stop();
	var varDATA = this.getProperty("keyID");
	$$(".rolloverTexture"+varDATA).setStyle('background-image', 'url(images/rolloverTexture.gif)');
});
$$(".itemContainer").addEvent("mouseout", function(e){
	e = new Event(e);
	e.stop();
	var varDATA = this.getProperty("keyID");
	$$(".rolloverTexture"+varDATA).setStyle('background-image', 'url(images/category_bkgnd.gif)');
});

$("magnifierFeatured").addEvent("click", function(e){
	e = new Event(e);
	e.stop();
	var varDATA = $("magnifierFeatured").getProperty("varDATA");
	var enlargeURL = "insert_enlargeItem.php?varDATA="+varDATA;
	var enlargeContainer = "enlargeArea";
	mooInsert(enlargeURL, enlargeContainer);
	
	//enlargeBoxSwitch.start({"opacity": 1});
	showdiv("enlargeBox");
});
$("addToCartFeatured").addEvent("click", function(e){
	e = new Event(e);
	e.stop();
	var varDATA = this.getProperty("varDATA");
	scrollTop();
	var enlargeURL = "insert_cart_qty.php?itemno="+varDATA;
	var enlargeContainer = "columnRight";
	mooInsert(enlargeURL, enlargeContainer);
});

$("buttonEnlargeBox").addEvent("click", function(e){
	e = new Event(e);
	e.stop();
	
	//enlargeBoxSwitch.start({"opacity": 0});
	hidediv("enlargeBox");
});

$$(".itemMagnifierOverlay").addEvent("click", function(e){
	e = new Event(e);
	e.stop();
	var varDATA = this.getProperty("varDATA");
	var positionDATA = ""+this.getProperty("positionDATA")+"px";
	var enlargeURL = "insert_enlargeItem.php?varDATA="+varDATA;
	var enlargeContainer = "enlargeArea";
	mooInsert(enlargeURL, enlargeContainer);
	
	//enlargeBoxSwitch.start({"opacity": 1});
	$('enlargeBox').setStyle('top', positionDATA);
	showdiv("enlargeBox");
	
});

$$(".itemImage").addEvent("click", function(e){
	e = new Event(e);
	e.stop();
	var varDATA = this.getProperty("varDATA");
	var positionDATA = ""+this.getProperty("positionDATA")+"px";
	var enlargeURL = "insert_enlargeItem.php?varDATA="+varDATA;
	var enlargeContainer = "enlargeArea";
	mooInsert(enlargeURL, enlargeContainer);
	
	//enlargeBoxSwitch.start({"opacity": 1});
	$('enlargeBox').setStyle('top', positionDATA);
	showdiv("enlargeBox");
});

$$(".itemAddCartOverlay").addEvent("click", function(e){
	e = new Event(e);
	e.stop();
	var varDATA = this.getProperty("varDATA");
	scrollTop();
	var enlargeURL = "insert_cart_qty.php?itemno="+varDATA;
	var enlargeContainer = "columnRight";
	mooInsert(enlargeURL, enlargeContainer);
});

/////////////////////////////////////////////////////////////////////////////////////////////////// FORMS

/////////////// LOGIN SETUP
var loginUserStatus = $("masterContainer").getProperty("loginStatus");
if(loginUserStatus =="no"){

hidediv("customerLoginError");
$("customerLogin").addEvent("submit", function(e) {
	   new Event(e).stop();
		showdiv("customerLoginError");
		var log = $("customerLoginError").empty().addClass("ajax-loading");
		this.send({
					  update: log,
					  onComplete: function() {
					  log.removeClass("ajax-loading");
					  $("customerLogin").reset();
					  var checkRedirectStatus = $("redirect").getProperty("redirectStatus");
					  if (checkRedirectStatus =="yes"){
					  var checkRedirect = $("redirect").getProperty("redirectDATA");
					  window.location = checkRedirect;
					  }
	              }
	        });
});
}


/////////// END WINDOW ADD EVENT
});

/////////////////////////////////////////////////////////////////////////////////////////////////// AJAX INSERT
var mooInsert = function(contentDATA, divDATA) {
var url = contentDATA;
new Ajax(url, {method: "get",update: $(divDATA)}).request();
}

/////////////////////////////////////////////////////////////////////////////////////////////////// CART FUNCTIONS

////// ADD ITEM AND SHOW CART
function cartAdd(form) {
var getItemNoSelected = form.itemno.value;
var getQtySelected = form.qty.value;
var getPriceSelected = form.price.value;
var getPage = document.getElementById("navContainer").getAttribute("bookmark");
var getPageCategory = document.getElementById("navContainer").getAttribute("category");
var getPageSubcategory = document.getElementById("navContainer").getAttribute("subcategory");
  if(getQtySelected=="") {
	////// VALIDATE ERROR
	alert("You need to enter a quantity.");
   return false;
  }
  if(getQtySelected+getQtySelected ==0){
	  alert("You need to enter a quantity.");
	return false;
  }
  mooInsert("insert_cart_complete.php?itemno="+getItemNoSelected+"&qty="+getQtySelected+"&price="+getPriceSelected+"&page="+getPage+"&category="+getPageCategory+"&subcategory="+getPageSubcategory,"columnRight");
  return false;
 }


////// GET BILLING INFO FOR ANONOMYOUS
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){   
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){    
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){ 
		    return false
		 }
		 if (str.indexOf(" ")!=-1){ 
		    return false
		 }
 		 return true					
	}
function cartBilling(form) {
var getFirstName = form.firstName.value;
var getLastName = form.lastName.value;
var getAddress = form.address.value;
var getCity = form.city.value;
var getState = form.state.value;
var getZip = form.zip.value;
var getEmail = form.email.value;
var getPhone = form.phone.value;
var getPage = document.getElementById("navContainer").getAttribute("bookmark");
var getPageCategory = document.getElementById("navContainer").getAttribute("category");
var getPageSubcategory = document.getElementById("navContainer").getAttribute("subcategory");
  if(getFirstName=="" || getLastName=="" || getAddress=="" || getCity=="" || getState=="" || getZip=="" || getEmail=="" || getPhone=="") {
	////// VALIDATE ERROR
	alert("Please complete the entire form.");
   return false;
  }
  var emailID=getEmail;
	if ((emailID==null)||(emailID=="")){
		alert("Please enter a valid email address.");
		return false
	}
	if (echeck(emailID)==false){
		alert("Please enter a valid email address.");
		return false
	}
  mooInsert("insert_cart_shipping.php?firstName="+getFirstName+"&lastName="+getLastName+"&address="+getAddress+"&city="+getCity+"&state="+getState+"&zip="+getZip+"&email="+getEmail+"&phone="+getPhone+"&loginStatus=no"+"&page="+getPage+"&category="+getPageCategory+"&subcategory="+getPageSubcategory,"columnRight");
  return false;
}

////// DETERMINE SHIP TO
function cartShipping(form) {
var getShippingLocation = form.shippingLocation.value;
var getFirstName = form.firstName.value;
var getLastName = form.lastName.value;
var getAddress = form.address.value;
var getCity = form.city.value;
var getState = form.state.value;
var getZip = form.zip.value;
var getEmail = form.email.value;
var getPhone = form.phone.value;
var getPage = document.getElementById("navContainer").getAttribute("bookmark");
var getPageCategory = document.getElementById("navContainer").getAttribute("category");
var getPageSubcategory = document.getElementById("navContainer").getAttribute("subcategory");
if(getShippingLocation=="no") {
	////// NEED TO GET SHIPPING INFO
	 mooInsert("insert_cart_shippingAlternate.php?firstName="+getFirstName+"&lastName="+getLastName+"&address="+getAddress+"&city="+getCity+"&state="+getState+"&zip="+getZip+"&email="+getEmail+"&phone="+getPhone+"&loginStatus=no"+"&page="+getPage+"&category="+getPageCategory+"&subcategory="+getPageSubcategory,"columnRight");
   return false;
  }
  /////// COMPLETE THE ORDER
  mooInsert("insert_cart_completeOrder.php?firstName="+getFirstName+"&lastName="+getLastName+"&address="+getAddress+"&city="+getCity+"&state="+getState+"&zip="+getZip+"&email="+getEmail+"&phone="+getPhone+"&loginStatus=no"+"&shipping=match&trigger=off&page="+getPage+"&category="+getPageCategory+"&subcategory="+getPageSubcategory,"columnRight");
  return false;
 }
 
 
 ////// ALTERNATE SHIPPING INFO
function cartShippingAlternate(form) {
var getAttentionTo = form.attentionTo.value;
var getShipAddress = form.shipAddress.value;
var getShipCity = form.shipCity.value;
var getShipState = form.shipState.value;
var getShipZip = form.shipZip.value;
var getFirstName = form.firstName.value;
var getLastName = form.lastName.value;
var getAddress = form.address.value;
var getCity = form.city.value;
var getState = form.state.value;
var getZip = form.zip.value;
var getEmail = form.email.value;
var getPhone = form.phone.value;
var getPage = document.getElementById("navContainer").getAttribute("bookmark");
var getPageCategory = document.getElementById("navContainer").getAttribute("category");
var getPageSubcategory = document.getElementById("navContainer").getAttribute("subcategory");
if(getAttentionTo=="" || getShipAddress=="" || getShipCity=="" || getShipState=="" || getShipZip=="") {
	////// VALIDATE ERROR
	alert("Please complete the entire form.");
   return false;
  }
  /////// COMPLETE THE ORDER
  mooInsert("insert_cart_completeOrder.php?attentionTo="+getAttentionTo+"&shipAddress="+getShipAddress+"&shipCity="+getShipCity+"&shipState="+getShipState+"&shipZip="+getShipZip+"&firstName="+getFirstName+"&lastName="+getLastName+"&address="+getAddress+"&city="+getCity+"&state="+getState+"&zip="+getZip+"&email="+getEmail+"&phone="+getPhone+"&shipping=alt&trigger=off&page="+getPage+"&category="+getPageCategory+"&subcategory="+getPageSubcategory,"columnRight");
  return false;
 }
 
  ////// ALTERNATE SHIPPING INFO
function cartSendOrder(form) {
var getTrigger = form.sendTrigger.value;
var getShipping = form.shipping.value;
if(getShipping =="alt"){
var getAttentionTo = form.attentionTo.value;
var getShipAddress = form.shipAddress.value;
var getShipCity = form.shipCity.value;
var getShipState = form.shipState.value;
var getShipZip = form.shipZip.value;
}
if(getShipping =="match"){
var getAttentionTo = "void";
var getShipAddress = "void";
var getShipCity = "void";
var getShipState = "void";
var getShipZip = "void";
}
var getFirstName = form.firstName.value;
var getLastName = form.lastName.value;
var getAddress = form.address.value;
var getCity = form.city.value;
var getState = form.state.value;
var getZip = form.zip.value;
var getEmail = form.email.value;
var getPhone = form.phone.value;
var getPage = document.getElementById("navContainer").getAttribute("bookmark");
var getPageCategory = document.getElementById("navContainer").getAttribute("category");
var getPageSubcategory = document.getElementById("navContainer").getAttribute("subcategory");
if(getAttentionTo=="" || getShipAddress=="" || getShipCity=="" || getShipState=="" || getShipZip=="") {
	////// VALIDATE ERROR
	alert("There was a problem sending your order. Please try again.");
   return false;
  }
  /////// COMPLETE THE ORDER
  mooInsert("insert_cart_completeOrder.php?attentionTo="+getAttentionTo+"&shipAddress="+getShipAddress+"&shipCity="+getShipCity+"&shipState="+getShipState+"&shipZip="+getShipZip+"&firstName="+getFirstName+"&lastName="+getLastName+"&address="+getAddress+"&city="+getCity+"&state="+getState+"&zip="+getZip+"&email="+getEmail+"&phone="+getPhone+"&shipping="+getShipping+"&trigger="+getTrigger+"&page="+getPage+"&category="+getPageCategory+"&subcategory="+getPageSubcategory,"columnRight");
  return false;
 }
 
 ///////////////////////// REGISTER
function userRegister(form) {
var getFirstName = form.firstName.value;
var getLastName = form.lastName.value;
var getAddress = form.address.value;
var getCity = form.city.value;
var getState = form.state.value;
var getZip = form.zip.value;
var getEmail = form.email.value;
var getPhone = form.phone.value;
var getPassword = form.password.value;
var getPasswordVerify = form.passwordVerify.value;
var getPage = document.getElementById("navContainer").getAttribute("bookmark");
var getPageCategory = document.getElementById("navContainer").getAttribute("category");
var getPageSubcategory = document.getElementById("navContainer").getAttribute("subcategory");
  if(getFirstName=="" || getLastName=="" || getAddress=="" || getCity=="" || getState=="" || getZip=="" || getEmail=="" || getPhone=="" || getPassword=="" || getPasswordVerify=="") {
	////// VALIDATE ERROR
	alert("Please complete the entire form.");
   return false;
  }
  var emailID=getEmail;
	if ((emailID==null)||(emailID=="")){
		alert("Please enter a valid email address.");
		return false
	}
	if (echeck(emailID)==false){
		alert("Please enter a valid email address.");
		return false
	}
	if (getPassword != getPasswordVerify){
  alert("Password does not match.");
  return false;
  }
  mooInsert("insert_register.php?firstName="+getFirstName+"&lastName="+getLastName+"&address="+getAddress+"&city="+getCity+"&state="+getState+"&zip="+getZip+"&email="+getEmail+"&phone="+getPhone+"&password="+getPassword+"&trigger=go&loginStatus=no"+"&page="+getPage+"&category="+getPageCategory+"&subcategory="+getPageSubcategory,"columnRight");
  return false;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ADMIN
function uploadReady() {
	var input = document.getElementById("photoupload-filedata-1");
	var uplooad = new FancyUpload(input, {
	swf: "upload/Swiff.Uploader.swf",
	queueList: "photoupload-queue",
	container: $E("h1")
	});
}

function adminNewSubCategory(form) {
var getTitle = filterCharText(form.title.value);
var getCategory = form.category.value;
  if(getTitle=="") {
	////// VALIDATE ERROR
	alert("You need to enter a title.");
   return false;
  }
  mooInsert("admin_newSubCategory.php?title="+getTitle+"&category="+getCategory,"adminDashboardContent");
  setTimeout(function(){uploadReady();}, 400);
  return false;
}

function adminNewItemOption(form) {
var getOption = form.optionType.value;
var getPage = form.page.value;
var getMainCategory = form.mainCategory.value;
  if(getOption=="") {
	////// VALIDATE ERROR
	alert("Please choose an option.");
   return false;
  }
  if(getOption == "new"){
  mooInsert("admin_newItemStart.php?category="+getMainCategory+"&page="+getPage,"adminDashboardContent");
  return false;
  }
  if(getOption == "existing"){
  mooInsert("admin_newItemExisting.php?category="+getMainCategory+"&page="+getPage,"adminDashboardContent");
  return false;
  }
}

function adminNewItemExisting(form) {
var existingItem = form.existingItem.value;
var getPage = form.page.value;
var getMainCategory = form.mainCategory.value;
  if(existingItem=="") {
	////// VALIDATE ERROR
	alert("Please select an item to add.");
   return false;
  }
  mooInsert("admin_newItemExistingEnd.php?itemno="+existingItem+"&category="+getMainCategory+"&page="+getPage,"adminDashboardContent");
  return false;
}

function adminNewItemDetails(form) {
var getPage = form.page.value;
var getMainCategory = form.mainCategory.value;
var itemno = form.itemno.value;
var price = form.price.value;
var title = filterCharText(form.title.value);
var details = form.details.value;
  if(itemno=="" || price=="$" || price=="" || title=="" || details=="") {
	////// VALIDATE ERROR
	alert("Please complete the entire form.");
   return false;
  }
  mooInsert("admin_newItem.php?page="+getPage+"&category="+getMainCategory+"&itemno="+itemno+"&price="+price+"&title="+title+"&details="+details+"","adminDashboardContent");
  setTimeout(function(){uploadReady();}, 400);
  return false;
}

function adminEditMain(form) {
var getID = form.getID.value;
var itemno = form.itemno.value;
var price = form.price.value;
var title = filterCharText(form.title.value);
var details = form.details.value;
  if(itemno=="" || price=="$" || price=="" || title=="" || details=="") {
	////// VALIDATE ERROR
	alert("Please do not leave any field empty :)");
   return false;
  }
  mooInsert("admin_editItemEnd.php?itemno="+itemno+"&price="+price+"&title="+title+"&details="+details+"+&id="+getID,"adminDashboardContent");
  setTimeout(function(){uploadReady();}, 400);
  return false;
}

function adminEditItemStart(form) {
var getOption = form.optionType.value;
var getItemno = form.itemno.value;
  if(getOption=="") {
	////// VALIDATE ERROR
	alert("Please choose an option.");
   return false;
  }
  if(getOption == "info"){
  mooInsert("admin_editItemInfo.php?itemno="+getItemno,"adminDashboardContent");
  return false;
  }
  if(getOption == "photo"){
  mooInsert("admin_editItemPhoto.php?itemno="+getItemno,"adminDashboardContent");
  setTimeout(function(){uploadReady();}, 400);
  return false;
  }
}

function adminDeleteItemStart(form) {
var getOption = form.optionType.value;
var getItemno = form.itemno.value;
var getPage = form.page.value;
var getMainCategory = form.mainCategory.value;
  if(getOption=="") {
	////// VALIDATE ERROR
	alert("Please select yes or no.");
   return false;
  }
  if(getOption == "no"){
  mooInsert("admin_deleteCancel.php","adminDashboardContent");
  return false;
  }
  if(getOption == "yes"){
  mooInsert("admin_deleteItemEnd.php?page="+getPage+"&category="+getMainCategory+"&itemno="+getItemno,"adminDashboardContent");
  return false;
  }
}

///////////////////////// FEATURED ITEM SETTINGS
function featuredSwitchControl(form) {
var getOption = form.optionType.value;
  if(getOption=="") {
	////// VALIDATE ERROR
	alert("Please choose an option.");
   return false;
  }
  if(getOption == "random"){
  mooInsert("admin_featuredItemRandom.php","adminDashboardContent");
  return false;
  }
  if(getOption == "select"){
  mooInsert("admin_featuredItemSelect.php","adminDashboardContent");
  return false;
  }
}
function adminFeaturedSelect(form) {
var getOption = form.itemno.value;
var getDetails = filterCharText(form.details.value);
  if(getOption=="") {
	////// VALIDATE ERROR
	alert("Please choose an item.");
   return false;
  }
  if(getDetails=="") {
	////// VALIDATE ERROR
	alert("Please enter details and information for the item such as shipping, brass stand prices or other extras that are available.");
   return false;
  }
  mooInsert("admin_featuredItemSelectEnd.php?itemno="+getOption+"&details="+getDetails,"adminDashboardContent");
  return false;
}

///////////////////////// ADD NEW ENTRY TO SECTION EXCLUSIVES OR APPEARANCES
function adminSectionAddEntry(form) {
var getOption = form.optionType.value;
var getTheDate = form.theDate.value;
var getTitle = form.title.value;
var getDetails = form.details.value;
var getSection = form.section.value;
  if(getTheDate=="" || getTitle=="" || getDetails=="") {
	////// VALIDATE ERROR
	alert("Please complete the entire form.");
   return false;
  }
  if(getOption == ""){
  alert("You need to select whether or not you want to include a photo.");
  return false;
  }
  if(getOption == "y"){
  mooInsert("admin_newEntrySectionPhoto.php?section="+getSection+"&date="+getTheDate+"&title="+getTitle+"&details="+getDetails,"adminDashboardContent");
  setTimeout(function(){uploadReady();}, 400);
  return false;
  }
  if(getOption == "n"){
  mooInsert("admin_newEntrySectionEnd.php?section="+getSection+"&date="+getTheDate+"&title="+getTitle+"&details="+getDetails,"adminDashboardContent");
  return false;
  }
}

///////////////////////// ADD NEW ENTRY TO SCRAPBOOK
function adminScrapbookAddEntry(form) {
var getTheDate = form.theDate.value;
var getTitle = form.title.value;
var getDetails = form.details.value;
var getLink = form.theLink.value;
var getSection = form.section.value;
  if(getTheDate=="" || getTitle=="" || getDetails=="") {
	////// VALIDATE ERROR
	alert("Please complete the form. Every entry is required except for the Link.");
   return false;
  }
  mooInsert("admin_newEntrySectionEnd.php?section="+getSection+"&date="+getTheDate+"&title="+getTitle+"&details="+getDetails+"&link="+getLink+"","adminDashboardContent");
  return false;
}
///////////////////////// DELETE SECTION ENTRY
function adminDeleteSectionEnd(form) {
var getOption = form.optionType.value;
var getID = form.dataID.value;
var getSection = form.section.value;
  if(getOption=="") {
	////// VALIDATE ERROR
	alert("Please select yes or no.");
   return false;
  }
  if(getOption == "no"){
  mooInsert("admin_deleteCancel.php","adminDashboardContent");
  return false;
  }
  if(getOption == "yes"){
  mooInsert("admin_deleteSectionEnd.php?section="+getSection+"&dataID="+getID,"adminDashboardContent");
  return false;
  }
}
///////////////////////// FORGOT PASSWORD
function forgotPassword(form) {
var getEmail = form.email.value;
  if(getEmail=="") {
	////// VALIDATE ERROR
	alert("Please enter your email address. Thank you.");
   return false;
  }
  mooInsert("customer_retrievePassword.php?email="+getEmail+"","columnRight");
  return false;
}
