
var doc=document;
var clAlert;
var isFocus=false;
var options = {border:1, borderStyle:"solid", borderColor:"#000000", width:320, titleColor:"#007A99", titleFontColor:"#FFFFFF", titleWeight:700, titleBorderColor:"#000000", contentColor:"#FFFFFF", contentFontColor:"#000000"};
clAlert = new Alert(options);
function Alert(options) {
	var ao = this;
	ao.version = "1.1";
	if (!window.XMLHttpRequest) {
		//simple test to check for ie6 or older browser or an older browser.
		var ie6 = true;
	}
	var aw,ab,at,ac,bc,alb,mouseX,mouseY,pe,alertY,alertX;
	if (ie6) {
		var af;
	}
	//The below code was found at Codylindley.com and is released under the same CC license
	var Client = {viewportWidth:function () {
		return self.innerWidth || (doc.documentElement.clientWidth || doc.body.clientWidth);
	}, viewportHeight:function () {
		return self.innerHeight || (doc.documentElement.clientHeight || doc.body.clientHeight);
	}, viewportSize:function () {
		return {width:this.viewportWidth(), height:this.viewportHeight()};
	}};
	//Methods
	ao.Position = rePos;
	ao.Dialog = function (title, text, button, buttonEvent) {
		if (doc.getElementById("modalWindow")) {
			return;
		}
		createWindow("dialog", title, text, button, buttonEvent);
		rePos();if (ie6) {changeSelect(true);}alb.focus();
	};
	ao.Confirm = function (title, text, button, buttonEvent, button2, button2Event) {
		if (doc.getElementById("modalWindow")) {
			return;
		}
		createWindow("confirm", title, text, button, buttonEvent, button2, button2Event);
		rePos();if (ie6) {changeSelect(true);}cb.focus();
	};
	//Functions
	function rePos() {
		var pageY = window.pageYOffset || doc.documentElement.scrollTop;
		var pageX = window.pageXOffset || doc.documentElement.scrollLeft;
		ab.style.left = (Client.viewportWidth() - ab.offsetWidth) / 2 + pageX + "px";
		ab.style.top = (Client.viewportHeight() - ab.offsetHeight) / 2 + pageY + "px";
		if (ie6) {
			af.style.left = (Client.viewportWidth() - ab.offsetWidth) / 2 + pageX + "px";
			af.style.top = (Client.viewportHeight() - ab.offsetHeight) / 2 + pageY + "px";
			af.style.height = ab.offsetHeight + "px";
			af.style.visibility = "visible";
		}
		ab.style.visibility = "visible";
	}
	function changeSelect(bool) {
		var sb = doc.getElementsByTagName("select");
		for (var i = 0; i < sb.length; i++) {
			sb[i].disabled = bool;
		}
	}
	function alarm_OK(event, on_OK) {
		if (ie6) {
			changeSelect(false);
		}
		doc.body.removeChild(aw);
		window.onscroll = null;window.onresize = null;aw = null;ab = null;at = null;ac = null;alb = null;bc = null;
		if (on_OK) {
			try {
				e = (event) ? event : window.event;
				on_OK(e);
			}catch (error) {}
		}
	}
	function alarm_CANCEL(event, on_CANCEL) {
		if (ie6) {changeSelect(false);}
		doc.body.removeChild(aw);
		window.onscroll = null;window.onresize = null;aw = null;ab = null;at = null;ac = null;alb = null;bc = null;
		if (on_CANCEL) {
			try {
				e = (event) ? event : window.event;
				on_CANCEL(e);
			}
			catch (error) {
			}
		}
	}
	function mouseDown(e) {
		e = (e == null) ? window.event : e;
		target = (e.target) ? e.target : e.srcElement;
		if (target.id == "content") {
			mouseX = e.clientX;
			mouseY = e.clientY;
			pe = target.parentNode;
			alertX = pe.style.left;
			alertY = pe.style.top;
			doc.onmousemove = mouseMove;doc.onmouseup = mouseUp; doc.onselectstart = function () {
				return false;
			};
			return false;
		}
	}
	function mouseMove(e) {
		e = (e == null) ? window.event : e;
		newX = parseInt(alertX.split("px")[0]);
		newY = parseInt(alertY.split("px")[0]);
		pe.style.left = (newX + e.clientX - mouseX) + "px";
		pe.style.top = (newY + e.clientY - mouseY) + "px";
		if (ie6) {
			af.style.left = (newX + e.clientX - mouseX) + "px";
			af.style.top = (newY + e.clientY - mouseY) + "px";
		}
	}
	function mouseUp(e) {
		e = (e == null) ? window.event : e; doc.onmousemove = null;	doc.onselectstart = null;
	}
	function createWindow(alertType, title, text, button, buttonEvent, button2, button2Event) {
		var msg = "<div style='float:left;width:35px;height:35px;'><img src='/images/alert_blue.png' style='width:35px;height:35px;padding-top:5px;padding-right:15px;' /></div><div id=\"alert_msg\" style='float:left;width:260px;margin-top:10px;margin-left:5px;margin-bottom:10px;'><p><font color='#000000'>" + text + "</font></p></div>";
		aw = doc.body.appendChild(doc.createElement("div"));
		ab = aw.appendChild(doc.createElement("div"));
		at = ab.appendChild(doc.createElement("div"));
		ac = ab.appendChild(doc.createElement("div"));
		bc = ab.appendChild(doc.createElement("div"));
		//Set up our modal Window
		aw.id = "modalWindow";
		aw.style.height = doc.documentElement.scrollHeight + "px";
		aw.style.position = "absolute";
		aw.style.width = "100%";
		aw.style.top = "0px";
		aw.style.left = "0px";
		aw.style.zIndex = "10000";
		//IE hack.  Overlap  z-index doo-dads
		aw.style.backgroundImage = "url(tp.png)";
		ab.style.visibility = "hidden";
		ab.style.position = "absolute";
		ab.style.width = options.width + "px";
		ab.style.border = options.border + "px";
		ab.style.borderStyle = options.borderStyle;
		ab.style.borderColor = options.borderColor;
		ab.style.textAlign = "center";
		ab.style.zIndex = 101;
		ab.style.background = options.contentColor;
		//Create an iframe
		if (ie6) {
			af = aw.appendChild(doc.createElement("iframe"));
			af.src = "javascript:void(0);";
			af.style.visibility = "hidden";
			af.style.position = "absolute";
			af.style.width = options.width + "px";
			af.style.zIndex = 100;
			af.frameBorder = "0";
		}
		//Create the content window
		ac = ab.appendChild(doc.createElement("div"));
		ac.style.padding = "5px";
		ac.id = "content";
		ac.style.background = options.contentColor;
		ac.style.color = options.contentFontColor;
		ac.innerHTML = msg;
		ac.style.marginBottom = "0px";
		ac.style.marginTop = "0px";
		ac.style.textAlign = "left";
		if (window.addEventListener) {
			ac.addEventListener("mousedown", function (e) {
				mouseDown(e);
			}, false);
		} else {
			ac.onmousedown = mouseDown;
		}
		//Create a button container
		bc = ab.appendChild(doc.createElement("div"));
		bc.style.background = options.contentColor;
		bc.style.marginBottom = "0px";
		bc.style.marginTop = "0px";
		bc.style.clear = "both";
		//Create a second button for confirm type
		if (alertType == "confirm") {
			cb = doc.createElement("div");
			cb.id = "btn3";
			//cb.style.background= "url(/images/btn3.jpg)";
			cb.style.cursor = "pointer";
			cb.innerHTML = "<div class='alert'>" + button2 + "</div>";
			cb.tabIndex=0;
			cb.onclick = function (event) {alarm_CANCEL(event, button2Event);};
			cb.onfocus = function (event) {isFocus=true;};
			cb.onkeypress = function (event) {if(isFocus&&(checkEnter(event)||checkSpace(event)))alarm_CANCEL(event, button2Event);};
			cb.style.marginRight = "5px";
			cb.style.marginLeft = "5px";
			cb.style.marginBottom = "5px";
			bc.appendChild(cb);
			cb.style.width = "150px";
			cb.style.height = "25px";
			cb.style.styleFloat = "right";
			cb.style.cssFloat = "right";
			cb.style.overflow = "visible";
			cb.style.zoom = "1";
			doc.getElementById("btn3").style.background= "url(/images/btn3.jpg)";
		}
		//Create our button
		alb = doc.createElement("div");
		alb.id = "btn1";
		//alb.style.background= "url(/images/btn1.jpg)";
		alb.style.cursor = "pointer";
		alb.innerHTML = "<div id='alertText' class='alert'>" + button + "</div>";
		if (alertType != "confirm")
			alb.tabIndex=0;
		else
			alb.tabIndex=1;
		alb.onclick = function (event) {alarm_OK(event, buttonEvent);};
		alb.onfocus = function (event) {isFocus=true;};
		alb.onkeypress = function (event) {if(isFocus&&(checkEnter(event)||checkSpace(event)))alarm_OK(event, buttonEvent);};
		alb.style.marginRight = "5px";
		alb.style.marginLeft = "5px";
		alb.style.marginBottom = "5px";
		alb.style.width = "83px";
		alb.style.height = "25px";
		alb.style.styleFloat = "right";
		alb.style.cssFloat = "right";
		alb.style.overflow = "visible";
		alb.style.zoom = "1";
		bc.appendChild(alb);
		doc.getElementById("btn1").style.background= "url(/images/btn1.jpg)";
		//Add event listeners
		window.onscroll = function () {
			ao.Position();
		};
		window.onresize = function () {
			ao.Position();
		};
	}
}