
// GroundBooth Software, Inc.
// Copyright 2006.  All rights reserved.
	function rand(low, high)
	{
		return (Math.round((Math.random()*high)+low));
	}

	function getAbsoluteTop(o)
	{
		var top = 0;
		while (o!=null)
		{
			top += Number(stripPx(o.offsetTop));
			
			if (!isMoz())
			{
				o = o.parentElement;
			}
			else
			{
				o = o.offsetParent;
			}
		}
		return top;		
	}
	
	function getAbsoluteLeft(o)
	{
		var top = 0;
		while (o!=null)
		{
			top += Number(stripPx(o.offsetLeft));
			
			if (!isMoz())
			{
				o = o.parentElement;
			}
			else
			{
				o = o.offsetParent;
			}
		}
		return top;		
	}	

	function geigelCam()
	{
		
		get("geigelCamLink").innerHTML = "<img id='webcamThumb' width='80' height='60' alt='art geigel | geigel.com webcam' title='art geigel | geigel.com webcam' style='border:1px solid #000000; display:none' src='http://www.geigel.com/webcam/webcam_thumb.jpg?" + String(Math.floor(Math.random()*1000000))  + "' border='1'>";
		
		show("webcamThumb");	
		setTimeout(geigelCam, 5000);
	}
	
	function fuzz(how)
	{
		if (how)
		{
			disableAllDropDowns(true);
		}
		
	}

	function bodyResize()
	{
		if (isClouded())
		{
			showCloud(true)
		}
	}
	

	function fadeAnim (prefix, start, end, imgType, hang, o, dur, step)
	{
		var i = start;		
		var firstTime = true;
		var img = document.createElement("img");
		hang *= 1000;
		document.body.appendChild(img);
		fade(img, 0);
		img.src = "acorn_base/anim/" + prefix + Number(start+1) + "." + imgType;
		img.width = o.width;
		img.height = o.height;
		img.border = o.border;
		img.id = "__under_" + o.id;
		img.style.position = "absolute";
		img.style.left = getTotalOffset(o, "left") + "px";
		img.style.top = getTotalOffset(o, "top") + "px";
		
		
		function _fadedOut(o2)
		{
			if (firstTime)
			{
				i+=2;
				firstTime = false;
			}
			else
			{
				i++;
			}						
			
			if (i > end)
			{
				i = start;	
			}	
					
			get(o2.id).src = "acorn_base/anim/" + prefix + i + "." + imgType + "?" + rand(0,900000);	
			
			function _wait2fadeIn()
			{
				fadeIn(get(o2.id), dur, step, _fadedIn);
			}
			
			setTimeout( _wait2fadeIn, hang);			
		}
		
		function _fadedIn(o3)
		{
			function _wait2fadeOut()
			{
				//debugger;
				fadeOut(get(o3.id), dur, step, _fadedOut);				
			}
			//debugger;

			setTimeout( _wait2fadeOut, hang);
		}
		
		function _firstFade()
		{
			fadeOut(o, dur, step, _fadedOut);
			fadeIn(img, dur, step, _fadedIn);		
		}
		
		setTimeout( _firstFade, hang);
	}

	function fadeWorker (o, dur, step, fn, way, ev)
	{
		function _fadeWorker()
		{
		
			function _fadeCycleComplete()
			{
				o.setAttribute("fading", "finished");
				if (fn!="" && fn!=null)
				{
					fn(o, dur);
				}
			}
			
			if (o.getAttribute("fading")=="in" && way.toUpperCase()=="OUT")
			{
				get(o.id).setAttribute("stopFadingIn", "true");			
			}
			if (o.getAttribute("fading")=="out" && way.toUpperCase()=="IN")
			{
				get(o.id).setAttribute("stopFadingOut", "true");
			}			
			
			var curOpacity = getOpacity(o);
			if (way.toUpperCase()=="IN")
			{
				o.setAttribute("fading", "in");
				fadeIn(o, dur, step, _fadeCycleComplete);
			}
			else
			{
				o.setAttribute("fading", "out");
				fadeOut(o, dur, step, _fadeCycleComplete);
			}
		}
						
		if (isMoz())
		{
			o.addEventListener(ev, _fadeWorker, false);
		}
		else
		{
			o.attachEvent("on" + ev, _fadeWorker);
		}
	}
			
	function fadeInOnMouseOver(o, dur, step, fn)
	{
		fadeWorker(o, dur, step, fn, "in", "mouseover");
	}	

	function fadeOutOnMouseOver(o, dur, step, fn)
	{
		fadeWorker(o, dur, step, fn, "out", "mouseover");	
	}	
	
	function fadeInOnMouseOut(o, dur, step, fn)
	{
		fadeWorker(o, dur, step, fn, "in", "mouseout");
	}	

	function fadeOutOnMouseOut(o, dur, step, fn)
	{
		fadeWorker(o, dur, step, fn, "out", "mouseout");	
	}		
	
	
	function fadeLoop (o, dur, step)
	{
		function fadeFlip()
		{
			if (getOpacity(o)==0)
			{
				fadeIn(o, dur, step, fadeFlip);
			}
			else
			{
				fadeOut(o, dur, step, fadeFlip);
			}		
		}
	
		fadeOut(o, dur, step, fadeFlip);	
	}

	function fade(o, op)
	{
		opacity(o, op);
	}
	
	function opacity(o, op)
	{
		if (op>100)
		{
			op = 100;
		}
		if (op<0)
		{
			op = 0;
		}
		
		if (isMoz())
		{	
			op *= .01;
			o.style.MozOpacity = op;
		}
		else
		{
			o.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity:" + op + ")";	
		}		
	}
	
	function ibeam(o, s, e)
	{
		if (isMoz())
		{
			o.setSelectionRange(s,e);
		}
		else
		{
			var r = o.createTextRange();		
			r.collapse(true);		
			r.moveEnd('character', e);		
			r.moveStart('character', s);		
			r.select();		
		}		
	}
	
	function fadeDirection(o, dur, step, fn, way)
	{
		//debugger;
		var origDur = dur;
		dur = dur * 1000; // to mili
		var stepDur = dur / 100;

		function _opacity()
		{
			var curOpacity = getOpacity(o);
			var newOpacity = 0;
			if (way=="in")
			{			
				newOpacity = curOpacity+step;
			}
			else
			{
				newOpacity = curOpacity-step;
			}
			opacity(o, newOpacity);
		}		

		function fadingDir ()
		{
			var conditionMet = -1;
			o = get(o.id); // remind our object what object is is including any new attributes
			if (way=="in")
			{
				if (o.getAttribute("stopFadingIn")=="true")
				{
					get(o.id).setAttribute("stopFadingIn", "false");
					return;
				}			
				else
				{
					_opacity();
					conditionMet = 100;
				}
			}
			else
			{
				if (o.getAttribute("stopFadingOut")=="true")
				{
					get(o.id).setAttribute("stopFadingOut", "false");
					return;
				}			
				else
				{
					_opacity();
					conditionMet = 0;
				}
			}			
			if (getOpacity(o)==conditionMet)
			{
				get(o.id).setAttribute("fading", "finished");
				if (fn!="" && fn!=null)
				{	
					fn(o, origDur);
				}
				return;
			}
			setTimeout(fadingDir, stepDur);
		}				
	
		// dur is duration in secs, and we have 100 % to go up thru, so
		// a step rate can be determined by 
		setTimeout(fadingDir, stepDur);	
	}


	function fadeIn(o, dur, step, fn)
	{
		fadeDirection(o, dur, step, fn, "in");
	}
	
	function fadeOut(o, dur, step, fn)
	{
		fadeDirection(o, dur, step, fn, "out");
	}	

	
	function getOpacity(o)
	{

		if (isMoz())
		{		
			if (o.style.MozOpacity=="")
			{
				o.style.MozOpacity = 1;
			}
			return (o.style.MozOpacity) * 100;
		}
		else
		{
			try
			{
				return o.filters.item("DXImageTransform.Microsoft.Alpha").Opacity;
			}
			catch (e)
			{
				o.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity:100)";
				return 100;
			}
		}		
	}

	
	function getEventObject(e)
	{
		if (isMoz())
		{
			return e.target;
		}
		else
		{
			return e.srcElement;
		}
	}
	
	function resetDLB(id)
	{
		var o = get(id);
		var trs = o.getElementsByTagName("tr");
		var i = 0;
		for (i=0; i<trs.length; i++)
		{
			if (trs[i].getAttribute("resetToVisible")!=null)
			{
				trs[i].style.display = trs[i].getAttribute("resetToVisible");
			}
		}	
		get(id.substr(1,id.length) + "_dirty").value = false;
	}
	
	function doneWaiting()
	{
		return;
	}

	function wait(delay)
	{
		/*
		delay = Number(delay);
		delay*=1000;

		var start = new Date();
		var end = new Date();
				
		
		do 
		{ 
			end = new Date(); 
			//alert(Number(end - start));
				
		}
		while(end-start < delay);
		*/
	}

	function niceDate(date)
	{
		// assume date = yyyy-mm-dd
		return String(date.substr(5,2)) + "/" + String(date.substr(8, 2)) + "/" + String(date.substr(0,4));
	}
	
	function mysqlDate(date)	
	{
		// assume date = mm/dd/yyyy
		return String(date.substr(6,4)) + "-" + String(date.substr(0,2)) + "-" + String(date.substr(3,2));
	}

	function getTotalOffset(o, what)
	{
		var totalLeft = 0;
		var totalTop = 0;
		while (o!=null)
		{
			totalLeft += o.offsetLeft;
			totalTop += o.offsetTop;
			o = o.offsetParent;
		}			
				
		if (what.toUpperCase()=="LEFT")
		{
			return totalLeft;
		}
		
		if (what.toUpperCase()=="TOP")
		{
			return totalTop;
		}
	}
	
	function imageServicesChange(id)
	{
		
		// make sure we're legit file extension
		var file = get(id + "_GBImageServices").value;
		var ext = String(file.substr(file.length-3, file.length)).toLowerCase();
		if (ext!="jpg" && ext!="gif")
		{		
			get(id + "_GBImageServices").value = "";
			alert("You must select either a JPG or a GIF image.");
			return;
		}
		hide(id + "_GBImageServices");
		
		get(id + "_customer_id").value = parent.get(id + "_uploadCustomerId").value;
		
		// if we've already been uploading a bunch let's just reuse the same file name
		// so we dont waste more time...
		if (parent.get(id + "_uploadedFile").value!="")
		{
			get(id + "_reuseFile").value = parent.get(id + "_uploadedFile").value;
		}
		
		// upon selection we immediately upload that beotch
		parent.get(id + "_realBrowseButton").src = "../uploadanim.gif";
		document.uploadForm.submit();
	}	

	function uploadNone(id)
	{
		disable(id + "_noneButton");
		parent.get(id + "_realBrowseButton").src = "../uploadanim.gif";
		function uploadNoneExecute(r)
		{
			get(id + "_realBrowseButton").src = "../missing.gif";
			get(id + "_toUpload").value = "";
			get(id + "_filename").innerHTML = "(none)";
			get(id + "_filesize").innerHTML = "(none)";
			get(id + "_uploadedFile").value = "";	
			get(id + "_newHeight").value = "57";	
			get(id + "_fakeBrowseButton").height = "57";	
			get(id + "_fakeBrowseButton").src = "imageServicesUpload.php?isid="+id;
			enable(id + "_noneButton");
		}

		if (get(id + "_uploadedFile").value!="")
		{		
			Aajax("admin/ajax.php", "removeFile=true&file=" + get(id + "_uploadedFile").value, uploadNoneExecute);
		}
		else
		{
			uploadNoneExecute();
		}

	}


	function saveCalendar()
	{
		var id = get("cal_id").value;
		var date = get("cal_selectedDate").innerHTML;
		
		
		get("month_"+id).value = date.substr(0,2);
		get("day_"+id).value = date.substr(3,2);
		get("year_"+id).value = date.substr(6,4);
		
		get(id).value = date.substr(6,4) + "-" + date.substr(0,2) + "-" + date.substr(3,2);
		
		hide("cal_box");

		updateDateValue(id);

		hideCloud();
	}
	
	function showCalendar(e, renderDate, title, id)
	{		
		var o = null;
		var mouseX = 0;
		var mouseY = 0;
		if (isMoz())
		{
			o = e.target;
			mouseX = e.pageX;
			mouseY = e.pageY;
		}
		else
		{
			o = e.srcElement;
			mouseX = e.clientX + document.body.scrollLeft;
		    mouseY = e.clientY + document.body.parentElement.scrollTop; //document.body.scrollTop;
		}
	
		if (getEventObject(e).disabled)
		{
			return;
		}
		
		
		var totalLeft = mouseX;
		var totalTop = mouseY - 290;
		/*
		while (o!=null)
		{
			totalLeft += o.offsetLeft;
			totalTop += o.offsetTop;
			o = o.offsetParent;
		}			
		*/
		
		cal_curDate = renderDate;
		cal_renderDate(renderDate);			

		var theNiceDate = renderDate.substr(5,2) + "/" + renderDate.substr(8,2) + "/" + renderDate.substr(0,4);
		
		get("cal_id").value = id;		
		get("cal_title").innerHTML = title;
		get("cal_selectedDate").innerHTML = theNiceDate;
		
		showCloud();
		var c = get("cal_box");
		c.style.left = String(Number(totalLeft)) + "px";
		c.style.top = String(Number(totalTop)) + "px";
		show("cal_box");
	}
	
	function hideCalendar()
	{
		hide("cal_box");
		hideCloud();
	}
	
	
	function saveDLB(id)
	{
		return dlbAction(id, "save");
	}
	
	function addDLB(id)
	{
		dlbAction(id, "avail");
	}

	function removeDLB(id)
	{
		dlbAction(id, "assign");
	}
	
	
	function dirtyDLB(id)
	{
		return eval(document.getElementById(id + "_dirty").value);	
	}
	
	function dlbAction(id, type)
	{
		var r = Array;
		var div = null;
		if (type=="assign" || type=="avail")
		{
			div = document.getElementById(id + "_" + type + "_div");
		}
		if (type=="save")
		{
			div = document.getElementById(id + "_assign_div");			
		}
		var tds = div.getElementsByTagName("td");
		var td = null;
		var tr = null;
		var index = -1;
		var o = null;
		var i = 0;
		var otherType = (type=="assign") ? "avail" : "assign";
		var val = "";
		var saveIndex = 0;
		//debugger;
		for (i = 0; i < tds.length; i++)
		{
			td = tds[i];
			if (type=="assign" || type=="avail")
			{
				if (eval(td.getAttribute("selected")))
				{
					document.getElementById(id + "_dirty").value = "true";					
					index = td.getAttribute("index");
					
					// show the selected item on the other list			
					document.getElementById(id + "_" + index + "_" + otherType).style.display = "";
					document.getElementById(id + "_" + index + "_" + otherType).setAttribute("selected", "false");	
					document.getElementById(id + "_" + index + "_" + otherType).className = "bgNormal";						
					td.style.display = "";
					td.className = "bgNormal";
					td.setAttribute("selected", "false");
					
					// set object moving from to nothing
					o = document.getElementById(id + "_" + index + "_" + type);
					o.setAttribute("selected", "false");
					o.className = "bgNormal";				
					o.style.display = "none";
				}
			}
			
			if (type=="save")
			{
				tr = td.parentElement;			
				if (tr.style.display=="")
				{
					r[saveIndex] = new Array
					r[saveIndex]["name"] = td.innerHTML;
					r[saveIndex]["value"] = tr.value;		
					saveIndex++;
				}
			}
		}		

		if (type=="save")
		{	
			get(id + "_dirty").value = false;
			return r;
		}
	}
	
	
	function validatePasswords(p1, p2)
	{
		
		p1 = unescape(p1);
		p2 = unescape(p2);
		
		if (trim(p1)=="" || trim(p2)=="")
		{
			alert("You must supply a password and a confirmed password.");
			return false;
		}
		
		if (p1!=p2)
		{
			alert("The passwords do not match.  Please try again.");
			return false;
		}
		
		return true;
		
	}
	
	function validateZip(zip)
	{	
		if (isNaN(Number(zip)))
		{
			return false;
		}
		
		if (String(zip).length!=5)
		{
			return false;
		}
		
		return true;
	}

	function harvest(h)
	{

		
		function oHarvest()
		{
			this.url = null;
			this.count = null;	
			this.vars = null;	
		}		
		
		var r = new oHarvest();
		var i = 0;
		var divs = document.getElementsByTagName("DIV");
		var div = null;
		var validDiv = false;
		var realCount = 0;
		for (i = 0; i < divs.length; i++)
		{
			div = divs[i];
			if (div.getAttribute("harvest")==h)
			{
				validDiv = true;
				break;
			}	
		}
		
		if (validDiv)
		{
			var c = div.getElementsByTagName("input");		// inputs
			var c2 = div.getElementsByTagName("select");	// selects
			var c3 = div.getElementsByTagName("textarea");	// textareas
			var ci = null;
			var url = "";
			var vars = new Array();
			var calcValue = null;
						
			//r.count = c.length + c2.length + c3.length;
			
			// gets all input boxes (not buttons)
			for (i = 0; i < c.length; i++)
			{
				ci = c[i];
				
				if (ci.type=="text" || ci.type=="password" || ci.type=="hidden")
				{
					calcValue = ci.value.replace(/’/g, "'");;
				}
				
				if (ci.type=="checkbox")
				{
					calcValue = ci.checked;
				}

				if (ci.type=="radio")
				{
					calcValue = ci.checked;
				}											
				
				if (ci.type!="button")
				{
					vars[ci.id] = calcValue;
					url += ci.id + "=" + escape(calcValue) + "&";
					realCount++;
				}
			}	
			
			// gets all select boxes
			for (i = 0; i < c2.length; i++)
			{
				ci = c2[i];
				realCount++;
				
				calcValue = ci.value.replace(/’/g, "'");;				
				vars[ci.id] = calcValue;
				url += ci.id + "=" + escape(calcValue) + "&";
			}
			
			// gets all textareas
			for (i = 0; i < c3.length; i++)
			{
				ci = c3[i];
				realCount++;
				
				calcValue = ci.value.replace(/’/g, "'");	
				vars[ci.id] = calcValue;
				url += ci.id + "=" + escape(calcValue) + "&";
			}			
			
			r.vars = vars;
			r.url = url.substring(0, url.length-1);
			r.count = realCount;
			return r;
		}
		else
		{
			return null;
		}
	
	}
	
	function get(id)
	{
		return document.getElementById(id);
	}
	
	function hide(id)
	{
		document.getElementById(id).style.display = "none";
	}
	
	function show(id)
	{
		document.getElementById(id).style.display = "inline";
	}

	function disable(id)
	{
		document.getElementById(id).disabled = true;
	}
	
	function enable(id)
	{
		document.getElementById(id).disabled = false;		
	}
	
	function clear(id)
	{
		document.getElementById(id).value = "";
	}

	function setFocus(id)
	{
		document.getElementById(id).focus();
	}	

function Aajax (page, query, fn)
{
	

	

	// weird IE bug related to HTTPS ajax calls, sometimes fails
	var x = null;	
	if (window.XMLHttpRequest)  
	{
		// FF
		x = new XMLHttpRequest(); 
	}
	else if (window.ActiveXObject)
	{	
		try
		{
			x = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e2)
		{
			try
			{
				// IE
				x = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e2) 
			{
				fn("Your browser does not support ActiveX objects.  Please turn this feature on or use a different browser.");
				  return;
			}
		}
	}

	function stateChange()
	{		
		if (x.readyState==4)		
		{
			fn(x.responseText);
		}
	}

	var postPage =  page;
	x.open("POST", postPage, true);
	x.onreadystatechange = stateChange;
	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");			
//	x.setRequestHeader("Connection", "close");
	x.send(query);
	success = true;
			

	//return x.responseText;
}

	function isMoz()
	{
		var browser = navigator.userAgent.toLowerCase();	
		if (browser.indexOf("firefox")!=-1)
		{
			return true;
		}
		else
		{
			return false;
		}		
	}
	
	function getEnv(envType)
	{
		return top.document.getElementById("env" + envType).value;
	}	
	
	function getScreenWidth()
	{
		return document.documentElement.clientHeight;
	}

	function updateCloudDivPosition()
	{
		scrollCloudDiv();
//				var height = document.documentElement.clientHeight);
	}
	
	
	function scrollCloudDiv()
	{		

		var pos = document.body.scrollTop;
		
		if (pos == 0)		
		{		
			if (window.pageYOffset)		
			{
				pos = window.pageYOffset;		
			}
			else		
			{
				if (document.body.parentElement)
				{
					pos = document.body.parentElement.scrollTop ;
				}
				else
				{
					pos = 0;
				}
			}
		}

		var o = document.getElementById("cloudDivDiv");
		var divHeight = 0;
		try
		{
			divHeight = document.getElementById("cloudDivHeight").height;
		}
		catch (e) 
		{
			divHeight = 0;	
		}
		var screenHeight = document.documentElement.clientHeight;
		var halfTheDiv = divHeight / 2;
		if (screenHeight<divHeight)
		{
			screenHeight = 0;
			halfTheDiv = 0;
		}
//		alert(halfTheDiv);
		if (o.style.display=="")
		{
			var fooPos = pos + (screenHeight/2) - halfTheDiv; //cloudHeightOffset;
			if (isMoz())
			{
				fooPos = fooPos + "px";
			}
			o.style.top = fooPos;	
		}
	}	
	
	function stripPx(value)
	{
		if (!isNaN(value))
		{
			value = String(value);
		}
		return parseInt(value.replace(/px/g, ""));
	}
	

	function showOverlayLite (height, width)
	{
		// set the content first so hopefully it loads a lot before we make it visible
		showCloud();

		var homeTableWidth = document.getElementById("homeTable").width;

		// stupid overlap error if 100%, this makes it look good
		if (width=="100%")
		{
			width="99%";
		}				
		
		// set homeTableCloud width = to the hometable (whatever it might be)
		// (this element contains the iframe and is not the iframe width itself, that's set below)
		document.getElementById("homeTableCloud").width = homeTableWidth;
	
		// set the width & h of the div
		document.getElementById("cloudDivWidth").width = width;
		document.getElementById("cloudDivHeight").height = height;
		
		// move to slightly lower than the top
		var cloudDivDiv = document.getElementById("cloudDivDiv");	
		//cloudDivDiv.style.top = cloudHeightOffset;
		
		// show the overlay after setting everything
		cloudDivDiv.style.display = "";
		scrollCloudDiv();
		
	}

	function showOverlay (src, values, height, width)
	{
		// set the content first so hopefully it loads a lot before we make it visible
		showCloud();
		var totalSrc = src + "?framedPageHeaderCode=donttrytohackthissite&" + values;
		document.getElementById("cloudDivContent").src = totalSrc;

		var homeTableWidth = document.getElementById("homeTable").width;

		// stupid overlap error if 100%, this makes it look good
		if (width=="100%")
		{
			width="99%";
		}				
		
		// set homeTableCloud width = to the hometable (whatever it might be)
		// (this element contains the iframe and is not the iframe width itself, that's set below)
		document.getElementById("homeTableCloud").width = homeTableWidth;
	
		// set the width & h of the div
		document.getElementById("cloudDivWidth").width = width;
		document.getElementById("cloudDivHeight").height = height;
		
		// move to slightly lower than the top
		var cloudDivDiv = document.getElementById("cloudDivDiv");	
		//cloudDivDiv.style.top = cloudHeightOffset;
		
		// show the overlay after setting everything
		cloudDivDiv.style.display = "";
		scrollCloudDiv();
		
	}
	
	
	function closeOverlay ()
	{
		// this code is in reference to a framed page, so it asks for it's parent (which is admin)
		// and the subordinate object which represents itself
		var me = parent.document.getElementById("cloudDivDiv");
		me.src = "";
		me.style.display = "none";
		hideCloud(true);
		
		// finally refresh any updates to the page that are needed
	}
	
	
	function showCloud()
	{
		disableAllDropDowns(true);
		var cloudContainer = document.getElementById("cloudContainer");
		var cloud = document.getElementById("cloud");
		
		var displace = 0;
		if (isMoz())
		{
			displace = 20;
		}
		else
		{
			displace = 35;
		}
		
		var height = document.getElementById("homeTable").scrollHeight + displace + 20;
		cloud.setAttribute("height", height);
		cloudContainer.style.display = "";
		
	}
	
	function disableAllDropDowns(trueOrFalse, asSub)
	{
		// only IE is stupid...
		if (!isMoz())
		{				
			var drops = document.getElementsByTagName("select");
			for(i=0; i<drops.length; i++)
			
			{
					var showOrHide = (trueOrFalse) ? "hidden" : "visible";
					drops[i].style.visibility = showOrHide;
			}
		}
	}
	
	
	function hideCloud(asSub)
	{
		var someObj = null;
		if (asSub)
		{
			someObj = parent;
		}
		else
		{
			someObj = window;
		}
		
		disableAllDropDowns(false, asSub);
		var cloudContainer = someObj.document.getElementById("cloudContainer");
		cloudContainer.style.display = "none";
	}
	
	function isClouded()
	{
		var cloudContainer = document.getElementById("cloudContainer");
		if (cloudContainer.style.display=="")
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function bgHighlight(id)
	{
		
		// actually update bg color
		var o = document.getElementById(id);
		o.className = "bgHighlight";
	}

	function bgNormal(id)
	{
		
		// actually update bg color
		var o = document.getElementById(id);
		o.className = "bgNormal";
	}

	function borderHighlight(id)
	{
		
		// actually update bg color
		var o = document.getElementById(id);
		o.className = "borderHighlight";
	}

	function borderNormal(id)
	{
		
		// actually update bg color
		var o = document.getElementById(id);
		o.className = "borderNormal";
	}

	function killMenu(e)
	{
		if (isMoz())
		{
			if (e.target.type!="text")
			{
				e.preventDefault();
			}			
		}
		else
		{
			if (event.srcElement.type!="text")
			{
				event.returnValue = false;
			}
		}
	}

	function updateDateValue (id)	
	{
		//debugger;
		var month = document.getElementById("month_" + id).value;
		var day = document.getElementById("day_" + id).value;
		var year = document.getElementById("year_" + id).value;
		var totalDate = year + "-" + month + "-" + day;
		get(id + "_href").innerHTML = month + "/" + day + "/" + year;
		document.getElementById(id).value = totalDate;
	}

	function updateTimeValue (id)	
	{
		var hour = document.getElementById("hour_" + id).value;
		var minute = document.getElementById("minute_" + id).value;
		var ampm = document.getElementById("ampm_" + id).value;
		var totalTime = hour+ ":" + minute + " " + ampm;
		document.getElementById(id).value = totalTime;
	}

	
	function validatePositiveInteger (val)
	{
		if (isNaN(val))
		{
			return false;
		}
		if (val.indexOf(".")!=-1)
		{
			return false;
		}
		if (val.indexOf("-")!=-1)
		{
			return false;
		}
		return true;
	}
	
	function validateCurrency (val)
	{
		if (isNaN(val))
		{
			return false;
		}
		
		// how many "." places are there?
		if (val.indexOf(".")!=-1)
		{
			var pos = -1;
			var cVal = val;
			pos = cVal.indexOf(".");
			cVal = cVal.substr(pos+1, cVal.length);
			if (cVal.length>2)
			{
				return false;
			}
		}	
		
		if (val.indexOf("-")!=-1)
		{
			return false;
		}
		
		return true;
	}	
	
	function trim(val)
	{
		return val.replace(/^\s+|\s+$/, "");
	}
	
	function validateEmail(email)
	{

		var atPos = email.indexOf("@");

		// no @ sign
		if (atPos==-1)
		{
			return false;
		}
		
		var first = email.substring(0, atPos);
		var second = email.substr(atPos+1, email.length);
		
		// confirm valid a-z 0-9 and . _ - chars only
		if (!first.match("^[-\._A-Za-z0-9]+$") || !second.match("^[-\._A-Za-z0-9]+$"))
		{
			return false;
		}
		
		
		// @ can't be in the second part if we've already split on it
		atPos = second.indexOf("@");
		if (atPos!=-1)
		{
			return false;
		}

		var tld = second.substr(second.length-5, second.length);
		tld = tld.toLowerCase();
		var cTld = tld;
		// only .com, .net, .org, .biz, .us, .gov, .info .edu addresses are allowed
		var periodPos = 0;
		var i = 0;
		while (i < cTld.length+1)
		{
			var foo = cTld.substr(cTld.length-i, cTld.length);
			if (foo.substring(0,1)==".")
			{
				periodPos = i;
			}
			
			i++;
		}

		var trueTld = tld.substr(tld.length-periodPos, tld.length);
		if (trueTld=="")
		{
			return false;
		}

		if (periodPos==5)
		{
			if (trueTld!=".info")
			{
				return false;
			}
		}				
		if (periodPos==4)
		{
			if (trueTld!=".com" && trueTld!=".net" && trueTld!=".org" && trueTld!=".biz" && trueTld!=".gov" && trueTld!=".edu")
			{
				return false;
			}
		}
		if (periodPos==3)
		{
			if (trueTld!=".us")
			{
				return false;
			}
		}	
		if (periodPos!=3 && periodPos!=4 && periodPos!=5)
		{
			return false;
		}
		
		return true;
	}
	
	function getKeyPress(e)
	{		
		//alert(event.keyCode);
		if (e.shiftKey)
		{
			// 68 - 69 - 66 - 85 - 71
			// 4 - 5 - 2 - 21 - 7
			var i = 0;
			for (i=0; i<4; i++)
			{
				prevKey[i] = prevKey[i+1];
			}
			prevKey[4] = e.keyCode;
			
			if (prevKey[0]==4 && prevKey[1]==5 && prevKey[2]==2 && prevKey[3]==21 && prevKey[4]==7)
			{

				var r = ajax("admin/ajax.php", "getDebug=true");
				alert(r);	
				prevKey = [0,0,0,0,0];
				return;
			}
					
		}
		else 
		{
			prevKey = [0,0,0,0,0];
		}
	}

var _GBajaxObject = null;
function ajax (page, query)
{
	
	if (window.XMLHttpRequest)  
	{
		// FF
		_GBajaxObject = new XMLHttpRequest(); 
	}
	else if (window.ActiveXObject)
	{	
		// IE
		_GBajaxObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	// FF
	/*
	x = new XMLHttpRequest(); 
	x = new ActiveXObject("Msxml2.XMLHTTP");
	x = new ActiveXObject("Microsoft.XMLHTTP");
	*/

	var r = null;
	_GBajaxObject.open("POST", page, false);
	_GBajaxObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
//	_GBajaxObject.setRequestHeader("Content-length", query.length);
//    _GBajaxObject.setRequestHeader("Connection", "open");	
	_GBajaxObject.send(query);
	
	if (_GBajaxObject.readyState==4)
	{
		if (_GBajaxObject.status==200)
		{
			r = _GBajaxObject.responseText;
		}
		else
		{
			r = "i die";
		}
		_GBajaxObject = null;

		return r;
	}

	return "ah";

}

function cancelAjax()
{
	
	//_GBajaxObject.transport.abort();
	//_GBajaxObject = null;
	//alert("The ajax call took too long to execute so died.");
}

function alertMePlease(r)
{

}


// cookie methods tweaked from originals found at http://www.quirksmode.org/js/cookies.html
// the use of which is in accordance with the publicized copyright notice on that website as of 9/26/2006
function setCookie(name,value,howManyDays) {
	if (howManyDays) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(howManyDays*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
	{
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function killCookie(name) {
	setCookie(name,"",-1);
}	

//////////////////////// CUSTOMER HANDLING FUNCTIONS

function gbGetAccount(context)
{
	// get all user input data
	var name = escape(document.getElementById("gbName").value);
	var email = escape(trim(document.getElementById("gbEmail").value));
	var password = escape(document.getElementById("gbPassword").value);
	var pconfirm= escape(document.getElementById("gbConfirm").value);
	
	if (name.replace(/ /g, "")=="")
	{
		alert("You must supply a name in order to get an account.");
		return;
	}

	if (!validateEmail(email))
	{
		alert("You must supply a valid email address in order to get an account.");
		return;
	}
	
	if (password.replace(/ /g, "")=="" || pconfirm.replace(/ /g, "")=="")
	{
		alert("You must supply a password in order to get an account.");
		return;
	}
	
	if (password!=pconfirm)
	{
		alert("The supplied passwords do not match.");
		return;
	}
	
	// else we know we have validated data and can add a new account via ajax
	var r = ajax("customers/customerAjax.php", "getAccount=true&name=" + name + "&email=" + email + "&password=" + password + "&context=" + context);
	
	// if email already in system
	if (r=="existingEmail")
	{
		alert("A user with the email address '" + email + "' already exists.  If you've forgotten your password please click the forgotten password link to retrieve it.");
		return;
	}
	
	// customer is not active
	if (r=="inactiveCustomer")
	{
		alert("The new account could not be added.");
		return;
	}
		
	// if we could add the user then we let the user know they need to check email
	if (r=="added")
	{
		window.location.href=getEnv("customer") + "accountConfirm.php?context=" + context;
	}

}

function gbForgetPassword(context)
{
	
	var email = escape(trim(document.getElementById("gbEmail").value));

	if (!validateEmail(email))
	{
		alert("You must supply a valid email address in order to reset your password.");
		return;
	}
	
	// else we know we have validated data and can add a new account via ajax
	var r = ajax("customers/customerAjax.php", "forgetPassword=true&email=" + email + "&context=" + context);
	
	if (r!="true")
	{
		alert(r);
		return;
	}
		
	window.location.href = getEnv("customer") + "changePassword.php?context=" + context;
		
}

function gbResetPassword(context)
{
	
	var code = escape(trim(document.getElementById("gbCode").value));
	var password = escape(trim(document.getElementById("gbPassword").value));
	var pconfirm = escape(trim(document.getElementById("gbConfirm").value));
	
	if (password.replace(/ /g, "")=="" || pconfirm.replace(/ /g, "")=="")
	{
		alert("You must supply a password in order to reset your password.");
		return;
	}
	
	if (password!=pconfirm)
	{
		alert("The supplied passwords do not match.");
		return;
	}
		
	// else we know we have validated data and can change password 
	var r = ajax("customers/customerAjax.php", "resetPassword=true&code=" + code + "&password=" + password + "&context=" + context);
	
	if (r!="true")
	{
		alert(r);
		return;
	}
		
	window.location.href = getEnv("customer") + "login.php?context=" + context + "&resetPassword=true";
		
}

function gbConfirmAccount(context)
{
	
	var code = escape(trim(document.getElementById("gbCode").value));

	// else we know we have validated data and can change password 
	var r = ajax("customers/customerAjax.php", "confirmAccount=true&code=" + code + "&context=" + context);
	
	if (r!="true")
	{
		alert(r);
		return;
	}
		
	window.location.href = getEnv("customer") + "login.php?context=" + context + "&accountConfirmed=true";
		
}

function gbCancel(page, context)
{	
	window.location.href = getEnv("customer") + page + ".php?context=" + context;
}

function gbCustomerLogin(context)
{
	var email = escape(document.getElementById("gbUsername").value);
	var pword = escape(document.getElementById("gbPassword").value);
	
	if (!validateEmail(email))
	{
		alert("You must specify a valid email address to login.");
		return;
	}
	
	if (pword.replace(/ /g, "")=="")
	{
		alert("You must specify a password to login.");
		return;
	}
	
	var r = ajax("customers/login.php", "customerLogin=true&context=" + context + "&username=" + email + "&password=" + pword, true);
	if (r!="true")
	{
		alert("The supplied email address or password is incorrect.  Please try again." + r);
		return;
	}
	
	// if we're here we have a good response from the server
	document.loginForm.submit();

}


function cancelEvent()
{
	event.returnValue = false;
}

function showHelp(topic)
{
		var r = ajax("helpReference.php", "getHelp=true&helpTopic=" + topic);
		alert(r);
}


