$(function() {  
  $("img[@type=transparent], .text-front, .logo").ifixpng();
  $('a[@rel*=facebox]').facebox();
  
  $(".uroven1 > li, .uroven2 > li").hover(
    function(){
      $(this).children().filter("[class=uroven2], [class=uroven3]").not(":animated").fadeIn("fast");
      $(this).addClass("hover");
    },
    function(){
      $(this).children().filter("[class=uroven2], [class=uroven3]").fadeOut("fast");
      $(this).removeClass("hover");
    });
  
});



var globZal = '';

function selZalozka(id, go) {
	$('#tab_'+id).attr('class', 'tab big');
	$('#tab_'+globZal).attr('class', 'tab');
	globZal = id;
	
	var data = '';
	
	jQuery.ajax({
		data: data,
		url: 'services.php?get=search-type&show='+go,
		type: 'POST',
		timeout: 3000,
				
		error: function() {
			alert('Dotaz zlyhal');
		},
		success: function(result) {
			$('#zalContent').html(result);
		},
		beforeSend: function() {
			
		},
		complete: function() {
			
		}
	})		
}

function SendForm(frm, status, ret) {
	if (!check_form(frm)) { return false; }
 
	$.ajaxFileUpload({
	    url				: "inc/submit.php?status="+status+"&"+$("#"+frm.id).serialize(),
	    secureuri		: false,
	    fileElementId	: 'import_file',
	    dataType		: 'json',
		success: function(result){
			if(result.status=="uploadError"){
				alert("Nepodarilo sa uploadnuť priložený súbor!");
			}
			else if(result.status=="fileTypeError"){
				alert("Zlý formát súboru, povolené sú iba jpg/png obrázky!");
			}
			else if(result.status=="fileSizeError"){
				alert("Uploadovaný súbor je príliš veľký! Maximálna povolená veľkosť súboru je 2Mb.");
			}
			else {				
				ret.html("<center><strong><p>Formulár bol úspešne odoslaný."+(result=="redirect" ? " Počkajte prosím...." : "")+"</p></strong></center>");
				if (result.status=="redirect") {
					setTimeout("document.location = document.location;", 1000);
				} 
			}
		},
		beforeSend: function(){
		}
    });
	return false;
}

function SendForm2(frm, status, ret) {
	if (!check_form(frm)) { return false; }

	$.ajaxFileUpload({
	    url				: "inc/submit.php?status="+status+"&"+$("#"+frm.id).serialize(),
	    secureuri		: false,
	    fileElementId	: 'import_file2',
	    dataType		: 'json',
		success: function(result){
			if(result.status=="uploadError"){
				alert("Nepodarilo sa uploadnuť priložený súbor!");
			}
			else if(result.status=="fileTypeError"){
				alert("Zlý formát súboru, povolené sú iba jpg/png obrázky!");
			}
			else if(result.status=="fileSizeError"){
				alert("Uploadovaný súbor je príliš veľký! Maximálna povolená veľkosť súboru je 2Mb.");
			}
			else {				
				ret.html("<center><strong><p>Formulár bol úspešne odoslaný."+(result=="redirect" ? " Počkajte prosím...." : "")+"</p></strong></center>");
				if (result.status=="redirect") {
					setTimeout("document.location = document.location;", 1000);
				}
			}
		},
		beforeSend: function(){
		}
    });
	return false;
}

function check_form(f) {
	err = "";
	for (i=0; i<f.elements.length; i++) {
		if (f.elements[i].id != "") {
			if ($("#"+f.elements[i].id).hasClass("required") && !f.elements[i].disabled && $("#"+f.elements[i].id).css("display")!="none") {
				lbl = $("#"+f.elements[i].id).attr("title");
				if (f.elements[i].type == "checkbox") {
					if (f.elements[i].checked == false) {
						err += "      - "+removeHTMLTags(lbl.replace(":*", "").replace(":", ""))+"\n";
					}
				} else if (f.elements[i].type == "radio") {
					if (!$("input[name='"+$("#"+f.elements[i].id).attr('name')+"']:checked").val()) {
						err += "      - "+removeHTMLTags(lbl.replace(":*", "").replace(":", ""))+"\n";
					}	
				} else if (f.elements[i].type.indexOf("select") != -1) {
					if (f.elements[i].selectedIndex == 0) {
						err += "      - "+removeHTMLTags(lbl.replace(":*", "").replace(":", ""))+"\n";
					}
				} else {
					if (f.elements[i].value == "" || f.elements[i].value == lbl) {
						err += "      - "+removeHTMLTags(lbl.replace(":*", "").replace(":", ""))+"\n";
					}
				}
			}
		}
	}
	if (err != "") {
		alert("Vyplňte prosím nasledovné údaje:\n"+err);
		return false;
	} else {
		return true;
	}
}

function removeHTMLTags(str) {
	str = str.replace(/&(lt|gt);/g, function (strMatch, p1) {
		return (p1 == "lt")? "<" : ">";
	});
	var str = str.replace(/<\/?[^>]+(>|$)/g, "");
	return str;
}


/*
function get_cat(go, item) {
	var data = '';
	
	jQuery.ajax({
		data: data,
		url: 'page.php?go='+go+'&parent='+item+'&sid=<?echo $_GET["sid"]?>',
		type: 'POST',
		timeout: 30000,
				
		error: function() {
			alert('Dotaz zlyhal');
		},
		success: function(result) {
			$('#zalContent').html(result);
		},
		beforeSend: function() {
			
		},
		complete: function() {
			
		}
	})		
}

function get_item(go, parent, item) {
	var data = '';
	
	jQuery.ajax({
		data: data,
		url: 'page.php?go='+go+'&parent='+parent+'&item='+item+'&sid=<?echo $_GET["sid"]?>',
		type: 'POST',
		timeout: 30000,
				
		error: function() {
			alert('Dotaz zlyhal');
		},
		success: function(result) {
			$('#zalContent').html(result);
		},
		beforeSend: function() {
			
		},
		complete: function() {
			
		}
	})		
}

*/

