﻿var varversion = 2;
var vardomain = "jobs.seek.com.au";	
var varcountry = "aus";

// JScript source code
function AddItemToDropDownAt(dropdown, text, value, index) {
	var opt = new Option(text, value, true, true);
	AddOptionAt(dropdown, opt, index);
}
function AddOptionAt(ctl, opt, index) {
	for (j=ctl.options.length; j >= index; j--) {
		if (j > 0) {
			var movedOpt = new Option(ctl.options[j-1].text, ctl.options[j-1].value)
			ctl.options[j] = movedOpt;
		}
	}
	ctl.options[index] = opt
}
					  
function GetObjectByPartName(name)
{
var obj; // string which is return referencing object by element id
var elementnumber; 
var elementname;

		//Go through the forms collection
		for (var i= 0; i < document.forms[0].length; i++)
		{
			elementname = document.forms[0].elements[i].name.toString();
		
			// if the object name passed equals the object name in the form collection - return it's number
			if (elementname.indexOf(name) != -1)
				{
				elementnumber = i;
				obj = document.forms[0].elements[i]
				break;
				}
		}
			
			// create the string which can be used to reference this object and return it could be used for Net 4.7
			//obj = "document.forms[0].elements[" + elementnumber + "]";
	
	return obj;
}

var aCatSelected = new Array(0);
var aDefaultOverrides = new Array(0);



//Gets the query string
function GetQueryString()
{
	var formItems = new Array();
	var formKeys = new Array();
	var myURL = document.URL;
	// Get the query string
	var startQs = myURL.indexOf('?',0);	
	if (startQs >=0)
	{
		var qs = myURL.substring(startQs+1);
		var items = qs.split('&');
		var keyIdx = 0;
		for(var idx=0; idx < items.length; idx++)
		{
			var tmpItem = items[idx].split('=');
			if(formItems[tmpItem[0]] == null)
			{
				formKeys[keyIdx++] = tmpItem[0];
				formItems[tmpItem[0]] = tmpItem[1];
			}
			else
			{
				formItems[tmpItem[0]] =  formItems[tmpItem[0]] + ',' + tmpItem[1];
			}
		}
	}
	return new Array(formKeys,formItems);
}
// Gets the Form element with the name speciifed
function GetFormElementByName(fName)
{
	var formItems = GetQueryString();
	var formValue = formItems[1][fName];
	if(formValue != null)
		return  SafeDecodeURL(formItems[1][fName]);
	else
		return null;
}

function GetPageURLNoQuery()
{
	var pIdx = document.URL.indexOf('?');
	
	if(pIdx >= 0)
	{
		return  document.URL.substring(0, pIdx);
	}
	else
	{
		return document.URL;
	}
}	
	


	function getItemValue(catId, catIdx)
	{
		switch(catId)
		{
		case 'location':
		{
			return document.forms[0].catlocation.options[catIdx].value;
		}
		case 'area':
		{
			return document.forms[0].catarea.options[catIdx].value;
		}
		case 'worktype':
		{
			return document.forms[0].catworktype.options[catIdx].value;
		}
		}
   }

		var submitCounter = 0;

	var aCategories = new Array(6);

	var childBehaviours = new Array();

	var categoryNames = new Array();

	var defaultIndexes = new Array();

	var isSorted = new Array();

	var categorySelections = new Array();

	var parentChildRelationships = new Array();

	parentChildRelationships["state"] = "location";

	var aLocationItems = new Array(6);
	aLocationItems[0] = new Array("Location", 0 );
	aLocationItems[1] = new Array("Sydney", 1000 );
	aLocationItems[2] = new Array("NSW - Other", 1001 );
	aLocationItems[3] = new Array("Melbourne", 1002 );
	aLocationItems[4] = new Array("VIC - Other", 1003 );
	aLocationItems[5] = new Array("Hobart", 1011);    
	aLocationItems[6] = new Array("TAS - Other", 1012);

	aCategories["location"] = aLocationItems;

	categoryNames[categoryNames.length] = "location";
	defaultIndexes["location"] = 0;
	isSorted["location"] = false;
	categorySelections["location"] = new Array();
	childBehaviours["location"] = new Array("ShowDirectChildren","ShowDirectChildren","AggregateChild");

	parentChildRelationships["location"] = "area";

	var aAreaItems = new Array(22);
	aAreaItems[0] = new Array("Ballarat", 2757 );
	aAreaItems[1] = new Array("Bendigo", 2759 );
	aAreaItems[2] = new Array("Geelong", 2769 );
	aAreaItems[3] = new Array("Melbourne - East", 2784 );
	aAreaItems[4] = new Array("Melbourne - Inner", 2785 );
	aAreaItems[5] = new Array("Melbourne - North", 2786 );
	aAreaItems[6] = new Array("Melbourne - South", 2787 );
	aAreaItems[7] = new Array("Melbourne - West", 2788 );
	aAreaItems[8] = new Array("Mildura", 2789 );
	aAreaItems[9] = new Array("Shepparton", 2817 );
	aAreaItems[10] = new Array("Warrnambool", 2830 );
	aAreaItems[11] = new Array("Rest of VIC", 2811 );
	aAreaItems[12] = new Array("Burnie", 2763 );
	aAreaItems[13] = new Array("Devonport", 2766  );
	aAreaItems[14] = new Array("Launceston", 2777  );
	aAreaItems[15] = new Array("Rest of TAS", 2810  );
	aAreaItems[16] = new Array("Wollongong", 2834 );
	aAreaItems[17] = new Array("Albury - Wodonga", 2751 );
	aAreaItems[18] = new Array("Sydney - Inner", 2819 );
	aAreaItems[19] = new Array("Sydney - North", 2820 );
	aAreaItems[20] = new Array("Sydney - South", 2821 );
	aAreaItems[21] = new Array("Sydney - West", 2822 );
	aAreaItems[22] = new Array("Sydney - Newcastle", 2795 );

	aCategories["area"] = aAreaItems;

	categoryNames[categoryNames.length] = "area";
	defaultIndexes["area"] = 0;
	isSorted["area"] = true;
	categorySelections["area"] = new Array();
	childBehaviours["area"] = new Array("ShowDirectChildren","ShowDirectChildren","ShowDirectChildren");

	var aWorktypeItems = new Array(4);
	aWorktypeItems[0] = new Array("Any", 0 );
	aWorktypeItems[1] = new Array("Full Time", 242 );
	aWorktypeItems[2] = new Array("Part Time", 243 );
	aWorktypeItems[3] = new Array("Contract/Temp", 244 );
	aWorktypeItems[4] = new Array("Casual/Vacation", 245 );

	aCategories["worktype"] = aWorktypeItems;

	categoryNames[categoryNames.length] = "worktype";
	defaultIndexes["worktype"] = 0;
	isSorted["worktype"] = false;
	categorySelections["worktype"] = new Array();
	childBehaviours["worktype"] = new Array("ShowDirectChildren","ShowDirectChildren","ShowDirectChildren");

	var aRelationShips  = new Array(3);

	var aLocationChildItems = new Array(1);
	aLocationChildItems[1000] = new Array(18,19,20,21,22);
	aLocationChildItems[1001] = new Array(17,16);
	aLocationChildItems[1003] = new Array(10,9,11,8,2,1,0);
	aLocationChildItems[1002] = new Array(7,6,5,4,3);
	aLocationChildItems[1011] = new Array(0);
	aLocationChildItems[1012] = new Array(12,13,14,15);
	aLocationChildItems[0] = new Array(17,7,6,5,4,3,10,9,18,19,20,21,11,8,2,1,0,12,13,14,15,16);
	
	aRelationShips["location"] = 	aLocationChildItems;
			
		function ValidateCategoryList(categoryId, maxItems, childCategoryId,populateChildren)
		{
			var defIdx = defaultIndexes[categoryId];
			var ddl = document.getElementById('cat' + categoryId);
			var chk = GetObjectByPartName('chkUnspecified' + categoryId);

			// Now validate that Any is not selected with other values
			var anyOption = ddl.options[0];

			getItemValue(categoryId,0);

			if(getItemValue(categoryId,0) == 0 &&  anyOption.selected)
			{
				for(var idx = 1; idx < ddl.options.length; idx++)
				{
					if(ddl.options[idx].selected)
					{
						anyOption.selected = false;						
						break;
					}
				}
			}

			// If the 'Any' option was selected, disabled the respective 
			// 'Include' checkbox.
			if(chk != null)
			{
				if(!anyOption.selected)
				{
					if(chk.disabled)
						chk.checked = true;
				}
				else
					chk.checked = false;
				
				chk.disabled = anyOption.selected;				
			}

			// Validate Max Items if required
			if(maxItems > 0)
			{
				var selectedIdx  = ddl.selectedIndex;

				if(ddl != null)
				{
					var removeIdx = 0;
					var removeOptions = new Array();
				
					var selected = 0;
					for(idx = 0; idx < ddl.options.length; idx++)
					{
						if(ddl.options[idx].selected)
						{
							if(selected > maxItems)
							{
								removeOptions[removeIdx++] = idx;
							}
							selected++;
						}
					}
					if(selected > maxItems)
					{
						alert('Only ' + maxItems + ' items may be selected for category ' + categoryId );
						
						for(rIdx = 0; rIdx < removeOptions.length; rIdx++)
						{
							ddl.options[removeOptions[rIdx]].selected = false;
						}
						populateChildren = false; // Don't continue populating
					}
				}
			}		

			if(populateChildren) // If we are cascading population events ...
			{
				aCatSelected['cat' + childCategoryId] = new Array(); //Clear out the old values

				ProcessChildList(categoryId,childCategoryId);

			}

			var cat = GetObjectByPartName('cat' + categoryId)
			cat.focus();
			
		}

	function populateClassiferList(ddListId, catID)
	{
		var ddl = document.getElementById(ddListId);
		var classifers = aCategories[catID];
		var defIdx = defaultIndexes[catID];
		var forceDefaultZero = (aDefaultOverrides[catID] != null);
		var defaults = new Array(); // defaults always at top
		var nonDefSelected = false;
		var ItemIndex = 0;
		var sorted = isSorted[catID];
		var selections = new Array();
		var defSelections = new Array();

		if(forceDefaultZero)
			defIdx = 0;
		
		if(ddl != null)
		{
			var sortArray = new Array();
			var sortIndex = 0;

			for(idx =0; idx < classifers.length; idx++)
			{	
				var isSelected = false;
				var classifier = classifers[idx];
				var opt = new Option(classifier[0],classifier[1]);

				if(opt.value == 0) // deal with std default
				{	if(defIdx == 0){
						//opt.selected=true;
						defSelections['OPT_' + opt.value ] = true;
					}
					else
					{	
						defSelections['OPT_' + opt.value ] = false;
					}
					defaults[0] = opt; 
				}	
				else
				{
					var selectedItems = aCatSelected['cat' + catID];

					if(selectedItems != null && selectedItems.length > 0)
					{
						for(sIdx =0; sIdx < selectedItems.length; sIdx++)
						{
							if(selectedItems[sIdx] == classifier[1])
							{
								//opt.selected = true;
								isSelected = true;
								if(idx != defIdx)
								{
									nonDefSelected=true;
								}
								break;
							}
						}
					}
					else
					{
						if(idx == defIdx)
						{
							//opt.selected = true;
							selections['OPT_'+ opt.value] = true;
							isSelected = true;
						}
					}
					if(idx != defIdx){
						sortArray[ItemIndex++] = opt;
						selections['OPT_'+ opt.value] = isSelected;
					}
					else
					{
						var def = defaults.length;
						defaults[def] = opt; 
						defSelections['OPT_'+ opt.value] = isSelected; 
					}	
				}
			}
			
			if(sorted) //only sort those that need it
				sortArray.sort(sortCategory);

			var finalList = new Array();

			// Add defaults
			for(var d = 0; d < defaults.length; d++)
			{
				if(nonDefSelected && defaults[d].value == '0')
				{			
					selections['OPT_'+ defaults[d].value] = false;
				}
				else
				{
					selections['OPT_'+ defaults[d].value] = defSelections['OPT_'+ defaults[d].value];
				}
				finalList[finalList.length] = defaults[d];
			}

			for(var i =0; i < sortArray.length; i++)
			{
				finalList[finalList.length] = sortArray[i];
			}

			finalList = removeDuplicates(finalList);

			for(var f =0; f < finalList.length; f++)
			{
				var selIdx = ddl.options.length;
				ddl.options[selIdx] = finalList[f];
				SelectItem(catID,selIdx,selections['OPT_'+ finalList[f].value]);
			}
			categorySelections[catID] = selections;			
		}
	}

	function removeDuplicates(arr)
	{
		var optText = '';
		for(var i =0; i<arr.length; i++)
		{
			optText = arr[i].text;
			
			if (i < (arr.length - 1))
			{
				if (optText == arr[i+1].text)
				{
					arr[i].value += ',' + arr[i+1].value;

					for(var j=i+1; j<arr.length; j++)
					{
						if (j < (arr.length - 1))
							arr[j] = arr[j+1]
					}

					arr.length = arr.length - 1;
				}
			}	
		}			
		return arr;
	}

	function isNS62()
	{
		var browserType = navigator.appName;
		var browserVer = navigator.appVersion;

		if(browserType == 'Netscape' && browserVer.indexOf('5.0') >= 0)
		{
			return true;
		}
		return false;
	}



	// Works out the current mode of operation - Multi, Single or any Select
	function ProcessChildList(parentCategoryId, childCategoryId)
	{
		var ddl = document.getElementById('cat' + parentCategoryId);
		var mode = 0; // Default. 0 = Single, 1= Multi, 2 = Any
		var anyOption = false;
		var classifers = aCategories[parentCategoryId];
	
		ddl.blur();

		if(classifers.length <= 2) // Including the any option
		{
			anyOption = true;
		}
		else{
			// Now validate that Any is not selected with other values
			anyOption = ddl.options[0].selected;
		}

		if(anyOption) // Can only be selected in isolation (Not with other items)
		{
			mode = 2;
		}
		else
		{
			var selCount = 0;
			mode = 0;
			for(var idx = 1; idx < ddl.options.length; idx++)
			{
				if(ddl.options[idx].selected)
				{
					selCount++;
					if(selCount > 1)
					{
						mode = 1;
						break;
					}
				}
			}
		}
		//window.alert('something ' + mode);
		//Process the correct Mode

		processListSelect(childBehaviours[parentCategoryId][mode],parentCategoryId,childCategoryId);

		if(parentChildRelationships[childCategoryId] != null)
		{
			ProcessChildList(childCategoryId,parentChildRelationships[childCategoryId]);
		}
	}

	// Processes the selection using the prescribed behaviour
	function processListSelect(action, parentListId, childListId)
	{
		//window.status = action + ' ' + parentListId;
		switch(action)
		{
			case 'AggregateChild':
				aggregateChildList(parentListId , childListId);
				break;
			case 'DisableChild':
				clearCategoryList(parentListId, childListId,true,'No Selection Required')
				break;
			case 'EmptyChild':
				break;
			case 'ShowDirectChildren':
			case 'Default':
			default:
				populateChildList(parentListId, childListId);
				break;
		}
	}
	// used to create dummy timeouts
	function nsFix()
	{
		window.status = '';
	}

	// Clears a Category List and then fires an 'any' event for the child list if one exists
	function clearCategoryList(parentListId, childListId, showAny, anyCopy)
	{
		var pList = document.getElementById('cat' + parentListId);
		var cList = document.getElementById('cat' + childListId);
		var defIdx = defaultIndexes[childListId];

		// Now validate that Any is not selected with other values
		var anyOption = pList.options[0];

		//pseudo: If ANY behaviour is CLEAR
		//Clear out the Child List Box
		for(var cIdx = cList.options.length -1; cIdx >= 0 ; cIdx--)
		{	
			cList.remove(cIdx);
		}

		if(showAny)
		{
			// if occupation is set to 'Any', display 'Select a Sub-Classification' 
			// in the specialisation list box.
			if(anyOption.selected && childListId == 'specialisation')
				cList.options[0] = new Option('Select a Sub-Classification',0,true,true);
			else
				cList.options[0] = new Option(anyCopy,0,true,true);
		}

		populateCheckBox(null, childListId);
	}


function populateCheckBox(selectedItems, childListId)
	{
		var chkBox = GetObjectByPartName('chkUnspecified' + childListId);

		if (selectedItems != null)
		{
			if(selectedItems.length > 0)
			{		
				if (chkBox != null)
				{
					var chkBoxValues = chkBox.value.split(',');
					for(idx=0; idx<selectedItems.length; idx++)
					{
						for(var j=0; j<chkBoxValues.length; j++)
						{
							if(selectedItems[idx] == chkBoxValues[j].value)
							{
								chkBox.disabled = false;
								chkBox.checked = true;
								break;
							}
							else
								chkBox.disabled = false;
						}
					}
				}
			}
			else
				disableCheckBox(chkBox);
		}
		else
			disableCheckBox(chkBox);
	}

	function disableCheckBox(chkBox)
	{
		if (chkBox != null)
		{
			chkBox.checked = false;
			chkBox.disabled = true;
		}
	}


	// Populates the Child With a Full (Aggregated) List of it's applicable values
	function aggregateChildList(parentListId, childListId)
	{	
		clearCategoryList(parentListId, childListId,false,'Any');
		
		
		var cList = document.getElementById('cat' + childListId);
		var defIdx = defaultIndexes[childListId];
		var classifers = aCategories[childListId];
		var anyOption = new Option('Any',0,false,false);
		var nonDefaults = 0;	
		var sortIdx = 0;
		var selectedItems = aCatSelected['cat' + childListId];
		var sortedArray = new Array();
		var defaults = new Array();
		var selections = new Array();
	
		// Check each option
		for(var classIdx =1; classIdx < classifers.length; classIdx++)
		{ 
			var cItem = classifers[classIdx];
			var newOpt = new Option(cItem[0],cItem[1]);
			var isSelected = false;

			if(selectedItems != null)
			{
				for(sIdx = 0; sIdx < selectedItems.length; sIdx++)
				{
					if(cItem[1] == selectedItems[sIdx])
					{
						newOpt.selected = true;
						isSelected = true;
						nonDefaults++;
						break;
					}
				}
			}

			selections['OPT_' + newOpt.value] = isSelected;
	
			if(newOpt.value == defIdx)
			{
				defaults[defaults.length] = newOpt;
			}
			else
			{
				sortedArray[sortIdx++] = newOpt;
			}
		}

		sortedArray.sort(sortCategory);
		// Create a new Array (NS62 workaround)
		var finalArray = new Array();

		finalArray[0] = anyOption;
		selections['OPT_' + anyOption.value] = (nonDefaults == 0 && defIdx == 0);

		for(var dIdx =0; dIdx < defaults.length; dIdx++)
		{	
			var defOpt = defaults[dIdx];
			selections['OPT_'+ defOpt.value] = (nonDefaults == 0);
			finalArray[	finalArray.length ] = defOpt;
		}

		for(var s=0; s < sortedArray.length; s++)
		{
			finalArray[	finalArray.length ] = sortedArray[s];
		}

		finalArray = removeDuplicates(finalArray);

		cList.blur();
		
		var insertAt = 0;
		for(var i =0; i < finalArray.length; i++)
		{
			insertAt = cList.options.length;
			cList.options[insertAt] = finalArray[i];

			var sel = false;
			var arrIds = finalArray[i].value.split(',');

			for(var j=0; j<arrIds.length; j++)
			{
				sel = selections['OPT_'+ arrIds[j]];
				if (sel)
					break;
			}

			SelectItem(childListId,insertAt, sel);
		}

		aCatSelected['cat' + childListId] = new Array(); // Clear out the selections

		populateCheckBox(selectedItems, childListId);
	}


function SelectItem(catId, catIdx, selected)
	{
		switch(catId)
		{
		case 'location':
		{
			document.forms[0].catlocation.options[catIdx].selected = selected;
			break;
		}
		case 'area':
		{
			document.forms[0].catarea.options[catIdx].selected = selected;
			break;
		}
		case 'worktype':
		{
			document.forms[0].catworktype.options[catIdx].selected = selected;
			break;
		}
		}
   }

	function getItemValue(catId, catIdx)
	{
		switch(catId)
		{
		case 'location':
		{
			return document.forms[0].catlocation.options[catIdx].value;
		}
		case 'area':
		{
			return document.forms[0].catarea.options[catIdx].value;
		}
		case 'worktype':
		{
			return document.forms[0].catworktype.options[catIdx].value;
		}
		}
   }


	// Populates the child list of the currently selected list (if applicable)
	// Only populates direct descendants
	function populateChildList(parentListId, childListId)
	{
		// must cater for duplicates when multi-parent items exist

		var cList = document.getElementById('cat' + childListId);
		var pList = document.getElementById('cat' + parentListId);
		var defIdx = defaultIndexes[childListId];
		var parentSelections  = new Array();
		var parentClassifications = aCategories[parentListId].length;
		// Save the currenlty selected Parent Options if applicable
		// Save the currently selected child options
		var currentSelections = new Array();

		var selections = new Array();

		var cSelIdx = 0;
		for(var cIdx =0; cIdx < cList.options.length; cIdx++)
		{
			if(cList.options[cIdx].selected)
			{
				var arrIds = cList.options[cIdx].value.split(',');

				for(var i=0; i<arrIds.length; i++)
					currentSelections[cSelIdx++] = arrIds[i];
			}
		}

		// Clear the list and show message if the item selected is a duplicate
		if (pList.options.selectedIndex >= 0)	
		{
			if (pList.options[pList.options.selectedIndex].value.split(',').length > 1)
			{
				clearCategoryList(parentListId,childListId,true,'No Selection is Required');
				return;	
			}
		}			

		// Now clear the list 
		clearCategoryList(parentListId,childListId,false,'Any');

		var aRels = aRelationShips[parentListId];
		var classifers = aCategories[childListId];
		var selectedItems = aCatSelected['cat' + childListId];
		
		var optIdx = 0;
		var selectedAll = false;
	    var anyOption = new Option('Any',0,false,false);

		if(defIdx == 0){
			anyOption.selected = true;	
			selections['OPT_'+ anyOption.value] = true;
		}

		if(aRels != null && aRels.length > 0)
		{
			var sortedArray = new Array();
			for(pIdx =1; pIdx < pList.options.length; pIdx++)
			{
				if(selectedAll)
				{
					selectedAll = false;
					break;	
				}
				var pOpt = pList.options[pIdx];
				
				if(pOpt.selected == true)
				{
					if(pOpt.value != 0) // If not ANY
					{		
						var itemRels = aRels[pOpt.value]; //PW CHange

						//window.status = pIdx;
						if(itemRels != null)
						{
							for(idx =0; idx < itemRels.length ; idx++)
							{
								var rIdx = itemRels[idx];
								var cat = classifers[rIdx];
								var opt = new Option(cat[0],cat[1]);

								if(selectedItems != null){
									for(sIdx = 0; sIdx < selectedItems.length; sIdx++)
									{
										if(opt.value == selectedItems[sIdx])
										{
											opt.selected = true;
											anyOption.selected = false;
											selections['OPT_'+ opt.value] = true;
											selections['OPT_'+ anyOption.value] = false;
										}
									}
								}

								for(var oldSelIdx = 0; oldSelIdx < currentSelections.length; oldSelIdx++)
								{
									if(opt.value == currentSelections[oldSelIdx])
									{
										opt.selected = true;
										anyOption.selected = false;

										selections['OPT_'+ opt.value] = true;
										selections['OPT_'+ anyOption.value] = false;
								
									}
								}

								var add = true; // Check for duplicates
								var optValue = 0;
								var optIndex = 0;
								for(var dupIdx=0; dupIdx < sortedArray.length; dupIdx++)
								{
									if(opt.text == sortedArray[dupIdx].text)
									{
										add = false;

										if(opt.value != sortedArray[dupIdx].value)
										{
											optValue = opt.value;
											optIndex = dupIdx;
										}
										
										break;
									}
								}

								// If the item has the same text but different ids, concatenate
								// the ids into one.
								if (optValue != 0)
								{
									sortedArray[optIndex].value += ',' + opt.value;
								}
								else
								{
									if(add)
										sortedArray[optIdx++] = opt;
								}								
							}
						}
					}
					else // IS ANY
					{
						//Clear out the search box
						clearCategoryList(parentListId,childListId,false,'Any');
						selectedAll = true;
						
					}
				}
			}

			var sorted = isSorted[childListId];
			if (sorted == null || sorted)
				sortedArray.sort(sortCategory);

			var finalArray = new Array();
			finalArray[0] = anyOption;

			for(var s=0 ; s < sortedArray.length; s++)
			{
				finalArray[finalArray.length] = sortedArray[s];
			}

			finalArray = removeDuplicates(finalArray);
	
			for(var i =0; i < finalArray.length; i++)
			{
				cList.options[cList.options.length] = finalArray[i];

				var sel = false;
				var arrIds = finalArray[i].value.split(',');

				for(var j=0; j<arrIds.length; j++)
				{
					sel = selections['OPT_'+ arrIds[j]];
					if (sel)
						break;
				}

				//SelectItem(childListId,i,sel);

			}

		}

		populateCheckBox(selectedItems, childListId);
	}


	// Custom case insensitive Sorter for option arrays
	function sortCategory(opt1, opt2)
	{
		// Expects 2 option objects
		
		if ( opt1.text.toLowerCase() == opt2.text.toLowerCase() )
			return 0;
		else if( opt1.text.toLowerCase() > opt2.text.toLowerCase())
			return 1;
		else
			return -1;
		
	}
			

	function  ValidateBeforePost()
	{
		submitCounter++;
	var listArray = new Array(6);
	var forceDefault = new Array(6);
	var minSelection = 1;
	var selectedCount = 0;
	var ctrlIdx = 0;
	var refineKw = '';
	var selectedJobs = '';
	var qString = '?';
	
	var selectedItemsList = document.forms[0].elements['chkJob'];
	var refineTextBox = document.forms[0].elements['refine'];

	if(refineTextBox != null && refineTextBox.value != '')
	{
		refineKw = refineTextBox.value;
	}

	if(selectedItemsList != null && selectedItemsList.value != '')
	{
		for (var i=0; i < selectedItemsList.length; i++)
		{
		if (selectedItemsList[i].checked)
			{
				selectedJobs += selectedItemsList[i].value;
				selectedJobs += ',';
			}
		}
	}

	var dateRangeList = document.getElementById('DateRange');
	if(dateRangeList != null){
		forceDefault[ctrlIdx]  = 0;
		listArray[ctrlIdx++] = dateRangeList;
		
	}
listArray[0] = dateRangeList;
	forceDefault[ctrlIdx]  = '0';
	listArray[ctrlIdx++] = document.getElementById('catlocation');
	forceDefault[ctrlIdx]  = '0';
	listArray[ctrlIdx++] = document.getElementById('catarea');
	forceDefault[ctrlIdx]  = '0';
	listArray[ctrlIdx++] = document.getElementById('catworktype');
	var blnlocationChecked = false;
	var chkBoxlocation = GetObjectByPartName('chkUnspecifiedlocation');
	if (chkBoxlocation != null) 
		if (!chkBoxlocation.disabled)
			blnlocationChecked = chkBoxlocation.checked;
	var blnareaChecked = false;
	var chkBoxarea = GetObjectByPartName('chkUnspecifiedarea');
	if (chkBoxarea != null) 
		if (!chkBoxarea.disabled)
			blnareaChecked = chkBoxarea.checked;
	var blnworktypeChecked = false;
	var chkBoxworktype = GetObjectByPartName('chkUnspecifiedworktype');
	if (chkBoxworktype != null) 
		if (!chkBoxworktype.disabled)
			blnworktypeChecked = chkBoxworktype.checked;

		for(var idx=0;idx < listArray.length; idx++)
		{	
			var searchableItems = '';
			var ddList = listArray[idx];
			var doForceDefault = false;
			var countedCategory = false;
			
			if(ddList == null) //suppressed categories will be null so bypass them
				continue;

			// If Category control doesnt appear (eg. Area not shown for 30 days), but
			// exists in model, then must test that control exists first.
			if (ddList != null)
			{
				for(var k=0; k < ddList.options.length; k++)
				{ 
					var sItems = 0;
					var opt = ddList.options[k];
				
					if(opt.selected && opt.value != '0' && opt.value != '999')
					{
						searchableItems += '&' + ddList.name + '=' + opt.value;
						sItems++;
					
						// for non-zero defaults ensure that any is actually reset
						if(opt.selected && forceDefault[idx] != 0 && opt.value == '0')
						{
							doForceDefault = true;
						}

						if(listArray[idx].name == 'catlocation')
							searchableItems += '&stateselected=true';
					}
					else
					{
						if(opt.selected && ddList.name == 'DateRange' && opt.value == '999')
						{
							qString += '&DateRange=999'; // add it but dont count it
						}
					
					}

					if(sItems > 0 && !countedCategory)
					{
						selectedCount++;
						countedCategory = true;
					}
				}
			}

			if(doForceDefault)
			{
				//qString += '&def' + ddList.name + '=1';
			}
			if(selectedCount > 0)
			{
				qString += searchableItems;
			}
		}
	if(blnlocationChecked)
 { 
	var chkBoxValues = chkBoxlocation.value.split(',')
	for(var j=0; j<chkBoxValues.length; j++)
		qString += '&catlocation=' + chkBoxValues[j];
 } 

	if(blnareaChecked)
 { 
	var chkBoxValues = chkBoxarea.value.split(',')
	for(var j=0; j<chkBoxValues.length; j++)
		qString += '&catarea=' + chkBoxValues[j];
 } 

	if(blnworktypeChecked)
 { 
	var chkBoxValues = chkBoxworktype.value.split(',')
	for(var j=0; j<chkBoxValues.length; j++)
		qString += '&catworktype=' + chkBoxValues[j];
 } 

		if(selectedCount < minSelection)
		{
			if (minSelection == 2)
				alert('Please select a minimum of two categories before proceeding with your search.');
			else
				alert('Please select at least one category before proceeding with your search.');
			submitCounter--;
			return false;
		}
		else
		{
			
				var page;
				var pIdx = document.URL.indexOf('?');

				if(pIdx >= 0)
				{
					page =  document.URL.substring(0, pIdx);
				}
				else
				{
					page = ('http://'+ vardomain +'/jobsearch/index.ascx');
				}
				if(refineKw != '')
				{
					qString += '&refine=' + doUriEncode(refineKw);
				}
				if(varversion != '')
				{
					qString += '&catversion=' + doUriEncode(varversion);
				}			
				
				qString += '&AdvertiserID=8083487,19952716';

				submitCounter++;
				
				var pageURL = page + qString;
				window.open(pageURL, "RDNS", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480,left = 480,top = 360");

				return false;
		}
	}

	function doUriEncode(uri)
	{
		var isOld = false;

		var bBrowser= navigator.appName;
		var bVersion = navigator.appVersion;
		var encoded = uri;

		if(bBrowser == 'Microsoft Internet Explorer')
		{
			isOld = (bVersion.indexOf('MSIE 5.0') != -1);
		}

		if(isOld)
			encoded = escape(uri);
		else
			encoded = encodeURIComponent(uri);	

		while (encoded.search('\'') != -1)
		{
			encoded = encoded.replace('\'','%27'); //encode single quotes
		}

		while (encoded.search('[\+]') != -1)
		{
			encoded = encoded.replace('+','%2B'); //encode single quotes
		}
		
		return encoded;
	}
	

