
function saveProductInput(value_, customers_name_, products_id_, type_, question_) {
    XMLRequest.dfSendForm(null, {'action':'save', 'text' : value_, 'username' : customers_name_, 'type': type_, 'question': question_, 'products_id' : products_id_, 'osCsid': ajaxsid}, '/c2c_coop/c2c_coop.php', 'POST', 'txt', null, getProductInputs, products_id_);
}

function getProductInputs(async_, products_id_) {
    XMLRequest.dfSendForm(null, {'action':'get', 'products_id' : products_id_, 'osCsid': ajaxsid}, '/c2c_coop/c2c_coop.php', 'POST', 'txt', null, refreshElement, 'product_input_list');
}

function deleteProductInput(comment_id_, products_id_) {
    XMLRequest.dfSendForm(null, {'action':'delete', 'comment_id' : comment_id_, 'osCsid': ajaxsid}, '/c2c_coop/c2c_coop.php', 'POST', 'txt', null, getProductInputs, products_id_);
}

function refreshElement(response_, refreshId_) {
    var e = document.getElementById(refreshId_);
    if (!e) { window.status='Element ' + refreshId_ + ' not found.'; return; }
    e.innerHTML = response_;
}

function visibleStartlink() {
    var l = document.getElementById('product_input_startlink');
    if (l) { l.style.display = 'inline'; }    
}

function hiddenInputField() {
    var f = document.getElementById('product_input_frame');
    if (f) { f.parentNode.removeChild(f); }
}

function removeProductInput(comment_id_, products_id_) {
    if (window.confirm('Soll Ihr Beitrag gelöscht werden?')) {
        deleteProductInput(comment_id_, products_id_);
    }
}

function openProductInput(event_, products_id_, customers_name_, type_, question_) {
    var ev = event_ || window.event;
    var el = ev.srcElement || ev.target;
    var href = document.location.href;
    var search = document.location.search;
    
    if (!document.getElementById('product_input_frame')) {
        var f = document.createElement('DIV');
        f.id = 'product_input_frame';
        f.style.width = '360px';
        f.style.height = '130px';
        f.style.display = 'inline';
        f.style.position = 'relative';
        
        var name = document.createElement('DIV');
        name.className = 'main';
        name.style.fontWeight = 'bold';
        name.style.fontSize = '12px';
        name.id = 'product_input_username';
        if (!customers_name_) {
            customers_name_ = 'Anonymer Nutzer';
            name.innerHTML = customers_name_ + ' schreibt:<br><ul><li><i style="font-weight: normal; font-size: 10px">Um später diesen Text löschen zu können, sollten Sie sich zuvor anmelden.</i></li><li><i style="font-weight: normal; font-size: 10px">Anonyme Beiträge erscheinen erst nach Freischaltung.</i></li></ul>';
        } else {
            name.innerHTML = customers_name_ + ' schreibt:';
        }
        f.appendChild(name);

        var question = document.createElement('SELECT');
        question.className = 'main';
        question.style.fontWeight = 'bold';
        question.style.fontSize = '12px';
        question.id = 'product_input_type';
        var msg = '';
        for(var c=0; c <= 5; c++) {
            switch(c) {
                case 0:
                  msg = 'Was ist Ihre Meinung zu diesem Produkt?';
                  break;
                case 1:
                  msg = 'Haben Sie einen guten Tipp zu diesem Produkt?';
                  break;
                case 2:
                  msg = 'Würden Sie dieses Produkt weiter empfehlen?';
                  break;
                case 3:
                  msg = 'Kennen Sie sich mit dem Produkt aus? Was würden Sie hier ergänzen wollen?';
                  break;
                case 4:
                  msg = 'Wie verwenden Sie dieses Produkt?';
                  break;
                case 5:
                  msg = 'Wie würden Sie anderen dieses Produkt beschreiben?';
                  break;
            }
            var o = new Option(msg);
            o.value = c;
            if (type_ == c) {
                o.selected = true;
            }
            question[question.length] = o;            
        }

        f.appendChild(question);

        var content = document.createElement('TEXTAREA');
        content.id = 'product_input_textarea';
        content.style.width = '440px';
        content.style.height = '130px';
        content.style.display = 'block';
        content.style.position = 'relative';

        f.appendChild(content);

        var button = document.createElement('INPUT');
        button.type = 'button';
        button.style.width = '110px';
        button.style.height = '30px';
        button.style.display = 'inline-block';
        button.style.position = 'relative';        
        button.value = 'Speichern';

        button.onclick = function() {
            var pt = document.getElementById('product_input_type');
            var t = document.getElementById('product_input_textarea');
            saveProductInput(t.value, customers_name_, products_id_, pt.selectedIndex, pt[pt.selectedIndex].text);
            hiddenInputField();
            visibleStartlink();               
        }
        
        f.appendChild(button);

        var button = document.createElement('INPUT');
        button.type = 'button';
        button.style.width = '110px';
        button.style.height = '30px';
        button.style.display = 'inline-block';
        button.style.position = 'relative';
        button.style.left = '10px';
        button.value = 'Abbrechen';

        button.onclick = function() {
            hiddenInputField();
            visibleStartlink();
        }
        
        f.appendChild(button);
        
        el.style.display = 'none';
        el.parentNode.appendChild(f);
        
        content.focus();
    }
}

function highlightBackgroundImage(self_) {
    if (!self_) { return; }
    
    if (self_ && self_.style && self_.style.backgroundImage) {
        if (self_.style.backgroundImage.indexOf('_default') != -1) {
            self_.style.backgroundImage = self_.style.backgroundImage.replace('_default', '_highlight');
        }
    }
}

function defaultBackgroundImage(self_) {
    if (!self_) { return; }
    
    if (self_ && self_.style && self_.style.backgroundImage) {
        if (self_.style.backgroundImage.indexOf('_highlight') != -1) {
            self_.style.backgroundImage = self_.style.backgroundImage.replace('_highlight', '_default');
        }
    }
}
