var ns4 = (document.layers) ? 1 : 0;
var ie4 = (document.all) ? 1 : 0;
var std = (document.getElementById) ? 1 : 0;
var ns6 = std && !ie4;
var delayhide=0;

function hide_popup() {
  winobj = MM_findObj('popwin');
  winobj.thestyle = (winobj.style) ?  winobj.style : winobj;
  winobj.thestyle.visibility="hidden";
  return false;
}

function show_popup(dx, dy) {
  var winobj, d;  
  winobj = MM_findObj('popwin');
  if (!winobj) return true;			// process link normally
  d = MM_findObj('currentflag');
 
  winobj.thestyle = (winobj.style) ?  winobj.style : winobj;
  winobj.contentwidth=(ie4||ns6) ? winobj.offsetWidth : winobj.document.gui.document.width;
  winobj.contentheight=(ie4||ns6) ? winobj.offsetHeight : winobj.document.gui.document.height;

  if (ns4) {
      x = d.x; 
      y = d.y + d.height + top.pageYOffset;
  } else if (std) {
      x=d.offsetLeft; 
      y=d.offsetTop + d.offsetHeight;
      while (d.offsetParent) {
        d = d.offsetParent;
        x += parseInt(d.offsetLeft);
        y += parseInt(d.offsetTop);
      }
  } else {
      d = window.event.srcElement;
      x=d.offsetLeft; 
      y=d.offsetTop + d.offsetHeight;
      while (d.offsetParent) {
        d = d.offsetParent;
        x += parseInt(d.offsetLeft);
        y += parseInt(d.offsetTop);
      }
  }

  x += dx; y += dy;
  if(navigator.appName=="Netscape" && parseInt(navigator.appVersion)>4) {
    x += "px"; y += "px";
  }
  if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1) {
    x += parseInt(document.body.leftMargin); x += "px";
    y += parseInt(document.body.topMargin); y += "px";
  }

  winobj.thestyle.left = x;
  winobj.thestyle.top = y;
  winobj.thestyle.visibility="visible";
  return false;
}

function _item(ix) {
	var res, link;
	ix = ix * 3;
	link = '<a href="/' + LANG[ix + 2] + '">';
	res = '<td width="37">' + link + '<img src="/img/flags/' + LANG[ix] + '.gif" width="35" height="21" border="0"></a></td>';
	res += '<td class="item">' + link + LANG[ix + 1] + ' (' + LANG[ix + 2] + ')</a></td>';
	return res;
}

function _LocateLanguage() {
	var i, ix = 0;
	for(i = 0; i < LANG.length; i+= 3) 
		if (LANG[i + 2] == LANGID) {
			ix = i;
			break;
		}	
	return ix;
}

function generate_window(ix) {
	var txt, list, i, c;
	if (!ns4 && !ns4 && !std) return;

	list = '';
	c = LANG.length / 3;
	c = parseInt((c + 2)/ 3);
	for(i = 0; i < c; i++) {
		list += '<tr>' + _item(i);
		if ((i + c) * 3 < LANG.length) {
			list += _item(i + c);
		} 
		if ((i + 2 * c) * 3 < LANG.length) {
			list += _item(i + 2 * c);
		} 
		list += "</tr>\n";
	}

	txt = '<div id="popwin" style="z-index: 1000">' + 
		'<div id="pop_title"><table border="0" cellspacing="0" cellpadding="0" height="30" width="100%">' +
		'<tr><td width="51" align="center"><img src="/img/flags/' + LANG[ix] + '.gif" width="47" height="28"></td>'+
		'<td width="530"><strong>' + LANG[ix + 1] + ' (' + LANG[ix + 2] + ')</strong>' + 
		'</td><td width="20" align="center"><a href="#" onclick="return hide_popup();"><img src="/img/btn_close.gif" width="16" height="14" border="0"></a></td></tr>' +
		'</table></div>' +
		'<div id="pop_body"><table border="0" cellspacing="1" cellpadding="0" width="100%">' + list +
		'</table></div>' +
		'</div>';
	document.write(txt);
}

ix = _LocateLanguage();
generate_window(ix);

function display_flag() {
	document.write('<a href="#" onClick="return show_popup(-553, -28);">');
	document.write('<img src="/img/flags/' + LANG[ix] + '.gif" width="47" height="28" border="0" id="currentflag"><img src="/img/arrow_small.gif" width="10" height="28" border="0"></a>');
}
