function startVote(id,t) {
	$('#iVoteUp').mouseover(function(){rateShow('up')}).mouseout(function(){rateClear()}).click(function(){rateSendVote(1,id,t)});
	$('#iVoteDown').mouseover(function(){rateShow('down')}).mouseout(function(){rateClear()}).click(function(){rateSendVote(0,id,t)});;
}

function rateShow(type) {
	switch(type) {
		case 'up': $('#iVoteInfo').html('Tak polecam innym');break;
		case 'down': $('#iVoteInfo').html('Szkoda czasu');break;
	}
}

function rateClear() {
	$('#iVoteInfo').html('Kliknij aby ocenić');
}

function rateSendVote(vote,id,t) {
	
	$.ajax({
    	url: '/ajax/vote/id/'+id+'/v/'+vote+'/t/'+t.toLowerCase().charAt(0),
    	type: 'GET',
    	dataType: 'json',
    	timeout: 1000,
    	error: function(){
    		$('#iVoteInfo').html('Wystąpił błąd');
    	},
    	success: function(response){
        	reteMakeResponse(response);
		}
	});
}

function reteMakeResponse(r){
	if (r>0) {
		$('#iVoteInfo').html('Głos zaliczono');
	} else if ( r == -1 ) { 
		$('#iVoteInfo').html('Musisz być zalogowany');
	} else {
		$('#iVoteInfo').html('Wystąpił błąd');
	}
	$('#iVoteUp').unbind();
	$('#iVoteDown').unbind();
	
}

function showForm(loginUrl) {
	var userNick = $.cookie('kafito_user');
	if (userNick!=null){
		$('.addForm').get(0).style.display='block';
	} else {
        $('#iCmtInfo').html('Aby dodać komentarz musisz być <a href="'+loginUrl+'">zalogowany</a>');
        $('#iCmtInfoContent').show();
	}
	return false;
}

function clearField(frm) {
	if (frm.name=='login' && frm.value=='użytkownik') {
		frm.value='';
	} else if (frm.name=='password' && frm.value=='hasło') {
		frm.value='';
		frm.type  = 'password';
		
	}
}

function searchSubmit() {
	return document.getElementById('srhPhrase').value.length > 0;
}