// DivPopup JScript source code
function DivPopup(name)
{
	this.Name = name;
	this.ServerPage = applicationPath + "RS/Common/Server/EnlargeImage.aspx"; // relative virtual path from root to xmlhttp aspx
	this.StyleSheet = applicationPath + "RS/Common/Server/IE5.0/EnlargeImage.xslt"; // relative virtual path from root to xsl
	this.ApplicationPath = applicationPath;
	this.Debug = false;
	this.PopupDiv;
	this.MaxWidth = 0;
	this.MaxHeight = 0;
	this.OnClose = "yes";
}

DivPopup.prototype.TargetElement =
function ()
{
	return div;
}

DivPopup.prototype.Close = 
function ()
{
	document.body.removeChild(this.PopupDiv);
}

DivPopup.prototype.Show = 
function (imageUrl)
{
	var xmlDocument,
		scrollTop;
	
	this.PopupDiv = document.createElement("div");
	document.body.appendChild(this.PopupDiv);
	try
	{
		if ((xmlDocument = this.LoadXMLFromURL(this.ServerPage, imageUrl)) != null)
		{
			this.PopupDiv.innerHTML = this.EvaluateXPath(xmlDocument.documentElement, "html");
			try
			{
				scrollTop = document.body.scrollTop;
			}
			catch (mozilla)
			{
				scrollTop = window.pageYOffset;
			}
			document.getElementById("imgpopup").style.top = scrollTop;
			document.getElementById("popupbg").style.top = scrollTop;
		}
	}
	catch (exception)
	{
		this.PopupDiv.innerHTML = exception;
	}
}

DivPopup.prototype.LoadXMLFromURL =
function(url, imageUrl) {
	var httpRequest,
		request;

	if ((httpRequest = XmlHttpObject()) != null) {
		httpRequest.open("POST", url, false);
		request = "<parameters " +
			"maxwidth=\"" + this.MaxWidth + "\" " +
			"maxheight=\"" + this.MaxHeight + "\" " +
			"varname=\"" + this.Name + "\" " +
			"imageurl=\"" + imageUrl + "\" " +
			"stylesheet=\"" + this.StyleSheet + "\" " +
			"onclose=\"" + this.OnClose + "\" " +
			"/>";
		httpRequest.send(request);
		/**************************************/
		if (this.Debug)
			alert(httpRequest.responseText);
		/**************************************/
		if (httpRequest.status == 200)
			return httpRequest.responseXML;
		else
			alert(httpRequest.status + ": " + httpRequest.statusText);
	}
} 

DivPopup.prototype.EvaluateXPath =
function (contextNode, xpath)
{
	var value = null;
	try
	{
		var node;
		if ((node = contextNode.selectSingleNode(xpath)) != null)
			value = node.text;
	}
	catch (mozilla)
	{
		var document;
		if (contextNode.nodeType != 9)
			document = contextNode.ownerDocument;
		else
			document = contextNode;
		value = document.evaluate(xpath, contextNode, null, 2, null).stringValue;
	}
	return value;
}



