// Managing multiple object event
function addEvent(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		var originalEvent = obj["on" + evType];
		if (typeof obj["on" + evType] != "function") {
			obj["on" + evType] = fn;
		} else {
			obj["on" + evType] = function() {
				originalEvent();
				fn();
			}
		}
	}
}

// Image rollover and rollout functions
function imgOut(image) {
	ext = image.src.substr(image.src.lastIndexOf('.') + 1);
	image.src = image.src.replace(new RegExp('ov.' + ext + '$'), 'on.' + ext);
}

function imgOver(image) {
	ext = image.src.substr(image.src.lastIndexOf('.') + 1);
	image.src = image.src.replace(new RegExp('on.' + ext + '$'), 'ov.' + ext);
}

// Generic image popup window
function imagePopUp(imageURL,imageTitle){
	var defaultWidth  = 400;
	var defaultHeight = 500;
	var autoClose = false;
	var imgWin = openPopUpCenter("about:blank", defaultWidth, defaultHeight, "scrollbars=no");
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(400,500);');
		writeln('width=400-(document.body.clientWidth-document.images[0].width);');
		writeln('height=500-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);');
		writeln('window.moveTo(screen.width/2-width/2, screen.height/2-height/2);}');
		writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;');
		writeln('window.moveTo(screen.width/2-window.innerWidth/2, screen.height/2-window.innerHeight/2);}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!autoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
		close();
	}
}

function openPopUpCenter(pageUrl, width, height, feature) {
	feature += ",width=" + width + ",innerWidth=" + width;
	feature += ",height=" + height + ",innerHeight=" + height;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		feature += ",left=" + xc + ",screenX=" + xc;
		feature += ",top=" + yc + ",screenY=" + yc;
	}
	return window.open(pageUrl, "PopPage", feature);
}

function centerWindow() {
	var ns = (navigator.appName == "Netscape") ? true : false;
	iWidth = (ns) ? window.innerWidth : document.body.clientWidth;
	iHeight = (ns) ? window.innerHeight : document.body.clientHeight;
	window.moveTo(screen.width/2-iWidth/2, screen.height/2-iHeight/2);
	self.focus();
}

// Hint popup
function prepareHints() {
	var triggerList = [
		{tagName:"input", displayEvent:"focus", hideEvent:"blur"},
		{tagName:"select", displayEvent:"focus", hideEvent:"blur"},
		{tagName:"textarea", displayEvent:"focus", hideEvent:"blur"},
		{tagName:"img", displayEvent:"mouseover", hideEvent:"mouseout"},
		{tagName:"a", displayEvent:"mouseover", hideEvent:"mouseout"}
	];
	for(var i = 0; i < triggerList.length; i++) {
		var trigger = triggerList[i];
		var triggerElements = document.getElementsByTagName(trigger.tagName);
		for (var j = 0; j < triggerElements.length; j++){
			var triggerObj = triggerElements[j];
			var hintObj = triggerObj.parentNode.getElementsByTagName("span")[0];
			if(hintObj && hintObj.className == "hint") {
				// Add pointer
				var pointer = document.createElement("span");
				pointer.className = "hint_pointer";
				pointer.innerHTML = " ";
				hintObj.appendChild(pointer);
				// Add the event
				triggerObj.hintObj = hintObj;
				addEvent(triggerObj, trigger.displayEvent, function(eventObj) {
					var thisObj = eventObj["srcElement"] ? eventObj["srcElement"] : eventObj["target"];
					thisObj.hintObj.style.display = "inline";
				}, false);
				addEvent(triggerObj, trigger.hideEvent, function(eventObj) {
					var thisObj = eventObj["srcElement"] ? eventObj["srcElement"] : eventObj["target"];
					thisObj.hintObj.style.display = "none";
				}, false);
			}
		}
	}
}
addEvent(window, "load", prepareHints, false);

function getObject(elmID) {
	if (document.getElementById) { elmID = document.getElementById(elmID); }
	else if (document.all) { elmID = document.all[elmID]; }
	else if (document.layers) { elmID = this._getLayer(elmID); }
	else if (document.forms) {
		if(document.forms[elmID]) { elmID = document.forms[elmID]; }
		else {
			for(var i=0; i<document.forms.length; i++) {
				if(document.forms[i][elmID]) {
					elmID = document.forms[i][elmID];
					break;
				}
			}
		}
	} else { elmID = null; }
	return elmID;
}