
function openwindow_Setup() {
	var d = openwindow_getElementsByTagNames('img,span,a,p,div');
	if(d.length>0) {
		var found = false;
		for(i=0; i<d.length; i++) {
			Item = d[i];
			if(Item.getAttribute('msg') != null) {
				Item.msg = Item.getAttribute('msg');
				Item.msgClass = Item.getAttribute('msgClass');
				Item.msgTitle = Item.getAttribute('msgTitle');
				Item.msgFooter = Item.getAttribute('msgFooter');
				Item.onclick = openwindow_ShowMessage;
				found = true;
			} else if (Item.getAttribute('msgURL') != null) {
				Item.msgURL = Item.getAttribute('msgURL');
				Item.msgWidth = Item.getAttribute('msgWidth'); if(Item.msgWidth == null) Item.msgWidth = 300;
				Item.msgHeight = Item.getAttribute('msgHeight'); if(Item.msgHeight == null) Item.msgHeight = 300;
				Item.onclick = openWindow_ShowURL;
			} else if (Item.getAttribute('msgHtmlID') != null) {
				Item.msgObject = document.getElementById(Item.getAttribute('msgHtmlID'));
				if(Item.msgObject) {
					found = true;
					Item.msgWidth = Item.getAttribute('msgWidth'); if(Item.msgWidth == null) Item.msgWidth = 300;
					Item.msgHeight = Item.getAttribute('msgHeight'); if(Item.msgHeight == null) Item.msgHeight = 300;
					Item.msgClass = Item.getAttribute('msgClass');
					Item.msgStyles = Item.getAttribute('msgStyles');
					Item.msgTitle = Item.getAttribute('msgTitle'); if(Item.msgTitle == null) Item.msgTitle = '';
					v = Item.getAttribute('msgWindow'); if(v == null) v = '';
					if(v == 'window') {
						Item.onclick = openWindow_ShowURL;
					} else {
						Item.onclick = openwindow_ShowMessage;
					}
				}
			}
		}
		if(found) {
			ob = document.createElement('div');
			ob.id = 'helpObject';
			ob.close = function() { this.style.display = 'none'; }
			document.body.appendChild(ob);
		}
	}
}

function openwindow_ShowMessage(evt) {
	if(!evt) evt = event;

	d = document.getElementById('helpObject');

	d.innerHTML = '';
	d.className = 'openwindow_DIV openwindow_MessageBox';
	if(this.msgClass != null) d.className = 'openwindow_DIV ' + this.msgClass;

	if(this.msgObject != null) {
		d.innerHTML = this.msgObject.innerHTML;
	} else {
		if(this.msgTitle) d.innerHTML = '<h1>' + this.msgTitle + '</h1>';
		d.innerHTML += '<p>' + this.msg + '</p>'
		if(this.msgFooter) d.innerHTML += '<h6>' + this.msgFooter + '</h6>';
	}
		
	d.closeable = false;
	setTimeout('document.getElementById("helpObject").closeable = true;', 250);

	document.body.onclick = function() { 
		d = document.getElementById('helpObject');
		if(d.closeable) {
			d.style.display = 'none';
			document.body.onclick = null;
		}
	}

	d.style.display = 'block';

//alert(document.documentElement.scrollTop);

	scrollLeft = document.documentElement.scrollLeft + document.body.scrollLeft;
	scrollTop = document.documentElement.scrollTop + document.body.scrollTop;

	if(typeof evt.pageX != 'undefined') {
		d.style.left = (evt.pageX + '') + 'px';
		d.style.top = (evt.pageY + '') + 'px';
	} else {
		d.style.left = evt.x + scrollLeft;
		d.style.top = evt.y + scrollTop;
	}

	if(d.offsetLeft > scrollLeft + openwindow_GetWindowWidth() - d.offsetWidth - 22) {
		d.style.left = scrollLeft + openwindow_GetWindowWidth() - d.offsetWidth - 22;
	}
	if(d.offsetTop > scrollTop + openwindow_GetWindowHeight() - d.offsetHeight - 22) {
		d.style.top = scrollTop + openwindow_GetWindowHeight() - d.offsetHeight - 22;
	}
	if(d.offsetTop < 0) d.style.top = 0;
	if(d.offsetLeft < 0) d.style.left = 0;
}

function openWindow_ShowURL() {
	l = (screen.width / 2) - (this.msgWidth / 2);
	t = (screen.height / 2) - (this.msgHeight / 2);
	features = 'left=' + l + ',top=' + t + ',' + 
			   'width=' + this.msgWidth + ',height=' + this.msgHeight + 
			   ',location=no,menubar=no,resizable=yes,status=yes,titlebar=yes,toolbar=no';
	if(this.msgObject != null) {
		w = window.open('', '', features);
		w.document.open();
		w.document.write('<html><head><title>' + this.msgTitle + '</title>');
		if(this.msgStyles != null) w.document.write('<link rel=stylesheet type="text/css" href="' + this.msgStyles + '">');
		w.document.write('</head><body>' + this.msgObject.innerHTML + '</body></html>');
		w.document.close();
	} else {
		window.open(this.msgURL, '', features);
	}
}

function openwindow_getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	return resultArray;
}

function openwindow_GetWindowHeight() {
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetHeight;
	} else {
		return window.innerHeight;
	}
}

function openwindow_GetWindowWidth() {
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetWidth;
	} else {
		return window.innerWidth;
	}
}

function openwindow_AddEvent(object, eventName, fn) {
	if (document.addEventListener) object.addEventListener(eventName, fn, false);
	else object.attachEvent('on' + eventName, fn); 
}
openwindow_AddEvent(window, 'load', openwindow_Setup);

document.write('<style>.openwindow_MessageBox { background-color: #ffffcc; padding: 3px; border: solid 1px black; }' + 
			   '.openwindow_MessageBox p { margin: 0px; color: black; }' +
			   '.openwindow_DIV { position: absolute; display: none; }<\/style>');


