function toggle_form(arg)
{
	if(arg.innerHTML=='Logowanie')
	{
		document.getElementById('login_tab_form').style.display='block';
		document.getElementById('login_tab_under').style.display='block';
		document.getElementById('register_tab_form').style.display='none';
		document.getElementById('register_tab_under').style.display='none';
	}
	else
	{
		document.getElementById('login_tab_form').style.display='none';
		document.getElementById('login_tab_under').style.display='none';
		document.getElementById('register_tab_form').style.display='block';
		document.getElementById('register_tab_under').style.display='block';
	} 
	
	var tab=document.getElementById('tabs').getElementsByTagName('li');
	tab[0].className='';
	tab[1].className='';
	arg.parentNode.className='active';
}

function show_popup(arg1,arg2)
{
	var curtain=document.getElementById('curtain');
	var popup=document.getElementById('popup');
	
	curtain.style.width=parseInt(document.documentElement.offsetWidth)+'px';
	curtain.style.height=parseInt(document.documentElement.offsetHeight)+'px';
	curtain.style.display='block';
	
	document.getElementById('popup_tytul').innerHTML=arg1;
	document.getElementById('popup_tresc').innerHTML=arg2;
	popup.style.display='block';
	popup.style.left=Math.round((parseInt(document.documentElement.offsetWidth)-parseInt(popup.offsetWidth))/2)+'px';
	popup.style.top=Math.round((parseInt(document.documentElement.clientHeight)-parseInt(popup.offsetHeight))/2)+'px';
	
}

function show_popup2(arg1,arg2)
{
	var curtain=document.getElementById('curtain');
	var popup=document.getElementById('popup2');
	
	curtain.style.width=parseInt(document.documentElement.offsetWidth)+'px';
	curtain.style.height=parseInt(document.documentElement.offsetHeight)+'px';
	curtain.style.display='block';
	
	popup.innerHTML=arg2;
	popup.style.display='block';
	popup.style.left=Math.round((parseInt(document.documentElement.offsetWidth)-parseInt(popup.offsetWidth))/2)+'px';
	popup.style.top=Math.round((parseInt(document.documentElement.clientHeight)-parseInt(popup.offsetHeight))/2)+'px';
	
}

function hide_popup()
{
	var curtain=document.getElementById('curtain');
	var popup=document.getElementById('popup');
	
	popup.style.display='none';
	curtain.style.display='none';
}

function hide_popup2()
{
	var curtain=document.getElementById('curtain');
	var popup=document.getElementById('popup2');
	
	popup.style.display='none';
	curtain.style.display='none';
}

var ajax_login=new ajax('action.php?op=log');
ajax_login.ladowanie=function()
{
	var curtain=document.getElementById('login_curtain');
	curtain.style.display='block';
}

var ajax_register=new ajax('action.php?op=reg');
ajax_register.ladowanie=function ()
{
	var curtain=document.getElementById('register_curtain');
	curtain.style.display='block';
}

ajax_register.zakonczono=function()
{
	document.getElementById('register_curtain').style.display='none';
	
	if(this.x.status==200)
	{
		var tab=this.x.responseText.split('|');
		
		if(tab[0]=='ok')
		{
			show_popup('Sukces',tab[1]);
			document.getElementById('logl').value=document.getElementById('logr').value;
			document.getElementById('hasl').value=document.getElementById('hasr').value;
			toggle_form(document.getElementById('a_logowanie'));
			setTimeout('hide_popup()',2000);
		}
		else if(tab[0]=='notok')
		{
			show_popup(vals['blad'],tab[1]);
			var tabx=document.getElementById('register_tab_form').getElementsByTagName('input');
			for(var i=0;i<tabx.length;i++)
			{	
				if(tabx[i].name==tab[2]) 
				{
					tabx[i].focus();
					tabx[i].style.color='darkorange';
					break;
				}
			}
			setTimeout('hide_popup()',2000);
		}
		else
		{
			show_popup(vals['blad'],vals['blad_polaczenia']);
			setTimeout('hide_popup()',2000);
		}
	}
	else
	{
		show_popup(vals['blad'],vals['blad_polaczenia']);
		setTimeout('hide_popup()',2000);
	}
}

function after_login()
{
	document.location="program.php";
}

ajax_login.zakonczono=function()
{
	document.getElementById('login_curtain').style.display='none';
	if(this.x.status==200)
	{
		var tab=this.x.responseText.split('|');
		
		if(tab[0]=='ok')
		{
			show_popup('Sukces',tab[1]);
			setTimeout('after_login()',2000);
		}
		else if(tab[0]=='notok')
		{
			show_popup(vals['blad'],tab[1]);
			setTimeout('hide_popup()',2000);
		}
		else
		{
			show_popup(vals['blad'],vals['blad_polaczenia']);
			setTimeout('hide_popup()',2000);
		}
	}
	else
	{
		show_popup(vals['blad'],vals['blad_polaczenia']);
		setTimeout('hide_popup()',2000);
	}
}

function register_submit()
{
	var tab=document.getElementById('register_tab_form').getElementsByTagName('input');
	var zmienne='';
	for(var i=0;i<tab.length;i++)
	{
		zmienne+='&'+tab[i].name+'='+tab[i].value;
		tab[i].style.color='';
	}
	ajax_register.wyslijPOST(zmienne);
}

function show_info(arg,arg2)
{
	if(document.getElementById('strzalka')) document.removeChild(document.getElementById('strzalka'));
	
	var obj=document.createElement('div');
	obj.id='strzalka';
	obj.className='strzalka';
	obj.innerHTML=vals['info'][arg2];
	obj.style.left=parseInt(arg.offsetLeft)+parseInt(arg.offsetWidth)+'px';
	document.getElementById('register_tab_form').appendChild(obj);
	obj.style.top=parseInt(arg.offsetTop)+Math.round(parseInt(arg.offsetHeight)/2)-Math.round(parseInt(obj.childNodes[0].offsetHeight)/2)+'px';
}	

function hide_info()
{
	document.getElementById('strzalka').parentNode.removeChild(document.getElementById('strzalka'));
}

function login_submit()
{
	var tab=document.getElementById('login_tab_form').getElementsByTagName('input');
	var zmienne='';
	for(var i=0;i<tab.length;i++)
	{
		zmienne+='&'+tab[i].name+'='+tab[i].value;
		tab[i].style.color='';
	}
	ajax_login.wyslijPOST(zmienne);
}

move_menu_link_to=new Array();
move_menu_link_position=new Array();
move_menu_link_to_position=new Array();
move_menu_link_obj=new Array();

function move_menu_link(arg)
{
	clearTimeout(move_menu_link_to[arg.innerHTML]);
	if(move_menu_link_position[arg.innerHTML]!='') move_menu_link_position[arg.innerHTML]=15;
	move_menu_link_to_position[arg.innerHTML]=155-parseInt(arg.className);
	move_menu_link_obj[arg.innerHTML]=arg;
	move_menu_link_continue(arg.innerHTML);
}

function move_menu_link_continue(arg)
{
	if(move_menu_link_position[arg]<move_menu_link_to_position[arg])
	{
		move_menu_link_obj[arg].style.backgroundPosition=move_menu_link_position[arg]+'px -1px';
		move_menu_link_position[arg]+=10;
		move_menu_link_to[arg]=setTimeout('move_menu_link_continue("'+arg+'")',30);
	}
	else 
	{
		move_menu_link_obj[arg].style.backgroundPosition=move_menu_link_to_position[arg]+'px -1px';
		move_menu_link_position[arg]=move_menu_link_to_position[arg];
	}

}

function move_menu_link_back(arg)
{
	clearTimeout(move_menu_link_to[arg.innerHTML]);
	move_menu_link_obj[arg.innerHTML]=arg;
	move_menu_link_back_continue(arg.innerHTML);
}

function move_menu_link_back_continue(arg)
{
	if(move_menu_link_position[arg]>15)
	{
		move_menu_link_obj[arg].style.backgroundPosition=move_menu_link_position[arg]+'px -1px';
		move_menu_link_position[arg]-=5;
		move_menu_link_to[arg]=setTimeout('move_menu_link_back_continue("'+arg+'")',30);
	}
	else 
	{
		move_menu_link_obj[arg].style.backgroundPosition='15px -1px';
		move_menu_link_position[arg]=15;
	}

}

function pobierz_kod(arg1,arg2)
{
	var obj=document.createElement('textarea');
	obj.value="<script type=\"text/javascript\" src=\"http://programpartnerski.shipo.pl/banner.php?t="+arg2+"&h="+user_hash+"\"></script>";
	var objbig=document.getElementById('code'+arg2);
	objbig.innerHTML='';
	objbig.appendChild(obj);
	obj.focus();
	obj.select();

}

var images=new Array();
images.push(new Image());
images[images.length-1].src="gfx/lewa.png";
images.push(new Image());
images[images.length-1].src="gfx/prawa.png";
images.push(new Image());
images[images.length-1].src="gfx/mid.png";
images.push(new Image());
images[images.length-1].src="gfx/close.png";

function show_stats()
{
	typ=document.getElementById('wyb_typ').getElementsByTagName('option')[document.getElementById('wyb_typ').selectedIndex].value;
	stats='';
	stats+= (document.getElementById('typ1').checked ? 'x' : 'o');
	stats+= (document.getElementById('typ2').checked ? 'x' : 'o');
	stats+= (document.getElementById('typ3').checked ? 'x' : 'o');
	m=document.getElementById('wyb_miech').getElementsByTagName('option')[document.getElementById('wyb_miech').selectedIndex].value;
	r=document.getElementById('wyb_rok').getElementsByTagName('option')[document.getElementById('wyb_rok').selectedIndex].value;
	if(typ=='-' ||  m=='-' || r=='-' || stats=='ooo') alert('Wybierz wszystkie opcje wykresu!');
	else swfobject.embedSWF("swf/open-flash-chart.swf", "my_chart", "680", "350", "9.0.0", "expressInstall.swf", {"data-file":"swf/swf_chart.php?dane="+typ+"i"+stats+"i"+m+"i"+r+"","loading":"Wczytywanie statystyk..."});
}
function show_raport()
{
	m=document.getElementById('wyb_miech').getElementsByTagName('option')[document.getElementById('wyb_miech').selectedIndex].value;
	r=document.getElementById('wyb_rok').getElementsByTagName('option')[document.getElementById('wyb_rok').selectedIndex].value;

	if(m=='-' || r=='-') 
	{
		alert('Podaj rok i miesiąc!');
		return 0;
	}
	var data=new Date();
	if(parseInt(r) > data.getFullYear() || (parseInt(r)==data.getFullYear() && parseInt(m) >= data.getMonth()+1)) alert('Ten raport jest jeszcze niedostępny');
	else document.location="pdf/raport.php?r="+r+"&m="+m;
}

function send_support()
{
	if(document.getElementById('tresc').value=='') alert('Podaj treść wiadomości!');
	else document.getElementById('form_support').submit();
}

var vals=new Array();
vals['blad']='Błąd';
vals['blad_polaczenia']='Wystąpił błąd połączenia. Spróbuj ponownie';
vals['info']=new Array();
vals['info'][0]='<div><b>Tu wprowadź login.</b> Powinien on składać się z 6-30 liter i/lub znaków i rozpoczynać się od litery.</div>';
vals['info'][1]='<div><b>Tu podaj hasło.</b> Powininno ono składać się z 6-30 liter i/lub znaków.</div>';
vals['info'][2]='<div><b>Powtórz hasło.</b> W celu pominięcia problemu z błędnie wpisanym hasłem powtórz je tutaj.</div>';
vals['info'][3]='<div><b>Tu wprowadź swój adres E-mail.</b> Ten adres będzie służył do komunikacji z Tobą.</div>';
