$(document).ready(function(){
	
	//debug close
	if ($('div.debug_info')){
		$('#close_div_debug').click(function(ev){
			$('div.debug_info').hide();
		});
	}
	
	//photoreports accordion
	if ($('#photoreports_entry')){
		jQuery('#photoreports_entry').accordion({
			header: 'div.pht_title',
		    autoheight: true,
		    animated: "bounceslide",
		    active: '.selected'
		});
	}
	
	$("#send_vote").click(function() {
		// validate and process form
		var radio_value = $("input[@name='ankieta_opt']:checked").val();

		if (typeof radio_value != 'undefined'){
			if (pytania.length){
				var ankieta_odp;
				for(var i=0; i<pytania.length; i++){
					if (radio_value == pytania[i]){
						ankieta_odp = radio_value;
						break;
					}

				}
			}
			$.ajax({
				type: "POST",
				url: "/ankieta_vote/",
				data: "pytanie=" + ankieta_odp + "&ankieta=" + ankieta_id,
				success: function(data) {
					if (data){
						$('#ankieta_container').html("<div id='message' style='font-size: 12px; font-weight: bold; display: none;'></div>");
						$('#message').append(data).fadeIn(1500);
					}
				}
			});
		}
	    return false;
	});
});

//on submit kontakt form
function onSubmitKontaktForm(){
	var temat = document.getElementById('kontakt_temat').value;
	var tresc = document.getElementById('kontakt_tresc').value;
	if (temat.length >= 3 && tresc.length >= 5){	
		return true;
	} else {
		return false;
	}
}

//on submit search form
function onSubmitSearchForm(search_word){
    var query = document.getElementById('search_query').value;
    if (query.length >= 2 && query != search_word){    
        return true;
    } else {
        return false;
    }
}
