// popup windows functions - see Design guidelines on intranet



/* 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);

// 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 - named 'popUpSingle'
		// used for product demo

		// 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=820,height=850,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=520,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=500,height=480,resizable=1,toolbar=1,location=1,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(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 URLoverlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
//leave display none in for change default image link
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
subobj.style.width=(subobj.style.width!="width")? "400px" : "1px"
subobj.style.height=(subobj.style.height!="height")? "auto" : "1px"
subobj.style.border=(subobj.style.border!="border")? "1px solid #B0B0AF" : "none"
subobj.style.background=(subobj.style.background!="background")? "#EAF3C0" : "none"
subobj.style.padding=(subobj.style.padding!="padding")? "8px" : "0px"

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){
//leave display none in for change default image link
document.getElementById(subobj).style.display="none"
document.getElementById(subobj).style.width="1px"
document.getElementById(subobj).style.height="1px"
document.getElementById(subobj).style.border="none"
document.getElementById(subobj).style.background="none"
document.getElementById(subobj).style.padding="1px"

}  
// Set style function to change style of a given elelement (id)



function setStyle(theId, theStyle, theValue){

	x = document.getElementById(theId);

	x.style[theStyle] = theValue;

}
//for dragging layers e.g. scale for images
/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};