var autoDisableFilters=true;
function tfPageLoaded(){
 	typeChanged();
}
// different accomo types enable/disable some of the oterh sarc params
function typeChanged(){
    var elTypeSelect = document.forms[0].type;

    if (elTypeSelect){
        var typeVal = elTypeSelect.options[elTypeSelect.selectedIndex].value;
        var firstChars=typeVal.substr(0,3);
        var elSleeps = document.forms[0].sleeps;

        if (firstChars=='SC-' || firstChars=='B-B' || firstChars=='C-H' ){     
          // Self cater, B&B & Country House enables Sleeps input
         	 if (elSleeps){
             	elSleeps.value = '';
		 	elSleeps.disabled = false;
		 }
        }
	   else{   // Non-Self caterins DISABLES Sleeps input
         	 if (elSleeps){
             	elSleeps.value = '';
		 	elSleeps.disabled = true;
		}
    	   }

		  /*
	   var elVegMeals = document.forms[0].vegMeals;
	   if (elVegMeals){
	        if (firstChars=='*' || firstChars=='B-B' || firstChars=='C-H'|| firstChars=='HOT' ){
	           // B&B, Country House & Hotels enables Veg Meals input
	         	 elVegMeals.value = false;
			 elVegMeals.disabled = false;
	        }
		   else{   // Non-Self caterins DISABLES Sleeps input
	         	 elVegMeals.checked = false;
			 elVegMeals.disabled = true;
	    	   }
		}
		*/
	}
}
function countryChanged( ){	// Also called on form load to set filters
     var arGeoRegions;
     var elCountrySelect = document.forms[0].country;
	var elRegionSelect = document.forms[0].region;
	var elCountySelect = document.forms[0].county;
     var elGeoRegionSelect = document.forms[0].geoRegion;

	var countryVal = elCountrySelect.options[elCountrySelect.selectedIndex].value;

	// Clear county select
	if (elCountySelect) elCountySelect.options.length=0
	// Get new county array

	if(countryVal == '*'){     // All countries
		 if (elGeoRegionSelect){
			 elGeoRegionSelect.selectedIndex = 0;    // Set region = All regions
			 elGeoRegionSelect.disabled = true;      // Disable Regions
		 }
		 if (elRegionSelect){
			 elRegionSelect.selectedIndex = 0;    // Set region = All regions
			 elRegionSelect.disabled = true;      // Disable Regions
		 }
		 if (elCountySelect){
		 	elCountySelect.selectedIndex = 0;    // Disable Counties
		 	elCountySelect.disabled = true;      // Set county = All Counties
		 }
 	}
	else if(countryVal == 'United Kingdom'){     // UK
       	if (elGeoRegionSelect){
       		var arGeoRegions =  arAllGeoRegions[countryVal].split(",");
			elGeoRegionSelect.disabled = false;	// Enable regions
			elGeoRegionSelect.options.length=0;    // Clear region select
		}

		if (elRegionSelect){
       		if(arAllRegions[countryVal]) arRegions =  arAllRegions[countryVal].split(",");
			elRegionSelect.disabled = false;	// Enable regions
			elRegionSelect.options.length=0;    // Clear region select
		}
		if (elCountySelect){
       		var arCounties =  arAllCounties[countryVal].split(",");
			elCountySelect.disabled = false;	// Enable regions
			elCountySelect.options.length=0;    // Clear region select
		}
 	}
	else{          // Non-UK
       	if (elGeoRegionSelect){
       		var arGeoRegions =  arAllGeoRegions[countryVal].split(",");
			elGeoRegionSelect.disabled = false;	// Enable regions
			elGeoRegionSelect.options.length=0;    // Clear region select

		}
		if (elRegionSelect){
       		var arRegions =  arAllRegions[countryVal].split(",");
			elRegionSelect.disabled = false;	// Enable regions
			elRegionSelect.options.length=0;    // Clear region select
		}
		if (elCountySelect){
	          var arCounties =  arAllCounties[countryVal].split(",");
			elCountySelect.options.length=0;    // Clear region select
			elCountySelect.disabled = true;	// Disable  regions
		}

	}
	if (elGeoRegionSelect){
	  	for(i=0;i<arGeoRegions.length;i++) {
	       key = (i==0)? '*' : arGeoRegions[i];
	       val=arGeoRegions[i];
	       if (val) elGeoRegionSelect.options[i]=new Option(val, key, true, false)
	  	}
	}

	if(arRegions){
	     for(i=0;i<arRegions.length;i++) {
	       key = (i==0)? '*' : arRegions[i];
	       val=arRegions[i];
	       if (val) elRegionSelect.options[i]=new Option(val, key, true, false)
	  	}
 	}

	if (arCounties){
	  	for(i=0;i<arCounties.length;i++) {
	       key = (i==0)? '*' : arCounties[i];
	       val=arCounties[i];
	       if (val) elCountySelect.options[i]=new Option(val, key, true, false)
	  	}
 	}

}
function geoRegionChanged( ){
  	// If region is selected disable counties
  	var elRegionSelect = document.forms[0].region;
	var elGeoRegionSelect = document.forms[0].geoRegion;
	var elCountySelect = document.forms[0].county;

	var geoRegionVal = elGeoRegionSelect.options[elGeoRegionSelect.selectedIndex].value;

	if(geoRegionVal=='*'){     // All Regions
		 elCountySelect.selectedIndex = 0;    // Select All Counties
		 if (autoDisableFilters) elCountySelect.disabled = false;      // Enable counties
		 elRegionSelect.selectedIndex = 0;    // Select All  Regions
           if (autoDisableFilters) elRegionSelect.disabled = false;      // Enable Regions
 	}
	else{
		elCountySelect.selectedIndex=0    // Select All Counties
		if (autoDisableFilters) elCountySelect.disabled = true;	// Disable counties
		elRegionSelect.selectedIndex = 0;    // Select All  Regions
		if (autoDisableFilters) elRegionSelect.disabled = true;      // Disable Regions
	}
}

function regionChanged( ){

  	// If region is selected disable counties
	var elRegionSelect = document.forms[0].region;
	var elCountySelect = document.forms[0].county;
     var elGeoRegionSelect = document.forms[0].geoRegion;
	var regionVal = elRegionSelect.options[elRegionSelect.selectedIndex].value;

	if(regionVal=='*'){     // All Regions

		 if (autoDisableFilters) elCountySelect.disabled = false;      // Enable counties
		 elCountySelect.selectedIndex = 0;    // Select All Counties
		 if (elGeoRegionSelect){
			 elGeoRegionSelect.selectedIndex = 0;    // Select All Geo Regions
			 if (autoDisableFilters) elGeoRegionSelect.disabled = false;      // Enable Geo Regions
   }
 	}
	else{

		elCountySelect.selectedIndex=0    // Select All Counties
		if (autoDisableFilters) elCountySelect.disabled = true;	// Disable counties
		if (elGeoRegionSelect){
			elGeoRegionSelect.selectedIndex = 0;    // Select All Geo Regions
			if (autoDisableFilters) elGeoRegionSelect.disabled = true;      // Disable Geo Regions
  		}
	}
}
function countyChanged( ){
  	// If region is selected disable counties
	elRegionSelect = document.forms[0].region;
	elCountySelect = document.forms[0].county;
     elGeoRegionSelect = document.forms[0].geoRegion;
	var countyVal = elCountySelect.options[elCountySelect.selectedIndex].value;

	if(countyVal=='*'){     // All Regions
		 if (autoDisableFilters) elRegionSelect.disabled = false;      // Enable counties
		 elRegionSelect.selectedIndex = 0;    // Select All Counties
	      if (elGeoRegionSelect){
			 if (autoDisableFilters) elGeoRegionSelect.disabled = false;      // Enable Geo Regions
			 elGeoRegionSelect.selectedIndex = 0;    // Select All Geo Regions
 	 	   }
	 }
	else{
		elRegionSelect.selectedIndex=0    // Select All Counties
		if (autoDisableFilters) elRegionSelect.disabled = true;	// Disable counties
		if (elGeoRegionSelect){
			if (autoDisableFilters) elGeoRegionSelect.disabled = true;      // Disable Geo Regions
			 elGeoRegionSelect.selectedIndex = 0;    // Select All Geo Regions
		}
	}
}

function checkBoxClick(el){
    	offElName =   el.name + '_off';
    	offEl =  xbGetElement(window, offElName);
	if (offEl){	
       	if ( ! el.checked) offEl.value =1;
  		else offEl.value =0;
 	} 	
}

 function tfLocalMapSBClick(ptrText){
 	alert('GoogleMap Pointer Text...\n' + ptrText);
	return(false);
 }
