// éáűőúöóü
/*
 külső felület
*****************************************************/
// saját folyamatjelzéses ajax osztályok:
/*document.observe('dom:loaded',function() {
	div=new Element('div');
	div.setAttribute('id','__js_ajax_frame');
	div.setStyle({ position: 'absolute', 'zIndex':10101, padding: '2px' });
	div.update('<img src="http://static.imgsrv.farm.hu/ajax-loader.gif">');
	div.setOpacity(0.9);
	div.hide();
	div.my_state=0;
	document.body.appendChild(div);
	
	$(document.body).observe('click',function(e) {
		try {
			var div=$('__js_ajax_frame');
			if(!div) return true;
			var ox=Event.pointerX(e)+30>document.viewport.getWidth()?-20:10;
			div.setStyle({ left: (Event.pointerX(e)+ox)+'px', top: (Event.pointerY(e)+10)+'px' });
		} catch(e) { Prototype.emptyFunction(); }
	});
});
Ajax.Request=Class.create(Ajax.Request, {
		 initialize:function($super,link,opt) {
			var div=$('__js_ajax_frame');
			var state=div.my_state;
			var opt=$H(opt);
			var _onComplete=opt.clone().get('onComplete');
			
			opt.set('onComplete', function(t) {
				if(_onComplete) _onComplete(t);
				var _div=$('__js_ajax_frame');
				var _state=_div.my_state-1;
				
				_div.my_state=_state;
				if(_state==0) {
					_div.hide();
					clearTimeout(_div.my_timer);
					clearTimeout(_div.my_timer);
					clearTimeout(_div.my_timer);
				}
			});
			
			state++;
			div.my_state=state;
			if(state==1) {
				div.my_timer=setTimeout("$('__js_ajax_frame').show();",750);
				Event.observe($(document.body),'mousemove', function(e) {
					var div2=$('__js_ajax_frame');
					if(div2.my_state==0) { Event.stop(e); return; }
					var ox=Event.pointerX(e)+30>document.viewport.getWidth()?-20:10;
					div2.setStyle({ left: (Event.pointerX(e)+ox)+'px', top: (Event.pointerY(e)+10)+'px' });
				});
			}
			
			try {
				$super(link,opt.toObject());
			} catch(e) { }
		}
	});
	
Ajax.Updater=Class.create(Ajax.Updater, {
		 initialize:function($super,cont,link,opt) {
			var div=$('__js_ajax_frame');
			var state=div.my_state;
			var opt=$H(opt);
			var _onComplete=opt.clone().get('onComplete');
			
			opt.set('onComplete', function(t) {
				if(_onComplete) _onComplete(t);
				var _div=$('__js_ajax_frame');
				var _state=_div.my_state-1;
				
				_div.my_state=_state;
				if(_state==0) {
					_div.hide();
					clearTimeout(_div.my_timer);
					clearTimeout(_div.my_timer);
					clearTimeout(_div.my_timer);
				}
			});
			
			state++;
			div.my_state=state;
			if(state==1) {
				div.my_timer=setTimeout("$('__js_ajax_frame').show();",750);
				Event.observe($(document.body),'mousemove', function(e) {
					var div2=$('__js_ajax_frame');
					if(div2.my_state==0) { Event.stop(e); return; }
					var ox=Event.pointerX(e)+30>document.viewport.getWidth()?-20:10;
					div2.setStyle({ left: (Event.pointerX(e)+ox)+'px', top: (Event.pointerY(e)+10)+'px' });
				});
			}
			
			try {
				$super(cont,link,opt.toObject());
			} catch(e) { }
		}
	});*/
// --------------------------------------
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];*/
		return ['a','0'];
	}
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;
		if(reDrawFooterINIT>2) return reDrawFooter1();
		var resize=(resize_ || false);
		var bottom=10;
		if(resize) $('main_left_addsize').setStyle({ height: '' });
		var bottom1=$H($('main_left_menu').positionedOffset()).get('top')+$('main_left_menu').getHeight();
		var bottom2=$H($('main_table').positionedOffset()).get('top')+$('main_table').getHeight();
		if(bottom1<bottom2) bottom=bottom*1+bottom2;
			else bottom=bottom*1+bottom1;
		
		var height_=bottom-$H($('main_left_addsize').positionedOffset()).get('top');
		if(bottom2<=bottom1+10 || resize) 
			$('main_left_addsize').setStyle({ height: height_+'px'});
		
		reDrawFooterINIT++;
		if(reDrawFooterINIT<2) {
			setTimeout('reDrawFooter();',400);
			if($('main_content_frame').getHeight()>800) setTimeout("$('main_content_bottom_height').setStyle({ height: '3px' });",20);
		}
	};
var reDrawFooter1=function() {
		return;
		var bottom1=$H($('main_left_menu').positionedOffset()).get('top')+$('main_left_menu').getHeight();
		var bottom2=$H($('main_left_addsize').positionedOffset()).get('top')+$('main_left_addsize').getHeight();
		if(bottom2>bottom1-10 || bottom2<bottom1-10) {
			var height_=$('main_left_addsize').getHeight()-(bottom2-bottom1);
			if(height_<0) height_=0;
			$('main_left_addsize').setStyle({ height: height_+'px'});
		}
		reDrawFooterINIT++;
		if($('main_content_frame').getHeight()>800) setTimeout("$('main_content_bottom_height').setStyle({ height: '3px' });",20);
	};

var changeMyPanel=function(_th) {
		var th=$(_th);
		var inner='';
		var temp=new Template('<div class="handcursor" onclick="changeAuthPetId(#{id}); $(this).up(1).remove();" style="height:14px; width:150px; overflow:hidden; padding:2px; margin:0px 3px;"'
			+' onmouseover="$(this).setStyle({ background: \'#dd5\'});" onmouseout="$(this).setStyle({ background: \'transparent\'});">'
			+'#{name}</div>');
		
		try { $('mypanel_float').remove(); } catch(e) { }
		if(th.hasClassName('my_panel_tab_sel') && th.id=='mypanel_my') return;
		if(th.id=='mypanel_my') {
			changeAuthPetId(0);
		} else {
				if(AUTHPETIDS.keys().size()<2) inner='<div style="margin-left:4px;">Még nincs egy kedvenced sem!</div>';
					else {
						AUTHPETIDS.each(function(pair) {
							if(pair.key!=0) {
								var h=$H(pair.value);
								var name=h.get('name');
								
								inner+=temp.evaluate({'name':name.truncate(20), id: pair.key });
							}
						});
					}
				var div=new Element('div',{ id: 'mypanel_float' });
				var pos=$H($('mypanel_pet').positionedOffset());
				var left=pos.get('left')-100;
				var top=pos.get('top')+20;
				div.setStyle({
					 'position':'absolute'
					,'top': top+'px'
					,'left': left+'px'
					,'width': '180px'
					,'overflow': 'hidden'
					,zIndex: 10
					});
				//div.setOpacity(0.5);
				div.update('<div class="mypanel_petselect_top"></div><div class="mypanel_petselect_bg" id="mypanel_petselect_ssss">'+inner+'</div><div class="mypanel_petselect_bottom"></div>');
				$('mypanel').appendChild(div);

				if(isIE6() && $('mypanel_petselect_ssss').getHeight()>=200)
					$('mypanel_petselect_ssss').setStyle({ height: '200px'});
				//new Effect.Opacity(div,{ to: 1.0, duration: 0.3});
				
				/*if(isBrowser() && !isIE7()) {
					setTimeout( function() {
						$(document.body).observe('click', function(e) {
							Event.stop(e);
							setTimeout(function() { try { $('mypanel_float').remove(); } catch(e) { } },200);
						});
					}, 300);
				}*/
			}
	};

var changeAuthPetId=function(id) {
		new Ajax.Request('/ajax.php',{
			 method: 'post'
			,parameters: { act: 'setAuthpetid', 'id': id }
			});
		
		var h=$H(AUTHPETIDS.get(id));
		var link=id==0?'/users.php':'/pets.php?act=info&petid='+id;
		$('mypanel_avatar').src=h.get('avatar');
		$('mypanel_avatar').setAttribute('alt',h.get('name'));
		$('mypanel_avatar').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());
		
		var star='<div class="star_pet handcursor"></div>';
		var star_bg='<div class="star_pet_bg"></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;
		$('mypanel_rank').update(rank);
		var obj,obj_my,obj_pet;
		obj_my=$('mypanel_my');
		obj_pet=$('mypanel_pet');
		
		if(id!=0) $('mypanel_activity').setOpacity(0.0);
			else $('mypanel_activity').setOpacity(1.0);
			
		obj=(id==0)?obj_my:obj_pet;
		obj.removeClassName('my_panel_tab');
		obj.addClassName('my_panel_tab_sel');
		obj.next().removeClassName('my_panel_tab_l');
		obj.next().addClassName('my_panel_tab_sel_l');
		obj.previous().removeClassName('my_panel_tab_r');
		obj.previous().addClassName('my_panel_tab_sel_r');
		
		obj=(id==0)?obj_pet:obj_my;
		obj.addClassName('my_panel_tab');
		obj.removeClassName('my_panel_tab_sel');
		obj.next().addClassName('my_panel_tab_l');
		obj.next().removeClassName('my_panel_tab_sel_l');
		obj.previous().addClassName('my_panel_tab_r');
		obj.previous().removeClassName('my_panel_tab_sel_r');
	};

var changeMenuLast=false;
var changeMenu=function(th,_sn) {
		var o=$(th.parentNode);
		var sel=o.hasClassName('selected');
		if(sel) return;

		if(changeMenuLast===false) {
			var objs=$$('.menu_high .selected');
			if(objs.size()) changeMenuLast=objs.first();
		}

		o.childElements().each(function(obj) {
			if(obj.hasClassName('menu_item')) obj.removeClassName('hide');
			if(obj.hasClassName('menu_root_top_hide')) {
				obj.addClassName('menu_root_top');
				obj.removeClassName('menu_root_top_hide');
			}
			if(obj.hasClassName('menu_root_bottom_hide')) {
				obj.addClassName('menu_root_bottom');
				obj.removeClassName('menu_root_bottom_hide');
			}
			
			if(obj.hasClassName('menu_item1')) obj.removeClassName('hide');
			if(obj.hasClassName('menu_root1_top_hide')) {
				obj.addClassName('menu_root1_top');
				obj.removeClassName('menu_root1_top_hide');
			}
			if(obj.hasClassName('menu_root1_bottom_hide')) {
				obj.addClassName('menu_root1_bottom');
				obj.removeClassName('menu_root1_bottom_hide');
			}
		});
		
		o.addClassName('selected');
		/*if(changeMenuElements===false) {
			changeMenuElements=[$$('.menu_high .menu_root'),$$('.menu_high .menu_root1')];
		}*/
		if(changeMenuLast) {
			obj_root=$(changeMenuLast);
			//console.log(changeMenuLast.inspect());
			obj_root.removeClassName('selected').childElements().each(function(obj) {
				obj=$(obj);
				if(obj.hasClassName('menu_item')) obj.addClassName('hide');
				if(obj.hasClassName('menu_root_top')) {
					obj.removeClassName('menu_root_top');
					obj.addClassName('menu_root_top_hide');
				}
				if(obj.hasClassName('menu_root_bottom')) {
					obj.removeClassName('menu_root_bottom');
					obj.addClassName('menu_root_bottom_hide');
				}

				if(obj.hasClassName('menu_item1')) obj.addClassName('hide');
				if(obj.hasClassName('menu_root1_top')) {
					obj.removeClassName('menu_root1_top');
					obj.addClassName('menu_root1_top_hide');
				}
				if(obj.hasClassName('menu_root1_bottom')) {
					obj.removeClassName('menu_root1_bottom');
					obj.addClassName('menu_root1_bottom_hide');
				}
			});
		}

		changeMenuLast=o;

		reDrawFooter();
	};
var chgM=changeMenu;

var sendFriendRequest=function(_petid,_userid,_ghost_authpetid) {
		_ghost_authpetid=_ghost_authpetid || '0';
		var par=$H({ 'userid': _userid, 'petid': _petid, 'message': $F('message'), 'ghost_authpetid': _ghost_authpetid });
		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) {
		if(id==10000) {
			$('main_content_frame').setStyle({'background':'#FFFFFF url(http://static.imgsrv.farm.hu/content533_bg_main_book.jpg) top left no-repeat'});
		} else {
			$('main_content_frame').setStyle({'background':'#FFFFFF url(http://static.imgsrv.farm.hu/content533_bg_main.gif) top left no-repeat'});
		}

		$$('.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');
	};

var changeAlbumType=function() {
		var form=Form.serialize($('typeform'),true);
		form=$H(form);
		
		petid=form.get('petid');
		
		if(petid) location.href='/albums.php?act=viewpetalbum&petid='+petid;
			else location.href='/albums.php?act=viewuseralbum';
	};

/* Megjelenít egy képet a képernyő közepén (a többit elsötétíti*/
var showPicture=function(url) {
		if(url.strip().empty()) 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() {
			var imgratio=1;
			var imgt=0;
			if(img.height>img.width) imgt=1; // 0 - álló, 1 - fekvő
			if(img.width>800 && imgt==0)
			{
				imgratio=img.width/img.height;
				img.width=800;
				img.height=img.width/imgratio;
			}
			if(img.height>600 && imgt==1)
			{
				imgratio=img.height/img.width;
				img.height=600;
				img.width=img.height/imgratio;
			}
			if(img.width==800)
			{
				img.style.top=(scroll+(dim.h-600)/2)+'px';
				img.style.left=((dim.w-800)/2)+'px';
			} else if(img.height==600) {
				img.style.top=(scroll+(dim.h-600)/2)+'px';
				img.style.left=((dim.w-600)/2)+'px';
			} else {
				img.style.top=(scroll+(dim.h-500)/2)+'px';
				img.style.left=((dim.w-500)/2)+'px';
			}
			
			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.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.farm.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 = "Farm.hu"; url = "http://farm.hu"; if (window.sidebar) { window.sidebar.addPanel(title, url, ""); } else if (window.external) { window.external.AddFavorite(url, title); } }
function AddHomePage() { if (document.all) { document.body.style.behavior = "url(#default#homepage)"; document.body.setHomePage("http://farm.hu"); } else { alert("Sajnos a b\xF6ng\xE9sz\u0151d nem t\xE1mogatja ezt a funkci\xF3t.\nHa be szeretn\xE9d \xE1ll\xEDtani az Farm.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() {
	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">');
	//setTimeout('reDrawFooter(true);',100);
}

var MAINinit=function() { 
		//var obj=$('my_panel');
		/*	obj.removeClassName('hide');
			var _left=Element.positionedOffset(obj);
			var _top=_left[1]-16;
			var _left=_left[0]-8;
			obj.setStyle({position:'absolute', left: _left+'px', top: _top+'px' });*/
		
			//specmenuinit.delay(1);
			$$('input[type=checkbox]','input[type=radio]').invoke('setStyle',{ background: 'transparent', border: '0px'});
			if($('main_content_frame').getHeight()>800) {
				(function() { $('main_content_bottom_height').setStyle({ height: '3px' }); }).delay(0.1);
				(function() { $('main_content_bottom_height').setStyle({ height: '3px' }); }).delay(0.3);
				(function() { $('main_content_bottom_height').setStyle({ height: '3px' }); }).delay(0.7);
			}

		//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 specmenuinit=function() {
		new Effect.Morph('menu_spec_title',{ style: 'color:#ff0', duration: 5, fps: 10, afterFinish: function() {
			new Effect.Morph('menu_spec_title',{ style: 'color:#1b49cc', duration: 5, fps: 10});
		}});
	};
	
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 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,_petselector,_forceauthpetid,_filter_name) {
		new Ajax.Updater(
			 'contact_ajax'
			,'/contact.php?act=friend_ajax&page='+_page
				+'&p='+_p+'&petselector='+_petselector
				+(Object.isUndefined(_forceauthpetid)?'':'&ghost_authpetid='+_forceauthpetid)
				+'&filter_name='+(Object.isUndefined(_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,_petid) {
	if(confirm('Biztosan törölni szeretnéd az ismerőseid közül?')) {
		_ghost='&ghost_authpetid='+GHOST_AUTHPETID;
		_petid=_petid || '0';
		new Ajax.Request('/contact.php?act=delfriend'+_ghost, { 
			 method: 'post'
			,parameters: { userid: _userid, petid: _petid }
			,onComplete: function(t) { 
					$('card_'+_userid+'_'+_petid).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
				}});
	};

//***********************************************************

// 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;
			petid=0;
		} else {
			userid=0;
			petid=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, petid: petid }
				,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: '249px', height: '152px', 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: '249px', height: '152px', 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' });
			});
		});
	};

	
/* 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 showwnd1(url,width,height,scroll) {
	scroll=scroll | false;
	return window.open(url,'',"width="+width+",height="+height+",left="+((screen.width-width)/2)+",top="+((screen.height-height)/2)+(scroll?',scrollbars=1':''));
}

/************************************************************/

function openGalleryWithFolder(folderid) {
	showwnd('/gallery.php?folderid='+folderid,'', 639,630);
}
function openGalleryWithImage(imageid) {
	showwnd('/gallery.php?imageid='+imageid,'', 639,630);
}


var g_bPngHackSupported = /MSIE (5\.5)|[6789]/.test(navigator.userAgent) && navigator.platform == "Win32";

function SetTransparentPng(img,src)
{
	var blankSrc = "http://static.imgsrv.divat.hu/empty.gif";
	if(g_bPngHackSupported && img.runtimeStyle)
	{
		if ( /\.png$/.test( src.toLowerCase() ) ) {
			// set blank image
			img.src = blankSrc;
			//img.src= src;
			// set filter
			img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
		}
		else {
		// remove filter
			img.runtimeStyle.filter = "";
			img.src=src;
		}
	}
	else img.src=src;
}

//hirdoboz legujabb/top cikkek kozti valtas
function ArticleBoxSetActive(element)
{
	if (element=='new')
	{
		elementid_to_activate='rightside_articles_new';
		elementid_to_disable='rightside_articles_top';
	}
	
	if (element=='top')
	{
		elementid_to_activate='rightside_articles_top';
		elementid_to_disable='rightside_articles_new';
	}
	document.getElementById(elementid_to_activate).style.display="block";
	document.getElementById(elementid_to_disable).style.display="none";
}

function ToggleExpertpageRow(id)
{
	if ($('expertpages_details_'+id).style.display=='none')
		$('expertpages_details_'+id).style.display='block';
	else
		$('expertpages_details_'+id).style.display='none';
}
