<!--
// Search Wizard Scripts

// Image Preloading
Image1 = new Image();
Image1.src = "images/search_wizard/btn_back_over.gif";
Image2 = new Image();
Image2.src = "images/search_wizard/btn_next_over.gif";
Image3 = new Image();
Image3.src = "images/search_wizard/btn_back.gif";
Image4 = new Image();
Image4.src = "images/search_wizard/btn_next.gif";

function submitWizard(dir) {
	
	rExp = /jump/gi;
	var searchTerm = dir;
	
	if (dir == 'back') {
		// Go to previous page
		var dirBox = document.getElementById('dir');
		dirBox.value = 'back';
		
	} else if (searchTerm.search(rExp) == 0) {
		var dirBox = document.getElementById('dir');
		dirBox.value = dir;
	}
	
	document.forms[1].submit();
}

// Search form lists to narrow searching options
function listSearch(pattern_text, list) {
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  pattern = new RegExp(pattern_text,"i");

  if (!list.bak){
    /*
    Attach an array to the select object
    to keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }
  
  if (pattern_text.length < 2)
  {
      list.length = 0;
      for (n=0;n<list.bak.length;n++){

        list.options[n] = new Option(list.bak[n][1], list.bak[n][0]);
      }
      return 1;
  }

  /*
  Iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
    if(pattern.test(list.bak[n][1])){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }
  /*
  Completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  if (match.length > 0)
  {
      list.length = match.length;
      for (n=0;n<match.length;n++){
        list[n].value = match[n][0];
        list[n].text = match[n][1];
      }
  }
  else
  {
      list.length = 0;
  }

  /*
  Make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}

// Add/Remove ALL Classifications with checkbox
function addAllClassifications() {
	var classificationBoxes = document.getElementsByName('classification');
	var totalBoxes = classificationBoxes.length;
	var checkAllBox = document.getElementById("classification['all']");

	if (checkAllBox.checked == true) {
		// Check All
		var checkedValue = true;
	} else {
		var checkedValue = false;
	}
	
	for (x=0; x < 99; x++) {
		// Check all boxes
		if (document.getElementById('classification['+x+']')) {
			if (document.getElementById('classification['+x+']').disabled != true) {
				document.getElementById('classification['+x+']').checked = checkedValue;
			}
		}
	}
}

function hidify_showify(e_table, e_img, alt_less, alt_more) {
   if(document.getElementById) {
      var id_table = document.getElementById(e_table).style;
      var id_img = document.getElementById(e_img);

      //Set the object to table-cell if the browser is
      //Firefox and block if it's anything else.
      if(navigator.userAgent.indexOf("Firefox") != -1){
         if(id_table.display == "table-cell") {
            id_table.display = "none";
            id_img.src = "images/content/btn-search-view.jpg";
            id_img.alt = alt_more;
         }
         else {
            id_table.display = "table-cell";
            id_img.src = "images/content/btn-search-close.jpg";
            id_img.alt = alt_less;
         }
      }
      else {
         if(id_table.display == "block") {
            id_table.display = "none";
            id_img.src = "images/content/btn-search-view.jpg";
            id_img.alt = alt_more;
         }
         else {
            id_table.display = "block";
            id_img.src = "images/content/btn-search-close.jpg";
            id_img.alt = alt_less;
         }
      }
	  refreshThis();
      return false;
   }
   else {
      return true;
   }
}

function setCheckboxes(thisId,x,y) {
	if (thisId == "all") {
		var thisUnavail = "classification['"+thisId+"']";
		
	} else if (y != -1) {
		var thisUnavail = 'classification['+y+']';
	
	} else {
		var thisUnavail = 'null';
	}

	// Disable (0) boxes
	if (thisUnavail != 'null') {
		if (thisId != "all" && thisId != "avail" && thisId) {
			// alert('unavail: '+thisUnavail);
			
			document.getElementById(thisUnavail).checked = false;
			document.getElementById(thisUnavail).disabled = true;
			
		} else if (thisId == "avail") {
			// alert('avail: '+thisUnavail);
			document.getElementById(thisUnavail).disabled = false;
		
		} else {
			// alert('null: '+x+' | '+thisUnavail+' | '+thisId);
		}
	}
}


var searchOpen = false;
function expandSearch() {
	
	if (searchOpen == false) {
		
		var wizardObject = document.getElementById('wizardFormBlock');
		
		if (wizardObject.style.display == 'none') {
			// wizardObject.style.display = 'block';
			
		} else {
			// wizardObject.style.display = 'none';
		}
		searchOpen = true;
	}
	
	// Update Checkbox Values to Match Selection
	var permBox = document.getElementById('permanent');
	var tempBox = document.getElementById('temporary');
	
	var showFull = document.getElementsByName('catFull');
	var showPerm = document.getElementsByName('catPerm');
	var showTemp = document.getElementsByName('catTemp');
	
	if (permBox.checked == true && tempBox.checked != true) {
		// Show Perm
		for (x=0; x < (showPerm.length); x++) {
			
			showFull[x].style.display = 'none';
			showPerm[x].style.display = 'inline';
			showTemp[x].style.display = 'none';
			
			var y = (x-1);
			var thisId = showPerm[x].id;
			setCheckboxes(thisId,x,y);
		}
		
	} else if (tempBox.checked == true && permBox.checked != true) {
		// Show Temp
		for (x=0; x < showTemp.length; x++) {
			// alert('temp: '+x);
			showFull[x].style.display = 'none';
			showPerm[x].style.display = 'none';
			showTemp[x].style.display = 'inline';
			
			var y = (x-1);
			var thisId = showTemp[x].id;
			setCheckboxes(thisId,x,y);
		}
		
	} else {
		// Show Full
		for (x=0; x < showFull.length; x++) {
			// alert('full: '+x);
			showFull[x].style.display = 'inline';
			showPerm[x].style.display = 'none';
			showTemp[x].style.display = 'none';
			
			var y = (x-1);
			var thisId = showFull[x].id;
			setCheckboxes(thisId,x,y);
		}
	}
}

function searchCategoryBegin() {
	var permBox = document.getElementById('permanent');
	var tempBox = document.getElementById('temporary');
	
	if (permBox.checked == true || tempBox.checked == true) {
		expandSearch();
	
	} else {
		// Check for selected categories
		for (x=0; x <= 7; x++) {
			var classBox = document.getElementById('classification['+x+']');
			
			if (classBox.checked == true) {
				expandSearch();
			}
		}
	}
}

function selectSearchStatus() {
	var thisStatus = document.getElementById('statusSearch');
	var thisPage = window.location+"";
	
	if (thisPage.indexOf("&status=")) {
		// thisPage = "http://employment.gov.bc.ca/?p=Search_Wizard";
		thisPage = window.location;
		thisPage = new String(thisPage);
		thisPage = thisPage.replace(/&status=postings_draft/g,"");
		thisPage = thisPage.replace(/&status=postings_live/g,"");
		thisPage = thisPage.replace(/&status=postings_archive/g,"");
	}
	
	if (thisStatus.value) {
		window.location.replace(thisPage+"&status="+thisStatus.value);
	}
}
-->