<!--
var OnLoad = "";
var OnDOM = "";
OnLoad += "highlightFormFields();";

// Detect absence of jquery
if($j == undefined) {
	var $j = '';
	window.onload = function() { eval(OnLoad); }
} else {
	$j(window).bind('load',function() { eval(OnLoad); }); // Executes when onload event fires (after images loaded)
	$j(document).ready(function() {  // Executes when DOM is ready (before all images loaded)
		$j('form:not(:has(:submit))').submit(function() { return false; }); // this is to stop ALL forms WITHOUT submit buttons from submitting on enter
		eval(OnDOM);
	}); 
}

// checks if a text element is filled in a form
function isFilled(element) {
	var pattern = /^\s+$/;
	if ((element.value == "") || (element.value == null)) { return false; }
	if (pattern.test(element.value)) { return false; }
	return true;
}
// checks to see if string is a number between min and max digits long
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 number between min and max values
function isNumericRange(element, minimum, maximum) {
	var pattern = /^\d+$/;
	if (pattern.test(element.value)) {
		if (element.value >= minimum && element.value <= maximum) { return true; }
	}
	return false;
}
// checks to see if string is a number between min and max
function isCMNumber(value) {
	var pattern = /^(cm)?-?\d{1,6}$/i;
	if (pattern.test(value)) { return true; }
	return false;
}
// checks to see if string is a valid price
function isPrice(value) {
	var pattern = /^\d{1,6}(\.\d{1,2})?$/;
	var pattern2 = /^\.\d{1,2}$/;
	if ((pattern.test(value) || pattern2.test(value)) && value > 0) { return true; }
	return false;
}
// checks to see if string is a valid price code
function isPriceCode(value) {
	var pattern = /^([A-K]|[P-Z])$/;
	if (pattern.test(value)) { return true; }
	return false;
}
// checks to see if string has any non-alphanumeric chars
function isString(value) { 
	var pattern = /^[a-zA-Z\s\.\-\_]{3,255}$/;
	if (pattern.test(value)) { return true; }
	return false;
}
// checks to see if string has any non-alphanumeric chars
function isDomain(value) {
	var pattern = /^(\w|\-|\.){2,50}\.\w{2,4}$/;
	if (pattern.test(value)) { return true; }
	return false;
}
// checks to see if string looks like an email address
function isEmailAddress(value) {
	var pattern = /^(\w|\.|\-|_)+@(\w|\.|\-|_)+$/;
	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] > 10) { return false; } // 2005-present
	return true;
}
// trims trailing and leading whitespace from string
function trimSpaces(obj) {
	while (obj.value.charAt(0) == ' ') {
		obj.value = obj.value.substring(1,obj.value.length);
	}
	while (obj.value.charAt(obj.value.length-1) == ' ') {
		obj.value = obj.value.substring(0,obj.value.length-1);
	}
}
// general pattern match function, regex in argument
function doesPatternMatchValue(pattern, value) {
	if (pattern.test(value)) { return true; }
	return false;
}
// searches for a value in an array, returns true on match
function searchArray(match, array) {
	for (var x = 0; x < array.length; x++) {
		if (array[x] == match) { return true; }
	}
	return false;
}
// searches for a value in an array, returns true on match
function searchArrayRegEx(pattern, array) {
	for (var x = 0; x < array.length; x++) {
		if (array[x].match(pattern)) { return true; }
	}
	return false;
}
// general window opener function
function openWindow(url) {
	var newwin = window.open(url, "newwin", "location=no,toolbar=no,status=yes,scrollbars=yes,resizable=yes,width=820,height=520");
	newwin.opener = window;
}
// custom window opener function
function openCustomWindow(url, width, height) {
	var newwin = window.open(url, "newwin", "location=no,toolbar=no,status=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height);
	newwin.opener = window;
}
// opens the picket widget window
function openPicker(obj, form) {

	var url = "/widgets/picker/index.php";
	if (form.config_id) { url = url + "?id=" + form.config_id.value; }
	obj.previousSibling.form.activeHex.value = obj.previousSibling.name;
	var picker = window.open(url, "picker", "location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=400,height=620");
	picker.opener = window;
	picker.moveTo(40,40);
	if (window.focus) { picker.focus(); }
}
function downloadImage(id, type, file) {
	url = "/admin_scripts/download.php?type=" + type + "&id=" + id + "&file=" + file;
	var download = window.open(url, "newwin", "location=no,toolbar=no,status=no,scrollbars=no,resizable=yes,width=200,height=200");
	download.opener = window;
}

// 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;
}
// appends a function to the onload statement of the body tag
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { window.onload = func; }
	else { 
		window.onload = function() { 
			oldonload(); 
			func(); 
		};
	} 
} 
// 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 (var 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; }
}

function returnParentFormByNode(node) {
	var currNode = node.parentNode;
	while (currNode.nodeName != "FORM") { currNode = currNode.parentNode; }
	return currNode;
}
function returnFirstChildNodeByTag(node, tag) {
	for (var x = 0; x < node.childNodes.length; x++) {
		if (node.childNodes[x].nodeName == tag) { return node.childNodes[x]; }
	}
	return false;
}
function returnFormFieldsFromChildNodes(nodes) {
	var cnt = 0;
	var newNodes = new Array();
	for (var x = 0; x < nodes.length; x++) {
		
		if ((nodes[x].nodeName == 'INPUT' ||
			 nodes[x].nodeName == 'SELECT' ||
			 nodes[x].nodeName == 'TEXTAREA') && nodes[x].disabled == false) {
			newNodes[cnt] = nodes[x];
			cnt++;
		}
	}
	return newNodes;
}

function toggleElement(obj) {
	if (obj.style.display == 'none') {
		obj.style.display = '';
		if (obj.form) { obj.disabled = false; obj.focus(); }
	} else {
		obj.style.display = 'none';
		if (obj.form) { obj.disabled = true; }
	}
}

// function to return element height when display is non
function returnComputedProperty(obj, property) {
	if (!document.all) { return document.defaultView.getComputedStyle(obj, '').getPropertyValue(property); }
	else {
		
		var re = /(-)(\w)/g;
		property = property.replace (re, function(fullmatch,paren1,paren2) { return paren2.toUpperCase(); });
		return eval("obj.currentStyle." + property);
	}
}

function returnComputedWidth(obj) {
	var total = 0;
	var pixels = new Array(returnComputedProperty(obj, 'padding-left'),returnComputedProperty(obj, 'padding-right'),returnComputedProperty(obj, 'border-left-width'),returnComputedProperty(obj, 'border-right-width'));
	for (var i = 0; i < pixels.length; i++) {
		if (isNaN(parseInt(pixels[i])) == false) {
			total += parseInt(pixels[i]);
		}
	}
	return obj.offsetWidth - total;
}

function removeLinkFocus() {
    if (document.getElementsByTagName) {
        var an = document.getElementsByTagName('A');
        for (var i = 0; i < an.length; i++) {
            var evn = "this.blur()";
            var fun = new Function('e',evn);
            an.item(i).onmouseup = fun;
		}
    }
} 

// function to highlight form fields in a page for IE Only
function highlightFormFields() {
	if (document.all && document.getElementById) {

		// cycle through forms in document
		for (i = 0; i < document.forms.length; i++) {
			node = document.forms[i];
			
			// cycle through all form nodes
			for (j = 0; j < node.length; j++) {

				// if node is a form element
				if (node[j].nodeName == "INPUT" || node[j].nodeName == "TEXTAREA") {
					if (node[j].type != "hidden" && node[j].type != "radio" && node[j].type != "checkbox" && node[j].type != "submit") {
						node[j].onfocus = function() { this.style.backgroundColor = "#fffedb"; this.style.cursor = 'text'; }
						node[j].onblur = function() { this.style.backgroundColor = "#fff"; this.style.cursor = 'pointer'; }
					}
				}
			}
		}
	}
}
function openHelp(obj) {
	obj.previousSibling.childNodes[0].style.display = 'block';
	obj.previousSibling.childNodes[0].onmouseover = function() { this.style.display = 'block'; };
	obj.previousSibling.childNodes[0].onmouseout = function() { this.style.display = 'none'; };
}
// select and displays dropdown menu, if menu is open, function will close menu
function openMenu(obj) { 
	var divNodes = obj.getElementsByTagName("DIV");
	if (divNodes[0].style.display != 'block') {
		divNodes[0].style.display = 'block';
		divNodes[1].className = "dropdownMenuOn";
		divNodes[2].className = "dropdownArrowOn";
	} else { closeMenu(obj); }
	return true;
}
// closes a dropdown menu
function closeMenu(obj) {
	var divNodes = obj.getElementsByTagName("DIV");
	divNodes[0].style.display = 'none';
	divNodes[1].className = "dropdownMenu";
	divNodes[2].className = "dropdownArrow";
	return true;
}
// closes all dropdown menus on page
function closeAllMenus(e) {

	if (!e) var e = window.event; // ie fix
	if (!e.target) { div = e.srcElement.className; }
	else { div = e.target.className; }
	if (div != 'dropdownMenuOn') {
		var menuNodes = getElementsByClass('dropdownContainer', $('podOptions'), 'DIV');
		for (var x = 0; x < menuNodes.length; x++) { closeMenu(menuNodes[x]); }
		document.onclick = null;
	}
	return true;
}
// change the selected item to the value user has selected
function setMenu(obj) {
	// find the div that has the class 
	var container = obj.parentNode;
	while (container.className != "dropdownContainer") { container = container.parentNode; }
	var divNodes   = container.getElementsByTagName("DIV");
	var inputNodes = container.getElementsByTagName("INPUT");
	divNodes[1].innerHTML = obj.childNodes[0].innerHTML; // update menu with selected item title
	inputNodes[0].value = obj.title; // update form with selected item value
	inputNodes[0].form.submit();
	
	return true;
}
// sets all dropdown menus to "ALL" and submits form
function unFilterList(form) {
	var pod = $('podOptions');
	var divNodes   = pod.getElementsByTagName("DIV");
	var inputNodes = pod.getElementsByTagName("INPUT");
	
	for (var x = 0; x < divNodes.length; x++) { if (divNodes[x].className == 'dropdownMenu') { divNodes[x].innerHTML = "-All-"; } }
	for (var x = 0; x < inputNodes.length; x++) { if (inputNodes[x].name != "url") { inputNodes[x].value = "NULL"; } }
	return true;
}
function submitOnEnter(field,e) {
	var keycode;
	if (window.event) { keycode = window.event.keyCode; }
	else if (e) { keycode = e.which; }
	else { return true; }
	if (keycode == 13) {
		if (window.isReady) { 
			isReady(field.form);
		} else { field.form.submit(); }
	} else { return true; }
}
//-->
