diversion_rates.modal_block = function(eid)
{
	//Below are the settings you can change.
	this.blocker_opacity = 50;				//A number from 1 to 100
	this.blocker_background = "#000000";	//CSS background string for blocker
	this.blocker_zindex = 5000; 			//z-index of blocker.

	//Do not change this unless you know what you're doing.
	this.blocker = null;
	this.block_id = eid;
	this.auto_focus_id = null;
	this.show_hook = null;
	this.hide_hook = null;
}

diversion_rates.modal_block.prototype.create_blocker = function() {
	this.blocker = document.createElement('div');
	var b = this.blocker;
	var c = document.body;
	var height = this.get_document_height() > this.get_window_height() ? this.get_document_height() : this.get_window_height();

	//Setup defaults for blocker
	b.style.width = this.get_window_width() + "px";
	b.style.height = height + "px";
	b.style.margin = '0';
	b.style.padding = '0';
	b.style.border = 'none';
	b.style.background = this.blocker_background;
	b.style.position = 'absolute';
	b.style.top = '0px';
	b.style.left = '0px';
	b.style.zIndex = this.blocker_zindex;

	//Blocker opacity	
	b.style.opacity = this.blocker_opacity / 100;
	b.style.filter = "alpha(opacity=" + this.blocker_opacity + ")";

	c.appendChild(b);

	return(true);
}

diversion_rates.modal_block.prototype.get_window_width = function() {
	var ret = false;

	if(window.innerWidth)
	{
		ret = document.body.clientWidth;
	}
	else
	{
		if(document.compatMode && document.compatMode != "BackCompat")
		{
			ret = document.documentElement.clientWidth;
		}
		else
		{
			ret = document.body.clientWidth;
		}
	}

	return(ret);
}

diversion_rates.modal_block.prototype.get_window_height = function() {
	var ret = false;

	if(window.innerHeight)
	{
		ret = window.innerHeight;
	}
	else
	{
		if(document.compatMode && document.compatMode != "BackCompat")
		{
			ret = document.documentElement.clientHeight;
		}
		else
		{
			ret = document.body.clientHeight;
		}
	}

	return(ret);
}

diversion_rates.modal_block.prototype.get_document_height = function() {
	var ret = false;

	if(window.innerHeight)
	{
		ret = document.documentElement.offsetHeight;
	}
	else
	{
		ret = document.body.clientHeight;
	}

	return(ret);
}

diversion_rates.modal_block.prototype.destroy_blocker = function() {
	if(this.blocker != null)
	{
		document.body.removeChild(this.blocker);
		this.blocker = null;
	}

	return(true);
}

diversion_rates.modal_block.prototype.position_block = function() {
	var e = document.getElementById(this.block_id);
	var screen_width = this.get_window_width();
	var screen_height = this.get_window_height();
	var y_offset = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;

	e.style.top = (Math.floor((screen_height - e.offsetHeight) / 2) + y_offset) + "px";
	e.style.left = Math.floor((screen_width - e.offsetWidth) / 2) + "px";

	return(true);
}

diversion_rates.modal_block.prototype.show_block = function() {
	var e = document.getElementById(this.block_id);

	e.style.display = "block";
	e.style.position = "absolute";
	e.parentNode.removeChild(e);
	document.body.appendChild(e);
	e.style.zIndex = this.blocker_zindex + 1;

	this.position_block();

	return(true);	
}

diversion_rates.modal_block.prototype.hide_block = function() {
	var e = document.getElementById(this.block_id);
	e.style.display = "none";

	return(true);	
}

diversion_rates.modal_block.prototype.set_block = function(eid) {
	this.block_id = eid;

	return(true);	
}

diversion_rates.modal_block.prototype.set_auto_focus = function(eid) {
	this.auto_focus_id = eid;

	return(true);	
}

diversion_rates.modal_block.prototype.set_show_hook = function(func) {
	this.show_hook = func;

	return(true);	
}

diversion_rates.modal_block.prototype.set_hide_hook = function(func) {
	this.hide_hook = func;

	return(true);	
}


diversion_rates.modal_block.prototype.show = function()
{
	if(this.show_hook != null)
	{
		this.show_hook();
	}

	if(this.blocker == null)
	{
		this.create_blocker();
		this.show_block();

		if(this.auto_focus_id != null)
		{
			document.getElementById(this.auto_focus_id).focus();
		}
	}

	return(true);
}

diversion_rates.modal_block.prototype.hide = function()
{
	if(this.hide_hook != null)
	{
		this.hide_hook();
	}

	this.destroy_blocker();
	this.hide_block();
}

