/*
	OXYLUS Developement web framework
	copyright (c) 2002-2007 OXYLUS Developement

	$Id: message.js,v 0.0.2 9/12/2007 20:38:15 Exp $

	Note: tested in IE 6.0 / 7.0 , MOZILLA FIREFOX, OPERA, SAFARI 3.0

	contact:
		www.oxylus.ro
		devel@oxylus.ro

		office@oxyls.ro

	ALL THIS CODE IS THE PROPERTY OF OXYLUS DEVELOPEMENT. YOU CAN'T USE ANY OF THIS CODE WITHOUT
	A WRITTEN ACCORD BETWEEN YOU AND OXYLUS DEVELOPEMENT. ALL ILLEGAL USES OF CODE WILL BE TREATED
	ACCORDING THE LAWS FROM YOUR COUNTRY.

	THANKS FOR YOUR UNDERSTANDING.
	FOR MORE INFORMATION PLEASE CONTACT US AT: office@oxylus.ro
*/


var __box_overlay = false;
var __box_html = false;
var __box_images = false;
var __box_settings = {
		"hide_body_scrooling" : false
	};

var __box_cache = {};
function ShowMessageBox(title , message , buttons) {
	__messageHtml();
	__messageOverlay();
	__messageBackground();

	var _div_main = document.getElementById("msgbox");
	var _div_title = document.getElementById("msgboxtitle");
	var _div_msg = document.getElementById("msgboxbody");
	var _div_buttons = document.getElementById("msgboxbuttons");
	var _div_overlay = document.getElementById("overlay");

	if (isIe() && (browserVersion() <= 7)) {
		_div_overlay.style.position = "absolute";
		_div_main.style.position = "absolute";

		_div_overlay.style.height = document.body.offsetHeight + "px";
		_div_overlay.style.width = document.body.offsetWidth + "px";
	}

	//window.location = window.location.href + "#";
	window.scroll(0,0);

	//try to hide the scrolling

	if (__box_settings["hide_body_scrooling"])
		try {		
			//cache the existing settings
			__box_cache["body_overflow"] = document.body.style.overflow ;
			document.body.style.overflow = "hidden";
		} catch (e) {
		}	

	_div_overlay.style.display="inline";

	//set the title
	_div_title.innerHTML = title;
	_div_msg.innerHTML = message;


	var _win = getWindowSize();
	//center the box right on the middle.
	var left = (_win["width"] / 2) - (450 / 2);
	var top = _win["height"] / 2 - 204 ;

	_div_main.style.left = parseInt(left) + "px";
	_div_main.style.top = parseInt(top)  + "px";

	//clear the existing list of buttons
	_div_buttons.innerHTML = "";

	//generate the buttons
	for (i in buttons ) {
		if (buttons[i] == "__close__") 
			buttons[i] = "javascript:HideMessageBox();";

		_div_buttons.innerHTML +=
				'<a class="btn" href="' + buttons[i] + '">' + i + '</a>';
	}

	//make the box visible
	_div_main.style.display = "block";	
}

function UserBox(id) {
	if (typeof id == "object") {
		ShowMessageBox(
				id["title"],
				id["msg"],
				id["buttons"]
			);
	} else {
		ShowMessageBox(
				__messagesBox[id]["title"],
				__messagesBox[id]["msg"],
				__messagesBox[id]["buttons"]
			);
	}
} 

function HideMessageBox() {
	document.getElementById("msgbox").style.display = "none";
	var _div_overlay = document.getElementById("overlay");
	_div_overlay.style.display="none";


	if (__box_settings["hide_body_scrooling"])
		try {		
			document.body.style.overflow = __box_cache["body_overflow"];
		} catch (e) {
		}	

}


function __messageOverlay() {
	if (__box_overlay == false) {
		__box_overlay = true;

		div_element = document.createElement("div");
		div_element.setAttribute("id" , "overlay");
		div_element.setAttribute("class" , "overlay");
		document.body.appendChild(div_element);
	}
}

function __messageHtml() {
	if (__box_html == false) {
		__box_html = true;

		div_element = document.createElement("div");
		div_element.setAttribute("id" , "msgbox");
		div_element.setAttribute("class" , "alert-box");

		document.body.appendChild(div_element);
 
		document.getElementById("msgbox").innerHTML =
		'<table cellspacing="0" cellpadding="0" class="msgbox"> ' +
		'	<tr><td id="msgboxtitle">.</td></tr>' +
		'	<tr><td id="msgboxbody"></td></tr>' +
		'	<tr><td id="msgboxbuttons"></td></tr>' +
		'	<tr><td id="msgboxfooter"></td></tr>'+
		'</table>'
	}
}


function __messageBackground() {

}


/* History 

0.0.2 
	Added support for custom messages to UserBox( {title: "" , message : "" , buttons : { ...}  } )

0.0.1
	Basic functions


*/