
//############################################################
function modal( url, w, h )
	{
	if( !w ) w = 400;
	if( !h ) h = 400;
	url = HOMEDIR +'/'+ url;
	var w = W.showModalDialog( url, top.window, 'dialogHeight: '+h+'px; dialogWidth: '+w+'px; center: yes; dialogHide: no; edge: sunken; help: off; resizable: on; status: no; unordered: off;' );
	}
//############################################################

function dsize( w, h )
	{
	if( !w || !h ) return;
	W.dialogWidth = w+'px';
	W.dialogHeight = h+'px';
	}
	
//#############################################################

function wait( key )	
	{
	if( key ) 
		{
		W.D.wait_div.style.display = "none";
		return;
		}
	W.D.wait_div.style.display = "block";
	
	}
	
//#####################################################################

function wopen( url, target, w, h, asize, title )	
	{
	if( !url )
		{
		event.cancelBubble = true;
		event.returnValue = false;
		return;
		}
	if( !target ) target = '_blank';
	if( !w ) w = 500;
	if( !h ) h = 400
	if( !title ) title = '';
	
	
	w = parseInt( w, 10 );
	h = parseInt( h, 10 );
	if( asize ) asize = true;
	else asize = false;
	
	var aw = screen.availWidth;
	var ah = screen.availHeight;
	if( w > aw ) w = aw;
	if( h > ah ) h = ah;
	
	var left = Math.round( ( aw - w ) / 2 );
	
	var wd = window.open( url, target, 'channelmode= 0, directories=0, fullscreen=0, height='+h+'px, width='+w+'px, location=0, menubar=0, resizable=1, scrollbars=1, status=0, toolbar=0, top=10px, left='+left+'px' );
	
	
	if( url.indexOf( window.location.host ) != -1 || url.indexOf( 'http://' ) == -1  ) wd.attachEvent( "onload", function() {resize_new_win( wd, asize, title )	} );
	
	}

function resize_new_win( win, asize, title )	
	{
	if( win.document.body == null )
		{
		win.document.createElement( "body" );
		}
		var wb = win.document.body;
		
		wb.style.padding = "0px";
		wb.style.margin = "0px";
		wb.style.overflow="auto";
			
		
		if( asize )
			{
			
			var ofw = wb.scrollWidth - wb.clientWidth;
			var ofh = wb.scrollHeight - wb.clientHeight;
				
				var eflag = false;
			
			if( ( wb.clientWidth + ofw ) > ( screen.availWidth - 40 ) )
				{
				ofw =  screen.availWidth - wb.clientWidth - 50 ;
				eflag = true;
				}
			if( wb.clientHeight + ofh > screen.availHeight - 60 )
				{
				ofh = screen.availHeight - wb.clientHeight - 60;
				eflag = true;
				}
				
			win.resizeBy( ofw , ofh  );
			
			var left = 2;
			if( eflag == false )
				{
				win.resizeBy( wb.scrollWidth - wb.clientWidth,  wb.scrollHeight - wb.clientHeight );
				left = Math.round( ( screen.availWidth - wb.clientWidth+20 ) / 2 );
				}
				
			
			win.moveTo( left, 10 );
			if( title )
				{
				win.document.title = title;
				}
			}
		
	}
	
//##################################################
//Fix problems with base tag and anchors
	
function makeHrefHashBases()
	{
	var bases = document.getElementsByTagName('base');
	if( bases.length == 0 )
		{
		return;	
		}
		
		
	var lnks = document.links;
	var anchrs = document.anchors;
	var baseHref = bases[0].href;
	
		
	for( var i = 0; i < lnks.length; i++ )
		{
		if( baseHref+lnks[i].hash == lnks[i].href ||  baseHref+'/'+lnks[i].hash == lnks[i].href)
			{
			for( var k = 0; k < anchrs.length; k++ )	
				{
				if( '#'+anchrs[k].name ==  lnks[i].hash)
					{
					lnks[i].href = window.location.pathname+lnks[i].hash;
					break;
					}	
				}
			}
		}
		
		
	
	}
	
