$(document).ready(function(){
	$("a.fancybox").fancybox();
	$("a.lightbox").fancybox();
	$('#banner_top_change').cycle({
		fx: 'fade',
		timeout: 10000
	});
	$("input[name=key]").click(function(){
		$(this).val('');
	})
	$("#n_content").click(function(){
		$(this).val('');
	})
	$("#menutop li a").addClass('normal');
	$("#menu_dolne li").hover(
		function() {
			$(this).find("ul").show();
			//$(this).find("a").addClass('menuactive');
		},
		function(){
			$(this).find("ul").hide();
			//$(this).find("a").removeClass('menuactive');
		}
	)
	$("#menu_gorne li").hover(
		function() {
			$(this).find("ul").show();
			$(this).find("ul li ul").hide(); // ukrywanie trzeciego poziomu
			//$(this).find("a").addClass('menuactive');
			},
		function(){
			$(this).find("ul").hide();
			//$(this).find("a").removeClass('menuactive');
		}
	)
})
function sendEmail(){
	var content = $("#n_content").val();
	if(content == '' || content == 'wpisz swój email'){
		$("#info_field").text('wprowadź poprawny e-mail');
		return false;
	}
	if(checkEmail(content) == 0){
		$("#info_field").text('wprowadź poprawny e-mail');
		return false;
	}
	$.ajax({
		type: "GET",
		url: "index.php/admin/newslettercheckemail",
		data:"email="+content,
		beforeSend: function(){
			var loading = '<div style="text-align:center;"><img src="media/img/loading.gif" /></div>';
			$('#info_field').html(loading);
		},
		error: function(xhr, desc, e) {
		   alert(xhr.responseText);
		},
		success: function(msg){
			//alert(msg);return false;
			if(trim(msg) == '1' ){
				$("#info_field").text('Ten e-mail istnieje w naszej bazie');
			}else{
				$("#info_field").text('E-mail został dodany do bazy');
				$("#n_content").val('');
			}
		}
	})
}
function formSearch(){
	var key = $("input[name=key]");
	if(key.val() == '' || key.val() == 'wypełnij pole'){
	key.val('wypełnij pole');
	return false;
	}
}
function checkEmail(email) {
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if(email.search(emailRegEx) == -1) {
		return 0;
    }
}
function clearText(field){
   if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
