function PopInMessage(ContentElem, LocationX, LocationY) {
	if(typeof LocationX == "undefined" || LocationX == null) {
		var LocationX = parseInt(document.body.offsetWidth/2);
	}
	if(typeof LocationY == "undefined" || LocationX == null) {
		var LocationY = 150;
		window.scrollTo(0,0);
	}
	var box = document.createElement("div");
	box.style.position = "absolute";
	box.appendChild(ContentElem);
	
	box.style.zIndex = 500;
	if(LocationX > -1 && LocationY > -1) {
		document.body.appendChild(box);
		box.style.left = LocationX - parseInt(box.offsetWidth/2) + "px";
		box.style.top = LocationY - parseInt(box.offsetHeight/2) + "px";
		
	} else {
		document.body.appendChild(box);
		box.style.left = "200px";
		box.style.top = "200px";
	}
	
	return box;

}


function displayMessage(message, width, closeElements, LocationX, LocationY) {
	if(typeof width == "undefined") var width = 350;
	var modal = document.createElement("div");
	modal.style.zIndex = 499;
	setOpacity(modal, .3);
	modal.style.backgroundColor = "#000000";
	modal.style.position = "absolute";
	modal.style.top = "0px";
	modal.style.left = "0px";
	modal.style.width = document.body.offsetWidth + "px";
	modal.style.height = document.body.offsetHeight + "px";
	document.body.appendChild(modal);
	var div = document.createElement("div");
	div.style.fontSize = "12px";
	div.style.width = width + "px";
	var box = PopInMessage(div, LocationX, LocationY);
	
			iHTML = "<div style='width:17px;height:17px;background:url(/images/dialog/chouette/corners.png);float:left;'>";
			if(getOSFromUserAgent() == "Mac OS X") {
				iHTML += "<img src='/images/dialog/chouette/close.png' style='margin-left:-7px;margin-top:-7px;cursor:pointer;' />"
			}
			iHTML += "</div>";
			iHTML += "<div style='width:" + (width - 34) + "px;height:17px;background:url(/images/dialog/chouette/top.png);float:left;'></div>";
			iHTML += "<div style='width:17px;height:17px;background:url(/images/dialog/chouette/corners.png) 17px 0px;float:left;'>";
			if(getOSFromUserAgent() != "Mac OS X") {
				iHTML += "<img src='/images/dialog/chouette/close.png' style='margin-left:3px;margin-top:-7px;cursor:pointer;' />"
			}
			iHTML += "</div>";
			iHTML += "<div style='width:" + (width - 34) + "px;background:url(/images/dialog/chouette/side.png) top left repeat-y white;float:left;padding:0px 17px;'>";
			iHTML += "<div style='width:" + (width - 17) + "px;background:url(/images/dialog/chouette/side.png) top right repeat-y;float:left;'>";
			iHTML += "<div style='float:left;padding-bottom:51px;width:" + (width - 34) + "px;'>" + message + "</div>";
			iHTML += " </div></div>";
			iHTML += "<div style='width:17px;height:17px;background:url(/images/dialog/chouette/corners.png) 0px 17px;float:left;'></div>";
			iHTML += "<div style='width:" + (width - 34) + "px;height:17px;background:url(/images/dialog/chouette/top.png) 0px 17px;float:left;'><div style='width:" + (width - 34) + "px;height:51px;float:left;'><img src='/images/medium_chouette.png' style='display:block;margin-top:-38px;float:left;'/></div></div>";
			iHTML += "<div style='width:17px;height:17px;background:url(/images/dialog/chouette/corners.png) 17px 17px;float:left;'></div>";
			div.innerHTML = iHTML;
			
			div.getElementsByTagName("img")[0].onclick = function() {
				box.parentNode.removeChild(box);
				document.body.removeChild(modal);
			};
			
			if(typeof closeElements != "undefined") {
				for(var index in closeElements) {
					addEventSimple(document.getElementById(closeElements[index]), 'click', function() {box.parentNode.removeChild(box);	document.body.removeChild(modal);});
				}
			}
			/*
			text.getElementsByTagName("button")[0].onclick = function() {
				box.parentNode.removeChild(box);
			};
			*/
}

function getOSFromUserAgent() {
	if(navigator.userAgent.search(/Windows NT 5\.1/) != -1) 
		return "Windows XP";
	if(navigator.userAgent.search(/Windows NT 6\.0/) != -1) 
		return "Windows Vista";
	if(navigator.userAgent.search(/M(a|A)(c|C) ?OS ?X/) != -1) 
		return "Mac OS X";
	if(navigator.userAgent.search(/Linux/) != -1) 
		return "Linux";
	return "unknown";
		
}

function setOpacity(elem, op) {
	elem.style.MozOpacity = op;
	elem.style.KhtmlOpacity = op;
	elem.style.MsFilter = "progid:DXImageTransform.Microsoft.Alpha(Opacity="+parseInt(op*100)+")";
	elem.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity="+parseInt(op*100)+")";
	elem.style.opacity = op;
}

function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent) {
		obj.detachEvent('on'+evt,fn);
	}
}

