//<?
function ValidateMemberBookNow(form)
   {
   if (form.double_click.value == "Yes")
      {
      alert("Warning: You have clicked the 'Booking' button twice.\nThis will send two requests to the server and result in a slower response.\nFor optimum performance, please press all buttons in the booking system only once.");
      return false;
      }

   form.double_click.value = "Yes";
   return true;
   }

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
                                    'MSXML2.XMLHTTP.5.0',
                                    'MSXML2.XMLHTTP.4.0',
                                    'MSXML2.XMLHTTP.3.0',
                                    'MSXML2.XMLHTTP',
                                    'Microsoft.XMLHTTP');
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}


var serverdate;
var tickCount = 0;
var ticker;

function padlength(what){
	var output=(what.toString().length==1)? '0'+what : what
	return output
}

function displaytime(){
	tickCount++;
	if (tickCount == 3600) tickCount = 1;
	if (tickCount == 1) {
		//get time from server
		// proceed only if the xmlHttp object isn't busy and our call hasn't been cancelled
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
			clearInterval(ticker);
			
			url = "gettime.php?tzOffset=" + tzOffset;
			//alert(url);
			xmlHttp.open("GET", url, true);  
			xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
			// define the method to handle server responses
			xmlHttp.onreadystatechange = gotTime;
			// make the server request
			xmlHttp.send(null);
		  
		} else {
			//try next time
			tickCount = 0;
			doTick();
		}
	
	} else {
		doTick();
	}	
}   

function gotTime() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
	    	serverdate = new Date(xmlHttp.responseText);
	    	//alert(xmlHttp.responseText);
	    	showTime();
		} else {
			// do a tick to cater for delay approximate delay, time will correct when connection ok again
			doTick();
		}
		//restart the ticker even after an error
		ticker = setInterval('displaytime()', 1000)
	}
}

function doTick() {
	serverdate.setSeconds(serverdate.getSeconds()+1)
	showTime();
}

function showTime() {
	var timestring=padlength(serverdate.getHours())+':'+padlength(serverdate.getMinutes())+':'+padlength(serverdate.getSeconds())
	document.getElementById('servertime').innerHTML=timestring
}
//?>
