/* @version 2.0.1 */
function errorHandler(text, url, lineNr) {
	var txt = 'Hiba: ' + text + "\n Sor: " + lineNr + "\n";
	txt += "\n" + url;

	var E = new MyError(txt);
	if (document.forms[0].DEBUGGING) {
		E.alert();
	} else {
		if (url && url.indexOf('inc/js/') >= 0) {
			E.errorFeedback();
		}
	}
	return true;
}
window.onerror = errorHandler;


function MyError(message){
    this.message = (message) ? message : '';
    this.sysAlert = (!window.ModalWindow);
    if (!(this.sysAlert || Error.prototype.EWin)) {
		Error.prototype.EWin = new ModalWindow('_ErrorWindow');
    }
}
MyError.prototype = new Error();

Error.prototype.isError = false;
Error.prototype.errList = [];
Error.prototype.EWin = false;
Error.prototype.errorFeedback = function() {
	if (window.AjaxUpdater) {
		AjaxUpdater.update('POST', '/_error/feedback.php?msg=' + escape(this.message.replace(/\n/gm, '<br/>')), true);
	}
}
Error.prototype.add = function(txt, input) {
	this.errList.push([txt, input]);
	this.isError = true;
}
Error.prototype.show = function() {
	if (this.errList.length > 0) {
		var err;
		for(var i=0; i<this.errList.length; i++) {
			err = this.errList[i];
			this.message += err[0] + "\n";
			if (err[1]) {
				try {
					err[1].className += " error";
					if (i == 0) {
						try{err[1].focus();} catch(e){};
					}
				} catch(e) {}
			}
		}

		this.alert();
	}
}
Error.prototype.alert = function(msg) {
	if (this.sysAlert) {
		alert(this.message);
	} else {
		Error.prototype.EWin.openWithVeil(this.message.replace(/\n/gm, '<br/>'), 'Hiba!', 0, 0);
		Error.prototype.EWin.show();
	}
}
Error.prototype.clear = function() {
	var err;
	for(var i=0; i<this.errList.length; i++) {
		err = this.errList[i];
		if (err[1] && typeof err[1].className == 'string') {
			err[1].className = err[1].className.replace(" error", '');
		}
	}
	this.isError = false;
	this.errList = [];
	this.message = '';
}
/* Demo:
	Validálás előtt, a legfelsőbb ellenőrző szinten, a korábbi hibák törlése:
	E.clear();

	validálás után:
	if (E.isError) {
		E.show();
	} else {
		//submit
	}
*/
/*
    * Error - base type for all errors. Never actually thrown by the engine.
    * EvalError - thrown when an error occurs during execution of code via eval()
    * RangeError - thrown when a number is outside the bounds of its range. For example, trying to create an array with -20 items (new Array(-20)). These occur rarely during normal execution.
    * ReferenceError - thrown when an object is expected but not available, for instance, trying to call a method on a null reference.
    * SyntaxError - thrown when the code passed into eval() has a syntax error.
    * TypeError - thrown when a variable is of an unexpected type. For example, new 10 or "prop" in true.
    * URIError - thrown when an incorrectly formatted URI string is passed into encodeURI, encodeURIComponent, decodeURI, or decodeURIComponent.


    if (E instanceof TypeError){
        //handle the error
    } else if (E instanceof ReferenceError){
        //handle the error
    } else {
        //handle all others
    }
*/