//------------------------------------------------------------------------------
// XML HTTP REQUEST: GET AWARDS
//------------------------------------------------------------------------------
// Supports Safari, Mozilla 1.3+ (Firefox, etc) and IE 5.5+
// © 2006 | SAT 
// http://www.game-play.ru
// Awards System v.3.1.0
//------------------------------------------------------------------------------

/*--------------------------------------------*/
// INIT VARS
/*--------------------------------------------*/

var gnp_div  = 'get-new-posts_menu';
var msg_div  = 'get-new-msgs_menu';
var mem_div  = 'get-members';
var divobj;
var divopen  = 0;
var xmlobj_aw;

var awards_main;
var awards_drag;
var awards_content;
var awards_loaded   = 0;
var pm_cycle_count = 0;
var search_cache   = {};
var posts_st       = 0;



/*--------------------------------------------*/
// Load Member Awards
/*--------------------------------------------*/

function xml_awards_init( memberid )
{
	awards_main    = document.getElementById( 'get-awards' );
	awards_drag    = document.getElementById( 'awards-drag' );
	awards_content = document.getElementById( 'awards-content' );

	
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/

	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		
		if ( ! xmlobj_aw.readystate_ready_and_ok() )
		{
			// Could do a little loading graphic here?
			return;
		}
		
		//----------------------------------
		// INIT
		//----------------------------------
		
		var html = xmlobj_aw.xmlhandler.responseText;
		
		//----------------------------------
		// Stop IE showing select boxes over
		// floating div [ 1 ]
		//----------------------------------
		
		if ( is_ie )
		{
			 html = "<iframe id='awards-shim' src='javascript:;' class='iframshim' scrolling='no' frameborder='0' style='position:absolute; top:0px; left:0px; display:none;'></iframe>" + html;
		}
		
		if ( html.match( /^ERROR:/ ) )
		{
			html = html.replace( /^ERROR:/, '' );
			awards_main.style.display  = 'none';
			alert( html );
			
		}
		else
		{
			awards_content.innerHTML = html;
		}
		
		//----------------------------------
		// Stop IE showing select boxes over
		// floating div [ 2 ]
		//----------------------------------
		
		if ( is_ie )
		{
			awards_shim               = document.getElementById('awards-shim');
			awards_shim.style.width   = awards_content.offsetWidth;
			awards_shim.style.height  = awards_content.offsetHeight;
			awards_shim.style.zIndex  = awards_content.style.zIndex - 1;
			awards_shim.style.top     = awards_content.style.top;
			awards_shim.style.left    = awards_content.style.left;
			awards_shim.style.display = "block";
		}
	}
	
	xmlobj_aw = new ajax_request();
	xmlobj_aw.onreadystatechange( do_request_function );
	
	//----------------------------------
	// LOAD XML
	//----------------------------------

	xmlobj_aw.process( ipb_var_base_url + 'automodule=awards&inc=memawards&xml=1&MID=' + memberid );
  	
  	awards_main.style.position = 'absolute';
	awards_main.style.display  = 'block';
	awards_main.style.zIndex   = 66;
	

	//----------------------------------
	// show position
	//----------------------------------
		
	var my_width  = 0;
	var my_height = 0;
		
	if ( typeof( window.innerWidth ) == 'number' )
	{
		//----------------------------------
		// Non IE
		//----------------------------------
		  
		my_width  = window.innerWidth;
		my_height = window.innerHeight;
	}
	else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//----------------------------------
		// IE 6+
		//----------------------------------
			
		my_width  = document.documentElement.clientWidth;
		my_height = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//----------------------------------
		// Old IE
		//----------------------------------
			
		my_width  = document.body.clientWidth;
		my_height = document.body.clientHeight;
	}
		
	//----------------------------------
	// Get div height && width
	//----------------------------------
		
	var divheight = parseInt( awards_main.style.Height );
	var divwidth  = parseInt( awards_main.style.Width );
		
	divheight = divheight ? divheight : 400;
	divwidth  = divwidth  ? divwidth  : 400;
		

	var scrollY = 0;
	
	if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
	else if ( document.body && document.body.scrollTop )
	{
		scrollY = document.body.scrollTop;
	}
	else if ( window.pageYOffset )
	{
		scrollY = window.pageYOffset;
	}
	else if ( window.scrollY )
	{
		scrollY = window.scrollY;
	}

	
	//----------------------------------
	// Finalize...
	//----------------------------------
	
	var setX = ( my_width  - divwidth  ) / 2;
	var setY = ( my_height - divheight ) / 2 + scrollY + 100;
	
	setX = ( setX < 0 ) ? 0 : setX;
	setY = ( setY < 0 ) ? 0 : setY;
	
	awards_main.style.left = setX + "px";
	awards_main.style.top  = setY + "px"; 		

	Drag.init( awards_drag, awards_main );

}

/*-------------------------------------------------------------------------*/
// Pop up Awards System window
/*-------------------------------------------------------------------------*/

function card_pop(memberid)
{
	var not_loaded_yet = 0;
	
	if ( use_enhanced_js )
	{
		try
		{
			xml_awards_init(memberid);
			not_loaded_yet = 1;
		}
		catch( e )
		{
			//alert(e);
			not_loaded_yet = 0;
		}
	}
	
	if ( ! not_loaded_yet )
	{
		ipb_var_base_url = ipb_var_base_url.replace( '&amp;', '&' );
		window.open( ipb_var_base_url + 'automodule=awards&inc=memawards&MID=' + memberid,'Awards','width=600,height=300,resizable=yes,scrollbars=yes');
	}
}

/*-------------------------------------------------------------------------*/
// Hide Pop up Awards System window
/*-------------------------------------------------------------------------*/

function hide_awards()
{
	document.getElementById("get-awards").style.display="none";
}

