$(document).ready(function()
{
	$(function(){$('.nav').droppy();});
	
	$(function() {$('a.lbox').lightBox({fixedNavigation:true});});
	
	// style input
	$("input[type='text'], input[type='password'], textarea").focus(function (){$(this).css({'background':'#EEF'});});
	$("input[type='text'], input[type='password'], textarea").blur(function (){$(this).css({'background':'#FFF'});});
	$("input[type='submit']").mouseover(function (){$(this).css({'background':'#999'});});
	$("input[type='submit']").mouseout(function (){$(this).css({'background':'#D4D0C8'});});
	
	// drukuj
	$('#drukuj').click(function()
	{
		$('#wyslijLink').hide();
		print();
	
	});
	
	// kalendarz
	$.ajaxSetup({cache: false});
	
	$.ajax(
	{
		type: 'POST',
		datatype: 'html',
		url: "kalendarz.php",
		data: 'kalendarz=1',
		beforeSend: function(html){$('#kalendarz').html('<img src="gfx/loader.gif" alt=" " />');},
		error: function(html){},
		success: function(html)
		{
			$('#kalendarz').html(html);
		}
	});
	
	$('#wstecz').live('click',function()
	{
	
		$.ajax(
		{
			type: 'POST',
			datatype: 'html',
			url: "kalendarz.php",
			data: 'kalendarz=wstecz&teraz='+$('#kalData').val(),
			beforeSend: function(html){$('#kalendarz').html('<img src="gfx/loader.gif" alt=" " />');},
			error: function(html){},
			success: function(html)
			{
				$('#kalendarz').html(html);
			}
		});
	});
	
	$('#naprzod').live('click',function()
	{
	
		$.ajax(
		{
			type: 'POST',
			datatype: 'html',
			url: "kalendarz.php",
			data: 'kalendarz=naprzod&teraz='+$('#kalData').val(),
			beforeSend: function(html){$('#kalendarz').html('<img src="gfx/loader.gif" alt=" " />');},
			error: function(html){},
			success: function(html)
			{
				$('#kalendarz').html(html);
			}
		});
	});
	
	$('.jest').live('mouseover',function(e)
	{
		var left = $(this).offset().left;
		var top  = $(this).offset().top;
		
		$.ajax(
		{
			type: 'POST',
			datatype: 'html',
			url: "kalendarz.php",
			data: 'kalendarz=pokaz&teraz='+$('#kalData').val()+'&dzien='+$(this).html(),
			beforeSend: function(html){$('#informacja').show(); $('#informacja').html('<img src="gfx/loader.gif" alt=" " />');},
			error: function(html){},
			success: function(html)
			{				
				$('#informacja').css('top',top+24+'px');
				$('#informacja').css('left',left+(-1)+'px');
				$('#informacja').html(html);
			}
		});
	});
	
	$('.jest').live('mouseover',function()
	{
		$('#informacja').mouseover(function()
		{
			$('#informacja').mouseleave(function()
			{
				$('#informacja').show();
			});
			
			$('#informacja').mouseleave(function()
			{
				$('#informacja').hide();
				$('#informacja').html('');
			});
		});
		
		$('.jest').mouseleave(function()
		{
			$('.nic').mouseover(function(){$('#informacja').hide();});
			$('.nd').mouseover(function(){$('#informacja').hide();});
			$('.dzis').mouseover(function(){$('#informacja').hide();});
		});
	});
	
	// wyslij link znajomym
	$('#wyslij').click(function()
	{
		$('#wyslijLink').toggle('slow');
	
	});
	
	$('#wyslijLinkSubmit').click(function()
	{
		var regExp = /^[0-9a-z\._-]{3,16}@[0-9a-z\._-]{1,16}\.[a-z]{2,3}$/;
		if($("#od").val().length<=2){alert('Brak poprawnego wpisu w polu \'Od\'');}
		else if(!(regExp.test($("#odEmail").val()))) {alert('Niepoprawny adres e-mail w polu \'Od\'');}
		else if($("#do").val().length<=2){alert('Brak poprawnego wpisu w polu \'Do\'');}
		else if(!(regExp.test($("#doEmail").val()))) {alert('Niepoprawny adres e-mail w polu \'Do\'');}
		else
		{
			$.ajax(
			{
				type: 'POST',
				datatype: 'html',
				url: "wyslij.php",
				data: 'od='+$("#od").val()+'&do='+$("#do").val()+'&odE='+$("#odEmail").val()+'&doE='+$("#doEmail").val()+'&link='+$("#Link").val(),
				beforeSend: function(html){$('#loader').html('<img src="gfx/loader.gif" alt=" " />');},
				error: function(html){},
				success: function(html)
				{				
					if(html=='ok')
					{
						$('#loader').html('');
						alert('Formularz został poprawnie wysłany');
						$("#od").val('');
						$("#do").val('');
						$("#odEmail").val('');
						$("#doEmail").val('');
						$('#wyslijLink').hide('slow');
					}
				}
			});
		}
		return false;
	});
	
});

function el(id)
{
	return document.getElementById(id);
}

function pokaz_info(id,tresc)
{	
	document.onmousemove=function(e)
	{
		// 1 - google chrome
		var str = navigator.userAgent;
		var chrome = 'Chrome';
	
		if(str.search(chrome)!=-1) var przesuniecie = document.body.scrollTop;
		else var przesuniecie = (document.documentElement||document.body).scrollTop;
		
		if(str.search(chrome)!=-1) var przesuniecie1 = document.body.scrollLeft;
		else var przesuniecie1 = (document.documentElement||document.body).scrollLeft;
	
		el(id).style.left = (e=e||event).clientX+przesuniecie1+20+'px';
		el(id).style.top = e.clientY+przesuniecie+20+'px';
		el(id).style.display = 'block';
		el(id).innerHTML = bbcode(tresc);
		//el(id).innerHTML = tresc;
	}
}

function wylacz_info(id)
{
	document.onmousemove=function(e)
	{
		el(id).style.display = 'none';
	}
}

function bbcode(text)
{
	var s = String(text)
	s=s.replace(/\[/g,'<');
	s=s.replace(/\]/g,'>');
	//s=s.replace(/ę/g,'e');
	return s;
}

function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}

// rejestracja
function potwierdz(text)
{
	if(confirm(text))
	{
		el('K7potw').value = 'potwierdzone';
		document.forms['Formularz'].submit();
	}
	else el('K7potw').value = '';
}

function zapisano(konto,email)
{
	alert('Konto '+konto+' zostało poprawnie założone.\nAby dokończyć rejestrację, system wysłał na adres '+email+' kod aktywujący Twoje konto.');
	window.top.location.href = 'kursy.html';
}

function zapis_blad()
{
	alert('Wystąpił nieznany błąd ! Spróbuj ponownie');
	window.top.location.href = 'rejestracja.html';
}

function aktywacja(info)
{
	alert(info);
	window.top.location.href = 'kursy.html';
}

// wykonauje podana funkcje po n czasie
function wstrzymacz(funkcja,n)
{
	setTimeout(funkcja,n);
}

function hidden(id)
{
	el(id).style.display = 'none';
}
