//javascript for controlling popup windows
/* 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;
	}
}


function pop_help(item_url)
{
	window.open(item_url,'pop_help','toolbar=yes,location=no,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=610,height=500');
}


/* 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);
// IE 5 needs special treatment because it's a bit special
if(!links[i].ownerDocument) {
				blankImg = document.createElement('img');
				blankImg.src = '/images/blank.gif';
				blankImg.className = 'borderNone';
				links[i].appendChild(blankImg);
			}
		}
		if (links[i].className && links[i].className.match("externalLink")) {
			hideSpan = document.createElement('span');
			hideSpan.className = 'hiddenText';
			hideText = document.createTextNode(' link to external site, this link will open in a new window');
			hideSpan.appendChild(hideText);
			links[i].setAttribute("title", "Link to external site, this link will open in a new window");
			links[i].appendChild(hideSpan);
// IE 5 needs special treatment because it's a bit special
if(!links[i].ownerDocument) {
				blankImg = document.createElement('img');
				blankImg.src = '/images/blank.gif';
				blankImg.className = 'borderNone';
				links[i].appendChild(blankImg);
			}
		}
		// attributes if single page only e.g. Durable URL - named 'popUpSmall'
		// change PRODUCT for your product name and add attributes as required
		if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpSingle ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'PRODUCTPopUpSingle','width=480,height=360,resizable=1,toolbar=1,location=0,directories=0,addressbar=1,scrollbars=1,status=0,menubar=0');
				return false;
			}
		} 
		// attributes if medium popup - named 'popUpHelp'
// change PRODUCT for your product name and add attributes as required
		else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpHelp ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'PRODUCTPopUpHelp','width=500,height=480,resizable=1,toolbar=1,location=1,directories=0,addressbar=1,scrollbars=1,status=0,menubar=0');
				return false;
			}
		} 
		// attributes if large popup - named 'popUpMulti' and 'externalLink'
		// change PRODUCT for your product name and add attributes as required
		else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpMulti ') != -1 || (' ' + links[i].className + ' ').indexOf(' externalLink ') != -1) {
			links[i].onclick = function() {
window.open(this.href,'','width=800,height=480,resizable=1,toolbar=1,location=1,directories=0,addressbar=1,scrollbars=1,status=0,menubar=1');
				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(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(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 overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}  



function openUrlWindow(type,id) {
	var page = "/common/openUrl.jsp?type=" + type + "&id=" + id;
	var windowPrefs = "toolbar=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=530,height=320";
	var 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 change_page_size(pageSize, formobj)
{
	if (formobj["value(pageSize)"] != null)
	{
		formobj["value(pageSize)"].value = pageSize;
	}
	if (formobj["pageSize"] != null)
	{
		formobj["pageSize"].value = pageSize;
	}
	formobj.submit();
}

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=610,height=500');
}

function pop_fieldhelp(item_url)
{
	window.open(item_url,'pop_fieldhelp','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=460,height=320');
}

function pop_glossary(item_url)
{
	window.open(item_url,'pop_glossary','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=700,height=500');
} 

function pop_gloss(item_url)
{
 window.open(item_url,'pop_gloss','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=500,height=200');
} 
 
// Project Seven code for popup text
 
function MM_reloadPage(init) {  //Updated by PVII. Reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
 
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function P7_hideDiv(evt) { //v1.2 by PVII
 var b,relT,mT=false; 
 if(document.layers){b=evt.target;if(b.p7aHide){
  b.visibility="hidden";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;
  while(b!=null){if(b.tagName=="DIV" && b.p7ahD){mT=true;break;}b=b.parentElement;}
  if(!b.contains(event.toElement)){b.style.visibility="hidden";}
 }else if(document.getElementById){b=evt.currentTarget;relT=evt.relatedTarget;
  while(relT!=null){if(b==relT){mT=true;break;}
  relT=relT.parentNode;}if(!mT){b.style.visibility="hidden";}}
}
 
function P7_autoHide() { //v1.2 by PVII
 var i,g,args=P7_autoHide.arguments;
 for(i=0;i<args.length;i++){if((g=MM_findObj(args[i]))!=null){
  g.p7aHide=true;if(document.layers){
  g.captureEvents(Event.MOUSEOUT);}g.onmouseout=P7_hideDiv;g.p7ahD=true;}}
}
 
function P7_autoLayers() { //v1.2 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;
 var a = parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc) {p7c=new Array();document.p7setc=true;
  for (var u=0;u<10;u++) {p7c[u] = new Array();}}
 for(k=0; k<p7c[a].length; k++) {
  if((g=MM_findObj(p7c[a][k]))!=null) {
   b=(document.layers)?g:g.style;b.visibility="hidden";}}
 for(k=1; k<args.length; k++) {
  if((g=MM_findObj(args[k])) != null) {
   b=(document.layers)?g:g.style;b.visibility="visible";f=false;
   for(j=0;j<p7c[a].length;j++) {
    if(args[k]==p7c[a][j]) {f=true;}}
  if(!f) {p7c[a][p7c[a].length++]=args[k];}}}
}
