/*

 külső felület
*****************************************************/
// saját folyamatjelzéses ajax osztályok:
//document.observe('dom:loaded',function() {
var ajax_init=function() {
};

var popup_data;

var getBrowserType=function() {
	// SF: mozilla/5.0 (windows; u; windows nt 5.1; hu-hu) applewebkit/525.13 (khtml, like gecko) version/3.1 safari/525.13
	// OP: opera/9.50 (windows nt 5.1; u; en)
	// CR: mozilla/5.0 (windows; u; windows nt 5.1; en-us) applewebkit/525.13 (khtml, like gecko) chrome/0.2.149.30 safari/525.13
	// FF2: mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.1.16) gecko/20080702 firefox/2.0.0.16
	// FF3: mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.9.0.3) gecko/2008092417 firefox/3.0.3
	// IE6: mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; fdm; .net clr 2.0.50727)
	// IE7: mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; fdm; .net clr 2.0.50727)
		var agt=navigator.userAgent.toLowerCase();
		var browser,version;
		
		$A([
			 /^.*(chrome)\/(\d+\.\d+).*$/
			,/^.*(firefox)\/(\d+\.\d+).*$/
			,/^.*(opera)\/(\d+\.\d+).*$/
			,/^.*version\/(\d+\.\d+).+(safari)\/.*$/
			,/^.*(msie)\s+(\d+\.\d+).*$/
		]).each(function(obj) {
			if(obj.match(agt)) {
				browser=agt.replace(obj,'$1').match(/\w+/)?agt.replace(obj,'$1'):agt.replace(obj,'$2');
				version=agt.replace(obj,'$1').match(/\w+/)?agt.replace(obj,'$2'):agt.replace(obj,'$1');
				throw $break;
			}
		});
		
		return [browser,version];
	}
var isBrowser=function() {
		var agt=navigator.userAgent.toLowerCase();
		return /msie\s+[78]/.test(agt) || /gecko.*[23]\.0/.test(agt) || /chrome/.test(agt);
	};
var isIE7=function() {
		var agt=navigator.userAgent.toLowerCase();
		return /msie\s+[7]/.test(agt);
	};
var isIE6=function() {
		var agt=navigator.userAgent.toLowerCase();
		return /msie\s+[6]/.test(agt);
	};
//if(!isBrowser()) Effect.Opacity=function(obj,par) { $(obj).setOpacity($H(par).get('to')); };
var dw=function(txt) { document.write(txt || ''); };
var dwn=function(txt) { dw(txt+'<br>'); };

var showwnd=function(url,wnd,width,height) {
		return window.open(url,'',"width="+width+",height="+height+",left="+((screen.width-width)/2)+",top="+((screen.height-height)/2));
	};

var checkDate=function(date) {
	return (/^[12][\d]{3}-((1[0-2])|0[\d])-((3[01])|([0-2][0-9]))$/).match(date);
	};

var checkEmail=function(email) {
	return (/^[A-Z0-9+._-]+@[A-Z0-9][A-Z0-9.-]{0,63}[A-Z0-9]\.[A-Z.]{2,8}$/i).match(email);
	};

var content_dopage=function(_link) {
		try { $('mypanel_float').remove(); } catch(e) { }
		try {
			new Ajax.Updater('main_content_frame',_link,{ 
					 method: 'post'
					,evalScripts: true
					,onComplete: reload_median
				});
		} catch(e) { }
	};
	
var changeRegion=function(_rid,_seltext,_hungary) {
		$('regionid').value=_rid==0?1:_rid;
		new Ajax.Updater('region','ajax.php'+(_seltext?'?profile_selector_text='+_seltext:'')+(_hungary?'&hungary_only=true':''), { 
			method: 'post', 
			parameters: { act: 'getregions', regionid: _rid }
		});
	};

var reDrawFooterINIT=0;
var reDrawFooter=function(resize_) {
		return;
	};
var reDrawFooter1=function() {
		return;
	};

// lebegő data kiválasztó	
var change_myp=function(_th) {
		var o1=$('myp_1');
		var o2=$('myp_2');
		var co=$(_th);
		var inner='';
		var r=new Template('<div onclick="change_data(#{id});" onMouseOver="$(this).setStyle({background:\'#def\'});" onMouseOut="$(this).setStyle({background:\'transparent\'});">#{name}</div>');
		
		try { $('mypanel_float').remove(); } catch(e) { }
		if(o1==co) {
			change_data(0);		// magát akarja látni
		} else {
			if(AUTHDATAIDS.keys().size()<2) {
				inner=r.evaluate({'name':'Még nincs kedvenc adatlapod!', id: 0 });
			} else {
				AUTHDATAIDS.each(function(pair) {
					if(pair.key!=0) {
						var h=$H(pair.value);
						var name=h.get('name');
						inner+=r.evaluate({'name':name.truncate(20), id: pair.key });
					}
				});
			}
			
			var div=new Element('div',{ id: 'mypanel_float' });
			var pos=$H(o2.positionedOffset());
			var left=pos.get('left')-100;
			var top=pos.get('top')+25;
			div.setStyle({
				 'position':'absolute'
				,'top': top+'px'
				,'left': left+'px'
				,'width': '180px'
				,'overflow': 'hidden'
				});
			div.update(inner);
			$(document.body).appendChild(div);

		}
	};

// data kiválasztás
var change_data=function(id) {
		reload_median();
		var o1=$('myp_1');
		var o2=$('myp_2');
		try { $('mypanel_float').remove(); } catch(e) { }
		
		new Ajax.Request('/ajax.php',{
			 method: 'post'
			,parameters: { act: 'setAuthdataid', id: id }
			});
		
		var h=$H(AUTHDATAIDS.get(id));
		var link=id==0?'/users.php':'/data.php?act=info&dataid='+id;
		var av=$('mypanel_avatar');
		av.src=h.get('avatar');
		av.setAttribute('alt',h.get('name'));
		av.setAttribute('title',h.get('name'));
		$('mypanel_imglink').setAttribute('href',link);
		$('mypanel_score').update(h.get('score'));
		$('mypanel_name').setAttribute('href',link);//('<a href="'+link+'">'+h.get('name').escapeHTML()+'</a>');
		$('mypanel_name').update(h.get('name').escapeHTML());
		
		(id==0?o1:o2).addClassName('myps');
		(id!=0?o1:o2).removeClassName('myps');
		
		/*var star='<div class="rank_star_p"></div>';
		var star_bg='<div class="rank_star_n"></div>';
		var rank='';
		var i;
		for(i=0;i<h.get('rank');i++) rank+=star;
		for(i=0;i<5-h.get('rank');i++) rank+=star_bg;
		rank+='<div class="cb"></div>';
		$('mypanel_rank').update(rank);*/
	};

var changeMenu=function(th,_sn) {
		reload_median();
		var o=$(th);
		var onext=o.next();
		var oup=o.up();
		var sel=!onext.hasClassName('hide');
		
		$$('.ls_menu .p').each(function(obj) {
			obj.removeClassName('op');
			obj.childElements().last().addClassName('hide');
		});
		
		if(sel) {
			onext.addClassName('hide');
			oup.removeClassName('op');
		} else {
			onext.removeClassName('hide');
			oup.addClassName('op');
		}

		//new Ajax.Request('/ajax.php', { method: 'post', parameters: { act: 'menuexp', sn: _sn } } );
	};
var chgM=changeMenu;

var sendFriendRequest=function(_dataid,_userid,_ghost_authdataid) {
		_ghost_authdataid=_ghost_authdataid || '0';
		var par=$H({ 'userid': _userid, 'dataid': _dataid, 'message': $F('message'), 'ghost_authdataid': _ghost_authdataid });
		var url='/contact.php?act=dofriendrequest';
		
		new Ajax.Updater('popupcontent',url, {
			method : 'post',
			evalScripts : true,
			parameters : par
		});
	};

var encURL=function(url) {
		url=url.sub(/\+/,'$');
		url=url.sub(/\-/,'*');
		return escape(url);
	};


var articleTab=function(obj,id) {
		$$('.article_main_box').each(function(val) {
			if(!val.hasClassName('hide')) val.addClassName('hide');
		});
		$$('.article_tab_sel').each(function(val) {
			val.removeClassName('article_tab_sel');
			val.addClassName('article_tab');
		});
		
		$(obj).removeClassName('article_tab');
		$(obj).addClassName('article_tab_sel');

		try { $('article_main_box_'+id).removeClassName('hide'); } catch(e) { }
		
		var is=false;
		var first=false;
		$$('.article_main_box').each(function(obj) {
			if(!first) first=obj.id;
			if(!obj.hasClassName('hide')) is=true;
		});
		if(!is) $(first).removeClassName('hide');
	};

/* Megjelenít egy képet a képernyő közepén (a többit elsötétíti*/
var showPicture=function(url) {
		if(url == '') return false;
	    var dim=getWindowDimension();
	    var scroll=window.pageYOffset ? window.pageYOffset : 
			document.documentElement ? document.documentElement.scrollTop : 
			document.body ? document.body.scrollTop : 0;
		var div=NewTag('div',document.body);
	    div.style.position='absolute';
	    div.style.top='0px';
	    div.style.left='0px';
	    div.style.width='100%';
	    div.style.height=getDocumentHeight()+"px";
	    div.style.zIndex=10000;
	    div.style.background='black';
	    //SetOpac(div,60);
		$(div).setOpacity(0.6);

	    var img=NewTag('img',document.body);
	    img.src=url;
	    img.style.position='absolute';
	    var he=((dim.h-500)/dim.h/2)*100;
	    var we=((dim.w-500)/dim.w/2)*100;
	    img.style.top=(scroll+(dim.h-500)/2)+'px';
	    img.style.left=((dim.w-500)/2)+'px';
	    img.style.zIndex=10002;
	    img.style.border="1px solid white";
	    
	    /*img.style.padding="1px";*/
	    img.style.cursor="pointer";
	    img.style.margin="auto";
	    img.style.width="";
	    img.style.height="";
	    
	    
	    img.onclick=function() {
	        document.body.removeChild(div);
	        document.body.removeChild(this);
	        document.body.removeChild(ifr);
	    }
	    
	    img.onload=function() {
	    	ifr.style.width=img.width+'px';
	    	ifr.style.height=img.height+'px';
	    	//ifr.style.display="block";
	    	img.style.border="1px solid white";
	    }
	    
	    var ifr=NewTag('iframe',document.body);
	    ifr.style.position="absolute";
	    ifr.style.top=(scroll+(dim.h-500)/2)+'px';
	    ifr.style.left=((dim.w-500)/2)+'px';
	    ifr.style.zIndex=10001;
	    ifr.style.width=img.width;
	    ifr.style.height=img.height;
	    //ifr.style.display="none";
	    reload_median();
	};

var getWindowDimension=function() {
	    if( typeof( window.innerWidth ) == 'number' ) {
	        //Non-IE
	        w = window.innerWidth;
	        h = window.innerHeight;
	    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	        //IE 6+ in 'standards compliant mode'
	        w = document.documentElement.clientWidth;
	        h = document.documentElement.clientHeight;
	    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	        //IE 4 compatible
	        w = document.body.clientWidth;
	        h = document.body.clientHeight;
	    }
	    return {w:w,h:h};
	};

function NewTag(id, pParent, pBefore) {
    var tag = document.createElement(id);
    if(pParent != undefined) AddTag(tag, pParent, pBefore);
    return tag;
}

function AddTag(pChild, pParent, pBefore) {
    if(pBefore != undefined) InsertBefore (pParent, pChild, pBefore);
    else pParent.appendChild(pChild);
}

function getDocumentHeight() {
    var htmlheight = document.body.parentNode.scrollHeight; 
    var windowheight = window.innerHeight; 
    if ( htmlheight < windowheight ) { return windowheight; } 
    else { return htmlheight; } 
}

function showPopup(url, width, height) {
    if (popup_data!=null) hidePopup();
    
    var dim=getWindowDimension();
    var scroll=window.pageYOffset ? window.pageYOffset : 
		document.documentElement ? document.documentElement.scrollTop : 
		document.body ? document.body.scrollTop : 0;
	var div=NewTag('div',document.body);
    div.style.position='absolute';
    div.style.top='0px';
    div.style.left='0px';
    div.style.width='100%';
    div.style.height=getDocumentHeight()+"px";
    div.style.zIndex=10000;
    div.style.background='black';
    SetOpac(div,60);
	//div.setOpacity(0.6);

    var ifr=NewTag('iframe',document.body);
    ifr.style.position="absolute";
    ifr.style.top=Math.max(0,(scroll+(dim.h-height)/2))+'px';
    ifr.style.left=Math.max(0,((dim.w-width)/2))+'px';
    ifr.style.zIndex=10001;
    ifr.style.width=(width-5)+'px';
    ifr.style.height=(height-5)+'px';
    
    var content=NewTag('div',document.body);
    content.style.position="absolute";
    content.style.top=Math.max(0,(scroll+(dim.h-height)/2))+'px';
    content.style.left=Math.max(0,((dim.w-width)/2))+'px';
    content.style.zIndex=10002;
    content.style.width=width+'px';
    content.style.height=height+'px';
    content.style.background='#503e1e';
    content.style.overflow='hidden';
    content.style.border="1px solid white";
    
    var content2=NewTag('div',content);
    content2.style.width=(width-14)+'px';
    content2.style.height=(height-14)+'px';
    content2.id="popupcontent";
    content2.style.background='white';
    content2.style.overflow='hidden';
    content2.style.margin="2px";
    content2.style.padding= '5px';
    
    popup_data={'backgrnd': div, 'iframe': ifr, 'content': content};
    
    new Ajax.Updater("popupcontent",url,{method: 'get',evalScripts: true});
    reload_median();
}

function hidePopup() {
    if (popup_data!=null) {
        document.body.removeChild(popup_data.backgrnd);
        document.body.removeChild(popup_data.iframe);
        document.body.removeChild(popup_data.content);
        delete popup_data;
        popup_data=null;
    }
}

function SetOpac(block,value) {
	block.style.opacity = value/100;
	block.style.filter = 'alpha(opacity=' + value + ')';
}  

function changeCheckBox(control,checked) {
    if (checked==2) {
        var val=document.getElementById(control).checked?false:true;
    } else {
        val=(checked==0)?false:true;
    }

    $(control).checked=val;
    $(control+"_img").src="http://static.imgsrv.sporthirado.hu/"+(val?"icon_checkbox_on.gif":"icon_checkbox_off.gif");
    //new Effect.Opacity(control+'_img', { from: 0.4, to:1.0, duration: 0.5 });
}
// ---------------------------------------------

function parseToXML(req) {
	var xmlDocument;
	if (!(window.ActiveXObject)) //For motherfucking Firefox !&}>#&&@#&?&#{&@{
	{
		var responseString = req.responseText;
		var domParser = new DOMParser();
		xmlDocument = domParser.parseFromString(responseString, 'application/xml');
	}
	else xmlDocument = req.responseXML

	return xmlDocument;
}

var CACHE_videothumbs=[];
var videothumb_auto=function(_this,_maxthumb) {
	var obj=$(_this.id);
	var src=obj.getAttribute('src');
	$(obj).setAttribute('stopmovie','');
	
	var settimeid=1;
	if($(obj).getAttribute('timeidvideo')) settimeid=($(obj).getAttribute('timeidvideo')*1)+1;
	$(obj).setAttribute('timeidvideo',settimeid);
	
	// képek gyorstárazása:
	$R(1,_maxthumb).each(function(i) {
		CACHE_videothumbs[i]=new Image;
		CACHE_videothumbs[i].src=src.replace(/^(.*?_)\d+(\.jpg)$/i,'$1'+i+'$2');
	});
	
	var cur=$(obj).getAttribute('src').replace(/^.*?_(\d+)\.jpg$/i,'$1');
	if(_maxthumb>1) setTimeout('videothumb_timer('+(cur*1)+',"'+$(obj).id+'",'+_maxthumb+','+settimeid+');',600);
};

var videothumb_timer=function(_cur,_obj,_maxthumb,_timeid) {
	if($(_obj).getAttribute('timeidvideo')==_timeid) {
		if($(_obj).getAttribute('stopmovie')!='') {
			$(_obj).setAttribute('src',$(_obj).getAttribute('stopmovie'));
		} else {
			if(_cur==_maxthumb) _cur=1;
				else _cur++;
				
			var newsrc=$(_obj).getAttribute('src').replace(/^(.*?_)\d+(\.jpg)$/i,'$1'+_cur+'$2');
			$(_obj).setAttribute('src',newsrc);
			setTimeout('videothumb_timer('+_cur+',"'+$(_obj).id+'",'+_maxthumb+','+_timeid+');',1200);
		}
	}
};

function AddFavourites() { 
	title = "Sporthirado.hu";
	url = "http://sporthirado.hu";
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if (window.external) {
		window.external.AddFavorite(url, title);
	}
}
function AddHomePage() {
	var site='Sporthirado'
	if (document.all) {
		document.body.style.behavior = "url(#default#homepage)";
		document.body.setHomePage("http://"+site+".hu");
	} else {
		alert("Sajnos a b\xF6ng\xE9sz\u0151d nem t\xE1mogatja ezt a funkci\xF3t.\nHa be szeretn\xE9d \xE1ll\xEDtani az "+site+".hu-t kezd\u0151lapnak, akkor az Esz\xF6z\xF6k/Be\xE1ll\xEDt\xE1sok men\xFCpontban, a els\u0151 f\xFCln\xE9l megteheted."); 
	}
}

/*function reload_median() {
	try {
		console.log('median');
	} catch(e) { }
	return;
	
	var same=Math.floor(Math.random()*1000000);
	same=same+sameext;
	$("median").update('<img style="position:absolute;top:-100px;left:-100px" src="http://audit.median.hu/cgi-bin/track.cgi?uc=12211467718578&dc=1&ui='+same+'" width="1" height="1">');
}*/

var MAINinit=function() { 
		$$('input[type=checkbox]','input[type=radio]').invoke('setStyle',{ background: 'transparent', border: '0px'});
		setTimeout("if(isBrowser()) { initDisplayCard(); } $$('.warning_symbol').each(function(obj) { new PeriodicalExecuter(function(pe) { obj.setOpacity(obj.getOpacity()==1?0.0:1.0); },0.8); });",1500);
	};
	
var openWindow=function(url) {
		window.open(url,'farm_more','width=660,height=450,left='+((screen.width-660)/2)+',top='+((screen.height-450)/2+',scrollbars,status,resizable'));
		reload_median();
	};
var openWindow2=function(url,width,height) {
	width=width || 660;
	height=height || 450;
	window.open(url,'farm_more','width='+width+',height='+height+',left='+((screen.width-width)/2)+',top='+((screen.height-height)/2+',scrollbars,status,resizable'));
	reload_median();
}

var friendrequest_accept=function(_fid) {
		new Ajax.Request('/contact.php?act=friendrequest_accept&friendid='+_fid, {
			 onComplete: function(r) {
					$('row_'+_fid).remove();
					reload_median();
				}
			});
	};
var friendrequest_reject=function(_fid) {
		if(confirm('Biztosan el szeretnéd utasítani?')) {
			new Ajax.Request('/contact.php?act=friendrequest_reject&friendid='+_fid, {
				 onComplete: function(r) {
						$('row_'+_fid).remove();
						reload_median();
					}
				});
		}
	};
var friendrequest_del=function(_fid) {
		if(confirm('Biztosan vissza szeretnéd vonni?')) {
			new Ajax.Request('/contact.php?act=friendrequest_del&friendid='+_fid, {
				 onComplete: function(r) {
						$('row_'+_fid).remove();
						reload_median();
					}
			});
		}
	};
var popupContentChange=function(_link) {
	new Ajax.Updater('popupcontent',_link, {
			 evalScripts: true
			,onComplete: reload_median
		});
	};
	
var friend_popup_del=function(_link) {
		new Ajax.Request(_link,{ onComplete: function(t) { reload_median(); hidePopup(); }});
	};
	
var pager_friends_list=function(_p,_page,_dataselector,_forceauthdataid,_filter_name) {
		new Ajax.Updater(
			 'contact_ajax'
			,'/contact.php?act=friend_ajax&page='+_page
				+'&p='+_p+'&dataselector='+_dataselector
				+(Object.isUndefined(_forceauthdataid)?'':'&ghost_authdataid='+_forceauthdataid)
				+'&filter_name='+_filter_name
			,{ 
				 evalScripts: true
				,onComplete: reload_median
			});
	};
	
var setTRstyle=function(tr,style) {
		tr=$(tr);
		tr.childElements().each(function(obj) {
			if(obj.tagName=='TD' || obj.tagName=='TD') obj.setStyle(style);
		});
	};
	
// LEVELEK ********************************************************************************

    function mail_haschecked() {
        var hascheck=false;
        for (i=0; i<boxes.length;i++) {
            if(document.maillist.elements["selectedmail["+boxes[i]+"]"].checked) hascheck=true;
        }
        return hascheck;
    }
	
    function delmail(flag) {
        if (!mail_haschecked()) {
            alert("Legalább egy levelet ki kell jelölni!");
        } else {
            if (confirm("Biztosan törölni akarod a kijelölt leveleket?")) {
                if (flag==1) document.maillist.act.value="finaldelmail";
                else document.maillist.act.value="delmail";
                document.maillist.submit();
            }
        }
    }
    
    function movemail() {
        if (!mail_haschecked()) {
            alert("Legalább egy levelet ki kell jelölni!");
        } else {
            document.maillist.act.value="move";
            document.maillist.submit();
        }
    }

    function checkmail(val) {
        for (i=0; i<boxes.length;i++) {
            changeCheckBox("selectedmail["+boxes[i]+"]",(val?1:0));
        }
    }
	
// *******************CARD*********************************
var friend_delete=function(_userid,_dataid) {
	if(confirm('Biztosan törölni szeretnéd az ismerőseid közül?')) {
		_ghost='&ghost_authdataid='+GHOST_AUTHDATAID;
		_dataid=_dataid || '0';
		new Ajax.Request('/contact.php?act=delfriend'+_ghost, { 
			 method: 'post'
			,parameters: { userid: _userid, dataid: _dataid }
			,onComplete: function(t) { 
					$('card_'+_userid+'_'+_dataid).remove();
					reload_median();
					$('num_friends').update($('num_friends').innerHTML*1-1);
				}
			}); 
	}
}
//***********************************************************
	
var expertpages_dopage=function(_p) {
		new Ajax.Updater('ajax_content','/expert_pages.php?act=ajax_dopage&page='+_p,{ 
				 method: 'post'
				,parameters: {
					 evalScripts: true
					,onComplete: reload_median
				}});
	};
	
var change_new_tab=function(obj,id) {
		reload_median();
		$$('.article_main_box').each(function(val) {
			if(!val.hasClassName('hide')) val.addClassName('hide');
		});
		$$('.new_article_main_tab .tab').each(function(val) {
			val.removeClassName('tab');
			val.addClassName('t');
		});
		
		$(obj).removeClassName('t');
		$(obj).addClassName('tab');
		
		try { $('article_main_box_'+id).removeClassName('hide'); } catch(e) { }
	}

//***********************************************************

// kártyák kijelzése
var CACHE_card=[];
var displayCard=function(_id) {
		if(!_id.match(/^[pu]\d+$/)) return false;
		
		type=_id.replace(/^([pu])\d+$/i,'$1');
		id=_id.replace(/^[pu](\d+)$/i,'$1');
		if(type=='u') {
			userid=id;
			dataid=0;
		} else {
			userid=0;
			dataid=id;
		}
		
		if(CACHE_card[_id]) {
			$('__card_frame').update(CACHE_card[_id]);
			$('__card_frame').show();
			$('__card_frame_bg').show();
		} else new Ajax.Request('/ajax.php?act=genCard',{
				 parameters: { userid: userid, dataid: dataid }
				,method: 'post'
				,onComplete: function(t) {
						if(t.responseText!='') {
							$('__card_frame').update(t.responseText);
							CACHE_card[_id]=t.responseText;
							$('__card_frame').show();
							$('__card_frame_bg').show();
						}
					}
				});
		return true;
	};
	
var initDisplayCard=function(_filter) {
		_filter=_filter || 'a[farmcard]';
		var div=$('__card_frame') || false;
		var iframe=$('__card_frame_bg') || false;
		
		if(!Object.isElement(iframe)) {
			var _null=new Element('div');
			_null.update('<iframe frameborder="0" id="__card_frame_bg"></iframe>');
			document.body.appendChild(_null);
			iframe=$('__card_frame_bg');
			iframe.setStyle({width: '240px', height: '142px', overflow: 'hidden', position: 'absolute', 'z-index': 1000, background: 'transparent' });
			iframe.hide();
			iframe.setOpacity(0);
		}
		
		if(!Object.isElement(div)) {
			div=new Element('div');
			document.body.appendChild(iframe);
			div.setStyle({width: '240px', height: '142px', overflow: 'hidden', position: 'absolute', 'z-index': 1001, background: 'transparent' });
			div.hide();
			div.setAttribute('id','__card_frame');
			div.setOpacity(0.9);
			document.body.appendChild(div);
		}
		
		$(div).observe('mouseover',function(e) {
			$(div).hide();
			$(iframe).hide();
		});
		
		$$(_filter).each(function(evobj) {
			evobj.observe('mouseover', function(e) {
				displayCard(evobj.getAttribute('farmcard'));
			});
			evobj.observe('mouseout',function(e) {
				$(div).hide();
				$(iframe).hide();
			});
			evobj.observe('mousemove',function(e) {
				$(div).setStyle({ left: (Event.pointerX(e)+15)+'px', top: (Event.pointerY(e)+15)+'px' });
				$(iframe).setStyle({ left: (Event.pointerX(e)+15)+'px', top: (Event.pointerY(e)+15)+'px' });
			});
		});
	};
	
var calendarEvents=function() {
		var div=$('__calendar_js_frame');
		if(!div) { 
			div=new Element('div');
			$(div).hide();
			$(div).setStyle({ 'z-index': 1001 });
			$(div).addClassName('calendar_js_frame');
			$(div).setOpacity(0.90);
			$(div).setAttribute('id','__calendar_js_frame');
			document.body.appendChild(div);
		}
		
		$$('.calendar_cube').each(function(obj) {
			if(!$(obj).hasClassName('calendar_cube_set')) return;
			
			$(obj).observe('mouseover', function(e) {
				if(obj.getAttribute('caltext')=='') return;
				var ox=Event.pointerX(e)+300>document.viewport.getWidth()?-300+20:-20;
				$(div).setStyle({ left: (Event.pointerX(e)+ox)+'px', top: (Event.pointerY(e)+20)+'px' });
				var html=obj.getAttribute('caltext').split('|');
				html='<ul><li>'+html.join('<li>')+'</ul>';
				$(div).update(html);
				$(div).show();
			});
			$(obj).observe('mouseout',function(e) {
				$(div).hide();
				$(div).update('');
			});
			$(obj).observe('mousemove',function(e) {
				var ox=Event.pointerX(e)+300>document.viewport.getWidth()?-300+20:-20;
				$(div).setStyle({ left: (Event.pointerX(e)+ox)+'px', top: (Event.pointerY(e)+20)+'px' });
			});
		});
	};
	
/* tools ----------------------------------*/
/* tools end ------------------------------*/

/* start flash detect functions */

function Flashdetect()
{
	this.ver= [-1,0,0];
}

Flashdetect.prototype.getversion = function()
{
	this.ver= [-1,0,0];
	if(navigator.plugins && navigator.mimeTypes.length)
	{
		var x=navigator.plugins["Shockwave Flash"];
		if(x && x.description)
		{
			this.ver = (x.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));
		}
	}
	else
	{
		try
		{
			var axObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for(var i=3;axObj!=null;i++)
			{
				axObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				this.ver = [i,0,0];
			}
		}
		catch(e){}
	}
	if(axObj)axObj = null;
}

Flashdetect.prototype.version= function()
{
	if(this.ver[0] == -1)
	{
	    this.getversion();
	}
	return (this.ver[0]*1);
}

Flashdetect.prototype.enabled= function()
{
	var must_ver = 1;
	if(arguments.length==1)must_ver = arguments[0];
	if(this.ver[0] == -1)
	{
	    this.getversion();
	}
	return (this.ver[0]*1>=must_ver);
}
/* end flash detect functions */


//-------------------------------------------------
function forum_cell_width()
{
	if($$('[_forum="width"]').first())
	{
		var cell_width = $$('[_forum="width"]').first().getWidth()-12;
		$$('.forum_csop_cim div').invoke('setStyle',{width:cell_width+"px"});
	}
}

function topic_to_fav(topicid)
{
	new Ajax.Request(
		'/forum.php?act=topictofav&topicid='+topicid,{
			method:'post',
			onComplete: function(response){
       			if(response.responseText=="OK")
       				alert("Sikeresen hozzáadtad a témát a kedvencekhez!");
       			else
       				alert("Nem sikerűlt hozzáadni a témát a kedvencekhez!");
    		}
		});
}

var setRovatElements=function(th,elmid,type) {
		var rid=$F(th);
		var php='/upload'+(type==0?'img':'vid')+'.php'+'?act=dosport&id='+elmid+'&rovatid_marci='+rid;
			
		new Ajax.Request(php, {
			 method: 'post'
			,onComplete: function(r) {
				var t=r.responseText;
				if(/^ERROR3$/.match(t)) {
					if(type==0) alert("Kategórizálni csak publikus album képeit lehet!");
						else alert("Kategórizálni csak publikus album átkonvertált videóit lehet!");
					$(th).value=0;
				}
			}
		});
		
	};


var setRovatElements1=function(th,elmid,type) {
		var rid=$F(th);
		var php='/upload'+(type==0?'img':'vid')+'.php'+'?act=dosport1&id='+elmid+'&elementcat='+rid;

		new Ajax.Request(php, {
			 method: 'post'
			,onComplete: function(r) {
				var t=r.responseText;
				if(/^ERROR3$/.match(t)) {
					if(type==0) alert("Kategórizálni csak publikus album képeit lehet!");
						else alert("Kategórizálni csak publikus album átkonvertált videóit lehet!");
					$(th).value=0;
				}
			}
		});

	};

/**
 * @param	_ret	befoglaló objektum
 * @return	befoglaló objektum
 */
var ecatInput=function(_ret,_id,_type) {
		var first='- Válassz kategóriát! -';
		var html='';
		var pid=0;
		var id=_id || 0;
		var opt=$H();
		opt.set(0,first);
		var childs;
		var ret=$(_ret);
		var pname;

		ecats.each(function(pair) {
			var key=pair.key;
			var val=pair.value;
			opt.set(key,$H(val).get('name'));
			if(key==id) {
				pid=key;
				childs=Object.isArray($H(val).get('childs'))?[]:$H($H(val).get('childs'));
				pname=$H(val).get('name');
			}
			$H($H(val).get('childs')).each(function(pair1) {
				if(pair1.key==id) {
					pid=key;
					childs=$H($H(val).get('childs'));
					pname=$H(val).get('name');
				}
			});
		});

		html+='<select onChange="setRovatElements1(this,'+ret.getAttribute('_elementid')+','+_type+'); ecatInput($(this).up(),$F(this),'+_type+');" style="width:150px;">';
		opt.each(function(pair) {
			var obj=pair.value;
			var i=pair.key;
			html+='<option value="'+i+'"'+(pid==i?'selected="selected"':'')+'>'+obj+'</option>';
		});
		html+='</select>';

		if(pid && Object.isHash(childs)) {
			html+=' <select onChange="setRovatElements1(this,'+ret.getAttribute('_elementid')+','+_type+');" style="width:150px; margin-top:2px;">';
			//html+='<option value="'+pid+'">- '+pname+' -</option>'
			html+='<option value="'+pid+'">- Válassz sportágat! -</option>'
			childs.each(function(pair) {
					html+='<option value="'+pair.key+'"'+(id==pair.key?'selected="selected"':'')+'>'+$H(pair.value).get('name')+'</option>';
			});
			html+='</select>';
		}
		return $(ret).update(html);
	};

var ecatSelect=function(_ret,_id) {
		var first='- összes -';
		var html='';
		var pid=0;
		var id=_id || 0;
		var opt=$H();
		opt.set(0,first);
		var childs;
		var ret=$(_ret);
		var pname;

		ecats.each(function(pair) {
			var key=pair.key;
			var val=pair.value;
			opt.set(key,$H(val).get('name'));
			if(key==id) {
				pid=key;
				childs=Object.isArray($H(val).get('childs'))?[]:$H($H(val).get('childs'));
				pname=$H(val).get('name');
			}
			$H($H(val).get('childs')).each(function(pair1) {
				if(pair1.key==id) {
					pid=key;
					childs=$H($H(val).get('childs'));
					pname=$H(val).get('name');
				}
			});
		});

		var action;
		action=_ret.getAttribute('_action');
		html+='<select onChange="'+action+';ecatSelect($(this).up(),$F(this));" style="width:110px;">';
		opt.each(function(pair) {
			var obj=pair.value;
			var i=pair.key;
			html+='<option value="'+i+'"'+(pid==i?'selected="selected"':'')+'>'+obj+'</option>';
		});
		html+='</select>';

		if(pid && Object.isHash(childs)) {
			html+=' <select id="rovattype" onChange="'+action+'" style="width:150px; margin-top:2px;">';
			html+='<option value="'+pid+'">- összes sportág -</option>'
			childs.each(function(pair) {
					html+='<option value="'+pair.key+'"'+(id==pair.key?'selected="selected"':'')+'>'+$H(pair.value).get('name')+'</option>';
			});
			html+='</select>';
		}
		return $(ret).update(html);
	};

function echolog(_var) {
	try {
		console.log(_var);
	} catch(e) { }
}

function sales_cangeStatus(userid,set)
{
	var myAjax = new Ajax.Request
	('users.php',
		{
			method: 'post',
			parameters: 'act=setSales&userid='+userid+'&set='+set,
			asynchronous: false,
			onComplete: function(ajaxReq)
			{
				var response = ajaxReq.responseText;
				if(response != 'HIBA')
				{
					var resp_arr = response.split('|');
					$('setSalesButton_id').setAttribute('rel',resp_arr[0]);
					$('setSalesButton_id').value = resp_arr[1];
				}
			}
		}
	);
}