var newWindow = null;
var timehnd = null;

function hideMenu()
{
	for (i in menuObj) 
	{
		if(menuObj[i].style)
		{
			menuObj[i].style.display = 'none';
		}
	}
	document.getElementById('iframe').style.display = 'none';
	//alert('s');
	//document.getElementById('countrylistbox').style.visibility = 'visible';	
}

function showMenu(obj, id)
{	
	p = findPos(obj);
	l = p[0];
	t = p[1];
	hideMenu();
	m = document.getElementById('menu' + id);
	if(m != null)
	{
		m.style.display = 'block';	
		b = findPos(document.getElementById('menu_m'+id));
		m.style.left = b[0] + 'px';
		m.style.top = b[1] + 27 + 'px';
		//MenuOverTimer();
		mp = findPos(m);
		iframeObj = document.getElementById('iframe');
		iframeObj.style.left = m.style.left;
		iframeObj.style.top = m.style.top;
		iframeObj.style.width = m.offsetWidth;
		iframeObj.style.height = m.offsetHeight;
		iframeObj.style.display = 'block';			
	}
}  

function isOverlay(a,b)
{
	aw = a[0] + a[2];
	ah = a[1] + a[3];
	bw = b[0] + b[2];
	bh = b[1] + b[3];
	if(b[0] >= a[0] && b[0] <= aw && b[1] >= a[1] && b[1] <= ah) return 1;
	if(bw >= a[0] && bw <= aw && bh >= a[1] && bh <= ah) return 1;
	if(bw >= a[0] && bw <= aw && b[1] >= a[1] && b[1] <= ah) return 1;
	if(b[0] >= a[0] && b[0] <= aw && bh >= a[1] && bh <= ah) return 1;
	if(b[0] + (b[2] / 2) >= a[0] && b[0] + (b[2] / 2) <= aw && b[1] + (b[3] / 2) >= a[1] && b[1] + (b[3]/2) <= ah) return 1;
	
	return 0;
}

function MenuOutTimer()
{
  timehnd = setTimeout("hideMenu();", 700);
}

function MenuOverTimer()
{	
	clearTimeout(timehnd);
  if(timehnd) {
  	
  	//alert(timehnd);
    
    //timehnd = null;
  }
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	leftVal = (screen.width - strWidth ) / 2;
	topVal = (screen.height - strHeight) / 2;	
	
	var tools="";	
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left="+leftVal+",top="+topVal+"";
	if (type == "scroll") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left="+leftVal+",top="+topVal+"";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}