var XB_VER = "0.1";							// Cross-browser fuggvenygyujtemeny verziószáma
var XB_PRELOADED = new Array();             // Előbetöltött képek

var XB_POPUP_NORMAL = "location:yes;menubar:yes;resizable:yes;scrollbars:yes;status:yes;titlebar:yes;toolbar:yes;center:yes";
var XB_ISIE = (document.all);
var XB_NODETOOLTIP = null;

function getXBVer()
{
}

function showTooltip(event,owner,width,height,className,content)
{
    var left = event.clientX;
    var top = event.clientY;

    if( XB_NODETOOLTIP )
    {
        var divBox = XB_NODETOOLTIP;
        divBox.style.left = left + 2+"px";
        divBox.style.top = top + 2+"px";
    }
    else
    {
        var divBox = document.createElement("DIV");

        divBox.id = 'xbTooltip';
        divBox.style.position = "absolute";
        divBox.style.left = left + 2 + "px";
        divBox.style.top = top + 2 + "px";
        if( width )  divBox.style.width = width + "px";
        if( height ) divBox.style.height = height + "px";
        if( className ) divBox.className = className;
        divBox.innerHTML = content;

        document.body.appendChild(divBox);

        XB_NODETOOLTIP = divBox;
    }

    if( owner.setCapture )
        owner.setCapture();
    else
        event.stopPropagation();
}

function hideTooltip(event,owner)
{
    if( XB_NODETOOLTIP )
    {
        document.body.removeChild(XB_NODETOOLTIP);
        XB_NODETOOLTIP = null;
    }

    if( owner.releaseCapture )
        owner.releaseCapture();
    else
        event.stopPropagation();
}

function getCurrentStyle(element,property)
{
    if( element )
    {
        if( element.currentStyle )
            return element.currentStyle[property];

        if( document.defaultView )
        {
            try
            {
                return document.defaultView.getComputedStyle(element, null).getPropertyValue(property);
            }
            catch(e)
            {
                return '';
            }
        }

        if( element.style )
            return element.style[property];

        return '';
    }

    return null;
}

function isVisible(element)
{
    while( element )
        if( getCurrentStyle(element,'display') == "none" || getCurrentStyle(element,'visibility') == "hidden" )
            return false;
        else
            element = element.parentNode;

    return true;
}

function toAbsXPos(x)
{
    // if( document.documentElement ) x = x - 2;     in quirk mode ??
    if( document.documentElement ) x = x - 0;
    x = x + getScrollLeft();

    return x;
}

function toAbsYPos(y)
{
    // if( document.documentElement ) y = y - 2;     in quirk mode ??
    y = y + getScrollTop();

    return y;
}

function pointInRect(point,rect)
{
    return ( (point.x >= rect.left) && (point.x <= rect.right) && (point.y >= rect.top) && (point.y <= rect.bottom) );
}

function isIntersect(rect1,rect2)
{
    return (
                pointInRect( {"x":rect1.left, "y":rect1.top}, rect2 ) ||
                pointInRect( {"x":rect1.right,"y":rect1.top}, rect2 ) ||
                pointInRect( {"x":rect1.left, "y":rect1.bottom}, rect2 ) ||
                pointInRect( {"x":rect1.right,"y":rect1.bottom}, rect2 ) ||

                pointInRect( {"x":rect2.left, "y":rect2.top}, rect1 ) ||
                pointInRect( {"x":rect2.right,"y":rect2.top}, rect1 ) ||
                pointInRect( {"x":rect2.left, "y":rect2.bottom}, rect1 ) ||
                pointInRect( {"x":rect2.right,"y":rect2.bottom}, rect1 )
            );
}

function isEqualRect(rect1,rect2)
{
	return (
				(rect1.left == rect2.left) &&
				(rect1.top == rect2.top) &&
				(rect1.right == rect2.right) &&
				(rect1.bottom == rect2.bottom)
			);
}

function getScrollLeft()
{
    if (self.pageXOffset) // all except Explorer
    	return self.pageXOffset;
    if (document.documentElement && document.documentElement.scrollLeft)
    	return document.documentElement.scrollLeft;
    if (document.body) // all other Explorers
        return document.body.scrollLeft;

    return 0;
}

function getScrollTop()
{
    if (self.pageYOffset) // all except Explorer
    	return self.pageYOffset;
    if (document.documentElement && document.documentElement.scrollTop)
    	return document.documentElement.scrollTop;
    if (document.body) // all other Explorers
    	return document.body.scrollTop;
    return 0;
}

function getScrollWidth()
{
    if (self.pageYOffset) // all except Explorer
    	return self.pageYOffset;
    if (document.documentElement && document.documentElement.scrollWidth)
    	return document.documentElement.scrollWidth;
    if (document.body) // all other Explorers
    	return document.body.scrollWidth;
    return 0;
}

function getScrollHeight()
{
    if (document.documentElement && document.documentElement.scrollHeight)
    	return document.documentElement.scrollHeight;
    if (document.body) // all other Explorers
    	return document.body.scrollHeight;
    return 0;
}

function getBlockLeft(node)
{
	var bcr = node.getBoundingClientRect();
	return toAbsXPos(bcr.left);
}

function getBlockTop(node)
{
	var bcr = node.getBoundingClientRect();
	return toAbsYPos(bcr.top);
}

function getBlockWidth(node)
{
    return node.offsetWidth;
}

function getBlockHeight(node)
{
	var bcr = node.getBoundingClientRect();
	return (bcr.bottom - bcr.top);
}

function getBlockRect(node)
{
   var result = {
                    "left"   : getBlockLeft(node),
                    "top"    : getBlockTop(node),
                    "right"  : getBlockLeft(node) + getBlockWidth(node),
                    "bottom" : getBlockTop(node) + getBlockHeight(node)
                 };

    return result;
}


function setBlockLeft(node,left)
{
    node.style.left = left + "px";
}

function setBlockTop(node,top)
{
    node.style.top = top + "px";
}


function setBlockWidth(node,width)
{
    var temp = node.offsetWidth - node.clientWidth;
    temp += intVal(node.currentStyle.paddingLeft);
    temp += intVal(node.currentStyle.paddingRight);
	var w = width - temp; if( w < 0 ) w = 0;
	node.style.width = w + "px";
}

function setBlockHeight(node,height)
{
    var temp = node.offsetHeight - node.clientHeight;
    temp += intVal(node.currentStyle.paddingTop);
    temp += intVal(node.currentStyle.paddingBottom);
	var h = height - temp; if( h < 0 ) h = 0;
    node.style.height = h + "px";
}

function showBlock(node,bShow)
{
	node.style.display = (bShow) ? 'block' : 'none';
	node.style.visibility = (bShow) ? 'visible' : 'hidden';
}

function displayBlock(node,bShow)
{
	node.style.visibility = (bShow) ? 'visible' : 'hidden';
}

function isBlockVisible(node)
{
	return ( (node.style.visibility != "hidden") && (node.style.display != "none") )
}

function setBlockHTML(node,html)
{
	node.innerHMTL = html;
}

function getScrollLeft()
{
    if (self.pageXOffset) // all except Explorer
    	return self.pageXOffset;
    if (document.documentElement && document.documentElement.scrollLeft)
    	return document.documentElement.scrollLeft;
    if (document.body) // all other Explorers
        return document.body.scrollLeft;

    return 0;
}

function getWindowWidth()
{
    if (self.innerHeight)
        return x = self.innerWidth;
    if (document.documentElement && document.documentElement.clientHeight)
	    return document.documentElement.clientWidth-4;
    if (document.body)
        return document.body.clientWidth;

    return 0;
}

function getWindowHeight()
{
    if (self.innerHeight)
	    return self.innerHeight;
    if (document.documentElement && document.documentElement.clientHeight)
	    return document.documentElement.clientHeight;
    if (document.body)
	    return document.body.clientHeight;

    return 0;
}

function getScrollTop()
{
    if (self.pageYOffset) // all except Explorer
    	return self.pageYOffset;
    if (document.documentElement && document.documentElement.scrollTop)
    	return document.documentElement.scrollTop;
    if (document.body) // all other Explorers
    	return document.body.scrollTop;

    return 0;
}

function intVal(val)
{
    var result = parseInt(val);
    if( isNaN(result) )
        return 0;

    return result;
}

function getEbyID(elementID)
{
    return document.getElementById(elementID);
}

function getEbyTag(tagName,parent)
{
    if( parent == undefined )
        parent = document;
    return parent.getElementsByTagName(tagName);
}

function addEvent(target,eventName,handlerObj,handlerName)
{
    var attachEvent = (target.attachEvent) ? true : false;
    var addEventList = (target.addEventListener) ? true : false;
    switch( true )
    {
        case ((handlerObj) && (attachEvent)) :  var res = target.attachEvent("on" + eventName, function(e){return handlerObj[handlerName](e);});
                                                return res;
                                                break;
        case ((!handlerObj)&& (attachEvent)) :  var res = target.attachEvent("on" + eventName, handlerName);
                                                return res;
                                                break;
        case ((handlerObj) && (addEventList)) : target.addEventListener(eventName, function(e){return handlerObj[handlerName](e);},false);
                                                return true;
                                                break;
        case ((!handlerObj) && (addEventList)): target.addEventListener(eventName, handlerName, false);
                                                return true;
                                                break;
        default                              :  return false;
                                                break;
    }
}

function mapIEEventProp(prop)
{
    switch( prop )
    {
        case 'target'   :   return 'srcElement';
        default         :   return prop;
    }
}

function getEventProp(evt,prop)
{
    if( XB_ISIE )
        return evt[ mapIEEventProp(prop) ];
    else
        return evt[prop];
}

function loadJavascript(src)
{
	fileref = document.createElement('script')
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", src);
	document.getElementsByTagName("head").item(0).appendChild(fileref)
}

function loadCSS(src)
{
	fileref = document.createElement('link')
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", src);
	document.getElementsByTagName("head").item(0).appendChild(fileref)
}

//  param:
//	 to_name
//	 to_email
//   subject
//   body
//	 cc
//	 bcc
function composeEmailTo(param)
{
	try
	{
		var opt_params = ['subject','body','cc','bcc'];

		if( param.to_name )
			var res = "mailto:" + param.to_name + "<"+param.to_email+">";
		else
			var res = "mailto:" + param.to_email;

		var res_params = "";

		if( param['body'] )
			param['body'] = param['body'].replace(/\r/g,"").replace(/\n/g,"\x0d\x0a");

		for(var i = 0; i < opt_params.length; i++)
			if( param[opt_params[i]] != undefined )
				res_params += opt_params[i] + "=" + encodeURIComponent(param[opt_params[i]]) + "&";

		if( res_params != "" )
			res = res + "?" + res_params;

		return res;
	} catch (e) {alert("composeEmailTo ["+e+"]")};
}

// paramStr:
//  left
//  top
//  center [yes/no]

//  fullscreen [yes/no]
//  location [yes/no]
//  menubar [yes/no]
//  resizable [yes/no]
//  scrollbars [yes/no]
//  status [yes/no]
//  titlebar [yes/no]
//  toolbar [yes/no]


function openPopupPage(url,wndName,width,height,paramStr, returnWithInstane)
{
	var res 	= [];
	var left	= 10;
	var top		= 10;
	var sb		= false;
	var mb		= false;
	var op = (navigator.userAgent.search("Opera")!=-1);
	var ms = (navigator.userAgent.search("MSIE")!=-1) && (!op);

	var	param = paramStr.split(";");
	for(var i in param)
	{
		var nam = param[i].split(":")[0].toLowerCase();
		var val = param[i].split(":")[1];

		switch( nam )
		{
			case "fullscreen" 	: res.push("fullscreen="+val);	break;
			case "location" 	: res.push("location="+val);	break;
			case "menubar" 		: res.push("menubar="+val);
								  mb=(val == 'yes');			break;
			case "resizable" 	: res.push("resizable="+val);	break;
			case "scrollbars" 	: res.push("scrollbars="+val);
								  sb=(val == 'yes');			break;
			case "status" 		: res.push("status="+val);		break;
			case "titlebar" 	: res.push("titlebar="+val);	break;
			case "toolbar" 		: res.push("toolbar="+val);		break;
			case "left"			: left	= val; break;
			case "top"			: top 	= val; break;
			case "center"		: if( val == 'yes' )
								  {
								  	left= Math.round((screen.width - width)/2);
									top	= Math.round((screen.height - height)/2);
								  }
								  break;
		}
	}

	if( ms )
	{
		width	+= (sb) ? 13 : -4;
		height	+= (sb) ? 0 : -4;
		if( mb ) height -= 20;
	}

	res.push("width="+width);
	res.push("height="+height);
	res.push("left="+left);
	res.push("top="+top);

	var win = window.open(url, wndName, res.join(","));
	win.focus();

	if( returnWithInstane )
		return win;
}

// enlargeImage('images/image.jpg');
// enlargeImage('images/image.jpg','800x*');
// enlargeImage('images/image.jpg','*x600');
// enlargeImage('images/image.jpg','800x600');
function enlargeImage(url, limit)
{
		try{ appImgZoomWnd.close() } catch(e) {};

		appImgZoomWnd = openPopupPage('','IMGZOOM',195,150,"scrollbars:yes;resizable:yes;center:yes", true);

		if( limit )
		{
			var xLimit = limit.split('x')[0];if( xLimit == '*' ) xLimit = 0;
			var yLimit = limit.split('x')[1];if( yLimit == '*' ) yLimit = 0;
		}

		var src = "";
		src += '<html><title>Kép nagyítva</title>';
		src += '<head>';
		src += ' <script type="text/javascript">';
		src += ' var NS = (navigator.appName=="Netscape")?true:false;';
		src += ' function init() {';
		src += ' xLimit = '+xLimit+';';
		src += ' yLimit = '+yLimit+';';
		src += ' iWidth = (NS)?window.innerWidth:document.body.clientWidth;';
		src += ' iHeight = (NS)?window.innerHeight:document.body.clientHeight;';
		src += '  var img=document.images[0];';
		src += '  if( img && img.width && img.height ) {';
		src += '	if( xLimit && (xLimit < img.width) ) {img.height *= xLimit/img.width;img.width = xLimit;} ';
		src += '	if( yLimit && (yLimit < img.height) ) {img.width *= yLimit/img.height;img.height = yLimit;} ';
		src += '	var dw=img.width-iWidth; var dh=img.height-iHeight;';
		src += '	window.moveBy(-dw/2,-dh/2);';
		src += '	window.resizeBy(dw,dh);';
		src += '  } else setTimeout("init()",50);';
		src += ' }';
		src += ' </'+'script>';
		src += '</head>';
		src += '<body onload="init()" style="margin:0px;padding: 0px;overflow:scroll;text-align:center;"><img onclick="window.close()" title="bezár" src="'+url+'" border="0" style="cursor:pointer;margin:0px;padding:0px;"></body>';
		src += '</html>';
		appImgZoomWnd.document.open("text/html", "replace");
		appImgZoomWnd.document.write(src);
		appImgZoomWnd.document.close();
}

function scaleDim(width,height,maxWidth,maxHeight)
{
	tempWidth = width;
	tempHeight = height;
	tempRatio = tempWidth / tempHeight;

	if( (tempWidth > maxWidth) || (tempHeight > maxHeight) )
	{
		if(tempWidth > maxWidth)
		{
			tempWidth = maxWidth;
			tempHeight = tempWidth / tempRatio;
		}

		if(tempHeight > maxHeight)
		{
			tempHeight = maxHeight;
			tempWidth = tempHeight * tempRatio;
		}
	}

	return { "width" : Math.round(tempWidth), "height" : Math.round(tempHeight) };
}

function createPreviewImage(nodeTempImg,nodeImg,maxWidth,maxHeight)
{
	nodeImg.src = nodeTempImg.src;
	tempWidth = nodeTempImg.width;
	tempHeight = nodeTempImg.height;
	tempRatio = tempWidth / tempHeight;

	if( (tempWidth > maxWidth) || (tempHeight > maxHeight) )
	{
		if(tempWidth > maxWidth)
		{
			tempWidth = maxWidth;
			tempHeight = tempWidth / tempRatio;
		}

		if(tempHeight > maxHeight)
		{
			tempHeight = maxHeight;
			tempWidth = tempHeight * tempRatio;
		}
	}

	nodeImg.style.width = tempWidth;
	nodeImg.style.height = tempHeight;
	nodeImg.style.borderStyle = "solid";
	nodeImg.style.borderWidth = "1px";
	nodeImg.style.borderColor = "#000000";
}

function previewImage(inputFile,idImg,maxWidth,maxHeight)
{
	var nodeImg = document.getElementById(idImg);
	if( nodeImg )
	{
		var filename = "file:///" + inputFile.value;
		var nodeTemp = new Image();
		nodeTemp.onload = function(){createPreviewImage(this,nodeImg,maxWidth,maxHeight);};
		nodeTemp.src = filename;
	}
}

function getUnitFromCSSLength(value,defUnit)
{
	value = value.toString();
	value = value.toUpperCase();
	if( value.indexOf("PX") != -1 )	return "px";
	if( value.indexOf("MM") != -1 )	return "mm";
	if( value.indexOf("CM") != -1 )	return "cm";
	if( value.indexOf("EM") != -1 )	return "em";
	if( value.indexOf("EX") != -1 )	return "ex";
	if( value.indexOf("PC") != -1 )	return "pc";
	if( value.indexOf("PT") != -1 )	return "pt";
	if( value.indexOf("IN") != -1 )	return "in";

	return defUnit;
}

function preloadImages()
{
    for (var i = 0; i < arguments.length; i++)
    {
        XB_PRELOADED[i] = document.createElement('img');
        XB_PRELOADED[i].setAttribute('src',arguments[i]);
    };
};

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG()
{
    for(var i=0; i<document.images.length; i++)
      {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
    	 var imgID = (img.id) ? "id='" + img.id + "' " : ""
    	 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
    	 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
    	 var imgStyle = "display:inline-block;" + img.style.cssText
    	 if (img.align == "left") imgStyle = "float:left;" + imgStyle
    	 if (img.align == "right") imgStyle = "float:right;" + imgStyle
    	 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
    	 var strNewHTML = "<span " + imgID + imgClass + imgTitle
    	 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
    	 + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>"
    	 img.outerHTML = strNewHTML
    	 i = i-1
         }
      }
}

function getCookie(NameOfCookie)
{
	// First we check to see if there is a cookie stored.
	// Otherwise the length of document.cookie would be zero.

	if (document.cookie.length > 0)
	{
		// Second we check to see if the cookie's name is stored in the
		// "document.cookie" object for the page.

		// Since more than one cookie can be set on a
		// single page it is possible that our cookie
		// is not present, even though the "document.cookie" object
		// is not just an empty text.
		// If our cookie name is not present the value -1 is stored
		// in the variable called "begin".

		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) // Note: != means "is not equal to"
		{
			// Our cookie was set.
			// The value stored in the cookie is returned from the function.

			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}

	// Our cookie was not set.
	// The value "null" is returned from the function.
	return null;
}

function setCookie(NameOfCookie, value, expiredays)
{
	// Three variables are used to set the new cookie.
	// The name of the cookie, the value to be stored,
	// and finally the number of days until the cookie expires.
	// The first lines in the function convert
	// the number of days to a valid date.

	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	// The next line stores the cookie, simply by assigning
	// the values to the "document.cookie" object.
	// Note the date is converted to Greenwich Mean time using
	// the "toGMTstring()" function.

	document.cookie = NameOfCookie + "=" + escape(value) +
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie)
{
	// The function simply checks to see if the cookie is set.
	// If so, the expiration date is set to Jan. 1st 1970.

	if (getCookie(NameOfCookie))
	{
		document.cookie = NameOfCookie + "=" +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function fixBGCache()
{
    try
    {
      document.execCommand("BackgroundImageCache", false, true);
    }
    catch(err) {}
}


if( window.attachEvent )
    window.attachEvent("onload", correctPNG);

if( window.attachEvent )
    window.attachEvent("onload", fixBGCache);