// Copyright (C) 2007 Stephane Lavergne <http://www.imars.com/>
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.

// Analogue to Google's "minimessage" concept, with an alert() fallback
// mechanism. If an HTML element with "id" is found, its contents are appended
// with a message box which the user can close. If no such element is found, a
// classic JavaScript alert is popped up instead.
//
// Each message box is of class "imars_alert_box" which displays your message
// and a hyperlink "x" designed to make the box disappear. Note that it is not
// hidden, but removed from the DOM structure completely.

imars.notifier = function(id) {
	this.c = 0;
	this.id = id;
};

imars.notifier.prototype.alert = function(msg) {
	var log = (document.getElementById && document.removeChild) ? document.getElementById(this.id) : undefined;
	if (log) {
		this.c++;
		log.innerHTML += "<div class=\"imars_alert_box\" id=\""+this.id+"_box_"+this.c+"\" style=\"position: relative; top: 0; left: 0;\">"+msg+"<div style=\"position: absolute; top: 0; right: 0;\"><a href=\"#\" style=\"text-decoration: none; \" onclick=\"var me = document.getElementById('"+this.id+"_box_"+this.c+"'); me.parentNode.removeChild(me); return false;\">x</a></div></div>\r\n";
	} else {
		alert(msg);
	};
};
