

function addAttachment(noteID,notecategory) {
	$("#note-wrapper-"+noteID+"-"+notecategory).find(".note-attachments.add").slideToggle("fast");
}

function toggleContentFunc(obj, parent) {
	var targetContent = $('div.note-content', parent);
	if (targetContent.css('display') == 'none') {
		targetContent.slideDown(300);
		$(obj).html('[-]');
		$(obj).attr('title', 'Zbaliť poznámku');
		$(obj).attr("href", "#hide");
		$(obj).removeClass("plus");
		$(obj).parent().children(".note-title").remove();
	} else {
		targetContent.slideUp(300);
		$(obj).html('[+]');
		$(obj).attr('title', 'Rozbaliť poznámku');
		$(obj).attr("href", "#show");
		$(obj).addClass("plus");

		$(obj).before("<p class='note-title'>"+$(obj).parents(".note-wrapper").find(".note-date").html()+"</p>");
	}
}

var toggleContent = function(e)
{
	toggleContentFunc(this, this.parentNode.parentNode);
	return false;
};


function activateEditor(isToggleContent) {
	if(isToggleContent == true) {
		$('a.closeEl').bind('click', toggleContent);
	} else {
		$(".note-header .closeEl").hide();
	}
	$('.note-editor').emolrte({
		cssFile: 'css/rte.css',
		tools: rteLiteTools
	});
}

function removeEditorToolbar() {
	$('#notes-toolbar').remove();
}



		function editNote(noteID, textareaID) {
			$.post("modules/notes/ajax.php", { action: "NoteEdit", noteid: noteID, text: $(textareaID).val() },
				function(data){
					if(data == "1") {
						humanMsg.displayMsg('"Vaša poznámka bola úspešne uložená."');
						return false;
					} else {
						humanMsg.displayMsg('"Nastala chyba!"<br />'+data);
						return false;
					}
				}
			);
		}

		function deleteNote(noteID, notecategory) {
			$.post("modules/notes/ajax.php", { action: "NoteDelete", noteid: noteID, catid: notecategory },
				function(data){
					if(data != "0") {
						$("#notes").fadeTo("fast",0.33, function(){
							$("#note-wrapper-"+noteID+"-"+notecategory).remove();
							$(this).fadeTo("fast",1);

							humanMsg.displayMsg('"Vaša poznámka bola úspešne vymazaná."');
							return false;
						});
					} else {
						humanMsg.displayMsg('"Nastala chyba!"<br />'+data);
						return false;
					}
				}
			);
		}

		function uploadFile(noteID, notecategory) {
			 $('#attachment-form-'+noteID).ajaxForm({
				beforeSubmit: function(a,f,o) {
					o.dataType = "html";
					$('#note-wrapper-'+noteID+'-'+notecategory).find(".note-attachments.add input[type=submit]").after("<img src='images/loader.gif' id='uploadLoader-"+noteID+"' alt='Odosielam ...' />");
				},
				resetForm: true,
				success: function(data) {
					$("#uploadLoader-"+noteID).remove();
					if(data != 0)
					{
						var $out = $('#note-wrapper-'+noteID+'-'+notecategory);
						if($($out).find(".note-attachments.files").size() > 0) {
							$out.find(".note-attachments.files").replaceWith(data);
						} else {
							$out.find("textarea.note-editor").after(data);
						}
						humanMsg.displayMsg('"Súbor bol nahraný."');
					} else {
						humanMsg.displayMsg('"Nastala chyba!"');
					}
				}
			 });
		}


		function deleteFile(fileID, noteID, fileName, userID, notecategory) {
			$.post("modules/notes/ajax.php", { action: "FileDelete", fileid: fileID, noteid: noteID, filename: fileName, userid: userID, notecategory: notecategory },
				function(data){
					if(data != "0") {
						var $out = $('#note-wrapper-'+noteID+'-'+notecategory);
						if($($out).find(".note-attachments.files li").size() == 1) {
							$($out).find(".note-attachments.files").fadeTo("fast",0, function(){
								$(this).remove();
								humanMsg.displayMsg('"Súbor bol vymazaný."');
							});
						} else {
							$($out).find(".note-attachments.files li#attachment-"+fileID).fadeTo("fast",0, function(){
								$(this).remove();
								humanMsg.displayMsg('"Súbor bol vymazaný."');
							})
						}
						return false;
					} else {
						humanMsg.displayMsg('"Nastala chyba!"<br />'+data);
						return false;
					}
				}
			);
		}

		function catEditName(catid) {
			alert("coming soon");
		}


		function move_opt(from_id, to_id, opt_val, sel_id) {
      var newOption = document.createElement("option");
      newOption.text = opt_val;
      newOption.value = opt_val;
      document.getElementById(to_id).options.add(newOption);

      var elSel = document.getElementById(from_id);
      var i;
      for (i = elSel.length - 1; i>=0; i--) {
        if (elSel.options[i].selected) {
          elSel.remove(i);
        }
      }
		}

    function dalsi_obr()
    {
      var popis = document.getElementById("test9").alt;
      if(popis == "Logo c.1")
      {
        document.getElementById("test9").src="images/logo2.png";
        document.getElementById("test9").alt="Logo c.2";
      }
      else if (popis == "Logo c.2")
      {
        document.getElementById("test9").src="images/logo3.png";
        document.getElementById("test9").alt="Logo c.3";
      }
      else
      {
        document.getElementById("test9").src="images/logo1.png";
        document.getElementById("test9").alt="Logo c.1";

      }
    }

    function vypocet()
    {
      var xy=document.getElementById("test9a").value;
      var ab=document.getElementById("test9b").value;
      var vysledok = 0;

      if(xy>0 && ab>0)
        vysledok=xy*ab;

      setTimeout("document.getElementById('test9v').value="+vysledok,1250);

    }
