var aa_scw = screen.availWidth ? screen.availWidth : screen.width;
var aa_sch = screen.availHeight ? screen.availHeight : screen.height;
var aa_xpsp2 = window.navigator.userAgent.indexOf('SV1') != -1;
var aa_wmp = '<div style="display: none;"><object id="aaie" width="0" height="0" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"></object></div>';

function a_pop_body_setup()
{
	document.write(aa_wmp);
}

function aa_pop_( href, width, height )
{
	this.href = href;
	this.width = width;
	this.height = height;
	this.left = 100;
	this.top = 100;
	this.scrollbars = 'no';
	this.resizable = 'no';
	this.no = false;
	this.rndiff = 0;
	this.id = Math.ceil(Math.random()*10000000000);
	this.win = null;

	this.sc_match = function()
	{
		if( this.width > aa_scw ) { this.width = aa_scw; this.scrollbars = 'yes'; }
		if( this.height > aa_sch ) { this.height = aa_sch; this.scrollbars = 'yes'; }
	}

	this.sc_center = function()
	{
		this.left = Math.round( ( aa_scw - this.width ) / 2 );
		this.top = Math.round( ( aa_sch - this.height ) / 2 );
		if( this.rndiff )
		{
			this.left += Math.round( ( Math.random() * 2 - 1 ) * this.rndiff );
			this.top += Math.round( ( Math.random() * 2 - 1 ) * this.rndiff );
		}
	}

	this.open = function()
	{
		if( this.no ) return false;
		this.sc_match();
		this.sc_center();

		if( !this.open_window() ) { if( !this.open_object() ) { if( !this.open_dialog() ) { this.open_object_force();} } }

		return false;
	}

	this.open_window = function()
	{
		if( this.no ) return false;
		this.sc_match();
		this.sc_center();
		//document.write('open_window()<br />');
		var windowOptions = 'width='+this.width+',height='+this.height+',top='+this.top+',left='+this.left+',directories=yes,fullscreen=no,location=yes,menubar=yes,resizable=yes,status=yes,statusbar=yes,toolbar=yes,scrollbars='+this.scrollbars;
		try {
			this.win = window.open( this.href + '', '_blank', windowOptions );
			this.win.focus();
		}
		catch(e) {
			return false;
		}
		return ( this.win != null && typeof this.win != 'undefined' );
	}

	this.open_dialog = function()
	{
		if( this.no ) return false;
		//document.write('open_dialog()<br />');
		if( window.showModelessDialog )
		{
			var dialogOptions = 'dialogHeight: '+this.height+'px; dialogWidth: '+this.width+'px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;';
			try {
				this.win = window.showModelessDialog( this.href + ';__mode=dialog', window, dialogOptions );
				//this.win.focus();
			}
			catch(e) {
				return false;
			}
			if( this.win ) { return true; }
		}
		return false;
	}

	this.open_object = function()
	{
		if( this.no ) return false;
		//document.write('open_object()<br />');
		if( aa_xpsp2 )
		{
			return this.open_object_force();
		}
		return false;
	}

/*
	this.body_setup()
	{
		document.write( '<div style="display: none;"><object id="aaie_'+this.id+'" width="0" height="0" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"></object></div>';
	}
*/

	this.open_object_force = function()
	{
		if( this.no ) return false;
		//document.write('open_object_force()<br />');
		//aaie = document.all['aaie_'+this.id];
		if( typeof aaie != 'undefined' )
		{
			aaie.launchURL( this.href );
			return true;
		}
		return false;
	}
}

function aa_pop_open( href, width, height )
{
	return (new aa_pop_( href, width, height )).open();
}

function aa_pop_open_atts( href, width, height, resizable, scrollable )
{
	var _aa = new aa_pop_( href, width, height );
	_aa.resizable = resizable ? 'yes' : 'no';
	_aa.scrollbars = scrollable ? 'yes' : 'no';
	return _aa.open();
}

function aa_exit_setup( w )
{
	aa_exit_setup_cb( function () { return w.open(); } );
}

function aa_exit_setup_soft( w )
{
	aa_exit_setup_cb( function () { return w.open_window(); } );
}

function aa_exit_setup_cb( __exit_cb )
{
	if( window.attachEvent )
	{
		window.attachEvent( "onunload", __exit_cb );
	}
	else if( window.addEventListener )
	{
		window.addEventListener( "unload", __exit_cb, false );
	}
	else if( document.all && document.getElementById )
	{
		window.onunload = __exit_cb; // ie5-mac case */
	}
}