var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]
};
BrowserDetect.init();

function aM(oB,mD) {
	tmpSrc = oB.src;
	if (mD == "on") {
		oB.src = tmpSrc.replace("_off.","_on.");
	} else if (mD == "off") {
		oB.src = tmpSrc.replace("_on.","_off.");
	}
}

function getQuerystring(key, default_) {
	if (default_==null) default_=""; 
	key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	var qs = regex.exec(window.location.href);
	if(qs == null)
		return default_;
	else
		return qs[1];
}

function eefCheck() {
	reqSet = document.eef.eefReqd.value
	if (reqSet.length > 0) {
		reqArray = reqSet.split("|");
		for (i = 0; i < reqArray.length; i++) {
			if (eval("document.eef."+reqArray[i]+".value == \"\"")) {
				window.alert("Please complete all required fields, including "+reqArray[i]+".  Click OK to continue.");
				eval("document.eef."+reqArray[i]+".focus();");
				return false;
			}
		}
	}
	return true;
}

function formAdvance (formField, formNext, formCount) {
	if (formField.value.length >= formCount) {
		eval("document." + formNext + ".focus();");
	}
}
function formNumberValidation (formField, formStrict) {
	if (typeof formStrict == "undefined") { formStrict = 0; }
	if (formStrict == 0) {
		allowedChars = "0123456789.,-";
	} else {
		allowedChars = "0123456789";
	}
	tmpValue = "";
	for (i = 0; i < formField.value.length; i++) {
		if (allowedChars.indexOf(formField.value.charAt(i)) != -1) {
			tmpValue = tmpValue + formField.value.charAt(i);
		}
	}
	if (tmpValue != formField.value) {
		formField.value = tmpValue;
	}
}
function formRefcodeValidation (formField) {
	allowedChars = "acdhmrstwyACDHMRSTWY";
	tmpValue = "";
	for (i = 0; i < formField.value.length; i++) {
		if (allowedChars.indexOf(formField.value.charAt(i)) != -1) {
			tmpValue = tmpValue + formField.value.charAt(i);
		}
	}
	tmpValue = tmpValue.toUpperCase();
	if (tmpValue != formField.value) {
		formField.value = tmpValue;
	}
}
function formValidateEmail (formField) {
	allowedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@.-_";
	tmpValue = "";
	isValid = 0;
	for (i = 0; i < formField.value.length; i++) {
		if (allowedChars.indexOf(formField.value.charAt(i)) != -1) {
			tmpValue = tmpValue + formField.value.charAt(i);
		}
	}
	if (tmpValue != formField.value) {
		formField.value = tmpValue;
	}
	if (tmpValue.indexOf("@") > -1 && tmpValue.indexOf(".") > -1) {
		isValid = 1;
	}
	return isValid
}
function formDisableEnter(e) {
	var key;
	if (window.event) {
		key = window.event.keyCode;
	} else {
		key = e.which;
	}
	if (key == 13) {
		return false;
	} else {
		return true;
	}
}
function formFormatter (formField, formatMode) {
	if (document.selection) {
		formField.focus();
		var sel = document.selection.createRange();
		tmpSelection = sel.text;
		if (tmpSelection == "") {
			tmpSelection = "ENTER TEXT HERE";
		}
		switch(formatMode) {
			case "bold":
				sel.text = "**" + tmpSelection + "**";
				break;
			case "italic":
				sel.text = "!!" + tmpSelection + "!!";
				break;
			case "under":
				sel.text = "__" + tmpSelection + "__";
				break;
			case "strike":
				sel.text = "^^" + tmpSelection + "^^";
				break;
			case "bullet":
				sel.text = "\n* " + tmpSelection + "\n";
				break;
			case "quote":
				sel.text = "\"\"" + tmpSelection + "\"\"";
				break;
			default:
				sel.text = tmpSelection;
		}
	} else {
		tmpSelectionStart = formField.selectionStart;
		tmpSelectionEnd = formField.selectionEnd;
		tmpSelection = (formField.value).substring(tmpSelectionStart, tmpSelectionEnd);
		if (tmpSelection) {
			tmpSelectionPre = (formField.value).substring(0, tmpSelectionStart);
			tmpSelectionPost = (formField.value).substring(tmpSelectionEnd, (formField.value).length);
		} else {
			tmpSelectionPre = formField.value;
			tmpSelectionPost = "";
			tmpSelection = "ENTER TEXT HERE";
		}
		switch(formatMode) {
			case "bold":
				formField.value = tmpSelectionPre + "**" + tmpSelection + "**" + tmpSelectionPost;
				break;
			case "italic":
				formField.value = tmpSelectionPre + "!!" + tmpSelection + "!!" + tmpSelectionPost;
				break;
			case "under":
				formField.value = tmpSelectionPre + "__" + tmpSelection + "__" + tmpSelectionPost;
				break;
			case "strike":
				formField.value = tmpSelectionPre + "^^" + tmpSelection + "^^" + tmpSelectionPost;
				break;
			case "bullet":
				formField.value = tmpSelectionPre + "\n* " + tmpSelection + "\n" + tmpSelectionPost;
				break;
			case "quote":
				formField.value = tmpSelectionPre + "\"\"" + tmpSelection + "\"\"" + tmpSelectionPost;
				break;
			default:
				formField.value = formField.value;
		}
	}
}
function formPreview (formField) {
	tmpContent = formField.value;
	document.formatPreview.c.value = tmpContent;
	window.open("", "pr", "height=600,width=400,scrollbars=yes");
	var x = window.setTimeout("document.formatPreview.submit();", 500);
}

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; } else { document.onmousemove = UpdateCursorPosition; }

var drawerCurrent = "";
function toggleDrawer(drawerNew) {
	if (drawerCurrent == "" && drawerNew != "") {
		if (BrowserDetect.browser == "Explorer") {
			$(drawerNew).style.display = "block";
		} else {
			new Effect.SlideDown(drawerNew, {queue: {position: "end", scope: "drawer"}, duration: 0.5});
		}
		drawerCurrent = drawerNew;
	} else if (drawerCurrent != "" && drawerNew != drawerCurrent) {
		if (BrowserDetect.browser == "Explorer") {
			$(drawerCurrent).style.display = "none";
			$(drawerNew).style.display = "block";
		} else {
			new Effect.SlideUp(drawerCurrent, {queue: {position: "end", scope: "drawer"}, duration: 0.5});
			new Effect.SlideDown(drawerNew, {queue: {position: "end", scope: "drawer"}, duration: 0.5});
		}
		drawerCurrent = drawerNew;
	} else {
		if (BrowserDetect.browser == "Explorer") {
			$("wInboxFrame").innerHTML = "<div style=\"width: 936px;height: 280px;position: relative;\"><a href=\"#?\" onclick=\"loadIbx('inbox','');\"><img src=\"/images/wait_inbox.gif\" style=\"position:absolute;top: 118px;left: 446px;\" /></a></div>";
			$(drawerCurrent).style.display = "none";
		} else {
			new Effect.SlideUp(drawerCurrent, {queue: {position: "end", scope: "drawer"}, duration: 0.5});
		}
		drawerCurrent = "";
	}
}

function ibxOpen() {
	if (drawerCurrent == "wInbox") {
		toggleDrawer('wInbox');
	} else {
		loadIbx('inbox','');
		toggleDrawer('wInbox');
	}
}

function loadIbx(ibxArea, loadProperties) {
	if (loadProperties == "send") {
		new Ajax.Request("/data/ibx_inbox.php", {onSuccess: writeIbx, parameters: Form.serialize(document.ibxCompose)});
	} else {
		new Ajax.Request("/data/ibx_"+ibxArea+".php?"+loadProperties, {onSuccess:writeIbx, evalScripts:true});
	}
}
function writeIbx(t) {
	tmpResponse = t.responseText;
	$("wInboxFrame").innerHTML = tmpResponse;
	if (tmpResponse != "") {
		Scroller.reset("scrollReady");
		ibxNew();
		ibxSelected.length=0;
		if (drawerCurrent != "wInbox") {
			toggleDrawer("wInbox");
		}
	}
}

function ibxNew() {
	new Ajax.Request("/data/ibx_new.php", {onSuccess:ibxNewWrite});	
}
function ibxNewWrite(t) {
	tmpNew = t.responseText;
	if (tmpNew == 0) {
		$("wMastTabInbox").className = "tabInbox";
		$("wMastTabInboxItems").innerHTML = "0";
	} else {
		$("wMastTabInbox").className = "tabInboxNew";
		$("wMastTabInboxItems").innerHTML = tmpNew;
	}
}

var ibxSelected = new Array();
function ibxSelectItem(itemId, itemFolder) {
	var tmpInArray = -1;
	var tmpArray = new Array();
	var tmpOut = "";
	for (i = 0; i < ibxSelected.length; i++) {
		if (itemId == ibxSelected[i]) {
			tmpInArray = i;
		} else {
			tmpArray.push(ibxSelected[i]);
		}
	}
	if (tmpInArray > -1) {
		ibxSelected = tmpArray;
		aM($("ibx_sel_"+itemId),"off");
	} else {
		ibxSelected.push(itemId);
		aM($("ibx_sel_"+itemId),"on");
	}
	tmpCount = ibxSelected.length;
	if (tmpCount == 0) {
		$("ibxMoveButton").style.display = "none";
	} else {
		for (i = 0; i < ibxSelected.length; i++) {
			if (i == ibxSelected.length - 1) {
				tmpOut = tmpOut + ibxSelected[i];
			} else {
				tmpOut = tmpOut + ibxSelected[i] + ",";
			}
		}
		if (itemFolder == "inbox") {
			$("ibxMoveButton").innerHTML = "<a onclick=\"ibxSelected.length=0;loadIbx('archive','mid=" + tmpOut + "');\">Archive Selected (" + tmpCount + ")</a>";
		} else {
			$("ibxMoveButton").innerHTML = "<a onclick=\"ibxSelected.length=0;loadIbx('inbox','mid=" + tmpOut + "');\">Unarchive Selected (" + tmpCount + ")</a>";
		}
		$("ibxMoveButton").style.display = "block";
	}
}
function ibxSearchFocus() {
	if (document.ibxSearch) {
		var tmpSearch = document.ibxSearch.st.value;
		if (tmpSearch.length > 0) {
			document.ibxSearch.st.focus();
			document.ibxSearch.st.value = "";
			document.ibxSearch.st.value = tmpSearch.toLowerCase();
		}
	}
}
function ibxSearchX(ibxFolder) {
	var tmpSearch = document.ibxSearch.st.value;
	if (tmpSearch.length > 1) {
		loadIbx(ibxFolder, "st=" + tmpSearch);
	}
}
function ibxSend() {
	var tmpMessage = "";
	if (document.ibxCompose.ms.value == "" && document.ibxCompose.mm.value == "") {
		tmpMessage = "Your message has no subject and no content. Are you sure you want to send it?";
	} else if (document.ibxCompose.ms.value == "") {
		tmpMessage = "Your message has no subject. Are you sure you want to send it?";
	} else if (document.ibxCompose.mm.value == "") {
		tmpMessage = "Your message has no content. Are you sure you want to send it?";
	}
	if (tmpMessage != "") {
		if (window.confirm(tmpMessage)) {
			loadIbx('inbox','send');
		} else {
			if (document.ibxCompose.ms.value == "") {
				document.ibxCompose.ms.focus();
			} else {
				document.ibxCompose.mm.focus();
			}
		}
	} else {
		loadIbx('inbox','send');
	}
}

function acctSave() {
	var tmpReady = 1;
	var tmpZip = document.acctEdit.user_zip.value;
	if (document.acctEdit.user_email.value == "" || formValidateEmail(document.acctEdit.user_email) == 0) {
		window.alert("Please enter a valid email address.");
		document.acctEdit.user_email.focus();
		tmpReady = 0;
	} else if (tmpZip == "" || tmpZip.length < 5) {
		window.alert("Please enter a valid zip code.");
		document.acctEdit.user_zip.focus();
		tmpReady = 0;
	}
	if (tmpReady == 1) {
		document.acctEdit.submit();
	}
}
var acctEditStatus = 0;
function acctOpen() {
	if (drawerCurrent == "wAccount") {
		toggleDrawer('wAccount');
	} else {
		acctLoad('');
		toggleDrawer('wAccount');
	}
}
function acctLoad(loadProperties) {
	if (loadProperties == "save") {
		var tmpReady = 1;
		var tmpZip = document.acctEdit.user_zip.value;
		if (document.acctEdit.user_email.value == "" || formValidateEmail(document.acctEdit.user_email) == 0) {
			window.alert("Please enter a valid email address.");
			document.acctEdit.user_email.focus();
			tmpReady = 0;
		} else if (tmpZip == "" || tmpZip.length < 5) {
			window.alert("Please enter a valid zip code.");
			document.acctEdit.user_zip.focus();
			tmpReady = 0;
		}
		if (tmpReady == 1) {
			new Ajax.Request("/data/acct_edit.php", {onSuccess: acctWrite, parameters: Form.serialize(document.acctEdit)});
		}
	} else {
		new Ajax.Request("/data/acct_edit.php?"+loadProperties, {onSuccess:acctWrite, evalScripts:true});
	}
}
function acctWrite(t) {
	var tmpResponse = t.responseText;
	if (tmpResponse == "//close//") {
		if (drawerCurrent == "wAccount") {
			toggleDrawer("wAccount");
		}
		alertBubbleAdd("Your changes have been saved.");
	} else {
		$("wAccountFrame").innerHTML = t.responseText;
		if (drawerCurrent != "wAccount") {
			toggleDrawer("wAccount");
		}
	}
}
function acctCheckZip(zipField) {
	var tmpZip = zipField.value;
	if (tmpZip.length == 5) {
		new Ajax.Request("/data/lookup_zip_citystate.php?zip="+tmpZip, {onSuccess:acctCheckZipWrite, evalScripts:true});
	}
}
function acctCheckZipWrite(t) {
	$("acctZipLoc").innerHTML = t.responseText;
}
function acctEditCancel() {
	if (acctEditStatus == 1) {
		if (window.confirm("By canceling without saving, your changes will be lost. If you are okay with this, please click OK. To return to your edits, click Cancel.")) {
			if (drawerCurrent == "wAccount") {
				toggleDrawer("wAccount");
			}
			acctEditStatus = 0;
		}
	} else {
		if (drawerCurrent == "wAccount") {
			toggleDrawer("wAccount");
		}
	}
}

var navCurrent = "";
function toggleNavDrop(navNew) {
	if (navNew == navCurrent) {
		$("wNavI"+navNew).className = "navInner";
		new Effect.Fade("wNav"+navNew, {duration:0.2});
		navCurrent = "";
	} else if (navCurrent == "") {
		//$("wNav"+navNew).style.display = "block";
		$("wNavI"+navNew).className = "navInnerOn";
		new Effect.Appear("wNav"+navNew, {duration:0.2});
		navCurrent = navNew;
	} else {
		$("wNavI"+navCurrent).className = "navInner";
		new Effect.Fade("wNav"+navCurrent, {duration:0.2});
		$("wNavI"+navNew).className = "navInnerOn";
		new Effect.Appear("wNav"+navNew, {duration:0.2});
		navCurrent = navNew;
	}
}



function paneLoad (panePath, paneQs) {
	new Ajax.Request("/data/" + panePath + ".php?" + paneQs, {onSuccess: paneDraw});
}
function paneDraw (t) {
	$("wPane").innerHTML = t.responseText;
	if (BrowserDetect.browser == "Explorer") {
		$("wPane").style.display = "block";
	} else {
		new Effect.Appear("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
	}
}
function paneCancel () {
	if (BrowserDetect.browser == "Explorer") {
		$("wPane").style.display = "none";
	} else {
		new Effect.Fade("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
	}
}

var acctLoginPath = "";
function acctLoginPathSet (tmpPath) {
	acctLoginPath = tmpPath;
}

function acctLogin () {
	paneLoad("acct_login", "");
}
function acctLogout () {
	paneLoad("acct_logout", "");
}

function acctLoginEnabler(beMode) {
	document.acct.acctLoginSubmit.disabled = true;
	if (beMode == 0) {
		// disable all buttons, hide password field
		document.acct.acctLoginSubmit.disabled = true;
	} else if (beMode == 1) {
		// enable login, hide password
		document.acct.acctLoginSubmit.disabled = false;
	} else {
		// show all
		document.acct.acctLoginSubmit.disabled = false;
	}
}
function acctLoginCheck() {
	if (formValidateEmail(document.acct.acctEmail) == 1) {
		new Ajax.Request("/data/acct_login.php?ax=urp&id=" + document.acct.acctEmail.value, {onSuccess:acctLoginCheckLoad});
	} else {
		acctLoginEnabler(0);
	}
}
function acctLoginCheckLoad(t) {
	reqPassword = t.responseText;
	if (reqPassword == "1") {
		acctLoginEnabler(2);
		if (document.acct.acctPassword.value != "") {
			document.acct.acctLoginSubmit.disabled = false;
		} else {
			document.acct.acctLoginSubmit.disabled = true;
		}
	} else {
		acctLoginEnabler(1);
	}
}
function acctLoginEnter(e) {
	var characterCode;
	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	if (characterCode == 13) {
		if (document.acct.acctLoginSubmit.disabled == false) {
			acctLoginProcess();
		}
		return false;
	} else {
		return true;
	}
}
function acctLoginProcess () {
	new Ajax.Request("/data/acct_login.php", {onSuccess: acctLoginProcessOut, parameters: Form.serialize(document.acct)});
}
function acctLoginProcessOut (t) {
	tmpMessage = t.responseText;
	if (tmpMessage == "//reload//") {
		if (acctLoginPath == "") {
			window.location.reload(false);
		} else {
			window.location.href = acctLoginPath;
		}
	} else {
		$("wPane").innerHTML = t.responseText;
	}
}

function securePane(varOptQs) {
	if (!varOptQs) {
		varOptQs = "";
	}
	secureLeadLoad("acct_welcome", varOptQs);
	if (BrowserDetect.browser == "Explorer") {
		$("wSecure").style.display = "block";
	} else {
		new Effect.Appear("wSecure", {queue: {position: "end", scope: "pane"}, duration: 0.25});
	}
}
function secureLeadLoad(leadPath, leadQs) {
	new Ajax.Updater("paneSecureLead", "/data/" + leadPath + ".php?" + leadQs, {evalScripts: true});
}
function secureLeadDraw (t) {
	$("paneSecureLead").innerHTML = t.responseText;
}

var acctAddNameOk = 0;
var acctAddEmailOk = 0;
var acctAddZipOk = 0;
var acctAddRefOk = 0;
function acctAddCheckName () {
	if (document.acctEdit.user_name_first.value == "" || document.acctEdit.user_name_last.value == "") {
		$("acctAddNameOk").src = "/images/icon_ok_dis.png";
		acctAddNameOk = 0;
	} else {
		$("acctAddNameOk").src = "/images/icon_ok.png";
		acctAddNameOk = 1;
	}
	if (formValidateEmail(document.acctEdit.user_email) == 1) {
		new Ajax.Request("/data/acct_add.php?ax=checkEmail&user_email=" + document.acctEdit.user_email.value, {onSuccess: acctAddCheckEmailDraw});
	} else {
		$("acctAddEmailOk").src = "/images/icon_ok_dis.png";
		acctAddEmailOk = 0;
		acctAddEnabler();
	}
}
function acctAddCheckEmail () {
	if (formValidateEmail(document.acctEdit.user_email) == 1) {
		new Ajax.Request("/data/acct_add.php?ax=checkEmail&user_email=" + document.acctEdit.user_email.value, {onSuccess: acctAddCheckEmailDraw});
	} else {
		$("acctAddEmailOk").src = "/images/icon_ok_dis.png";
		acctAddEmailOk = 0;
		acctAddEnabler();
	}
}
function acctAddCheckEmailDraw (t) {
	var tmpResponse = t.responseText;
	if (tmpResponse == 1) {
		acctAddEmailOk = 1;
		$("acctAddEmailOk").src = "/images/icon_ok.png";
		acctAddEnabler();
	} else {
		acctAddEmailOk = 0;
		$("acctAddEmailOk").src = "/images/icon_ok_dis.png";
		acctAddEnabler();
	}
}
function acctAddCheckZip() {
	acctAddZipOk = 0;
	$("acctAddZipOk").src = "/images/icon_ok_dis.png";
	acctAddEnabler();
	var tmpZip = document.acctEdit.user_zip.value;
	if (tmpZip.length == 5) {
		new Ajax.Request("/data/lookup_zip_citystate.php?zip="+tmpZip, {onSuccess:acctAddCheckZipWrite, evalScripts:true});
	}
}
function acctAddCheckZipWrite(t) {
	tmpResponse = t.responseText;
	$("acctZipLoc").innerHTML = tmpResponse;
	if (tmpResponse == "") {
		acctAddZipOk = 0;
		$("acctAddZipOk").src = "/images/icon_ok_dis.png";
		acctAddEnabler();
	} else {
		acctAddZipOk = 1;
		$("acctAddZipOk").src = "/images/icon_ok.png";
		acctAddEnabler();
	}
}
function acctAddCheckRef () {
	$("acctRefValid").style.display = "none";
	formRefcodeValidation(document.ca.ref_code_1);
	formRefcodeValidation(document.ca.ref_code_2);
	formRefcodeValidation(document.ca.ref_code_3);
	tmpRef1 = document.ca.ref_code_1.value;
	tmpRef2 = document.ca.ref_code_2.value;
	tmpRef3 = document.ca.ref_code_3.value;
	if (tmpRef1.length == 1 && tmpRef2.length == 6 && tmpRef3.length == 1) {
		new Ajax.Request("/data/acct_add.php?ax=checkRef&ref_code=" + tmpRef1 + "-" + tmpRef2 + "-" + tmpRef3, {onSuccess: acctAddCheckRefDraw});
	} else {
		$("acctAddRefOk").src = "/images/icon_ok_dis.png";
		acctAddRefOk = 0;
	}
}
function acctAddCheckRefDraw (t) {
	var tmpResponse = t.responseText;
	if (tmpResponse == 1) {
		acctAddRefOk = 1;
		$("acctAddRefOk").src = "/images/icon_ok.png";
	} else {
		acctAddRefOk = 0;
		$("acctAddRefOk").src = "/images/icon_ok_dis.png";
		$("acctRefValid").style.display = "block";
	}
}
function acctAddEnabler(beMode) {
	if (acctAddNameOk == 0 || acctAddEmailOk == 0 || acctAddZipOk == 0) {
		document.acctEdit.save.disabled = true;
	} else {
		document.acctEdit.save.disabled = false;
	}
}
function acctAddSave () {
	if (acctAddEmailOk == 1 && acctAddZipOk == 1) {
		tmpTypeIdx = document.acctEdit.user_type.selectedIndex;
		tmpType = document.acctEdit.user_type.options[tmpTypeIdx].value;
		tmpSpecialty = 0;
		tmpDiscipline = 0;
		if (tmpType == 0) {
			tmpSpecialtyIdx = document.acctEdit.specialty_id.selectedIndex;
			tmpSpecialty = document.acctEdit.specialty_id.options[tmpSpecialtyIdx].value;
		} else if (tmpType == 1) {
			tmpDisciplineIdx = document.acctEdit.discipline_id.selectedIndex;
			tmpDiscipline = document.acctEdit.discipline_id.options[tmpDisciplineIdx].value;
		}
		tmpNameFirst = document.acctEdit.user_name_first.value;
		tmpNameLast = document.acctEdit.user_name_last.value;
		tmpEmail = document.acctEdit.user_email.value;
		tmpZip = document.acctEdit.user_zip.value;
		tmpRef = document.acctEdit.ref_code_1.value + "-" + document.acctEdit.ref_code_2.value + "-" + document.acctEdit.ref_code_3.value;
		secureLeadLoad("acct_add", "ax=save&user_type=" + tmpType + "&specialty_id=" + tmpSpecialty + "&discipline_id=" + tmpDiscipline + "&user_name_first=" + tmpNameFirst + "&user_name_last=" + tmpNameLast + "&user_email=" + tmpEmail + "&user_zip=" + tmpZip + "&ref_code=" + tmpRef);
	}
}


function acctLoginCheck() {
	if (formValidateEmail(document.acct.acctEmail) == 1) {
		new Ajax.Request("/data/acct_login.php?ax=urp&id=" + document.acct.acctEmail.value, {onSuccess:acctLoginCheckLoad});
	} else {
		acctLoginEnabler(0);
	}
}
function acctLoginCheckLoad(t) {
	reqPassword = t.responseText;
	if (reqPassword == "1") {
		acctLoginEnabler(2);
		if (document.acct.acctPassword.value != "") {
			document.acct.acctLoginSubmit.disabled = false;
		} else {
			document.acct.acctLoginSubmit.disabled = true;
		}
	} else {
		acctLoginEnabler(1);
	}
}

searchBoxVisible = 0;
function searchBox(searchString) {
	if (searchString.length > 2) {
		new Ajax.Request("/data/search_results.php?ss=" + searchString, {onSuccess:searchBoxDraw});
	} else {
		searchBoxClear();
	}
}
function searchBoxDraw(t) {
	searchBoxData = t.responseText;
	if (searchBoxData != "") {
		$("searchBoxResults").innerHTML = searchBoxData;
		$("searchBoxResults").style.display = "block";
		searchBoxVisible = 1;
	} else {
		searchBoxClear();
	}
}
function searchBoxClear() {
	$("searchBoxResults").innerHTML = "";
	$("searchBoxResults").style.display = "none";
	searchBoxVisible = 0;
}

var promoTotal = 5;
var promoCurrent = 1;
var promoActive = 1;

function promoSwap(promoNew) {
	if (promoNew == 0) {
		if (promoActive == 0) {
			promoNew = promoCurrent
		} else {
			promoNew = promoCurrent + 1;
			if (promoNew > promoTotal) {
				promoNew = 1;
			}
		}
	} else {
		promoActive = 0;
	}
	if (promoNew > promoCurrent) {
		new Effect.Appear("promoPane" + promoNew, {queue:{position:"end",scope:"promo"}});
		new Effect.Fade("promoPane" + promoCurrent, {queue:{position:"end",scope:"promo"}});
	} else if (promoNew < promoCurrent) {
		$("promoPane" + promoNew).style.display = "block";
		new Effect.Fade("promoPane" + promoCurrent, {queue:{position:"end",scope:"promo"}});
	}
	$("promoBar" + promoCurrent).src = "/images/promo_bar_" + promoCurrent + "_off.png";
	$("promoBar" + promoNew).src = "/images/promo_bar_" + promoNew + "_on.png";
	promoCurrent = promoNew;
	if (promoActive == 1) {
		setTimeout("promoSwap(0);",10000);
	}
}

function fieldBubble(bubbleMode, bubbleContent) {
	if (bubbleMode == 1 || bubbleMode == 2) {
		$("fieldBubbleShadow").innerHTML = bubbleContent + "<div><img src=\"/images/hlbubble_tail_shadow.png\" /></div>";
		$("fieldBubbleContent").innerHTML = bubbleContent + "<div><img src=\"/images/hlbubble_tail.png\" /></div>";
		if (bubbleMode == 1) {
			if(self.pageYOffset) {
				rX = self.pageXOffset;
				rY = self.pageYOffset;
			} else if(document.documentElement && document.documentElement.scrollTop) {
				rX = document.documentElement.scrollLeft;
				rY = document.documentElement.scrollTop;
			} else if(document.body) {
				rX = document.body.scrollLeft;
				rY = document.body.scrollTop;
			}
			if(document.all) {
				cX += rX; 
				cY += rY;
			}
			$("fieldBubble").style.left = (cX) + "px";
			$("fieldBubble").style.top = (cY) + "px";
		}
		$("fieldBubble").style.display = "block";
	} else {
		$("fieldBubble").style.display = "none";
	}
}

var alertStatus = 0;
var alertArray = new Array;
function alertBubbleAdd(bubbleContent) {
	alertArray.push(bubbleContent);
	if (alertStatus == 0) {
		alertBubbleDraw();
		alertStatus = 1;
	}
}
function alertBubbleDraw() {
	if (alertStatus == 1) {
		new Effect.Fade("alertBubble", {queue: {position: "end", scope: "alertBubble"}, duration: 1.5});
	}
	if (alertArray.length > 0) {
		alertOndeck = alertArray.shift();
		if (alertStatus == 1) {
			setTimeout("$('alertBubbleShadow').innerHTML = alertOndeck;",1500);
			setTimeout("$('alertBubbleContent').innerHTML = alertOndeck;",1500);
		} else {
			$('alertBubbleShadow').innerHTML = alertOndeck;
			$('alertBubbleContent').innerHTML = alertOndeck;
		}
		new Effect.Appear("alertBubble", {queue: {position: "end", scope: "alertBubble"}, duration: 1.0});
		setTimeout("alertBubbleDraw()",4000);
	} else {
		alertStatus = 0;
	}
}

function lookupZip(zipValue) {
	if (zipValue.length == 5) {
		new Ajax.Request("/data/lookup_zip_citystate.php?zip=" + zipValue, {onSuccess: lookupZipWrite});
	}
}
function lookupZipWrite(t) {
	var tmpText;
	tmpText = t.responseText;
	if (tmpText == "") {
		alertBubbleAdd("This zip code has not been found in our records. Please check your entry.");
	} else {
		alertBubbleAdd("We have found this zip code in <span class='emph'>" + tmpText + "</span>.");
	}
}

function showBig(bigValue) {
	$("wBig").innerHTML = "<div>" + bigValue + "</div>";
	new Effect.Appear("wBig", {duration: 0.25});
}

function swapPrettyRadio (formPath, newValue, className) {
	formArray = formPath.split(".");
	formName = formArray[0];
	varName = formArray[1];
	currentValue = eval("document." + formPath + ".value");
	if (currentValue != newValue) {
		eval("document." + formPath + ".value = '" + newValue + "';");
		$(varName + "_" + currentValue).className = className + "Off";
		$(varName + "_" + newValue).className = className + "On";
	}
}

var rcrStatus = 0;
var rcrValid = 0;

function requireRcr (destUrl) {
	if (rcrStatus == 1) {
		if (rcrValid == 1) {
			location.href = destUrl;
		} else {
			window.alert("The referral code that you've entered is invalid. Let's take a minute to try to find the right code.");
			location.href = "/tools/rc/?u=" + destUrl;
		}
	} else {
		window.alert("This pricing plan requires that you enter a referral code. Let's take a minute to try to find one for you.");
		location.href = "/tools/rc/?u=" + destUrl;
	}
}