/*

	/global-old/global.js
	===================================
	OpenLink
	ShowImage
	GetIntFromStr
	IsSelected
	GetTrigger - used in budget.js only
	GetQueryString
	Trim
	
	Mozilla/Opera emulation prototypes:
	-----------------------------------
	insertAdjacentHTML
	insertAdjacentText
	insertAdjacentElement
*/

// Global Constants

var vbCrLf = "\r\n";
var vbTab = "\t";
var astrUrl = location.href.split("/");
var strDomain = astrUrl[0] + "//" + astrUrl[2];
var keyEnter = 13;


function OpenLink(strUrl) {
	// strips referrer
	location.href = strUrl;
}


function ShowImage(strURL, strTitle, strAlt) {
	if (strURL!="") {
		var intHeight = 200;
		var intWidth = 200;
		var intTop;
		var intLeft;
		var ImageViewer;
		var strImageViewerProperties;

		intTop = window.screen.height;
		intLeft = window.screen.width;
		strImageViewerProperties = "channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=yes,toolbar=no,top="+intTop+",left="+intLeft+",height="+intHeight+",width="+intWidth;

		ImageViewer = window.open("/Picture.asp?url="+strURL+"&title="+strTitle+"&alt="+strAlt, "ImageViewer", strImageViewerProperties);
		intTop = (window.screen.availHeight - intHeight)/2;
		intLeft = (window.screen.availWidth - intWidth)/2;

		ImageViewer.resizeTo(intWidth, intHeight);
		ImageViewer.moveTo(intLeft, intTop);
	}
}


function GetIntFromStr(str) {
	return parseInt(str.replace(/\D/g, ""));
}


function IsSelected(strA, strB) {
	if (strA == strB) {
		return " selected";
	} else {
		return "";
	}
}


function GetTrigger(evt) {
	var objEvent;
	if (!evt) {
		objEvent = event.srcElement;
	} else {
		objEvent = evt.target;
		if (objEvent.nodeType && objEvent.nodeType==3) {
			objEvent = objEvent.parentNode;
		}
	}
	return objEvent;
}


function GetQueryString(strVariable) {
	if (document.location.search.length > 0) {
		var astrQueryString = document.location.search.substr(1).split("&");
		var astrValuePair;

		for (i=0;i<astrQueryString.length;i++) {
			astrValuePair = astrQueryString[i].split("=");
			if (astrValuePair[0] == strVariable) {
				return astrValuePair[1];
			}
		}
	}
	return "";
}


function Trim(str) {
	if (str.replace(/\s/g, "") == "") return "";
	return str.replace(/^(\s*)([\W\w]*)(\b\s*$)/, "$2");
}




// Mozilla/Opera emulation prototypes

// insertAdjacentHTML()
// insertAdjacentText()
// insertAdjacentElement()

if (typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement) {
	HTMLElement.prototype.insertAdjacentElement = function (strWhere, objNode) {
		switch (strWhere){
		case "beforeBegin":
			this.parentNode.insertBefore(objNode, this)
			break;
		case "afterBegin":
			this.insertBefore(objNode, this.firstChild);
			break;
		case "beforeEnd":
			this.appendChild(objNode);
			break;
		case "afterEnd":
			if (this.nextSibling) {
				this.parentNode.insertBefore(objNode, this.nextSibling);
			} else {
				this.parentNode.appendChild(objNode);
			}
			break;
		}
	}
	HTMLElement.prototype.insertAdjacentHTML = function (strWhere, strHtml) {
		var range = this.ownerDocument.createRange();
		range.setStartBefore(this);
		var objFragment = range.createContextualFragment(strHtml);
		this.insertAdjacentElement(strWhere, objFragment)
	}
	HTMLElement.prototype.insertAdjacentText = function (strWhere, strText) {
		var objTextNode = document.createTextNode(strText)
		this.insertAdjacentElement(strWhere, objTextNode)
	}
}

