/**********************************************/

function openUrlWindow(id, type) {
	page = "/common/openUrl.jsp";
	if (id != null) {
		page += "?id=" + id + "&type=" + type;
	}
	windowPrefs = "toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=480,height=320";
	urlWindow = window.open(page, "openUrl", windowPrefs);
	urlWindow.focus();
}

function saveToMyArchive() {
	document.forms['StorableObjectForm'].submit();
}

function deleteAll(msg, url) {
	if (confirm(msg))
		window.location = url;
}

function pop_help(item_url)
{
	window.open(item_url,'pop_help','toolbar=yes,location=no,directories=no,status=no,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=600,height=550');
}
function pop_alerts(item_url)
{
	window.open(item_url,'pop_help','toolbar=yes,location=no,directories=no,status=no,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=450,height=320');
}

function change_page_size(pageSize, formobj)
{
	formobj["value(pageSize)"].value = pageSize;
	formobj.submit();
}

function launchSummaryWindow() {
	// I use 'open' to get the window, and then change the location, as
	// there's a 'feature' in IE which means that if the window is already
	// open, then 'open' doesn't change it's location.  Bloody thing.
	windowPrefs = "toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=480,height=600";
	urlWindow = window.open("", "summary", windowPrefs);
	urlWindow.location = "/search/overviewSummary.do";
	urlWindow.focus();
}

function back2main(url) 
	{
		// Make sure the main window hasn't been closed accidentally.
		if(opener && !opener.closed)
		{
		    	opener.location.replace(url);
		}
		else
		{
			var	sOptions = ",location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,copyhistory=yes,directories=yes,scrollbars=yes";
			var	nWidth	= 800;
			var	nHeight	= 600;		
			opener = CreateSatellite(url, "", nWidth, nHeight, "center", sOptions);
			opener.opener = null;
		}
	}

/* add Array.push if needed (for IE5.x) */
if (Array.prototype.push == null) {
	Array.prototype.push = function(item) {
		this[this.length] = item; return this.length;
	}
}

/* Add Event function taken from http://www.dustindiaz.com/rock-solid-addevent/ */

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

/*	EventCache Version 1.0
	Copyright 2005 Mark Wubben

	Provides a way for automagically removing events from nodes and thus preventing memory leakage.
	See <http://novemberborn.net/javascript/event-cache> for more information.
	
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

/* doTheLinks manages all links in document with specific class names */

function doTheLinks() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className && links[i].className.match("popUp")) {
			hideSpan = document.createElement('span');
			hideSpan.className = 'hiddenText';
			hideText = document.createTextNode(' - this link will open in a new window');
			hideSpan.appendChild(hideText);
			links[i].setAttribute("title", "This link will open in a new window");
			links[i].appendChild(hideSpan);
		}
		if (links[i].className && links[i].className.match("externalLink")) {
			hideSpan = document.createElement('span');
			hideSpan.className = 'hiddenText';
			hideText = document.createTextNode(' - link to external site');
			hideSpan.appendChild(hideText);
			links[i].setAttribute("title", "Link to external site");
			links[i].appendChild(hideSpan);
		}
		// attributes if single page only e.g. end session - named 'popUpSmall'
		if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUp1 ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'FIAFPopUp1','width=800,height=600,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=1');
				return false;
			}
		} 
		// attributes if medium popup - named 'popUpHelp'
		else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpHelp ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'PFIAFPopUpHelp','width=600,height=550,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=0');
				return false;
			}
		} 
		// attributes if large popup - named 'popUpMulti'
		// change PRODUCT for your product name and add attributes as required
		else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpMulti ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'FIAFPopUpMulti','width=800,height=600,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=0');
				return false;
			}
		}
	}
}

/* Focus any window as it loads */

function doFocus() {
	window.focus();
}

/* Calls for above functions */

addEvent(window,'load',doFocus);
addEvent(window,'load',doTheLinks);
addEvent(window,'unload',EventCache.flush);

//new durable url layer
/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function getposOffset(URLoverlay, offsettype){
var totaloffset=(offsettype=="left")? URLoverlay.offsetLeft : URLoverlay.offsetTop;
var parentEl=URLoverlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function URLoverlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth): 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}

function URLoverlayclose(subobj){
document.getElementById(subobj).style.display="none"
}  