  //////////////////////////
 // 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));
};

////////////////////// DEBUG //////////////////////
function PO(objname, dest) {
	function out(s0) {
		if(io) {
			var div = document.createElement("p");
			div.innerHTML = s;
			dest.appendChild(div);
		} else {
			alert(s);
		}
	}

	var io = false;
	if(dest) {
		if(typeof dest == "string") dest = document.getElementById(dest);
		io = true;
	}

	var s = "[["+objname+"]] ->";
	var eo;
	if(typeof objname == "object") {
		eo = objname;
	} else {
		try {
			eo = eval(objname);
		} catch(e) {
			out("Initial error: " + e);
			return;
		}
	}
	var re = new RegExp('\n', 'g');
	var re_amp = new RegExp('&', 'g');
	var re_lt = new RegExp('<', 'g');
	var re_gt = new RegExp('<', 'g');
	var re_quot = new RegExp('"', 'g');

	var j = 0;
	for(var i in eo) {
		var x;
		try {
			x = eo[i];
		} catch(e) {
			x = "err: " + e;
		}
		var ss = "" + new String(x);
		ss = new String(ss).replace(re, ' ');
		if(ss.length > (io ? 128 : 64)) ss = ss.substr(0, io ? 125 : 61) + '...';
		if(io) {
			ss = ss.replace(re_amp, '&amp;').replace(re_lt, '&lt;').replace(re_gt, '&gt;').replace(re_quot, '&quot;');
			s = s + i + '=<code>' + ss + '</code> ';
		} else {
			s = s + i + '=' + ss + '   ';
		}

		if(j == 3) {
			s += io ? '<br/>' : '\n';
			j = 0;
		} else {
			j++;
		}
	}

	out(s);
}

////////////////// END DEBUG //////////////////////

  ///////////////////////////
 // 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;
	}
}

/**
 * Automatikus hájlájtos gombok kezelése.
 */
function AutoButtons() {
	var _re_autoButtons = new RegExp("\\.(jpg|jpeg|gif|png)$", 'i');

	function chg(img, src) {
		return function() {
			img.src = src;
		}
	}

	with(document.images) {
		for(var i = 0; i < length; i++) {
			var img = item(i);
			if(img.id.substring(0, 5) == "abtn_" && img.parentNode.nodeName == 'A') {
				var off = img.src;
				var on = off.replace(_re_autoButtons, "-over.$1");
				var a = img.parentNode;
				CaptureEvent(a, "mouseover", chg(img, on), true);
				CaptureEvent(a, "mouseout", chg(img, off), true);
			}
		}
	}
}

CaptureEvent(window, "load", function() { new AutoButtons(); }, true);

