var zoneCountry = 
{ 
  '0:0'   : {en:'London GMT', fa:'لندن'},
  '1:0'   : {en:'Rome', fa:'رم'},
  '2:0'   : {en:'Cairo', fa:'قاهره'},
  '3:0'   : {en:'Mecca', fa:'مكه'},
  '3:30'  : {en:'Tehran', fa:'تهران'},
  '4:0'   : {en:'Dubai', fa:'دبي'},
  '4:30'  : {en:'Kabul', fa:'كابل'},
  '5:0'   : {en:'Karachi', fa:'كراچي'},
  '7:0'   : {en:'Bangkok', fa:'بانكوك'},
  '8:0'   : {en:'Hong Kong', fa:'هنگ كنگ'},
  '9:0'   : {en:'Tokyo', fa:'توكيو'},
  '10:0'  : {en:'Sydney', fa:'سيدني'},
  '-10:0' : {en:'Hawaii', fa:'هاوايي'},
  '-8:0'  : {en:'San Francisco', fa:'سانفرانسيسكو'},
  '-7:0'  : {en:'Arizona', fa:'آريزونا'},
  '-5:0'  : {en:'New York', fa:'نيويورك'}
}
zone 	   = 0;
isitlocal  = false;
clockTimer = '';

function createPopUp(html) {
	var div = document.getElementById('clockContainer');
	if (div.style.visibility == 'hidden') {
		div.style.visibility = 'visible';
	}
	div.innerHTML = html;
}

function ClockAndAssign(){
	document.getElementById('clockImg').onclick = '';
	var html = '<div id="myDiv" class="popUp"><table class="tbl" border="0" width="150" cellspacing="1" cellpadding="3">';
	html     += '<tr><td colspan="2" align="right"><span onclick="closePopUp()" class="popupToolBar">X</span></td></tr>';
	i = 0;
	for(c in zoneCountry) {
		zoneArray = c.split(':');
		
		zone = parseInt(zoneArray[0]);
		zone2 = (zone < 0) ? parseInt(zoneArray[1])*-1 : parseInt(zoneArray[1]);
		now  = new Date();
		oo   = now.getTimezoneOffset()/60;
		ofst = parseInt(oo);
		ofst2 = (parseFloat(oo) - ofst)*60;
		secs = now.getSeconds();
		mins = now.getMinutes();
		hr   = (isitlocal)?now.getHours():(now.getHours() + ofst) + zone;
		mins   = mins + ofst2 + zone2;
		if (hr < 0) hr+=24;
		if (mins < 0) mins+=60;
		if (hr > 23) hr-=24;
		if (mins > 60) mins-=60;
		ampm = (hr > 11)?"PM":"AM";
		statusampm = ampm.toLowerCase();
		
		hr2 = hr;
		if (hr2 == 0) hr2=12;
		(hr2 < 13)?hr2:hr2 %= 12;
		var Q1=hr2+':'+((mins < 10)?"0"+mins:mins)+':'+((secs < 10)?"0"+secs:secs)+' '+statusampm;
		bgColor = (i%2 == 0) ? '#D1DFEF' : '#FFFFFF';
		html += '<tr bgcolor="'+bgColor+'"><td>'+Q1+'</td><td align="right">'+zoneCountry[c]['fa']+'</td></tr>';
		i++;
	}
	html += '<table></div>';
	createPopUp(html);
	clockTimer = setTimeout('ClockAndAssign()', 1000);
}

function closePopUp() {
	//document.body.removeChild(document.body.lastChild);
	document.getElementById('clockImg').onclick = ClockAndAssign;
	document.getElementById('clockContainer').style.visibility = 'hidden';
	clearTimeout(clockTimer);
}

