var agt = navigator.userAgent.toLowerCase();
var is_ie = agt.indexOf("msie") != -1;

try {// gecko
	window.addEventListener("load", C4_init, false);
} catch (e) {}
try {// IE
	window.attachEvent("onload", C4_init);
} catch (e) {}

function C4_init(e) {
	if (!document.getElementsByTagName) return true;

	var a = document.getElementsByTagName("a");
	for (var i=0; i<a.length; i++) {
		if (a[i].className == "pasts") {
			a[i].href = "mailto:";
			a[i].href += a[i].childNodes[0].firstChild.nodeValue;
			a[i].href += "%40";
			a[i].href += a[i].childNodes[2].firstChild.nodeValue;
		} else if (a[i].className == "jImgPopup") {
			if (a[i].target == "" || a[i].target == null) {
				a[i].target = "_jimgpopup";// _blank, if each link in new window
			}
			a[i].onclick = C4_popJImg;
		}
	}
	return true;
}

function C4_popJImg(e) {
	var img = new Image();
	img.hspace = 0;
	img.vspace = 0;

	var win = window.open(this.href, this.target, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,copyhistory=no');

	img.onerror = function() {
		win.close();
		win = window.open(this.href, this.target);
	}

	img.onabort = function() {
		win.close();
	}

	img.onload = function() {
		var w = 0;
		var hpos = 0;
		if (this.width < screen.width - 40) {
			if (is_ie) {
				w = this.width + 50;
			} else {
				w = this.width + 35;
			}
			hpos = Math.round(screen.width / 2 - w / 2);
		} else {
			w = screen.width - 20;
		}

		var h = 0;
		var vpos = 0;
		if (this.height < screen.height - 30) {
			if (is_ie) {
				h = this.height + 85;
			} else {
				h = this.height + 77;
			}
			vpos = Math.round(screen.height / 2 - h / 2);
		} else {
			h = screen.height - 100;
		}

		win.moveTo(hpos, vpos);
		win.moveTo(hpos, vpos);// need to call 2x, firefox &^*&(%*...
		win.resizeTo(w, h);
	}

	img.src = this.href;

	return false;
}


