    
    var Tagcloud = {


        req : "",
        data : "",
        
        
        getUserTags : function(motivid)
        {
            this.MotivID = motivid;
            
            $.ajax({
                url: 'ajax.php?func=getUserTags&motivid='+motivid+'',
                type: 'GET',
                dataType: 'json',
                timeout: 5000,
                cache: false,
                global: 'false',
                error: function(){
                   alert('Fehler. Deine Tagcloud konnte nicht geladen werden.');
                },
                success: this.showTagcloud
             
            });
        },
        
        showTagcloud : function(data, textStatus)
        {
            document.getElementById("container_usertags").innerHTML = "";
            
            if(data.Usertags) {
                    
                var ausgabe  = "deine Tags: ";
                             
                for (var i=0;i<data.Usertags.length;i++)
                {
                    ausgabe += " <a href=\"index.php?page=tags&tag="+data.Usertags[i].Tag+"\">"+data.Usertags[i].Tag+"</a> <a href=\"#\" onclick=\"Tagcloud.deleteUserTag("+Tagcloud.MotivID+", "+data.Usertags[i].TagID+"); return false;\" ><img src=\"gfx/icons/delete_icon.gif\"></a>";
                               
                        
                }
                document.getElementById("container_usertags").innerHTML = ausgabe;
                      
            }
            else {
                //document.getElementById("container_usertags").innerHTML = "keine"; 
            }
            if(data == "Du musst dich einloggen") {
                //document.getElementById("container_usertags").innerHTML = "du musst dich <a href=\"index.php?page=login\">einloggen</a> um Tags speichern zu können."; 
            }
             
        },
	
	showFormular : function(motivid)
	{
	    
	    
	    
	    var ausgabe = "Tagge den Artikel. <a href=\"index.php?page=faq&id=36\"><img src=\"gfx/icons/info.png\"></a>";
	   
	    ausgabe += "<form id=\"tagging\" method=\"POST\"  name=\"\">";
	    ausgabe += "<input type=\"hidden\" name=\"func\" value=\"insertTag\">";
	    ausgabe += "<input type=\"hidden\" name=\"motivid\" id=\"motivid\" value=\""+motivid+"\">";
		    
	    ausgabe += "<input type=\"text\" name=\"tagstring\" id=\"tagstring\" value=\"\">";
	    ausgabe += "<input type=\"submit\" class=\"\" value=\"los\" name=\"senden\" />";              
	    ausgabe += "</form>";
            
            ausgabe += " <small>(getrennt durch Komma)</small>";
            
	    ausgabe += "<div id=\"container_usertags_info\">";        
	    ausgabe += "</div>";     
	    ausgabe += "<div id=\"container_usertags\">";     
	    ausgabe += "</div>";
	
	    document.getElementById("container_tagging").innerHTML = ausgabe;
	    
	},
	sendFormular : function()
	{
	   
		    input = new Object();
		    
		    input.motivid   = $("#motivid").attr('value');
		    input.tagstring = $("#tagstring").attr('value');
		  
		    $.ajax({
			    type: "POST",
			    timeout: 5000,
			    data: {
				
				 motivid: input.motivid,
				 tagstring: input.tagstring
				
			    },
			    url: "ajax.php?func=insertTag",
			    success: function(data, textStatus) {
				
				    if(textStatus == "success" && data != "false") {
					    document.getElementById("container_usertags_info").setAttribute("class", "infobox");
					    document.getElementById("container_usertags_info").innerHTML = "Hinweis: "+data+"";
					    Tagcloud.getUserTags(input.motivid);
				    }
				    else {
					    document.getElementById("container_usertags_info").setAttribute("class", "infobox");
					    document.getElementById("container_usertags_info").innerHTML = "Hinweis: Daten konnten nicht eingetragen werden";
				    }
			    },
			    
			    error: function(data, textStatus) {
				document.getElementById("container_usertags_info").setAttribute("class", "errorbox");
				document.getElementById("container_usertags_info").innerHTML = "Error: Daten konnten nicht eingetragen werden";
				    
			    }
		    });
	},
	
	deleteUserTag : function(motivid, tagid)
        {
            $.ajax({
                url: 'ajax.php?func=deleteUserTag&motivid='+motivid+'&tagid='+tagid+'',
                type: 'GET',
                dataType: 'json',
                timeout: 5000,
                global: 'false',
                error: function(){
                   alert('Fehler. der Tag konnte nicht gelöscht werden.');
                },
                success: function(data, textStatus) {
                    if(textStatus == "success" && data != "false") {
                            document.getElementById("container_usertags_info").setAttribute("class", "infobox");
                            document.getElementById("container_usertags_info").innerHTML = "Hinweis: "+data+"";
                            Tagcloud.getUserTags(motivid);
                    }
                    else {
                            document.getElementById("container_usertags_info").setAttribute("class", "infobox");
                            document.getElementById("container_usertags_info").innerHTML = "Hinweis: Daten konnten nicht gelöscht werden";
                    }
                   
                }
             
            });
        }
        
    };
               

        
    
