//
// Page title detection.
//
function setTitle( )
{
	var title = document.getElementById("title");
	if (title) {
		var img = title.getElementsByTagName("img").item(0);
		document.title += (img?(img.alt?" - "+img.alt:""):" - "+title.innerHTML);
	}
}

//
// Regular popup.
//
function openPopup( url, width, height, name, left, top, properties ) {

    if (isValidUrl(url)) { 
		window.open(url, ((name&&name!="")?name:"popup"), ((width&&width!="")?"width="+width+",":"")+((height&&height!="")?"height="+height+",":"")+((properties&&properties!="")?properties:"status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes")+((left&&left!="")?",left="+left:"")+((top&&top!="")?",top="+top:""));
	}
}

function isValidUrl( url )
{
    return !(typeof(url)=="undefined" || url==null || url=="" || url.toLowerCase()=="none" || url.toLowerCase()=="null" || url=="-1");
}

//
// Procedure details in-page popup.
//
function showDetails( link, height )
{
	var info = document.getElementById("details-popup");
	if (info == null)
		info = createDetailsPopup();

	if (info.style.display == "block") {
		closeDetails();
	} else {
		var parent = link.parentNode;
		while (parent && parent.className != "procedure")
			parent = parent.parentNode;
		
		if (parent) {
			info = info.parentNode.removeChild(info);
			var title = parent.getElementsByTagName("h2").item(0);
			parent.insertBefore(info, title.nextSibling);
			
			// Remove any iframe that exists and create a new one
			var iframe = info.getElementsByTagName("iframe").item(0);
			
			// Set height and show it	
			if (height) {		
				iframe.style.height = (height-25)+"px";
				info.style.height 	= height+"px";
			}

			info.style.display 	= "block";
			
			// Delayed loading of iframe (bug in Safari)
			if (navigator.userAgent.indexOf("WebKit") != -1)
				setTimeout("showDetailsFrame('"+link.href+"')", 1);
			else
				showDetailsFrame(link.href);
		}
	}
}


function showDetailsFrame( url )
{
	var info = document.getElementById("details-popup");
	info.getElementsByTagName("iframe").item(0).src = url;
}


function createDetailsPopup( )
{
	var info = document.createElement("div");
	info.setAttribute("id", "details-popup");
	
	info.innerHTML = "<h3><a href=\"Close\" id=\"close-popup\" onclick=\"closeDetails(); return false\">Close</a>" +
		"<span>Procedure Details</span></h3><iframe frameborder=\"0\" src=\"about:blank\"></iframe>";
	
	document.body.appendChild(info);
	
	return info;
}


function closeDetails()
{
	var info = document.getElementById("details-popup");
	info.style.display = "none";
	
	var iframe = info.getElementsByTagName("iframe").item(0);
	iframe.src = "about:blank";
}


function getPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
		while (obj.offsetParent) {
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
		}
	else if (obj.x)
			curleft += obj.x;
	return curleft;
}


function getPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
		while (obj.offsetParent) {
				curtop += obj.offsetTop
				obj = obj.offsetParent;
		}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}