// To open a popup window
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// Zonal time calculator script

//Detect Browser Type.
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
  is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
  is_major = parseInt(is_minor);
}
var isMinNS4 = ((navigator.appName.indexOf("Netscape") >= 0 || agt.indexOf("gecko") >= 0) && is_major >= 4) ? true : false;
var isMinNS6 = (agt.indexOf("gecko") >=0 && is_major >= 5) ? true : false;
var isMinIE4 = (document.all) ? true : false;
var isMinIE5 = (isMinIE4==1 && is_major >= 5) ? true : false;
var isMinIE6 = (isMinIE4 && is_major >= 6) ? true : false;
var isDOM = (document.getElementById) ? true : false;
var isSafari = (agt.indexOf("safari") != -1) ? true : false
var isOpera = (agt.indexOf("opera") != -1) ? true : false
var isIE = (isMinIE4 || isMinIE5 ||  isMinIE6);
var isNN = (isMinNS4 || isMinNS6 );

dstZones = new Array ();

qReport = new Array ();

TableTimes = new Array();

var Local = new Date();

var GMToffset = Local.getTimezoneOffset();
	
if (!(navigator.appName.charAt(0) == "M" && navigator.appVersion.charAt(0)==3))  {

		if (GMToffset < 0) {GMToffset = Math.abs(GMToffset)}

		else {GMToffset = GMToffset - (Math.abs(GMToffset) *2)};

};
	
function qHandler(ZoneData) {

	qReport[0] = ""; qReport[1] = ""; qReport[2] = ""; qReport[3] = "";	



	var qGMTparse = parseFloat(ZoneData);

	var qGMToffset_hrs = parseInt(qGMTparse, 10) ; 

	var qGMToffset_min= parseInt ( Math.round((qGMTparse-qGMToffset_hrs) * 100), 10);

	var qDSTperiod = ZoneData.charAt (ZoneData.length - 1);

	var qGMTperiod = 1440/60;

	if ( (qGMToffset_hrs > 12) || (qGMToffset_hrs <-11) ) {qReport[0] = "BAD DATA"; return};

	if (qDSTperiod > dstZones.length) {qReport[3] = "BAD DATA"};



	var relGMT = (qGMToffset_hrs * 60) + qGMToffset_min; 

	if (qDSTperiod>1 && dstZones [qDSTperiod]) {relGMT += 60; qReport[3] = "Yes (+1 hour)"} else {qReport[3] = "No"};

	if (qDSTperiod == 0) {qReport[3] = "n/a"};

	if (qDSTperiod == 1) {qReport[3] = "uncertain"};



	var qPlaceTotMins = GMTnow (qPlaceTotMins);

	qPlaceTotMins += relGMT; 

	qPlaceTotMins = Into24hrs (qPlaceTotMins);

	qReport[0] = qPlaceTotMins;



	qReport[2] = formatOffset (relGMT);



	var relLoc = relGMT - GMToffset;

	qReport[1] = formatOffset (relLoc);

	}	

function formatOffset (time) {

	var Report = null;

	var Direction  = (time > 0) ? " ahead" : " behind";

	time = Math.abs (time);

	var Hours = Math.floor (time/60);

	var Mins = (time - Hours * 60);

	Report = Hours + "h ";

	if (Mins != 0) {Report=Report+Mins + "m "};

	Report = Report+ Direction;

	if (time== 0) {Report="Same Time"};

	return Report;

	};
	
	function formatTime (time) {

	var fHours = Math.floor (time/60) ;

	if (fHours <= 9) {fHours = "0" + fHours}; 

	var fMins = time - (fHours * 60);

	if (fMins <= 9) {fMins = "0" + fMins}; 

	var fTime = fHours + ":" + fMins;

	return fTime;

	}
	
	function Into24hrs (time) {

	if ( time > 1440)

		{ time -= 1440}

	else

		{ if ( time <0) { time = 1440 + time } };

	return time;

	}
	
	function GMTnow (GMT) {

	var time = new Date();

	hrs = time.getHours();

	mins = time.getMinutes();

	secs = time.getSeconds();

	GMT = (hrs*60 + mins) - GMToffset;

	GMT = Into24hrs(GMT);

	return GMT;

	}
	
	function qReply (ZoneData) {

	currentQuery = ZoneData;

	qHandler (ZoneData);

	return formatTime(qReport[0]);

	}	
	
	function showTime()
	{
		if(!isIE)
		{
			document.getElementById('usTime').textContent = qReply('-5%2')
			document.getElementById('indTime').textContent = qReply('5.30%0')
			document.getElementById('ukTime').textContent = qReply('0%3')
		} else {
			document.getElementById('usTime').innerText = qReply('-5%2')
			document.getElementById('indTime').innerText = qReply('5.30%0')
			document.getElementById('ukTime').innerText = qReply('0%3')			
		}
		
		st = window.setTimeout("showTime();",1000);
	}