String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


$(document).ready(function() {	
	
	setTimeout("resize()", 300);
	
	$(window).resize(function() {
			setTimeout("resize()", 300);
		});
	
	$('#znak').click(function(){
			window.location.href = this.className;
	});
	
	
	$('#send').click(function(){
		send();
	});
	
	$("#katD").bind('change', function() {
		//alert("aaa");
		window.location.href = $("#url").val()+"/"+$("#katD option:selected").val();
	});
	
	$('.main').click(function(){
		var clas = this.className;
		var names = clas.split(" ");
		var sel = names[1];
		if ($('.group.'+sel).css('display') == 'none') {
			$('.group.'+sel).slideDown(100);
			setTimeout("resize()", 100);
		} else {
			$('.group.'+sel).slideUp(100);
			setTimeout("smaller()", 200);
		}
	});
	
	
});
	
function resize() {
if ($("#forum").height() > 0) {
	if ($("#left").height()-250 > $("#forum").height()) {
		$("#forum").height($("#left").height()-250);
	}
}
	if ($("#left").height() > $("#right").height()) {
		$("#right").height($("#left").height());
	}

if ($("#main").height() > 0) {
	if ($("#contact").height()+$("#poll").height() > $("#main").height()) {
		$("#main").height($("#contact").height()+$("#poll").height());
	}
	
	if ($("#left").height() > $("#main").height()+$("#head").height()+$("#topmenu").height()) {
		$("#main").height($("#left").height()-$("#head").height()-$("#topmenu").height()-$("#foot").height()-10);
	}
}

setTimeout("resize()", 300);

}


function smaller() {
	if ($("#left").height() < $("#right").height()) {
		$("#right").animate({height: 'auto'}, 200);
	}
	
}


function openM(id) {
	var clas = document.getElementById('m'+id).className;
	var names = clas.split(" ");
	var sel = names[1];
	if ($('.group.'+sel).css('display') == 'none') {
		$('.group.'+sel).slideDown(0);
	} 
	setTimeout("resize()", 100);
}

function openN(url) {
	window.location.href = url;
}

function send() {
	
	if ($('#author').val().trim() == "") {
		jAlert("Nevyplnili jste jméno", "");
		return false;
	} else if ($('#text').val().trim() == "") {
		jAlert("Nenapsali jste žádný text", "");
		return false;
	}
	if ($('#ida').val().trim() == 0) {
		if ($('#title').val().trim() == "") {
			jAlert("Nenapsali jste nadpis", "");
			return false;
		} 
	}
	if ($('#user').val().trim() != 1) {
		if ($('#email').val().trim() != "") {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			var address = $('#email').val();
			if(reg.test(address) == false) {
			  jAlert("Nesprávně zadaný e-mail", "");
			  return false;
			}	
			
		}
		if ($('#antispam').val().trim() == "") {
			jAlert("Nevyplnili jste antispam", "");
			return false;
		} else {
			var today = new Date();
			var thisDay = today.getDay();
			var myDays = ["nedele","pondeli","utery","streda","ctvrtek","patek","sobota","nedele"];
			thisDay = myDays[thisDay];
			
			var antispam = $('#antispam').val().toLowerCase();
			
			var arr = new Array("ě", "ú", "č", "ř", "í", "ý", "á"); 
			 var by = new Array("e", "u", "c", "r", "i", "y", "a"); 
			 for (var i=0; i<arr.length; i++) { 
				 antispam = antispam.replace(arr[i], by[i]); 
			 }
			 
			 if (antispam != thisDay) {
				jAlert("Špatně vyplněný antispam", "");
				return false;
			 }
		} 
	}
	$("#forumF").submit();
	
}


function slideF() {
	if ($(".forumarea").css('display') != 'none') {
		$(".forumarea").slideUp();
		setTimeout("resize()", 150);
	} else { 
		$(".forumarea").slideDown();
		$("#forum").css('height', 'auto');
	}
}

function delF(id) {
	jConfirm("Opravdu chcete smazat tuto položku ?", 'Smazání položky', function(r) {
	if (r == true) {
		$.post("module/delf.php", { 'id': id },
			function(data){
				datas = data.split(";");
				if (datas.length < 1) {	
					jAlert("Při mazání nastala chyba", "");
				} else {			
					jAlert("Položka smazána", "");
					var i;
					for (i=0; i<datas.length-1; i++) {
						$('#f'+datas[i]).fadeOut();
					}
				}
			});
		}
	});
}

function vote(idp, ida) {
	$.post("module/vote.php", { 'idp': idp, 'ida': ida },
		function(data){
			if (data.indexOf("err") >= 0) {
				jAlert("Již jste hlasovali.", "");
			} else {
				jAlert("Děkujeme za hlas.", "", function(r) {
				if (r) {
					window.location.reload(true);
				}
				});
			}
		});
	
}

function showF(id) {
	//alert (id);
	$("#h"+id).toggleClass("hide");
	$("#l"+id).toggleClass("hide");
	
}


