function showHide(obj, obja, objp) {
	var objID = document.getElementById(obj);
	var aID = document.getElementById(obja);
	var pID = document.getElementById(objp);
	var aHTML = aID.innerHTML;
	
	//alert("obj:"+obj+", a:"+obja+", p:"+objp+", p display:"+pID.style.display);
	
	if (objID.className == 'off') {
		objID.className = 'on';
		//change link to have - instead of +
		aHTML = aHTML.substring(2);
		aID.innerHTML = '- ' + aHTML;
	} else if (objID.className == 'on') {
		objID.className = 'off';
		//change link to have + instead of -
		aHTML = aHTML.substring(2);
		aID.innerHTML = '+ ' + aHTML;
	}
	
	aID.blur();
}

function displayCenterWin(obj,w,h,src) {
	//-obj is the div object we are displaying
	//-w is the width of the object
	//-h is the height of the object
	//-src is the server page that populates the object
	
	var object = document.getElementById(obj);
	//start with our loading message
	object.innerHTML = '<div align="center" style="padding-top:100px;"><img src="/images/loading_dkgreen.gif" alt="loading" width="100" height="100" /></div>';
	//populate the object from our server page
	var serverPage = src + "?cacheKiller=" + new Date().getTime();
	processAjax(serverPage, obj, 'get');
	//figure out where to put this thing!
	var screenW;
	var screenH;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
		screenW = window.innerWidth;
		screenH = window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0) {
	    screenW = document.documentElement.clientWidth;
		screenH = document.documentElement.clientHeight;
	}
	// older versions of IE
	else {
	    screenW = document.getElementsByTagName('body')[0].clientWidth;
		screenH = document.getElementsByTagName('body')[0].clientHeight;
	}
	//user scroll positions
	var scrollX = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;
  	var scrollY = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
	//position the popup window
	var midX = Math.floor(screenW/2) + scrollX;
	var midY = Math.floor(screenH/2) + scrollY;
	var imgMidX = Math.floor(w/2);
	var imgMidY = Math.floor(h/2);
	var posLeft = midX - imgMidX;
	var posTop = midY - imgMidY;
	// display the panel
	object.style.width = w + 'px';
	object.style.height = h + 'px';
	object.style.left = posLeft + "px";
	object.style.top = posTop + "px";
	object.style.display = "block";
}

function hideWin(obj) {
	document.getElementById(obj).style.display = "none";
}

function checkForm(obj) {
	alert('You submited the form');
	return false;
}

/****************************************************************************************
AJAX
****************************************************************************************/

var timer = null;
var delay = 1000; //milliseconds

/***************************************************************************************/

function getxmlhttp()
{
	var xmlHttp;
	try {
		//firefox, opera 8.0+, safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		//ie
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support this site");
				return false;
			}
		}
	}
	return xmlHttp;
}

/***************************************************************************************/

function processAjax(serverPage, obj, meth, arg)
{
	//clear timer if set
	window.clearTimeout(timer);
	
	//get the xmlhttp object
	var xmlhttp = getxmlhttp();
	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	};
	
	//see what the form method is
	if (meth == 'get') {
		xmlhttp.open("GET", serverPage, true);
	} else {
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset-UTF-8");
	}
	
	//process
	xmlhttp.send(arg);
}

/***************************************************************************************/

function showProgress(obj)
{
	if (document.getElementById(obj).style.display == 'block') {
		document.getElementById(obj).style.display = 'none';
	} else {
		document.getElementById(obj).style.display = 'block';
	}
}

/***************************************************************************************/

function setProgress(obj, im, msg)
{
	var img = '';
	if (im != '') {
		img = "<img src=\"" + im + "\" border=\"0\" alt=\"" + msg + "\" />";
	}
	document.getElementById(obj).innerHTML = img + " " + msg;
}

/***************************************************************************************/

function getDisplay(obj) {
	return document.getElementById(obj).style.display;
}
function setDisplay(obj, display) {
	document.getElementById(obj).style.display = display;
}

/***************************************************************************************/

function trim(inputString)
{
	//removes leading and trailing spaces from the passed string.
	//also replaces multiple blank spaces with one space.
	//if a non-string is passed in, just return the input.
	if (typeof(inputString) == "string")
	{
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		//check for spaces at beginning of string
		while (ch == " ")
		{
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring((retValue.length - 1), retValue.length);
		//check for spaces at end of string
		while (ch == " ")
		{
			retValue = retValue.substring(0, (retValue.length - 1));
			ch = retValue.substring((retValue.length - 1), retValue.length);
		}
		//check for multiple spaces within string
		while (retValue.indexOf("  ") != -1)
		{
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
		}
		//return the trimmed string
		return retValue;
	}
	else
	{
		return inputString;
	}
}

/***************************************************************************************/

function validateForm(theForm, theValue, theName)
{
	var cont = true;
	
	//set up exceptions...
	//alert(theForm.className + " : " + theName);
	if (theForm.className == 'userForm' && theName == 'phone') {
		//do nothing (not required)
	} else if (trim(theValue) == "") {
		alert("You must fill in the " + theName + " field!");
		theForm.elements[theName].focus();
		cont = false;
	}
	
	return cont;
}

/***************************************************************************************/

var aok = true;

function getFormValues(theForm, valFunc)
{
	aok = true;
	var str = '';
	var checkStr;
	var val;
	//alert('theForm = ' + theForm + ' with the name: ' + theForm.name + ' and this many elements: ' + theForm.elements.length);
	//run thru form's objects
	for (var i = 0; i < theForm.elements.length; i++)
	{
		if (valFunc)
		{
			if (aok == true)
			{
				val = valFunc(theForm, theForm.elements[i].value, theForm.elements[i].name);
				if (val == false) {
					aok = false;
				}
			}
		}
		//see if our element is a checkbox
		if (theForm.elements[i].type == 'checkbox') {
			checkStr = '';
			//for (var c = 0; c < theForm.elements[i].length; c++) {
			//	if (theForm.elements[i][c].checked == true) {
			//		checkStr += escape(theForm.elements[i][c].value) + ',';
			//	}
			//}
			//alert(theForm.elements[i].name + ' is a checkbox');
			if (theForm.elements[i].checked == true) {
				checkStr += theForm.elements[i].value + ',';
			//	alert(theForm.elements[i].name + ' is checked as ' + theForm.elements[i].value);
			}
			checkStr = checkStr.substring(0, checkStr.length-1);
			str += theForm.elements[i].name + "=" + escape(checkStr) + "&";
		} else {
			//populate the str variable
			str += theForm.elements[i].name + "=" + escape(theForm.elements[i].value) + "&";
		}
	}
	//alert(str);
	return str;
}

/***************************************************************************************/

function submitForm(theForm, serverPage, objID, valFunc)
{
	//alert('we are in submitForm()');	
	var ourForm = document.getElementById(theForm);
	var numElements = ourForm.elements.length;
	
	var arg = getFormValues(ourForm, valFunc);
	//alert(arg);
	
	//if everything validated
	if (aok == true)
	{
		showProgress(objID);
		//alert('we are aok, so processAjax()');
		processAjax(serverPage, objID, 'post', arg);
	}
}

/***************************************************************************************/

function toggleBox(obj) {
	if (document.getElementById(obj).className == 'noshow') {
		document.getElementById(obj).className = 'show';
	} else {
		document.getElementById(obj).className = 'noshow';
	}
}