<!--
/**
 * Miscellaneous functionality
 * @version 09/17/2009 - SC
 */

var YES = 1;
var NO = 0;

// set the browser type
var isNS = false;
var isIE = false;
var isOther = false;
var browser = navigator.appName;
var browserVersion = parseInt(navigator.appVersion);
if (browser.indexOf("Netscape") >= 0) { isNS = true; }
else if (browser.indexOf("Microsoft") >= 0) { isIE = true; }
else { isOther = true; }

// the delimeter used in AJAX responses
var delim = '|||';

// used to track clicking rows or checkboxes
var check_clicked=false;

/**
* Compatibility check
* Thanks Google Maps!
*/
function checkBrowserIsCompatible()
{
	if (!browserIsCompatible())
	{
		var loc = document.location;
		var locExpr = new RegExp('incompatible.php');
		if (!ret && locExpr.exec(loc) == null)
		{
			document.location.replace('/incompatible.php');
		}
	}
}

/**
* Compatibility check
* Thanks Google Maps!
*/
function browserIsCompatible()
{
	if (!window.RegExp)
	{
		return false;
	}
	var AGENTS = ['opera','msie','safari','firefox','netscape','mozilla'];
	var agent = navigator.userAgent.toLowerCase();
	for (var i=0; i<AGENTS.length; i++)
	{
		var agentStr = AGENTS[i];
		if (agent.indexOf(agentStr) != -1)
		{
			var versionExpr = new RegExp(agentStr + "[ \/]?([0-9]+(\.[0-9]+)?)");
			var version = 0;
			if (versionExpr.exec(agent) != null)
			{
				version = parseFloat(RegExp.$1);
			}
			if (agentStr == 'opera')
			{
				return (version >= 7);
			}
			if (agentStr == 'safari')
			{
				return (version >= 125);
			}
			if (agentStr == 'msie')
			{
				return (version >= 5.5 && agent.indexOf('powerpc') == -1);
			}
			if (agentStr == 'netscape')
			{
				return (version > 7);
			}
		}
	}
	return document.getElementById;
}

/**
* Explode the given string into pieces, split with the delimeter
* @param	string	str
* @return	array
*/
function boom(str)
{
	return str.split(delim);
}

/**
* Row selection/highlighting
*/
var selID = 0;
var prev_class = '';
function selectRow(num)
{
	if (num != -1)
	{
		if (selID != 0)
		{
			var obj = $('row' + selID);
			if (obj)
			{
				obj.className = prev_class;
			}
		}

		var obj = (num!=0 ? $('row' + num) : null);
		if (obj != null)
		{
			prev_class = (num ? obj.className : '');
			selID = num;

			if (num != 0)
			{
				obj.className = 'sel';
			}
		}
		else
		{
			selID = 0;
		}
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true
	}

function selectRowRadio(num)
{
	if (num != -1)
	{
		if (selID != 0)
		{
			var obj = $('row' + selID);
			var radioObj = $('select' + selID);
			if (obj)
			{
				obj.className = prev_class;
			}
			if (radioObj)
			{
				radioObj.checked = false;
			}
		}

		var obj = (num!=0 ? $('row' + num) : null);
		var radioObj = (num!=0 ? $('select' + num) : null);
		if (obj != null)
		{
			prev_class = (num ? obj.className : '');
			selID = num;

			if (num != 0)
			{
				obj.className = 'sel';
				radioObj.checked = true;
			}
		}
		else
		{
			selID = 0;
		}
	}
}

/**
* Clear the current row selection
*/
function clearRowSelectRadio()
{
	selectRowRadio(0);
}
/**
* Clear the current row selection
*/
function clearRowSelect()
{
	selectRow(0);
}

// open a popup window
function open_window(url,winname,width,height,scroll)
{
	// append '[?/&]ispopup=1' to URL
	url = url+(url.indexOf('?')==-1 ? '?' : '&')+'ispopup=1';

	l = (screen.width/2)-(width/2);
	t = (screen.height/2)-(height/2);
	var win = window.open(url,winname,'width='+width+',height='+height+',top='+t+',left='+l+',resizable=no,scrollbars='+scroll+',toolbar=no,location=no,directories=no,status=no,menubar=no');
	if (win != null) { win.focus(); }
}

// focus and select on the object
function focusSelect(obj)
{
	obj.focus();
	if (obj.select) { obj.select(); }
}

// stop enter from being pressed in a form (onkeypress="return noEnter()")
function noEnter(e)
{
	if (window.event)
	{
		return (window.event.keyCode!=13);
	}
	else
	{
		var code = (e.keyCode ? e.keyCode : (e.which ? e.which : (e.charCode ? e.charCode : 0)));
		return (code!=13);
	}
}

// returns true if the needle (string) is in the haystack (array)
function in_array(needle,haystack)
{
	var isin = false;

	for (var i=0; i<haystack.length; i++)
	{
		if (haystack[i] == needle) { isin = true; break; }
	}

	return isin;
}

// returns the array position of needle (string) in haystack (array)
function array_search(needle,haystack)
{
	var ret = -1;

	for (var i=0; i<haystack.length; i++)
	{
		if (haystack[i] == needle) { ret = i; break; }
	}

	return ret;
}

// removes an element from an array and returns the new array
function array_remove(needle,arr)
{
	var newarr = new Array();
	for (var i=0; i<arr.length; i++)
	{
		if (arr[i] != needle) { newarr[newarr.length] = arr[i]; }
	}
	return newarr;
}

/**
* Return a blank if the value is undefined; otherwise, return the value
* @param	mixed	val
* @return	mixed
*/
function fixUndef(val)
{
	if (typeof(val) == 'undefined') { return ''; }
	else { return val; }
}


/**
* Go to location selection page and return
*/
function doLocation()
{
	var page;
	page = './select_location.php?act=search&return='+document.location;
	go(page,'Loading');
}

/**
* Return the number formatted as a float
* @param mixed num
* @return float
*/
function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if (isNaN(num)) { num = 0; }
	var sign = (num==(num=Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	var cents = (num % 100);
	num = Math.floor(num / 100).toString();
	if (cents < 10) { cents = '0' + cents; }
	return (sign ? '' : '-') + num + '.' + cents;
}


// find the Nth occurance of a string in another string (returns the index)
function strpos(str,fnd,n)
{
	var pos = -1;
	var totmatches = 0;
	var chr = '';

	for (var i=0; i<str.length; i++)
	{
		chr = str.substring(i,(i+1));
		if (chr == fnd)
		{
			totmatches++;
			if (totmatches == n) { pos = i; break; }
		}
	}

	return pos;
}

// return the Nth token in the string, separated by a separator
function token(str,sep,n)
{
	if (str.substring(0,1) != sep) { str = sep+str; }
	if (str.substring((str.length-1),1) != sep) { str = str+sep; }

	var pos1 = (n==1&&0?0:strpos(str,sep,n)+1);
	var pos2 = strpos(str,sep,(n+1));

	return str.substr(pos1,(pos2-pos1));
}

// returns true if the given date is valid (mm/dd/yyyy)
function validDate(check_date)
{
	var re = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
	if (re.test(check_date))
	{
		var darr = check_date.split('/');
		var d = new Date(check_date);
		return (d.getMonth()+1 == darr[0] && d.getDate() == darr[1] && d.getFullYear() == darr[2]);
	}
	else { return false; }
}

// only allow numbers in the textbox
// if allowzero is false, don't allow a zero as the first number
// if nextifenter is true and enter is pressed, go to the next field
function onlynumbers(val,e,allowzero,nextifenter)
{
	var code;
	if (window.event) { code = window.event.keyCode; }
	else if (e) { code = e.which; }
	else { return true; }

	var range = document.selection.createRange();
	var seltext = range.htmlText;

	if ((code >= 48 && code <= 57) || code == 46) // a number or a period
	{
		if (code == 46)
		{
			if (val.indexOf('.') == -1 || seltext.length) { return true; } else { return false; }
		}
		else if (allowzero == true || (allowzero == false && (val.length || (!val.length && code != 48))))
		{
			// if the first number is a zero, there is no period, and they typed a zero, return false
			// otherwise, return true
			var first = val.substring(0,1);
			if (first == '0' && val.indexOf('.') == -1 && code == 48) { return false; }
			else { return true; }
		}
		else { return false; }
	}
	else if (code == 13) // enter key
	{
		if (nextifenter) { return checkenter(window.event.srcElement,e); }
		else { return true; }
	}
	else if (code == 45) // '-'
	{
		// do not allow a hyphen unless it is the first character
		if (!val.length || seltext == val) { return true; }
		else { return false; }
	}
	else { return false; }
}

// if the user hits enter on a form element, go to the next element instead of submitting the form
function checkenter(obj,e)
{
	var code;
	if (window.event) { code = window.event.keyCode; }
	else if (e) { code = e.which; }
	else { return true; }

	var shift = window.event.shiftKey;
	if (code == 13)
	{
		var nobj = (shift?getprev(obj):getnext(obj));
		if (nobj != -1) { nobj.select(); }
		return false;
	}
	else { return true; }
}

// perform onload events
var onloads = new Array();
function checkOnload()
{
	if (typeof(doOnload) != 'undefined')
	{
		doOnload();
	}
}

// go to the given URL
function go(url,txt)
{
	if (txt && txt.length)
	{
		showLoadIcon(txt);
	}
	document.location = url;
}

/**
* Return the X/Y of the mouse for the given event
* @param	object	e	event
*/
function getMouseXY(e)
{
	var posx = 0;
	var posy = 0;
	if (!e) { var e = window.event; }
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = (e.clientX + document.body.scrollLeft);
		posy = (e.clientY + document.body.scrollTop);
	}

	var pos = [posx,posy];

	return pos;
}

/**
* Return the # of pixels scrolled left
*/
function getScrollLeft()
{
	return (
		isIE
		?
		(document.body.scrollLeft ? document.bodyScrollLeft : document.documentElement.scrollLeft)
		:
		(window.pageXOffset ? window.pageXOffset : 0)
	);
}

/**
* Return the # of pixels scrolled from the top
*/
function getScrollTop()
{
	return (
		isIE
		?
		(document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop)
		:
		(window.pageYOffset ? window.pageYOffset : 0)
	);
}

/**
* Return the number with the ordinal suffix added
* @param integer num
* @return string
*/
function addOrdinalSuffix(num)
{
	var mod = (num%10);
	if (mod == 1) { suffix = 'st'; }
	else if (mod == 2) { suffix = 'nd'; }
	else if (mod == 3) { suffix = 'rd'; }
	else { suffix = 'th'; }

	return num+suffix;
}

/**
* Throw a form error, optionally focus on a field, and return false
* @param string msg
* @param object obj
* @return false
*/
function err(msg,obj)
{
	alert(msg);

	var foc = ['select','select-one'];
	var sel = ['text','password','textarea'];

	if (obj && in_array(obj.type,foc)) { obj.focus(); }
	else if (obj && in_array(obj.type,sel)) { obj.select(); }

	return false;
}

/**
* Open a window
* @param string url
* @param integer w
* @param integer h
*/
function openWindow(url,w,h)
{
	var params = [
		'width=' + w,
		'height=' + h,
		'left=' + ((screen.width/2) - (w/2)),
		'top=' + ((screen.height/2) - (h/2)),
		'scrollbars=yes',
		'status=yes'
	];
	var win = window.open(url,'openWin' + (new Date).getTime(),params.join(','));
	checkOpenWin(win);
	return win;
}

/**
* Check if the given object is an open window or not
* @param object obj
*/
function checkOpenWin(obj)
{
	if (!obj) { alert('Unable to open the window.\nIf you have a popup blocker, please configure it to allow popups for this site.'); }
}

/**
* Is this a Gecko browser? (IE: firefox)
* @return boolean
*/
function isGecko()
{
	var agent = navigator.userAgent.toLowerCase();
	return ((agent.indexOf('gecko')!=-1) || (agent.indexOf('opera')!=-1));
}

/**
* Check/uncheck the given checkboxes
*/
function toggleCheck()
{
	if (typeof(arguments[0]) == 'object' && arguments[0].length) { arguments = arguments[0]; }
	for (var i=0; i<arguments.length; i++)
	{
		var obj = $(arguments[i]);
		if (obj && obj.type == 'checkbox')
		{
			obj.checked = !obj.checked;
		}
	}
}

// toggle the visibility of the given elements
function toggleVis()
{
	if (typeof(arguments[0]) == 'object' && arguments[0].length) { arguments = arguments[0]; }
	for (var i=0; i<arguments.length; i++)
	{
		$(arguments[i]).style.visibility = ($(arguments[i]).style.visibility=='visible' ? 'hidden' : 'visible');
	}
}

// toggle the display of the given elements
function toggleDisplay()
{
	if (typeof(arguments[0]) == 'object' && arguments[0].length) { arguments = arguments[0]; }
	for (var i=0; i<arguments.length; i++)
	{
		$(arguments[i]).style.display = ($(arguments[i]).style.display=='none'||$(arguments[i]).style.display=='' ? 'block' : 'none');
	}
}

// hide the given elements (display)
function hideDisp()
{
	if (typeof(arguments[0]) == 'object' && arguments[0].length) { arguments = arguments[0]; }
	for (var i=0; i<arguments.length; i++)
	{
		$(arguments[i]).style.display = 'none';
	}
}

// show the given elements (display)
function showDisp()
{
	if (typeof(arguments[0]) == 'object' && arguments[0].length) { arguments = arguments[0]; }
	for (var i=0; i<arguments.length; i++)
	{
		var obj = $(arguments[i]);
		var tag = obj.tagName.toUpperCase();
		var setto = (tag=='TR' && !isIE ? 'table-row' : 'block');
		obj.style.display = setto;
	}
}

// hide the given elements (visibility)
function hideVis()
{
	if (typeof(arguments[0]) == 'object' && arguments[0].length) { arguments = arguments[0]; }
	for (var i=0; i<arguments.length; i++)
	{
		$(arguments[i]).style.visibility = 'hidden';
		$(arguments[i]).style.height = 0+'px';
	}
}

// show the given elements (visibility)
function showVis()
{
	if (typeof(arguments[0]) == 'object' && arguments[0].length) { arguments = arguments[0]; }
	for (var i=0; i<arguments.length; i++)
	{
		$(arguments[i]).style.visibility = 'visible';
		$(arguments[i]).style.height = 50+'px';
	}
}

/**
* Show/hide all selectboxes/iframes in the page
* @param	boolean	vis
*/
function setSelectVis(vis)
{
	var objs = document.getElementsByTagName('select');
	for (var i=0; i<objs.length; i++)
	{
		if (!objs[i].getAttribute('notoggle'))
		{
			objs[i].style.visibility = (vis ? 'visible' : 'hidden');
		}
	}

	var objs = document.getElementsByTagName('iframe');
	for (var i=0; i<objs.length; i++)
	{
		if (!objs[i].getAttribute('notoggle'))
		{
			objs[i].style.visibility = (vis ? 'visible' : 'hidden');
		}
	}
}

/**
* Center the given div
* @param	string	divID
*/
function centerDiv(divID)
{
	var obj = $(divID);
	$(divID).style.top = (((getBodyHeight() - obj.offsetHeight) / 2) + getScrollTop()) + 'px';
	$(divID).style.left = (((getBodyWidth() - obj.offsetWidth - 19) / 2) + getScrollLeft()) + 'px';
}

/**
* Position the div near the mouse cursor
* @param	mixed	divID
* @param	object	e		event object
* @param	integer	x		force this relative X [optional, defaults to mouse X]
* @param	integer	y		force this relative Y [optional, defaults to mouse Y]
* @param	boolean	center	center the DIV horizonatally? [optional, defaults to true]
*/
function positionDiv(divID,e,x,y,center)
{
	if (typeof(center) == 'undefined') { center = true; }
	if (typeof(x) == 'undefined' || x == null)
	{
		var pos = getMouse(e);
		x = pos[0];
		y = pos[1];
	}

	var obj = $(divID);
	var objH = obj.offsetHeight;
	var objW = obj.offsetWidth;
	$(divID).style.top = (y - (objH / 2)) + 'px';
	if (center)
	{
		// center the DIV
		$(divID).style.left = ((getBodyWidth() - objW - 19) / 2) + 'px';
	}
	else
	{
		// move it by the mouse cursor, but not off the screen
		var leftpos = (x - (objW / 2));
		if (leftpos < 10) { leftpos = 10; }
		$(divID).style.left = leftpos + 'px';
	}
}

/**
* Get the body width
* @return	integer
*/
function getBodyWidth()
{
	return parseInt(isIE ? document.body.offsetWidth : window.innerWidth);
}

/**
* Get the body height
* @return	integer
*/
function getBodyHeight()
{
	return parseInt(isIE ? document.body.offsetHeight : window.innerHeight);
}

/**
* Return the mouse position for the event
* @param	object	e	event object
* @return	array	[x,y]
*/
function getMouse(e)
{
	return [Event.pointerX(e),Event.pointerY(e)];
}

/**
* Toggle the 'please wait' icon
* @param	boolean	tf
* @param	string	txt	text to show in addition to 'Please Wait...' [optional, default '']
*/
var isLoading = false; // is anything loading?
function loadIcon(tf,txt)
{
	isLoading = tf;
	if (tf)
	{

		setSelectVis(false);
		centerDiv('loadIcon');
		showVis('loadIcon');
	}
	else
	{
		// hide
		setSelectVis(true);
		hideVis('loadIcon');
	}
}
function showLoadIcon(txt) { loadIcon(true,txt); }
function hideLoadIcon() { loadIcon(false); }

/**
* Reset the odd/even light/dark coloring for the given table
* @param	mixed	tbl			table ID or object
* @param	boolean	header		is there a header row? [optional, default false]
* @param	integer	head_rows	number of header rows [optional, default 0]
* @param	boolean	footer		is there a footer row? [optional, default false]
* @param	integer	foot_rows	number of footer rows [optional, default 0]
*/
function fixRowColors(tbl,header,head_rows,footer,foot_rows)
{
	if (!header)
	{
		start_row = 0;
	}
	else
	{
		head_rows = (typeof(head_rows)=='undefined' ? 1 : head_rows);
		start_row = head_rows;
	}

	if (!footer)
	{
		foot_rows = 0;
	}
	else
	{
		foot_rows = (typeof(foot_rows)=='undefined' ? 1 : foot_rows);
	}

	var even = 'line_1';
	var odd = 'line_2';
	var obj = $(tbl);

	for (var i=start_row,idx=-1; i<(obj.rows.length - foot_rows); i++)
	{
		if (obj.rows[i].style.display != 'none')
		{
			idx++;
			obj.rows[i].className = (!(idx%2) ? even : odd);
		}
	}
}

/**
* Set an objects attributes
* @param	object	obj
* @param	object	atts	['name1','val1'[,'name2','val2'[,...]]]
*/
function setObjectAttribs(obj,atts)
{
	for (var i=0; i<atts.length; i+=2)
	{
		var attrib = atts[i];
		var val = atts[i+1];
		//alert(attrib + ' = ' + val);

		switch (attrib)
		{
			case 'onclick':
				obj.onclick = new Function(val);
				break;

			case 'ondblclick':
				obj.ondblclick = new Function(val);
				break;

			case 'onmouseover':
				obj.onmouseover = new Function(val);
				break;

			case 'onmouseout':
				obj.onmouseout = new Function(val);
				break;

			default:
				obj.setAttribute(attrib,val);
		}
	}
}

/**
* Add a row to a table
* @param	string	tableID		ID of the table
* @param	string	rowID		ID for the row
* @param	string	beforeID	ID of the row to insert the new row before. -1 to add to the end
* @param	array	cells		array of cell data
*/
function addRow(tableID,rowID,beforeID,cells,row_attribs)
{
	// validate the table object
	var tblobj = $(tableID); // entire table object
	if (tblobj == 'null' || typeof(tblobj) == 'undefined')
	{
		alert('Invalid tableID: ' + tableID);
		return;
	}
	var tbl = tblobj.getElementsByTagName('tbody')[0]; // table body object

	// create the new row object
	var row = document.createElement('TR');
	row.setAttribute('id',rowID);
	if (typeof(row_attribs) == 'object' && row_attribs.length)
	{
		setObjectAttribs(row,row_attribs);
	}

	// add the cells to the row
	for (var i=0; i<cells.length; i++)
	{
		var td = document.createElement('TD');
		if (typeof(cells[i]) == 'object')
		{
			content = cells[i][0];
			atts = cells[i][1];
			setObjectAttribs(td,atts);
		}
		else
		{
			content = cells[i];
		}
		td.innerHTML = content;
		row.appendChild(td);
	}

	// add the new row to the table
	if (beforeID == -1)
	{
		// add it to the end
		tbl.appendChild(row);
	}
	else
	{
		// validate the beforeID object
		var beforeobj = $(beforeID);
		if (typeof(beforeobj) == 'undefined')
		{
			alert('Invalid beforeID: ' + beforeID);
			return;
		}
		tbl.insertBefore(row,beforeobj);
	}
}

if (!Array.prototype.shift)
{
	Array.prototype.shift = function()
	{
		var ret = this[0];
		for (var i=0; i<(this.length - 1); i++)
		{
			this[i] = this[i + 1];
		}
		this.length--;
		return ret;
	}
}

/**
* Remove the given index from the passed array
*/
Array.prototype.removeIndex = function(idx)
{
	var new_this = new Array();
	if (this.length > idx)
	{
		for (var i=(idx + 1); i<=this.length; i++)
		{
			this[i - 1] = this[i];
		}
		this.length--;
	}
}

/**
* Delete the elements from all passed arrays with an array index of the passed ID in the first array
* That made no sense...if you find it in usage, you'll get it!
* This function requires at least 2 parameters: an ID to remove and an array of IDs
* All other parameters must be arrays that need to have the element unset
* @return	array(ID_array[,other_array1[,other_array...]])
*/
function removeIDValues()
{
	if (arguments.length < 2) { return; }
	else if (typeof(arguments[1]) != 'object') { return; }
	else
	{
		var removeID = arguments[0];
		var arrayIDs = arguments[1];
		var idx = array_search(removeID,arrayIDs);
		if (idx == -1)
		{
			// ID not found; return all array arguments
			arguments.shift();
			return arguments;
		}
		else
		{
			var ret = new Array();
			for (var i=1; i<arguments.length; i++)
			{
				arguments[i].removeIndex(idx);
				ret[i - 1] = arguments[i];
			}
			return ret;
		}
	}
}
Object.extend(Field,
	{
		// enable the passed fields
		enable:function()
		{
			if (typeof(arguments[0]) == 'object')
			{
				// array passed
				arguments = arguments[0];
			}
			for (var i=0; i<arguments.length; i++)
			{
				$(arguments[i]).disabled = false;
			}
		}, // end function Field.enable

		// disable the passed fields
		disable:function()
		{
			if (typeof(arguments[0]) == 'object')
			{
				// array passed
				arguments = arguments[0];
			}
			for (var i=0; i<arguments.length; i++)
			{
				$(arguments[i]).disabled = true;
			}
		} // end function Field.disable
	}
);

Object.extend(Form,
	{
		// blur all fields in the given form
		blurAll:function(frm)
		{
			var frm = $(frm);
			for (var i=0; i<frm.elements.length; i++)
			{
				if (frm.elements[i].blur)
				{
					frm.elements[i].blur();
				}
			}
		},

		// are any of the checkboxes in the given form checked?
		anyChecked:function(frm)
		{
			var objs = Form.getInputs(frm,'checkbox');
			for (var i=0; i<objs.length; i++)
			{
				if (objs[i].type == 'checkbox' && objs[i].checked && !objs[i].ignored)
				{
					return true;
				}
			}
			return false;
		},

		// check/uncheck all checkboxes in the given form
		checkAll:function(frm,chk)
		{
			var objs = Form.getInputs(frm,'checkbox');
			for (var i=0; i<objs.length; i++)
			{
				if (objs[i].type == 'checkbox')
				{
					objs[i].checked = chk;
				}
			}
		}
	}
);



/**
* Center the login page values
*/
function moveLoginPage()
{
	var moveX = Position.cumulativeOffset($('canvas'))[0];
	var moveY = Position.cumulativeOffset($('canvas'))[1];

	var objs = document.getElementsByClassName('canvas');
	for (var i=0; i<objs.length; i++)
	{
		obj = objs[i];
		var w = obj.offsetWidth;
		obj.style.left = (Position.cumulativeOffset(obj)[0] + moveX) + 'px';
		obj.style.top = (Position.cumulativeOffset(obj)[1] + moveY) + 'px';
		obj.style.width = w + 'px';
		obj.style.visibility = 'visible';
	}
}

/**
* Switch the cost and retail prices
*/
function switchCostRetail()
{
	cr_show = (cr_show=='cost' ? 'retail' : 'cost');
	cr_noshow = (cr_show=='cost' ? 'retail' : 'cost');

	var objs = document.getElementsByClassName(cr_noshow);
	for (var i=0; i<objs.length; i++) { hideDisp(objs[i]); }

	var objs = document.getElementsByClassName(cr_show);
	for (var i=0; i<objs.length; i++) { showDisp(objs[i]); }
}

/**
* Fill the given selectbox with the given values
* @param	mixed	selID
* @param	array	opts
* @param	boolean	add_blank	first option is a blank?
*/
function fillOptions(selID,opts,add_blank)
{
	var obj = $(selID);
	if (!obj || !obj.options) { return; }
	if (typeof(add_blank) == 'undefined') { add_blank = false; }

	obj.options.length = 0;
	if (add_blank)
	{
		// add a blank entry
		obj.options[obj.options.length] = new Option('','');
	}
	for (var i=0; i<opts.length; i+=2)
	{
		obj.options[obj.options.length] = new Option(opts[i],opts[i+1]);
	}
}

// returns the index in the selectbox object that the needle (string) is found, or -1 if it is not found
function select_search(needle,obj)
{
	for (var i=0; i<obj.options.length; i++)
	{
		if (''+obj.options[i].value == ''+needle) { return i; }
	}
	return -1;
}

/**
* Resize a report iframe to fit in the user's browser window
*/
function resizeReport(obj,add_top)
{
	if ($(obj))
	{
		var pad_top = 200;
		var pad_lr = 20;
		var pad_bottom = 80;
		var winw = document.body.offsetWidth;
		var winh = document.body.offsetHeight;

		var setw = (winw - (pad_lr * 2));
		var seth = (winh - pad_top - pad_bottom) + (typeof(add_top) != 'undefined' ? add_top : 0);

		// correct difference between IE/non-IE browsers finding offsetHeight different
		if (!isIE) { seth += 125; }

		$(obj).style.width = setw + 'px';
		$(obj).style.height = seth + 'px';
	}
}

/**
* Cross-browser event handling
* @param	object	obj
* @param	string	event_name	ie: 'load', 'click'
* @param	string	func		function to call
* @param	boolean	use_capture	[optional]
*/
function addEventHandler(obj,event_name,func,use_capture)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(event_name,func,use_capture);
		return true;
	}
	else if (obj.attachEvent)
	{
		if (event_name.substring(0,2) != 'on') { event_name = 'on' + event_name; }
		return obj.attachEvent(event_name,func);
	}
	else
	{
		alert('Handler could not be attached');
	}
}

/**
 * Show the vehicle select/change layer
 */
function showVehicleSelect()
{
	if ($('vehLookup'))
	{
		// hide the home page vehicle lookup
		$('vehLookup').innerHTML = '';
	}

	$('change_vehicle').style.display = 'block';
	setVehicleObject('vehChange');
	doVehicleChange(0, 'init');
}

/**
 * Hide the vehicle selection
 */
function hideVehicleSelect()
{
	$('vehChange').innerHTML = '- Please Wait -';
	$('change_vehicle').style.display = 'none';

	if ($('vehLookup'))
	{
		// reload the home page vehicle lookup
		setVehicleObject('vehLookup');
		doVehicleChange(0, 'init');
	}
}

/**
 * Show the size select/change layer
 */
function showSizeSelect()
{
	$('change_size').style.display = 'block';
}

/**
 * Hide the size selection
 */
function hideSizeSelect()
{
	$('change_size').style.display = 'none';
}

/**
 * Save the sizes
 */
function saveSizes()
{
	var url = 'lookup/lookupUpdate.php';
	var ajax = new Ajax.Request(
		url,
		{
			method:'post',
			parameters:Form.serialize('frmChangeSize'),
			onComplete:function()
			{
				go('/index.php');
			}
		}
	);
}

// header image cycling
var cycle_max     = 10;
var cycle_delay   = 5000;

var cycle_current = 6;

function doCycle()
{
	cycle_current++;
	if (cycle_current > cycle_max)
	{
		cycle_current = 1;
	}

	if (in_array(cycle_current, [7, 8, 9, 10]))
	{
		// skip this one
		doCycle();
		return;
	}

	link = 'javascript:void(0)';
	//link = '/specials.php?ad=goodyear';
	//link = '/view_tab.php';

	if (cycle_current == 8)
	{
		link = '/specials.php?ad=goodyear_100_rebate';
	}
	else if (cycle_current == 9)
	{
		link = '/specials.php?ad=bfgoodrich_prepaid_visa';
	}
	else if (cycle_current == 10)
	{
		link = '/specials.php?ad=continental_free_gps';
	}

	$('lnkRotate').href = link;
	$('imgRotate').src = '/images/plains_rotate' + (cycle_current<10 ? '0' : '') + cycle_current + '.gif';

	cycle_delay = (cycle_current==1 ? 8000 : 5000);
	cycleTimer();
}

function cycleTimer()
{
	setTimeout('doCycle()', cycle_delay);
}

-->
