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_POPUP_PRINT = "location:no;menubar:yes;resizable:yes;scrollbars:yes;status:yes;titlebar:no;toolbar:no;center:yes";
var XB_ISIE = (navigator.appName == "Microsoft Internet Explorer") && !((window['opera'] && opera.buildNumber));
var XB_ISIE_7_UP = XB_ISIE && getBrowser().ver >= 7;
var XB_NODETOOLTIP = null;

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["ifUploadAttachment","ifUploadVideo"];

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var XB_IFRAMEHIDE="yes";

var XB_FFVERSION=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var XB_IFEXTRAHIGH=parseFloat(XB_FFVERSION)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers

var XB_SPACER = '';

var xb_tabctrl = {};

function getXBVer()
{
}

function fetchDbgText(obj,level,maxlevel)
{
    if( level > maxlevel )
        return "Printing aborted, too much recursion";
        
    var str = "<ul>";
    for(e in obj)
        str += "<li>" + e + ": " + ((isObject(obj[e]) ? fetchDbgText(obj[e],level+1,maxlevel) : obj[e])) + "</li>";            
    str += "</ul>";
    
    return str;
}

function showDbgProp(obj,maxlevel)
{
    if( isUndefined(maxlevel) )
        maxlevel = 4;
    var wnd = openPopupPage('','SHOWPROP',400,400,"center:yes;fullscreen:no;location:no;menubar:no;resizable:yes;scrollbars:yes;status:no;titlebar:no;toolbar:no",true);
    wnd.document.write(fetchDbgText(obj,1,maxlevel));
}
function showDbgText(str)
{
    var wnd = openPopupPage('','SHOWPROP',400,400,"center:yes;fullscreen:no;location:no;menubar:no;resizable:yes;scrollbars:yes;status:no;titlebar:no;toolbar:no",true);
    wnd.document.write('<textarea>');
    wnd.document.write(str);
    wnd.document.write('</textarea>');
}


function showTooltip(event,owner,width,height,className,content, offsetLeft, offsetTop)
{
    var left = toAbsXPos(event.clientX);
    var top = toAbsYPos(event.clientY);
    offsetLeft  = (typeof offsetLeft != 'undefined' ? parseInt(offsetLeft) : 0);
    offsetTop   = (typeof offsetTop != 'undefined' ? parseInt(offsetTop) : 0);

    if( XB_NODETOOLTIP )
    {
        var divBox = XB_NODETOOLTIP;
        divBox.style.left = left + 2 +offsetLeft+"px";
        divBox.style.top = top + 2+offsetTop+"px";
    }
    else
    {
        var divBox = document.createElement("DIV");

        divBox.id = 'xbTooltip';
        divBox.style.position = "absolute";
        divBox.style.left = left + 2 +offsetLeft+ "px";
        divBox.style.top = top + 2 +offsetTop+ "px";
        if( width )  
            divBox.style.width = width + (isNaN(width) ? "" : "px");
        if( height ) 
            divBox.style.height = height + (isNaN(height) ? "" : "px");
        if( className ) divBox.className = className;
        divBox.innerHTML = content;

        document.body.appendChild(divBox);


        XB_NODETOOLTIP = divBox;
    }

    if(divBox.offsetWidth + left + offsetLeft + 10 > document.body.clientWidth)
    {
        divBox.style.left = left - divBox.offsetWidth - offsetLeft + 'px';
    }

    if(divBox.offsetHeight + top + offsetTop + 10 > document.documentElement.clientHeight + document.documentElement.scrollTop)
    {
        divBox.style.top = top - divBox.offsetHeight - offsetTop + 'px';
    }

    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)
{
    if( !element )
        return false;

    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 ( XB_ISIE && getBrowser().ver == 6) // Internet Explorer 6
		return document.body.scrollHeight;
	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 getOffsetTop(node)
{
    if( node.offsetParent )
        return node.offsetTop + getOffsetTop(node.offsetParent);

    return node.offsetTop;
}

function getOffsetLeft(node)
{
    if( node.offsetParent )
        return node.offsetLeft + getOffsetLeft(node.offsetParent);

    return node.offsetLeft;
}

function getOffsetWidth(node)
{
    return node.offsetWidth;
}

function getOffsetHeight(node)
{
    return node.offsetHeight;
}

function showBlock(node,bShow)
{
    if( node )
    {
	   node.style.display = (bShow) ? 'block' : 'none';
	   node.style.visibility = (bShow) ? 'visible' : 'hidden';
	}
}

function showRow(row,bShow)
{
    if( bShow )
        row.style.display = "";
    else
        row.style.display = "none";

}

function displayBlock(node,bShow)
{
    if( node )
    	node.style.visibility = (bShow) ? 'visible' : 'hidden';
}

function flipBlock(nodeID)
{
    var node = getEbyID(nodeID);
    if( node )
        showBlock(node,!isVisible(node));
}

function setBlockHTML(node,html)
{
	node.innerHMTL = html;
}

function getScrollLeft()
{
    if (self.pageXOffset) // all except Explorer
    	return self.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft)
    	return document.documentElement.scrollLeft;
    else if (document.body) // all other Explorers
        return document.body.scrollLeft;

    return 0;
}

function getWindowWidth()
{
    if (self.innerWidth)
        return x = self.innerWidth;
    else if (document.documentElement && document.documentElement.clientHeight)
	    return document.documentElement.clientWidth-4;
    else if (document.body)
        return document.body.clientWidth;

    return 0;
}

function getWindowHeight()
{
    if (self.innerHeight)
	    return self.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
	    return document.documentElement.clientHeight;
    else if (document.body)
	    return document.body.clientHeight;

    return 0;
}

function getScrollTop()
{
    if (self.pageYOffset) // all except Explorer
    	return self.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
    	return document.documentElement.scrollTop;
    else if (document.body) // all other Explorers
    	return document.body.scrollTop;

    return 0;
}

function resizeWindowToContent()
{
    var width = document.documentElement.clientWidth;
    var height = document.documentElement.clientHeight;

    var contentWidth = document.documentElement.scrollWidth;
    var contentHeight = document.documentElement.scrollHeight;

    window.moveBy(-(contentWidth-width),-(contentHeight-height));
    window.resizeBy(contentWidth-width,contentHeight-height);
}

function resizeIframeToContent(iframe)
{
    var nodeIframe = ( typeof(iframe) == "object" ) ? iframe : getEbyID(iframe);
	if( nodeIframe )
    {
		var doc = nodeIframe.contentWindow.document;
        if( ((doc.readyState) && (doc.readyState == "complete")) || (!doc.readyState) )
        {
		    if( navigator.userAgent.indexOf("Firefox") != -1 )
			    nodeIframe.style.display = "block";

            var ifWidth = nodeIframe.offsetWidth;
            var ifHeight = nodeIframe.offsetHeight;
            var scWidth = doc.body.scrollWidth;
            var scHeight = doc.body.scrollHeight;

            if( ((doc.all) && (scWidth > ifWidth)) || ((nodeIframe.scrollMaxX != undefined) && (nodeIframe.scrollMaxX > 0)) )
                nodeIframe.style.height = (scHeight+20) + "px";
            else
                nodeIframe.style.height = scHeight + "px";
        }
    }
}

function autoResizeIframes()
{
    var dyniframe=new Array();
    for (i=0; i<iframeids.length; i++)
    {
        if (document.getElementById)
            resizeIframe(iframeids[i]);
        //reveal iframe for lower end browsers? (see var above):
        if ((document.all || document.getElementById) && XB_IFRAMEHIDE=="no")
        {
            var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i]);
            tempobj.style.display="block";
        }
    }
}

function resizeIframe(frameid)
{
    var currentfr=document.getElementById(frameid);
    if (currentfr && !window.opera)
    {
        currentfr.style.display="block";

        if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
            currentfr.style.height = (currentfr.contentDocument.body.offsetHeight+XB_IFEXTRAHIGH) + "px";
        else if (currentfr.contentWindow.document && currentfr.contentWindow.document.body && currentfr.contentWindow.document.body.scrollHeight) //ie5+ syntax
        {
            //alert(currentfr.contentWindow.parent.document.body.scrollHeight);
            //alert(frameid + "|" + currentfr.contentWindow.document.body.scrollHeight);
            currentfr.style.height = (currentfr.contentWindow.document.body.scrollHeight) + "px";
        }
        if (currentfr.addEventListener)
            currentfr.addEventListener("load", readjustIframe, false);
        else if (currentfr.attachEvent)
        {
            currentfr.detachEvent("onload", readjustIframe); // Bug fix line
            currentfr.attachEvent("onload", readjustIframe);
        }
    }
}

function readjustIframe(loadevt)
{
    var crossevt=(window.event)? event : loadevt;
    var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement;
    if (iframeroot)
        resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url)
{
    if (document.getElementById)
        document.getElementById(iframeid).src=URL;
}

function floatVal(val)
{
    val = val.toString();
    val = val.replace(/,/gi,".");
    val = val.replace(/ /gi,"");
    var result = parseFloat(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 removeEvent(target,eventName,handlerObj,handlerName)
{
    var removeEvent = (target.detachEvent) ? true : false;
    var removeEventList = (target.removeEventListener) ? true : false;
    switch( true )
    {
        case ((handlerObj) && (removeEvent)) :  var res = target.detachEvent("on" + eventName, function(e){return handlerObj[handlerName](e);});
                                                return res;
                                                break;
        case ((!handlerObj)&& (removeEvent)) :  var res = target.detachEvent("on" + eventName, handlerName);
                                                return res;
                                                break;
        case ((handlerObj) && (removeEventList)) : target.removeEventListener(eventName, function(e){return handlerObj[handlerName](e);},false);
                                                return true;
                                                break;
        case ((!handlerObj) && (removeEventList)): target.removeEventListener(eventName, handlerName, false);
                                                return true;
                                                break;
        default                              :  return false;
                                                break;
    }
}

function mapIEEventProp(prop)
{
    switch( prop )
    {
        case 'target'   :   return 'srcElement';
        default         :   return prop;
    }
}

function fireEvent(obj,eventName,param)
{
    if( obj.fireEvent )
    {
        obj.fireEvent("on" + eventName);
    }
    else
    {
        var event = document.createEvent("HTMLEvents");
        event.initEvent(eventName, true, true);
        obj.dispatchEvent(event);
    }
}

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 fullscreen  = false;
	var op = (navigator.userAgent.search("Opera")!=-1);
	var ms = (navigator.userAgent.search("MSIE")!=-1) && (!op);

	var	param = paramStr.split(";");
	for(var i=0;i < param.length;i++)
	{
		if(typeof param[i] != 'string') continue;

        var nam = param[i].split(":")[0].toLowerCase();
		var val = param[i].split(":")[1];

		switch( nam )
		{
			case "fullscreen" 	: res.push("fullscreen="+val); fullscreen = true;	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.availWidth/2 - width/2));
									top	= Math.round((screen.availHeight/2 - height/2));                                    
								  }
								  break;
		}
	}

	if( ms )
	{
		width	+= (sb) ? 13 : -4;
		height	+= (sb) ? 0 : -4;
		if( mb ) height -= 20;
	}

    if(fullscreen)
    {
        width = screen.availWidth;
        height = screen.availHeight;
        left = 0;
        top = 0;
    }
	res.push("width="+width);
    res.push("height="+height);
    res.push("left="+left);
    res.push("top="+top);


	var win = window.open(url, wndName, res.join(","));
	if( win )
        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,"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 enlargeFlash(url, width, height)
{
		try{ appImgZoomWnd.close() } catch(e) {};

		appImgZoomWnd = openPopupPage('','FLASHZOOM',width,height,"center:yes", true);

		var src = "";
		src += '<html><title>Flash</title>';
		src += '<head>';
		src += '</head>';
		src += '<body style="margin:0px;padding: 0px;overflow:scroll;text-align:center;">';
		src += ' <script type="text/javascript">';
        src += 'document.write(\'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" align="middle" >\');';
        src += 'document.write(\'<param name="allowScriptAccess" value="sameDomain" />\');';
        src += 'document.write(\'<param name="movie" value="'+url+'" />\');';
        src += 'document.write(\'<param name="quality" value="high" />\');';
        src += 'document.write(\'<param name="bgcolor" value="#ffffff" />\');';
        src += 'document.write(\'<embed src="'+url+'" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\');';
        src += 'document.write(\'</object>\');';
		src += ' </'+'script>';
		src += '</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;
		  if (img.useMap)
		  {
			 strAddMap = "<img style=\"display:block;position:relative;top:-" + img.height + "px;margin-bottom:-"+img.height+"px;"
			 + "height:" + img.height + "px;width:" + img.width +"px\" "
			 + "src=\"" + XB_SPACER + "\" usemap=\"" + img.useMap
			 + "\" border=\"" + img.border + "\">";
		  }
		  var strNewHTML = "<span " + imgID + imgClass + imgTitle
//		  + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		  + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		  + "filter:" + "progid:DXImageTransform.Microsoft.AlphaImageLoader"
		  + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
		  if (img.useMap) strNewHTML += strAddMap;
		  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() + "; path=/");
}

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; path=/";
	}
}

function utf8_encode(string)
{
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}

	return utftext
}


function parseURL(url)
{
	var res = {};

	var url = url.toString();

	if(url.length == 0)
		eval('throw "Invalid URL ['+url+'];');

	res.url		= url;
	res.port	= -1;
	res.query	= (res.url.indexOf('?') >= 0) ? res.url.substring(res.url.indexOf('?')+1) : '';

	if(res.query.indexOf('#') >= 0)
			res.query=res.query.substring(0,res.query.indexOf('#'));

	res.protocol	= '';
	res.host		= '';
	var protocolSepIndex = res.url.indexOf('://');

	if(protocolSepIndex >= 0)
	{
		res.protocol	= res.url.substring(0,protocolSepIndex).toLowerCase();
		res.host		= res.url.substring(protocolSepIndex+3);

		if(res.host.indexOf('/')>=0)
			res.host = res.host.substring(0,res.host.indexOf('/'));

		var atIndex = res.host.indexOf('@');

		if(atIndex >= 0)
		{
			var credentials	= res.host.substring(0,atIndex);
			var colonIndex	= credentials.indexOf(':');
			if(colonIndex >= 0)
			{
				res.username = credentials.substring(0,colonIndex);
				res.password = credentials.substring(colonIndex);
			}
			else
			{
				res.username = credentials;
			}
			res.host = res.host.substring(atIndex+1);
		}

		var portColonIndex = res.host.indexOf(':');

		if(portColonIndex >= 0)
		{
			res.port = res.host.substring(portColonIndex);
			res.host = res.host.substring(0,portColonIndex);
		}

		res.file = res.url.substring(protocolSepIndex+3);
		res.file = res.file.substring(res.file.indexOf('/'));

	}
	else
	{
		res.file = res.url;
	}

	if(res.file.indexOf('?') >= 0)
		res.file = res.file.substring(0, res.file.indexOf('?'));

	var refSepIndex = url.indexOf('#');

	if(refSepIndex >= 0)
	{
		res.file		= res.file.substring(0,refSepIndex);
		res.reference	= res.url.substring(res.url.indexOf('#'));
	}
	else
	{
		res.reference='';
	}

	res.path = res.file;
	if(res.query.length > 0)
		res.file += '?'+res.query;

	if(res.reference.length > 0)
		res.file += '#'+res.reference;


	res.arguments = [];
	if( res.query )
	{
		var list = res.query.split("&");
		for(var i=0;i<list.length;i++)
		{
			try {
				res.arguments.push({
					name	: list[i].split("=")[0],
					value	: list[i].split("=")[1]
				});
			} catch(e) {};
		}
	}

	return res;
}


function composeURL(param)
{
	var res = "";
	if( param.protocol )
		res = param.protocol + "://";

	if( param.username )
	{
		if( param.password )
			res += param.username+":"+param.password+"@";
		else
			res += param.username+"@"+res;
	}

	if( param.host )
		res += param.host;

	if( param.path )
		res += param.path;
	else
		res += "/";

	if( param.arguments && param.arguments.length )
	{
		var list = [];
		for(var i=0;i<param.arguments.length;i++)
		{
			if( param.arguments[i].value != undefined )
				list.push(param.arguments[i].name+"="+param.arguments[i].value);
			else
				list.push(param.arguments[i].name+"=");
		}

		res += "?" + list.join('&');
	}

	if( param.port && (param.port > 0) )
		res += ":"+param.port;

	if( param.reference )
		res += param.reference;

	return res;
}

function getURLArgument(url,name,def)
{
    var url = parseURL(url)

    for( var i=0; i < url.arguments.length; i++)
        if( url.arguments[i].name == name )
			return url.arguments[i].value;
	
	return def;
}

function setURLArgument(url,name,value)
{
    var url = parseURL(url)

    var idx = -1;
    for( var i=0; i < url.arguments.length; i++)
        if( url.arguments[i].name == name )
            idx = i;
            
    if( isNull(value) )
    {
        var args = new Array();
        for( var i=0; i < url.arguments.length; i++)
            if( url.arguments[i].name != name )
                args.push({
        					"name"	: url.arguments[i].name,
        					"value"	: url.arguments[i].value
        				});
        url.arguments = args;
    }
    else
    {
        if( idx == -1 )
            url.arguments.push({
    					"name"	: name,
    					"value"	: value
    				});
        else
            url.arguments[idx].value = value;
    }

    return composeURL(url);
}

function getRedirectURL(url,urlargs)
{
    if( isNull(url) )
        url = window.location.href;

    if( !isNull(urlargs) )
        for(arg in urlargs)  
            if( !isFunction(urlargs[arg]) )
                url = setURLArgument(url,arg,urlargs[arg]);
            
    return url;
}

function redirectLocation(url,urlargs)
{
    if( isUndefined(url) )
        url = null;
    if( isUndefined(urlargs) )
        urlargs = null;
    window.location = getRedirectURL(url,urlargs);    
}

function hideTab(name,index)
{
	var tabtitle = getEbyID("tabtitle_" + name + index);
	var tab = getEbyID("tab_" + name + index);

	if(tabtitle)
		tabtitle.className = "tabctrl-inactivetitle";

	if(tab)
	   showBlock(tab,false);

	xb_tabctrl[name] = 0;
}

function showSavedTab(name,defindex)
{
	var lastTabIdx = getCookie('tabctrlLastTabIdx_'+name);
	if( (lastTabIdx == '') || (lastTabIdx == null) )
		lastTabIdx = defindex;
	xb_tabctrl = {name:lastTabIdx};
	showTab(name,lastTabIdx);
}

function getActiveTabIndex(name)
{
	return xb_tabctrl[name];
}

function showTab(name,index)
{
	var tabtitle = getEbyID("tabtitle_" + name + index);
	var tab = getEbyID("tab_" + name + index);

    if(xb_tabctrl[name] > 0)
		hideTab(name,xb_tabctrl[name]);

	if(tabtitle)
		tabtitle.className = "tabctrl-activetitle";

	if(tab)
	   showBlock(tab,true);

	xb_tabctrl[name] = index;
	setCookie('tabctrlLastTabIdx_'+name,index,1);
}

function fixBGCache()
{
    try
    {
      document.execCommand("BackgroundImageCache", false, true);
    }
    catch(err) {}
}


function addIframeUnderlay(id_node, zIndex)
{
	if( !XB_ISIE )
		return true;

	var node = document.getElementById(id_node);
	if( node )
	{
		var id_underlay = "__IFU_"+id_node;
		var underlay = document.getElementById(id_underlay);
		if( underlay == null )
		{
			underlay = document.createElement('iframe');
			underlay.id = id_underlay;
			underlay.frameBorder = 0;
			underlay.style.position = "absolute";
			underlay.style.top = "0px";
			underlay.style.left = "0px";
			underlay.style.visibility = "hidden";
			underlay.style.filter = "alpha(opacity=0)";
			if( zIndex )
				underlay.style.zIndex = zIndex;
			else
				underlay.style.zIndex = 1;

			if( document.body.firstChild )
				document.body.insertBefore(underlay, document.body.firstChild);
			else
				document.body.appendChild(underlay);
		}

		var left = node.offsetLeft;
		for(var temp=node;temp.offsetParent;temp = temp.offsetParent)
			if( temp.style.position != "absolute" )
				left += temp.offsetLeft;

		var top = node.offsetTop;
		for(var temp=node;temp.offsetParent;temp = temp.offsetParent)
			if( temp.style.position != "absolute" )
				top += temp.offsetTop;

		underlay.style.left			= left + "px";
		underlay.style.top			= top + "px";
		underlay.style.width		= node.offsetWidth+"px";
		underlay.style.height		= node.offsetHeight+"px";
		underlay.style.visibility	= "visible";
	}

	return true;
}

function delIframeUnderlay(id_node)
{
	if( !XB_ISIE )
		return true;

	var node = document.getElementById(id_node);
	if( node )
	{
		var id_underlay = "__IFU_"+id_node;
		var underlay = document.getElementById(id_underlay);
		if( underlay )
		{
			underlay.parentNode.removeChild(underlay);
		}
	}

	return true;
}

function formatNumber(a, b, c, d)
{
	// number_format(number, decimals, comma, formatSeparator), thanks for Mathias (http://mathiasbynens.be)
	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = a + '';
	f = e.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < b)
	{
		g = f[1];
		for(i = f[1].length + 1; i <= b; i++)
			g += '0';
		f[1] = g;
	}
	if(d != '' && f[0].length > 3)
	{
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3)
		{
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '': c;
	var result = f[0] + c + f[1];
	if( a < 0 )
	    result = result.replace('- ','-');
	return result;
}

function insertText(obj, txt)
{
    var obj = ( typeof(obj) == "object" ) ? obj : getEbyID(obj);

    if( obj )
    {
    	obj.focus();


    	var	back = 0;

    	if( document.selection )
    	{
    		obj.caretPos = document.selection.createRange();

    		if ( obj.caretPos )
    		{
    			obj.caretPos.text = txt;
    			obj.caretPos.move('character',-back);
    			obj.caretPos.select();
    		}
    		else
    		{
    			obj.value = obj.value + txt;

    			var Sel = document.selection.createRange ();

    			Sel.move('character', -back);
    			Sel.select();
    		}
    	}
    	else
    	{
    		otext = obj.value;
    		ss = obj.selectionStart;

    		obj.value = otext.substring(0,ss) + txt + otext.substring(ss,obj.value.length);
    		obj.selectionStart = ss + txt.length - back;
    		obj.selectionEnd = obj.selectionStart;
    	}

    	return true;
    }

    return false;
}

function getFormData(form)
{
    var result = {};

    for(var i = 0;i < form.elements.length; i++)
    {
        var element = form.elements[i];
        switch( element.tagName.toUpperCase() )
        {
            case 'SELECT'   :   result[element.name] = (element.options.length > 0) ? element.options[element.selectedIndex].value : '';
                                break;
            case 'INPUT'    :   switch( element.type.toUpperCase() )
                                {
                                    case 'TEXT' :   result[element.name] = element.value;
                                                    break;
                                    case 'RADIO':   if(element.checked)
                                                        result[element.name] = element.value;
                                                    break;
                                }
                                break;
        }
    }

    return result;
}

function inArray(obj,value)
{
    for(i in obj)
        if( obj[i] == value )
            return true;

    return false;
}


if( XB_ISIE && !XB_ISIE_7_UP)
    window.attachEvent("onload", correctPNG);

if( window.attachEvent )
    window.attachEvent("onload", fixBGCache);

if (window.addEventListener)
    window.addEventListener("load", autoResizeIframes, false);
else if (window.attachEvent)
    window.attachEvent("onload", autoResizeIframes);
else
    window.onload=autoResizeIframes;