﻿
// Toggle the grey-light layer for this area on the map on and off
// to match the state of the check box
// Note the area codes are one higher than the array indexes
function toggle(location_code){
  if(document.forms.search_form.vol_location[(parseInt(location_code)-1)].checked) {
    MM_showHideLayers("loclayer_"+location_code,'','show');
  } else{
    MM_showHideLayers("loclayer_"+location_code,'','hide');
  }
}

// Set up the initial states if we've come back from a reload or refine
// Note this is called at the bottom of the page :)
function setup_toggles(){
  for (n=0; n<=25; n++){
    if (document.forms.search_form.vol_location[n].checked){
      toggle(n+1);
    }
  }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function selectLocation(index){
  document.forms.search_form.vol_location[index].click();
}

// This function sets or clears the location checkboxes.
function selectAllLocations(){
  var gohigh = document.forms.search_form.selectalllocations.checked;
  // Clear them all
  for (n=0; n<=25; n++){
    if (document.forms.search_form.vol_location[n].checked ^ gohigh){
      document.forms.search_form.vol_location[n].click();
    }
  }
}

// This function sets or clears the available times checkboxes.
function selectAllTimes(){
  var gohigh = document.forms.search_form.selectalltimes.checked;
  // Clear them all
  for (n=1; n<=21; n++){
    if (document.forms.search_form["when_"+n].checked ^ gohigh){
      document.forms.search_form["when_"+n].click();
    }
  }
}

// This function sets or clears the location checkboxes for locations in the city centre
function selectCityCentreLocations(){
  var gohigh = document.forms.search_form.selectcitycentrelocations.checked;
  // Clear them all
  if (document.forms.search_form.vol_location[3].checked ^ gohigh){
      document.forms.search_form.vol_location[3].click();
  }
if (document.forms.search_form.vol_location[5].checked ^ gohigh){
      document.forms.search_form.vol_location[5].click();
  }
if (document.forms.search_form.vol_location[13].checked ^ gohigh){
      document.forms.search_form.vol_location[13].click();
  }
if (document.forms.search_form.vol_location[14].checked ^ gohigh){
      document.forms.search_form.vol_location[14].click();
  }
if (document.forms.search_form.vol_location[16].checked ^ gohigh){
      document.forms.search_form.vol_location[16].click();
  }
if (document.forms.search_form.vol_location[17].checked ^ gohigh){
      document.forms.search_form.vol_location[17].click();
  }
}

if (document.images){
  zero_text=new Image();
  zero_text.src="img/mainmap.gif";
}

// Preload the search button images
var imageSearch1 = new Image();
imageSearch1.src = 'img/btn_search_small.gif';
var imageSearch2 = new Image();
imageSearch2.src = 'img/btn_search_small-over.gif';

function swapImage(imgName, fileName){
  if(document.images){
      document[imgName].src = fileName;
  }
}
function doSubmit(){
  if (validateSearchForm()){
    document.forms.search_form.submit();
  }
}

function validateSearchForm(){
  if(!validateTimes()){
    alert("Please choose at least one time period!");
    document.forms.search_form.when_1.focus();
    return false;
  }

//if ((document.forms.<%=form_name%>.refinesearch.value==1)){
//  if (!(document.forms.<%=form_name%>.capacity[0].checked
//      || document.forms.<%=form_name%>.capacity[1].checked
//      || document.forms.<%=form_name%>.capacity[2].checked
//      || document.forms.<%=form_name%>.capacity[3].checked) ){
//    document.forms.<%=form_name%>.capacity[0].focus();
//    alert("Please choose a capacity option.");
//    return false;
//  }
//  if (!(document.forms.<%=form_name%>.cost[0].checked
//      || document.forms.<%=form_name%>.cost[1].checked
//      || document.forms.<%=form_name%>.cost[2].checked
//      || document.forms.<%=form_name%>.cost[3].checked) ){
//    document.forms.<%=form_name%>.cost[0].focus();
//    alert("Please choose a cost option.");
//    return false;
//  }
//  if (!(document.forms.<%=form_name%>.availability_1.checked
//      || document.forms.<%=form_name%>.availability_2.checked
//      || document.forms.<%=form_name%>.availability_3.checked
//      || document.forms.<%=form_name%>.availability_4.checked) ){
//    document.forms.<%=form_name%>.availability_1.focus();
//    alert("Please indicate when you want to hold your event.");
//    return false;
//  }
//  return true;
//}else{
//  if (!(document.forms.<%=form_name%>.availability_1.checked
//      || document.forms.<%=form_name%>.availability_2.checked
//      || document.forms.<%=form_name%>.availability_3.checked
//      || document.forms.<%=form_name%>.availability_4.checked) ){
//    document.forms.<%=form_name%>.availability_1.focus();
//    alert("Please indicate when you want to hold your event.");
//    return false;
//  }
//}
return true;
}

function validateTimes(){
  for (n=1; n<=21; n++){
    if(document.forms.search_form["when_"+n].checked){
      return true;
    }
  }
  return false;
}
