$jsq = jQuery.noConflict();	// Make sure our implementation doesn't conflict with anyone elses

var popHelpT;
var overPopHelp;
var gpLinkHover = 0; 		// Tells us that we're hovering over the Geek Professor Link area
var gpLinkInterval = null;
var onJsearchPage = 0;		// This will be set to 0 by default, but will be overrided later by the jsearch template IF we're on the right page

$jsq(document).ready(function() {

	// Keyword entry stuff
	$jsq("#jsearch_sb_terms,#jsearch_gsearch_box").keydown(
		function (event) {
			if (event.keyCode == 13) {
				jsearchSbSearch($jsq(this).val());
			}
		});
	$jsq("#jsearch_sb_terms,#jsearch_gsearch_box").keydown(
		function (event) {
			if (event.keyCode == 13) {
				jsearchSbSearch($jsq(this).val());
			}
		});
	$jsq("#jsearch_gsearch_box").focus( function () {
			$jsq(this).removeClass("jsearch_gsearch_box_off");
			$jsq(this).addClass("jsearch_input_focused");
		});
	$jsq("#jsearch_gsearch_box").blur( function () {
			if ($jsq(this).val().length == 0)
				$jsq(this).addClass("jsearch_gsearch_box_off");
			$jsq(this).removeClass("jsearch_input_focused");
		});
	$jsq('#jsearch_control_area input[type="text"]').focus( function() {
			$jsq(this).addClass("jsearch_input_focused");
		});
	$jsq('#jsearch_control_area input[type="text"]').blur( function() {
			$jsq(this).removeClass("jsearch_input_focused");
		});

	if (onJsearchPage)
	{	
		jsearchWriteSearchItems("term");		// Update the listing of search terms based on the current term arrays
		jsearchWriteSearchItems("cat");			// Write any categories that are already selected (from a URL string)
		jsearchWriteSearchItems("tag");
	
		//************
		// Side Help functions		
		$jsq("#jsearch_items_adder_side_help").hover ( 
			function () { jsearchSideHelpSwitcher("default"); },
			function () { }
		);
		$jsq("#jsearch_term_input_td").hover ( 
			function () { jsearchSideHelpSwitcher("term"); },
			function () { }
		);
		$jsq("#jsearch_cat_dropbox_container").hover ( 
			function () { jsearchSideHelpSwitcher("cat"); },
			function () { }
		);
		$jsq("#jsearch_tag_dropbox_container").hover ( 
			function () { jsearchSideHelpSwitcher("tag"); },
			function () { }
		);
		
			
		// HANDLE TERMS
		// If they're typing terms and hit ENTER, add the terms
		$jsq("#jsearch_term_input").keydown( function (event) {
			if (event.keyCode == 13) {
				jsearchControlAddTerms('any');
			}
			});
		$jsq("#jsearch_term_input").keyup( function (event) {
			jsearchFilterCatTagBox('cat');	// Show categories that match this term
			jsearchFilterCatTagBox('tag');	// Show tags that match this term
			});	
		$jsq("#jsearch_term_delete_button").click ( function () {
			$jsq('#jsearch_term_input').val('');
			jsearchFilterCatTagBox('cat');	// Show categories that match this term
			jsearchFilterCatTagBox('tag');	// Show tags that match this term
		});
		$jsq("#jsearch_term_none_button").click ( function () {
				jsearchControlAddTerms('none');			
		});
		$jsq("#jsearch_term_any_button").click ( function () {
				jsearchControlAddTerms('any');			
		});
		$jsq("#jsearch_term_all_button").click ( function () {
				jsearchControlAddTerms('all');			
		});


		// **** HELP BUTTON TOGGLER ****
		$jsq("#jsearch_help_button").click( function () {
			if ($jsq("#jsearch_help_area").is(":visible")) 
				$jsq("#jsearch_help_area").hide();
			else
				$jsq("#jsearch_help_area").show();
		} );
		$jsq("#jsearch_help_closer_button").click( function () { $jsq("#jsearch_help_area").hide(); });

		jsearchSectionHeaderToggleStuff("items_adder");
		jsearchSectionHeaderToggleStuff("items_added");
		jsearchSectionHeaderToggleStuff("options");

		$jsq("#jsearch_about_button").hover ( 
			function () { jsearchPopHelp("#jsearch_about_button","Click to learn more about Jsearch and how you can get it for your page");	},
			function () { jsearchPopHelpOff();	}
		);
		$jsq("#jsearch_help_button").hover ( 
			function () { jsearchPopHelp("#jsearch_help_button","Click to learn how to use Jsearch"); },
			function () { jsearchPopHelpOff();	}
		);

		$jsq("#jsearch_search_button").click ( function () {
			document.location.href = jsearchURL();
		});
		
		
		$jsq(".jsearch_button").hover( 
			function (){ $jsq(this).addClass("jsearch_button_on");},
			function (){ $jsq(this).removeClass("jsearch_button_on");}
		);
	}
	
	$jsq("#jsearch_control_hider").show();		// Show the controls now that the rest of the page and such has loaded.
	$jsq("#jsearch_loading_notice").hide();		// and hide the notice
});


// Just a bit of code abstraction for standardization and saving space
function jsearchSectionHeaderToggleStuff(which)
{
	$jsq("#jsearch_"+which+"_title_area").click ( function () { 
		if ($jsq("#jsearch_"+which+"_table").is(":visible")) 
		{
			$jsq("#jsearch_"+which+"_table").hide();
			$jsq("#jsearch_"+which+"_hs").html('Click to show this section...');
		}
		else
		{
			$jsq("#jsearch_"+which+"_table").show();
			$jsq("#jsearch_"+which+"_hs").html('Click to hide this section...');
		}
	});
	$jsq("#jsearch_"+which+"_help_button").hover ( 
		function () { $jsq('#jsearch_'+which+'_help').show(); },
		function () { $jsq('#jsearch_'+which+'_help').hide(); }
	);
	// When hovering on the title, see if the area is open. If so, give the "click to close" hint. Otherwise, give the "click to open" hint.
	$jsq("#jsearch_"+which+"_title_area").hover ( 
		function () { $jsq('#jsearch_'+which+'_hs').show(); },
		function () { $jsq('#jsearch_'+which+'_hs').hide(); }
	);
}

// Test for enter key so we can submit even without a form by hitting the enter key
function jsearchIsEnter(e)
{
	if (window.event)
		ccode = e.keyCode
	else if (e.which)
		ccode = e.which
	if (ccode == 13)
		return true;
	else
		return false;
}

// This supports a special search box that's google-like that can be placed whereever.
// Anything entered into it is just sent to the search page to be parsed.
function jsearchSbSearch(terms)
{	
	// Clear these so they don't get appended to anything that's already there.
	term_any = [];
	term_all = [];
	term_none = [];
	if (!terms || terms.length < 2) return;
	jsearchParseTerms(terms,'auto');	// Get the value and parse it.
	document.location.href = jsearchURL();
}	

// Used to show a popup for diagnostics purposes
function jsearchPopHelp(caller,text)
{
	if (text.length==0) return;
	callerP = $jsq(caller).offset();
	$jsq("#jsearch_help_pop").html(text);
	top = Math.max(0,callerP.top-$jsq("#jsearch_help_pop").outerHeight());
	top = Math.min(top,$jsq(window).height()-$jsq("#jsearch_help_pop").outerHeight())
	$jsq("#jsearch_help_pop").css('top',top-3);
	left = Math.max(callerP.left-$jsq("#jsearch_help_pop").width()/2,0);
	left = Math.min(left,$jsq(window).width()-$jsq("#jsearch_help_pop").width());
	$jsq("#jsearch_help_pop").css('left',left);
	$jsq("#jsearch_help_pop").show();
}

// Turn off the popup
function jsearchPopHelpOff()
{
	$jsq('#jsearch_help_pop').hide();
}

// Change the "side help" based on which type of thing we're adding.
function jsearchSideHelpSwitcher(which)
{
	$jsq('#jsearch_default_side_help').hide();
	$jsq('#jsearch_term_side_help').hide();
	$jsq('#jsearch_cat_side_help').hide();
	$jsq('#jsearch_tag_side_help').hide();
	$jsq('#jsearch_'+which+'_side_help').show();
}

//*************************
// Term functions
//*************************

function jsearchParseTerms(termString,which)
{
	var parseCount = 0;		// For walking down the string
	var quoted = false;		// For handling quotes

	termString = termString.replace('\"','"');
	while (parseCount < termString.length)
	{
		while (termString.charAt(parseCount) == ' ' && parseCount<termString.length) 
			parseCount++;	// Get to a non space character
			
		// use the passed mode for adding. Default to "any". If they manually used the + - codes though, always let those override.	
		if (which != 'auto') mode = which;
		else mode = 'any';
		if (termString.charAt(parseCount)== '-')	// None
			mode = "none";
		else if (termString.charAt(parseCount)== '+')	// All
			mode = "all";
						
		// Now make sure we don't accidentally add a control character to the string
		if (mode == "none" || mode == "all")
			parseCount++;
		if (termString.charAt(parseCount)== '"')	// Quoted string
		{
			parseCount++;
			quoted = true;				// Special case. Have to store this for a sec.
		}
		startCut = parseCount;				// Start at the first non-control character
		if (quoted)
			while (termString.charAt(parseCount+1) != '"' && parseCount<termString.length) parseCount++;	// Find the match
		else
			while (termString.charAt(parseCount+1) != ' ' && parseCount<termString.length) parseCount++;	// Find the match
		stopCut = parseCount;
		stopCut++;
		term = jsearchTrim(termString.substr(startCut,stopCut-startCut));
		if (term.length > 1)				// Ignore 0 length items and also anything less than 2 characters
			eval("term_"+mode+"[term_"+mode+".length] = \""+term+"\";");
		if (quoted) parseCount++;			// Skip the trailing quote
		parseCount++;
	}
}

//*************************
// Search area functions
//*************************

// A special function for the term adder popup. Used to feed the AddTerms function with a special modification to handle which button they hit.
function jsearchPopAddTerms(which)
{
	if (which == "none")
	{
		alert($jsq("#jsearch_term_input").val());
	}
	if (which == "any")
	{
		alert($jsq("#jsearch_term_input").val());
	}
	if (which == "all")
	{
		alert($jsq("#jsearch_term_input").val());
	}
}

function jsearchControlAddTerms(which)
{
	jsearchParseTerms($jsq("#jsearch_term_input").val(),which);	// Get the value and parse it.
	$jsq("#jsearch_term_input").val('');				// Empty the value now that we've added these terms
	$jsq("#jsearch_term_input").blur(); 				// To remove the special class, we call blur which already does this.
	jsearchWriteSearchItems("term");				// Write the terms area
}

function jsearchWhichArr(which,value)					// Which of the three (any, all, or none) has this value.
{
	var found = "";
	
	if (!which) return;
	if (!value) return;
	
	eval("if ("+which+"_none.length && ("+which+"_none.indexOf(\""+value+"\") != -1)) found='none';");	
	eval("if ("+which+"_any.length && ("+which+"_any.indexOf(\""+value+"\") != -1)) found='any';");
	eval("if ("+which+"_all.length && ("+which+"_all.indexOf(\""+value+"\") != -1)) found='all';");
	
	return found;
}

function jsearchValFromTo(value,which,to)
{
	var found = jsearchWhichArr(which,value);
	// Check to see if it's already there
	if (found && to != found)								// If it's there, but not in the right one so kill it!
	{
		eval(which+"_"+found+".splice("+which+"_"+found+".indexOf(\""+value+"\"),1)"); 	// evals to term_any.splice(term_any.indexOf("value")) (if from was term_any anyway)
//		eval(which+"_"+found+"["+which+"_"+found+".indexOf(\""+value+"\")] == ''"); 	// evals to term_any.splice(term_any.indexOf("value")) (if from was term_any anyway)
	}
	if (to != 'del')									// If we're not deleting, move it to the new array
		eval(which+"_"+to+"["+which+"_"+to+".length] = \""+value+"\"");			// evals to term_none[term_none.length] = "value";
	return found;
}

var jsearchTermCount = 0;


// This is a copy of the printout used for the pop-up boxes. It prints selectable items that are part of the search.
function jsearchWriteSearchItem(which, aan, value)
{
	var to_return = "";	// To define it as a local variable...
	
	if (which == 'cat' || which == 'tag')
		id = value;
	else
		id = jsearchTermCount;
	
	to_return += "<tr><td colspan=5 style='display:none' id='search_"+which+"_value_"+id+"'>"+value+"</td></tr>";	// It's too hard to have this inline. Store the value here for extraction later (now it can have quotes of any kind without issue!
	to_return += "<tr id='search_"+which+"_del_"+id+"'>";
	to_return += "<td style='padding-right:6px'><img src="+jsearch_theme_url+"/delete_off.gif onclick=jsearchChangeSearchItem('"+which+"','del',"+id+") class=hand /></td>";
	to_return += "<td><img id='search_"+which+"_none_"+id+"' src="+jsearch_theme_url+"/none_"+((aan=="none")?"on":"off")+".gif onclick=jsearchChangeSearchItem('"+which+"','none',"+id+")  class=hand /></td>";
	to_return += "<td><img id='search_"+which+"_any_"+id+"' src="+jsearch_theme_url+"/any_"+((aan=="any")?"on":"off")+".gif  onclick=jsearchChangeSearchItem('"+which+"','any',"+id+") class=hand  /></td>";
	to_return += "<td><img id='search_"+which+"_all_"+id+"' src="+jsearch_theme_url+"/all_"+((aan=="all")?"on":"off")+".gif  onclick=jsearchChangeSearchItem('"+which+"','all',"+id+") class=hand  /></td>";
	if (which == "cat")
		to_return += "<td class='jsearch_item_name'>"+jsearchCats[jsearchCatIndexes[value]]['name']+"</td>";
	else if (which == "tag")
		to_return += "<td class='jsearch_item_name'>"+jsearchTags[jsearchTagIndexes[value]]['name']+"</td>";
	else
		to_return += "<td class='jsearch_item_name'>"+value+"</td>";
	to_return += "</tr>";
	jsearchTermCount++;
	return to_return;
}

// Writes a listing of any added search items
function jsearchWriteSearchItems(which)
{
	var to_write = "";
	
	temp = eval(which+"_none");
	tLen = temp.length;
	for (i=0;i<tLen;i++)
		to_write += jsearchWriteSearchItem(which,"none",temp[i]);
	temp = eval(which+"_any");
	tLen = temp.length;
	for (i=0;i<tLen;i++)
		to_write += jsearchWriteSearchItem(which,"any",temp[i]);
	temp = eval(which+"_all");
	tLen = temp.length;
	for (i=0;i<tLen;i++)
		to_write += jsearchWriteSearchItem(which,"all",temp[i]);
	$jsq("#jsearch_selected_"+which+"s_list").html(to_write);
}

function jsearchChangeSearchItem(which,to,id)
{
	value = $jsq("#search_"+which+"_value_"+id).html();				// Stored the value in between HTML tags in case it has ' or " (now we don't have to deal with it at all).
	from = jsearchValFromTo(value,which,to);					// Move or delete the value
	if (to == "del")								// Delete is a special case
	{
		$jsq("#search_"+which+"_del_"+id).hide();				// Hide the whole row until the next re-write;
		
		// Now clear the ctonrol markings (this way, when they click delete it doesn't still show as selected in the control)
		$jsq("#jsearch_"+which+"_none_"+id).attr("src", jsearch_theme_url+"/none_off.gif");
		$jsq("#jsearch_"+which+"_any_"+id).attr("src", jsearch_theme_url+"/any_off.gif");
		$jsq("#jsearch_"+which+"_all_"+id).attr("src", jsearch_theme_url+"/all_off.gif");
		
	}
	else										// Turn off the previous button, turn on the new one
	{
		$jsq("#search_"+which+"_none_"+id).attr("src", jsearch_theme_url+"/none_off.gif");
		$jsq("#search_"+which+"_any_"+id).attr("src", jsearch_theme_url+"/any_off.gif");
		$jsq("#search_"+which+"_all_"+id).attr("src", jsearch_theme_url+"/all_off.gif");
		// Turn off all the buttons for the search area AND the pop area
		if (which == 'cat' || which == 'tag')
		{
			$jsq("#jsearch_"+which+"_none_"+id).attr("src", jsearch_theme_url+"/none_off.gif");
			$jsq("#jsearch_"+which+"_any_"+id).attr("src", jsearch_theme_url+"/any_off.gif");
			$jsq("#jsearch_"+which+"_all_"+id).attr("src", jsearch_theme_url+"/all_off.gif");
		}

		// Now turn on the one that's valid (for both the search area and pop area)
		$jsq("#search_"+which+"_"+to+"_"+id).attr("src", jsearch_theme_url+"/"+to+"_on.gif");
		if (which == 'cat' || which == 'tag')
			$jsq("#jsearch_"+which+"_"+to+"_"+id).attr("src", jsearch_theme_url+"/"+to+"_on.gif");
	}	
}

// USED FOR THE PAGELINKS SECTION
// Just checks the current paged value and goes to the selected page
function jsearchGoto(targetPage)
{
	var toKill = "paged="+jsearchPaged; 			// jsearchPaged is set on the jsearch_control.php page when dropping vars to JS
	var toAdd = "paged="+targetPage;
	
	temp = document.location.href;
	if (temp.indexOf(toKill) != -1)
		temp = temp.replace(toKill,toAdd);
	else
		temp = jsearchAddVars(temp,toAdd);
	document.location.href = temp;
}


//*************************
// Term functions
//*************************


//*************************
// Category and Tag functions
//*************************

// This function is called to update category and tag items in the floating boxes. Also adds and deletes items from the arrays
function jsearchAddCatTag(which,aan,id)
{
	if (found = jsearchValFromTo(id,which,aan))				// Switch it from where it is to the new one (returns false if it wasn't found)
	{
		$jsq("#jsearch_"+which+"_none_"+id).attr("src", jsearch_theme_url+"/none_off.gif");
		$jsq("#jsearch_"+which+"_any_"+id).attr("src", jsearch_theme_url+"/any_off.gif");
		$jsq("#jsearch_"+which+"_all_"+id).attr("src", jsearch_theme_url+"/all_off.gif");
		$jsq("#jsearch_"+which+"_"+found+"_button"+id).attr("src", jsearch_theme_url+"/"+found+"_off.gif");
	}
	$jsq("#jsearch_"+which+"_"+aan+"_"+id).attr("src", jsearch_theme_url+"/"+aan+"_on.gif");
	jsearchWriteSearchItems(which);
}



// Restrict the view of the catbox or tagbox items based on a filter
function jsearchFilterCatTagBox(which)
{
	var parent = -1;
	var filter = "";
	filter = $jsq('#jsearch_term_input').val();

	if (which == 'cat')
		forCount = jsearchCats.length;
	else 	
		forCount = jsearchTags.length;
	for (i=0; i<forCount; i++)
	{
		dontPrint = false;
		if (parent != -1)
			if (jsearchCats[i]["parent"] != parent && jsearchCats[i]["id"] != parent)	// Added this little thing to make allow the parent itself to print.
				dontPrint = true;
		if (which == 'cat')
			temp = jsearchCats[i]["name"].toLowerCase();					// Hold on to its actual name
		else
			temp = jsearchTags[i]["name"].toLowerCase();
		if (filter && temp.indexOf(filter) == -1)						// It's filtered, but this doesn't match
			dontPrint = true;
		if (which == 'cat')
			subject = '#jsearch_cat_'+jsearchCats[i]['id'];
		else
			subject = '#jsearch_tag_'+jsearchTags[i]['id'];
		if (dontPrint)
			$jsq(subject).hide();
		else
			$jsq(subject).show();
	}
}

//*************************
// TAG STUFF
//*************************

//*************************
// ENGLISH STUFF
//*************************

function jsearchIDsToNames(which,anyall)
{
	temp = "";
	first = "";
	eval("len = "+which+"_"+anyall+".length;\n");
	if (which == 'cat') vwhich = 'Cat';
	if (which == 'tag') vwhich = 'Tag';
	for (i=0;i<len;i++)				// Iterate through and create a comma separated list of cat names
	{
		eval("index = jsearch"+vwhich+"Indexes["+which+"_"+anyall+"[i]];\n");	
		eval("temp += first+jsearch"+vwhich+"s[index]['name'];\n");	
		if (!first.length)
			first = ", ";
	}
	return temp;
}


function jsearchMakeSentence(term_update,cat_update,tag_update,andor)
{
	to_update = "";
	if (term_update && cat_update && tag_update)
		to_update += term_update+", "+cat_update+", "+andor+tag_update;
	else if (term_update && cat_update)
		to_update += term_update+" "+andor+cat_update;
	else if (term_update && tag_update)
		to_update += term_update+" "+andor+tag_update;
	else if (cat_update && tag_update)
		to_update += cat_update+" "+andor+tag_update;
	else
		to_update += term_update+cat_update+tag_update;		// Since two of these are blank, only one will show
	return to_update+".</p>";
}

// The paged variable here is ONLY for preserving paged information on FIRST PAGE LOAD. It won't be used any other time
function jsearchUpdateEnglish()
{
	found = 0;			// We don't want to print anything at all if there's nothing to say. This variable tracks that		
	to_update = "";			// Build a string to update all at once
	term_update = cat_update = tag_update = "";
	if (term_any.length || cat_any.length || tag_any.length)
	{
		to_update += "a result will have to  ";
		if (term_any.length) term_update = "have at least one of these keywords: <b>"+term_any+"</b>";
		if (cat_any.length) cat_update = "be in one of these categories: <b>"+jsearchIDsToNames("cat","any")+"</b>";
		if (tag_any.length) tag_update = "be tagged with any of these tags: <b>"+jsearchIDsToNames("tag","any")+"</b>";
		
		to_update += jsearchMakeSentence(term_update,cat_update,tag_update,"and ");	
		found = 1;		
	}
	if (term_all.length || cat_all.length || tag_all.length)
	{
		term_update = cat_update = tag_update = "";
		if (found)
			to_update += "<p>They will also ";
		else
			to_update += "a result will have to  ";
		if (term_all.length) term_update = "contain ALL of these keywords: <b>"+term_all+"</b>";
		if (cat_all.length) cat_update = "be filed in ALL of these categories: <b>"+jsearchIDsToNames("cat","all")+"</b>";
		if (tag_all.length) tag_update = "have ALL of these tags: <b>"+jsearchIDsToNames("tag","all")+"</b>";
		
		to_update += jsearchMakeSentence(term_update,cat_update,tag_update,"and ");	
		found = 1;		
	}
	if (term_none.length || cat_none.length || tag_none.length)
	{
		term_update = cat_update = tag_update = "";
		if (found)
			to_update += "<p>But, results CAN NOT ";
		else
			to_update += "a result CAN NOT  ";
		if (term_none.length) term_update = "have any these keywords: <b>"+term_none+"</b>";
		if (cat_none.length) cat_update = "be in any of these categories: <b>"+jsearchIDsToNames("cat","none")+"</b>";
		if (tag_none.length) tag_update = "be tagged with any of these tags: <b>"+jsearchIDsToNames("tag","none")+"</b>";
		
		to_update += jsearchMakeSentence(term_update,cat_update,tag_update,"or ");	
		found = 1;		
	}
	
	$jsq("#jsearch_english").html("Base on how your search is configured "+to_update);
}

//*************************
// INPUT CLEANER STUFF
//*************************

//**
//*
//*  Javascript trim, ltrim, rtrim
//*  http://www.webtoolkit.info/
//*
//**
 
function jsearchTrim(str, chars) {
	return jsearchLtrim(jsearchRtrim(str, chars), chars);
}
 
function jsearchLtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function jsearchRtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function getSelectedOption(name)
{
	return $jsq("#"+name).val();
}


// Used because I was always having to check to see if there were already vars before adding more. This just helps
function jsearchAddVars(url,vars)
{
	if (url.indexOf('?')==-1)
		return url+"?"+vars;
	else
		return url+"&"+vars;
}

function jsearchURL()
{
	vars = jsearchVars();
	var_string = "";
	for (var_name in vars)
	{
		var_string += var_name+"="+vars[var_name]+"&";
	}
	return jsearchAddVars(jsearchTargetPage,var_string);
}

function jsearchVars()
{
	var vars = {};

	// Terms
	if (term_any.length)	// We have some
		vars['term_any'] = term_any.toString(); 
	if (term_all.length)	// We have some
		vars['term_all'] = term_all.toString(); 
	if (term_none.length)	// We have some
		vars['term_none'] = term_none.toString(); 


	if (onJsearchPage)		// If we're not on the jsearch page, don't look for these.
	{
		// The different stuff we can search with the terms
		if ($jsq('#jsearch_search_titles').attr('checked')) vars['search_titles'] = "1";
		else vars['search_titles'] = "0";
		if ($jsq('#jsearch_search_content').attr('checked')) vars['search_content'] = "1";
		else vars['search_content'] = "0";
		if ($jsq('#jsearch_search_excerpts').attr('checked')) vars['search_excerpts'] = "1";
		else vars['search_excerpts'] = "0";
		if ($jsq('#jsearch_search_custom').attr('checked')) vars['search_custom'] = "1";
		else vars['search_custom'] = "0";
		if ($jsq('#jsearch_search_comments').attr('checked')) vars['search_comments'] = "1";
		else vars['search_comments'] = "0";


		vars['jsearch_hide_adder'] = ($jsq('#jsearch_items_adder_table').is(":visible")) ? 0 : 1;		// If the options are open, leave them open.
		vars['jsearch_hide_added'] = ($jsq('#jsearch_items_added_table').is(":visible")) ? 0 : 1;		// If the options are open, leave them open.
		vars['jsearch_hide_options'] = ($jsq('#jsearch_options_table').is(":visible")) ? 0 : 1;			// If the options are open, leave them open.
		
		// OPTIONS
		vars['ppp'] = $jsq('#jsearch_ppp_input').val();
		vars['ppall'] = $jsq('#jsearch_ppall_input').val();
		vars['tefull'] = $jsq('#jsearch_tefull_input').val();
		vars['order'] = $jsq('#jsearch_order_input').val();
		vars['results_type'] = $jsq('#jsearch_results_type').val();			// What type of results display do we want?
		vars['jsearch_sdate_year'] = $jsq('#jsearch_sdate_year').val();
		vars['jsearch_sdate_month'] = $jsq('#jsearch_sdate_month').val();
		vars['jsearch_sdate_day'] = $jsq('#jsearch_sdate_day').val();
		vars['jsearch_edate_year'] = $jsq('#jsearch_edate_year').val();
		vars['jsearch_edate_month'] = $jsq('#jsearch_edate_month').val();
		vars['jsearch_edate_day'] = $jsq('#jsearch_edate_day').val();
	}
	
	// Categories	
	if (cat_any.length)	// We have some
		vars['cat_any'] = cat_any.toString(); 
	if (cat_all.length)	// We have some
		vars['cat_all'] = cat_all.toString(); 
	if (cat_none.length)	// We have some
		vars['cat_none'] = cat_none.toString(); 
	
	// Tags	
	if ($jsq('#jsearch_tag_filter').val()) vars['tag_filter'] = $jsq('#jsearch_tag_filter').val();
	if (tag_any.length)	// We have some
		vars['tag_any'] = tag_any.toString(); 
	if (tag_all.length)	// We have some
		vars['tag_all'] = tag_all.toString(); 
	if (tag_none.length)	// We have some
		vars['tag_none'] = tag_none.toString();
		
//	vars['control_vis'] = jsearchControlVis;

	return vars;
}
