  //////////////////////////
 // The global variables //
//////////////////////////
var is = new function() {
	var agent = navigator.userAgent.toLowerCase();
	this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
	this.ie = (agent.indexOf("msie") != -1);
	this.o = (agent.indexOf("opera") != -1);
	var nav = navigator.appVersion.toLowerCase();
	this.ie6 = (this.ie && (nav.indexOf('msie 6.0') != -1));
	this.ie7 = (this.ie && (nav.indexOf('msie 7.0') != -1));
};

  ///////////////////////////
 // Nagyon Common rutinok //
///////////////////////////
function nop() {
}

function GetComputedStyle(e) {
	return is.ie ? e.currentStyle : window.getComputedStyle(e, null);
}

function GetBounds(e) {
	var x = 0;
	var y = 0;
	var w = e.offsetWidth;
	var h = e.offsetHeight;

	while(e != null) {
		x += e.offsetLeft;
		y += e.offsetTop;
/*		if(is.ie) {
			webxPrintLog("|-" + e.nodeName + (e.id ? '#' + e.id : '') + (e.className ? '.' + e.className : '') + ' (' + e.offsetLeft + ';' + e.offsetTop + ';' + e.clientLeft + ';' + e.clientTop + ')');
		} */
		if(is.ie && e.nodeName == 'TD') { // IE hack, nem biztos, hogy jó.
			x += e.clientLeft;
			y += e.clientTop;
		}
		e = e.offsetParent;
	}

//	webxPrintlnLog();
	return { "x": x, "y": y, "w": w, "h": h };
}

function OverElement(ss, x, y) {
	var pos = GetBounds(ss);
	var x0 = pos.x
	var x1 = x0 + pos.w;
	var y0 = pos.y;
	var y1 = y0 + pos.h;
	return x > x0 && x < x1 && y > y0 && y < y1;
}

/*function openPopup(htmname, winname, xs, ys, plus) {
	return window.open(htmname, winname, "width="+xs+",height="+ys+",screenX=1,screenY=1,status=0,resizable=0"+plus);
}*/

function openPopupN(htmname, winname, xs, ys, plus) {
	var w = window.open(htmname, winname, "width="+xs+",height="+ys+",screenX=1,screenY=1,status=0,resizable=0"+plus);
	w.focus();
}

function setCookie(name, value, days, path, domain, secure) {
	var c = name + "=" + escape(value);
	if(days && days >= 0) {
		var d = new Date();
		d.setTime(d.getTime()+(days*24*60*60*1000));
		c += "; expires=" + d.toGMTString();
	}
	if(path) c += "; path=" + path;
	if(domain) c += "; domain=" + domain;
	if(secure) c += "; secure";
	document.cookie = c;
}

function getCookie(name, defVal) {
	if(typeof defVal == "undefined") defVal = null;

	var idx = document.cookie.indexOf(name + '=');
	if(idx == -1) return defVal;
	value = document.cookie.substring(idx + name.length + 1);
	var end = value.indexOf(';');
	if(end == -1) end = value.length;
	value = unescape(value.substring(0, end));
	return value;
}

function CaptureEvent(element, event, fn, useCapture) {
	if(is.ie) {
		element.attachEvent("on" + event, fn);
	} else {
		element.addEventListener(event, fn, useCapture);
	}
}

function ReleaseEvent(element, event, fn, useCapture) {
	if(is.ie) {
		element.detachEvent("on" + event, fn);
	} else {
		element.removeEventListener(event, fn, useCapture);
	}
}

function DiscardEvent(event) {
	if(is.ie) {
		event.cancelBubble = true;
		event.returnValue = false;
	} else {
		event.preventDefault();
	}
}

Object.prototype.clone = function(deep) {
	var o = new this.constructor();
	for(i in this) {
		var e = this[i];
		var t = typeof e;
		if(t == 'function' && this.constructor.prototype[i]) continue;
		else if(deep && t == 'object') o[i] = e.clone();
		else o[i] = e;
	}
	return o;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, '');
};

if(!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(src, fromIdx) {
		for(var max = this.length, i = fromIdx ? (fromIndex < 0 ? Math.max(max - fromIndex, 0) : fromIndex) : 0; i < max; i++) {
			if(this[i] === src) return i;
		}
		return -1;
	}
}

/**
 * JSONML funkciók, némi kiegészítéssel.
 */
function jsonML(jsonml) {
	var t = typeof jsonml;
	if(jsonml instanceof Array && jsonml.length > 0) {
		// Element
		var tag = jsonml[0].toUpperCase();
		var e;
		e = document.createElement(tag);
		if(jsonml.length > 1) {
			var i = 1;
			var ad = jsonml[1];
			if(typeof ad == 'object' && !(ad instanceof Array)) {
				// attr
				for(var a in ad) {
					if(a == 'element') {
						if(ad.element != null && typeof ad.element == 'object') {
							ad.element[ad.elementId ? ad.elementId : 'element'] = e;
						} else {
							ad.element = e;
						}
					} else if(a == 'elementId') {
						// Az "element" property feldolgozásánál kell.
					} else if(a == 'class') {
						e.className = ad[a];
					} else if(a == 'style') {
						if(is.ie) e.style.cssText = ad[a];
						else e.setAttribute('style', ad[a]);
					} else if(!ad.constructor.prototype[a]) {
//						e.setAttribute(a, ad[a]);
						e[a] = ad[a];
//						wxlog.log("attr0: " + a + ": " + e[a]);
					}
				}
				i = 2;
			}

			var e1;
			if(tag == "TABLE") {
				e1 = document.createElement("TBODY");
				e.appendChild(e1);
			} else {
				e1 = e;
			}

			for(; i < jsonml.length; i++) {
				e1.appendChild(jsonML(jsonml[i]));
			}
		}
		return e;
	} else if(t == "string" || t == "number" || t == "boolean" || (jsonml instanceof String) || (jsonml instanceof Boolean) || (jsonml instanceof Number)) {
		// Text
		return document.createTextNode(jsonml);
	}

	var e = "Hibás jsonml! Nem megfelelö tipus: " + t;
	if(typeof console != 'undefined') {
		console.error(e);
		console.trace();
	}
	throw new Error(e);
}
