$(document).ready(function(){	
	
	// pola formularzy - tekst w srodku znikajacy po kliknieciu
	$('.newsletter .input_txt').focus(function(){$(this).attr('value','');});
	$('.newsletter .input_txt').blur(function(){if($(this).attr('value')=='') $(this).attr('value','Twój adres e-mail');});
	
	$('#block_search .input_txt').focus(function(){$(this).attr('value','');});
	$('#block_search .input_txt').blur(function(){if($(this).attr('value')=='') $(this).attr('value','Wpisz szukane słowo');});
	
	var livechat = $('.livechat .input_text');
	livechat.eq(0).focus(function(){if($(this).attr('value')=='login tymczasowy') $(this).attr('value','');});
	livechat.eq(1).focus(function(){if($(this).attr('value')=='treść wiadomości') $(this).attr('value','');});
	livechat.eq(0).blur(function(){if($(this).attr('value')=='') $(this).attr('value','login tymczasowy');});
	livechat.eq(1).blur(function(){if($(this).attr('value')=='') $(this).attr('value','treść wiadomości');});
	if(livechat.eq(0).attr('value') == '') livechat.eq(0).attr('value','login tymczasowy');
	if(livechat.eq(1).attr('value') == '') livechat.eq(1).attr('value','treść wiadomości');
	
	var login = $('#block_login .input_txt');
	login.eq(0).focus(function(){$(this).attr('value','');});
	login.eq(1).focus(function(){$(this).attr('value','');});
	login.eq(0).blur(function(){if($(this).attr('value')=='') $(this).attr('value','Login');});
	login.eq(1).blur(function(){if($(this).attr('value')=='') $(this).attr('value','Hasło');});

	// kolorowanie co drugiego wpisu na szaro w livechat
	$(".chat_window .message:odd").addClass("grey");
		
	attachActions();
	
	$('a.tooltip').bstip();
	
});

function attachActions(){
	// obsluga livechat'a
	var form = $(".form-post-action");
	form.submit(function(e){
		e.preventDefault();
		// POST request + refresh widoku dopiero na request callback
		$.post("http://strefam.tv/components/livechat/modul.php", form.serialize(), function(data){
			$(".livechat .chat_window").replaceWith(data);
			$(".form-post-action .long").attr("value","");
			
			// kolorowanie na nowo co drugiego wpisu na szaro w livechat
			$(".chat_window .message:odd").addClass("grey");
		});
	});
	
	var poll = $(".poll_form");
	poll.submit(function(e){
		$.post("http://strefam.tv/components/poll/modul.php", poll.serialize(), function(data){
			$(".poll .body form").replaceWith(data);
		});
		e.preventDefault();
	});
}

function validateForm(formularz_nazwa,lista_wymaganych_pol,styl_ok,styl_empty){

	var i,e=formularz_nazwa.elements,puste=false
	var pola=lista_wymaganych_pol
	var komunikat1,komunikat2

for(i=pola.length-1; i>=0; --i)
	if(e['zawartosc'].value!=''&&e['zawartosc'].value!='treść wiadomości'){
		e['zawartosc'].style.border=styl_ok

	} else{
        puste=true
        e['zawartosc'].style.border=styl_empty
    }

	for(i=pola.length-1; i>=0; --i)
	if(e['autor'].value!=''&&e['autor'].value!='login tymczasowy'){
		e['autor'].style.border=styl_ok

	} else{
        puste=true
        e['autor'].style.border=styl_empty
    }
	if(puste) alert('Musisz wypełnić wymagane pola')

	return !puste
}
