/*
===================================
SET ENVIRONMENTAL VARIABLES
===================================
*/




/* -- FEATURE DETECTION -- */

var hallPass = true;

if (!document.addEventListener) {
	hallPass = false;
//confirm("listener");
	}

if (!window.localStorage) {
	hallPass = false;
//confirm("storage");
	}

// TEST FOR IE AND IE 9
var uaString = navigator.userAgent;
var ieBrowser = /MSIE/;
var ieValVersion = /MSIE 9/;
var googleBot = /Google/i;

if (ieBrowser.test(uaString)) {

	// send all IE to old site for now
	//	location.href = "http://www.stantonpark.com/cgi-bin/spv5loader.cgi?0";

	// IS IT LESS THAN IE8?
	if (!ieValVersion.test(uaString)) {

		// less than IE9
		hallPass = false;

		} else {

		// IE9  -- stay on this site
		hallPass = true;
		}


	}

// ALLOW GOOGLE AND BOTS IN
if (googleBot.test(uaString)) {
	hallPass = true;
	}


// IF BRWOSER < IE9, THEN GO TO OLD PAGE
if (hallPass == false) {

﻿	// SET COOKIE FOR OLD BROWSERS
	﻿expireDate = new Date;
	expireDate.setDate(expireDate.getDate()+1);
	document.cookie = "hallPass=false;expires="+expireDate.toGMTString()+";path=﻿/cgi-bin";


	location.href = "http://www.stantonpark.com/cgi-bin/spv5loader.cgi?0";
	}




/* -- SET GLOBAL VARS -- */

var thePath = "";
var dirPath = new Array();
var i = 0;
dirPath = document.location.pathname.split("/");


/* SET THE COPYRIGHT DATE */

var theDate = new Date();
var theYear = theDate.getFullYear();
var theCopyright = "&copy " + theYear + " STANTON PARK RECORDS";


/* -- IF THERE IS A PATH AFTER THE DOMAIN, SET IT UP -- */

for (i=0; i<dirPath.length; i++){

	// STOP WHEN WE GET TO THE CGI DIR
	if (dirPath[i] == "cgi-bin") {
		break;
		}

	// DONT INCLUDE BLANK PATHS
	if (dirPath[i] != "") {
		thePath += dirPath[i] + "/";
		}
	}


/* -- SET THE BASE PATH -- */
var basePath = "http://" + document.location.hostname + "/" + thePath;

/* -- CHECK FOR THE PRINT FILE - DOESN'T GET THE EVENTS -- */
var checkFile = dirPath[dirPath.length-1];



/* -- GLOBAL ON LOAD SCRIPTS -- */
if(document.addEventListener && checkFile != "print.html"){
	window.addEventListener("DOMContentLoaded",onLoadScripts,false);
	window.addEventListener("DOMContentLoaded",attachEvts,false);
	window.addEventListener("DOMContentLoaded",extraEvt,false);
	} else if (checkFile != "print.html") {

	// IF BROWSER CAN'T HANDLE EVENT REGISTRATION SEND TO THE OLDER PAGE
	location.href="http://www.stantonpark.com/cgi-bin/spv5loader.cgi?0";
	}


/* -- GENRE SUBCATEGORIES -- */
var genreType = {
	"" : "All Categories",
	"A" : "Alternative/Indie",
	"B" : "Boston Area",
	"G" : "Garage/Psych",
	"P" : "Punk",
	"S" : "Sixties Garage/Rock"
	}


/* -- EXPAND THE MEDIA TYPE FROM THE DB CODE -- */
var mediaType = {
	""	: "All Formats",
	"45" : "Singles",
	"LP" : "LPs &amp; EPs",
	"CD" : "Compact Discs",
	"MG" : "Magazines"
	};










/*
===================================
STORAGE SCRIPTS
===================================
*/



/* -- LOAD CART DETAIL INFO FROM LOCAL STORAGE -- */
function fetchCartDetails () {
	var cartItems = window.localStorage.itemList;
	document.getElementById('cart-detail').innerHTML = cartItems;
/* 	document.getElementById('cart-items').style.display = "block"; */
	}




/* -- GET DETAILED BROWSER STATS -- */

function getBrowserStats() {

	var x = navigator;
	var userAgent = x.userAgent;

	var iconPath = "resources/gifs/icons/";

	var wkEngine = /webkit/i;
	var mozEngine = /firefox/i;
	var opEngine = /opera/i;
	var mozEngine = /firefox/i;
	var tridentEng = /MSIE/;


	// IF MOZILLA
	if (mozEngine.test(userAgent)) {
		var browserInfo = userAgent.match(/Firefox\/[0-9b\.]*$/);		// b is included in the regex to allow for Betas
		browserInfo = browserInfo.toString();	// convert to string
		var browserParts = new Array();
		browserParts = browserInfo.split("/");

		var browserName = browserParts[0].toLowerCase();
		var theVersion = browserParts[1];

		document.getElementById('browser').src = iconPath + browserName + "-64.png";
		document.getElementById('browser').alt = browserName;

		var theStats = browserParts[0].toUpperCase() + "<br />" + browserParts[1];
		document.getElementById('stats').innerHTML = theStats;
		}

	//IF WEBKIT
	if (wkEngine.test(userAgent)) {

		// ARE WE USING CHROME OR SAFARI
		if (userAgent.match(/Chrome\/[0-9\.]*/)) {

			var browserInfo = userAgent.match(/Chrome\/[0-9\.]*/);

			} else if (userAgent.match(/Version\/[0-9\.]* Safari\/[0-9\.]*$/)) {

			var browserInfo = userAgent.match(/Safari\/[0-9\.]*$/);
			var getVersion = x.appVersion.match(/ Version\/[0-9\.]* /);
			getVersion = getVersion.toString();
			var theVersion = getVersion.replace("Version/","");
			theVersion = theVersion.replace(/ /g, "");
			}


		// PARSE THE DATA TO PREP FOR SCREEN DISPLAY
		browserInfo = browserInfo.toString();	// convert to string
		var browserParts = new Array();
		browserParts = browserInfo.split("/");

		var browserName = browserParts[0].toLowerCase();

		document.getElementById('browser').src = iconPath + browserName + "-64.png";
		document.getElementById('browser').alt = browserName;

		var theStats = browserParts[0].toUpperCase() + "<br />" + theVersion;
		document.getElementById('stats').innerHTML = theStats;
		}

	//IF OPERA
	if (opEngine.test(userAgent)) {

		//Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.5.24 Version/10.53

		var browserInfo = userAgent.match(/^Opera\/[0-9\.]*/);

		browserInfo = browserInfo.toString();	// convert to string
		var browserParts = new Array();
		browserParts = browserInfo.split("/");

		var browserName = browserParts[0].toLowerCase();

		document.getElementById('browser').src = iconPath + browserName + "-64.png";
		document.getElementById('browser').alt = browserName;

		var theStats = browserParts[0].toUpperCase() + "<br />" + browserParts[1];
		document.getElementById('stats').innerHTML = theStats;
		}


	// IF IE9
	if (tridentEng.test(userAgent))	{

		// Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)

		var browserInfo = userAgent.match(/MSIE 9/);
		browserInfo = browserInfo.toString();	// convert to string
		var browserParts = new Array();
		browserParts = browserInfo.split(" ");

		var browserName = browserInfo.replace("MSIE 9", "ie9");

		document.getElementById('browser').src = iconPath + browserName + "-64.png";
		document.getElementById('browser').alt = browserName;

		var theStats = browserParts[0].toUpperCase() + "<br />" + browserParts[1];
		document.getElementById('stats').innerHTML = theStats;


		}



	}




/* -- INITIALIZE STORAGE -- */

function initializeStorage(){

	// CLEAR LOCAL STORAGE IN CASE IT EXISTS FROM LAST VISIT  -- ONLY HAPPENS IF THERE'S A NEW COOKIE
	window.localStorage.clear();

	// SHOPPING CART
	window.localStorage.cartItems = 0;
	window.localStorage.cartTotals = 0;
	window.localStorage.itemList = "";

	// ORDER STATUS
	window.localStorage.ordSummary = "";
	window.localStorage.ordShipStatus = "pending";
	window.localStorage.ordPayStatus = "pending";
	window.localStorage.orderStatus = "";

	// HINTS LISTS
	window.localStorage.bands = "";
	window.localStorage.records = "";

	// LIST DATA -- PREFORMATTED LISTS BY FORMAT
	window.localStorage.catalog = "";

	// ADVANCED SEARCH/LIST
	window.localStorage.searchBand = "";
	window.localStorage.searchRecord = "";
	window.localStorage.searchLabel = "";
	window.localStorage.searchFormat = "";
	window.localStorage.searchGenre = "";
	window.localStorage.filterFormat = "";
	window.localStorage.filterGenre = "";
	window.localStorage.filterLabel = "";
	window.localStorage.totalFound = "";
	window.localStorage.searchType = "";
	window.localStorage.startAt = "";

	// READ SESSION NUMBER FROM COOKIE
	theCookie = document.cookie.split("; ");

	for (i=0; i<theCookie.length; i++) {

		// LOAD THE SESSION COOKIE, AND SET THE FLAG
		if (theCookie[i].split("=")[0] == "session" ) {
			theSession = theCookie[i].split("=")[1];
			}
		}


	//PAGE PREFS
	window.localStorage.fontSize = 1;
	window.localStorage.session = theSession;

	// PAGE HISTORY -- MAINTAIN THE LAST 20 PAGES
	window.localStorage.history = "";

	/* RENDERING ENGINE DETECTION */
	var x = navigator;
	var userAgent = x.userAgent;
	var wkEngine = /webkit/i;
	var mozEngine = /firefox/i;
	var opEngine = /presto/i;
	var tridentEng = /MSIE/;


	// IF THIS IS A WEBKIT BROWSER, SET THE WEBKIT STYLESHEET
	if (userAgent.match(wkEngine)) {
		window.localStorage.render = "webkit";
		}


	// IF THIS IS A MOZILLA BROWSER, SET THE MOZILLA STYLESHEET
	if (userAgent.match(mozEngine)) {
		window.localStorage.render = "mozilla";
		}


	// IF THIS IS OPERA SET THE OPERA STYLESHEET
	if (userAgent.match(opEngine)) {
		window.localStorage.render = "presto";
		}

	// IF THIS IS IE9 SET THE IE9 STYLESHEET
	if (userAgent.match(tridentEng)) {
		window.localStorage.render = "trident";
		}


	// LOAD INFO INTO DATABASE FOR LISTS/SEARCHES
	initListData();
	}




/* -- INITIALIZE STORAGE FOR LISTS/ADVANCED SEARCH  -- */

function initListData() {

	// DOES THE CATALOG STORAGE ITEM EXIST?
	if (!window.localStorage.catalog) {
		window.localStorage.catalog = "";
		}

	// IS DATA LOADED
	if (window.localStorage.catalog == "" || window.localStorage.catalog == "undefined") {
		runExternal("list", "all");
		}

	// ARE THE HINT LISTS LOADED?
	if (window.localStorage.bands == "" || window.localStorage.bands == "undefined") {
		runExternal("list", "bandlist");
		runExternal("list", "recordlist");
		}

	}




/* -- UPDATE SHOPPING CART -- ITEM ADDED -- */

function updateCart(returnInfo, cartOrder) {
	var returnInfo = returnInfo;
	var retInfo = new Array();
	var cartOrder = cartOrder;
	var cartUpdates = new Array();

	var currentCartItems = 0;
	var currentCartTotals = 0;
	var currentCartList = "";

	var newCartItems = 0;
	var newCartTotals = 0;
	var newCartList = "";

	var extPrice = 0;


	retInfo = returnInfo.split(":-:");

	// SPLIT THE INFO INTO VARIABLES
	ordQty = retInfo[0];
	ordBand = retInfo[1];
	ordRecord = retInfo[2];
	ordPrice = retInfo[3];
	ordMessage = "<span>" + retInfo[4] + "</span>";


	// LOAD CART INFO
	currentCartItems = window.localStorage.cartItems;
	currentCartTotals = window.localStorage.cartTotals;
	currentCartList = window.localStorage.itemList;

	// CALCULATE NEW TOTALS
	newCartItems = parseInt(currentCartItems) + parseInt(ordQty);
	extPrice = parseInt(ordQty) * parseFloat(ordPrice);				// get the extended price in case of more than 1 copy
	newCartTotals = parseFloat(currentCartTotals) + parseFloat(extPrice);
	newCartTotals = newCartTotals.toFixed(2);

	//ADD TO THE CART LIST
	var bandRec = ordBand + ": " + ordRecord;
	bandRec = bandRec.substr(0,25);	// only add 25 chars of string
//	bandRec = bandRec.substr(0,30);	// only add 35 chars of string

	newCartList = currentCartList + "<li>" +  bandRec + "&#8230;<span>$" + parseFloat(ordPrice).toFixed(2) + "</span></li>";

	// IF THIS IS A CHANGE IN QUANTITY OF AN EXISTING ITEM, THEN ENTIRE CART IS REPLACED BY cartOrder INFO
	if (cartOrder) {
		cartUpdates = cartOrder.split(":-:");
		newCartItems = cartUpdates[0];
		newCartTotals = cartUpdates[1];
		newCartList = cartUpdates[2];
		}

	// PUT INFO BACK IN LOCAL STORAGE
	window.localStorage.cartItems = newCartItems;
	window.localStorage.cartTotals = newCartTotals;
	window.localStorage.itemList = newCartList;


	// REFRESH THE CART IN SIDEBAR
	if (newCartItems == 1) {
		document.getElementById('cartsum').innerHTML = newCartItems + " item | $" + newCartTotals;
		} else {
		document.getElementById('cartsum').innerHTML = newCartItems + " items | $" + newCartTotals;
		}

	// SEND MESSAGE TO USER
	document.getElementById('notification').innerHTML = ordMessage;
	document.getElementById('notification').className = "show-notification";

	// FADE MESSAGE AFTER SPECIFIED TIME
	var xTime = setTimeout("document.getElementById('notification').className = '';",3000);
	}



/*
=================================================
ONLOAD SCRIPTS -- SET MAJOR PROPERTIES ON PAGE
=================================================
*/

function onLoadScripts (){

	/* SET COPYRIGHT NOTICE IN FOOTER */
	document.getElementById('copyright').innerHTML = theCopyright;

	/* INITIALIZE STORAGE IF IT IS EMPTY */
	if (!window.localStorage.history) {
		initializeStorage();
		}

	/* DETERMINE CURRENT PAGE */
	var theURL = location.href;
	var theTitle = document.title.replace("Stanton Park Records -- ", "");

	// TRUNCATE PAGE NAME IF TOO LONG
	if (theTitle.length > 35) {
		theTitle = (theTitle.substring(0,35)) + "&#8230;";	// add only the first 35 chars
		}

	var thePage = "<a href='" + theURL + "'>" + theTitle + "</a>";

	// RETRIEVE HISTORY
	var pageHistory = window.localStorage.history;

	// ADD CURRENT PAGE
	pageHistory = thePage + ":-:" + pageHistory;  // this adds newest page at top


	//WRITE CURRENT PAGE TO HISTORY
	window.localStorage.history = pageHistory


	/* LOAD THE CART */
	var cartItems = window.localStorage.cartItems;
	if (cartItems == 1) {	// if there is only one item, then cut the "s" off the end
		cartItems += " item | ";
		} else {
		cartItems += " items | ";
		}

	var cartTotals = window.localStorage.cartTotals;
	cartTotals = parseFloat(cartTotals);

	cartTotals = cartTotals.toFixed(2);
	var cartString = cartItems + " $" + cartTotals;
	document.getElementById('cartsum').innerHTML = cartString;


	/* SET DEFAULT FONT SIZE FOR CONTENT -- USE SAVED PREF OR DEFAULT */
	var theSize = window.localStorage.fontSize;

	if (theSize == "") {
		// DEFAULT FONT SIZE
		document.getElementById('main-copy').style.fontSize = "1em";
		} else {
		// SAVED PREF
		document.getElementById('main-copy').style.fontSize = theSize + "em";
		}


	/* SWITCH OUT FONT SLIDER FOR MOZILLA AND IE */
	if (window.localStorage.render == "mozilla" || window.localStorage.render == "trident") {
		document.getElementById('slider').style.display = "none";
		document.getElementById('radio').style.display = "block";

		//SET DEFAULT VALUE OF FONT CHANGE FORM TO SAVED VALUE
		theSize *= 10; // convert value for form
		var theID = "fs" + theSize;
		theID = theID.replace(".", "");
		document.getElementById(theID).checked = true;
		}

	/* SET DEFAULT VALUE OF FONT CHANGE FORM TO SAVED VALUE */
	if (window.localStorage.render == "webkit") {
		theSize *= 10;
		document.getElementById('fontsize').value = theSize;
		}


	/* LOAD EXTENSIONS STYLESHEET */

	// DETERMINE RENDERING ENGINE
	var essName = window.localStorage.render;


	// CREATE OBJECT
	var ess = document.createElement("link");
	ess.type = "text/css";
	ess.rel = "stylesheet";
	ess.href = "resources/css/" + essName + ".css";

	// APPEND STYLESHEET TO HEAD
	document.getElementsByTagName('head')[0].appendChild(ess);

	// CLEAR ACTIVE MAIN SECTION
	var mainSec = document.getElementById('site-sections');
	var mainSecList = new Array();
	mainSecList = mainSec.firstElementChild.children;

	for (i=0; i<5; i++) {
		mainSecList[i].firstChild.className = "";
		}

	// APPLY THE CLASS ACTIVE TO THE CURRENT PAGE BUTTON
	var basePre = basePage.split("-");
	var theBase = basePre[0];

	var baseSection = {"home" : 0, "index" : 0, "browse" : 1, "detail" : 1, "stanton" : 2,"news" : 3,"feature" : 4};
	var currPage = baseSection[theBase];

	// IF THIS PAGE IS PART OF A MAIN SECTION  --  doesn't include overlays (for now)
	if (currPage > -1) {
		mainSecList[currPage].firstChild.className = "active";
		}


	/* SET THE MAIN DIV TO FILL THE BROWSER IN HEIGHT */
	checkHeight();
	}




/*
======================================
REGISTER EVENTS AND ASSIGN FUNCTIONS
======================================
*/



/* -- ATTACH EVENTS FOR ABOUT THIS SITE PAGE -- */

function attachASEvts() {

	var otherBrowse = document.getElementById('clients');
	var extLinks = new Array();
	extLinks = otherBrowse.getElementsByTagName('a');

	for (var i = 0; i < extLinks.length; i++) {
		var theID = extLinks[i].id;
		var theObj = document.getElementById(theID);
		var theHREF = theObj.href;

		theObj.addEventListener("click",function(e){outlink(theHREF);e.preventDefault();},false);
		}
	}




/* -- ATTACHES THE HOVER EVENT FOR BROWSE PAGE -- */

function attachEvt(theSrc, targID){
	var theSrc = theSrc;
	var targID = targID;

	theSrc.addEventListener("mouseover",function(e){highlightSection(targID,'over');e.preventDefault();},false);
	theSrc.addEventListener("mouseout",function(e){highlightSection(targID,'out');e.preventDefault();},false);
	theSrc.addEventListener("click",function(e){e.preventDefault();},false);

	}




/* -- MAIN ATTACH EVENTS FUNCTION -- */

function attachEvts() {

	/* COLLECT ALL CLICK IDS */
	var clickEvents = new Array();
	clickEvents = document.getElementsByTagName("a");


	/* FIND ELEMENTS THAT HAVE THE CLASS "CLICK" */
	for (var i = 0; i < clickEvents.length; i++) {

		// SURPRESS THE SELECTION RECTANGLE ON CLICKING A LINK
		clickEvents[i].addEventListener("focus",function(e){if(this.blur)this.blur(); e.preventDefault();},false);

		// FIND THE CLASS OF AN OBJECT TO TEST AGAINST
		var theClass = clickEvents[i].className;

		// IF ANCHOR IS AN EXTERNAL LINK, SEND IT TO A NEW WINDOW
		if (theClass.match(/outlink/)) {
			clickEvents[i].addEventListener("click",function(e){outlink(e);e.preventDefault();},false);
			}

		// IS THIS FROM A BAND PAGE SIDEBAR
		if (theClass.match(/thumb/)) {

			var theID = clickEvents[i].id;
			var theSwitch = theID.substr(-3);

			switch (theSwitch){

				// PHOTO GALLERY
				case "-pg":
				clickEvents[i].addEventListener('click',function(e){showPhotoGallery(e);e.preventDefault();},false);
				break;

				// SCRAPBOOK
				case "-sb":
				clickEvents[i].addEventListener('click',function(e){showPhotoGallery(e);e.preventDefault();},false);
				break;

				// VIDEO
				case "-yt":
				clickEvents[i].addEventListener('click',function(e){showVideoGallery(e);e.preventDefault();},false);
				break;

				}

			}


		// DOES THIS ELEMENT HAVE CLICK ATTACHED TO IT
		if (theClass.match(/click/)) {
			var theID = clickEvents[i].id;
			var theObj = document.getElementById(theID);

			// USE SWITCH TO FIND THE RIGHT SCRIPT TO RUN
			switch (theID) {

				/* SECONDARY NAVIGATION BUTTONS */
				case "closecontact":
				theObj.addEventListener("click",function(e){hideOverlay('contact');e.preventDefault();},false);
				theObj.addEventListener("mouseover",function(e){showMessage('closmess');},false);
				theObj.addEventListener("mouseout",function(e){showMessage('closmess');},false);
				break;

				case "closegallery":
				theObj.addEventListener("click",function(e){hideGallery();e.preventDefault();},false);
				theObj.addEventListener('mouseover',function(e){showMessage('closmess4');},false);
				theObj.addEventListener('mouseout',function(e){showMessage('closmess4');},false);
				break;

				case "closesearch":
				theObj.addEventListener("click",function(e){hideOverlay('advanced-search-close');e.preventDefault();},false);
				theObj.addEventListener('mouseover',function(e){showMessage('closmess2');},false);
				theObj.addEventListener('mouseout',function(e){showMessage('closmess2');},false);
				break;

				case "contactbutton":
				theObj.addEventListener("click",function(e){showContactOverlay();e.preventDefault();},false);
				break;

				case "contactlink":
				theObj.addEventListener("click",function(e){showContactOverlay();e.preventDefault();},false);
				break;

				case "contactorder":
				theObj.addEventListener("click",function(e){contactOrder();e.preventDefault();},false);
				break;

				case "searchbutton":
				theObj.addEventListener('click',function(e){showAdvSearch();e.preventDefault();},false);
				break;


				/* SIDEBAR TOOLS */
				case "back":
				theObj.addEventListener("click",function(e){backOnePage();e.preventDefault();},false);
				break;

				case "b-hint":
				theObj.addEventListener("click",function(e){searchMode('Band');e.preventDefault();},false);
				break;

				case "cart":
				theObj.addEventListener("click",function(e){showPane('cart-items');e.preventDefault();},false);
				break;

				case "cartclose":
//				theObj.addEventListener("click",function(e){closePane('cart-items');e.preventDefault();},false);
//				theObj.addEventListener("click",function(e){showPane('search-form');e.preventDefault();},false);
				theObj.addEventListener("click",function(e){showPane('cart-totals');e.preventDefault();},false);
				break;

				case "cart-details":
				theObj.addEventListener("click",function(e){showPane('cart-items');e.preventDefault();},false);
				break;

				case "expand-history":
				theObj.addEventListener("click",function(e){showPane('previous-list');e.preventDefault();},false);
				break;

				case "fontbuttons":
//				theObj.addEventListener("click",function(e){closePane('font-prefs');e.preventDefault();},false);
				theObj.addEventListener("click",function(e){showPane('cart-totals');e.preventDefault();},false);
				break;

				case "fontpref":
				theObj.addEventListener('click',function(e){showPane('font-prefs');e.preventDefault();},false);
				break;

				case "fontslider":
//				theObj.addEventListener("click",function(e){closePane('font-prefs');e.preventDefault();},false);
				theObj.addEventListener("click",function(e){showPane('cart-totals');e.preventDefault();},false);
				break;

				case "histclose":
//				theObj.addEventListener("click",function(e){showPane('search-form');e.preventDefault();},false);
				theObj.addEventListener("click",function(e){showPane('previous');e.preventDefault();},false);
				break;

				case "historylist":
				theObj.addEventListener("click",function(e){buildHistory();showPane('history');e.preventDefault();},false);
				break;

				case "infoclose":
				theObj.addEventListener("click",function(e){showPane('cart-totals');e.preventDefault();},false);
				break;

				case "print":
				theObj.addEventListener("click",function(e){printPage();e.preventDefault();},false);
				break;

				case "r-hint":
				theObj.addEventListener("click",function(e){searchMode('Record');e.preventDefault();},false);
				break;

				case "searchclose":
				theObj.addEventListener("click",function(e){closeAll();e.preventDefault();},false);
				break;

				case "showhints":
				theObj.addEventListener("click",function(e){showPane('search-form');e.preventDefault();},false);
				break;

				}

			}
		}


		/* ATTACH SCRIPTS TO SUBNAV BUTTONS AS NECESSARY -- DOES NOT AFFECT TEXT LINKS IN SUBNAV */
		var buttonEvents = new Array();
		var theSubNav = document.getElementById('sub');

		buttonEvents = theSubNav.getElementsByTagName("a");
		var buttonCnt = buttonEvents.length;

		/* FIND ELEMENTS THAT HAVE THE CLASS "CLICK" */
		for (var i = 0; i < buttonCnt; i++) {

			var theClass = buttonEvents[i].className;

			if (theClass.match(/click/)) {
				var theID = buttonEvents[i].id;
				var theObj = document.getElementById(theID);

				// USE SWITCH TO FIND THE RIGHT SCRIPT TO RUN
				switch (theID) {

					case "sub45s":
					theObj.addEventListener("click",function(e){prepareNewSearch('listformat', '45'); e.preventDefault();},false);
					break;

					case "subLPs":
					theObj.addEventListener("click",function(e){prepareNewSearch('listformat', 'LP');e.preventDefault();},false);
					break;

					case "subCDs":
					theObj.addEventListener("click",function(e){prepareNewSearch('listformat', 'CD');e.preventDefault();},false);
					break;

					case "subMAGs":
					theObj.addEventListener("click",function(e){prepareNewSearch('listformat', 'MG');e.preventDefault();},false);
					break;

					}

				}

			}


		/* ATTACH EVENTS FOR PAGES THAT ARE BROKEN UP INTO SECTIONS */
		switch (basePage) {
			case "stanton-park-catalog":
			displaySection(1);

			// SET UP SCRAPBOOK
			var theSB = document.getElementById('tb-sb');
			theSB.addEventListener('click',function(e){showPhotoGallery(e);e.preventDefault();},false);
			var thePhotos = runExternal('photoList', "vinyl-photos");
			break;

			case "stanton-park-label":
			displaySection(1);
			break;
			}


		/* CALL SCRIPT TO BUILD VIDEO GALLERY IF THIS IS A STANTON PARK BAND PAGE */
		var thePrefix = /stanton-park-band/;
		if (thePrefix.test(basePage)) {
			createVideoGallery();
			}


		/* ATTACH EVENTS TO HINTS FORM */
		var hField = document.getElementById('hints');
		hField.addEventListener("focus",function(e){focusHints();},false);
		hField.addEventListener("blur",function(e){blurHints();},false);
		hField.addEventListener("keydown",function(e){checkKey(e);},false);

		/* ENTER HINTS FOR PRE HTML5 BROWSERS */
		if (!document.getElementById('hints').placeholder) {
			document.getElementById('hints').value = "Search for Band";
			}

	return false;
	}




/* -- ATTACH EVENTS FOR FLOATING COVERS -- */

function attachFloatingCovers(theObj, cvrID, cvrTitle) {
	var theObj = theObj;
	var cvrID = cvrID;
	var cvrTitle = cvrTitle;

	// ADD ALL THE FUNCTIONS FOR THE COVER HOVERS
	theObj.addEventListener("mouseover",function(e){showFloat(cvrID, cvrTitle);e.preventDefault();},false);
	theObj.addEventListener("mouseout",function(e){hideFloat(cvrID);e.preventDefault();},false);
	theObj.addEventListener("click",function(e){showDetail(cvrID);e.preventDefault();},false);
	}




/* -- ATTACH HOVER EVENTS FOR BROWSE PAGE -- */

function attachHoverEvts() {
	var theContent = document.getElementById('main-copy');
	var tagList = new Array();
	tagList = theContent.getElementsByTagName("a");
	var anchorCnt = tagList.length;

	for (i=0; i<anchorCnt; i++) {
		if (tagList[i].className == "hover") {

			// EXTRACT THE TARGET DIV FROM THE TAG
			theAtt = tagList[i].attributes;
			targetDiv = theAtt.getNamedItem("id").value;
			theID = targetDiv.replace("hover", "");
			theObj = document.getElementById(targetDiv);

			// SEP FUNCTION TO ATTACH THE EVENT
			attachEvt(theObj, theID);

			}
		}

	}




/* -- ATTACH EVENTS FOR THE VIEW ORDER PAGE -- */

function attachOrdEvts() {

	// FIND ALL A TAGS IN LIST
    	var tagList = document.getElementsByTagName('a');

	// FIND THE A TAGS THAT ARE MEMBERS OF THE CONTENT-BUTTON CLASS
   	for (i = 0; i < tagList.length; i++) {

		if (tagList[i].className == "content-button") {
			tagList[i].removeEventListener("click",openEdit,false);
			tagList[i].removeEventListener("click",changeQty,false);
			tagList[i].addEventListener("click",openEdit,false);
			}
		}

	// IF PRINT MAILING LABEL LINK IS ON PAGE ATTACH EVENT
	if (document.getElementById('print-label')) {
		var printLab = document.getElementById('print-label');
		printLab.addEventListener("click",function(e){printLabel();e.preventDefault();},false);
		}



	// CHECK STATUS OF ORDER FOR TURNING ON PAYMENT TAB
	if (document.getElementById('label-tab')) {

		// IF THE SHIPPING INFO HAS NOT BEEN ADDED, THEN DISABLE THE TAB
		var theTab = document.getElementById('label-tab');
		var shipInfoStat = window.localStorage.ordShipStatus;


		// SHIPPING HAS NOT BEEN FILLED IN, KEEP TAB DISABLED
		if (shipInfoStat == "pending" && theTab.className == "payment") {
			theTab.className = "disabled";
			}

		// SHIPPING HAS BEEN FILLED IN, MAKE TAB ACTIVE
		if (shipInfoStat == "completed" && theTab.className == "disabled") {
			theTab.ClassName = "payment";
			theTab.parentNode.innerHTML = '<a href="../cgi-bin/sprv6index.cgi?payment-information" class="payment" id="label-tab">3check out</a>';
			}


		}


	// GET THE MEDIA CONTAINER WITH ITEM COUNT
	var mediaContainer = document.getElementById('information-items').innerHTML;
	var testContents = /Order Summary/;


	// SET INDICATORS IN SIDEBAR FOR COMPLETED ITEMS
	var shipInfoStat = window.localStorage.ordShipStatus;
	var payInfoStat = window.localStorage.ordPayStatus;
	var orderSentStat = window.localStorage.orderStatus;

	// SET STATUS MESSAGE OF ORDER
 	if (orderSentStat != "pending" && orderSentStat != "") {
		orderSentStat = "ORDER SENT";
		}


	// SEE IF WE HAVE BUILT THE ORDERINFO BOX
	if (testContents.test(mediaContainer)) {
		var orderInfo = mediaContainer
		} else {
		//IF WE HAVE NOT BUILD THE ORDER STATUS BOX, DO IT NOW
		var orderInfo = "<li>Order Summary: <span><a href='#' id='summary'>view</a></span>" + mediaContainer + "</li>";
		orderInfo += "<li id='ship-stat'>Shipping Info: <span><a href='../cgi-bin/sprv6index.cgi?shipping-information'>" + window.localStorage.ordShipStatus + "</a></span><span id='ship-ind' class='p-ord'><span>&#10004;</span></span></li>";
		orderInfo += "<li id='payment-stat'>Payment Info: <span><a href='../cgi-bin/sprv6index.cgi?payment-information'>" + window.localStorage.ordPayStatus + "</a></span><span id='pay-ind' class='p-ord'><span>&#10004;</span></span></li>";
		orderInfo += "<li id='send-stat' class='pending'>Send Order: <span>" + orderSentStat + "</span><span id='ord-ind' class='p-ord'><span>&#10004;</span></span></li>";
		}

	// SHOW INFORMATION BOX
	document.getElementById('information-items').innerHTML = orderInfo;

	// MAKE SURE TO CLOSE THE SEARCH FORM
	if (document.getElementById('search-form')) {
		document.getElementById('search-form').style.display = "none";
		}
	showPane('information');

	// ATTACH MEDIA COUNT EVENT
	var summary = document.getElementById('summary');
	summary.addEventListener("click",showSummary,false);

	// IF WE ARE VIEWING THE ORDER, WE NEED TO UPDATE THE SUMMARY IN LOCAL STORAGE
	if (basePage == "view") {
		var theData = document.getElementById('media-count').attributes[0].value;
		window.localStorage.ordSummary = theData;
		}

	// IF WE ARE ON OTHER PAGES OF CHECKOUT, WE NEED TO LOAD MEDIA COUNT DATA FROM LOCAL STORAGE
	if (basePage != "view") {
		var theData = window.localStorage.ordSummary
		document.getElementById('media-count').attributes[0].value = theData;
		}


	// ADJUST INDICATORS TO SHOW ORDER PROGRESS
	if (shipInfoStat == "completed") {
		document.getElementById('ship-ind').className = "v-ord";
		document.getElementById('ship-ind').firstElementChild.display = "inline";
		}

	if (payInfoStat == "completed") {
		document.getElementById('pay-ind').className = "v-ord";
		document.getElementById('pay-ind').firstElementChild.display = "inline";
		}

	if (window.localStorage.ordShipStatus == "completed" && window.localStorage.ordShipStatus == "compeleted") {
		document.getElementById('ord-ind').className = "v-ord";
		document.getElementById('send-stat').className = "";	// make the Send Order option active in the status box
		}

	// ADJUST STYLE IF ORDER HAS BEEN SENT
	if (orderSentStat == "ORDER SENT") {
		document.getElementById('ord-ind').className = "v-ord";
		document.getElementById('send-stat').firstElementChild.style.color = "rgba(204, 0, 0, 0.6)";
		document.getElementById('send-stat').className = "";

		}

	// IF ORDER HAS BEEN SENT SET THE SEND ORDER STATUS
	if (basePage == "order-sent") {
		var sentOrder = document.getElementById('send-stat');
		sentOrder.className = "";
		sentOrder.firstElementChild.style.color = "rgba(204,0,0,.6)";
		sentOrder.innerHTML = sentOrder.innerHTML.replace("pending", "completed");
		document.getElementById('ord-ind').className = "v-ord";
		}



	// DON'T FORGET TO REMOVE THE EVENTS WHEN LEAVING....
	return false;

	}




/* -- ATTACH EVENTS FOR SHIPPING INFO PAGE -- */

function attachSIEvts() {

	// ADD HANDLING FOR INPUT FIELDS THAT HAVE ERRORS
	var theForm = document.getElementById('shipinfo');
    	var tagList = theForm.getElementsByTagName('input');


	// IF CUSTOMER IS GOING BACK TO EDIT THE PAGE WE NEED TO ADD ADDITIONAL FUNCITONS

	// FIRST - ON LOAD VALIDATE THE FORM FIELDS SO THEY SHOW CORRECTLY IN BROWSER
	if (theForm.className == "edit-ship") {
		testFormValues('country');
		testFormValues('method');


		// UPDATE INSTRUCTIONS FOR EDITING SHIPPING INFO
		var theInstructions = document.getElementById('shipping').firstElementChild;
		theInstructions.innerHTML = "Please update any fields you wish. Your changes will be saved automatically. Click <a href='../cgi-bin/sprv6index.cgi?payment-information'>here</a> when you&#8217;re done.";

		// MODOFY THE SUBMIT BUTTON FROM THE FORM HERE
		var subMsg = theForm.firstElementChild.lastElementChild.firstElementChild.textContent = "Click the button below when you have made all your changes.";
		var subButton = document.getElementById('editship');
		subButton.value = "DONE";
		subButton.addEventListener('click',loadPayPage,false);


		// GET RID OF THE DOUBLE BORDER
		var textAreaDiv = document.getElementById('comments').offsetParent;
		textAreaDiv.setAttribute("style", "border-width:0px;");


		// ATTACH SCRIPT THAT WILL "SAVE CHANGES" FOR INPUT FIELDS
		tagList[0].addEventListener("focus",selectContents,false);
		tagList[0].addEventListener("change",function(e){saveFormValues('first');e.preventDefault();},false);
		tagList[1].addEventListener("focus",selectContents,false);
		tagList[1].addEventListener("change",function(e){saveFormValues('last');e.preventDefault();},false);
		tagList[2].addEventListener("focus",selectContents,false);
		tagList[2].addEventListener("change",function(e){saveFormValues('addOne');e.preventDefault();},false);
		tagList[3].addEventListener("focus",selectContents,false);
		tagList[3].addEventListener("change",function(e){saveFormValues('addTwo');e.preventDefault();},false);
		tagList[4].addEventListener("focus",selectContents,false);
		tagList[4].addEventListener("change",function(e){saveFormValues('city');e.preventDefault();},false);
		tagList[5].addEventListener("focus",selectContents,false);
		tagList[5].addEventListener("change",function(e){saveFormValues('state');e.preventDefault();},false);
		tagList[6].addEventListener("focus",selectContents,false);
		tagList[6].addEventListener("change",function(e){saveFormValues('zip');e.preventDefault();},false);
		tagList[7].addEventListener("focus",selectContents,false);
		tagList[7].addEventListener("change",function(e){saveFormValues('emailaddress');e.preventDefault();},false);


		// ATTACH SCRIPT THAT WILL "SAVE CHANGES" FOR SELECT AND TEXTAREA FIELDS
		document.getElementById('comments').addEventListener("focus",selectContents,false);
		document.getElementById('comments').addEventListener("change",function(e){saveFormValues('comments');e.preventDefault();},false);
		document.getElementById('country').addEventListener("focus",selectContents,false);
		document.getElementById('country').addEventListener("change",function(e){saveFormValues('country');e.preventDefault();},false);
		document.getElementById('method').addEventListener("focus",selectContents,false);
		document.getElementById('method').addEventListener("change",function(e){saveFormValues('method');e.preventDefault();},false);


		} else {


		// IF WE ARE ADDING SHIPPING INFO FROM A BLANK FORM ATTACH THESE HERE

		// MANUALLY ADD THE EVENT LISTENER TO THE FIELD
		tagList[0].addEventListener("blur",function(e){testFormByClass('first');e.preventDefault();},false);
		tagList[1].addEventListener("blur",function(e){testFormByClass('last');e.preventDefault();},false);
		tagList[2].addEventListener("blur",function(e){testFormByClass('addOne');e.preventDefault();},false);
		tagList[3].addEventListener("blur",function(e){testFormByClass('addTwo');e.preventDefault();},false);
		tagList[4].addEventListener("blur",function(e){testFormByClass('city');e.preventDefault();},false);
		tagList[5].addEventListener("blur",function(e){testFormByClass('state');e.preventDefault();},false);
		tagList[6].addEventListener("blur",function(e){testFormByClass('zip');e.preventDefault();},false);
		tagList[7].addEventListener("blur",function(e){testFormByClass('emailaddress');e.preventDefault();},false);


		// PAYMENT METHOD MENU
		var paymethod = document.getElementById("method");
		paymethod.addEventListener("change",function(e){testFormByClass('method');e.preventDefault();},false);

		// VALIDIFY COUNTRY
		var countryfield = document.getElementById("country");
		countryfield.addEventListener("change",function(e){testFormByClass('country');e.preventDefault();},false);

		// ADD SHIPPING SUBMIT
		var addship = document.getElementById("addship");
		addship.addEventListener('click',checkShipForm,false);



		}


	}




/* -- ATTACH EXTRA EVENTS BASED ON PAGE -- */

function extraEvt () {

	var thePage = basePage;

	// MAKE THE BAND BIO PAGES GENERIC TO SET EVENT
	var theBio =  new RegExp('^' + 'stanton-park-band-');
	if (thePage.match(theBio)) {
		thePage = "stanton-park-band-";
		}


	// SWITCH STATEMENTS HERE TO LOAD THE VARIOUS EVENTS
	switch (thePage) {

		case "browse":
		drawArrows();
		attachHoverEvts();
//		window.addEventListener("unload",removeEvts,false);   this won't work as is, but should be implemented
		break;

		case "detail":
		drawArrows();
		break;

		case "error":
		sendError();
		break;

		case "home-about-this-site":
		getBrowserStats();
		attachASEvts();
		break;

		case "home-site-stats":
		siteStats();  // this will pass info to drawChart();
		break;

		case "index":
		setTimeout("startAni()", 4000);
		break;

		case "news-from-stanton-park":
		setStoryHeight();
		var allNews = document.getElementById('scroll-news');
		allNews.addEventListener("click",function(e){scrollNews();e.preventDefault();},false);
		checkHeight();
		break;

		case "payment-information":
		checkForShipping();
		attachOrdEvts();
		var chgPay = document.getElementById('change-payment');
		chgPay.addEventListener("click",function(e){changePayment();e.preventDefault();},false);
		break;

		case "order-sent":
		attachOrdEvts();
		break;

		case "shipping-information":
		attachOrdEvts();
		attachSIEvts();
		break;

		case "stanton-park-discography":
		cancelClick();
		preloadCovers();   // preloads large covers on mousever the thumb

		// IF IE9 || OPERA MODIFY PAGE TO HANDLE DRAG AND DROP
		if (window.localStorage.render == "trident" || window.localStorage.render == "presto") {

			var discWall = document.getElementById('discwall');
			var discItems = discWall.getElementsByTagName('a');
			var discItemsLength = discItems.length;


			for (var i=0; i<discItemsLength; i++) {

				theAtt = discItems[i].attributes;

				// SET DRAGGABLE TO FALSE
				discItems[i].setAttribute("draggable", "false");

				// MODIFY ONDRAGSTART SO THAT IT WILL BE AN ONCLICK OR AN ID
				var dragStart = theAtt.getNamedItem("ondragstart");
				dragStart = dragStart.value;
				remText = "event.dataTransfer.setData('text/plain', '";
				dragStart = dragStart.replace(remText, "");
				dragStart = dragStart.replace("')", "");

				// REMOVE ONDRAGSTART
				theAtt.removeNamedItem("ondragstart");

				// ADD ONCLICK
				var newAtt = document.createAttribute("onclick");
				newAtt.value = "loadInfo('" + dragStart + "');";
				discItems[i].setAttributeNode(newAtt);

				}

				// ADJUST THE MESSAGE ABOVE THE TARGET
				var msgBlock = document.getElementById('detail').firstElementChild;
				msgBlock.innerHTML = "CLICK A THUMBNAIL FOR MORE INFO";


			} else {

			// attach the drag and drop events
			var theTarget = document.getElementById('target');
			theTarget.addEventListener("drop",function(e){loadInfo(e);e.preventDefault();},false);
			theTarget.addEventListener("dragover",function(e){e.preventDefault();},false);

			}

		break;

		case "stanton-park-label":
		floatCovers(); // creates floating covers and links to detail pages
		break;

		case "stanton-park-band-":
		setPhotoCap();
		setSideBar();
		setTabActions();
		setReviewActions();
		setAttachDiscDetail();
		preloadPhotos();
		break;

		case "view":
		attachOrdEvts();
		break;

		}
	}




/* -- ATTACHES HOVER EVENT FOR DISCOGRAPHY PAGE -- */

 function preloadCovers (){
	var theID = document.getElementById('discwall');
	var theList = theID.getElementsByTagName('img');
	var listLen = theList.length;

	for (var i=0; i < listLen; i++) {
		theList[i].addEventListener("mouseover",loadCvr,false);
		theList[i].addEventListener("mouseout",clearInfo,false);
		}
 	}




/* -- ATTACH THE SCRIPT TO BUTTONS IN BAND DISCOGRAPHIES -- */

function setAttachDiscDetail() {
	var theDiscog = document.getElementById('discs');
	var discDetail = theDiscog.getElementsByTagName('a');
	var discCount = discDetail.length;

	for (var i=0; i<discCount; i++){
		discDetail[i].addEventListener("click", function(e){showDiscDetails(e);e.preventDefault();},false);
		}
	}




/* -- SET REVIEW ACTIONS -- */

function setReviewActions(){
	var revList = document.getElementById('rev-list');
	var theReviews = revList.getElementsByTagName('a');
	var revCount = theReviews.length;

	for (var i=0; i<revCount; i++){
		theReviews[i].addEventListener("click", function(e){showReview(e);e.preventDefault();},false);
		}
	}




/* -- SET ACTIONS TO TABS ON BAND PAGE -- */

function setTabActions()	{
	var theTabs = document.getElementById('gen-tab-bar');
	var tabAnchors = theTabs.getElementsByTagName("a");
	var tabAnchLen = tabAnchors.length;

	for (var i=0; i<tabAnchLen; i++) {
		tabAnchors[i].addEventListener("click",function(e){bandTabs(e);e.preventDefault();},false);
		}
	}




/*
===================================
MAIN UTILITY FUNCTIONS
===================================
*/



/* -- SET BUTTON TO ACTIVE STATE -- */

function activeButton(theButton) {
	var theButton = document.getElementById(theButton);
	var curClass = theButton.className;
	var theChange = "";

	if (curClass == "click") {
		newClass = curClass + " active";
		theChange = "active";
		} else {
		newClass = "click";
		}

	// REPLACE WITH BOTH CLASSES
	theButton.className = newClass;

	// CHANGE COLOR OF LI
	theButton.parentNode.className = theChange;
	}




/* -- BACK ONE PAGE -- */

function backOnePage(){
	var pageHistory = window.localStorage.history;
	var thePages = pageHistory.split(":-:");

	// GET THE LATEST PAGE
	var backPage = thePages[1];

	// TEST IF IT'S A JS CALL RATHER THAN A URL
	var theType = backPage.match(/#/);

	if (theType) {
		// THIS IS CALLING A SCRIPT, AND NOT A NEW LOCATION

		// EXTRACT THE URL ONLY  FROM THE HISTORY STRING
		backPage = backPage.replace("<a href='#' onclick=\"", "");
		backPage = backPage.replace(/ return false;\">.*$/, "");

		// CALL THE EXTRACTED SCRIPT
		eval(backPage);

		} else {

		//THIS IS CALLING A NEW LOCATION

		// EXTRACT THE URL ONLY FROM THE HISTORY STRING
		backPage = backPage.replace("<a href='", "");
		backPage = backPage.replace(/'>.*$/, "");

		location.href = backPage;
		}
	}




/* -- BAND BIO PAGES -- */

function bandTabs(evt) {
	var theEvt = evt.target || evt.srcElement;
	var selTab = theEvt.id;

	var selData = selTab.replace ("band-", "");
	var theTabs = new Array ("band-bio", "band-discog", "band-reviews", "band-stantonrel");
	var theData = new Array ("bio", "discog", "reviews", "stantonrel");

	// DESELECT ALL TABS
	for (i = 0; i < theTabs.length; i++) {
		document.getElementById(theTabs[i]).className = "";
		document.getElementById(theData[i]).style.display = "none";
		}

	// SELECT PROPER TAB
	document.getElementById(selTab).className = "selected";
	document.getElementById(selData).style.display = "block";

	return false;
	}




/* -- BAND BIO PAGE -- START WITH REVIEWS ACTIVE -- */
function bandReviews() {
	document.getElementById('band-bio').className = "";
	document.getElementById('bio').style.display = "none";

	document.getElementById('band-reviews').className = "selected";
	document.getElementById('reviews').style.display = "block";
	}




/* -- BLUR HINTS FIELD -- */

function blurHints() {
	setOpacity('search-form','Fade');
	if (!document.getElementById('hints').placeholder) {
		resetMsg();
		}
	}




/* -- BLUR SELECTION RECTAGLE -- */

function blurRectangle (theID) {
	var theID = theID;
	var theButton = document.getElementById(theID);
	if(theButton.blur){theButton.blur()};
	}




/* -- BUILD HISTORY LIST -- */

function buildHistory() {

	// RETRIEVE HISTORY
	var pageHistory = window.localStorage.history;

	// GET RID OF TRAILING DELIMITER
	var pageHistory = pageHistory.replace(/:-:$/, "");

	// SPLIT INTO AN ARRAY
	var thePages = pageHistory.split(":-:");
	var pageLen = thePages.length;

	// IF THERE ARE MORE THAN 20 ITEMS, TAKE THE LAST 2O PAGES
	if (pageLen > 19) {
		pageLen = 20;
		}

	var theList = "";
	for (i = 0; i < pageLen; i++){
		theList += "<li>"  + thePages[i] + "</li>";
		}

	// SET TO THE PAGE
	document.getElementById('history-items').innerHTML = theList;
	}




/* -- CANCEL CLICKING ON THUMBNAILS IN SP DISCOGRAPHY -- */
function cancelClick(){
	var theID = document.getElementById('discwall');
	var theThumbs = theID.getElementsByTagName("a");
	var theThumbsLen = theThumbs.length;

	for (var i=0; i<theThumbsLen; i++) {
		theThumbs[i].addEventListener("click",nullEvent,false);
		}

	return false;
	}




/* -- PROTOTYPE TO CAPITALIZE FIRST LETTER OF WORD -- */

String.prototype.capitalize = function() {
	return this.replace(/\b[a-z]/g, function (matchChar) {
		return matchChar.toUpperCase();
		});
	}




/* -- WEBKIT - CHANGE FONT SIZE -- */

function changeSize() {

	// THIS SHOULD START AT THE CURRENT FONT SIZE --- NOT AT THE DEFAULT 1 AS CODED IN THE HTML PAGE
	var theDiv = document.getElementById('main-copy');
	var newSize = document.getElementById('fontsize').value;

	newSize = newSize/10;  // bring back to decimals
	theDiv.style.fontSize = newSize + "em";

	window.localStorage.fontSize = newSize;
	}



/* -- MOZILLA - CHANGE FONT SIZE IN CONTENT DIV (ONLY!) -- */

function changeMozSize(theVal) {

	var	newSize = theVal;
	var theDiv = document.getElementById('main-copy');

	newSize = newSize/10;  // bring back to decimals
	theDiv.style.fontSize = newSize + "em";

	window.localStorage.fontSize = newSize;
	}




/* -- MAKE SURE THAT THE CONTENT AT LEAST FILLS THE HEIGHT OF THE WINDOW -- */

function checkHeight(){


	/* SET THE MAIN DIV TO FILL THE BROWSER IN HEIGHT */
	var contentHeight = document.getElementById('main').offsetHeight;		// the main div's height

	if (navigator.appName.indexOf("Microsoft")!=-1) {
		var windowHeight = document.documentElement.clientHeight;  // the browser window height for IE
		} else {
		var windowHeight = window.innerHeight;		// the browser window height
		}

	// FIX THE HEIGHT
	var theDiff = windowHeight-112;
	var copyDiff = theDiff - 55;

//confirm(windowHeight + " -- " + contentHeight);



	// THESE SET THE HEIGHTS ONLY IF WINDOW IS TALLER THAN THE CONTENT  -- KEEPS LONG CONTENT FROM OVERFLOWING
	if (windowHeight > contentHeight) {
		document.getElementById('content').style.height = theDiff + "px";
		document.getElementById('main-copy').style.height = copyDiff + "px";

		} else {


//		theDiff += 55;
		theDiff = contentHeight - 112;
		document.getElementById('main-copy').style.height = theDiff + "px";
//		document.getElementById('main-copy').style.minHeight = theDiff + "px";
		}



/*

	// THESE SET THE HEIGHTS ONLY IF WINDOW IS TALLER THAN THE CONTENT  -- KEEPS LONG CONTENT FROM OVERFLOWING
	if (windowHeight > contentHeight) {
		document.getElementById('content').style.height = theDiff + "px";
		document.getElementById('main-copy').style.height = copyDiff + "px";

		} else if (basePage == "browse") {		// ONLY FOR THE BROWSE/LIST PAGES

		theDiff += 55;
		document.getElementById('main-copy').style.height = theDiff + "px";
//		document.getElementById('main-copy').style.minHeight = theDiff + "px";


		} else {			// FOR MOST PAGES

		theDiff += 55;
//		document.getElementById('main-copy').style.height = theDiff + "px";
		document.getElementById('main-copy').style.minHeight = theDiff + "px";


		}

*/





	}




/* -- CLEAR DISCOG COVER INFO -- */
function clearInfo (evt) {
	var theObj = evt.target || evt.srcElement;
	theObj.nextElementSibling.className = "info";
	return false;
	}




/* -- SIDEBAR TOOLS -- CLOSE ALL OPEN TOOLS -- */

function closeAll(){
//	var theTools = new Array ("cart-items", "font-prefs", "history", "information", "search-form");   //  "shopping-cart",    -- i'm not sure that we should be closing the cart -- see how it goes
	var theTools = new Array ("shopping-cart", "font-prefs", "history", "information");

	// IF THE DIV IS OPEN, COLLAPSE IT
	for (theDiv in theTools) {

		if (document.getElementById(theTools[theDiv])) {
//			var collapsedDiv = theTools[theDiv] + "-collapsed";
//			document.getElementById(theTools[theDiv]).id = collapsedDiv;
//			document.getElementById(theTools[theDiv]).className = "mod-part-hidden";
			}

		}

	return true;
	}




/* -- LIST PAGE - CLOSE LABEL MENU -- */

function closeLabelList() {
	document.getElementById('label-menu').style.display = "none";
	}




/* -- CONDITIONAL CLEAR -- CLEAR DEFAULT TEXT FROM FORM FIELDS -- */

function condClear(theField){
	var theField = theField;
	var selID = document.getElementById(theField);
	var curVal = selID.value;

	switch (curVal) {

		// HINTS MENU
		case "Search for Band":
		selID.value = "";
		break;

		// HINTS MENU
		case "Search for Record":
		selID.value = "";
		break;
		}

	}




/*-- SEND SP AN EMAIL ABOUT AN ORDER --*/

function contactOrder() {

	var theOrdNum = document.getElementById('ordNum').textContent;

	// SHOW EMAIL MESSAGE
	showContactOverlay();

	// SET THE SUBJECT LINE TO INLCUDE ORDER NUMBER
	if (document.getElementById('subject')) {
		document.getElementById('subject').value = "Question about Stanton Park Order " + theOrdNum;
		}


	return false;
	}




/* -- SHOW VIDEO GALLERY -- SLIGHTLY DIFFERENT THAN PHOTO GALLERY -- */

function createVideoGallery() {

	/* BUILD VIDEO LIST FROM XML FILE */

	// GET THE FILE NAME
	var dirPath = "";
	dirPath += document.location;
	var dirParts = dirPath.split("?");
	var dirLen = dirParts.length;

	// EXTRACT FILE NAME FROM URL THEN GET RID OF PREFIX
	band = dirParts[dirLen-1];
	band = band.replace("stanton-park-band-", "");

	// SET THE PATH TO THE XML FILES
	var bandVidPath = "../spr/content/photos/bandvid/" + band + ".xml";

	// REINITIALIZE LOCAL STORAGE
	window.localStorage.vidTmp = "";

	// GET THE BAND XML AND THE TEMPLATE XML
	runExternal("vidlist", bandVidPath);


	}



/* -- DEACTIVATE BUTTON WITH THE OVERLAY CLOSES -- */

function deactivateButton(theButton) {

	var theButton = document.getElementById(theButton);
	var curClass = theButton.className;
	var newClass = curClass.replace(" active", "");

	// REPLACE WITH BOTH CLASSES
	theButton.className = newClass;

	// CHANGE COLOR OF LI
	theButton.parentNode.className = "";
	}




/* -- SHOW A SPECIFIC SECTION OF LONG STORY -- */

function displaySection (secNum) {


	var secNum = secNum;
	var theSec = "s" + secNum;
	var nextSec = secNum + 1;
	var prevSec = secNum - 1;
	var theStory = document.getElementById('main-copy');
	var theSection = theStory.getElementsByTagName("section");
	var secLen = theSection.length;
	var theNav = theStory.getElementsByTagName("a");
	var navLen = theNav.length;
	var contentHeight = 150;		// set extra height

	// RESET VISIBILITY OF ALL SECTIONS
	for (var i=0; i<secLen; i++) {
		theSection[i].style.display = "none";
		}


	// DISPLAY CORRECT SECTION TAGS
	for (var i = 0; i < secLen; i++) {
		if (theSection[i].className == theSec) {
			theSection[i].style.display = "block";
			contentHeight += theSection[i].offsetHeight;		// add height to section
			}
		}


	// SET CORRECT NAVIGATION
	for (var i = 0; i < navLen; i++){

		// NEXT SECTION
		if (theNav[i].className ==  "next-sec") {
			theNav[i].addEventListener("click",function(e){displaySection(nextSec);window.scrollTo(0,0);e.preventDefault();},false);
			}

		// GO TO THE TOP
		if (theNav[i].className == "top-sec") {
			theNav[i].addEventListener("click",function(e){displaySection(1);window.scrollTo(0,0);e.preventDefault();},false);
			}

		// PREVIOUS SECTION
		if (theNav[i].className == "prev-sec") {
			theNav[i].addEventListener("click",function(e){displaySection(prevSec);window.scrollTo(0,0);e.preventDefault();},false);
			}

		}


	// MAKE SURE WE DON'T CLIP THE TEXT
	document.getElementById('main-copy').style.height = contentHeight + "px";

	return false;
	}




/* -- FLOATING COVERS ON STANTON PARK PAGE -- */

function floatCovers() {
	theDiv = document.getElementById('main-copy')
	var cvrAnchors = new Array();
	cvrAnchors = document.getElementsByTagName('a');
	var cvrLength = cvrAnchors.length;

	for (var i=0; i<cvrLength; i++) {
		var theObj = cvrAnchors[i];

		if (theObj.className == "relative") {
			var cvrID = theObj.id;		// get the ID of the anchor
			var theAtt = theObj.attributes;
			var cvrTitle = theAtt.getNamedItem("data-title").value;
			attachFloatingCovers(theObj, cvrID, cvrTitle);
			}
		}
	}




/* -- FOCUS HINTS INPUT FIELD -- */

function focusHints(){
	condClear('hints');		// need this for backwards compatibility
	setOpacity('search-form', 'Full');
	return false;
	}




/* -- REMOVES THE FLOATING COVER CODE FROM THE TEXT LINK -- */

function hideFloat(cvrID){
	var cvrID = cvrID;
	var targetText = document.getElementById(cvrID).innerHTML;

	// SET A REGEX TO GRAB THE CODE THAT PRODUCES THE FLOATING IMG
	var clearText = /<span[^>]*>[^>]*><br>[^<]*<\/[^>]*>/;
	var origText = targetText.replace(clearText,"");
	document.getElementById(cvrID).innerHTML = origText;
	}




/* -- HIDE GALLERY OVERLAY -- */

function hideGallery(){
	// SET THE CONTENT UNDER THE OVERLAY BACK TO NORMAL
	document.getElementById('main-copy').style.opacity = 1;
	var theDiv = document.getElementById('photo-gallery');
	theDiv.className = "contact";

	// ENABLE PRINTING WHEN GALLERY CLOSES
	document.getElementById('print').style.display = "inline-block";


	/* IF VIDEO GALLERY, REMOVE EVENTS AND CONVERT BACK TO PHOTO GALLERY  */

	var phGall = document.getElementById('photo-gallery');

	if (phGall.firstChild.id == "vid-gallery") {

		// REMOVE THE CLOSE EVEN FROM THE VIDEO GALLERY
 		var theObj = document.getElementById('closegallery');
		theObj.removeEventListener("click",function(e){hideGallery();e.preventDefault();},false);
		theObj.removeEventListener('mouseover',function(e){showMessage('closmess4');},false);
		theObj.removeEventListener('mouseout',function(e){showMessage('closmess4');},false);

		// RESET THE PHOTO GALLERY LAYOUT
		var photoContent = "<div><h6>Photo Gallery</h6><span id='cl-gallery'><span id='closmess4'>Close the gallery.</span> <a id='closegallery' class='click' href='#'>✘</a></span></div><p id='msg-pg' style='display: block;'>Click each photo to advance to the next.</p><div id='img-cont'><ul id='theImg'></ul></div>";
		phGall.innerHTML = photoContent;

		// ADD CLOSE EVENT ONTO THE REPLACED PHOTO GALLERY
 		var theObj = document.getElementById('closegallery');
		theObj.addEventListener("click",function(e){hideGallery();e.preventDefault();},false);
		theObj.addEventListener('mouseover',function(e){showMessage('closmess4');},false);
		theObj.addEventListener('mouseout',function(e){showMessage('closmess4');},false);

		}












	}




/* -- HIDE OVERLAY AND CONTENT -- */

function hideOverlay(theSec){
	var theSec = theSec;
	var theButton = "";


	// CLOSE THE ADVANCED SEARCH PANEL WITH A SEARCH
	if (theSec == "advanced-search") {
		document.getElementById('msg').style.display = "none";

		// SELECT THE BUTTON TO DEACTIVATE
		theButton = "searchbutton";
		}

	// CLOSE THE ADVANCED SEARCH PANEL BY CLOSE BUTTON
	if (theSec == "advanced-search-close") {
		document.getElementById('msg').style.display = "none";

		// REOPEN HINTS FORM IN SIDEBAR ONLY IF SEARCH WAS CLOSED WITHOUT PERFORMING A FIND
		showPane("search-form");

		// RESET theSec TO STANDARD VALUE
		theSec = "advanced-search";

		// SELECT THE BUTTON TO DEACTIVATE
		theButton = "searchbutton";

		}

	// CLOSE THE CONTACT PANEL BY CLOSE BUTTON
	if (theSec == "contact") {
		theButton = "contactbutton";
		}

	// SET THE CONTENT UNDER THE OVERLAY BACK TO NORMAL
	document.getElementById('main-copy').style.opacity = 1;
	var theDiv = document.getElementById(theSec);
	theDiv.className = "contact";


	// ENABLE PRINTING WHEN OVERLAY CLOSES
	document.getElementById('print').style.display = "inline-block";


	// CALL SCRIPT TO DEACTIVATE THE BUTTON
//	deactivateButton(theButton);
	activeButton(theButton);
	}




/* -- HIGHLIGHT CONTROLS ON BROWSE PAGE TO ILLUSTRATE TOOLS THAT CAN BE USED -- */

function highlightSection (theID, state) {
	var theID = theID;
	var state = state;

	switch (theID) {

		// SEARCH FORM
		case "search-form":

		// NEED TO MAKE SURE FORM IS SHOWING
		if(!document.getElementById(theID)) {
			showPane('search-form');
			}

		// SET STYLE TO SHOW IT OFF
		var domID = document.getElementById(theID);
		var theForm = domID.getElementsByTagName("fieldset");

		if (state == "over") {
			domID.style.opacity = "1";
			theForm[0].className = "element-highlight";
			} else {
			domID.style.opacity = ".6";
			theForm[0].className = "";
			}

		break;


		// BROWSE BUTTONS
		case "sub":
		var domID = document.getElementById(theID);
		var theButtons = domID.getElementsByTagName("a");

		// HIGHLIGHT THE BUTTONS
		if (state == "over") {

			for (i=0; i<4; i++) {
				theButtons[i].className += " sub-highlight";
				}

			} else {

			for (i=0; i<4; i++) {
				theButtons[i].className = "genre-buttons click";
				}

			}

		break;


		// ADVANCED SEARCH BUTTON
		case "searchbutton":
		var domID = document.getElementById(theID);

		// HIGHLIGHT THE BUTTON
		if (state == "over") {
			domID.className += " highlight";
			} else {
			domID.className = "click";
			}

		break;

		}

	}




/* -- SP DISCOG -- LOADS THE COVER AND SHOWS INFO LABEL OVER COVER -- */

function loadCvr(evt) {

	var theObj = evt.target || evt.srcElement;
	var theSrc = theObj.src;
	var mainImg = theSrc.replace("-tb", "");

	var theImg = new Image()
	theImg.src = mainImg;

	theObj.nextElementSibling.className = "show-info";

	return false;
	}




/* -- LOAD THE VIDEO INTO THE PLAYER -- */

function loadVideo(evt) {

	var vidID = evt.target || evt.srcElement;
	vidID = vidID.id;
	var vidCont = document.getElementById('player');
	vidCont.src = "http://www.youtube.com/embed/" + vidID;

	// CHANGE TO SHOW THE SELECTION IN VIDEO LIST
	var thumbCont = document.getElementById("vid-thumbs");
	var thumbList = thumbCont.getElementsByTagName("a");
	var thumbLen = thumbList.length;

	// SET THE CLASS TO NONE
	for (var i=0; i<thumbLen; i++) {
		var vidListID = thumbList[i].id;
		document.getElementById(vidListID).parentNode.className = "";	// set style to show that it's playing
		}

	// SHOW THE VIDEO THAT IS PLAYING
	document.getElementById(vidID).parentNode.className = "playing";	// set style to show that it's playing

	return false;
	}




/* -- HANDLE DRAG AND DROP EVENTS -- */

function loadInfo(event) {

	var theEngine = window.localStorage.render;
	var theEvent = event || window.event;
	var newMatrix = "";

	// EXTRACT THE MATRIX INFO
	if (theEngine == "trident") {
		newMatrix = event;
		} else {
		newMatrix = theEvent.dataTransfer.getData("text/plain");
		//	var newMatrix = event.dataTransfer.getData("text/plain");
		}


	// SET THE SRC OF THE BIG IMAGE
	var bigCvrSrc = document.getElementById('big-cover').src;

	//FIND FILENAME OF CURRENT COVER
	var bigCvrParts = bigCvrSrc.split("/");
	var oldMatrix = bigCvrParts.pop();

	// DISPLAY NEW COVER IN DETAIL SECTION
	var newCvrSrc = bigCvrSrc.replace(oldMatrix, newMatrix);
	document.getElementById('big-cover').src = newCvrSrc + ".jpg";


	// CALL AJAX ROUTINE TO LOAD OTHE INFO FOR THE DETAIL SECTION

	// ARRAY OF RELEASES WITH ASSOCIATED BAND
	var bandList = {"STP-001":"trodds", "STP-002":"trodds", "STP-003":"ladds", "STP-004":"hackmasters", "STP-005":"distortion", "STP-006":"grovellers", "STP-007":"dog", "STP-008":"jumpercables", "STP-009":"hard", "STP-010":"commandments", "STP-011":"willie", "STP-012":"voodoo", "STP-013":"bags", "STP-014":"brood", "STP-015":"jumpercables", "STP-016":"voodoo", "STP-018":"bags", "STP-019":"facts", "STP-020":"voodoo", "STP-021":"rising", "STP-022":"time", "STP-023":"brian", "STP-024":"bald", "STP-SSC":"subskin", "7-HHTT":"head", "LES-001":"senseurround", "LES-003":"nines", "LES-004":"psycho", "LES-005":"slump", "LES-006":"kenne", "SLP-001":"kenne", "SLP-002":"swamp", "SLP-003":"where", "SLP-004":"bags", "SCD-005":"bags", "SLP-006":"voodoo", "SLP-007":"medicine", "SLP-008":"head", "SLED-001":"kenne", "SRE-001":"rising", "SRE-002":"relative", "SRE-003":"stroke", "SRE-004":"lost", "SRE-005":"banjo", "SRE-007":"banjo"};
	var theBand = bandList[newMatrix] + ":-:" + newMatrix;

	// CALL AJAX TO LOOK UP INFO
	runExternal("bandData", theBand);

	return false;
	}




/*-- LOAD THE PAYMENT PAGE FROM EDITING SHIPPING INFO --*/

function loadPayPage(){
	location.href = "../cgi-bin/sprv6index.cgi?payment-information";
	return false;
	}




/* -- TRAP CLICK EVENTS -- */

function nullEvent(e){
	e.preventDefault();
	return false;
	}




/* -- PHOTO GALLERY NAVIGATION -- */

function nextPhoto(){
	var theGallery = document.getElementById('theImg');
	var galleryList = theGallery.getElementsByTagName("li");
	var theGallerySize = galleryList.length;
	var lastPhoto = theGallerySize-1;		// this is the last photo -- allow to catch and go back to photo 1

	//FIND THE CURRENT PHOTO AND SET UP THE NEXT PHOTO
	for (i=0; i<theGallerySize; i++) {
		var startPos = galleryList[i].offsetTop;
		if (startPos == 0) {
			curID = i;
			theID = curID + 1;

			// IF THE END HAS BEEN REACHED, SET THE NEXT PHOTO TO THE FIRST
			if (theID > lastPhoto) {
				theID = 0;
				}

			}

		}

	// MOVE THE PHOTOS NOW
	galleryList[curID].className = "above";
	galleryList[theID].className = "";
	}




/* -- OUTLINK  -- LOAD EXTERNAL LINKS IN NEW WINDOW/TAB -- */

function outlink (evt) {
	var theObj = evt.target || evt.srcElement;
	var theAtt = theObj.attributes;
	var theURL = theAtt.getNamedItem("data-url").value;

	var winName = "FromStantonPark";

	window.open(theURL, winName);

	return false;
	}




/* -- PRELOAD PHOTOS FOR THE GALLERY -- */

function  preloadPhotos(){
	var baseBand = basePage;
	baseBand = baseBand.replace("stanton-park-band-", "");

	// SPLIT BAND NAMES INTO MULTIPLE WORDS TO GRAB FIRST (FOR PHOTO DIRS)
	var bandWords = baseBand.split("-");
	var theBand = bandWords[0];

	// ADD FLAG TO PRELOAD PHOTOS
	theBand = theBand + "-photos";

//	var theBand = "brood-photos";   // ============>> this will need to change to a var
	var thePhotos = runExternal('photoList', theBand);
	return false;
	}




/* -- PRELOAD PHOTOS FOR THE GALLERY -- */

function preloadPhotosNow(theList){
	var theList = theList;
	var theCache = document.getElementById('cache');

	// LOAD THE IMAGES IN THE CACHE
	theCache.style.content = theList;
	}




/* -- PREPARE CURRENT PAGE FOR PRINTING -- */

function prepPrint() {

	/* RUN SCRIPTS WHEN PAGE IS FINISHED LOADING */

	// ENTER COPYRIGHT
	document.getElementById('copyright').innerHTML = theCopyright;

	// GET URL OF REFERRING DOCUMENT
	document.getElementById('refer').innerHTML = document.referrer;

	// GET THE CONTENT FROM THE PARENT PAGE
	var topWin = window.opener;
	var theContent = topWin.document.getElementById('main-copy').innerHTML;


	// HIDE INFO THAT SHOULDN'T BE PRINTED
	if(document.getElementById('rotate')) {
		document.getElementById('rotate').style.display = "none";
		}
	if(document.getElementById('reverse')) {
		document.getElementById('reverse').style.display = "none";
		}

	// PUT THE MODIFIED CONTENT INTO THE PRINT PAGE
	document.getElementById('page').innerHTML = theContent;


	// RESIZE IMAGES IF NECESSARY
	var imgList = new Array(document.images);
	imgList = document.getElementsByTagName('img');

	for (i = 0; i < imgList.length; i++) {

		// GET CURRENT DIMENSIONS OF IMAGE
		var imgWidth = imgList[i].width;
		var imgHeight = imgList[i].height;

		// IF TOO WIDE, KEEP REDUCING SIZE BY 10% TILL IMAGE FITS WIDTH-WISE
		while (imgWidth > 550) {
			imgWidth *= .9;
			imgHeight *= .9;
			}

		// SET THE IMAGE TO THE NEW DIMENSIONS
		imgList[i].width = imgWidth;
		imgList[i].height = imgHeight;
		}


	/* ADJUSTMENTS FOR SPECIFIC PAGES */

	// FIND THE PAGE THAT'S BEING PRINTED
	var history = new Array ();
	var lsHistory = window.localStorage.history;
	history = lsHistory.split(":-:");
	var curPage = history[0];

	// SET RE TO CHECK FOR SPECIFIC PAGES
	var about = /about/i;
	var detail = /detail/i;
	var discog = /-discography/i;
	var ordering = /ordering/i;
	var search = /search/i;
	var sp = /stanton-park-/i;
	var stats = /stats/i;
	var view = /view/i;


	// ABOUT THIS SITE
	if (about.test(curPage)) {
		document.getElementById('clients').style.display = "none";
		document.getElementById('otherbrowsers').nextElementSibling.nextElementSibling.style.display = "none"; // download other browsers message
		}

	// SITE STATS
	if (stats.test(curPage)) {
		siteStats();
		}


	// IF WE'RE PRINTING A SP PAGE
	if (sp.test(curPage)) {

		// MAKE SURE THAT ALL SECTIONS ARE SHOWING
		var theSec = document.getElementsByTagName("section");
		var theSecLen = theSec.length;

		for (var i=0; i<theSecLen; i++) {
			theSec[i].style.display = "block";
			}
		}

	// IF WE'RE PRINTING A LIST OR SEARCH
	if (search.test(curPage)) {
		var theBody = document.getElementById('page');

		// HIDE THE REVERSE SUBHEAD
		var theDiv = theBody.getElementsByTagName('div');
		var theDivLen = theDiv.length;

		for (var i=0; i < theDivLen; i++) {
			if (theDiv[i].className = "reverse") {
				theDiv[i].style.display = "none";
				}
			}

		// HIDE THE FILTER LINKS
		var theList = document.getElementById('list');
		var theAnch = theList.getElementsByTagName('a');
		var theAnchLen = theAnch.length;
		var detAnch = /more/;


		for (var i=0; i < theAnchLen; i++) {

			// REMOVE THE LINK TO MORE DETAIL
			if (detAnch.test(theAnch[i].innerHTML)) {
				theAnch[i].style.display = "none";
				}

			// ADD PARENS AROUND LABEL
			if (theAnch[i].className == "label") {
				theAnch[i].innerHTML = "(" + theAnch[i].innerHTML + ")";
				}

			}

		// FIX SOME STYLE THINGS HERE
		document.getElementById('list').style.marginBottom = "15px";
		document.getElementById('page').firstElementChild.style.marginBottom = "10px";
		document.getElementById('nav-arrows').style.display = "none";

		}

	// IF WE'RE PRINTING A DETAIL PAGE
	if (detail.test(curPage)) {

		var thePage = document.getElementById('page');
		var theHead = thePage.getElementsByTagName('h1');
		theHead[0].style.fontSize = "1.3em";
		theHead[0].style.lineHeight = "1.1em";
		theHead[0].style.marginBottom = "0px";
		theHead[0].style.display = "inline-block";
		theHead[0].textContent = theHead[0].textContent + ": ";

		var theSubHead = thePage.getElementsByTagName('h2');
		theSubHead[0].style.fontSize = "1.3em";
		theSubHead[0].style.marginBottom = "0px";
		theSubHead[0].style.display = "inline-block";

		// REMOVE OTHER METADATA INFO
		document.getElementById('tab-bar').style.display = "none";
		document.getElementById('related').style.display = "none";

		// ADD A HEAD IN FOR THE TRACSK
		var theTracks = document.getElementById('tracks').innerHTML;
		var theList = /<ol>/;
		var theHead = "<h5>The Tracks</h5><ol>";

		theTracks = theTracks.replace(theList, theHead);
		document.getElementById('tracks').innerHTML = theTracks;

		}

	// IF WE'RE PRINTING THE DISCOGRAPHY PAGE
	if (discog.test(curPage)) {
		document.getElementById('singScrollBut').style.display = "none";
		document.getElementById('detail').style.display = "none";

		}



	// IF WE'RE PRINTING THE ORDER
	if (view.test(curPage)) {

		// GET RID OF THE TABS
		document.getElementById('tab-bar').style.display = "none";

		// MODIFIY THE TABLE TO REMOVE EDITING FORM ELEMENTS
		var theOrder = document.getElementById('orderitems');
		var theQty = new Array();
		var theTD = new Array();
		theTD = theOrder.getElementsByTagName("td");
		var tdLength = theTD.length;

		for (var i=0; i<tdLength; i++){
			if (theTD[i].className == "left") {
				var theInput = theTD[i].firstElementChild.value;
				theTD[i].innerHTML = theInput;
				}
			}

		}


	// IF WE'RE PRINTING THE ORDERING INFORMATION
	if (ordering.test(curPage)) {



		}




	// THROW UP A PRINT DIALOG
	setTimeout("window.print();",500);
	return false;
	}




/* -- PRINT MAILING LABEL -- */

function printLabel(){
	window.open ("../spr/print-label.html", "Print Page", "width=612pt,height=792pt");
	return false;
	}




/* -- PRINT CURRENT PAGE -- */

function printPage(){
	window.open ("../spr/print.html", "Print Page", "width=612pt,height=792pt");
	return false;
	}




/* -- RUN EXTERNAL PERL SCRIPTS VIA AJAX AND RETURN RESULTS -- */

function runExternal(scriptKey, theArgs){

	// KEY TO SCRIPT HAS
	var scriptKey = scriptKey;
	var theArgs = theArgs;  			// ARGUMENTS TO PASS TO THE SCRIPT

	// LIST OF POSSIBLE SCRIPTS TO RUN
	var theScripts = new Array();

	// CHECK TO SEE IF THE ORDER HAS RUN YET
	var checkOrderStatus = checkOrderSentStatus();
	if (checkOrderStatus == "completed" && scriptKey == "add"){
		alert("This order has already been sent, and can no longer be edited.");
		return;
		}

	theScripts = {
		"add" : "sprv6addItem.cgi",
		"bandData" : "sprv6getBandData.cgi",
		"bandList" : "sprv6loadSearch.cgi?band",
		"changeqty" : "sprv6editQty.cgi",
		"editShip" : "sprv6editShipInfo.cgi",
		"email" : "sprv6contact.cgi",
		"error" : "sprv6error.cgi",
		"list" : "sprv6loadMainList.cgi",
		"news" : "sprv6getNewsStory.cgi",
		"photoList" : "sprv6photoList.cgi",
		"recordList" : "sprv6loadSearch.cgi?record",
		"resetqty" : "sprv6resetQty.cgi",
		"vidlist" : ""
		};

	var scriptURL = basePath + "cgi-bin/" + theScripts[scriptKey];

	// MAKE EXCEPTION FOR ADD ITEM SCRIPT  -- PATH NEEDS TO BE PRECISE FOR COOKIES
	if (scriptKey == "add") {
		scriptURL = basePath + "cgi-bin/" + theScripts[scriptKey];
		}

	// IF THERE ARE ARGUMENTS TO PASS TO THE SCRIPT, ADD THEM HERE  -- DON'T ADD UNDEFINED AS AN ARGUMENT
	if (theArgs != "" && theArgs != "undefined") {
		scriptURL += "?" + theArgs;
		}


	// ADD SESSION TO CHANGEQTY TO PASS TO THE VIEW ORDER SCRIPT
	if (scriptKey == "changeqty") {
		scriptURL += ":-:" + window.localStorage.session;
		}

	// JUST OPEN THE XML FILES FOR VIDEO LIST
	if (scriptKey == "vidlist") {
		scriptURL = theArgs;
		}


	// TEST AJAX COMPATIBILITY
	var xmlHttp;
	try {   // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}

	catch (e){ // Internet Explorer
	try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e) {
	try {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	catch (e) {
		alert("Your browser does not support AJAX!");
		return false;
		}
		}
	}


	// RUN THE SCRIPT
	xmlHttp.open("GET",scriptURL,true);
	xmlHttp.send(null);

	xmlHttp.onreadystatechange=function() {

		if(xmlHttp.readyState==4) {

		switch (scriptKey) {

			case "add":
				// UPDATE CART AND ORDER DETAILS IN STORAGE.JS
				var returnInfo = xmlHttp.responseText;
				updateCart(returnInfo);
				break;

			case "bandData":
				document.getElementById('disc-info').innerHTML = xmlHttp.responseText;
				break;

			case "bandList":
				window.localStorage.bands = xmlHttp.responseText;
				break;

			case "changeqty":

				var retVal = xmlHttp.responseText.split(":-:");
				var argVal = theArgs.split(":-:");

				var newVal = retVal[0];
				//var message = retVal[1];
				var lineNum = "r" + argVal[0];

				// PUT NEW VALUE IN THE FORM
				document.getElementById(lineNum).value = newVal;

				// PREPARE RETURN DATA TO UPDATE THE CART WITH THE NEW INFO
				var retVals = new Array();
				retVals = xmlHttp.responseText.split(":=:");

				// UPDATE CART AND SHOW MESSAGE
				updateCart(retVals[0], retVals[1]);

				var xTime = setTimeout("document.getElementById('notification').className = '';",1500);
				var yTime = setTimeout("location.href = basePath + 'cgi-bin/sprv6index.cgi?view-order';",1500);


				// REFRESH VIEW PAGE
//				location.href = basePath + "cgi-bin/sprv6index.cgi?view-order";
				break;

			case "email":
				break;

			case "error":
				break;


			case "editShip":
				var theResult = xmlHttp.responseText;

				var argList = new Array();
				argList = theArgs.split(":-:");
				var fieldMsg = document.getElementById(argList[0]).nextElementSibling.firstElementChild;


				if (theResult == "1") {
					// success

					fieldMsg.innerHTML = "&#10004;&nbsp;&nbsp;<span>Changes Saved</span>";
					fieldMsg.style.width = "115px";
					fieldMsg.style.left = "-1px";

					if (window.localStorage.render == "webkit" || window.localStorage.render == "presto") {
						fieldMsg.style.left = "-4px";
						}


					} else {
					//failure

					}

				break;

			case "news":
				document.getElementById('news-cont').innerHTML = xmlHttp.responseText;
				setStoryHeight();

				// ADJUST SUBNAV STATE
				document.getElementById('scroll-news').className = "";
				document.getElementById('news').firstElementChild.firstElementChild.className = "active";


				/* ATTACH EVENTS TO OUTLINK IF PRESENT */

				// COLLECT ALL CLICK IDS */
				var clickEvents = new Array();
				var newsStory = document.getElementById('news-cont');
				clickEvents = newsStory.getElementsByTagName("a");


				// FIND ELEMENTS THAT HAVE THE CLASS "CLICK"
				for (var i = 0; i < clickEvents.length; i++) {

					// SURPRESS THE SELECTION RECTANGLE ON CLICKING A LINK
					clickEvents[i].addEventListener("focus",function(e){if(this.blur)this.blur(); e.preventDefault();},false);

					// FIND THE CLASS OF AN OBJECT TO TEST AGAINST
					var theClass = clickEvents[i].className;

					// IF ANCHOR IS AN EXTERNAL LINK, SEND IT TO A NEW WINDOW
					if (theClass.match(/outlink/)) {
						clickEvents[i].addEventListener("click",function(e){outlink(e);e.preventDefault();},false);
						}

					}

				break;

			case "photoList":
				var photoList = xmlHttp.responseText;
				preloadPhotosNow(photoList);
				break;

			case "recordList":
				window.localStorage.records = xmlHttp.responseText;
				break;

			case "resetqty":
				var theID = "r" + theArgs;
				document.getElementById(theID).value = xmlHttp.responseText;
				break;

			case  "vidlist":
				var xmlDoc = xmlHttp.responseXML;

				if (xmlDoc != null) {

					// CONVERT THE XML DOC INTO A LIST
					var theVidList = "";

					var x = xmlDoc.getElementsByTagName("name");
					var y = xmlDoc.getElementsByTagName("id");

					for (var i=0; i<x.length;i++) {
						theVidList += "<li><a href='#' id='" + y[i].childNodes[0].nodeValue + "'>" + x[i].childNodes[0].nodeValue + "</a></li>";

						// TRANSFER DATA BACK VIA LOCAL STORAGE
						if (i == (x.length-1)) {
							window.localStorage.vidTmp = theVidList;
							}
						}
					}


				break;
				}



		// IF WE ARE LOADING THE MAIN LIST, PROCESS THE RETURN AS FOLLOWS
		switch (theArgs) {
			case "all":
			window.localStorage.catalog = xmlHttp.responseText;
			break;
			}

		return;
		}
	}
}




/* -- TEMP HERE === SAVE EDITED SHIPPING INFORMATION   -- */

function saveFormValues(theField) {

	var theField = theField;

	// NEEDS TO TEST FIELD FIRST, THEN IF SUCCESSFUL SAVE IT, IF INVALID DON'T SAVE.
//	var theResult = testFormValues(theField);
	var theResult = testFormByClass(theField);
	var fieldValue = document.getElementById(theField).value;

	// IF NOT AN ERROR CALL SCRIPT TO SAVE CHANGES IN DB
	if (theResult != "error") {
		runExternal("editShip", theField + ":-:" + fieldValue);
		}

	return;
	}




/* -- HANDLE SCROLLING IN DISCOGRAPHY -- */

function scrollDisc (theType) {

	var theType = theType;

	// CLEAR THE TOP TABS
	var theTabs = document.getElementById('gen-tab-bar')
	var tabLink = theTabs.getElementsByTagName('a');

	for (i=0; i<2; i++){
		tabLink[i].className = "";
		}

	//SET THE PROPER TOP TAB
	if (theType == "albums"){
		tabLink[1].className = "selected";
		} else {
		tabLink[0].className = "selected";
		}

	// FIND CURRENT ID
	var theID = document.getElementById('discwall');

	// SCROLL CURRENT ID UP
	theID.firstElementChild.className = theType;

	// SHOW-HIDE MORE SINGLES BUTTON
	var singScrollBut = document.getElementById('singles').className;
	if (singScrollBut == "" || singScrollBut == "singles") {
		document.getElementById('singScrollBut').style.display = "block";
		} else {
		document.getElementById('singScrollBut').style.display = "none";
		}

	return;
	}




/* -- SCROLL NEWS STORY -- */

function scrollNews () {

	// FIND CURRENT ID
	var theID = document.getElementById('story');

	// FIND HEIGHT OF STORY
	var storyHeight = theID.offsetHeight;
	var moveUp = -1 * (storyHeight + 10);

	// SCROLL CURRENT ID UP
	theID.className = "hide-story";
	theID.style.marginTop = moveUp + "px";

	//SHOW NEWS LIST
	document.getElementById('newslist').className = "show-list";

	// ADJUST SUBNAV STATE
	document.getElementById('scroll-news').className = "active";
	document.getElementById('news').firstElementChild.firstElementChild.className = "";

	return;
	}




/* -- SELECT FORM FIELDS ON FOCUS -- */

function selectContents(){

	// SEE IF ORDER HAS BEEN SENT
	var checkOrderStatus = checkOrderSentStatus();
	if (checkOrderStatus == "completed"){
		alert("This order has already been sent, and can no longer be edited.");
		return;
		} else {

		// IF ORDER HAS NOT BEEN SENT YET, SELECT THE CONTENT IN INPUT FIELDS
		if (this.nodeName == "input") {
			this.select();
			}
		}
	}




/* -- SEND ERROR MESSAGE TO STANTON PARK -- */

function sendError(){

	// GET ERROR NUMBER
	var errorAtt = document.getElementById('error-detail').attributes;
	var errorNum = errorAtt.getNamedItem("data-error").value;

	// GET ERROR DETAIL
	var pageRequested = document.getElementById('requested').innerHTML;
//	var referringPage = document.getElementById('referring').innerHTML;

	// PREPARE MESSAGE FOR EMAIL
//	var emailMessage = "Error #:" + errorNum + "\n" + pageRequested + "\n" + referringPage;
	var emailMessage = "Error #:" + errorNum + "\n\t" + pageRequested;
	emailMessage = escape(emailMessage);

	// SEND MESSAGE TO SP
	runExternal("error", emailMessage);

	return;
	}



/* -- FADE OUT THE ERROR MESSAGES -- */

function setFade(theID){
	var origID = document.getElementById(theID);
	var theID = document.getElementById(theID).nextElementSibling.nextElementSibling;
	theID.className = "error";

	/* MAKE SURE THAT THE ERROR MESSAGE DISAPPEARS IN IE */
	if (window.localStorage.render == "trident" && origID.className == "selected") {
		theID.style.display = "none";
		}

	return false;
	}




/* --SELECT FIELD -- */

function selectField(theSel) {
	var theSel = theSel.id;
	var theObj = document.getElementById(theSel);

	// SEE IF OBJ IS SELECTED
	var curClass = theObj.className;

	//IF OBJ SELECTED, DESELECT, ELSE SELECT IT
	if (curClass == "selected") {
		theObj.className = "";
		} else {
		theObj.className = "selected";
		}
	}




/* -- SET OPACITY  !!! is this used -- really, does the class still exist? or are we using diff css method for fade -- */

function setOpacity(theID, theClass) {
	var theID = theID;
	var theClass = theClass;
	if (document.getElementById('theID')) {
		document.getElementById(theID).className = "op" + theClass;
		}
	}




/* -- SET NEWS STORY HEIGHT -- */

function setStoryHeight () {
	// FIND HEIGHT OF CURRENT STORY
	var storyHeight = document.getElementById('story').offsetHeight;
	storyHeight += 10;

	// SET NEWS CONTAINER TO HEIGHT OF STORY PLUS 10 EXTRA PIXELS
	document.getElementById('news-cont').style.height = storyHeight + "px";
	}




/* -- SET PHOTO CAPTION FOR BAND BIO PAGE -- */

function setPhotoCap() {
	var theImg = document.getElementById('band-img').firstChild;
	var theWidth = theImg.width;
	var theHeight = theImg.height;

	document.getElementById('band-img').style.width = theWidth + "px";
	document.getElementById('band-img').style.height = theHeight + "px";

	}




/* -- SET SIDEBAR THUMBNAILS -- */

function setSideBar(){
	var theSB = document.getElementById('right-sidebar');
	var theThumbs = theSB.getElementsByTagName("a");

	var thePG = theThumbs[0].id;
	var theSB = theThumbs[1].id;
	var theWS = theThumbs[2].id;

	var bandName = thePG.replace("-tb-pg", "");

	document.getElementById(thePG).style.backgroundImage = "url(content/photos/" + thePG + ".jpg)";
	document.getElementById(theSB).style.backgroundImage = "url(content/photos/" + theSB + ".jpg)";
	document.getElementById(theWS).style.backgroundImage = "url(content/photos/" + theWS + ".jpg)";
	}




/* -- SHOW ADVANCED SEARCH OVERLAY -- */

function showAdvSearch() {
	blurRectangle('searchbutton');
	searchMode('advanced');
	showOverlay('advanced-search');
	activeButton('searchbutton');

	// ATTACH EVENTS NOW -- MUST BE ACTIVE TO DO THAT
	var bandField = document.getElementById('band');
	bandField.addEventListener("focus",function(e){selectField(this);e.preventDefault();},false);
	bandField.addEventListener("blur",function(e){selectField(this);e.preventDefault();},false);

	var recField = document.getElementById('record');
	recField.addEventListener("focus",function(e){selectField(this);e.preventDefault();},false);
	recField.addEventListener("blur",function(e){selectField(this);e.preventDefault();},false);

	var labelField = document.getElementById('label');
	labelField.addEventListener("focus",function(e){selectField(this);e.preventDefault();},false);
	labelField.addEventListener("blur",function(e){selectField(this);e.preventDefault();},false);

	// DISABLE PRINTING FOR WHILE OVERLAY IS ACTIVE
	document.getElementById('print').style.display = "none";

	return false;
	}




/* -- SHOW CONTACT OVERLAY -- */

function showContactOverlay () {
	blurRectangle('contactbutton');
	showOverlay('contact');
	activeButton('contactbutton');

	// SEE IF VISITOR IS USING IE9
	var theBrowser = window.localStorage.render;
	var emailField = document.getElementById('email');
	var theSubject = document.getElementById('subject');
	var theMsg = document.getElementById('mess');

	// ATTACH EVENTS NOW -- MUST BE ACTIVE TO DO THAT

			/*  ATTACH FORM VALIDATION   V1
				if (theBrowser != "trident" && theBrowser != "mozilla") {
					emailField.addEventListener("focus",function(e){selectField(this);e.preventDefault();},false);
					emailField.addEventListener("blur",function(e){selectField(this);testFormValues('email');e.preventDefault();},false);

					theSubject.addEventListener("focus",function(e){selectField(this);e.preventDefault();},false);
					theSubject.addEventListener("blur",function(e){selectField(this);testFormValues('subject');e.preventDefault();},false);

					theMsg.addEventListener("keyup",function(e){testFormValues('mess');e.preventDefault();},false);
					theMsg.addEventListener("blur",function(e){unfocusStyle('mess');e.preventDefault();},false);

					}
			*/


	// ADD THE "PLACEHOLDER" TEXT ATTACH FORM VALIDATION V2 FOR IE9
	if (theBrowser == "trident") {
		emailField.value = "Please enter your email address.";
		emailField.addEventListener("focus",function(e){if (emailField.value == "Please enter your email address.") {emailField.value = "";}e.preventDefault();},false);
		emailField.addEventListener("keyup",function(e){testFormByClass('email');e.preventDefault();},false);

		theSubject.value = "Please enter a subject for this email.";
		theSubject.addEventListener("focus",function(e){if (theSubject.value == "Please enter a subject for this email."){theSubject.value=""};e.preventDefault();},false);
		theSubject.addEventListener("keyup",function(e){testFormByClass('subject');e.preventDefault();},false);

		theMsg.value = "Type your message here.";
		theMsg.addEventListener("focus",function(e){if (theMsg.value == "Type your message here."){theMsg.value=""};e.preventDefault();},false);
		theMsg.addEventListener("keyup",function(e){testFormByClass('mess');e.preventDefault();},false);

		}


	// ATTACH FORM VALIDATION V2 FOR OTHER BROWSERS
	if (theBrowser != "trident") {

		emailField.addEventListener("focus",function(e){if (emailField.value == "Please enter your email address.") {emailField.value = "";}e.preventDefault();},false);
		emailField.addEventListener("blur",function(e){testFormByClass('email');e.preventDefault();},false);

		theSubject.addEventListener("focus",function(e){if (theSubject.value == "Please enter a subject for this email."){theSubject.value=""};e.preventDefault();},false);
		theSubject.addEventListener("blur",function(e){testFormByClass('subject');e.preventDefault();},false);

		theMsg.addEventListener("focus",function(e){if (theMsg.value == "Type your message here."){theMsg.value=""};e.preventDefault();},false);
		theMsg.addEventListener("keyup",function(e){testFormByClass('mess');e.preventDefault();},false);

		}




	// MAKE SURE THAT FORM IS ACTIVE -- EVEN IF AN EMAIL HAS BEEN SENT.
	document.getElementById('contactform').className = "";

	// CLOSE ERROR MESSAGES INITIALLY
	document.getElementById('email').nextElementSibling.nextElementSibling.style.display = "none";
	document.getElementById('subject').nextElementSibling.nextElementSibling.style.display = "none";

	// DISABLE PRINTING FOR WHILE OVERLAY IS ACTIVE
	document.getElementById('print').style.display = "none";

	return false;
	}



/* -- CALL SCRIPT TO GET THE DETAIL OF AN ITEM -- */

function showDetail(itemNumber) {
	var itemNumber = itemNumber;
	location.href ="../cgi-bin/sprv6detail.cgi?" + itemNumber;
	return false;
	}




/* -- SHOW DETAILS IN BAND DISCOGRAPHY -- */

function showDiscDetails(evt) {

	var theID = evt.target || evt.srcElement;
	theID = theID.id;

	var theDetails = theID.replace("control", "details");
	var theControl = document.getElementById(theID);
	var closeNode = "hideDiscDetails('"+ theID +"'); return false;"

	var detail = document.getElementById(theDetails);

	if (detail.className == "") {
		document.getElementById(theDetails).className = "show";
		theControl.innerHTML = "&#10008;";
		} else {
		document.getElementById(theDetails).className = "";
		theControl.innerHTML = '&#10148;';
		}

	return false;
	}




/* -- SHOW THE COVER WHEN TEXT LINK IS HOVERED OVER -- */

function showFloat (cvrID, cvrTitle){
	var cvrID = cvrID;
	var cvrTitle = cvrTitle;
	var theSpan = "<span class='float'><img src='../spr/content/covers/" + cvrID + "-tb.jpg' class='' alt='"+ cvrTitle +"' /><br />" + cvrTitle + "</span>";

	// INSERT IT INTO PAGE
	var linkText = document.getElementById(cvrID).textContent;
	document.getElementById(cvrID).innerHTML = linkText + theSpan;
	}




/* -- SHOW INLINE MESSAGES -- */

function showMessage(theDiv){
	var theDiv = theDiv;
	var msgCont = document.getElementById(theDiv);
	var theState = msgCont.style.display;

	// TOGGLE THE DISPLAY STATE
	if (theState == "none" || theState == "") {
		msgCont.style.display = "inline";
		} else {
		msgCont.style.display = "none";
		}
	}




/* -- SHOW LABELS IN FILTER MENUBAR -- */

function showLabelList() {
	document.getElementById('label-menu').style.display = "block";
	}




/* -- SLIDE OVERLAY AND CONTENT INTO VIEW -- */

function showOverlay (theSec) {
	var theSec = theSec;

	var theDiv = document.getElementById(theSec);
	var mainHeight = document.getElementById('main-copy').offsetHeight;

	// FIRST MAKE SURE BOTH THE ADVANCED SEARCH AND CONTACT DIVS ARE HIDDEN
	document.getElementById('contact').className = "contact";
	document.getElementById('advanced-search').className = "contact";

	// TURN OFF THE BUTTONS FOR ADVANCED SEARCH/CONTACT
	deactivateButton("searchbutton");
	deactivateButton("contactbutton");


	theDiv.style.height = mainHeight + "px";
	theDiv.className = "contact-active";

	// IF THIS IS THE CONTACT FORM, MAKE SURE IT'S THE DEFAULT FORM
	if(theSec == "contact") {
		document.getElementById('confirmation').innerHTML = "If you have a question or comment, please use this form to contact us.";
		var theForm = document.getElementById('contactform');
		theForm.email.value = "";
		theForm.subject.value = "";
		theForm.curpage.checked = "";
		theForm.mess.value = "";

		// DISABLE THE SEND BUTTON FOR IE TILL ALL THE FIELDS ARE VALID
		var theBrowser = window.localStorage.render;
		var sendButton = document.getElementById('sendbutton');

		if (theBrowser == "trident") {
			// ATTACH EVENT
			sendButton.addEventListener("click",function(e){validMsg('contactform'); e.preventDefault();},false);
			sendButton.disabled = true;
			}



		}

	// IF THIS IS ADVANCED SEARCH FORM, MAKE SURE VALUES ARE CLEAR AND MSG IS STD.
	if (theSec == "advanced-search") {
		document.getElementById('msg').innerHTML = "Enter as much information as you like to narrow your search.";
		document.getElementById('msg').style.display = "block";
		document.getElementById('msg').className = "";

		document.getElementById('band').value = "";
		document.getElementById('record').value = "";
		document.getElementById('label').value = "";

		document.getElementById('filtercat').value = "";
		document.getElementById('filterformat').value = "";

		// MAKE SURE THAT ERROR ARROWS ARE HIDDEN
		document.getElementById('band-err').style.display = "none";
		document.getElementById('record-err').style.display = "none";
		document.getElementById('label-err').style.display = "none";


		// CLOSE INFORMATION SIDEBAR
		document.getElementById('information').className = "mod-part-hidden";

/* 		if (document.getElementById('information')) {
			document.getElementById('information').id = "information-collpased";
			} */

		}


	// SET THE CURRENT PAGE URL
	var thePage = document.search;  // document.search   -- when we start to have some pages
	if (document.search) {
		thePage = document.search;
		} else {
		thePage = "index";
		}

	// ADD CURRENT PAGE TO CONTACT FORM
	if (theSec == "contact") {
		document.getElementById('curpage').value = thePage;
		}

// MAYBE TRY USING document.title to get the actual name of the page -- will not show the changes in content due to JS -- ie browse/search/details launched from Browse landing



	// DIM THE CONTENT UNDER THE OVERLAY
	document.getElementById('main-copy').style.opacity = .3;

	}




/* -- SIDEBAR TOOLS -- SLIDE PANE INTO VIEW -- */

function showPane(thePane) {
	var thePane = thePane;

	// MAKE SURE ALL PANES ARE CLOSED

	var sideTabs = document.getElementById('side-tabs');
	var pageTools = document.getElementById('page-tools1');
	var stAnch = pageTools.getElementsByTagName("a");
	var ptDiv = pageTools.getElementsByTagName("div");
	var ptLen = ptDiv.length;
	var selClass = /selected/;
	var mpClass = /mod-part/;

	// TURN OFF EACH MODULE
	for (var i=0; i<ptLen; i++) {

/* 		if (ptDiv[i].className == "mod-part") { */
		if (mpClass.test(ptDiv[i].className)) {
			ptDiv[i].className = "mod-part-hidden";
			}
		}


	// DESELECT EACH TAB
	for (var i=0; i<4; i++) {
		if (selClass.test(stAnch[i].className) && i < 4) {

			stAnch[i].className = "sb-button click";

			}
		}


	// SHOW REQUESTED PANE
	switch (thePane) {

		/* SHOW SHOPPING CART DETAIL - HIDE TOTALS */
		case "cart-items":

			// TURN TAB ON AND SELECT THE TAB
			document.getElementById('shopping-cart').className = "mod-part";
			document.getElementById('cart').className = "sb-button click selected";

/*
			// SETS THE DIV TO THE CORRECT ID DEPENDING ON THE CURRENT ID
			if (document.getElementById('cart-items-init')) {
				document.getElementById("cart-items-init").id = "cart-items";
				} else if (document.getElementById('cart-items')) {
				document.getElementById("cart-items").id = "cart-items";
				} */

			document.getElementById('totals').className = "hidden";
			document.getElementById("cart-items").className = "short";

			fetchCartDetails();

		break;


		/* KEEP CART TAB - CLOSE CART DETAILS AND SHOW JUST TOTALS*/
		case "cart-totals":

			// TURN TAB ON AND SELECT THE TAB
			document.getElementById('shopping-cart').className = "mod-part";
			document.getElementById('cart').className = "sb-button click selected";

			document.getElementById('cart-items').className = "hidden";
			document.getElementById('totals').className = "short";

		break;


		/* CLOSE OTHER MODULES, OPEN HISTORY MODULE */
		case "history":

			// TURN TAB ON AND SELECT THE TAB
			document.getElementById('history').className = "mod-part";
			document.getElementById('historylist').className = "sb-button click selected";

			// SHOW LIST, BUT NOT THE PREVIOUS PAGE
			document.getElementById('expanded-history').className = "short";
			document.getElementById('prev-page').className = "hidden";


		break;


		/* COLLAPSE THE HISTORY LIST TO SHOW ONLY THE PREVIOUS PAGE */
		case "previous":
			document.getElementById('history').className = "mod-part short";
			document.getElementById('expanded-history').className = "hidden";
			document.getElementById('historylist').className = "sb-button click selected";



			// FIGURE OUT THE LAST PAGE FROM THE LOADED LIST
			var prevItems = document.getElementById('history-items').children;
			var lastPage = prevItems[1].innerHTML;

			document.getElementById('prev-page').className = "short";
			document.getElementById('back-page').innerHTML = lastPage;
		break;


		/* IF WE ARE ON THE PAGES PANE IN COLLAPSED MODE, EXPAND */
		case "previous-list":

			// KEEP THE HISTORY TAB SELECTED AND THE WINDOW OPEN.
			document.getElementById('history').className = "mod-part";
			document.getElementById('historylist').className = "sb-button click selected";

			document.getElementById('prev-page').style.display = "none";
			document.getElementById('expanded-history').style.display = "block";

		break;



		/* SHOW INFORMATION FOR SEARCHES AND ORDERS */
		case "information":

			document.getElementById('information').className = "mod-part";

		break;



		/* SHOW/HIDE FONT PREFS */
		case "font-prefs":

			var fontForm = document.getElementById("font-prefs");
			var fontTab = document.getElementById('fontpref');

			if (document.getElementById('font-prefs').className == "mod-part-hidden") {
				fontForm.className = "mod-part";
				fontTab.className ="sb-button click selected";
				}

		break;




			case "search-form":
/* 			if (document.getElementById('search-form-init')) {
				theID = "search-form-init";
				} else {
				theID = "search-form-collapsed";
				}
			document.getElementById(theID).id = "search-form"; */

			// SET DEFAULT VALUES
			document.getElementById("b-hint").className = "sb-button selected click";
			document.getElementById("r-hint").className = "sb-button click";
			document.getElementById('hints').value = "";
			document.getElementById('search-results').innerHTML = "";
			break;

		}

	return false;
	}




/* -- SHOW PHOTO GALLERY -- */

function showPhotoGallery(evt) {

	var theObj = evt.target || evt.srcElement;
	var theSec = theObj.id;
	var theTag = theSec.substr(-3);		// DETERMINES WHICH IMAGES WILL SHOW

	var theDiv = document.getElementById('photo-gallery');
	var mainHeight = document.getElementById('main-copy').offsetHeight;

	// FIRST MAKE SURE ALL OVERLAY DIVS ARE HIDDEN
	document.getElementById('advanced-search').className = "contact";
	document.getElementById('contact').className = "contact";
	document.getElementById('photo-gallery').className = "contact";


	// SET PROPERTIES FOR OVERLAY
	theDiv.style.height = mainHeight + "px";
	theDiv.className = "contact-active";

	// BUILD GALLERY
	var thePhotos = document.getElementById('cache').style.content;

	var photoList = new Array();
	photoList = thePhotos.split("url");
	var photoListLen = photoList.length;
	var galleryList = "";
	var band = /band/;
	var scrap = /scrapbook/;

	for (var i=0; i < photoListLen; i++) {

		// IF THIS IS A PHOTO GALLERY
		if(photoList[i]) {

			// CLEAN URL
			var theSrc = photoList[i] + "   ";
			var theParen = /[()",]/g;		// FIND THE CHARS TO STRIP

			theSrc = theSrc.replace(theParen, '');	// CLEAN THE URLS

			var wkImg = new Image;
			wkImg.src=theSrc;

			// SET NEXT PHOTO, AND RESET TO 0 IF WE'VE HIT THE MAX
			var nextPhoto = i + 1;
			if (nextPhoto > photoListLen){
				nextPhoto = 1;
				}


			// FILTER OUT PHOTO GALLERY ITEMS ONLY
			if (theTag == "-pg" && band.test(photoList[i])) {

				// SET THE FIRST ONE TO BE IN POSITION
				if (galleryList == "") {
					galleryList += "<li onclick='nextPhoto(); return false;'><a href='#'><img width='" + wkImg.width + "'  height='" + wkImg.height + "' src='" + theSrc + "' alt='Gallery Image' /></a></li>";
					} else {
					galleryList += "<li class='above' onclick='nextPhoto(); return false;'><a href='#'><img width='" + wkImg.width + "'  height='" + wkImg.height + "' src='" + theSrc + "' alt='Gallery Image' /></a></li>";
					}

				}


			// FILTER OUT SCRAPBOOK ITEMS ONLY
			if (theTag == "-sb" && scrap.test(photoList[i])) {

				// SET THE FIRST ONE TO BE IN POSITION
				if (galleryList == "") {
					galleryList += "<li onclick='nextPhoto(); return false;'><a href='#'><img width='" + wkImg.width + "'  height='" + wkImg.height + "' src='" + theSrc + "' alt='Gallery Image' /></a></li>";
					} else {
					galleryList += "<li class='above' onclick='nextPhoto(); return false;'><a href='#'><img width='" + wkImg.width + "'  height='" + wkImg.height + "' src='" + theSrc + "' alt='Gallery Image' /></a></li>";
					}

				}


			}

		}




	// POPULATE THE GALLERY
	var theGallery = document.getElementById('theImg');
	theGallery.innerHTML = galleryList;

	// SET THE CONTAINER HEIGHT
	var conHeight = theGallery.firstChild.firstChild.height;

	// SHOW THE GALLERY
	document.getElementById('photo-gallery').className = "contact-active";

	// DIM THE CONTENT UNDER THE OVERLAY
	document.getElementById('main-copy').style.opacity = .3;

	// DISABLE PRINTING FOR WHILE OVERLAY IS ACTIVE
	document.getElementById('print').style.display = "none";


	}




/* -- SHOW SELECTED REVIEW -- */

function showReview(evt) {
	var theEvt = evt.target || evt.srcElement;
	var theAtt = theEvt.attributes;
	targetDiv = theAtt.getNamedItem("data-id").value;

	// HIDE ALL OTHER REVIEWS
	var revDetail = document.getElementById('rev-detail');
	var revDetailTag = revDetail.getElementsByTagName('div');
	var revDetailCount = revDetailTag.length;

	for (var i=0; i<revDetailCount; i++) {
		revDetailTag[i].className = "review-detail"
		}

	// SHOW SELECTED REVIEW
	document.getElementById(targetDiv).className = "show-review";
	}




/* --SHOW TRACKS TAB IN DETAIL PAGE -- */

function showTracks() {
	var theTabs = new Array ("track-tab", "band-tab", "label-tab", "category-tab");

	// DESELECT ALL TABS
	for (i = 0; i < theTabs.length; i++) {
		document.getElementById(theTabs[i]).className = "";
		}

	// SELECT PROPER TAB
	document.getElementById('track-tab').className = "selected";

	// TURN OFF THE RELATED CONTENT, AND TURN ON THE TRACKS TAB
	document.getElementById('related').style.display = "none";
	document.getElementById('tracks').style.display = "block";

	return false;
	}





/* -- SHOW VIDEO GALLERY -- SLIGHTLY DIFFERENT THAN PHOTO GALLERY -- */

function showVideoGallery() {

	// FIRST MAKE SURE ALL OVERLAY DIVS ARE HIDDEN
	document.getElementById('advanced-search').className = "contact";
	document.getElementById('contact').className = "contact";
	document.getElementById('photo-gallery').className = "contact";

	// SET UP OVERLAY
	var theDiv = document.getElementById('photo-gallery');
	var mainHeight = document.getElementById('main-copy').offsetHeight;

	// SET PROPERTIES FOR OVERLAY
	theDiv.style.height = mainHeight + "px";
	theDiv.className = "contact-active";

	// LOAD VIDEO LIST
	var bandVids = window.localStorage.vidTmp;


	// CONVERT PHOTO GALLERY TO VIDEO GALLERY -- THIS WILL HAVE TO GO BACK ON CLOSING THE VIDEO GALLERY
	var videoContent = "<div id='vid-gallery'><h6>Video Gallery</h6><span id='cl-gallery'><span id='closmess4'>Close the gallery.</span> <a id='closegallery' class='click' href='#'>&#10008;</a></span></div><p id='msg-pg' style='display: block;'>Select a video from the list below.</p><div id='vid-player'><iframe width='420' height='315' id='player' src='' frameborder='0' allowfullscreen></iframe></div><ul id='vid-thumbs'>" + bandVids + "</ul>";

	// ADD THE CONTENT TO THE OVERLAY
	theDiv.innerHTML = videoContent;


	// ADD LISTENER TO CLOSE VIDEO GALLERY
	var theObj = document.getElementById('closegallery');
	theObj.addEventListener("click",function(e){hideGallery();e.preventDefault();},false);
	theObj.addEventListener('mouseover',function(e){showMessage('closmess4');},false);
	theObj.addEventListener('mouseout',function(e){showMessage('closmess4');},false);



	// REGISTER THE VIDEO LINKS
	var thumbCont = document.getElementById("vid-thumbs");
	var thumbList = thumbCont.getElementsByTagName("a");
	var thumbLen = thumbList.length;

	for (var i=0; i<thumbLen; i++) {
		var vidID = thumbList[i].id;
		thumbList[i].addEventListener("click",function(e){loadVideo(e);e.preventDefault();},false);
		}


	// LOAD THE FIRST VIDEO
	var vidCont = document.getElementById('player');
	var vidID = thumbList[0].id;	// get first video from list
	vidCont.src = "http://www.youtube.com/embed/" + vidID;
	document.getElementById(vidID).parentNode.className = "playing";	// set style to show that it's playing



	// SHOW THE GALLERY
	document.getElementById('photo-gallery').className = "contact-active";

	// DIM THE CONTENT UNDER THE OVERLAY
	document.getElementById('main-copy').style.opacity = .3;

	// DISABLE PRINTING FOR WHILE OVERLAY IS ACTIVE
	document.getElementById('print').style.display = "none";


	return false;
	}




/* -- GET SITE STATS -- */

function siteStats() {

	// INTITIALIZE FORMAT COUNT OBJECT
	fmtCnt = new Array();
	fmtCnt.singles = 0;
	fmtCnt.albums = 0;
	fmtCnt.cds = 0;
	fmtCnt.zines = 0;

	// INTITIALIZE GENRE COUNT OBJECT
	genreCnt = new Array();
	genreCnt.alt = 0;
	genreCnt.bos = 0;
	genreCnt.gar = 0;
	genreCnt.pun = 0;
	genreCnt.six = 0;

	/* MATCH AGAINST FORMATS */

	// LOAD THE CATALOG
	var theList = window.localStorage.catalog;

	var listArray = new Array();
	var listArray = theList.split("</li>");

	for (i=0; i < listArray.length-1; i++) {

		var theItem = listArray[i];						// get the item
		var theInfo = /data-media="[45CDLPMG]*-[ABGPS]/;		// set up regex to extract data info
		var formatGenre = theItem.match(theInfo);			// pull the data
		formatGenre = formatGenre.toString();				// convert to a string

		formatGenre = formatGenre.replace("data-media=\"", "");

		// SPLIT DATA TO EXAMINE
		var mediaInfo = new Array();
		mediaInfo = formatGenre.split("-");

		var theFormat = mediaInfo[0];
		var theGenre = mediaInfo[1];

		// INCREMENT THE PROPER FORMAT
		switch (theFormat) {

			case "45":
			fmtCnt.singles++;
			break;

			case "LP":
			fmtCnt.albums++;
			break;

			case "CD":
			fmtCnt.cds++;
			break;

			case "MG":
			fmtCnt.zines++;
			break;

			}


		// INCREMENT THE PROPER GENRE
		switch (theGenre){

			case "A":
			genreCnt.alt++;
			break;

			case "B":
			genreCnt.bos++;
			break;

			case "G":
			genreCnt.gar++;
			break;

			case "P":
			genreCnt.pun++;
			break;

			case "S":
			genreCnt.six++;
			break;

			}
		}

		// SEND THIS INFO TO DRAW CHART
		drawChart(fmtCnt, genreCnt);
	}




/* -- SUBHEAD ANIMATION ON HOME PAGE -- */

function startAni() {

	// IF WE ARE ON THE HOME PAGE VIEWING NORMAL CONTENT THERE -- NOT SEARCH, NOT CONTACT
	// needs some work in case of overlay, errors out

	if (document.getElementById('home-subhead')) {

		var subHead = document.getElementById('home-subhead');
		var subList = subHead.getElementsByTagName("span");
		var subLen = subList.length;

		var loopRet = subLen - 1;
		var msgItem = 0;
		var nextItem = 0

		// LOOP THROUGH TO FIND THE ACTIVE ITEM
		for (var i=0; i < subLen; i++){

			if (subList[i].className == "translucent") {

				// INCREMENT BY ONE
				msgItem = subList[i];
				var j=i+1;
				nextItem = subList[j];

				// RESET THE ANIMATION
				if (i == loopRet) {
					nextItem = subList[0];
					}

				break;
				}

			}

			// TURN ACTIVE OFF, AND NEXT ON
			msgItem.className = "transparent";
			nextItem.className = "translucent";

		//SET TIMEOUT AND CALL THIS SCRIPT AGAIN
		setTimeout("startAni()", 4000);
		}

	}





/* -- TEST FORM BY CLASSES -- built for IE and maybe Opera -- May become the final one -- */

function testFormByClass(theID) {

	var theID = theID;
	var theField = document.getElementById(theID);
	var theIndic = document.getElementById(theID).nextElementSibling;
	var fieldMsg = document.getElementById(theID).nextElementSibling.nextElementSibling;
	var theFlag = "";


	var fieldTagName = theField.tagName;
	var fieldAtt = theField.attributes;
	var textArea = /textarea/i;				// REGEXP for finding textarea tag name
	var select = /select/i;				// REGEXP for finding textarea tag name


	// GET FIELD TYPE
	if (textArea.test(fieldTagName)) {
		var fieldType = "textarea";   // capture textarea fields
		} else if (select.test(fieldTagName)) {
		var fieldType = "select";
		} else {
		var fieldType = fieldAtt.getNamedItem("type").value;
		}

	var fieldText = theField.value;



	// SET UP THE VALIDATING PATTERNS
	var emailPattern = /^[0-9a-zA-Z\._-]*@[a-zA-Z]*\.[a-zA-Z\.]{2,}$/;
	var textPattern = /[\^\$\*\(\)\[\]#%@`:;]/;			// We are looking to match the non-legal characters here


	// DISABLE THE SEND BUTTON TILL ALL THE FIELDS ARE VALID
	var theBrowser = window.localStorage.render;
	var sendButton = document.getElementById('sendbutton');

	if (theBrowser == "trident") {
		sendButton.disabled = true;
		}



	// HANDLE THE FILED INFO
	switch (fieldType) {


		case "email":
		var results = emailPattern.test(fieldText);

		// IF FIELD IS REQUIRED -- BE SURE IT'S FILLED IN
		if (fieldText == "") {
			fieldMsg.innerHTML = "This field is required.";
			} else {
			fieldMsg.innerHTML = "Please enter a valid email address.";
			}


		// SET THE CLASSES
		if (results == true && fieldText != "") {

			theField.className = "valid";
			theIndic.className = "valid";
			fieldMsg.className = "valid";

			} else if (results == false) {

			theField.className = "invalid";
			theIndic.className = "invalid";
			fieldMsg.className = "invalid";

			theFlag = "error";

			}

		break;



		case "select":
		if (fieldText == "" || fieldText == "null") {
			fieldMsg.innerHTML = "This field is required.";

			theField.className = "invalid";
			theIndic.className = "invalid";
			fieldMsg.className = "invalid";

			theFlag = "error";

			} else {

			theField.className = "valid";
			theIndic.className = "valid";
			fieldMsg.className = "valid";

			// SHOW MESSAGE BASED ON THE PAYMENT OPTION
			if (fieldText == "paypal"){
				document.getElementById('pp').style.display = "block";
				document.getElementById('ck').style.display = "none";
				}

			if (fieldText == "check"){
				document.getElementById('ck').style.display = "block";
				document.getElementById('pp').style.display = "none";
				}



			}

		break;


		case "text":
		var results = textPattern.test(fieldText);

		if (theID == "addTwo" && fieldText == "") {
			break;
			}


		// IF FIELD IS REQUIRED -- BE SURE IT'S FILLED IN
		if (fieldText == "") {
			fieldMsg.innerHTML = "This field is required.";
			} else if (results == true) {
			fieldMsg.innerHTML = "Please enter only text, numbers or ! ? . marks in this field.";
			}


		// SET THE CLASSES
		if (results == false && fieldText != "") {

			theField.className = "valid";
			theIndic.className = "valid";
			fieldMsg.className = "valid";

			} else if (results == false && fieldText == "") {

			theField.className = "invalid";
			theIndic.className = "invalid";
			fieldMsg.className = "invalid";

			theFlag = "error";

			} else if (results == true) {

			theField.className = "invalid";
			theIndic.className = "invalid";
			fieldMsg.className = "invalid";

			theFlag = "error";

			}


		break;



		case "textarea":

		var results = textPattern.test(fieldText);
		fieldMsg.innerHTML = "Please enter only text, numbers or ! ? . marks in this field.";


		// SET THE CLASSES
		if (results == false && fieldText != "") {

			theField.className = "valid";
			theIndic.className = "valid";
			fieldMsg.className = "valid";

			} else if (results == true) {

			theField.className = "invalid";
			theIndic.className = "invalid";
			fieldMsg.className = "invalid";

			theFlag = "error";

			}


		break;


	}





	// IF ALL FIELDS ARE VALID THEN RE-ENABLE THE SEND BUTTON

	if (theBrowser == "trident") {
		emClass = document.getElementById('email').className;
		subClass = document.getElementById('subject').className;
		messClass = document.getElementById('mess').className;

		if (emClass == "valid" && subClass == "valid" && messClass == "valid") {
			sendButton.disabled = false;
			}
		}



	return theFlag;

	}





/* -- TEST SHOWING FIELD LABELS ON INVALID FIELDS BEING BLURED     --   this is version 1 which is being phased out in favor of testFormByClass  -- */

function testFormValues(theID) {
	var theID = theID;
	var theField = document.getElementById(theID);
	var fieldMsg = document.getElementById(theID).nextElementSibling.nextElementSibling;
	var theFlag = "";

	var fieldTagName = theField.tagName;
	var fieldAtt = theField.attributes;
	var textArea = /textarea/i;				// REGEXP for finding textarea tag name
	var select = /select/i;				// REGEXP for finding textarea tag name


	// GET FIELD TYPE
	if (textArea.test(fieldTagName)) {
		var fieldType = "textarea";   // capture textarea fields
		} else if (select.test(fieldTagName)) {
		var fieldType = "select";
		} else {
		var fieldType = fieldAtt.getNamedItem("type").value;
		}


	var fieldText = theField.value;

	// SET UP THE VALIDATING PATTERNS
	var emailPattern = /^[0-9a-zA-Z\._-]*@[a-zA-Z]*\.[a-zA-Z\.]{2,}$/;
	var textPattern = /[\^\$\*\(\)\[\]#%@`:;]/;			// We are looking to match the non-legal characters here

	switch (fieldType) {

		case "email":
		var results = emailPattern.test(fieldText);


		// IF FIELD IS REQUIRED -- BE SURE IT'S FILLED IN
		if (fieldText == "") {
			fieldMsg.innerHTML = "This field is required.";
			theFlag = "error";
			} else {
			fieldMsg.innerHTML = "Please enter a valid email address.";
			theFlag = "error";
			}

		fieldMsg.style.display = "block";
		fieldMsg.className = "";		// clear the error class so we can set it again

		// MAKE EXCEPTION FOR TRIDENT
		if (window.localStorage.render == "trident" && results == true && fieldText != "") {
			fieldMsg.style.display = "none";
			theField.className = "valid";
			theField.nextElementSibling.firstElementChild.style.display = "inline-block";

			} else if (window.localStorage.render == "trident" && results == false) {
			theField.className = "invalid";
			}



		// ATTACH A HOVER EVENT TO THIS
		// fieldMsg.addEventListener("mouseover",function(e){setFade(theID);e.preventDefault();},false);
		break;



		case "select":
		if (fieldText == "" || fieldText == "null") {
			fieldMsg.innerHTML = "This field is required.";
			document.getElementById(theID).className = "invalid";
			theFlag = "error";

			// ACTIVATE MESSAGE HERE
			fieldMsg.style.display = "block";
			fieldMsg.className = "";		// clear the error class so we can set it again

			// ATTACH A HOVER EVENT TO THIS
			// fieldMsg.addEventListener("mouseover",function(e){setFade(theID);e.preventDefault();},false);

			} else {

			document.getElementById(theID).className = "valid";

			// SHOW MESSAGE BASED ON THE PAYMENT OPTION
			if (fieldText == "paypal"){
				document.getElementById('pp').style.display = "block";
				document.getElementById('ck').style.display = "none";
				}

			if (fieldText == "check"){
				document.getElementById('ck').style.display = "block";
				document.getElementById('pp').style.display = "none";
				}


			}

		break;


		case "text":
		var results = textPattern.test(fieldText);

		if (theID == "addTwo" && fieldText == "") {
			break;
			}


		// IF FIELD IS REQUIRED -- BE SURE IT'S FILLED IN
		if (fieldText == "") {
			fieldMsg.innerHTML = "This field is required.";
			theFlag = "error";
			} else if (results == true) {
			fieldMsg.innerHTML = "Please enter only text, numbers or ! ? . marks in this field.";
			theFlag = "error";
			}


		// MAKE EXCEPTION FOR TRIDENT
		if (window.localStorage.render == "trident" && results == false && fieldText != "") {
			fieldMsg.style.display = "none";
			theField.className = "valid";
			theField.nextElementSibling.firstElementChild.style.display = "inline-block";

			} else if (window.localStorage.render == "trident" && results == false) {
			theField.className = "invalid";

			// HIDE THE ERROR MESSAGE ON SELECTING THE FIELD AGAIN
/* 			theField.addEventListener("click",fieldMsg.style.display="none",false); */
			}

		// SET THE ERROR
		fieldMsg.style.display = "block";
		fieldMsg.className = "";		// clear the error class so we can set it again

		// ATTACH A HOVER EVENT TO ERROR MESSAGE
		// fieldMsg.addEventListener("mouseover",function(e){setFade(theID);e.preventDefault();},false);
		break;



		case "textarea":
		var results = textPattern.test(fieldText);
		var isFocus = /selected/;


		// IF WE HAVE AN ERROR
		if (results == true) {

			// SINCE THERE IS NO HTML PATTERN TEST -- NEED TO ADJUST STYLES HERE
			theField.className = "selected invalid";
			theFlag = "error";
			} else   {

			// SINCE THERE IS NO HTML PATTERN TEST -- NEED TO ADJUST STYLES HERE
			theField.className = "selected valid";

			}


		// MAKE EXCEPTION FOR TRIDENT
		if (window.localStorage.render == "trident" && results == false && fieldText != "") {
			fieldMsg.style.display = "none";
			theField.className = "selected valid";
			theField.nextElementSibling.firstElementChild.style.display = "inline-block";

			} else if (window.localStorage.render == "trident" && results == false) {
			theField.className = "selected invalid";
			// fieldMsg.addEventListener("mouseover",function(e){setFade(theID);e.preventDefault();},false);
			}


		break;


	}

	return theFlag;

	}




/* -- SET UNFOCUSED STYLE FOR TEXTAREAS -- */

function unfocusStyle(theID) {

	var theID = theID;
	var theField = document.getElementById(theID);
	var fieldMsg = theField.nextElementSibling.nextElementSibling;

	// DESELECT THE BACKGROUND COLOR
	var taClass =	theField.className;
	var newClass = taClass.replace("selected ", "");
	theField.className = newClass;

	// IF WE HAVE AN INVALID CHARACTER SHOW AN ERROR CONDITION AND MESSAGE
	if (theField.className == "invalid") {

		// SHOW THE ERROR MESSAGE
		fieldMsg.style.display = "block";

		// FIND THE BOTTOM OF THE TEXTAREA FIELD AND SET THE MESSAGE TO START BELOW IT
		var theTop = theField.offsetTop + theField.offsetHeight + 5;
		fieldMsg.style.top = theTop + "px";

		}

	return;
	}




/* -- VALIDATE CONTACT PAGE MESSAGE -- */

function validMsg(theID) {

	var theID = theID;
	if (window.localStorage.render == "trident") {
		var theResult = true;
		} else {
		var theResult = document.getElementById(theID).checkValidity();
		}

	// PARSE THE FORM ELEMENTS
	var emailAdd = document.getElementById('email').value;
	var theSubject = document.getElementById('subject').value;
	var thePage = document.title.replace("Stanton Park Records -- ", "");
	var aboutPage = document.getElementById('curpage').checked;
	var theMsg = document.getElementById('mess').value;

	// ONE LAST TIME TEST THE MESSAGE FOR ILLEGAL TEXT
	var textPattern = /[\^\$\*\(\)\[\]#%@`:;]/;		// We are looking to match the non-legal characters here
	var taTest = textPattern.test(theMsg);			// TRUE means we found bad chars. FALSE means text is clean

	// IF WE FOUND ILLEGAL CHARS, SET THE MESSAGE TO FALSE
	if (taTest == true) {
		theResult = false;
		}

	/* EXTRA VALIDATION FOR TRIDENT BROWSERS */
	if (window.localStorage.render == "trident") {

		// MAKE SURE ALL REQUIRED FIELDS HAVE SOME VALUE IN THEM
		if (emailAdd == "" || theSubject == "" || theMsg == "") {
			theResult = false;
			}
		}



	if (theResult == true) {

		// PRINT CONFIRMATION BACK TO THE PAGE
		document.getElementById('contactform').className = "hide-form";
		document.getElementById('confirmation').innerHTML = "Thank you for your message. We will respond as soon as possible."

		// PREPARE MESSAGE FOR EMAIL
		var emailMessage = "email=" + emailAdd + "&subject=" + theSubject  + "&page=" + thePage  + "&about=" + aboutPage + "&message=" + theMsg;

		// SEND MESSAGE TO SP
		runExternal("email", emailMessage);

		} else {

		confirm("There were errors in your information. Please check your message again, then resend.");

		}

	return false;
	}




/* -- WRITE A JAVASCRIPT CALL TO PAGE HISTORY -- */

function writeScriptCallHistory (scriptCall) {

	var scriptCall = scriptCall;
	var theScript = scriptCall.shift();	// remove first element from array and assign it to theScript
	var pageName = scriptCall.shift();		// remove first element from array and assign it to pageName

	// TRUNCATE PAGE NAME IF TOO LONG
	if (pageName.length > 35) {
		pageName = (pageName.substring(0,35)) + "&#8230;";	// add only the first 35 chars
		}

	var theArgs = scriptCall.join("','");
	theArgs = "'" + theArgs + "'";		// add quotes around the beginning and end of the args

	// IF NEW SEARCH, WE NEED TO CALL SPECIAL SCRIPT TO RECONSTRUCT THE SEARCH ON THE FLY
	var argTest = pageName.match(/^Search for/);

	if (argTest) {

		// CONCATENATE THE SCRIPT LINE
		var thePage = "<a href='#' onclick=\"reconHistSearch(" + theArgs + "); return false;\">" + pageName + "</a>";

		} else {

		// CONCATENATE THE SCRIPT LINE
		var thePage = "<a href='#' onclick=\"" + theScript + "(" + theArgs + "); return false;\">" + pageName + "</a>";

		}

	// RETRIEVE HISTORY
	var pageHistory = window.localStorage.history;

	// ADD CURRENT PAGE
	pageHistory =  thePage + ":-:" + pageHistory;  // this adds newest page at top

	//WRITE CURRENT PAGE TO HISTORY
	window.localStorage.history = pageHistory
	}




/*
===================================
SEARCH RELATED FUNCTIONS
===================================
*/




/* -- ADVANCED SEARCH - THIS DOES THE ACTUAL SEARCHING FOR LISTS AND SEARCHES-- */

function advancedSearch() {

	var searchBand = window.localStorage.searchBand;
	var searchRecord = window.localStorage.searchRecord;
	var searchLabel = window.localStorage.searchLabel;
	var searchGenre = window.localStorage.searchGenre;	// only happens when you search from list clicking alt/indie button, etc....
	var searchFormat = window.localStorage.searchFormat;	// happens when you search from list or BROWSE BUTTONS
	var relatedSearch = window.localStorage.searchType;	// if this is supposed to return related events
	var start = window.localStorage.startAt;			// where to start in the search

	// LOAD FILTERS
	var filterFormat = window.localStorage.filterFormat;
	var filterGenre = window.localStorage.filterGenre;
	if (window.localStorage.filterLabel != "") {
		searchLabel = window.localStorage.filterLabel;		// if we are filtering by label, it's the same as searching by label, so use the search by label function
		}
	var foundRecords = "";


	// INTITIALIZE FORMAT COUNT OBJECT
	fmtCnt = new Array();
	fmtCnt.singles = 0;
	fmtCnt.albums = 0;
	fmtCnt.cds = 0;
	fmtCnt.zines = 0;

	// INTITIALIZE GENRE COUNT OBJECT
	genreCnt = new Array();
	genreCnt.alt = 0;
	genreCnt.bos = 0;
	genreCnt.gar = 0;
	genreCnt.pun = 0;
	genreCnt.six = 0;

	// INITIALIZE LABEL MENU ARRAY
	labelMenu = "";

	// MAKE SURE THAT THE FORM HAS AT LEAST ONE SEARCH QUERY -- ELSE KICK IT BACK WITH AN ALERT
	if (searchBand == "" && searchRecord == "" && searchLabel == "" && searchGenre == "" && searchFormat == "") {
		alert("You must enter at least one search term.");
		document.getElementById('band').select();
		document.getElementById('band').focus();

		document.getElementById('band').nextElementSibling.style.display = "inline";
		document.getElementById('record').nextElementSibling.style.display = "inline";
		document.getElementById('label').nextElementSibling.style.display = "inline";

		// DRAW ARROWS
		drawErrorArrow('advanced');
		return false;
		}


	/* MATCH AGAINST FORMATS */

	// LOAD THE CATALOG
	var theList = window.localStorage.catalog;


	var listArray = new Array();
	var listArray = theList.split("</li>");

	// CHECK FOR MATCHES TO TERMS

	for (i=0; i < listArray.length-1; i++) {

		// RESET VARIABLES
		var mainFlag = "true";
		var theSlice = listArray[i];
		var theFormat = "";		// reset the filter var
		var theGenre = "";		// reset the filter var

		// IF SEARCHBAND HAS A VALUE -- SEARCH
		if (searchBand != "") {

			// PREP BAND QUERY
			var bandQuery = /<span>.*:/;					// REGEX TO EXTRACT BAND FROM LINE ITEM
			var bandSlice = theSlice.match(bandQuery);		// THE BAND FROM THE LINE ITEM
			bandSlice = bandSlice.toString();				// CONVERT TO STRING TO CLEAN
			bandSlice = bandSlice.replace("<span>", "");		// GET RID OF HTML TAB
			bandSlice = bandSlice.replace(":", "");			// GET RID OF : FROM THE END

			// SET SLICE AND SEARCH TO LOWER CASE
			bandSlice = bandSlice.toLowerCase();
			searchBand = searchBand.toLowerCase();

			// TEST THE PATTERN -- IF SEARCHBAND VALUE IS CONTAINED IN THE BANDSLICE VALUE, IT IS SUCCESSFULL
			if (bandSlice.search(searchBand, "i") != -1) {
				} else {
				mainFlag = false;
				}

			}

		// IF SEARCHRECORD HAS A VALUE
		if (searchRecord != "")	{

			// PREP RECORD QUERY
			var recordQuery = /: [^<]*<\//;					// REGEX TO EXTRACT record FROM LINE ITEM
			var recordSlice = theSlice.match(recordQuery);		// THE RECORD FROM THE LINE ITEM
			recordSlice = recordSlice.toString();				// CONVERT TO STRING TO CLEAN
			recordSlice = recordSlice.replace(": ", "");		// GET RID OF HTML TAB
			recordSlice = recordSlice.replace(" \$", "");			// GET RID OF : FROM THE END

			// SET SLICE AND SEARCH TO LOWER CASE
			recordSlice = recordSlice.toLowerCase();
			searchRecord = searchRecord.toLowerCase();

			// TEST THE PATTERN -- IF SEARCHRECORD VALUE IS CONTAINED IN THE recordSLICE VALUE, IT IS SUCCESSFULL
			if (recordSlice.search(searchRecord, "i") != -1) {
				} else {
				mainFlag = false;
				}
			}

		// IF SEARCHLABEL HAS A VALUE
		if (searchLabel != "") {

			// PREP LABEL QUERY
			var labelQuery = /"label">.*?</;					// REGEX TO EXTRACT label FROM LINE ITEM
			var labelSlice = theSlice.match(labelQuery);		// THE label FROM THE LINE ITEM
			labelSlice = labelSlice.toString();				// CONVERT TO STRING TO CLEAN
			labelSlice = labelSlice.replace("\"label\">", "");		// GET RID OF HTML TAB
			labelSlice = labelSlice.replace("<", "");			// GET RID OF : FROM THE END

			// SET SLICE AND SEARCH TO LOWER CASE
			labelSlice = labelSlice.toLowerCase();
			searchLabel = searchLabel.toLowerCase();

			// TEST THE PATTERN -- IF SEARCHLABEL VALUE IS CONTAINED IN THE labelSLICE VALUE, IT IS SUCCESSFULL
			if (labelSlice.search(searchLabel, "i") != -1) {
				} else {
				mainFlag = false;
				}
			}

		// IF SEARCHGENRE HAS A VALUE  -- THIS IS A SEARCH RATHER THAN FILTERING EXISTING SEARCHES
		if (searchGenre != "") {
			theGenre = theSlice.substr(19,1);

			// IF THE FORMAT FOR THIS TITLE IS NOT THE CHOSED FORMAT, REMOVE IT FROM THE LIST
			if (theGenre != searchGenre) {
				mainFlag = false;
				}
 			}

		// IF SEARCHFORMAT HAS A VALUE  -- THIS IS A SEARCH RATHER THAN FILTERING EXISTING SEARCHES
		if (searchFormat != "") {
			theFormat = theSlice.substr(16,2);

			// IF THE FORMAT FOR THIS TITLE IS NOT THE CHOSED FORMAT, REMOVE IT FROM THE LIST
			if (theFormat != searchFormat) {
				mainFlag = false;
				}
			}

		// IF THIS ITEM IS MATCHES A TERM -- NEXT APPLY THE FORMAT AND GENRE FILTERS IF THEY HAVE BEEN REQUESTED
		if (mainFlag) {

			// FILTER BY FORMAT
			if (filterFormat != "") {
				theFormat = theSlice.substr(16,2);
				// IF THE FORMAT FOR THIS TITLE IS NOT THE CHOSED FORMAT, REMOVE IT FROM THE LIST
				if (theFormat != filterFormat) {
					mainFlag = false;
					}
				}

			// FILTER BY GENRE
			if (filterGenre != "") {
				theGenre = theSlice.substr(19,1);
				// IF THE FORMAT FOR THIS TITLE IS NOT THE CHOSED FORMAT, REMOVE IT FROM THE LIST
				if (theGenre != filterGenre) {
					mainFlag = false;
					}
				}
			}

		// AS LONG AS AN ITEM HAS NOT BEEN FLAGGED FALSE - ADD TO LIST
		if (mainFlag) { //

			updateFmtCnt(theSlice);
			buildLabelMenu(theSlice);
			foundRecords += theSlice + "</li>";
			}
		}



	if (foundRecords != "") {

		var searchType = "all";

		// SEARCH BY GENRE
		if  (searchGenre != "") {
			searchType = "category";
			}

		// SEARCH TYPE IS BAND
		if (searchBand != "" && searchRecord == "" && searchGenre == "" && searchLabel == "" && searchFormat == "")	{
			searchType = "band";
			}

		// SEARCH TYPE IS RECORD
		if (searchBand == "" && searchRecord != "" && searchGenre == "" && searchLabel == "" && searchFormat == "")	{
			searchType = "record";
			}

		// SEARCH TYPE IS LABEL
		if (searchBand == "" && searchRecord == "" && searchGenre == "" && searchLabel != "" && searchFormat == "")	{
			searchType = "label";
			}

		// SEARCH TYPE IS LIST FORMAT --- BROWSE!
		if (searchBand == "" && searchRecord == "" && searchGenre == "" && searchLabel == "" && searchFormat != "")	{
			searchType = "listformat";
			}

		// IF THIS IS A REALTED SEARCH RETURN THE RESULTS AND EXIT SCRIPT (NO DISPLAY LIST)
		if (relatedSearch == "related") {
			document.getElementById('list').innerHTML = foundRecords

			// HIDE THE TRACKS TAB AND SHOW THE RESULTS TAB
			document.getElementById('tracks').style.display = "none";
			document.getElementById('related').style.display = "block";
			return;
			}


		// SEND FOUND RECORDS TO DISPLAY LIST FUNCTION  -- data is (found list, [all or spec format] );
		displayList(foundRecords, searchType, "advanced", start);

		// FADE OUT OVERLAY HERE
		hideOverlay('advanced-search');

		// MAKE SURE THAT SEARCH BUTTON IS NOT STILL ACTIVE
		document.getElementById('searchbutton').className = "click";
		document.getElementById('searchbutton').parentNode.className = "";

		} else {

		// IF THERE ARE NO SEARCHES, SEND A MESSAGE BACK TO BROWSER
		document.getElementById('msg').innerHTML = "Your search terms found no matches. Please try again with a more general search.";
		document.getElementById('msg').className = "alertmsg";
		}

	return false;
	}




/* -- APPLY A FILTER TO A SEARCH THAT HAS ALREADY STARTED -- */

function applyFilter (type, value, wild) {
	var type = type;
	var value = value;
	var wild = wild;

	var pageName = "";

	switch (type) {
		case "format":
		window.localStorage.filterFormat = value;
		filterName = "Filter search by " + mediaType[value];
		break;

		case "genre":
		window.localStorage.filterGenre = value;
		filterName = "Filter search by " + genreType[value];
		break;

		case "label":
		window.localStorage.filterLabel = value;
		filterName = "Filter search by " + value;
		break;
		}

	// WRITE THIS CALL TO PAGE HISTORY
	var scriptElements = new Array ("applyFilter", filterName, type, value, wild);
	writeScriptCallHistory(scriptElements);

	// RESET START COUNTER TO 0 WHEN APPLYING FILTERS
	window.localStorage.startAt = 0;

	// SEND TO advancedSearch TO REFRESH THE RESULT
	advancedSearch();
	}




/* -- BUILD FILTER LABEL MENU -- */

function buildLabelMenu(theSlice) {
	var theSlice = theSlice;

	// PREP LABEL QUERY
	var labelQuery = /"label">.*?</;					// REGEX TO EXTRACT label FROM LINE ITEM
	var labelSlice = theSlice.match(labelQuery);		// THE label FROM THE LINE ITEM
	labelSlice = labelSlice.toString();				// CONVERT TO STRING TO CLEAN
	labelSlice = labelSlice.replace("\"label\">", "");		// GET RID OF HTML TAB
	labelSlice = labelSlice.replace("<", "");			// GET RID OF : FROM THE END

	// SEE IF THE LABEL IS ALREADY IN LIST
	if (labelMenu.search(labelSlice, "i") != -1) {
		// LABEL HAS ALREADY BEEN ADDED
		} else {
		// ADD THE LABEL TO THE LIST
		labelMenu += "<li><a href='#' onclick='applyFilter(\"label\", \"" + labelSlice + "\"); return false;'>" + labelSlice + "</a></li>";
		}
	}




/* -- INTERCEPT KEYS IN HINTS FIELD TO TRIGGER EVENTS -- */

function checkKey(evt) {

	// GET THE KEY PRESSED
	var theKey = evt.keyCode;


	// GET VALUE OF THE SEARCH FIELD
	var theSearch = document.getElementById('hints').value;

	/* DECIDE HOW TO HANDE THE KEYSTROKE */

	// IF THIS IS A RETURN OR ENTER KEY, SEARCH FOR THE HINT
	if (theKey == 13) {    // maybe also need to see of the hints field is selected as well -- may be the issue

		var hintField = document.getElementById('hints');

		// MAKE SURE THE HINTS FIELD IS FOCUSED BEFORE SENDING SEARCH
		if (document.getElementById('hints').focus){
			searchFromHints();
			} else {
			hintField.focus();
			searchFromHints();
			}

		return;
		}

	// ESCAPE KEY -- Close form
	if (theKey == 27) {
		document.getElementById('search-results').innerHTML = "";  // CLEAR SEARCH RESULTS
		document.getElementById('hints').value = "";
		document.getElementById('hints').blur();
		return;
		}

	// DELETE KEY AND EMPTY SEARCH FIELD -- close resultDiv
	if (theKey == 8 && theSearch == "") {
		document.getElementById('search-results').style.display = "none";
		return;
		}

	// DETERMINE DIRECTION TO GO AND CALL FUNCTION TO CHANGE THE SELECTION IN MENU
	if (theKey == 40) {
		getSelected("next");
		return;
		} else if (theKey == 38) {
		getSelected("prev");
		return;
		}

	// IF THIS IS A REGULAR CHARACTER KEY -- call getHints()
	if (theKey != 13 && theKey != 27 && theKey != 38 && theKey != 40) {
		getHints();
		return;
		}

	return;
	}




/* -- DISPLAY LIST AND SEARCH RESULTS -- */

function displayList (foundRecords, genre, type, start) {


	// INITIALIZE VARIABLES
	var foundRecords = foundRecords;
	var genre = genre;
	var type = type;
	var start = start;
	var displaySet = "";
	var header = "";
	var subheader = "";
	var searchTerms = "";
	var filterBy = "";
	var itemsFound = "";
	var totalFound = "";
	var formatFilter = "";
	var genreFilter = "";

	// LOAD FILTERS FROM LOCAL STORAGE

	var searchBand = window.localStorage.searchBand;			// FOR HINTS
	var searchRecord = window.localStorage.searchRecord;		// FOR HINTS
	var searchFormat = window.localStorage.searchFormat;
	var searchGenre = window.localStorage.searchGenre;
	var searchType = window.localStorage.searchType;			// FOR HINTS
	var filterFormat = window.localStorage.filterFormat;
	var filterGenre = window.localStorage.filterGenre;
	var filterLabel = window.localStorage.filterLabel;


	// IF THIS IS A SEARCH, GET SEARCH TERMS FROM FORM     **************
	if (type == "advanced" && searchType != "hints") {
		var searchBand = document.getElementById('band').value;
		var searchRecord = document.getElementById('record').value;
		var searchLabel = document.getElementById('label').value;
		}


	// SET SUBHEADER INFO HERE
	theGenre = genreType[filterGenre];
	theFormat = mediaType[filterFormat];

	// IF WE SEARCHED RATHER THAN FILTERED
	if (searchGenre != "") {
		theGenre = genreType[searchGenre];
		}

	// SEARCH BY LABEL
	if (genre == "label") {
		searchBand = "";
		searchRecord = "";
		searchLabel = window.localStorage.searchLabel;
		}

	// SERACH BY CATEGORY
	if (genre == "category") {
		searchBand = "";
		searchRecord = "";
		searchLabel = "";
		}

	// IF SEARCH BY LIST
	var genreTest = genre.match(/^list/);
	if (genreTest) {
		searchBand = "";
		searchRecord = "";
		searchLabel = "";
		}



	/*  POPULATE THE INFORMATION ID IN SIDEBAR	*/

	// SET UP SEARCH TERMS LINE -- WILL BE DIFF FOR DIFF TYPES OF SEARCH

	if (searchBand !="") {
		searchTerms += "<span class='sc'>band: </span>" + searchBand + "<br /> ";
		}

	if (searchRecord !="") {
		searchTerms += "<span class='sc'>record: </span>" + searchRecord + "<br /> ";
		}

	if (searchLabel !="" && searchType != "hints") {
		searchTerms += "<span class='sc'>label: </span>" + searchLabel + " ";
		}

	if (searchGenre !="") {
		searchTerms += "<span class='sc'>category: </span>" + genreType[searchGenre] + " ";
		}

	if (searchFormat !="") {
		searchTerms += "<span class='sc'>format: </span>" + mediaType[searchFormat] + " ";
		theFormat = mediaType[searchFormat]; // set this only if we are browsing
		}

	// SET UP FILTER INFORMATION
	if (filterGenre != "") {
		filterBy = "<li><span class='sc'>filter category</span>: " + genreType[filterGenre] + "</li>";
		}

	if (filterFormat !="") {
		filterBy += "<li><span class='sc'>filter format</span>: " + mediaType[filterFormat] + "</li>";
		}

	if (filterLabel !="") {
		filterBy += "<li><span class='sc'>filter label</span>: " + filterLabel + "</li>";
		}


	/* FORMAT COUNT */

	// SINGLES COUNT
	if (fmtCnt.singles > 0) {
		itemsFound = "<strong>45s - </strong>" + fmtCnt.singles + "";
		formatFilter = "<a href='#' title='Show 45s Only' onclick='applyFilter(\"format\", \"45\"); return false;'>45s</a>";

		if (fmtCnt.singles == 1) {
			itemsFound = itemsFound.replace("45s", "45");
			}
		}

	// ALBUMS COUNT
	if (fmtCnt.albums > 0) {
		if (itemsFound != "") {
			itemsFound += ", ";
			}

		itemsFound += "<strong>LPs - </strong>" + fmtCnt.albums + "";
		formatFilter += "<a href='#' title='Show LPs Only' onclick='applyFilter(\"format\", \"LP\"); return false;'>LPs</a>";

		if (fmtCnt.albums == 1) {
			itemsFound = itemsFound.replace("LPs", "LP");
			}
		}

	// CDS COUNT
	if (fmtCnt.cds > 0) {
		if (itemsFound != "") {
			itemsFound += ", ";
			}

		itemsFound += "<strong>CDs - </strong>" + fmtCnt.cds + "";
		formatFilter += "<a href='#' title='Show CDs Only ' onclick='applyFilter(\"format\", \"CD\"); return false;'>CDs</a>";

		if (fmtCnt.discs == 1) {
			itemsFound = itemsFound.replace("CDs", "CD");
			}
		}

	// ZINES COUNT
	if (fmtCnt.zines > 0) {
		if (itemsFound != "") {
			itemsFound += ", ";
			}

		itemsFound += "<strong>MGs - </strong>" + fmtCnt.zines + "";
		formatFilter += "<a href='#'  title='Show Magazines Only' onclick='applyFilter(\"format\", \"MG\"); return false;'>ZINES</a>";

		if (fmtCnt.zines == 1) {
			itemsFound = itemsFound.replace("MGs", "MG");
			}
		}


	if (itemsFound == "") {
		itemsFound = "Your search found 0 matches.";
		} else {
		itemsFound = "<span class='sc'>found</span>: " + itemsFound;
		}


	/* GENRE FILTER BUTTONS */

	// ALT/INDIE COUNT
	if (genreCnt.alt > 0) {
		genreFilter = "<a href='#' title='Show Alt/Indie Titles' onclick='applyFilter(\"genre\", \"A\"); return false;'>ALT</a>";
		}

	if (genreCnt.bos > 0) {
		genreFilter += "<a href='#' title='Show Boston Area Titles' onclick='applyFilter(\"genre\", \"B\"); return false;'>BOSTON</a>";
		}

	if (genreCnt.gar > 0) {
		genreFilter += "<a href='#' title='Show Garage/Psych Titles' onclick='applyFilter(\"genre\", \"G\"); return false;'>GARAGE</a>";
		}

	if (genreCnt.pun > 0) {
		genreFilter += "<a href='#' title='Show Punk Titles' onclick='applyFilter(\"genre\", \"P\"); return false;'>PUNK</a>";
		}

	if (genreCnt.six > 0) {
		genreFilter += "<a href='#' title='Show Sixties Garage/Rock Titles' onclick='applyFilter(\"genre\", \"S\"); return false;'>60s</a>";
		}


	// ADD TO INFORMATION BOX IN SIDEBAR
	var infoItems = "<li>" + searchTerms + "</li>";			// you searched for
	infoItems += filterBy;								// filtered by
	infoItems += "<li>" + itemsFound + "</li>";				// what was found

	// MAKE SURE WE DON'T HAVE THE ORDER SUBHEAD IN THE SIDEBAR BOX -- IF SO REPLACE WITH REGULAR INFORMATION BOX
	if (document.getElementById('information-collapsed')){
		if (document.getElementById('information-collapsed').firstElementChild.innerHTML == "Order Status"){
			document.getElementById('information-collapsed').innerHTML = "<h3>You searched for&#8230;</h3><ul id='information-items'></ul>";
			}
		}


	// MAKE SURE OTHER SIDEBAR ITEMS ARE CLOSED FIRST
	closeAll();

	document.getElementById('information-items').innerHTML = infoItems;
	showPane("information");

//	document.getElementById('information').className= "mod-part";
//	document.getElementById('information').style.display = "block";		// show info block

	/* SET THE PROPER CLASS */
	document.getElementById('main-copy').className = "list";

	/* SET UP FILTER BUTTONS */

/* 	var removeFilterButton = "<span class='narrow' title='Remove filter'><a href='#' onclick='removeFilter(\"INSERT\"); return false;'>&#10008;</a></span>"; */
	var removeFilterButton = "<span class='narrow' title='Remove filter'><a href='#' id='remove-INSERT'>&#10008;</a></span>";
	var removeFormatFilter = "";
	var removeGenreFilter = "";
	var removeLabelFilter = "";
	var filterActive = "";

	// CREATE BUTTON IF THERE IS AN ACTIVE FILTER
	if (filterFormat) {
		removeFormatFilter = removeFilterButton.replace("INSERT", "format");
		filterActive = true;
		}

	if (filterGenre) {
		removeGenreFilter = removeFilterButton.replace("INSERT", "genre");
		filterActive = true;
		}

	if (filterLabel) {
		removeLabelFilter = removeFilterButton.replace("INSERT", "label");
		filterActive = true;
		}


	// SORT LABEL MENU
	labelMenu = sortLabelMenu(labelMenu);

	// BUILD THE FILTER BUTTONS
	var filterButtons = "Filter Your Results: ";
	filterButtons += "<span class='genre-buttons'>Category: " + genreFilter + removeGenreFilter + "</span>";
	filterButtons += "<span class='genre-buttons'>Format: " + formatFilter + removeFormatFilter + "</span>";
 	filterButtons += "<div class='wrap'><span class='genre-buttons' id='label-button' onmouseover='showLabelList(); return false;' onmouseout='closeLabelList(); return false;'>Label: <a href='#' class='labelfilter' id='da' onclick='return false;'><canvas  width='16' height='10' id='down-arrow'></canvas></a>" + removeLabelFilter +  "<ul id='label-menu'>" + labelMenu + "</ul></span></div>";

	// IF ANY FILTERS ARE ACTIVE SHOW THE CLEAR ALL BUTTON
	if (filterActive) {
		/* filterButtons += "<div id='closmess3'>Remove All Filters.</div><div id='remove-all'><span class='narrow' title='Remove all filters'><a href='#' onmouseover='showMessage(\"closmess3\");'  onmouseout='showMessage(\"closmess3\");'  onclick='removeFilter(\"all\"); return false;'>&#10008;</a></span></div>"; */
		filterButtons += "<div id='closmess3'>Remove All Filters.</div><div id='remove-all'><span class='narrow' title='Remove all filters'><a href='#' id='remove-all-filters'>&#10008;</a></span></div>";
		}

	// CONCATENATE HEADLINE
	switch (genre) {

		// SEARCH FOR ALL
		case "all":
		header = "Search Results";
		break;

		// SEARCH FOR GENRES
		case "category":
		header = "Search by Category";
		break;

		// SEARCH FOR LABEL
		case "band":
		header = "Search by Band";
		break;

		// SEARCH FOR LABEL
		case "record":
		header = "Search by Record";
		break;

		// SEARCH FOR LABEL
		case "label":
		header = "Search for Label";
		break;

		// SEARCH BY FORMAT
		case "format":
		header = "Search by Format";
		break;

		// LIST BY FORMAT
		case "listformat":
		header = "List by Format";
		break;

		}

	// GET THE HEIGHT OF YOUR MAIN COPY AREA
	var mainContent = document.getElementById('main-copy')
	var contentHeight = mainContent.style.height;
	contentHeight = contentHeight.replace("px", "");
	var calcHeight = contentHeight - 90;
	var itemsAllowed = parseInt(calcHeight/25);  // each <li> plus padding/border = approx 25px

	// START PROCESSING FOUND DATA
	var foundSet = new Array();
	foundSet = foundRecords.split("</li>");
	var totalFound = foundSet.length;			// found records
	totalFound--;

	// INITIALIZE BUTTON FLAGS HERE
	var nextButton = false;
	var prevButton = false;

	// CALCULATE THE LAST ITEM ALLOWED
	lastItemAllowed = parseInt(start) + parseInt(itemsAllowed);

	// MAKE SURE WE DON'T TRY TO DISPLAY MORE THAN WERE FOUND
	if (lastItemAllowed > totalFound) {
		lastItemAllowed = totalFound;
		}

	// IF WE ARE IN THE MIDDLE OF THE FOUND SET
	if (totalFound > itemsAllowed && start < totalFound) {
		nextButton = true;
		prevButton = true;
		}

	// IF WE ARE ON THE FIRST PAGE AND TOTAL FOUND ARE MORE THAN ITEMS ALLOWED
	if (start == 0 && itemsAllowed < totalFound) {
		nextButton = true;
		}


	// MAKES SURE WE DON'T HAVE A NEXT BUTTON IF IT STARTS BEYOND TOTAL FOUND
	if (start > totalFound) {
		nextButton = false;
		}

	// IF THE LAST ITEM ALLOWED IS THE SAME AS TOTAL FOUND, DON'T DISPLAY A NEXT BUTTON
	if (lastItemAllowed == totalFound) {
		nextButton = false;
		}

	// MAKES SURE WE DON'T HAVE A PREV BUTTON ON THE FIRST SET OF RESULTS
	if (start < itemsAllowed) {
		prevButton = false;
		}


	// CALCULATE AND WRITE THE NEW START VALUE TO LOCAL STORAGE
	var nextResults = "";
	var prevResults = "";
	var navArrows = "<span id='nav-arrows'>";
	var drawNext = false;
	var drawPrev = false;

	// LIST ITEM RANGE HERE
	startVal = parseInt(start) + 1;	// ACCOUNT FOR STARTING AT 0
	var displaying = startVal  + "&#8211;" + lastItemAllowed + " of " + totalFound;


	// IF WE NEED A NEXT BUTTON, SET IT UP HERE
	if (prevButton){
		newStart = parseInt(start) - parseInt(itemsAllowed); 		// calculate the new starting value if next is clicked

		// NO NEGATIVE NUMBERS
		if (newStart < 0) {
			newStart = 0;
			}

		// ON CLICK, UPDATE THE NEW START THEN LOAD THE ADVANCED SEARCH
		navArrows += "<a href='#' onclick='setStart(" + newStart + "); advancedSearch(); return false;'><canvas  width='16' height='16' id='prev-arrow'></canvas></a>";
		drawPrev = true;
		}

	// IF WE NEED A NEXT BUTTON, SET IT UP HERE
	if (nextButton){
		newStart = parseInt(start) + parseInt(itemsAllowed); 		// calculate the new starting value if next is clicked

		// ON CLICK, UPDATE THE NEW START THEN LOAD THE ADVANCED SEARCH
		navArrows += "<a href='#' onclick='setStart(" + newStart + "); advancedSearch(); return false;'><canvas  width='16' height='16' id='next-arrow'></canvas></a>";
		drawNext = true;
		}
	navArrows += "</span>";

	// SET THE STATUS BAR
	subheader = "<h2 class='list'><strong>Category:</strong> " + theGenre + "  <strong style='margin-left:20px;'>Format:</strong> " + theFormat + "  <strong style='margin-left:20px;'>Displaying:</strong> " + displaying + "</h2>";

	// DISPLAY THE FOUND RECORDS HERE -- BROKEN INTO BLOCKS BASED ON AVAILABLE DIV HEIGHT
	for (i = start; i < lastItemAllowed; i++) {

		// FIX EMPTY LABEL STYLE
		var searchTerm = "class=\"label\"><";
		var noLabel = "class=\"nolabel\"><";

		foundSet[i] = foundSet[i].replace(searchTerm, noLabel);

		displaySet += foundSet[i] + "</li>";
		}



	displayItems = "<hgroup><h1 class='list'>" + header + "</h1>" + subheader + navArrows + "</hgroup><div class='reverse'>" + filterButtons + "</div><ul id='list'>" + displaySet + "</ul>";



	// WRITE TO PAGE
	mainContent.innerHTML = displayItems;


	// IF FILTERS EXIST -- ATTACH EVENT TO CLOSE BUTTONS
	if (document.getElementById('remove-all-filters')) {
		var removeAll = document.getElementById('remove-all-filters');
		removeAll.addEventListener("click",function(e){removeFilter("all");e.preventDefault();},false);
		removeAll.addEventListener("mouseover",function(e){showMessage("closmess3");},false);
		removeAll.addEventListener("mouseout",function(e){showMessage("closmess3");},false);
		}

	if (document.getElementById('remove-format')) {
		var removeFormat = document.getElementById('remove-format');
		removeFormat.addEventListener("click",function(e){removeFilter("format");e.preventDefault();},false);
		}


	if (document.getElementById('remove-genre')) {
		var removeGenre = document.getElementById('remove-genre');
		removeGenre.addEventListener("click",function(e){removeFilter("genre");e.preventDefault();},false);
		}

	if (document.getElementById('remove-label')) {
		var removeLabel = document.getElementById('remove-label');
		removeLabel.addEventListener("click",function(e){removeFilter("label");e.preventDefault();},false);
		}



	// DRAWS ARROWS ON PAGE -- PAGE MUST BE VISIBLE TO CANVAS SCRIPT
	drawDownArrow("down-arrow");

	if (drawNext == true) {
		listNavButtons("next-arrow", "black");

		// ADD HOVER STATE
		var nextBut = document.getElementById('next-arrow');
		nextBut.addEventListener("mousedown",function(e){listNavButtons("next-arrow", "orange");},false);
		nextBut.addEventListener("mouseover",function(e){listNavButtons("next-arrow", "red");},false);
		nextBut.addEventListener("mouseout",function(e){listNavButtons("next-arrow", "black");},false);
		}

	if (drawPrev == true) {
		listNavButtons("prev-arrow", "black");

		// ADD HOVER STATE
		var prevBut = document.getElementById('prev-arrow');
		prevBut.addEventListener("mousedown",function(e){listNavButtons("prev-arrow", "orange");},false);
		prevBut.addEventListener("mouseover",function(e){listNavButtons("prev-arrow", "red");},false);
		prevBut.addEventListener("mouseout",function(e){listNavButtons("prev-arrow", "black");},false);
		}

	}




/* -- FIND RELATED ITEMS FROM DETAIL PAGE -- PUT SEARCH QUERY IN LOCAL STORAGE AND SEND TO ADVANCED SEARCH -- */

function findRelated (type, term) {
	var type = type;
	var term = term;
	var theHeadline = "";

	// SET CATEGORY HEADLINES
	var categoryHeads = new Array();
	categoryHeads["A"] = 'Alt/Indie';
	categoryHeads["B"] = 'Boston Area';
	categoryHeads["G"] = 'Garage/Psych';
	categoryHeads["P"] = 'Punk';
	categoryHeads["S"] = 'Sixties';

	// CLEARS STORED SEARCH VALUES
	resetStoredSearch();

	switch (type) {
		case "band":
		window.localStorage.searchBand = term;
		theHeadline = "Other Records by " + term;
		break;

		case "label":
		window.localStorage.searchLabel = term;
		theHeadline = "Other Records Released by " + term;
		break;

		case "category":
		var catTerms = term.split(":-:");
		window.localStorage.searchFormat = catTerms[0];
		window.localStorage.filterGenre = catTerms[1];
		theHeadline = "Other " + categoryHeads[catTerms[1]] + " " + catTerms[0] + "s";
		break;
		}

	// SET SEARCH TYPE TO RELATED
	window.localStorage.searchType = "related";

	// SELECT PROPER TAB
	var theTabs = new Array ("track-tab", "band-tab", "label-tab", "category-tab");

	// DESELECT ALL TABS
	for (i = 0; i < theTabs.length; i++) {
		document.getElementById(theTabs[i]).className = "";
		}

	// SELECT PROPER TAB
	document.getElementById(type + '-tab').className = "selected";

	// SET THE HEADLINE
	document.getElementById('related-head').innerHTML = theHeadline;

	// GO TO SEARCH NOW
	advancedSearch();

	// SET THE PROPER HEIGHT SO THAT PAGE CONTENT STAYS INSIDE LAYOUT
	document.getElementById('content').style.height = 100 + "%";
	document.getElementById('main-copy').style.height = 100 + "%";

	// NOW DOUBLE CHECK TO BE SURE THAT MIN HEIGHTS ARE GOOD

	// IF MAIN -112 (HEADER) IS LONGER THAN CONTENT, SET CONTENT TO MAIN HEIGHT
	var mainHeight = document.getElementById('main').offsetHeight;		// the main div's height
	var contentHeight = document.getElementById('content').offsetHeight;		// the content div's height

	// DON'T COUNT THE HEADER'S HEIGHT
	var theDiff = mainHeight-104;
	var mainCopyDiff = mainHeight-159;

	// THESE SET THE HEIGHTS ONLY IF WINDOW IS TALLER THAN THE CONTENT  -- KEEPS LONG CONTENT FROM OVERFLOWING
	if (mainHeight > contentHeight) {
		document.getElementById('content').style.height = theDiff + "px";
		document.getElementById('main-copy').style.height = mainCopyDiff + "px";
		}

	return false;
	}




/* -- SEARCH LISTS AND CREATE HINT LIST -- */

function getHints() {

	var theSearch = document.getElementById('hints').value;
	var searchTerm = new RegExp('^' + theSearch, 'gi'); 				// REGEXP TO LOOK FOR BAND/RECORD THAT STARTS WITH TERM
	var resultDiv = document.getElementById('search-results');
	var theField = document.getElementById('field').value;				// IS THIS BAND OR RECORD HINT
	var theList = "";											// LIST OF BANDS OR RECORDS
	var searchList = new Array();
	var searchResults = "";

	// CHECK IF BAND/RECORD SEARCH TERMS ARE POPULATED
	if (theField == "band" && window.localStorage.bands == "") {
		runExternal('bandList', '');
		}

	if (theField == "record" && window.localStorage.records == "") {
		runExternal('recordList', '');
		}

	// PARSE THE CORRECT LIST
	if (theField == "band") {
		theList = window.localStorage.bands;
		searchList = theList.split(":-:");
		} else {
		theList = window.localStorage.records;
		searchList = theList.split(":-:");
		}

	// RUN HINTS SEARCH HERE AND FORMAT RESULTS AS LIST
	// MATCH TERMS IN BAND LIST AND SET UP LIST OF FOUND ITEMS
	var j = 0;
	for (i in searchList) {
		if (searchList[i].match(searchTerm)) {
			searchResults = searchResults + "<li id='m" + j + "' onclick='setSearch(this.textContent);'>" + searchList[i] + "</li>";

			j++; //up the j counter to keep ids sequential

			// GET FIRST 22 MATCHES ONLY
			if (j == 22) {
				break;
				}

			}
		}

	// CHECK IF RESULT DIV IS ACTIVE
/* 	resultDiv.style.display = "block"; */
	resultDiv.className = "short";

	// ADD RESULTS TO PAGE
	resultDiv.innerHTML = searchResults;
	return;
	}




/* -- PUT SELECTED ITEM FROM HINT LIST IN HINTS FORM FIELD -- */

function getSelected(direction){

	var direction = direction;
	var ul = document.getElementById('search-results');
	var li = ul.getElementsByTagName('li').length;
	var i = 0;
	var hints = new Array();
	var selected = new Array();
	var selectedItem = -1;
	var selectNext = "";
	var selectPrev = "";
	var nextItem = "";
	var theLast = "";

	// GET HINTS FROM CURRENTLY DISPLAYED ITEMS AND FIND THE SELECTED ITEM
	for (i=0; i < li; i++) {
		hints[i] = ul.childNodes[i].innerHTML;
		selected[i] = ul.childNodes[i].className;

		// IF THE ITEM IS SELECTED SET UP THE INDEXES FOR THE NEXT/PREV IDS
		if (selected[i] == "selected") {

			// RESET NEXT/PREV ITEMS
			selectNext = "";
			selectPrev = "";

			// CURRENT SELECTION
			selectedItem = i;

			// SET THE NEXT AND PREVIOUS ITEMS. CHECK THAT THEY'RE NOT OUT OF THE SCOPE OF THE LIST
			if (i < li) {
				selectNext = i + 1;
				} else {
				selectNext = li-1;
				}

			if (i > 0) {
				selectPrev = i - 1;
				} else {
				selectPrev = 0;
				}

			}
		}

	// IF NOTHING IS SELECTED, THEN DEFAULT IS THE FIRST ITEM HERE
	if (selectNext == "") {
		selectedItem = -1;
		selectNext = 0;
		selectPrev = 0;
		}

	// IF WE'VE REACHED THE LAST ITEM, DO NOT ALLOW IT TO GO TO THE "NEXT" ITEM
	if (selectNext == li) {
		theLast = true;
		selectedItem = li-1;
		selectNext = li-1;
		selectPrev = li-2;
		}

	// NOW SET THE NEXT ITEM ID AND APPLY THE FOUND BAND IN THE SEARCHTERM FIELD
	if (direction == "next") {
		nextItem = "m" + selectNext;
		document.getElementById("hints").value = hints[selectNext];
		} else {
		nextItem = "m" + selectPrev;
		document.getElementById("hints").value = hints[selectPrev];
		}

	// SET SELECTED ITEM ID
	var selItem = "m" + selectedItem;

	// IF THIS ITEM IS CLICKED ON, SEND THE ID BACK TO CHECKKEYS
	if (direction == "current") {
		alert(selItem);
		}

	// CHANGE THE SELECTION MODE OF THE DIVS
	document.getElementById(nextItem).className = "selected";

	// SET A FLAG TO TURN OFF THE SELECTED ITEM IF APPROPRIATE
	var turnOff = true;

	if (selectedItem == -1) {
		if (direction == "next") {
			turnOff = false;
			}
		}


	if (selectedItem == 0) {
		if (direction == "prev") {
			turnOff = false;
			}
		}

	if (selectedItem == li || theLast == true) {
		if (direction == "next") {
			turnOff = false;
			}
		}


	// TURN OFF THE SELECTION CLASS IF APPROPRIATE
	if (turnOff == true) {
		document.getElementById(selItem).className = "";
		}

	}




/* -- LIST  BY FORMAT -- BROWSE PAGE   ||  START NEW SEARCH FROM LIST CALLS -- ADVANCEDSEARCH -- */

function prepareNewSearch (type, searchTerm) {
	var type = type;
	var searchTerm = searchTerm;
	var theTitle = "";

	// CLEARS STORED SEARCH VALUES
	resetStoredSearch();

	// APPLY THE VALUE TO THE CORRECT PROPERTY
	switch (type) {

		case "label":
		window.localStorage.searchLabel = searchTerm;
		theTitle = "Search for Label: " + searchTerm;
		break;

		case "category":
		window.localStorage.searchGenre = searchTerm;
		theTitle = "Search for Category: " + searchTerm;
		break;

		case "format":
		window.localStorage.filterFormat = searchTerm;
		theTitle = "Search by Format: " + searchTerm;
		break;

		case "listformat":
		window.localStorage.searchFormat = searchTerm;
		theTitle = "List " + mediaType[searchTerm];
		break;

		case "listfilter":
		var listFilter = searchTerm.split("-");
		window.localStorage.searchFormat = listFilter[0];  // format
		window.localStorage.filterGenre = listFilter[1];  // category filter
		theTitle = "List " + genreType[listFilter[1]] + " " + mediaType[listFilter[0]];
		break;

		}

	// VAR TO TEST IF THIS IS A LIST OR A SEARCH
	var typeTest = type.match(/^list/);

	// WRITE SEARCH/LIST TO PAGE HISTORY
	if (typeTest) {
		var scriptElements = new Array ("prepareNewSearch", theTitle, type, searchTerm);
		} else {
		var scriptElements = new Array ("prepareNewSearch", theTitle, searchTerm);
		}
	writeScriptCallHistory(scriptElements);

	// SEND IT TO ADVANCED SEARCH
	advancedSearch();
	return false;
	}




/* -- THIS FUNCTION SETS UP A SEARCH AGAIN FROM HISTORY, THEN CALLS ADVANCED SEARCH -- */

function reconHistSearch(searchBand, searchRecord, searchLabel, filterGenre, filterFormat) {
	var searchBand = searchBand;
	var searchRecord = searchRecord;
	var seardrLabel = searchLabel;
	var filterFormat = filterFormat;
	var filterGenre = filterGenre;

	// CLEARS STORED SEARCH VALUES
	resetStoredSearch();

	// PUT HISTORICAL SEARCH ITEMS INTO LOCAL STORAGE
	window.localStorage.searchBand = searchBand;
	window.localStorage.searchRecord = searchRecord;
	window.localStorage.searchLabel = searchLabel;

	window.localStorage.filterFormat = filterFormat;
	window.localStorage.filterGenre = filterGenre;
	window.localStorage.filterLabel = "";

	window.localStorage.totalFound = "";
	window.localStorage.startAt = 0;

	// SEND TO advancedSearch TO REFRESH THE RESULT
	advancedSearch();
	}




/* -- REMOVE FILTER FROM RESULTS -- */

function removeFilter (type){

	switch (type)  {

		case "format":
		window.localStorage.filterFormat = "";
		break;

		case "genre":
		window.localStorage.filterGenre = "";
		break;

		case "label":
		window.localStorage.filterLabel = "";
		break;

		case "all":
		window.localStorage.filterFormat = "";
		window.localStorage.filterGenre = "";
		window.localStorage.filterLabel = "";
		break;
		}

	// RESET START TO 0 AFTER REMOVING FILTERS
	window.localStorage.startAt = 0;

	// SEND TO advancedSearch TO REFRESH THE RESULT
	advancedSearch();
	}




/* -- RESET HINTS FIELD MESSAGE -- */

function resetMsg(){
	var theMode = document.getElementById('field').value;
	theMode = theMode.capitalize();
	document.getElementById('hints').value = "Search for " + theMode;
	document.getElementById('search-results').style.display = "none";
	}




/* -- CLEARS ALL SEARCH TERMS FROM LOCAL STORAGE BEFORE ADDING NEW SEARCH -- */

function resetStoredSearch() {

	// RESET STORAGE VALUES AND FILTERS
	window.localStorage.searchBand = "";
	window.localStorage.searchRecord = "";
	window.localStorage.searchLabel = "";
	window.localStorage.searchFormat = "";
	window.localStorage.searchGenre = "";

	window.localStorage.filterFormat = "";
	window.localStorage.filterGenre = "";
	window.localStorage.filterLabel = "";

	window.localStorage.totalFound = "";
	window.localStorage.searchType = "";
	window.localStorage.startAt = 0;

	}




/* -- START NEW SEARCH FROM HINTS -- PUT QUERY IN LOCAL STORAGE -- RESET FILTERS -- */

function searchFromHints() {

	var theField = document.getElementById('field').value;
	var searchTerm = document.getElementById('hints').value;

	// HIDE HINTS FORM IMMEDIATELY -- THE FADE IS TOO SLOW
/* 	document.getElementById('search-form1').className = "search-form-collapsed-fast"; */
	document.getElementById('search-results').className = "hidden";

	// SET STORAGE VALUES AND RESET FILTERS
	if (theField == "band") {
		window.localStorage.searchBand = searchTerm;
		window.localStorage.searchRecord = "";
		}

	if (theField == "record") {
		window.localStorage.searchBand = "";
		window.localStorage.searchRecord = searchTerm;
		}

	// SET TITLE OF SEARCH
	var theTitle = "Search for: " + searchTerm;

			// WRITE THIS SEARCH TO PAGE HISTORY
			//	var scriptElements = new Array ("startNewSearch", theTitle, searchBand, searchRecord, searchLabel, filterGenre, filterFormat);
			//	writeScriptCallHistory(scriptElements);

	// RESET OTHER VARIABLES
	window.localStorage.searchLabel = "";
	window.localStorage.searchFormat = "";
	window.localStorage.searchGenre = "";

	window.localStorage.filterFormat = "";
	window.localStorage.filterGenre = "";
	window.localStorage.filterLabel = "";

	window.localStorage.searchType = "hints";
	window.localStorage.totalFound = "";
	window.localStorage.startAt = 0;

	// GO TO SEARCH NOW
	advancedSearch();
	return false;
	}





/* -- SET SEARCH MODE TO BAND OR RECORD IN HINTS OR ADVANCED SEARCH -- */

function searchMode(theMode) {
	var theMode = theMode;
	var selID = "";

	// DESELECT ALL THE BUTTONS IF NOT ADVANCED
	if (theMode != "advanced") {
		var theButtons = new Array ("b-hint", "r-hint");  // "advanced"
		for (theBut in theButtons) {
			document.getElementById(theButtons[theBut]).className = "sb-button click";
			}
		}


	// DESELECT THE ADVANCED BUTTON
	document.getElementById('advanced').className = "tab click";

	// DESIGNATE THE SELECTED BUTTON
	if (theMode == "Band") {
		selID = "b-hint";
		} else if (theMode == "Record") {
		selID = "r-hint";
		} else {
		selID = "advanced";
		}

	// CHANGE MODE AND UPDATE THE SELECTED BUTTON
	if (theMode == "advanced") {

		// RESET SEARCH FORM
		document.getElementById('msg').innerHTML = "Enter as much information as you like to narrow your search.";
		document.getElementById('msg').className = "";

		document.getElementById('band').value = "";
		document.getElementById('record').value = "";
		document.getElementById('label').value = "";
		document.getElementById('filtercat').value = "";
		document.getElementById('filterformat').value = "";

		// CLEAR STORAGE AS WELL
		window.localStorage.searchGenre = "";
		document.getElementById(selID).className = "tab selected";
		initListData();	// make sure that data is loaded into the storage
//		closeAll();		// close all sidebar tools

		} else {

		document.getElementById('field').value = theMode.toLowerCase();
		document.getElementById('hints').value = "Search for " + theMode;
		document.getElementById(selID).className = "sb-button selected click";
		document.getElementById('search-results').innerHTML = "";		// clear results list
		}

	}



/* -- SEARCHS FROM TERM CLICKED ON IN THE HINTS MENU -- */

function setSearch (theTerm) {
	var theTerm = theTerm;							// term clicked on
	document.getElementById('hints').value = theTerm;		// set to hints menu
	searchFromHints();								// call function
	return false;
	}




/* -- THIS SETS THE NEW START VALUE IN LOCAL STORAGE ONCE A BUTTON IS CLICKED -- */

function setStart(startVal) {
	var startVal = startVal;
	window.localStorage.startAt = startVal;
	}




/* -- SORT FILTER LABEL MENU -- */

function sortLabelMenu(unsorted) {

	var unsorted = unsorted;
	var tempList = new Array
	tempList = unsorted.split("</li>");

	tempList = tempList.sort();
	var sorted = tempList.join("</li>");

	return sorted;
	}




/* -- START NEW SEARCH FROM FORM -- PUT QUERY IN LOCAL STORAGE -- RESET FILTERS -- */

function startNewSearch(theQuery){

	// CLEARS STORED SEARCH VALUES
	resetStoredSearch();

	var searchBand = theQuery.band.value;
	var searchRecord = theQuery.record.value;
	var searchLabel = theQuery.label.value;
	var filterGenre = theQuery.filtercat.value;
	var filterFormat = theQuery.filterformat.value;

	// PREAPARE TITLE FOR PAGE HISTORY
	var searchTerms = new Array();
	var i = 0;
	if (searchBand != "") {
		searchTerms[i] = searchBand;
		i++;
		}
	if (searchRecord) {
		searchTerms[i] = searchRecord;
		i++;
		}
	if (searchLabel) {
		searchTerms[i] = searchLabel;
		i++;
		}

	var connector = " &amp; ";
	var theTitle = searchTerms.join(connector);
	theTitle = "Search for: " + theTitle;

	// WRITE THIS SEARCH TO PAGE HISTORY
	var scriptElements = new Array ("startNewSearch", theTitle, searchBand, searchRecord, searchLabel, filterGenre, filterFormat);
	writeScriptCallHistory(scriptElements);

	// SET STORAGE VALUES AND RESET FILTERS
	window.localStorage.searchBand = searchBand;
	window.localStorage.searchRecord = searchRecord;
	window.localStorage.searchLabel = searchLabel;

	window.localStorage.filterFormat = filterFormat;
	window.localStorage.filterGenre = filterGenre;
	window.localStorage.filterLabel = "";

	window.localStorage.totalFound = "";
	window.localStorage.startAt = 0;

	// GO TO SEARCH NOW
	advancedSearch();
	return false;
	}




/* -- UPDATE FORMAT COUNT - KEEPS TRACK OF HOW MANY OF EACH FORMAT WAS FOUND -- */

function updateFmtCnt(theSource){

	var theSource = theSource;
	var theFormat = theSource.substr(16,2);
	var theGenre = theSource.substr(19,1);

	// INCREMENT THE PROPER FORMAT
	switch (theFormat) {

		case "45":
		fmtCnt.singles++;
		break;

		case "LP":
		fmtCnt.albums++;
		break;

		case "CD":
		fmtCnt.cds++;
		break;

		case "MG":
		fmtCnt.zines++;
		break;

		}


	// INCREMENT THE PROPER GENRE
	switch (theGenre){

		case "A":
		genreCnt.alt++;
		break;

		case "B":
		genreCnt.bos++;
		break;

		case "G":
		genreCnt.gar++;
		break;

		case "P":
		genreCnt.pun++;
		break;

		case "S":
		genreCnt.six++;
		break;

		}

	}




/*
===================================
ORDER RELATED FUNCTIONS
===================================
*/



/* -- VIEW ORDER - WATCH FOR 0 AMOUNT IN EDIT FIELD TO SET UP DELETING AN ITEM -- */

function buttonState(theID) {
	var theID = theID.id;			// SELECT THE PROPER FIELD
	var hintID = theID.replace(/^r/, "h");
	var curVal = document.getElementById(theID).value;		// GET THE VALUE IN THE FIELD
	var defMsg = "Change the quantity of this item or Enter 0 to delete it.";
	var hintMsg = "";

	// CHECK FOR NON-NUMERIC OR DECIMAL
	if (isNaN(curVal)) {
		// IF NOT A NUMBER, SEND ALERT MESSAGE TO HINT BUBBLE
		hintMsg = "<strong>Please only enter numbers in this field.</strong>";
		document.getElementById(hintID).firstChild.innerHTML = hintMsg;

		} else {

		if (document.getElementById(hintID).firstChild.innerHTML != defMsg){
			hintMsg = "Change the quantity of this item or Enter 0 to delete it.";
			document.getElementById(hintID).firstChild.innerHTML = hintMsg;
			}
		}


	// TEST FOR DECIMAL QUANTITY AMOUNTS
	var decPt = /\./;

	if (decPt.test(curVal)) {
		hintMsg = "<strong>Please use whole numbers only.</strong>";
		curVal = parseInt(curVal);		// MAKE SURE IT'S AN INTEGER
		document.getElementById(hintID).firstChild.innerHTML = hintMsg;
		document.getElementById(theID).value = curVal;
		}

	// RENAME THE SUBMIT BUTTON IF THE ITEM IS GOING TO BE DELETED
	if (curVal == 0) {
		hintMsg = "<strong>Clicking SAVE will delete this item from your order.</strong>";
		document.getElementById(hintID).firstChild.innerHTML = hintMsg;
		}

	return false;
	}



/* CHANGE PAYMENT METHOD */

function changePayment() {

	// CHECK IF ORDER HAS BEEN SENT
	var checkOrderStatus = checkOrderSentStatus();
	if (checkOrderStatus == "completed"){
		alert("This order has already been sent, and can no longer be edited.");
		return;
		} else {

		// IF ORDER HAS NOT BEEN SENT, GO TO SHIPPING PAGE TO CHANGE PAYMENT METHOD
		location.href="../cgi-bin/sprv6index.cgi?shipping-information";
		}

	return false;
	}




/* -- CHANGE THE QUANTITY -- */

function changeQty() {
	var lineNum = this.id;

	var qtyID = "r" + lineNum;
	var hintID = "h" + lineNum;
	var priceID = "p" + lineNum;
	var newVal = document.getElementById(qtyID).value;
	var theArgs = lineNum + ":-:" + newVal;

	// CALL EXTERNAL SCRIPT
	runExternal("changeqty", theArgs);

	// UPDATE THE FORM ITSELF
	var thePrice = document.getElementById(priceID).innerHTML;

	// CALC THE EXTENDED COLUMN AND PLACE THE UPDATED VALUE IN THE FORM
	var extPrice = thePrice * newVal;
	document.getElementById(priceID).nextSibling.innerHTML = extPrice.toFixed(2);

	// CALL closeEdit FUNCTION TO CLOSE INTERFACE
	closeEdit(lineNum);

	// IF THIS ITEM HAS BEEN DELETED, REMOVE THE ROW NOW
	if (newVal == 0) {
		document.getElementById(lineNum).parentNode.parentNode.style.display = "none";
		}

	return false;
	}



/* -- CHECK IF CUSTOMER HAS FILLED OUT SHIPPING INFORMATION YET -- */

function checkForShipping() {

	if (window.localStorage.ordShipStatus == "pending") {
		confirm("Please fill out your shipping information first.");
		location.href = "../cgi-bin/sprv6index.cgi?shipping-information";
		}
	}



/* -- CHECK IF ORDER HAS BEEN SENT YET -- */

function checkOrderSentStatus() {

	var checkOrderStatus = window.localStorage.orderStatus;
	var theSession = window.localStorage.session;

	// CHECK IF THE ORDER HAS BEEN SENT YET
	if (checkOrderStatus == "1-" + theSession + "-complete"){
		return "completed";
		} else {
		return "pending";
		}

	}




/* -- GET VALUES FROM FORM AND CHECK IF THEY'RE VALID -- */

function checkShipForm() {

	// START BY DISABLING SUBMIT BUTTON
	var subButton = document.getElementById('addship');
	subButton.disabled = true;


	// USE HTML 5 FORM ITEMS TO TEST VALIDITY
	if (window.localStorage.render == "trident") {
		// this needs better confirmation -- need to really check
		var theResult = true;

		} else {
		var theResult = document.getElementById("shipinfo").checkValidity();
		}

	if (theResult == true) {

		// IF SHIPPING INFO IS COMPLETE, SET INDICATOR IN SIDEBAR
		window.localStorage.ordShipStatus = "completed";
		document.getElementById('ship-stat').firstElementChild.firstElementChild.textContent = "completed";
		document.getElementById('ship-ind').className = "v-ord";
		document.getElementById('ship-ind').firstElementChild.display = "inline";

		// IF PAYMENT IS COMPLETE, SET INDICATOR IN SIDEBAR
		var payMethod = document.getElementById('method').value;
		if (payMethod == "check" || payMethod == "imo") {
			window.localStorage.ordPayStatus = "completed";
			document.getElementById('payment-stat').firstElementChild.firstElementChild.textContent = "completed";
			document.getElementById('pay-ind').className = "v-ord";
			document.getElementById('pay-ind').firstElementChild.display = "inline";

			}


		// SUBMIT THE FORM AS NORMAL
		return document.getElementById('shipinfo').submit();

		return false;

					/*    --- KEEP THIS WE MAY NEED IT FOR THE EDITING FIELDS


					// WE HAVE SUCCESSFULLY FILLED OUT THE FORM -- SUBMIT IT
					//probably need to do this via ajax
							var formVal = document.getElementById('shipinfo');
							var formInfo = new Array();
							var selectInfo = new Array();

							// GET ALL THE INPUT ELEMENTS IN TO THE ARRAY
							formInfo = formVal.getElementsByTagName('input');
							selectInfo = formVal.getElementsByTagName('select');
							var textInfo = document.getElementById('comments');

							// SET ASSOCIATIVE ARRAY TO HOLD FORM DATA BELOE
							var formData = new Array();
							formData["session"] = window.localStorage.session;

							for (var i=0; i<8; i++) {
								formData[formInfo[i].name] = formInfo[i].value;
								}

							// GET THE VALUE OF THE SELECT TAGS
							formData[selectInfo[0].name] = selectInfo[0].value;
							formData[selectInfo[1].name] = selectInfo[1].value;
							formData['comments'] = textInfo.value;

							runExternal("addShip", formData);

					// AFTER THIS RETURNS, WE PROGRESS TO THE PAYMENT PAGE

							return;
					*/

		}

	var theForm = new Array();
	 theForm = {
		"first" : document.getElementById('first').value,
		"last" : document.getElementById('last').value,
		"addOne" : document.getElementById('addOne').value,
		"addTwo" : document.getElementById('addTwo').value,
		"city" : document.getElementById('city').value,
		"state" : document.getElementById('state').value,
		"zip" : document.getElementById('zip').value,
		"country" : document.getElementById('country').value,
		"email" : document.getElementById('emailaddress').value,
		"method" : document.getElementById('method').value,
		"comments" : document.getElementById('comments').value
	 	}


	// CONFRIM THAT REQUIRED FIELDS ARE NOT EMPTY
	var reqFields = new Array ("first", "last", "addOne", "city", "state", "zip", "country","email", "method");
	var emptyFields = new Array();
	var badFields = new Array();

	for (i in reqFields) {
		if (theForm[reqFields[i]] == ""){
			emptyFields[emptyFields.length] = reqFields[i];
			}
		}

	// TEST THE DATA ENTERED AGAINST OUR PATTERN -- (IN-FORM VALIDATION DOESN'T PREVENT BOGUS DATA FROM BEING SUBMITTED)
	var safePattern = /[^a-zA-Z0-9\s\-\.]/;  // NOTE, THIS DOESN'T CATCH EMPTY FIELDS
	var safeEmail = /[0-9a-zA-Z\._-]*@[a-zA-Z]*\.[a-zA-Z]{2,3}(\.{1}[a-zA-z]{2})?/;

	for (j in theForm) {
		if (safePattern.test(theForm[j]) && j !="email") {
			// WE'VE FOUND BAD DATA HERE
			badFields[badFields.length] = j;
			}

		if (!safeEmail.test(theForm[j]) && j == "email") {
			// WE'VE FOUND BAD DATA HERE
			badFields[badFields.length] = j;			// WE'VE FOUND BAD DATA HERE
			}

		}

	// RETURN TO FORM AND MARK BAD FIELDS GIVING A REASON
/*	for (k in emptyFields){
		if (emptyFields[k] != "method") {
			document.getElementById(emptyFields[k]).value = "--> This field is required <--";
			document.getElementById(emptyFields[k]).style.color = "rgb(204,0,0)";
			} else {
			document.getElementById(emptyFields[k]).firstChild.innerHTML = "--> This field is required <--";
			document.getElementById(emptyFields[k]).style.color = "rgb(204,0,0)";
			}
		}
*/

/*	for (l in badFields) {
		document.getElementById(badFields[l]).nextSibling.textContent = "Please use only letters, numbers, periods or dashes in this field.";
		document.getElementById(badFields[l]).title = "Please use only letters, numbers, periods or dashes in this field.";
		document.getElementById(badFields[l]).className = "error";
		}
*/

	if (emptyFields.length || badFields.length) {
		var theErrorMsg = "";

		if (emptyFields.length) {
			theErrorMsg = "Please fill out all of the required fields (with red borders).\n\n";
			}

		if (badFields.length) {
			theErrorMsg += "Please check your information. There are some errors.";
			}

		confirm(theErrorMsg);

		}

	// ENABLE SUBMIT BUTTON AGAIN
	subButton.disabled = false;

	return;

	}





/* -- CLEARS THE ERROR TEXT AND STYLE UPON FOCUS !! this may not be necessary for placeholder fields --

function clearError(evt){
	var theID = document.getElementById(this.id);

	if (theID.value == "--> This field is required <--") {
		theID.value = "";
		theID.style.color = "rgb(98,98,98)";
		}

	evt.preventDefault();
	}
*/



/* -- CLOSE EDITING INTERFACE -- */

function closeEdit(theID) {
	var theID = theID;

	// SET UP VARIABLES
	var hintID  = "h" + theID;	// hint div
	var qtyID = "r" + theID;		// input field

	// RESET THE SAVE BUTTON TO THE EDIT BUTTON
	var saveButton = document.getElementById(theID);

	// CHANGE SAVE BUTTON TO BE ACTIVE
	saveButton.innerHTML = "EDIT";
	saveButton.style.backgroundColor = "rgba(204,0,0,.4)";
	saveButton.style.color = "rgba(255,255,255,.4)";

	// HIDE THE HINT BOX AND RESET MESSAGE
	document.getElementById(hintID).className = "edit-hint";
	var hintMsg = "Change the quantity of this item or Enter 0 to delete it.";
	document.getElementById(hintID).firstChild.innerHTML = hintMsg;

	// DEACTIVATE THE QUANTITY FIELD
	var x = document.getElementById(qtyID);
	x.className = "editQty";
	x.disabled = true;

	// RESET ORIG QTY VALUE -- LOADS INFO VIA AJAX
	runExternal("resetqty", theID);

	// REATTACH DEFAULT EVENTS EVENTS
	attachOrdEvts();

	return false;
	}




/* -- SHOW THE EDITING FIELD FOR A SPECIFIC ITEM -- */

function openEdit(evt){

	// CHECK IF THE ORDER HAS BEEN SENT YET
	var checkOrderStatus = checkOrderSentStatus();

	if (checkOrderStatus == "completed"){
		alert("This order has already been sent, and can no longer be edited.");
		nullEvent();
		} else {


		// EXTRACT THE PROPER ID AND NAME AND DEFINE OTHER IDS
		var lineNum = this.id;

		// GET THE ITEM CODE FROM THE DATA ATTRIBUTE. THIS BECOMES THE BASE FOR OTHER IDS
		var theID = document.getElementById(lineNum).getAttribute("data-id");
		var qtyID = "r" + lineNum;			// QTY FIELD ID
		var hintID = "h" + lineNum;		// HINTS MSG ID
		var editID = theID + "-info";		// DEFINE THE EDITING DIV ID

		// SHOW THE HINT DIV
		document.getElementById(hintID).className = "edit-hint-enabled";

		// CONVERT THE EDIT BUTTON INTO A SAVE BUTTON -- THE ID IS ACTUALLY THE LINE NUMBER
		var saveButton = document.getElementById(lineNum);

		// CHANGE SAVE BUTTON TO BE ACTIVE
		saveButton.innerHTML = "SAVE";
		saveButton.style.backgroundColor = "rgb(204,0,0)";
		saveButton.style.color = "rgb(255,255,255)";

		// ATTACH A NEW SCRIPT TO THE SAVE AND CANCEL BUTTONS
		var savebutton = document.getElementById(lineNum);
		savebutton.addEventListener('click',changeQty,false);

		//ACTIVATE QTY FIELD
		var x = document.getElementById(qtyID);
		x.className = "editQtyEnabled";
		x.disabled = false;
		x.focus();
		x.select();

		}

	evt.preventDefault();
	}




/* -- IF ORDER IS COMPLETED, SEND IT TO SP -- */

function sendOrder() {

	var shipInfoStat = window.localStorage.ordShipStatus;
	var payInfoStat = window.localStorage.ordPayStatus;
	var checkOrderStatus = checkOrderSentStatus();

	// CHECK IF THE ORDER HAS BEEN SENT YET
	if (checkOrderStatus == "completed"){
		alert("This order has already been sent.");
		return;
		}

	if (shipInfoStat == "completed" && payInfoStat == "completed" && checkOrderStatus == "pending") {
		location.href = "../cgi-bin/sprv6sendOrder.cgi";
		}

	return false;
	}



/* -- SHOWS SUMMARY OF ORDER ON VIEW ORDER PAGE -- */

function showSummary(evt){

	// IF SUMMARY IS BEING DISPLAYED, CLOSE IT, AND EXIT
	if (document.getElementById('summary').innerHTML == "close") {
		document.getElementById('media-count').innerHTML = "";
		document.getElementById('summary').innerHTML = "view";
		} else {

		// IF THE SUMMARY IS NOT DISPLAYED, FORMAT IT IN A LIST AND DISPLAY IT

		// GET THE DATA FROM THE TAG
		var theData = document.getElementById('media-count');
		var theAtt = theData.attributes;
		var theData = theAtt.getNamedItem("data-list").value;

		// PARSE DATA
		var dataList = new Array();
		dataList = theData.split(":-:");
		medialList = new Array ("45", "LP", "CD", "MAG");

		var displayList = "<ul>";

		for (i = 0; i < 4; i++){
			displayList += "<li>" + medialList[i] + ": " + dataList[i] + "</li>";
			}

		displayList += "</ul>";

		document.getElementById('media-count').innerHTML = displayList;
		document.getElementById('summary').innerHTML = "close";
		}

	evt.preventDefault();
	}




/* --FORM VALIDATION FOR SHIPPING INFO -- */

function validify(evt) {
/* 	var theID = document.getElementById(this.id);

	// SHOW MESSAGE BASED ON THE PAYMENT OPTION
	if (theID.value == "paypal"){
		document.getElementById('pp').style.display = "block";
		document.getElementById('ck').style.display = "none";
		}

	if (theID.value == "check"){
		document.getElementById('ck').style.display = "block";
		document.getElementById('pp').style.display = "none";
		}

	// SEE IF THE USER HAS CHOSEN A PAYMENT METHOD
	if (theID.value == "x") {
		confirm("Please pick a payment method for this order.");
		}

	evt.preventDefault();
 */	}




/*
===================================
CANVAS SCRIPTS START HERE
===================================
*/



/* -- SUBNAV BUTTON ARROWS -- */

function drawArrows() {
	var theID = new Array ("sub45", "subLP", "subCD", "subMAG");

	for (i=0; i<4; i++){

		var curButton = theID[i];

		var theButton = document.getElementById(curButton);
		var theArrow = theButton.getContext("2d");

		theArrow.beginPath();
		theArrow.fillStyle = "rgba(255,255,255,.4)";

		theArrow.moveTo(0,0);
		theArrow.lineTo(11,6);
		theArrow.lineTo(0,11);
		theArrow.lineTo(0,0);

		theArrow.fill();
		}
	}




/* -- DRAW STATS CHART -- */

function drawChart(fmtCnt, genreCnt){

	var fmtCnt = fmtCnt;
	var genreCnt = genreCnt;
	var label = new Array();
	var category = new Array();

	// FIND TOTAL OF ITEMS IN DATABASE
	var totalCnt = fmtCnt.singles + fmtCnt.albums + fmtCnt.cds + fmtCnt.zines;

	// FIND A PERCENTAGE FOR EACH FORMAT
	label.singles = fmtCnt.singles + " - (" + ((fmtCnt.singles/totalCnt) * 100).toFixed(2) + "%)";
	label.albums = fmtCnt.albums + " - (" + ((fmtCnt.albums/totalCnt) * 100).toFixed(2) + "%)";
	label.cds = fmtCnt.cds + " - (" + ((fmtCnt.cds/totalCnt) * 100).toFixed(2) + "%)";
	label.zines = fmtCnt.zines + " - (" + ((fmtCnt.zines/totalCnt) * 100).toFixed(2) + "%)";


	// SET PERCENTAGES FOR EACH CATEGORY
	category.alt = genreCnt.alt + " - (" + ((genreCnt.alt/totalCnt) * 100).toFixed(2) + "%)";
	category.bos = genreCnt.bos + " - (" + ((genreCnt.bos/totalCnt) * 100).toFixed(2) + "%)";
	category.gar = genreCnt.gar + " - (" + ((genreCnt.gar/totalCnt) * 100).toFixed(2) + "%)";
	category.pun = genreCnt.pun + " - (" + ((genreCnt.pun/totalCnt) * 100).toFixed(2) + "%)";
	category.six = genreCnt.six + " - (" + ((genreCnt.six/totalCnt) * 100).toFixed(2) + "%)";


	// THIS DATA IS POPULATED FROM THE DATABASE
	var rawChartVal = {"Vinyl Singles" : fmtCnt.singles, "LPs and EPs" : fmtCnt.albums, "Compact Discs" : fmtCnt.cds, "Magazines" : fmtCnt.zines};  	//data to draw chart
	var formatData =  {"Vinyl Singles" : label.singles, "LPs and EPs" : label.albums, "Compact Discs" : label.cds, "Magazines" : label.zines};	// actual numbers and percentages

	var rawCatVal = {"Alt/Indie" : genreCnt.alt, "Boston Area" : genreCnt.bos, "Garage/Psych" : genreCnt.gar, "Punk" : genreCnt.pun, "Sixties" : genreCnt.six};
	var catLabel = {"Alt/Indie" : category.alt, "Boston Area" : category.bos, "Garage/Psych" : category.gar, "Punk" : category.pun, "Sixties" : category.six};

	var y = 15;		// starting y axis

	// DRAW THE FORMAT CHART
	var theChart = document.getElementById("formatChart");
	var formatChart = theChart.getContext("2d");

	for (key in rawChartVal) {

		var label = key + ": " + formatData[key];
		var percent = rawChartVal[key]


		// FIGURE BAR WIDTH
		var barWidth = (percent/100) * 60;				////////   ****************************need to change division to get the percentages/widths correct
		barWidth = Math.round(barWidth);			// rounds the number just in case

		formatChart.beginPath();
		formatChart.fillStyle = "rgb(204,0,0)";
		z = y + 40;

		formatChart.moveTo(0,y);
		formatChart.lineTo(barWidth,y);
		formatChart.lineTo(barWidth,z);
		formatChart.lineTo(0,z);

		formatChart.fill();

		// ADD THE TEXT LABEL BELOW BAR
		formatChart.font = "9pt sans-serif";
		formatChart.fillStyle = "rgb(0,0,0)";
		formatChart.fillText(label, 5, (z+14));

		// MOVE THE STARTING Y AXIS POINT DOWN 50 PX
		y += 70;

		}



	// DRAW THE CATEGORY CHART
	var theChart = document.getElementById("categoryChart");
	var formatChart = theChart.getContext("2d");
	y = 15;

	for (key in rawCatVal) {

		var label = key + ": " + catLabel[key];
		var percent = rawCatVal[key]

		// FIGURE BAR WIDTH
		var barWidth = (percent/100) * 60;				////////   ****************************need to change division to get the percentages/widths correct
		barWidth = Math.round(barWidth);			// rounds the number just in case

		formatChart.beginPath();
		formatChart.fillStyle = "rgb(204,0,0)";
		z = y + 30;

		formatChart.moveTo(0,y);
		formatChart.lineTo(barWidth,y);
		formatChart.lineTo(barWidth,z);
		formatChart.lineTo(0,z);

		formatChart.fill();

		// ADD THE TEXT LABEL BELOW BAR
		formatChart.font = "9pt sans-serif";
		formatChart.fillStyle = "rgb(0,0,0)";
		formatChart.fillText(label, 5, (z+14));

		// MOVE THE STARTING Y AXIS POINT DOWN 50 PX
		y += 55;

		}

	}




/* -- DOWN ARROW -- */

function drawDownArrow(theID) {
	var curButton = theID;
	var theButton = document.getElementById(curButton);
	var theArrow = theButton.getContext("2d");

	theArrow.beginPath();
	theArrow.fillStyle = "rgba(204,0,0,.4)";

	theArrow.moveTo(0,0);
	theArrow.lineTo(16,0);
	theArrow.lineTo(8,10);
	theArrow.lineTo(0,0);

	theArrow.fill();
	}




/* -- DRAW ERROR ARROWS FOR FORM VALIDATION -- */

function drawErrorArrow(theForm){

	var theForm = theForm;
	var theID = new Array();

	if (theForm == "advanced") {
		theID = ["band-err", "record-err", "label-err"];
		}

	// FIND NUMBER OF ELEMENTS
	var numArrows = theID.length;

	//START DRAWING THE ARROWS
	for (i = 0; i < numArrows; i++) {

		var currID = document.getElementById(theID[i]);
		var currArrow = currID.getContext("2d");

		currArrow.beginPath();

		currArrow.fillStyle = "rgb(204,0,0)";
		currArrow.strokeStyle = "rgb(255,255,255)";
		currArrow.lineWidth = 4;

		currArrow.arc(12,13,13,0,Math.PI*2,true);

		currArrow.moveTo(24,13);
		currArrow.lineTo(5,13);

		currArrow.fill();
		currArrow.stroke();

		// DRAW HEAD OF ARROW -- LINE WIDTH LESS THAN STEM
		currArrow.beginPath();
		currArrow.lineWidth = 3;

		currArrow.moveTo(15,5);
		currArrow.lineTo(5,13);
		currArrow.lineTo(15,20);

		currArrow.stroke();

		}

	return;
	}




/* -- TOGGLE ARROW DIRECTION DEPENDING ON MENU OPEN OR CLOSED -- */

function drawSingleArrow(theID, close) {

	// FIGURE OUT WHICH ARROW TO SHOW
	if (close == true) {
		var theID = theID + "cl";
		} else {
		var theID = theID.replace("cl", "");
		}
	document.getElementById(theID).style.display = "inline";

	// START SHOWING ARROW
	var theButton = document.getElementById(theID);
	theButton.width = theButton.width;		// reset canvas, so we're not drawing over old elements
	var theArrow = theButton.getContext("2d");

	theArrow.beginPath();

	// DRAW THE ARROW -- EITHER LEFT OR RIGHT FACING
	if (close == true) {
		theArrow.fillStyle = "rgba(255,255,255,.4)";

		theArrow.moveTo(11,0);
		theArrow.lineTo(0,6);
		theArrow.lineTo(11,11);
		theArrow.lineTo(11,0);

		} else {
		theArrow.fillStyle = "rgba(255,255,255,.4)";

		theArrow.moveTo(0,0);
		theArrow.lineTo(11,6);
		theArrow.lineTo(0,11);
		theArrow.lineTo(0,0);

		}


	theArrow.fill();

	return;

	}




/* -- HIGHLIGHT THE ARROW -- */

function highlightArrow(theID, close, state) {

	// FIGURE OUT WHICH ARROW TO SHOW
	if (close == 'true') {
		var theID = theID + "cl";
		} else {
		var theID = theID.replace("cl", "");
		}
	document.getElementById(theID).style.display = "inline";

	// SET THE FILL COLOR
	if (state == "o") {
		var fillColor = "rgb(255,255,0)";
		} else {
		var fillColor = "rgba(255,255,255,.4)";
		}

	// START SHOWING ARROW
	var theButton = document.getElementById(theID);
	theButton.width = theButton.width;		// reset canvas, so we're not drawing over old elements
	var theArrow = theButton.getContext("2d");

	theArrow.beginPath();

	// DRAW THE ARROW -- EITHER LEFT OR RIGHT FACING
	if (close == 'true') {
		theArrow.fillStyle = fillColor;

		theArrow.moveTo(11,0);
		theArrow.lineTo(0,6);
		theArrow.lineTo(11,11);
		theArrow.lineTo(11,0);

		} else {
		theArrow.fillStyle = fillColor;

		theArrow.moveTo(0,0);
		theArrow.lineTo(11,6);
		theArrow.lineTo(0,11);
		theArrow.lineTo(0,0);

		}

	theArrow.fill();
	return;
	}




/* -- LIST NAVIGATION BUTTON ARROWS -- */

function listNavButtons(theID, theColor) {
	var curButton = theID;
	var theColor = theColor;
	var rgbColor = "";

	// CREATE THE ARROW OBJECT
	var theButton = document.getElementById(curButton);
	var theArrow = theButton.getContext("2d");

	theArrow.beginPath();


	// SET THE FILL COLOR OR THE ARROW
	if (theColor == "black"){
		theArrow.fillStyle = "rgb(0,0,0)";
		}

	if (theColor == "red"){
		theArrow.fillStyle = "rgb(204,0,0)";
		}

	if (theColor == "orange") {
		theArrow.fillStyle = "rgb(255,153,0)";
		}

	if(curButton == "next-arrow") {
		theArrow.moveTo(0,0);
		theArrow.lineTo(16,8);
		theArrow.lineTo(0,16);
		theArrow.lineTo(0,0);

		} else {

		theArrow.moveTo(0,8);
		theArrow.lineTo(16,0);
		theArrow.lineTo(16,16);
		theArrow.lineTo(0,8);
		}

		theArrow.fill();

	}
