window.onload = function () {
	var x = document.getElementsByTagName('a');
	for (var i=0; i < x.length; i++) {
		if (x[i].className == 'link') {
			x[i].onmouseover = activate;
			x[i].onmouseout = deactivate;
		}
	}
	function checkTime(i)
	{
		if (i<10)
		{
			i="0" + i;
		}
		return i;
	}

	var now = new Date();
	var mm = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "11");
	var d = new Date();
	var dd = d.getDate();
	var curr_month = d.getMonth();
	var yy = d.getFullYear();
	var h = now.getHours();
	var m = now.getMinutes();


	var pathname = window.location.pathname;
	var element = pathname.split("/"); 
    if ((yy == element[3] && mm[curr_month] == element[4] && dd == element[5]) || x.length == "52")
	{
	var i=1;
	$('#timetable_tr td').each(function()
	{
		
		var a = parseInt($(this).html().substring(0,2));
		var b = parseInt($(this).html().substring(3,5));
		if (h >= a)
		{
			if (typeof(hh)=='undefined' || hh===null)
			{
				ida = i;
				hh = a;
			}
			else if (a >= hh)
			{
					ida = i;
					hh = a;
			}
		}
		i++;
	}); 
	var i=1;
	$('#timetable_tr td').each(function()
	{
		if (i == ida)
		{
			//$(this).css('background', 'red');
		}
		i++;
	});
	}
	var country = document.getElementById('country');
	country.onchange = update;

	var city = document.getElementById('city');	
	city.onchange = submit;
}

function activate (e) {
	if (!e) var e = window.event;
	if (e.target) {
		var tg = e.target;
	}
	else if (e.srcElement) {
		var tg = e.srcElement;
	}

	var x = tg.id.split('-')[1];
	var img = document.getElementById('cntry-' + x);
	img.style.display = 'block';
}

function deactivate (e) {
	if (!e) var e = window.event;
	if (e.target) {
		var tg = e.target;
	}
	else if (e.srcElement) {
		var tg = e.srcElement;
	}

	var x = tg.id.split('-')[1];
	var img = document.getElementById('cntry-' + x);
	img.style.display = 'none';
}

function update (e) {
	if (!e) var e = window.event;
	if (e.target) {
		var tg = e.target;
	}
	else if (e.srcElement) {
		var tg = e.srcElement;
	}

	var city = document.getElementById('city');

	clear(city);

	for (var i = 1; i < cities[tg.value].length; i++) {
		if (cities[tg.value][i]) {
			var opt = document.createElement('OPTION');
			opt.setAttribute('value',i);
			var opText = document.createTextNode(cities[tg.value][i]);
			opt.appendChild(opText);
			city.appendChild(opt);
		}
	}
}

function submit (e) {
	var city = document.getElementById('city');
	city.form.submit();
}

function clear (select) {
	while (select.firstChild) {
		if (select.firstChild.value == -1) {
			var tmp = select.firstChild;
		}
		select.removeChild(select.firstChild);
	}
	select.appendChild(tmp);
}

function newWin (url, w, h) {
	l = (screen.availWidth-10 - w) / 2;
	t = (screen.availHeight-20 - h) / 2;
	
	features = "width="+w+",height="+h+",left="+l+",top="+t;
	features += ",screenX="+l+",screenY="+t;
	features += ",scrollbars=0,resizable=0,location=0";
	features += ",menubar=0,toolbar=0,status=0";

	window.open(url, null, features);
}

function blink_header (header,color1,color2) {
  if (header.currentStyle) {
    if (header.currentStyle['color'] == color1) {
      header.style.color = color2;
    }
    else {
      header.style.color = color1;
    }
  }
}
