var Modal = {
	html : null,
	confirm : function(options) {
		this.close();//close if open
		this.html = document.createElement("div");
		document.body.appendChild(this.html);
		this.html = $(this.html);
		this.cancelText = options && options.cancelText ? options.cancelText : "Cancel";
		this.okText = options && options.okText ? options.okText : "Continue";
		this.html.innerHTML = "\
			<div class='modal-container'>\
				<div class='modal-mask'>" + 
					/*@cc_on 
					"<iframe frameborder='0' src='javascript:document.write(\"<html><body></body></html>\");document.close();'></iframe>" +
					@*/
				"</div>\
				<div class='modal-confirm'>\
					" + options.message + "<br>\
					<br>\
					<input class='modal-cancel-button' type='button' value='" + this.cancelText + "' />\
					<input class='modal-ok-button' type='button' value='" + this.okText + "' />\
				</div>\
			</div>\
		";
		var y = window.pageYOffset || document.documentElement.scrollTop;
		this.html.select(".modal-container").invoke("setStyle", {top : "0", left: "0"})
		this.html.select(".modal-confirm").invoke("setStyle", {
			top : ((document.viewport.getHeight() / 2) - 100 + y) + "px",
			left : ((document.viewport.getWidth() / 2) - 200) + "px"
		})
		this.html.select(".modal-mask").invoke("setStyle", {
			height : document.body.offsetHeight + "px",
			width : document.body.offsetWidth + "px"			
		})
		this.html.select(".modal-cancel-button").invoke("observe", "click", Modal.close.bind(Modal));
		this.html.select(".modal-ok-button").invoke("observe", "click", function() {
			Modal.close();
			options.callback();
		});
	},
	close : function() {
		if (this.html) {
			this.html.remove();
			this.html = null;
		}
	}
}

Event.observe(window, "load", function () {
	var AnchorArray = document.body.getElementsByTagName("a");
	for (var i=0; i < AnchorArray.length; i++) {
		var A = AnchorArray[i];
		if (String(A.href).indexOf("http") == 0 && String(A.href).indexOf(FullSiteRoot) < 0 && String(A.className).indexOf("DontParse") < 0 && String(A.href).indexOf("/community_support/events/") < 0) {
			A.onclick = function() {
				var ThisHref = this.href;
				Modal.confirm({
					cancelText : OutsideLinkBack,
					okText : OutsideLinkProceed,
					message : OutsideLinkMessage, 
					callback : function() {
						window.open(ThisHref, "");
					}
				})
				return false;
			}
		}
		
		if (typeof(pageTracker) != "undefined" && String(A.href).indexOf(siteroot + "local/files/") >= 0) {
			Event.observe(A, "click", function () {
						pageTracker._trackPageview(this.href);
						return false;
					});
		}
	}
});
