﻿<!--
function ShowPopup(id)
{
document.getElementById(id).style.display='block'

}
// checks if a text element is filled in a form
function isFilled(element) {
	if ((element.value == "") || (element.value == null)) { return false; }
	else { return true; }
}
// checks if an object exists
function isObject(obj) {
	if (obj == null || obj == undefined) { return false; }
	return true;
}
// checks to see if string is number
function isNumber(value) {
	var pattern = /^(\d{1,5})$/;
	if (pattern.test(value)) { return true; }
	return false;
}
// checks to see if string is a number between min and max
function isNumeric(value, minimum, maximum) {
	var pattern = eval("/^\\d{" + minimum + "," + maximum + "}$/");
	if (pattern.test(value)) { return true; }
	return false;
}
// checks to see if string is a monetary value
function isPrice(value) {
	var pattern = /^(\d{1,5})(\.\d{2})?$/; // above 1
	var pattern2 = /^(\.\d{2})$/;
	if (pattern.test(value) || pattern2.test(value)) { return true; }
	return false;
}
// checks to see if string is an exp date
function isExpDate(value) { 
	var pattern = /^[0-9]{2}\/[0-5][0-9]$/;
	if (pattern.test(value)) { return true; }
	return false;
}		
// checks to see if string is a valid date mm/dd/yy or m/d/yy
function isDate(value) {
	var pattern = /^\d{1,2}\/\d{1,2}\/\d{2}$/;
	if (!pattern.test(value)) { return false; }
	
	// setup array of days by month
	// split date into 3 parts
	var monthDays = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var dateArray = value.split('/');
	
	// convert strings to numbers
	dateArray[0] = dateArray[0] * 1; // month
	dateArray[1] = dateArray[1] * 1; // day
	dateArray[2] = dateArray[2] * 1; // year

	// check day, month and year for validity
	if (dateArray[0] < 1 || dateArray[0] > 12) { return false; } // 1-12
	if (dateArray[1] < 1 || dateArray[1] > monthDays[dateArray[0]]) { return false; }
	if (dateArray[2] < 5 || dateArray[2] > 8) { return false; } // 2005-2007
	return true;
}
function randomNumber(arrayLength) {
	return Math.round(Math.random()*(arrayLength - 1));
}
function changeCatalogLimit(total, value) {
	location = "./index_scripts/catalog_limit.php?total=" + total + "&limit=" + value;
}
function changeCatalogSort(value) {
	location = "./index_scripts/catalog_sort.php?sort_by=" + value;
}

// redirects user to thumbnail page by category id
function viewThumbPage(category_id) {
	location = "./index.php?section=catalog&category_id=" + category_id;
	return false; // false so click doesn't move page to top
}

// general window opener function
function openWindow(url) {
	var newwin = window.open(url, "newwin", "location=no,toolbar=no,status=yes,scrollbars=yes,resizable=yes,width=600,height=400");
	newwin.opener = window;
}
function openWindowSize(url,w,h) {
	var newwin = window.open(url, "newwin", "location=no,toolbar=no,status=yes,scrollbars=yes,resizable=yes,width=" + w + ",height=" + h);
	newwin.opener = window;
}

// sets sidenav to height of content div
function initFooter() { 
	
	if (document.getElementById("sidenav")) {
		navHeight 	  = document.getElementById("sidenav").offsetHeight;
		contentHeight = document.getElementById("content").offsetHeight;
	
		// alert(contentHeight);
		if (contentHeight < navHeight) {
			document.getElementById("content").style.height = navHeight + "px";
			// alert(navHeight);
		}
	}
	
	if (document.getElementById("footer")) { 	
		document.getElementById("footer").style.display = "block";
	}
	return true;
}
// sets sidenav to height of 450 if lower, for template #2
function initSideNav() {
	if (document.getElementById("sidenav")) { 
		if (document.getElementById("sidenav").offsetHeight < 450) {
			document.getElementById("sidenav").style.height = "450px";
		} 
	}
	return true;
}

// function to initialize drop downs for IE
function startList() {
	if (document.all && document.getElementById && document.getElementById("categories")) {
		navRoot = document.getElementById("categories");

		// cycle through all li's in second tier (2)
		for (i = 0; i < navRoot.childNodes.length; i++) {
			
			// cycle through all li's in second tier (2)
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI") {
			    
				// if node is an LI apply class
				node.onmouseover = function() { this.className += " over"; }
 				node.onmouseout = function() { this.className = this.className.replace(" over", ""); }
                 
				// cycle through classes li's
				for (j = 0; j < node.childNodes.length; j++) {
					node2 = node.childNodes[j];
				
					// if it's the third tier UL (3)
					if (node2.nodeName == "UL") {
						
						// cycle through nodes
						for (k = 0; k < node2.childNodes.length; k++) {
							node3 = node2.childNodes[k];
							
							// if node is an LI apply class
							if (node3.nodeName == "LI") {
								node3.onmouseover = function() { this.className += "over"; }
								node3.onmouseout = function() { this.className = this.className.replace(" over", ""); }
								
								// cycle through classes li's (4)
								for (l = 0; l < node3.childNodes.length; l++) {
									node4 = node3.childNodes[l];
									
									// if it's the fourth tier UL (4)
									if (node4.nodeName == "UL") {
									
										// cycle through nodes
										for (m = 0; m < node4.childNodes.length; m++) {
											node5 = node4.childNodes[m];
											
											// if node is an LI apply class
											if (node5.nodeName == "LI") {
												node5.onmouseover = function() { this.className += " over"; }
												node5.onmouseout = function() { this.className = this.className.replace(" over", ""); }
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

var currID = 0;
function showMenu(id, parentOn) {
	if (document.getElementById && document.body.style) {
		curMenu = eval('document.getElementById("' + id + '")');
		curMenu.style.visibility  = "visible";
		
		curMenu = eval('document.getElementById("' + parentOn + '")');
		curMenu.style.backgroundColor = '#c3e4ed';
	}
	return id;
}
function hideMenu(id, parentOn) {
	if (id != 0) {
		if (document.getElementById && document.body.style) {
			curMenu = eval('document.getElementById("' + id + '")');
			curMenu.style.visibility  = "hidden";
			
			curMenu = eval('document.getElementById("' + parentOn + '")');
			curMenu.style.backgroundColor = 'transparent';
		}
	}
}

// prototype dollar function, shorthand for calling elements by id
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') { element = document.getElementById(element); }
		if (arguments.length == 1) { return element; }
		elements.push(element);
	}
	return elements;
}
// returns array of elements set to 'searchClass', within 'node' of type 'tag'
function getElementsByClass(searchClass,node,tag) {

	// init array and set default arguments
	var classElements = new Array();
	if (node == null) { node = document; }
	if (tag == null) { tag = '*'; }
	
	// traverse node array and test for class
	var pattern  = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
	var elements = node.getElementsByTagName(tag);
	for (i = 0, j = 0; i < elements.length; i++) {
		if (pattern.test(elements[i].className)) {
			classElements[j] = elements[i];
			j++;
		}
	}
	if (classElements.length > 0) {	return classElements; }
	else { return false; }
}

//-->
