var PlaylistSuggest = Class.create(TextSuggest, {
    
    callAjax: function() {
        
        if (this.id=='artistInput') {
            parameter0 = this.lastRequestString;
        }
        else {
            parameter0 = $F('artistInput');
        }
        if (this.id=='titelInput') {
            parameter1 = this.lastRequestString;
        }
        else {
            parameter1 = $F('titelInput');
        }
        
        new Ajax.Request('/ajax.php',
                     {
                       method:'post',
                       parameters: {
                            request: this.id,
                            id: this.id,
                            pars0: parameter0,
                            pars1: parameter1,
                            pars3: this.id,
                            pars4: this.options.matchAnywhere,
                            pars5: this.options.count,
                            jetztclass: 'Playlist',
                            jetztfunction: 'searchSong'
                       },                 
                       onSuccess: this.ajaxUpdate.bind(this)
                     }
                    );
    },

    createSuggestions: function(ajaxResponse) {
        this.suggestions = [];

        if (ajaxResponse.getElementsByTagName("data")[0].hasChildNodes() && 
            ajaxResponse.getElementsByTagName("data")[0].getElementsByTagName("success")[0].childNodes[0].nodeValue=='1' && 
            ajaxResponse.getElementsByTagName("data")[0].getElementsByTagName("songs")[0].hasChildNodes()) {
            
            var text = '';
            var value = '';
            
            for (var i=0;i<ajaxResponse.getElementsByTagName("row").length;i++) {
                if (this.id=='artistInput') {
                    text  = ajaxResponse.getElementsByTagName("row")[i].getElementsByTagName("artist")[0].childNodes[0].nodeValue;
                    value = ajaxResponse.getElementsByTagName("row")[i].getElementsByTagName("artist")[0].childNodes[0].nodeValue;
                }
                else if (this.id=='titelInput') {
                    text  = ajaxResponse.getElementsByTagName("row")[i].getElementsByTagName("titel")[0].childNodes[0].nodeValue;
                    value = ajaxResponse.getElementsByTagName("row")[i].getElementsByTagName("titel")[0].childNodes[0].nodeValue;
                }
                this.suggestions.push({ text: text, value:  value});
            }
        }
   }
   
});

