/*
 *	This script allows standard open calls to be interepreted as well as they can be by IE
 *	Any browser should be able to call this with the correct features and get what is expected
 *	Currently the only method that should be called is the WindowUtils.open method.
 */

function WindowUtils()
{
}

if (its.ie)
{
	function dialogHeightTranslate(strValue)
	{
		return("dialogHeight="+strValue+"px");
	}
	function dialogWidthTranslate(strValue)
	{
		return("dialogWidth="+strValue+"px");
	}
	WindowUtils.prototype.ieTranslate={"height":dialogHeightTranslate,
						"left":"dialogLeft",
						"top":"dialogTop",
						"width":dialogWidthTranslate,
						"scrollbars":"scroll"};
	WindowUtils.prototype.translate=function(strName,strValue)
	{
		var obj=this.ieTranslate[strName];
		if (typeof obj=="function")
		{
			return(obj(strValue));
		}
		else if (obj)
		{
			return(obj+"="+strValue);
		}
		else
		{
			return(strName+"="+strValue);
		}
	}
}
WindowUtils.prototype.isTrue=function(strValue)
{
	return(strValue=="yes" || strValue=="1");
}

/*
 *	This is the only method that should be called to open a window
 *	It will try mapping stardard features to IE features when openning a window
 */
WindowUtils.prototype.open=function(sURL,sName,sFeatures)
{
	if(its.ie)
	{
		var aTranslated=new Array();
		aTranslated[aTranslated.length]="help=0;";
		var aPairs=sFeatures.split(",");
		var aFeatures=new Array();
		for (var i=0; i < aPairs.length; i++)
		{
			if (aPairs[i].indexOf("=")!=-1)
			{
				var aPair=aPairs[i].split("=");
				aFeatures[aPair[0]]=aPair[1];
				var trans=this.translate(aPair[0],aPair[1]);
				if (trans)
				{
					aTranslated[aTranslated.length]=trans+";";
				}
			}
		}
		
		if (this.isTrue(aFeatures['modal']))
		{
			window.showModalDialog(sURL,window,aTranslated.join(""));
		}
	}
	else
	{
		window.open(sURL,sName,sFeatures);
	}
}

WindowUtils.prototype.getOpener=function()
{
	if (window.opener)
	{
		return(window.opener);
	}
	else
	{
		return(window.dialogArguments);
	}
}

WindowUtils.prototype.importNode=function(document,node)
{
	if (document.importNode)
	{
		//Simply return it
		return(node);
	}
	else
	{
		var ele=document.createElement(node.nodeName);

		for (name in node)
		{
			try
			{
				if (typeof(node[name])=="string")
				{
					ele[name]=node[name];
				}
			}catch(e)
			{
			}
		}
		for (var i=0;i < node.childNodes.length; i++)
		{
			var child=windowUtils.importNode(document,node.childNodes[i]);
			if (child!=null)
			{
				ele.appendChild(child);
			}
		}
		return(ele);
	}
}

var windowUtils=new WindowUtils();