


// requires prototype
	function showAdvanced() {
		$('advanced').className = 'formList';
		$('advanced_link').href = 'javascript:hideAdvanced();';
		$('advanced_link').innerHTML = 'Basic Search';
		$('basic').value = 0;
	}
	function hideAdvanced() {
		$('advanced').className = 'hidden';
		$('advanced_link').href = 'javascript:showAdvanced();';
		$('advanced_link').innerHTML = 'Advanced Search';
		$('basic').value = 1;
	}
	function toggleEducation() {
		var edu = $('ed');
		if ($('ed_detail').selectedIndex == 0) {
			edu.disabled = 'disabled';
		} else {
			edu.disabled = '';
		}
	}
	function toggleChildren() {
		var ch = $('r_children');
		if ($('children').selectedIndex == 1) {
			ch.className = '';
		} else {
			ch.className = 'hidden';
		}
	}
	function toggleChildrenAge() {
		var ch = $('children_level');
		if ($('children_detail').selectedIndex == 0) {
			ch.disabled = 'disabled';
		} else {
			ch.disabled = '';
		}
	}
	function toggleAge() {
		var ag = $('age');
		if ($('age_detail').selectedIndex == 0) {
			ag.disabled = 'disabled';
		} else {
			ag.disabled = '';
		}
	}
	function toggleStationed() {
		var sta = $('r_stationed');
		if ($('military').selectedIndex == 1) {
			sta.className = '';
		} else {
			sta.className = 'hidden';
		}
	}		
	function toggleSaveSearch() {
		var ss = $('name');
		if ($('savesearch').selectedIndex == 0) {
			ss.disabled = '';
		} else {
			ss.disabled = 'disabled';
		}
	}
	function focusName(box) {
		if (box.value == "Name") {
			box.value = "";
		}
	}
	
	function blurName(box) {
		if (box.value == "") {
			box.value = "Name";
		}
	}
	
	function saveSearch(value, index, name) {
		// if index is 0, ajax, otherwise redirect
		if (index == 0) {
			if ($('savingdiv')) {
				$('savingdiv').className = 'saving';
			}			
			new Ajax.Request('savesearch.php?query='+value+'&ss='+name, {
				method: 'get',
				onSuccess: function (transport) {
					doneSaving(transport.responseText);
				}
			});	
		} else {
			window.location = value;
		}
	}
	
	function doneSaving(jsonText) {
		// get the new list of saved searches, and update the load search drop down, then hide the saving div.		
		if ($('loadsearch')) {
			var searches = [];
			searches = eval(jsonText);
			emptyList($('loadsearch'));
			if (searches) {
				for (i=0,j=searches.length;i<j;i++){
					var o = document.createElement('option');
					o.text = searches[i].name;
					o.value = searches[i].query;
					try {
						$('loadsearch').add(o,null);
					} catch (ex) {
						$('loadsearch').add(o);
					}
				}
			}
		}		
		if ($('savingdiv')) {
			$('savingdiv').className = 'hidden';
		}		
	}
		
	function buildThemes(jsonText) {
		if ($('themes')) {
			var themeOptions = [];
			themeOptions = eval(jsonText);
			emptyList($('themes'));
			if (themeOptions) {
				$('themes').disabled = '';
				for (i=0,j=themeOptions.length;i<j;i++){
					var o = document.createElement('option');
					o.text = themeOptions[i].name;
					o.value = themeOptions[i].id;
					try {
						$('themes').add(o, null);
					} catch (ex) {
						$('themes').add(o);
					}
				}
			} else {
				$('themes').disabled = 'disabled';
				var o = document.createElement('option');
				o.text = 'All';
				o.value = '0';
				try {
					$('themes').add(o, null);
				} catch (ex) {
					$('themes').add(o);
				}
			}
		}
	}
	
	function emptyList(list){
		while (list.firstChild) {
			list.removeChild(list.firstChild);
		}
	}
	
	function choseCategory(category) {
		new Ajax.Request('themes.php?id='+category, {
			method: 'get',
			onSuccess: function (transport) {
				buildThemes(transport.responseText);
			}
		});
	}
		
	function togglePreview(cell, link) {
		if (cell.oldClassName) {
			i = cell.className;
			cell.className = cell.oldClassName;
			cell.oldClassName = i;
			i = link.innerHTML;
			link.innerHTML = link.oldLink;
			link.oldLink = i;			
		} else {
			cell.oldClassName = cell.className;
			link.oldLink = link.innerHTML;
			cell.className = 'preview_cell';
			link.innerHTML = 'Hide';
		}
	}	
	
	function showPIS() {
		$('personal_info').className = '';
		$('pis_link').href = 'javascript:hidePIS();';
		$('pis_link').innerHTML = 'Hide';
	}
	function hidePIS() {
		$('personal_info').className = 'hidden';
		$('pis_link').href = 'javascript:showPIS();';
		$('pis_link').innerHTML = 'Show';
	}
	
	function toggleClass(target, link, linktext, targetclass) {
	/***************************************************************************************
	*	Toggles the class of an object, and the text of a link.  
	*		target - the object to toggle the class of
	*		link - the object that toggles the class when clicked (anchor recommended)
	*		linktext (optional) - the new text to put in the inner html of the link object
	*		targetclass (optional) - the new class to give to the object
	*
	*  don't use this function yet - it's going to change significantly. 
	****************************************************************************************/
		if (!target) return;
		if (!link) return;
		// target class
		if (!targetclass) {
			if (!target.oldClass) {
				target.oldClass = target.className;
				target.className = 'hidden';
			} else {
				targetclass = target.oldClass;
				target.oldClass = target.className;
				target.className = targetclass;
			}
		} else {
			target.oldClass = target.className;
			target.className = targetclass;
		}
		// link text
		if (!linktext) {
			if (!link.oldLink) {
				link.oldLink = link.innerHTML;
				link.innerHTML = 'Toggle';  // perhaps show?
			} else {
				linktext = link.oldLink;
				link.oldLink = link.innerHTML;
				link.innerHTML = linktext;
			}
		} else {
			link.oldLink = link.innerHTML;
			link.innerHTML = linktext;
		}
		// link function - technically we'd only have to do this on the first toggle, so we could throw this under the !old ifs.
		if (!link.href) {
			link.onClick = 'javascript:toggleClass($(\''+target.id+'\'), $(\''+link.id+'\'));';
		} else {
			link.href = 'javascript:toggleClass($(\''+target.id+'\'), $(\''+link.id+'\'));';		
		}
	}