/*
	map.windows.js
	
    functions for launching and modifying windows
*/

// DEFINE WINDOW CLASS
windowClass = function() {}; // empty class constructor


//*****************************************************************************
// BEGIN WINDOW METHODS
//*****************************************************************************


//*****************************************************************************
// WINDOWDIALOG
//*****************************************************************************

windowClass.prototype.windowDialog = function(url, strName, w, h) {

  if (!w) w = 350;
  if (!h) h = 250;
  if (!strName) strName = "MITDialog";

  var mywin, winleft, wintop, winprops;
  winleft = (screen.availWidth - w)/2;
  wintop = (screen.availHeight - h)/2;
  winprops = "height=" + h + ",width=" + w + ",left=" + winleft + ",top=" + wintop + ",scrollbars=yes,resizable,dependent";
  mywin = window.open(url, strName, winprops);
  mywin.focus();
}

// END WINDOWDIALOG
//*****************************************************************************


//*****************************************************************************
// APPWINDOW
//*****************************************************************************

/*
 * This function is a wrapper for windowDialog. 
 * It opens an application window a height and width of 85%  
 */

windowClass.prototype.appWindow = function(url, strName){

	var w = screen.availWidth * 0.85;
	var h = screen.availHeight * 0.85;
	
	map.window.windowDialog(url, strName, w, h);
}

// END APPWINDOW
//*****************************************************************************


//*****************************************************************************
// HELPWINDOW
//*****************************************************************************

/*
 * This function is a wrapper for windowDialog. 
 * It opens an application window a 700 x 500 in size
 * It assumes that an appName of "help_apps" is defined in the map.appData.js file 
 */

windowClass.prototype.helpWindow = function(helpPage){

	var w = 700;
	var h = 500;
	var helpUrl = map.url.getAppUrl('help_apps') + helpPage;
	map.window.windowDialog(helpUrl, 'insideMITHelp', w, h);
}

// END HELPWINDOW
//*****************************************************************************


//*****************************************************************************
// WINDOW
//*****************************************************************************

windowClass.prototype.window = function(url, strName, w, h, toolbool) {  

	if (!strName) strName = "MITWindow";

	if (!w) w = map.window.convertWindowSize("70%","width");
	else w = map.window.convertWindowSize(w,"width");

	if (!h) h = map.window.convertWindowSize("50%","height");
	else h = map.window.convertWindowSize(h,"height");

	if (toolbool != false) toolbool = true;

    var win, winleft, wintop, winprops;


    winleft = (screen.availWidth - w)/2; // let's put it dead center on the screen
    wintop = (screen.availHeight - h)/2;

    // start building string of window properties

    winprops = "height=" + h + ",width=" + w;

	// the next two lines are for positioning the window in the
	// center of the screen -- commented out by default

	// if (strBr == "ns4") winprops += ",screenX=" + winleft + ",screenY=" + wintop;
	// else winprops += ",left=" + winleft + ",top=" + wintop;

	winprops += ",scrollbars,resizable";
	
	if (toolbool == true) winprops += ",menubar,toolbar,location,status";

    // end string of window properties

    window.open(url, strName, winprops);
    //win.focus();
}

// END WINDOW
//*****************************************************************************


//*****************************************************************************
// CONVERTWINDOWSIZE
//*****************************************************************************

windowClass.prototype.convertWindowSize = function(strIn, strAxis) {
	var intReturn;
	strIn = strIn.toString();
	if (strIn.indexOf("%") != -1) {
		intReturn = 0.01 * parseInt(strIn.substring(0,strIn.length-1)); // converting percent string to decimal int
		if (strAxis == "width") intReturn = screen.availWidth * intReturn;
		if (strAxis == "height") intReturn = screen.availHeight * intReturn;
	}
	else intReturn = parseInt(strIn);
	return intReturn;
}

// END CONVERTWINDOWSIZE
//*****************************************************************************


// END WINDOW METHODS
//*****************************************************************************


//*****************************************************************************
// ADD WINDOW CLASS TO MAPCLASS
//*****************************************************************************
mapClass.prototype.window = new windowClass();
