var bodyonloadfunc=[];
function bodyonload() {
	bodyonloadfunc.each(function(f) {
	try {
		if(Object.isFunction(f)) f();
	else eval(f);
  } catch(e) {}
 });
}

function bodyonloadadd(f) {
 bodyonloadfunc.push(f);
}

function fade_out_div(div_id)
{
	new Effect.Opacity(div_id, { from: 0.8, to: 0.0, duration: 0.7 });
}

function fade_in_div(div_id)
{
	$(div_id).setOpacity(0);
	new Effect.Opacity(div_id, { from: 0.0, to: 1.0, duration: 0.7 });
}

function uj_rendeles_alert()
{
	var div='scroll_div';
	var div2='scroll_div2';
	
	new Ajax.Request('/order/get_new_orders_ajax', 
			{ 
				method: 'post', 
				parameters:{}
				,onComplete:function(response){
					var isJSON=response.responseText.isJSON();
					var h=$H(isJSON?response.responseText.evalJSON(true):{error:-100});
    				var new_orders=h.get('new');
    				var in_work_orders=h.get('work');
					if(new_orders>0 || in_work_orders>0)
					{
						$(div).style['display']="block";
						$(div).setOpacity(0);
						new Effect.Opacity(div, { from: 0.0, to: 0.8, duration: 0.7 });
						var html_text="";
						if (new_orders>0) {
							html_text=html_text+new_orders+" feldolgozatlan, ";
						}
						if (in_work_orders>0) {
							html_text=html_text+in_work_orders+" feldolgozás alatt lévő";
						}
						html_text=html_text+' rendelés van. <br><a href="/megrendelesek">Rendelések ></a>';
						$(div).update(html_text);
						setTimeout("scrollozo_div_ie('scroll_div',5);", 100);
					}
					if (new_orders==0 && in_work_orders==0)
					{
						$(div).style['display']="none";
						$(div).setOpacity(0);
					}
				}
			}
	);
	
	new Ajax.Request('/arajanlat/get_new_arajanlat_ajax', 
			{ 
				method: 'post', 
				parameters:{}
				,onComplete:function(response){
					var isJSON=response.responseText.isJSON();
					var h2=$H(isJSON?response.responseText.evalJSON(true):{error:-100});
    				var news=h2.get('new');
    				var in_works=h2.get('work');
					if(news>0 || in_works>0)
					{
						$(div2).style['display']="block";
						$(div2).setOpacity(0);
						new Effect.Opacity(div2, { from: 0.0, to: 0.8, duration: 0.7 });
						var html_text2="";
						if (news>0) {
							html_text2=html_text2+news+" feldolgozatlan, ";
						}
						if (in_works>0) {
							html_text2=html_text2+in_works+" feldolgozás alatt lévő";
						}
						html_text2=html_text2+' árajánlat van. <br><a href="/arajanlat/arajanlatlist">Árajánlatok ></a>';
						$(div2).update(html_text2);
						setTimeout("scrollozo_div_ie('scroll_div2',190);", 100);
					}
					if (news==0 && in_works==0)
					{
						$(div2).style['display']="none";
						$(div2).setOpacity(0);
					}
				}
			}
	);		
			
	setTimeout("uj_rendeles_alert();", 60000); // percenként megnézi volt e új akció
}
// ezt má szereti mind
function scrollozo_div_ie(divname,padd) // pos: left | right
{
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ){
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	  
	var pading_left=padd; //px
	var pading_bottom=35; //px
	var div=divname;
		
	var div_dimansions=$(div).getDimensions(); // a div kiterjedse div_w['height']
	var window_actual_pos=$H(document.viewport.getScrollOffsets()).get('top'); // hol tart épp az ablak

	// div szélességének kiszámítása
	var div_width=myWidth/5; // a képerőny szélességének az ötöde
	if(div_width>170) div_width=170;
	if(div_width<150) div_width=150;

	var div_pozicioja=window_actual_pos+myHeight-div_dimansions['height']-pading_bottom;
	
	$(div).setStyle({ top: div_pozicioja+'px' , right: pading_left+'px', width:div_width+'px','z-index': 1001 });

	/*if(pos=='left')
		{
			$(div).setStyle({ top: div_pozicioja+'px' , left: pading_left+'px', width:div_width+'px','z-index': 1001 });
		}*/
	//$(div).setStyle({ top: div_pozicioja+'px' , right: pading_left+'px', width:div_width+'px','z-index': 1001 });
	
	/*
	if(pos=='left')	
	{
		var div_pozicioja=window_actual_pos+myHeight-div_dimansions['height']-pading_bottom;
		$(div).setStyle({ top: div_pozicioja+'px' , left: pading_left+'px', width:div_width+'px','z-index': 1001 });
	}
	
	if(pos=='right')
	{
		var div_pozicioja=window_actual_pos+myHeight-div_dimansions['height']-pading_bottom;
		$(div).setStyle({ top: div_pozicioja+'px' , right: pading_left+'px', width:div_width+'px','z-index': 1001 });
	}
	*/
	
	setTimeout("scrollozo_div_ie('"+divname+"',"+padd+");", 100);
	
}