/* Originals shared scripts file. */

var BEUtil = function () {
	return {};
}();

BEUtil.addEvent = function () {
	if (window.addEventListener) {
		return function(obj, type, fn) {
			obj.addEventListener(type, fn, false);
			this.eventCache.add(obj, type, fn);
		};
	} else if (window.attachEvent) {
		return function(obj, type, fn) {
			var f = function() {
				fn.call(obj, window.event);
			};
			obj.attachEvent('on' + type, f);
			this.eventCache.add(obj, type, fn);
		};
	} else {
		return function(obj, type, fn) {
			element['on' + type] = fn;
		}
	}
}();

BEUtil.eventCache = function () {
	var listEvents = [];
	return {
		listEvents: listEvents,
		add: function(obj, type, fn) {
			listEvents.push(arguments);
		},
		flush: function() {
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1) {
				item = listEvents[i];
				BEUtil.removeEvent(item[0],item[1],item[2]);
				if (item[1].substring(0, 2) != 'on') {
					item[1] = 'on' + item[1];
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

BEUtil.removeEvent = function () {
	if (window.removeEventListener) {
		return function(obj, type, fn) {
			obj.removeEventListener(type, fn, false);
		}
	}
	else if (window.detachEvent) {
		return function(obj, type, fn) {
			obj.detachEvent('on' + type, obj[type + fn]);
			obj[type + fn] = null;
			obj['e' + type + fn] = null;
		}
	}
};		


/* A few browser sniffs to circumvent some known bugs. */
var sUserAgent = navigator.userAgent.toLowerCase();
var isOp = (sUserAgent.indexOf('opera')!=-1)?true:false;

/****************************************************************
Make a new popup window...
Parameters:
  oAnchor: required object reference to the anchor (link)
  sWindow: optional string for the window name if wanting to reuse window or null to use the default.
  sProps: optional string of window properties ('width=300,height=200') or null to use the defaults defined here.
Notes:
  Notice in the example that the 'href' value maintains URL
  (not "#" or "javascript:") and the 'title' attribute indicates
  this will be a pop-up window. These things are required for
  accessibility reasons.
Example use:
  <a href="/home.jsp" onclick="return pop(this,'survey');" title="Survey opens a new window.">Take our survey!</a>
****************************************************************/
function pop(oAnchor,sWindow,sProps){
	var sUrl = '';
	if(oAnchor.getAttribute) sUrl = oAnchor.getAttribute('href');
	else if(sUrl=='') sUrl = oAnchor.href;
	var oPopup = false;
	if(sUrl && sWindow && sProps) oPopup = window.open(sUrl,sWindow,sProps);
	else if(sUrl && sWindow) oPopup = window.open(sUrl,sWindow);
	else if(sUrl) oPopup = window.open(sUrl);
	/* An Opera bug returns too early if you focus the window, so we don't focus it in that browser. */
	/* Only a noticable defect if a window is already open and hidden. */
	if(oPopup && !isOp) oPopup.focus();
	/* If popup was created successfully, cancel link in calling window. */
	/* Acts as regular link in browser that has pop-up blocking enabled or JavaScript disabled. */
	return (oPopup)?false:true;
}

/* This function disables any <input type="submit"> buttons when it is called. Call from onsubmit event in form tag. */
function disableSubmitButtons(){
	if(!document.getElementsByTagName) return;
	var aInputs = document.getElementsByTagName('input');
	for(var i=0;i<aInputs.length;i++){
		if(aInputs[i].type=='submit'){
			aInputs[i].disabled = 'true';
		}
	}
	return true;
}

function addEventAttribute(object,handler,addFunction) {
	if((!document.all) && (document.getElementById)) {
		object.setAttribute(handler,addFunction);
	}
	//workaround for IE 5.x
	if((document.all) && (document.getElementById)) {
		object[handler] = new Function(addFunction);
	}
}

BEUtil.getElementsByClass = function (clsName, obj, targets/*Array object*/) {
	var arr = [];
	targets = targets||[];
	obj = obj||document;
	var pattern = new RegExp("(^|\\s)" + clsName + "(\\s|$)");
	var elems = obj.getElementsByTagName("*");
	for (var a = 0; (elem = elems[a]); a++ ){
		if (pattern.test(elem.className)){
			if (targets.length != 0) {
				for (var i = 0; (target = targets[i]); i++) {
					if (elem.tagName === target) {
						arr[arr.length] = elem;
					}
				}
			} else {
				arr[arr.length] = elem;
			}
		}
	}
	return arr;
};

function confirmClick(e) {
	e = e||window.event;
	var bConfirmStatus = confirm('You are about to leave this section and will lose any information entered. Are you sure that you want to leave this page?');
	if (!bConfirmStatus) {
		if (e.preventDefault) {
			e.preventDefault();
		} else {
			e.returnValue = false;
		}
	}
}

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
		}
	else{
		window.onload = function()
			{
			oldonload();
			func();
			}
		}
	}

BEUtil.addEvent(window,'load',function() {
	var aLinks = BEUtil.getElementsByClass('confirm');
	for (var i=0; i<aLinks.length; i++) {
		BEUtil.addEvent(aLinks[i], 'click', confirmClick);
	}
});

BEUtil.addEvent(window,'unload',BEUtil.eventCache.flush);