// JavaScript Document Boxes 1.0

var timers = Array();

function info_box(message, title, delay) {
	d = document;
	var id = 'info_box'+ new Date().getTime();

   if (!d.getElementById('box_background')) {
      box_background = d.createElement('div');
      box_background.id = 'box_background';
      box_background.className = 'box_background';
      box_background.style.height = d.body.offsetHeight +'px';
	  box_background.style.zIndex = "2000";
      if (get_browser() == 'explorer') box_background.style.filter = 'alpha(opacity=80)';
      else if (get_browser() == 'firefox')  box_background.style.opacity = '0.80';
      else if (get_browser() == 'safari') box_background.style.opacity = '0.80';
      else box_background.style.background = 'none';
      d.body.appendChild(box_background);
	}

   this._prototype = d.createElement('table');
	this._prototype.id = id;
	window[id] = this;
	this._prototype.className = 'box';
	this._prototype.style.zIndex = "2001";

	// Check if there is a title
	if (title.length >= 1) {
		this.row = this._prototype.insertRow(-1);
		this.cell = this.row.insertCell(-1);
		this.cell.className = 'box_title';
		this.cell.innerHTML = title;
	}

	// Message to display
	this.row = this._prototype.insertRow(-1);
	this.cell = this.row.insertCell(-1);
	this.cell.className = 'box_message';
	this.cell.innerHTML = message;

	// Button to close
	this.button = d.createElement('input');
	this.button.type = 'button';
	this.button.className = 'box_button';
	this.button.value = 'OK';
	this.button.onclick = function() { window[id].remove_box(id); }
	this.button.style.cursor = "pointer";
	this.row = this._prototype.insertRow(-1);
	this.cell = this.row.insertCell(-1);
	this.cell.style.textAlign = 'center';
	this.cell.style.paddingTop = '4px';
	this.cell.appendChild(this.button);

   var window_width = (d.documentElement && d.documentElement.clientWidth)? d.documentElement.clientWidth : d.body.clientWidth;
   var window_height = (d.documentElement && d.documentElement.clientHeight)? d.documentElement.clientHeight : d.body.clientHeight;
   var scroll_y = (d.documentElement && d.documentElement.scrollTop)? d.documentElement.scrollTop : d.body.scrollTop;

	this._prototype.style.left = '0px';
	this._prototype.style.top = scroll_y +'px';

	d.body.appendChild(this._prototype);

	this._prototype.style.left = parseInt((window_width - this._prototype.clientWidth) / 2) +'px';
	this._prototype.style.top = parseInt(((window_height - this._prototype.clientHeight) / 2) + scroll_y) +'px';

	if (delay != null) timers[id] = window.setTimeout(id +'.remove_box(\''+ id +'\')', delay);

	this.remove_box = function(id) {
		if (delay != null) clearTimeout(timers[id]);
		window[id] = null;
		d.body.removeChild(d.getElementById('box_background'));
		d.body.removeChild(d.getElementById(id));
	}

	window.focus();
	this.button.focus();
}


function question_box(message, title, yes_text, yes_function , no_text, no_function) {
	d = document;
	var id = 'question_box'+ new Date().getTime();

   if (!d.getElementById('box_background')) {
      box_background = d.createElement('div');
      box_background.id = 'box_background';
      box_background.className = 'box_background';
      box_background.style.height = d.body.offsetHeight +'px';
	  box_background.style.zIndex = "2000";
      if (get_browser() == 'explorer') box_background.style.filter = 'alpha(opacity=85)';
      else if (get_browser() == 'firefox')  box_background.style.opacity = '0.85';
      else if (get_browser() == 'safari') box_background.style.opacity = '0.85';
      else box_background.style.background = 'none';
      d.body.appendChild(box_background);
	}

   this._prototype = d.createElement('table');
	this._prototype.id = id;
	window[id] = this;
	this._prototype.className = 'box';
	this._prototype.style.zIndex = "2001";

	// Check if there is a title
	if (title.length >= 1) {
		this.row = this._prototype.insertRow(-1);
		this.cell = this.row.insertCell(-1);
		this.cell.className = 'box_title';
		this.cell.colSpan = 2;
		this.cell.innerHTML = title;
	}

	// Message to display
	this.row = this._prototype.insertRow(-1);
	this.cell = this.row.insertCell(-1);
	this.cell.className = 'box_message';
	this.cell.colSpan = 2;
	this.cell.innerHTML = message;

	// Buttons
	this.row = this._prototype.insertRow(-1);
	this.cell = this.row.insertCell(-1);
	this.cell.style.width = '50%';
	this.cell.style.textAlign = 'center';
	this.cell.style.paddingTop = '4px';
	this.button_yes = document.createElement('input');
	this.button_yes.type = 'button';
	this.button_yes.className = 'box_button';
	this.button_yes.value = yes_text;
	this.button_yes.style.cursor = "pointer";
	this.button_yes.onclick = function() {
		if (yes_function != null) yes_function();
		window[id].remove_box(id);
	}
	this.cell.appendChild(this.button_yes);
	if (no_text != null) {
		this.cell = this.row.insertCell(-1);
		this.cell.style.width = '50%';
		this.cell.style.textAlign = 'center';
		this.cell.style.paddingTop = '4px';
		this.button_no = document.createElement('input');
		this.button_no.type = 'button';
		this.button_no.className = 'box_button';
		this.button_no.value = no_text;
		this.button_no.style.cursor = "pointer";
		this.button_no.onclick = function() {
   		window[id].remove_box(id);
			if (no_function != null) no_function();
		}
		this.cell.appendChild(this.button_no);
	} else this.cell.colSpan = 2;

   var window_width = (d.documentElement && d.documentElement.clientWidth)? d.documentElement.clientWidth : d.body.clientWidth;
   var window_height = (d.documentElement && d.documentElement.clientHeight)? d.documentElement.clientHeight : d.body.clientHeight;
   var scroll_y = (d.documentElement && d.documentElement.scrollTop)? d.documentElement.scrollTop : d.body.scrollTop;

	this._prototype.style.left = '0px';
	this._prototype.style.top = scroll_y +'px';

	d.body.appendChild(this._prototype);

	this._prototype.style.left = parseInt((window_width - this._prototype.clientWidth) / 2) +'px';
	this._prototype.style.top = parseInt(((window_height - this._prototype.clientHeight) / 2) + scroll_y) +'px';

	this.remove_box = function(id) {
		window[id] = null;
		d.body.removeChild(d.getElementById('box_background'));
		d.body.removeChild(d.getElementById(id));
	}

	window.focus();
	if (no_text != null) this.button_no.focus();
	else this.button_yes.focus();
}


function loading_box(message) {
	d = document;
	var id = 'loading_box'+ new Date().getTime();

   if (!d.getElementById('box_background')) {
      box_background = d.createElement('div');
      box_background.id = 'box_background';
      box_background.className = 'box_background';
      box_background.style.height = d.body.offsetHeight +'px';
	  box_background.style.zIndex = "2000";
      if (get_browser() == 'explorer') box_background.style.filter = 'alpha(opacity=80)';
      else if (get_browser() == 'firefox')  box_background.style.opacity = '0.80';
      else if (get_browser() == 'safari') box_background.style.opacity = '0.80';
      else box_background.style.background = 'none';
      d.body.appendChild(box_background);
	}

   this._prototype = d.createElement('table');
	this._prototype.id = id;
	window[id] = this;
	this._prototype.className = 'box';
	this._prototype.style.zIndex = "2001";

	// Loading gif
	this.row = this._prototype.insertRow(-1);
	this.cell = this.row.insertCell(-1);
	this.cell.className = 'box_message';
	this.cell.innerHTML = '<img src="'+ INCPATH +'imgsv3/loading.gif" border="0" alt="" />';
	this.cell.style.paddingLeft = '16px';
   this.cell.style.paddingBottom = '12px';

	// Message to display
	this.cell = this.row.insertCell(-1);
	this.cell.className = 'box_message';
	this.cell.innerHTML = message;
   this.cell.style.paddingBottom = '12px';

   var window_width = (d.documentElement && d.documentElement.clientWidth)? d.documentElement.clientWidth : d.body.clientWidth;
   var window_height = (d.documentElement && d.documentElement.clientHeight)? d.documentElement.clientHeight : d.body.clientHeight;
   var scroll_y = (d.documentElement && d.documentElement.scrollTop)? d.documentElement.scrollTop : d.body.scrollTop;

	this._prototype.style.left = '0px';
	this._prototype.style.top = scroll_y +'px';

	d.body.appendChild(this._prototype);

	this._prototype.style.left = parseInt((window_width - this._prototype.clientWidth) / 2) +'px';
	this._prototype.style.top = parseInt(((window_height - this._prototype.clientHeight) / 2) + scroll_y) +'px';

	this.remove_box = function(id) {
		window[id] = null;
		d.body.removeChild(d.getElementById('box_background'));
		d.body.removeChild(d.getElementById(id));
	}

	return this;
}
