function checkDebug(text) { try { return (top.document.location.href.toLowerCase().indexOf(text.toLowerCase()) >= 0); } catch (e) { return false; } }

isIE = navigator.appName.toLowerCase().indexOf("internet explorer") >= 0;

function objExtensionAddEvent(eventName,functionToCall) {
	if (typeof this.addEventListener == "function") {
		this.addEventListener(eventName,functionToCall,true);
	} else {
		this.attachEvent("on" + eventName,functionToCall);
	}
}
function objExtensionRemoveEvent(eventName,functionToCall) {
	if (typeof this.removeEventListener == "function") {
		this.removeEventListener(eventName,functionToCall,true);
	} else {
		this.detachEvent(eventName,functionToCall);
	}
}
function objExtensionGetLocation(corner) {
	var totalOffsetTop = this.offsetTop;
	var totalOffsetLeft = this.offsetLeft;
	var op = this.offsetParent;
	while (op) {
		totalOffsetTop += op.offsetTop;
		totalOffsetLeft += op.offsetLeft;
		if (op == op.offsetParent)
			op = null;
		else
			op = op.offsetParent;
	}

	if (corner != null) {
		if (corner.toLowerCase().indexOf("b") >= 0) totalOffsetTop += this.offsetHeight;  // bottom
		if (corner.toLowerCase().indexOf("r") >= 0) totalOffsetLeft += this.offsetWidth;  // right
	}
	return [totalOffsetTop, totalOffsetLeft];
}
function objExtensionGetStyle(name) {
	try {
		var response = "";
//		alert("objExtensionGetStyle\nwindow.getComputedStyle: " + typeof window.getComputedStyle + "\nthis.currentStyle: " + this.currentStyle);
		if (typeof window.getComputedStyle != "undefined" && window.getComputedStyle) {
			var mydivstyle = window.getComputedStyle(this, "");
			response = eval("mydivstyle." + name);
		} else {
			if (typeof this.currentStyle != "undefined") {
				response = eval("this.currentStyle." + name);
			} else {
				response = eval("this.style." + name);
			}
		}
		return response;
	} catch (e) {
//		alert("error getting style\nmessage: " + e.message + "\nstyle: " + eval("this.style." + name));
		return "error: " + e.message;
	}
}
function objExtensionHide() {
	var objType = this.tagName.toLowerCase();
	if (objType != 'iframe') {
		var orig = this.getStyle('display');
		this.style.display = "none";
		return orig;
	} else { // iframes
		if (this.offsetHeight > 0) {
			this.objExtension_originalHeight = this.getStyle('height');
			this.objExtension_originalWidth  = this.getStyle('width');
		}

		this.style.overflow = 'hidden';
		this.style.width = 0;
		this.style.height = 0;
		return [this.objExtension_originalHeight,this.objExtension_originalWidth];
	}
};
function objExtensionShow() {
	var objType = this.tagName.toLowerCase();
	if (objType != 'iframe') {
		var newStyle = "block";
		switch (objType) {
			case "li"		:	newStyle = "list-item";		break;
			case "table"	:	newStyle = "table"; 		break;
			case "tr"		:	newStyle = "table-row";		break;
			case "td"		:	newStyle = "table-cell";	break;
			case "th"		:	newStyle = "table-cell";	break;
			case "tfoot"	:	newStyle = "table-footer-group"; break;
			case "thead"	:	newStyle = "table-header-group"; break;
			case "colgroup"	:	newStyle = "table-column-group"; break;
			case "caption"	:	newStyle = "caption";		break;
			case "img"		:	newStyle = "inline";		break;
		}

		try {
			this.style.display = newStyle;
		} catch (e) {
			this.style.display = "block";
		}
		return newStyle;
	} else {  // iframes
		if (typeof what.objExtension_originalHeight != "undefined") {
			this.style.height = this.objExtension_originalHeight;
			this.style.width = this.objExtension_originalWidth;
		}
		return [this.objExtension_originalHeight, this.objExtension_originalWidth];
	}
}
function objExtensionToggleDisplay() {
	var objType = this.tagName.toLowerCase();
	if (objType != 'iframe') {
		var currentStyle = this.getStyle('display');
		if (currentStyle.toLowerCase() == "none")
			this.show();
		else
			this.hide();
	} else {
		var currentHeight = this.getStyle('height').toLowerCase();
		if (this.getStyle('height').toLowerCase() == '0px')
			this.show();
		else
			this.hide();
	}
}

function objExtensionDisable(bgColor) {
	try {
		this.disabled = true;
		if (bgColor != null) {
			this.style.backgroundColor = bgColor;
		}
	} catch (e) {}
}
function objExtensionEnable(bgColor,setFocus) {
	try {
		this.disabled = false;
		if (bgColor != null) {
			this.style.backgroundColor = bgColor;
		}
		if (setFocus) {
			this.focus();
		}
	} catch (e) {}
}

function $(which) {
	if ( (typeof which == "string") || (typeof which == "String") )
		what = document.getElementById(which);
	else
		what = which;

	if ( (what != null ) && (typeof what == "object") && (what.nodeType == 1) ) {
		try {
			what.getStyle 		= objExtensionGetStyle;
			what.show 		    = objExtensionShow;
			what.hide 		    = objExtensionHide;
			what.toggleDisplay	= objExtensionToggleDisplay;
			what.addEvent     	= objExtensionAddEvent;
			what.removeEvent  	= objExtensionRemoveEvent;
			what.disable	  	= objExtensionDisable;
			what.enable			= objExtensionEnable;
			what.getLocation	= objExtensionGetLocation;
		} catch (e) {
//			alert(e.message());
		}
	}
	return what;
}
String.prototype.trim = function () {return this.replace(/^[ \t\n]*/g,'').replace(/[ \t\n]*$/g,'');}
String.prototype.substringBefore = function (text) {var loc = this.indexOf(text); return (loc == -1 ? "" : this.substr(0,loc));}
String.prototype.substringAfter  = function (text) {var loc = this.indexOf(text); return (loc == -1 ? "" : this.substr(loc+text.length));}


function getScroll() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function getMousePosition(e) {
  var xcoord, ycoord;
  if( !e ) { e = window.event; }
  if( !e ) { return; }
  if( typeof( e.pageX ) == 'number' ) {
    xcoord = e.pageX;
    ycoord = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    xcoord = e.clientX;
    ycoord = e.clientY;
    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      xcoord += document.body.scrollLeft;
      ycoord += document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      xcoord += document.documentElement.scrollLeft;
      ycoord += document.documentElement.scrollTop;
    }
  } else { return; }
  return [xcoord,ycoord];
}


function getPage(url) {
	var i = 0;

	if (window.XMLHttpRequest) {  // native XMLHttpRequest object, Mozilla, etc.
		try {
			xmlhttp = new XMLHttpRequest();
		} catch( e ) {
			xmlhttp = false
		}
	} else if (window.ActiveXObject) {	// IE/Windows ActiveX version
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlhttp = false;
			}
		}
	}
	try {
		if( xmlhttp ) {
			xmlhttp.open("GET",url,false);
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.setRequestHeader("Cache-Control", "no-cache");
			xmlhttp.send(null);
			if (xmlhttp.status == 200)
				return xmlhttp.responseText;
			else
				return "ERROR - " + xmlhttp.status + " -  " + xmlhttp.statusText;
		} else {
			return "ERROR - Browser does not support object";
		}
	} catch (e) {
		if (checkDebug("nbc1"))
			alert("NBC1 error - " + e);
		return "ERROR - Error thrown during retrieval of document: " + e.message;
	}
}

function getCookie(name) {

	try {
		var dc = document.cookie;
		var allCookies = dc.split(';');

		for (var i = 0; i < allCookies.length; i++) {
			var parts = allCookies[i].split('=');
			parts[0] = parts[0].replace(/^ /,"");
			if (parts[0] == name) {
				var returnThis = "";
				for (var j = 1; j < parts.length; j++) {
					if (returnThis != "") {
						returnThis += "=";
					}
					returnThis += parts[j];
				}
				// if any application has to ask what their branding style sheet is, and it's "ppp" they shouldn't be using it
				if ( (name == "BrandStylesheet") && returnThis.toLowerCase().indexOf("/appls/ppp/stylesf2.css") >= 0) {
					returnThis = "";
				}
				return returnThis;
			}
		}
		return "";
	} catch (e) {
		return "";
	}
}

// **************************
// *   tabs                 *
// **************************

function tabClicked(what) {

	var row = what.parentElement;
	for (var i = 0; i < row.cells.length; i++) {
		if (row.cells[i] == what) {
			row.cells[i].className = row.cells[i].className.replace(/Unselected/,"Selected");
			$("div" + row.cells[i].innerHTML).show();
		} else {
			row.cells[i].className = row.cells[i].className.replace(/Selected/,"Unselected");
			$("div" + row.cells[i].innerHTML).hide();
		}
	}


}