/* *****************************************************************************

  windows.js

  (C) 2006 Ortiz Consulting. All rights reserved.

  Copy of any portion of this software is prohibited.

***************************************************************************** */

var ocChildWin = null, ocChildOfChildWin = null ;

function openChildWindow( url, width, height, resize, scrollbars )
{
	ocChildWin = openChildWindowCore( "ocChildWin", ocChildWin, url, width, height, resize, scrollbars ) ;
}

function openNewChildWindow( url, width, height, resize, scrollbars )
{
    // The difference between 'openChildWindow' and 'openNewChildWindow' is that
    // the latter creates a new unique windowId using date and time everytime is fired.
    // That way we will have a new independent window everytime we call the function.

    var now = new Date(), windowId = new String( "ocChildWin" ), newOcChildWin = null ;

    now.getDate() ;
    
    windowId += now.getDay() + now.getHours() + now.getMinutes() + now.getSeconds() ;

    ocChildWin = openChildWindowCore( windowId, newOcChildWin, url, width, height, resize, scrollbars ) ;

	delete now ;
	delete windowId ;
}

function openChildOfChildWindow( url, width, height, resize, scrollbars )
{
	ocChildOfChildWin = openChildWindowCore( "ocChildOfChildWin", ocChildOfChildWin, url, width, height, resize, scrollbars ) ;
}

function screenObjectExists()
{
	// Some browsers recognize it this way some others don't
	for ( var object in window )
		if ( object == "screen" )
			return true ;

	for ( var object in window.screen )
		if ( object == "availHeight" )
			return true ;

	return false ;
}

function openChildWindowCore( windowId, winHandle, url, width, height, resize, scrollbars )
{
	var top, left ;
	
	if ( screenObjectExists() )
	{
	    if ( width < 0  )
	        width = window.screen.availWidth + ( width * 2 ) ;

	    if ( height < 0  )
	        height = window.screen.availHeight + ( height * 2 ) ;

		top     = ( window.screen.availHeight - height ) / 2 ;
		left    = ( window.screen.availWidth  - width  ) / 2 ;
	} else {
	    if ( width < 0  )
	        width = 620 ;

	    if ( height < 0  )
	        height = 460 ;

		top = left = 50 ;
	}

	if ( winHandle && !winHandle.closed )
		winHandle.close() ;

	winHandle = window.open( url, windowId,
		"toolbar=0,location=0,status=0,menubar=0,"+
		"scrollbars=" + (scrollbars ? 1 : 0 ) + "," +
		"resizable="  + (resize     ? 1 : 0 ) + "," +
		"width="+ width + ",height=" + height + "," +
		"top="  + top   + ",left="   + left ) ;

	winHandle.focus() ;
	
	return winHandle ;
}

//function used to resize window
function resizeOuterTo(w,h) {

 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    window.outerWidth=w;
    window.outerHeight=h;
   }
   else window.resizeTo(w,h);
 }
}


//centrate window on screen
function centrateWindow()
{		
   window.moveTo(self.screen.width/4,self.screen.height/4-100);
}

/* EOF */
