var Cathmhaol = window.Cathmhaol || {};

/**
* @library     Cathmhaol.Error
* @description Creates an error object.
* @author      Robert King
*
* @example     try { //code } catch(err) { var oError = new Cathmhaol.Error(); oError.raise(err, "my code", 1000); }
*/
Cathmhaol.Error = function() {
	this.clear();
};

Cathmhaol.Error.prototype = {
	/**
	* @method      clear
	* @description Clears the error detail
	* @returns {void}
	*/
	clear: function() {
		this.source = "";
		this.description = "Unspecified Error";
		this.errNumber = 0;
	},

	/**
	* @property    description
	* @description The description of the error.
	* @type {string}
	*/
	description: null,

	/**
	* @property    errNumber
	* @description The number of the error
	* @type {integer}
	*/
	errNumber: null,

	/**
	* @method      raise
	* @description Raises and error and shows it
	* @returns {void}
	* @param {object} objError    Error object
	* @param {string} source      A string describing the source of the error
	* @param {integer} errNumber  An integer representing the error
	*/
	raise: function(objError, source, errNumber) {
		window.status = "";
		if (source) { this.source = source; }
		if (objError) { this.description = (objError.description ? objError.description : objError); }
		if (errNumber) { this.errNumber = errNumber; }
		this.show();
	},

	/**
	* @method      show
	* @description Displays the error
	* @returns {void}
	*/
	show: function() {
		window.status = "";
		alert("ERROR"+(this.errNumber !=0 ? " #"+this.errNumber : "")+"\n\n"+(this.source != "" ? "SOURCE: "+this.source+"\n\n" : "")+this.description);
	},

	/**
	* @property    source
	* @description The source of the error
	* @type {string}
	*/
	source: null
};
