/********************************************************************
* Copyright ©  Acsys, Inc.  All rights reserved.
* 
* This material contains the valuable properties and trade secrets of
* Acsys, Inc. embodying substantial creative efforts and confidential 
* information, ideas, and expressions, no part of which may be 
* reproduced or transmitted in any form or by any means, electronic, 
* mechanical, or otherwise, including photocopying and recording or 
* in connection with any information storage or retrieval system 
* without the permission in writing of Acsys, Inc.
*/

/********************************************************************
* This library defines a class for managing pop-up windows.
* 
* Dependencies: 
*	None
*/

// Constants used by this file
var DEFINE_ACSYS_POPUPWINDOW = true;

// Create a global pop up manager.
var popUpManager = new PopUpWindowMgr();

function PopUpWindowMgr()
{
	this.WindowOpen = _PopUpWindowMgr_WindowOpen;
	this.Windows={};
	this.GetFeaturesFromString = _PopUpWindowMgr_GetFeaturesFromString;
	this.WindowFeaturesToString = _PopUpWindowMgr_WindowFeaturesToString;
	this.IsGoodSize = _PopUpWindowMgr_IsGoodSize;
}

function _PopUpWindowMgr_WindowOpen(varName, url, winName, features, winReplace)
{
	if (this.Windows[varName] && this.Windows[varName].close)
		this.Windows[varName].close();

	var properties = this.GetFeaturesFromString(features);
	var isGoodSize = true;
	
	if (properties["width"] && 
		!isNaN(parseInt(properties["width"])) &&
		properties["height"] && 
		!isNaN(parseInt(properties["height"])))
	{
		isGoodSize = this.IsGoodSize(parseInt(properties["height"]), parseInt(properties["width"]));
		if (!isGoodSize)
		{
			properties["height"] = screen.availHeight - 50;
			properties["width"] = screen.availWidth - 50;
		}
	}
	
	this.Windows[varName] = window.open(url, winName, this.WindowFeaturesToString(properties), winReplace);
	if (this.Windows[varName] != null) 
	{
		this.Windows[varName].focus();
	}
}

function _PopUpWindowMgr_IsGoodSize(height, width)
{
	return (screen.availHeight > height && screen.availWidth > width) ? true : false;
}

function _PopUpWindowMgr_GetFeaturesFromString(features)
{
	var popUpFeatures = {};
	var properties = features.split(",");
	var property = [];
	
	for (var i = 0, len = properties.length; i < len; i++)
	{
		property = properties[i].split("=");
		popUpFeatures[property[0]] = property[1];
	}
	return popUpFeatures;
}

function _PopUpWindowMgr_WindowFeaturesToString(properties)
{
	var features = "";
	for (var item in properties)
	{
		features += item + "=" + properties[item] + ",";
	}
	return (features.length > 0) 
		? features.substr(0, features.length - 1)
		: features;
}


