document.write('<scr'+'ipt type="text/javascript" src="/js/pdf.js"></script>');
document.write('<scr'+'ipt type="text/javascript" src="/js/string.js"></script>');
document.write('<scr'+'ipt type="text/javascript" src="/js/maps.js"></script>');
// BROCHURE CREATION SCRIPT
// Checks to see which button you selected (Generate PDF or Customize Report) and does the appropriate actions

function submitBrochureSelectionForm(which, where, what) {

		var location_string = 'listings/listing';
		if (what == 'comp') {
			location_string = 'comparables/comp';
		}

	// If "Customize Report" button was clicked
	if (which == 'customize') {

		if ( what == 'comp' ) {
			document.choosetypeform.action = '/jsp/reports/report_customization.jsp';

		} else {

			// If Single Page Brochure is selected
			document.choosetypeform.action = '/jsp/reports/report_customization.jsp';
		}

		// Set the target of the form to the window the page is in (in case they already selected the popup, cause the target would have changed)
		document.choosetypeform.target = '_self';

		// Submit the form
		//document.choosetypeform.submit();

	// If "Generate PDF" button was clicked
	} else if (which == 'generate') {

		// Open the popup window
		window.open('','pdfPopup','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=400,height=300');

		if (where == 'customize') {
			document.customizeForm.action = '/jsp/reports/report_viewpdf.jsp';
			document.customizeForm.target = 'pdfPopup';
		} else {
			document.choosetypeform.action = '/jsp/reports/report_viewpdf.jsp';
			document.choosetypeform.target = 'pdfPopup';
		}


	}
}

function submitReportForm (form, theAction, theTarget) {
	if (theTarget == 'pdfPopup') {
	 window.open('','pdfPopup','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=400,height=300');
	}
	form.action = theAction;
	form.target = theTarget;
	form.submit();
}

// REPORT CREATION SCRIPT
// Checks to see which button you selected (Generate PDF or Customize Report) and does the appropriate actions
function submitReportSelectionForm(which, where, what) {
    var formToSubmit = null;

		var location_string = 'listing/listing';
		if (what == 'comp') {
			location_string = 'comparables/comp';
		}

	// If "Customize Report" button was clicked
	if (which == 'customize') {

		// Set the action of the form
		if ( what == 'comp') {
			document.choosetypeform.action = '/jsp/reports/report_customization.jsp';
		} else {
			document.choosetypeform.action = '/jsp/reports/report_customization.jsp';
		}

		// Set the target of the form to the window the page is in (in case they already selected the popup, cause the target would have changed)
		document.choosetypeform.target = '_self';

		// Submit the form
		formToSubmit = document.choosetypeform;

	// If "Generate PDF" button was clicked
	} else if (which == 'generate') {

		// Open the popup window
		window.open('','pdfPopup','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=400,height=300');

		var pathDir = 'multi_listing'
		if ( what == 'comp') {
			pathDir = 'multi_comp';
		}


		if (where == 'customize') {
			document.customizeForm.action = '/jsp/reports/report_viewpdf.jsp';
			document.customizeForm.target = 'pdfPopup';
			formToSubmit = document.customizeForm;
		} else if (where == 'reorder') {
			document.reorder_form.action = '/jsp/reports/report_viewpdf.jsp';
			document.reorder_form.target = 'pdfPopup';
			formToSubmit = document.reorder_form;

		} else {
			document.choosetypeform.action = '/jsp/reports/report_viewpdf.jsp';
			document.choosetypeform.target = 'pdfPopup';
			formToSubmit = document.choosetypeform;
		}

	}
	if (formToSubmit) formToSubmit.submit();
}

// POPUP WINDOW SCRIPT
// Pops up a window, centered on the screen. Example: popUp('/jsp/index.jsp', 'window_name', '400', '500');
// Note: The resultant window does not contain any scrollbars, file menus, etc. and is not resizable
function popUp(url, name, width, height) {
	size = "height=" + height + ",width=" + width + ",scrollbars=0,resizable=yes";
	if (parseInt(navigator.appVersion) > 3) {
		size += ",left=" + (screen.width -width)/2 + ",top=" + parseInt((screen.height -height)/3);
	}
	win = window.open(url,name,size);
}


// -------------------
// JUMP MENU FUNCTION
// -------------------
// When a drop down menu is changed (select one of the options) this script send the document location to the 'target'
// If 'restore' is true, the menu will go back to the first option (useful for framed pages)
// if the selected option's value is "kill" then do nothing (useful on menu separators)

// Old, Dreamweaver script
function MM_jumpMenu(targ,selObj,restore) {
  if ( selObj.options[selObj.selectedIndex].value != "kill" ) { 
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) {
        selObj.selectedIndex=0;
    }
  } else { 
    selObj.selectedIndex = 0; // reset val to first menu option
}
}

// Better, cleaner one (use this for new things)
// if the selected option's value is "kill" then do nothing (useful on menu separators)
function jumpMenu(target, selected, restore) {
  if ( selected.selectedIndex > 0 ) {
    if ( selected.options[selected.selectedIndex].value.substring(0,4) != "kill" ) { 
      eval(target + ".location='" + selected.options[selected.selectedIndex].value + "'");
      if (restore) {
        selected.selectedIndex = 0;
      }
    } else { 
      selected.selectedIndex = 0; // reset val to first menu option
    }
  }
}

// this guy (unlike the others) actually submits the form
// we should probably name him differently
function jumpMenu2(target, selected, restore) {
    eval(target + ".action='" + selected.options[selected.selectedIndex].value + "'");
    if (restore) {
        selected.selectedIndex = 0;
    }
    eval(target + ".submit()");
}


// STRIP CHARACTER FUNCTION
// Use: stripChars('thestring', 'thecharacter'); to remove 'thecharacter' from 'thestring'
function stripChars (s, bag) {
	var i;
	var returnString = "";

	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++) {
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

// CHANGE CLASS BY ID
function changeClass(id, newClass) {
	identity = document.getElementById(id);
	identity.className = newClass;
}

// JAVASCRIPT COOKIE FUNCTIONS
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {

		var j = i + alen;

		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
		}

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) {
			break;
		}
	}
	return null;
}

function SetCookie(name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function DeleteCookie () {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
	var cval = GetCookie ('DemoName');
	document.cookie ='DemoName' + "=" + cval + "; expires=" + exp.toGMTString();
	alert("The cookie has been deleted.");
}

// CONSOLE SPECIFIC FUNCTIONS
// MANAGE CATALOG ACTION FUNCTION

function catalogFormAction(param, additionalParam) {
	if (param == 'addNewCatalog') {
		document.catalogsForm.action = "/jsp/console/console_edit_catalog.jsp?action=createCatalog";
	} else if (param == 'delete') {
		document.catalogsForm.action = "/jsp/console/console_confirm_delete.jsp?action=remove";
	} else if (param == 'map') {
		var ids = mapFunction(function(x){return x.value},$("input:checked.jqueryIDHandle"));
        new MapBox().show(ids);		
	} else if (param == 'email') {
		document.catalogsForm.action = "/jsp/email/email_compose.jsp?newEmail=true";
	} else if (param == 'report') {
		document.catalogsForm.action = "/jsp/reports/report_choosetype.jsp?action=newReport&initialLoad=initialLoad";
	}else if (param == 'reorder') {
		document.catalogsForm.action = "/jsp/console/console_reorder_catalog.jsp?action=reorderCatalog";
	} else if (param == 'export') {
		document.catalogsForm.action = "/jsp/export/export.jsp?exportType=2" + ((additionalParam && additionalParam == "comps")?"&exportedEntityType=COMPARABLE":"");
	} else if (param == 'compare') {
		// Open the popup window
		window.open('','comparePopUp','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=800,height=600');

		//report type 0 is what is set in ViewReportsPageBean as a compare listings report
		document.catalogsForm.compareReportType.value = "true";
		document.catalogsForm.action = "/jsp/reports/report_comparelistings.jsp";
		document.catalogsForm.target = "comparePopUp";
	}

	if (param != 'compare') {
		document.catalogsForm.target = "_self";
	}

	if (param != 'map') {
		document.catalogsForm.submit();
	}
}


// SEARCH SPECIFIC FUNCTIONS

// SEARCH RESULTS NAV FUNCTION
// This is used in the search_nav_include.jsp file for changing the form action when clicking
// on "Map", "Compare", "Create Reports", etc...
function processAgents(type) {
	if (type == 'compareAgents') {
		// Open the popup window
		window.open('','comparePopUp','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=800,height=600');

		//report type 0 is what is set in ViewReportsPageBean as a compare listings report
		//document.resultsForm.compareReportType.value = "true";
		document.resultsForm.action = "/jsp/reports/agent/report_compareagents.jsp";
		document.resultsForm.target = "comparePopUp";

	// Create Report
	} else if (type == 'mapAgents') {
		document.resultsForm.action = "/jsp/mapping/results_agents_by_map.jsp";
		document.resultsForm.target = "_self";

	// email 'em
	} else if (type == 'emailAgents') {
		document.resultsForm.action = "/jsp/email/email_compose.jsp?newEmail=true";
		document.resultsForm.target = "_self";
	}
	document.resultsForm.submit();
}

function processListings(type) {
	// Email Listings
	if (type == 'email') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/email/email_compose.jsp?newEmail=true";

	// Compare
 	} else if (type == 'compare') {

		// Open the popup window
		window.open('','comparePopUp','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=800,height=600');

		//report type 0 is what is set in ViewReportsPageBean as a compare listings report
		document.resultsForm.compareReportType.value = "true";
		document.resultsForm.action = "/jsp/reports/report_comparelistings.jsp";
		document.resultsForm.target = "comparePopUp";
	// Create Report
	} else if (type == 'createReport') {
		document.resultsForm.compareReportType.value = "false";
		document.resultsForm.action = "/jsp/reports/report_choosetype.jsp?action=newReport&initialLoad=initialLoad";
		document.resultsForm.target = '_self';
	// Map Listings
	} else if (type == 'map') {
        var ids = mapFunction(function(x){return "{0}".format(x.value)},$("input:checked.jqueryIDHandle"));
        new MapBox().show(ids);
	// Add to Catalog
	} else if (type == 'addtoCatalog') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/console/console_addto_catalog.jsp?action=prepareForAdd";

	// Export
	} else if (type == 'export') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/export/export.jsp?exportType=1";

	}

	// Then submit the form
	if (type != 'map') {
		document.resultsForm.submit();
	}
}

function processProperties(type) {
	// Email Listings
	if (type == 'email') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/email/email_compose.jsp?newEmail=true";

	// Compare
	} else if (type == 'compare') {

		// Open the popup window
		window.open('','comparePopUp','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=800,height=600');

		//report type 0 is what is set in ViewReportsPageBean as a compare listings report
		document.resultsForm.compareReportType.value = "true";
		document.resultsForm.action = "/jsp/reports/multi_property/report_compareproperties.jsp";
		document.resultsForm.target = "comparePopUp";
	// Create Report
	} else if (type == 'createReport') {
		document.resultsForm.compareReportType.value = "false";
		document.resultsForm.action = "/jsp/reports/report_choosetype.jsp?action=newReport&initialLoad=initialLoad";
		document.resultsForm.target = '_self';
	// Map
	} else if (type == 'map') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/mapping/properties_by_map.jsp";
		//if no checkboxes are checked, then check all of them
		var checkBoxes = document.resultsForm["propertyID"];
		checkAllNotNone(checkBoxes);

	// Add to Catalog
	} else if (type == 'addtoCatalog') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/console/console_addto_catalog.jsp?action=prepareForAdd";

	// Export
	} else if (type == 'export') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/export/export.jsp?exportType=1&exportedEntityType=PROPERTY";

	}

	// Then submit the form
	document.resultsForm.submit();
}

function processComparables(type) {

	// Export
	if (type == 'export') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/export/export.jsp?exportType=1&exportedEntityType=COMPARABLE";

	// Map Listings
	} else if (type == 'map') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/mapping/comparables_by_map.jsp";
		//if no checkboxes are checked, then check all of them
		var checkBoxes = document.resultsForm["comparableID"];
		checkAllNotNone(checkBoxes);

	// Add to Catalog
	} else if (type == 'addtoCatalog') {
		document.resultsForm.target = '_self';
		document.resultsForm.action = "/jsp/console/console_addto_catalog.jsp?action=prepareForAdd";

	// Create Report
	} else if (type == 'createReport') {
		document.resultsForm.compareReportType.value = "false";
		document.resultsForm.action = "/jsp/reports/report_choosetype.jsp?action=newReport&initialLoad=initialLoad";
		document.resultsForm.target = '_self';

	// Compare
	} else if (type == 'compare') {
		// Open the popup window
		window.open('','comparePopUp','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=800,height=600');

		//report type 0 is what is set in ViewReportsPageBean as a compare listings report
		document.resultsForm.compareReportType.value = "true";
		document.resultsForm.action = "/jsp/reports/report_comparelistings.jsp";
		document.resultsForm.target = "comparePopUp";
	}

	// Then submit the form
	document.resultsForm.submit();
}


// SALE/LEASE/BOTH TOGGLE FUNCTION
// This gets used at the top of search pages, where they choose sale/lease or both
// It will check which radio button is selected, then hide/show the sale or lease fields based on that selection

function checkListingTypeSearch(which) {

	if (which == "both") {
		document.searchCriteriaForm.includeLeaseAndSale['0'].checked = true;
	} else if (which == "sale") {
		document.searchCriteriaForm.includeLeaseAndSale['1'].checked = true;
	} else if (which == "lease") {
		document.searchCriteriaForm.includeLeaseAndSale['2'].checked = true;
	}

	var saleDiv = document.getElementById('saleOptions');
	var leaseDiv = document.getElementById('leaseOptions');

	if (document.searchCriteriaForm.includeLeaseAndSale) {
		if (document.searchCriteriaForm.includeLeaseAndSale['0'].checked == true) {
			saleDiv.style.display = "block";
			leaseDiv.style.display = "block";
		} else if (document.searchCriteriaForm.includeLeaseAndSale['1'].checked == true) {
			saleDiv.style.display = "block";
			leaseDiv.style.display = "none";
		} else if (document.searchCriteriaForm.includeLeaseAndSale['2'].checked == true) {
			saleDiv.style.display = "none";
			leaseDiv.style.display = "block";
		}
	}
}



// CHECK ALL CHECKBOXES FUNCTION
function checkAllBoxes() {
	if (document.resultsForm.listingID) {
		if (document.resultsForm.checkAll.checked == true) {
			for (i=0; i < document.resultsForm.listingID.length; i++) {
				document.resultsForm.listingID[i].checked = true;
			}
		}
		if (document.resultsForm.checkAll.checked == false) {
			for (i=0; i < document.resultsForm.listingID.length; i++) {
				document.resultsForm.listingID[i].checked = false;
			}
		}
	} else if (document.resultsForm.comparableID) {
		if (document.resultsForm.checkAll.checked == true) {
			for (i=0; i < document.resultsForm.comparableID.length; i++) {
				document.resultsForm.comparableID[i].checked = true;
			}
		}
		if (document.resultsForm.checkAll.checked == false) {
			for (i=0; i < document.resultsForm.comparableID.length; i++) {
				document.resultsForm.comparableID[i].checked = false;
			}
		}
	}
}

function checkAllRecipients(checkboxName) {
	checkboxName = checkboxName || "agent_id";
	var elements = document.resultsForm[checkboxName];

	if (elements) {
		if (! elements["length"]) {
				//if this is not array-oid
				elements = new Array(elements);
		}

		if (document.resultsForm.checkAll.checked == true) {
			for (i=0; i < elements.length; i++) {
				elements[i].checked = true;
			}
		}
		if (document.resultsForm.checkAll.checked == false) {
			for (i=0; i < elements.length; i++) {
				elements[i].checked = false;
			}
		}
	}
}

// this method assumes that the "Check All" Checkbox is called "checkAll"
function checkAllCheckBoxes(formName, boxesToCheckName) {
	var elements = document.forms[formName][boxesToCheckName];

	if (elements) {
		if (document.forms[formName].checkAll.checked == true) {
			for (i=0; i < elements.length; i++) {
				elements[i].checked = true;
			}
		}
		if (document.forms[formName].checkAll.checked == false) {
			for (i=0; i < elements.length; i++) {
				elements[i].checked = false;
			}
		}
	}
}

// SUBTYPE CHECKBOX HANDLING FUNCTION
// Used on all search pages to keep "All Types" checkbox in sync with other checkboxes
function handleSubtypeCheckbox(checkbox) {
	var subtypes = checkbox.form.subtype;
	if (checkbox.name == "checkall") {
		for (var i=0;i<subtypes.length;i++) {
			subtypes[i].checked = checkbox.checked;
		}
	} else {
		var checkAll = checkbox.form.checkall;
		if (! checkbox.checked) {
			checkAll.checked = false;
		} else {
			//if all are checked then check the checkall box
			var allChecked = true;
			for (var i=0;i<subtypes.length;i++) {
				allChecked = subtypes[i].checked;
				if (! allChecked) {
					break;
				}
			}
			checkAll.checked = allChecked;
		}
	}
}

// HIDE SPLASH PAGE
// Toggles off a div, used on search pages to hide "please wait" message
function hideSplash() {
	thisDiv = document.getElementById("resultsSplash");

	if (thisDiv) {
		thisDiv.style.display = "none";
	} else {
		alert("Error: Could not locate div with id: " + divName);
	}
}

// TOGGLE OVERVIEW & THUMBNAIL FUNCTION
// Modified version of the toggle tag function
// Set's cookies for display / not display
function toggleSearchDisplay(thisCheckbox, tag, itemname, setCookie) {
	// Get Expiration Date for Cookies
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));

	// Get 'tag' elements and put them in an array
	tmp = document.getElementsByTagName(tag);

	// Find out which checkbox they're talking about
	checkname = thisCheckbox.name;

	// If showing
	if (thisCheckbox.checked) {
		for (i = 0; i < tmp.length; i++) {
			if (tmp[i].className == itemname) {
				if (thisCheckbox.name == "toggleOverview") {
					tmp[i].style.display = 'block';
				} else {
					tmp[i].style.display = 'inline';
				}
			}
		}

		if (setCookie) {
			// Set the cookie
			if (thisCheckbox.name == "toggleOverview") {
				SetCookie('toggleOverview', 'block', expdate);
			} else if (thisCheckbox.name == "toggleThumbnail") {
				SetCookie('toggleThumbnail', 'inline', expdate);
			} else {
				alert("Nothing known about " + thisCheckbox.name);
			}
		}

	// If hiding
	} else if (!thisCheckbox.checked) {
		for (i = 0; i < tmp.length; i++) {
			if (tmp[i].className == itemname) {
				tmp[i].style.display = 'none'
			}
		}

		if (setCookie) {
			// Set the cookie
			if (thisCheckbox.name == "toggleOverview") {
				SetCookie('toggleOverview', 'none', expdate);
			} else if (thisCheckbox.name == "toggleThumbnail") {
				SetCookie('toggleThumbnail', 'none', expdate);
			} else {
				alert("Nothing known about " + thisCheckbox.name);
			}
		}

	// Debugging
	} else {
		alert('tmp = ' + tmp);
		alert('thisCheckbox = ' + thisCheckbox);
		alert('Checked = ' + thisCheckbox.checked);
	}
}

function getSearchToggleCookie() {
	// Get the values from the cookies
	var overviewDisplayFromCookie = GetCookie('toggleOverview');
	var thumbnailDisplayFromCookie = GetCookie('toggleThumbnail');

	// Set the checkboxes to previous cookie state

	// Overview
	if (overviewDisplayFromCookie == "block") {
		document.resultsForm.toggleOverview.checked = true;
	} else if (overviewDisplayFromCookie == "none") {
		document.resultsForm.toggleOverview.checked = false;
	}

	// Thumbnail
	if (thumbnailDisplayFromCookie == "inline") {
		document.resultsForm.toggleThumbnail.checked = true;
	} else if (thumbnailDisplayFromCookie == "none") {
		document.resultsForm.toggleThumbnail.checked = false;
	}

	// Then run the toggle function and it will check the checkbox state
	toggleSearchDisplay(document.resultsForm.toggleOverview,'span','hiderow', false);
	toggleSearchDisplay(document.resultsForm.toggleThumbnail,'img','thumbnail', false);
}

// TOGGLE SEARCH HELP TIPS
// Similar to the toggle Overview function
// but only for hiding search tips (no toggle)
function toggleSearchTips(which, setCookie) {

	// Get Expiration Date for Cookies
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));

	// Get element pointer
	var helptips = document.getElementById('helptips');
	var showtips = document.getElementById('showtips');

	if (which == 'hide') {
		helptips.style.display = 'none';
		showtips.style.display = 'block';
	} else if (which == 'show') {
		helptips.style.display = 'block';
		showtips.style.display = 'none';
	}

	if (setCookie) {
		SetCookie('toggleSearchTips', which, expdate);
	}
}

function getSearchTipsDisplay() {

	// Get element pointer
	var helptips = document.getElementById('helptips');
	var showtips = document.getElementById('showtips');

	// Get the values from the cookies
	var display = GetCookie('toggleSearchTips');

	// Overview
	if (helptips && showtips) {
		if (display == 'hide') {
			helptips.style.display = 'none';
			showtips.style.display = 'block';
		} else if (display == 'show') {
			helptips.style.display = 'block';
			showtips.style.display = 'none';
		} else {
			helptips.style.display = 'none';
			showtips.style.display = 'block';
		}

	}
}

// EMAIL CIPHER
// You'll need to teach your bot to read javascript, sucker.

// Define possible char values
var availableChars = 'abcdefghijklmnopqrstuvwxyz0123456789!#$%&+-/=?^_`.{|}~';

// Simple algorithm shifts characters
// Note: changes here must be mirrored in Cipherer.java which enciphers addresses
function substituteChar(baseChar, shiftIndex, encipher) {
	// encipher
	if (encipher) {
        switch (baseChar) {
        case '$': return ';';
        case '@': return '(';
        case '*': return ')';
        case ' ': return ',';
        }

        var shiftSum = shiftIndex + this.availableChars.indexOf(baseChar);
		return (this.availableChars.charAt((shiftSum < this.availableChars.length) ?
				shiftSum : (shiftSum % this.availableChars.length)));
	// decipher
	} else {
        switch (baseChar) {
        case ';': return '$';
        case '(': return '@';
        case ')': return '*';
        case ',': return ' ';
        }

        var shiftDifference = this.availableChars.indexOf(baseChar) - shiftIndex;
		return (this.availableChars.charAt((shiftDifference < 0) ?
				shiftDifference + this.availableChars.length : shiftDifference));
	}
}

// Encodes (plain text -> ciphered text)
function encipher(plainText) {
	plainText = plainText.toLowerCase();
	var ciperedText = "";
	for (var i=0; i<plainText.length; i++) {
		ciperedText = ciperedText + substituteChar(plainText.charAt(i), plainText.length, true);
	}
	return ciperedText;
}

// Decodes (ciphered text -> plain text)
function decipher(ciperedText) {
	ciperedText = ciperedText.toLowerCase();
	var plainText = "";
	for (var i=0; i<ciperedText.length; i++) {
		plainText = plainText + substituteChar(ciperedText.charAt(i), ciperedText.length, false);
	}
	return plainText;
}

// Converts ciphered address to plain text at last second
function getMailTo(cipheredAddress) {
	parent.location = "ma" + "il" + "to" + ':' + decipher(cipheredAddress);
}

// Just spits out the plain text address
function showAddress(cipheredAddress) {
	document.write(decipher(cipheredAddress));
}

// Just spits out the ciphered address
function hideAddress(plainAddress) {
	document.write(encipher(plainAddress));
}

// FIND RECIPIENTS LINK
// Clicking the link submits the form, saving the entered info for later
function emailFormSaveInfo() {
	document.emailForm.action = "email_recipients_search.jsp";
	document.emailForm.enctype = "";
	document.emailForm.submit();
}

// FOR CHECK BOXES ACROSS PAGES
// See tom
function setAndSubmit(page) {
	document.resultsForm.action=page;
	document.resultsForm.target = '_self';
	document.resultsForm.submit();
}

// check all checkboxes if none are checked
function checkAllNotNone(checkBoxes) {
	//if no checkboxes are checked, then check all of them
	var anyChecked = false;
	for (var i=0;i<checkBoxes.length;i++) {
		anyChecked = checkBoxes[i].checked;
		if (anyChecked) {
			break;
		}
	}
	if (! anyChecked) {
		for (var i=0;i<checkBoxes.length;i++) {
			checkBoxes[i].checked = true;
		}
	}
}

function countCharsByName(textareaName, charCountIDName) {

    var string = $("textarea[name="+textareaName+"]")[0].value;

    string = trimString(string);
    if (string.length == 0) {
        $('#'+charCountIDName).html('');
    } else {
        //var a = string.split(/\s+/g);
        //alert("length  = " + a.length);
        $('#'+charCountIDName).html(string.length);
    }

}


function countChars(textarea, charCountIDName) {
    var string = textarea.value;
    string = trimString(string);
    if (string.length == 0) {
        $('#'+charCountIDName).html('');
    } else {
        $('#'+charCountIDName).html(string.length);
    }

}

function trimString(sInString) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
          return sInString.replace( /\s+$/g, "" );// strip trailing
  }

