// ============================================================================= 
// Handling Timezone actions. 
// Relies on http.js
// ============================================================================= 

// The ASP script will dump out something similar to the
// following in the head of the HTML document. These variable
// define the target script.

/*
<script type="text/javascript">
var timezones = Array();
timezones["areas"]=[httpObject(), "/ww/public/timezoneoptions.asp"];
</script>
*/

// html objects: 
// <select name='selTimezoneRegion'>...
// <div id='dTimezoneArea'> [<select name='timezone'>... ]
// selTimezoneRegion, dTimezoneArea
//
// Attach an event to selTimezoneRegion - when a change occurs
// make an ajax call to update the innerHTML select options of
// dTimezoneArea.

var TIMEZONEHTTP = 0;
var TIMEZONEURL  = 1;

function timezoneInit(areaHTMLID) {
  var selRegion = document.getElementById("selTimezoneRegion");

  // Attach Events
  if (document.attachEvent) {
    // IE
    if (selRegion) { selRegion.attachEvent("onchange", function () { 
		    selectRegion(event.srcElement.value, areaHTMLID);
		    }); }
  } else {
    // Other
    if (selRegion) { selRegion.addEventListener("change", function () { 
		    selectRegion(this.value, areaHTMLID); }, false); }
  }  
}

function selectRegion(region, areaHTMLID) {
  var timezone = timezones["areas"];
  var s = "setAreaOptions()";
  var handler = function(){eval(s)};
  httpContent(timezone[TIMEZONEHTTP], timezone[TIMEZONEURL] + "?region=" + region + "&htmlID=" + areaHTMLID, handler);
}

function setAreaOptions() {
  if (timezones["areas"][TIMEZONEHTTP].readyState == 4) {
    var dArea = document.getElementById("dTimezoneArea");
    if (dArea) {
      dArea.innerHTML = timezones["areas"][TIMEZONEHTTP].responseText;
    }
  }
}
