	// From http://c82.net/samples/checklist-basic.html
	
	//
	// Variables
	//
		var tlj_debug				= true;
		var tlj_debug_message		= "";
		var str_keywordText			= "Keywords...";
		var str_optionAllText			= "All";
		var str_optionAnyText			= "Any";
		var str_optionAllIndustryText	= "All Sectors";
		var str_optionAllLanguageText	= "All Languages";
		var str_optionAllLocationText	= "All Locations";
	//
	// OPTIONS: Following array contains all the options for the array form
	//
		var job_search_options_array 			= new Array ( );
		job_search_options_array["languages"]		= new Array ( );
		job_search_options_array["sectors"]		= new Array ( );
		job_search_options_array["locations"]		= new Array ( );
		job_search_options_array["salary_range"]	= new Array ( );
		job_search_options_array["emptype"]		= new Array ( );
	//
	// SUBMIT DATA: Following array contains all the data to submit
	//
		var job_search_criteria_array			= new Array ( );
		job_search_criteria_array["languages"]		= new Array ( );
		job_search_criteria_array["sectors"]		= new Array ( );
		job_search_criteria_array["locations"]		= new Array ( );
		job_search_criteria_array["salary_range"]	= new Array ( );
		job_search_criteria_array["emptype"]		= new Array ( );
		job_search_criteria_array["keywords"]		= " ";
	
	
	
	//
	// SINGLE SELECT FORM
	//
		var singleselectforms_skeleton_top		=	"";
		singleselectforms_skeleton_top			+=	"<select name=\"%type%[]\" id=\"sidebar_search_%type%_options\"  style=\"width: 200px;\">\n";
		var singleselectforms_skeleton_content		=	"";
		singleselectforms_skeleton_content		+=	"	<option value=\"%value%\">%text%\n";
		var singleselectforms_skeleton_end	=	"";
		singleselectforms_skeleton_end			+=	"</select>\n";
		singleselectforms_skeleton_end			+=	"<a href=\"\" onClick=\"JavaScript: turn_single_select_into_multiselect ( '%type%' ); return false;\" ><img src=\"/templates/tlj_v2/images/plus.gif\" /></a>\n";
		
		
		
	
	//
	// MULTI SELECT FORM
	//
		var multiselectforms_skeleton_top		=	"";
		multiselectforms_skeleton_top			+=	"<ul class=\"checklist\" >\n";
		var multiselectforms_skeleton_content		=	"";
		multiselectforms_skeleton_content		+=	"	<li >\n";
		multiselectforms_skeleton_content		+=	"		<label for=\"o-%type%-%id%\">\n";
		multiselectforms_skeleton_content		+=	"			<input id=\"o-%type%-%id%\" name=\"%type%[]\" type=\"checkbox\" value=\"%value%\" onClick=\"JavaScript: update_selectionList ('%type%');\" /> %text%\n";
		multiselectforms_skeleton_content		+=	"		</label>\n";
		multiselectforms_skeleton_content		+=	"	</li>\n";
			var multiselectforms_skeleton_content_special		=	"";
			multiselectforms_skeleton_content_special		+=	"	<li >\n";
// 			multiselectforms_skeleton_content_special		+=	"		<label for=\"o-%type%-%id%\">\n";
			multiselectforms_skeleton_content_special		+=	"			<div id=\"o-%type%-%id%\" >%text%</div>\n";
// 			multiselectforms_skeleton_content_special		+=	"		</label>\n";

//  			multiselectforms_skeleton_content_special		+=	"		<label for=\"o-%type%-%id%\">\n";
// 			multiselectforms_skeleton_content_special		+=	"			<div id=\"o-%type%-%id%\" >></div%text%\n";
//  			multiselectforms_skeleton_content_special		+=	"		</label>\n";

			multiselectforms_skeleton_content_special		+=	"	</li>\n";
		var multiselectforms_skeleton_end	=	"";
		multiselectforms_skeleton_end			+=	"</ul>\n";
		multiselectforms_skeleton_end			+=	"<div class=\"chosenlist\" id=\"chosenlist_%type%\" style=\"background: #bababa;font-size: .7em;\" >\n";
		multiselectforms_skeleton_end			+=	"</div>\n";
	
	
	
	//
	// Function swaps the keywords in the input box, depending on highlighting and content
	//
	//
	function swapKeywordText ( param_obj, keyword_text ) {
		if( param_obj.value == keyword_text ) {
			param_obj.style.color = "black";
			param_obj.value = "";
			return true;
		} else if( param_obj.value == "" ) {
			param_obj.style.color = "grey";
			param_obj.value = keyword_text;
			return true;
		}
		return false;
	}
	
	
	//Function only removes keywords at the moment
	function submit_sidebar_search_form ( param_formId ) {
		// Check to see if anything is specified
 		var something_modified = true;
 		var temp_obj;
		temp_obj = document.getElementById ( "search_string" );
		//if ( temp_obj.value != "" && temp_obj.value != "Keywords..." ) {
		if ( temp_obj.value != "" && temp_obj.value != get_keywordText ( ) ) {
			something_modified = true;
		}
		//if ( temp_obj.value == "Keywords..." ) {
		if ( temp_obj.value == get_keywordText ( ) ) {
			temp_obj.value = "";
		}
		temp_obj = null;
		temp_obj = document.getElementById ( param_formId );
		temp_obj.submit ( );
		return ( true );
	}
	
	function clear_sidebar_search_form ( ) {
		//turn_multi_select_into_singleselect ( "languages" );
		//turn_multi_select_into_singleselect ( "sectors" );
		//turn_multi_select_into_singleselect ( "locations" );
		//turn_multi_select_into_singleselect ( "emptype" );
		clear_to_default_option ( "languages", "0", "option" );
		clear_to_default_option ( "sectors", "0", "option" );
		clear_to_default_option ( "locations", "0", "option" );
		clear_to_default_option ( "salary", "0", "option" );
		clear_to_default_option ( "emptype", "0", "option"  );
		clear_to_default_option ( "search_string", "Keywords...", "input"  );
		//clear_to_default_option ( "search_string", get_keywordText ( ), "input"  );
		temp_obj = document.getElementById ( "search_string" );
		temp_obj.style.color = 'gray';
		return ( false );		// don't submit
	}
	
	function checkall(checkname,thestate){
		var el_collection=document.getElementsByName( checkname );
		for (c=0;c<el_collection.length;c++)
		el_collection[c].checked=thestate;
	}
	
	function hasOptions(obj) {
		if (obj!=null && obj.options!=null) { return true; }
		return false;
	}
	
	function selectAllOptions(selectid, thestate) {
		var obj=document.getElementById(selectid);
		if (!hasOptions(obj)) { return; }
		for (var i=0; i<obj.options.length; i++) {
			obj.options[i].selected = thestate;
		}
	}
	
	function clear_search_form() {
		checkall( 'sectors[]', false );
		checkall(  'languages[]', false );
		selectAllOptions( 'location', false );
		selectAllOptions( 'emptype', false );
		selectAllOptions( 'salary_band', false );
		keywords = document.getElementById( 'strongtextinput' );
		keywords.value = '';
	}
	
	function clear_to_default_option ( param_id, param_value, param_type ) {
		switch ( param_type ) {
			case "option" :
				var temp_obj = document.getElementById ( "sidebar_search_" + param_id + "_options" );
				temp_length = temp_obj.length;
				for ( temp_i = 0; temp_i < temp_length; temp_i++ ) {
					if ( temp_obj.options[temp_i].value == param_value ) {
						temp_obj.selectedIndex = temp_i;
						break;
					}
				}
				return ( true );
				break;
			case "input" :
				temp_obj = document.getElementById ( "search_string" );
				temp_obj.value = param_value;
				return ( true );
				break;
			default :
				return ( false );
		}
	}
	
	
	function turn_single_select_into_multiselect ( param_obj ) {
		// get div item
		var temp_var = document.getElementById ( "sidebar_search_" + param_obj + "_options" );
		// get currently selected option
		var temp_selectedIndex = temp_var.selectedIndex;
		if ( temp_selectedIndex > 0 ) {
			// if currently selected object is anything above the default 0, then store that
			var temp_selectedValue = temp_var.options[temp_selectedIndex].value;
		}
		temp_var = null;
		// now grab the container object
		temp_var = document.getElementById ( "sb_" + param_obj + "_container" );
		var temp_content = poplate_content_with ( param_obj, "multi" );
		if ( false === temp_content ) {
			return false;
		}
		// create the content for the multi-select
		temp_string_skel_end = multiselectforms_skeleton_end.replace( /%type%/g, param_obj );
		temp_var.innerHTML = multiselectforms_skeleton_top + temp_content + temp_string_skel_end;
		initChecklist ( );
		// if any option was previously set, set it now
		if ( temp_selectedValue ) {
			set_selectedMultiOption ( param_obj, temp_selectedValue );
		}
		
		update_selectionList( param_obj );
		return true;
	}
	
	function turn_multi_select_into_singleselect ( param_obj ) {
		var temp_var = document.getElementById ( "sb_" + param_obj + "_container" );
		var temp_content = poplate_content_with ( param_obj, "single" );
		if ( false === temp_content ) {
			return false;
		}
		temp_string_skel_top = singleselectforms_skeleton_top.replace( /%type%/g, param_obj );
		temp_string_skel_end = singleselectforms_skeleton_end.replace( /%type%/g, param_obj );
		switch ( param_obj ) {
			case "languages" :
				var temp_firstChar = param_obj.substring ( 0, 1 );
				temp_firstChar = temp_firstChar.toUpperCase ( );
				var temp_restOfString = param_obj.substring ( 1, param_obj.length );
				//temp_string_skel_top += "<option value=\"0\" selected />All " + temp_firstChar + temp_restOfString + "\n";
				//alert ( "a. " + temp_firstChar + temp_restOfString );
				//alert ( get_optionAllLanguageText ( ) );
				temp_string_skel_top += "<option value=\"0\" selected />" + get_optionAllLanguageText ( ) + "\n";
				break;
			case "sectors" :
				var temp_firstChar = param_obj.substring ( 0, 1 );
				temp_firstChar = temp_firstChar.toUpperCase ( );
				var temp_restOfString = param_obj.substring ( 1, param_obj.length );
				//temp_string_skel_top += "<option value=\"0\" selected />All " + temp_firstChar + temp_restOfString + "\n";
				//alert ( "b. " + temp_firstChar + temp_restOfString );
				//alert ( get_optionAllIndustryText ( ) );
				temp_string_skel_top += "<option value=\"0\" selected />" + get_optionAllIndustryText ( ) + "\n";
				break;
			case "locations" :
				var temp_firstChar = param_obj.substring ( 0, 1 );
				temp_firstChar = temp_firstChar.toUpperCase ( );
				var temp_restOfString = param_obj.substring ( 1, param_obj.length );
				//temp_string_skel_top += "<option value=\"0\" selected />All " + temp_firstChar + temp_restOfString + "\n";
				temp_string_skel_top += "<option value=\"0\" selected />" + get_optionAllLocationText ( ) + "\n";
				//alert ( "c. " + temp_firstChar + temp_restOfString );
				//alert ( get_optionAllLocationText ( ) );
				//alert ( "hi " + get_optionAllLocationText );
				break;
			default :
				//temp_string_skel_top += "<option value=\"0\" selected />Any\n";
				temp_string_skel_top += "<option value=\"0\" selected />" + get_optionAnyText ( ) + "\n";
				break;
		}
		temp_var.innerHTML = temp_string_skel_top + temp_content + temp_string_skel_end;
		return true;
	}
	
	function change_optionAllIndustryText ( param_str_text ) {
		//alert ( str_optionAllIndustryText );
		str_optionAllIndustryText	= param_str_text;
		//alert ( str_optionAllIndustryText );
		//alert ( get_optionAllIndustryText ( ) );
	}
	function change_optionAllLanguageText ( param_str_text ) {
		str_optionAllLanguageText	= param_str_text;
	}
	function change_optionAllLocationText ( param_str_text ) {
		str_optionAllLocationText	= param_str_text;
	}
	//
	function change_optionAnyText ( param_str_text ) {
		str_optionAnyText	= param_str_text;
	}
	function change_keywordText ( param_str_text ) {
		str_keywordText		= param_str_text;
	}
	//
	function get_optionAllIndustryText ( ) {
		return str_optionAllIndustryText;
	}
	function get_optionAllLanguageText ( ) {
		return str_optionAllLanguageText;
	}
	function get_optionAllLocationText ( ) {
		return str_optionAllLocationText;
	}
	//
	function get_optionAnyText ( ) {
		return str_optionAnyText;
	}
	function get_keywordText ( ) {
		return str_keywordText;
	}
	
	
	function poplate_content_with ( param_obj, param_type ) {
		var temp_string = "";
		var temp_final_string = "";
		var temp_arrayLen = job_search_options_array[param_obj].length;
		for ( temp_i=0; temp_i< temp_arrayLen; temp_i++) {
			switch ( param_type ) {
				case "multi" :
					if ( job_search_options_array[param_obj][temp_i][1] != 0 ) {
						temp_string = multiselectforms_skeleton_content.replace( /%id%/g, temp_i );
						temp_string = temp_string.replace( /%value%/g, job_search_options_array[param_obj][temp_i][1] );
						tmp_split = job_search_options_array[param_obj][temp_i][1];
						tmp_split_arr = tmp_split.split ( "-" );
						if ( tmp_split_arr[1] == "country" ) {
							temp_string = temp_string.replace( /%text%/g, "<b >" + job_search_options_array[param_obj][temp_i][0] + "</b>" );
						} else {
							temp_string = temp_string.replace( /%text%/g, job_search_options_array[param_obj][temp_i][0] );
						}
						temp_string = temp_string.replace( /%type%/g, param_obj );
						temp_final_string += temp_string;
					} else {
						temp_string = multiselectforms_skeleton_content_special.replace( /%id%/g, temp_i );
						temp_string = temp_string.replace( /%value%/g, job_search_options_array[param_obj][temp_i][1] );
						temp_string = temp_string.replace( /%text%/g, "<b >" + job_search_options_array[param_obj][temp_i][0] + "</b>" );
						temp_string = temp_string.replace( /%type%/g, param_obj );
						temp_final_string += temp_string;
					}
					break;
				case "single" :
					temp_string = singleselectforms_skeleton_content.replace( /%id%/g, temp_i );
					temp_string = temp_string.replace( /%value%/g, job_search_options_array[param_obj][temp_i][1] );
					temp_string = temp_string.replace( /%text%/g, job_search_options_array[param_obj][temp_i][0] );
					temp_string = temp_string.replace( /%type%/g, param_obj );
					temp_final_string += temp_string;
					break;
				default :
					return false;
					break;
			}
		}
		return temp_final_string;
	}
	
	function populate_options_data ( param_type, param_text, param_value ) {
		tlj_debug_message = "Function [populate_options_data] in [sidebar_search.js] :\n";
		if ( job_search_options_array[param_type] && param_text && param_value ) {
			job_search_options_array[param_type].push( new Array( param_text, param_value ) );
			return true;
		}
		tlj_debug_message += "Invalid parameters\n";
		tlj_debug_message += "- param_type = " + param_type.toString() + "\n";
		tlj_debug_message += "- param_text = " + param_text.toString() + "\n";
		tlj_debug_message += "- param_value = " + param_value.toString();
		if ( tlj_debug === true )
			alert( tlj_debug_message.toString ( ) );
		return false;
	}
	
	function set_selectedOption ( param_type, param_value ) {
		var temp_var;
		// first lets check to see if our select box is expanded into the multiselect, because then its different logic
		temp_var = document.getElementById ( "o-" + param_type + "-0" );
		if ( !temp_var ) {
			// its just a standard select dropdown
			temp_var = document.getElementById ( "sidebar_search_" + param_type + "_options" );
			var temp_i = 0;
			var safe_limit = 1000;
			while ( temp_var.options[temp_i] ) {
				if ( temp_var.options[temp_i].value == param_value ) {
					temp_var.selectedIndex = temp_i;
					break;
				}
				temp_i++;
				// safe limit exists only because i'd hate to get calls from people saying that for some reason they are
				// getting browser hangs, for some unforeseen reason
				if ( temp_i > safe_limit ) { break; }
			}
			return true;
		} else {
			return true;
		}
		
	}
	
	
	function set_selectedMultiOption ( param_type, param_value ) {
		//alert ( param_value.toString() );
		var temp_var;
		// first lets check to see if our select box is expanded into the multiselect, because then its different logic
		temp_var = document.getElementById ( "o-" + param_type + "-0" );
		if ( temp_var ) {
			// its justa standard select dropdown
			var temp_i = 0;
			var safe_limit = 1000;
			while ( temp_var = document.getElementById ( "o-" + param_type + "-" + temp_i.toString() ) ) {
				if ( temp_var.value == param_value ) {
					temp_var.checked = "true";
					break;
				}
				temp_i++;
				// safe limit exists only because i'd hate to get calls from people saying that for some reason they are
				// getting browser hangs, for some unforeseen reason
				if ( temp_i > safe_limit ) { break; }
			}
			return true;
		} else {
			return true;
		}
		
	}
	
	
	function update_selectionList ( param_obj ) {
		var temp_obj = document.getElementById ( "chosenlist_" + param_obj );
		var temp_var = document.getElementById ( "o-" + param_obj + "-0" );
		var temp_outputInnerHTML = "";
		if ( !temp_var ) {
			// single option, do nothing
			return false;
		} else {
			var temp_i = 0;
			var safe_limit = 1000;
			while ( temp_var = document.getElementById ( "o-" + param_obj + "-" + temp_i.toString() ) ) {
				if ( temp_var.checked == true ) {
					var nextSiblingLocation = temp_var.nextSibling.nodeValue;
					nextSiblingLocation = trim ( nextSiblingLocation );
					if ( nextSiblingLocation == "" ) {
						nextSiblingLocation = temp_var.nextSibling.nextSibling.childNodes[0].nodeValue;
					}
					temp_outputInnerHTML += nextSiblingLocation + " <a href=\"\" style=\"color: red;\" onclick=\"JavaScript: return remove_itemFromMultiSelection ('" + param_obj + "', '" + temp_i.toString() + "' );\">X</a><br />";
				}
				temp_i++;
				// safe limit exists only because i'd hate to get calls from people saying that for some reason they are
				// getting browser hangs, for some unforeseen reason
				if ( temp_i > safe_limit ) { break; }
			}
			
			temp_obj.innerHTML = temp_outputInnerHTML;
			return true;
		}
		return true;
	}
	
	
	
	function remove_itemFromMultiSelection ( param_obj, param_value ) {
		var temp_var = document.getElementById ( "o-" + param_obj + "-" + param_value.toString() );
		temp_var.checked = false;
		update_selectionList ( param_obj );
		return false;
	}
	
	function update_searchString ( param_string ) {
		var temp_var = document.getElementById ( "search_string" );
		temp_var.value = param_string;
	}
	
	
	function trim ( inputString ) {
		// Removes leading and trailing spaces from the passed string. Also removes
		// consecutive spaces and replaces it with one space. If something besides
		// a string is passed in (null, custom object, etc.) then return the input.
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		while (ch == " ") { // Check for spaces at the beginning of the string
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		while (ch == " ") { // Check for spaces at the end of the string
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		}
		return retValue; // Return the trimmed string back to the user
	} // Ends the "trim" function
