// POPUP window
var curr_x;
var curr_y;
var curr_text;

generatePopupTag();

function scroll_browser() {
	if( navigator.appName == "Netscape") {	
		document.getElementById("id_body").style.overflow = "scroll";
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//							popup windows
/////////////////////////////////////////////////////////////////////////////////////////////////////////

var timer_pos;	//move timer
var timer_popup_close;	//close timer

function openHintPopup(w_text) {
	curr_x = 0;
	curr_y = 0;
	curr_text = w_text;

	//closePopup();
	showPopup();
	//timer_pos = setInterval("movePopup();", 500);
	timer_pos =setTimeout("movePopup();", 500)
}

function showPopup()
{
	openPopup(null);
	clearTimeout(timer_popup_close);
	timer_popup_close = setTimeout("closePopup();", 10000);
}

// 
function openPopup() {

	clearInterval(fadeout_timer1);

	var target;

	var board = document.getElementById('category1board');

	var contentpanel = document.getElementById('contentpanel1');
	contentpanel.innerHTML = curr_text;

	if( navigator.appName == "Netscape") {	
		scroll_left = window.pageXOffset;
		scroll_top = window.pageYOffset;
		inner_width = window.innerWidth;
		inner_height = window.innerHeight;
		if (window.scrollbars.visible)
		{
			scroll_left -= 20;
		}
	}else{
		scroll_left = document.body.scrollLeft;
		scroll_top = document.body.scrollTop;
		inner_width = document.body.clientWidth;
		inner_height = document.body.clientHeight;
	}

	offsetX = board.offsetWidth;
	offsetY = board.offsetHeight;

	board.style.left = curr_x + scroll_left + inner_width - offsetX + 'px';
	board.style.top = curr_y + scroll_top + inner_height - offsetY + 'px';
	
	board.style.visibility = 'visible';
	
	board.style.filter = 'alpha(opacity=100)';	//IE
	board.style.mozOpacity = 1.0;	//Firefox
	board.style.opacity = 1.0;	// Safari
}

function movePopup() {
	var board = document.getElementById('category1board');

	if (board.style.visibility == 'visible') {
		if( navigator.appName == "Netscape") {	
			scroll_left = window.pageXOffset;
			scroll_top = window.pageYOffset;
			inner_width = window.innerWidth;
			inner_height = window.innerHeight;
			if (window.scrollbars.visible)
			{
				scroll_left -= 20;
			}
		}else{
			scroll_left = document.body.scrollLeft;
			scroll_top = document.body.scrollTop;
			inner_width = document.body.clientWidth;
			inner_height = document.body.clientHeight;
		}

		offsetX = board.offsetWidth;
		offsetY = board.offsetHeight;

		board.style.left = curr_x + scroll_left + inner_width - offsetX + 'px';
		board.style.top = curr_y + scroll_top + inner_height - offsetY + 'px';
	}
}

// 
var fadeout_opacity = 70;	
var fadeout_timer1;
var fadeout_timer2;

var close_flag = false;

//
function closePopup() {
	clearInterval(timer_pos);
	clearTimeout(timer_popup_close);

	if (document.getElementById('category1board').style.visibility != "hidden" && close_flag == false)
	{
		var board = document.getElementById('category1board');
		ua = navigator.userAgent;

		if (ua.indexOf("Opera") >= 0) {
			board.style.visibility = 'hidden';	
			return;
		}

		close_flag = true;
		
		//if want to fade out when close window, comment out below
		var func_ref = function() {
			fadeout_opacity = fadeout_opacity - 10;
			if (fadeout_opacity <= 0) {
				clearInterval(fadeout_timer1);
				board.style.visibility = 'hidden';
				fadeout_opacity = 70;
				close_flag = false;
			}

			board.style.filter = 'alpha(opacity=' + fadeout_opacity + ')';		//IE
			var non_ie_opacity = fadeout_opacity / 100;							//Firefox
			board.style.mozOpacity = non_ie_opacity;
			board.style.opacity = non_ie_opacity;
		}

		fadeout_timer1 = setInterval(func_ref, 100);

		//if you want to close the window immediately, comment out below
		//board.style.visibility = 'hidden';
		//close_flag = false;
	}
}

function generatePopupTag()
{
	if(navigator.appName == "Netscape"){//Firefox	
 		var html = "<div id='results' style='visibility:hidden'></div>" +
			"<div id=category1board style='visibility:hidden; position:absolute; z-index:100; width:250px; '>" + 
			"<table border=0 cellspacing=0 cellpadding=0 style='background-color:transparent' width=100%>" +
			"<col width=20 /><col width=1 /><col width=12 /><col width=100% /><col width=12 /><col width=1 />" +
			"<tr height=1><td></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_lt.gif'/></td><td width='1' bgcolor=#555555></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_rt.gif'/></td></tr>" +
			"<tr height=12><td></td><td bgcolor=#ffffff></td></tr>" +
			"<tr height=6><td></td><td width=1 bgcolor=#555555></td><td colspan=3 align=right bgcolor=#ffffff valign=top><DIV id=sMenu style='POSITION: absolute; TOP: 5px; right:5px'>&nbsp; <a href='javascript:closePopup();'><img id=close src=timer/images/cross_out.gif width=16 height=16 border=0 style='border:0px;' onmouseover='this.src=\"timer/images/cross_over.gif\"'  onmouseout='this.src=\"timer/images/cross_out.gif\"' onmousedown='this.src=\"timer/images/cross_down.gif\"' onmouseup='this.src=\"timer/images/cross_up.gif\"'></a></DIV></td><td width=1 bgcolor=#555555></td></tr>" +
			"<tr><td></td><td width=1 bgcolor=#555555></td><td width=12 bgcolor=#ffffff></td><td bgcolor=#ffffff><div style='padding:0 0 5px 0;'><img src=images/shout_box_small.gif /></div><div id=contentpanel1></div><a href='shout_box.php' style='text-decoration:none;'>Read more...</a></td><td width=12 bgcolor=#ffffff></td><td width=1 bgcolor=#555555></td></tr>" +
			"<tr height=12><td></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_lb.gif'/></td><td bgcolor=#ffffff></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_rb.gif'/></td></tr>" +
			"<tr height=1><td></td><td width=1 bgcolor=#555555></td></tr></table></div>";
	}else{
		var html = "<div id='results' style='visibility:hidden'></div>" +
			"<div id=category1board style='visibility:hidden; position:absolute; z-index:100; width:250px;'>" + 
			"<table border=0 cellspacing=0 cellpadding=0 style='background-color:transparent; margin-right:17px;' width=100%>" +
			"<col width=20 /><col width=1 /><col width=12 /><col width=100% /><col width=12 /><col width=1 />" +
			"<tr height=1><td></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_lt.gif'/></td><td width='1' bgcolor=#555555></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_rt.gif'/></td></tr>" +
			"<tr height=12><td></td><td bgcolor=#ffffff></td></tr>" +
			"<tr height=6><td></td><td width=1 bgcolor=#555555></td><td colspan=3 align=right bgcolor=#ffffff valign=top><DIV id=sMenu style=\"POSITION: absolute; TOP: 5px; right:22px\"><a href='javascript:closePopup()'><img id=close src=timer/images/cross_out.gif width=16 height=16 border=0 style='border:0px' onmouseover='this.src=\"timer/images/cross_over.gif\"'  onmouseout='this.src=\"timer/images/cross_out.gif\"' onmousedown='this.src=\"timer/images/cross_down.gif\"' onmouseup='this.src=\"timer/images/cross_up.gif\"'></a></DIV></td><td width=1 bgcolor=#555555></td></tr>" +
			"<tr><td></td><td width=1 bgcolor=#555555></td><td width=12 bgcolor=#ffffff></td><td bgcolor=#ffffff><div style='padding:0 0 5px 0;'><img src=images/shout_box_small.gif /></div><div id=contentpanel1></div><a href='shout_box.php' style='text-decoration:none;'>Read more...</a></td><td width=12 bgcolor=#ffffff></td><td width=1 bgcolor=#555555></td></tr>" +
			"<tr height=12><td></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_lb.gif'/></td><td bgcolor=#ffffff></td><td colspan=2 rowspan=2><img height=13 width=13 src='timer/images/popup_rb.gif'/></td></tr>" +
			"<tr height=1><td></td><td width=1 bgcolor=#555555></td></tr></table></div>";	
	}
	
	document.write(html);
}



var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="timer/getuser.php";
url=url+"?q="+str;
//url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}



function stateChanged()
{
if (xmlhttp.readyState==4)
{
//document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
if(xmlhttp.responseText){

openHintPopup(xmlhttp.responseText);

}
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}