/**
 * AJAX - Yana Bridge for plugin "bf_katalog"
 *
 * This file was generated automatically by the Yana-SDK code generator.
 *
 * @package     plugins
 */

/**
 * «constructor» "ApiBfKatalog"
 *
 * @access      public
 * @package     plugins
 * @subpackage  bf
 * @param       string  id
 */
function ApiBfKatalog ($id)
{
    if ($id && typeof $id != 'string') {
        alert('Wrong argument type for argument 1 in constructor ApiBfKatalog(). String expected, found "'+(typeof $id)+'" instead.');
        return;
    } else if (!$id) {
        $id = "yana_stdout";
    }

    if (typeof php_self != 'undefined') {
        var src = php_self;
    } else {
        var src = "";
    }

    if (AjaxRequest) {
        this.http = new AjaxRequest(src);
        if (!document.getElementById($id)) {
            alert('Invalid id in constructor ApiBfKatalog(). The container "'+$id+'" was not found.');
        } else {
            this.http.setTarget($id);
        }
    } else {
        alert('Unable to create new instance of "ApiBfKatalog". A required class "AjaxRequest" was not found.');
    }
}

/* BEGIN custom events */

/**
 * bf_katalog_get_product
 *
 * Type:        read
 * Permission:  0
 * Templates:   NULL
 *
 * @access  public
 * @param   string  $args  (optional) params passed to the function call
 * @param   string  $func  (optional) reference to a function that serves as a custom event handler
 */
ApiBfKatalog.prototype.bfKatalogGetProduct = function ($args, $func)
{
    if ($args && typeof $args  != 'string') {
        alert('Wrong argument type for argument 1 in method ApiBfKatalog.bf_katalog_get_product(). String expected, found "'+(typeof $args)+'" instead.');
        return;
    } else if ($func && typeof $func != 'Function' && typeof $func != 'function') {
        alert('Wrong argument type for argument 2 in method ApiBfKatalog.bf_katalog_get_product(). Function expected, found "'+(typeof $func)+'" instead.');
        return;
    } else if (this.http) {
        if ($func) {
            this.http.setHandler($func);
        } else {
            this.http.setHandler(function (httpResponse, htmlNode)
            {
                // put event handling code here !
                // See this example:
                htmlNode.innerHTML = httpResponse.responseText;
            });
        }
        this.http.send('action=bf_katalog_get_product&' + $args);
    }
}


/**
 * bf_katalog_get_assembly
 *
 * Type:        read
 * Permission:  0
 * Templates:   NULL
 *
 * @access  public
 * @param   string  $args  (optional) params passed to the function call
 * @param   string  $func  (optional) reference to a function that serves as a custom event handler
 */
ApiBfKatalog.prototype.bfKatalogGetAssembly = function ($args, $func)
{
    if ($args && typeof $args  != 'string') {
        alert('Wrong argument type for argument 1 in method ApiBfKatalog.bf_katalog_get_assembly(). String expected, found "'+(typeof $args)+'" instead.');
        return;
    } else if ($func && typeof $func != 'Function' && typeof $func != 'function') {
        alert('Wrong argument type for argument 2 in method ApiBfKatalog.bf_katalog_get_assembly(). Function expected, found "'+(typeof $func)+'" instead.');
        return;
    } else if (this.http) {
        if ($func) {
            this.http.setHandler($func);
        } else {
            this.http.setHandler(function (httpResponse, htmlNode)
            {
                if (httpResponse.responseXML) {
                    yanaXmlDecode(httpResponse.responseXML);
                    /* remove all entries */
                    while (htmlNode.hasChildNodes())
                    {
                        htmlNode.removeChild(htmlNode.firstChild);
                    }
                    /* add default entry */
                    var defaultNode = document.createElement('option');
                    defaultNode.setAttribute("value", 0);
                    if (typeof lang_any != 'undefined') {
                        defaultNode.appendChild(document.createTextNode(lang_any));
                    } else {
                        defaultNode.appendChild(document.createTextNode('beliebig'));
                    }
                    htmlNode.appendChild(defaultNode);

                    /* required for IE, who is not able to resize the element when it is redrawn */
                    if (document.all) {
                        htmlNode.style.width = '480px';
                    }
                    var root = httpResponse.responseXML.lastChild;
                    var node = null;
                    var child = null;
                    var category = null;
                    var assembly = null;
                    var optgroupLabel = 0;
                    var optionValue = 0;
                    var optionText = '';
                    var assemblyId = 0;
                    while ((typeof root != 'undefined') && !root.hasChildNodes())
                    {
                        var root = nextSibling();
                    }
                    if ((typeof root != 'undefined') && root.hasChildNodes()) {
                        for (var i = 0; i < root.childNodes.length; i++)
                        {
                            node = root.childNodes[i];
                            if (node.nodeType != 1) {
                                continue;
                            }
                            if (node.nodeName == 'array' && node.hasChildNodes()) {
                                optgroupLabel = node.getAttribute('id');
                                category = document.createElement('optgroup');
                                category.setAttribute("label", optgroupLabel);
                                for (var j = 0; j < node.childNodes.length; j++)
                                {
                                    child = node.childNodes[j];
                                    if (child.nodeType != 1) {
                                        continue;
                                    }
                                    optionValue = child.getAttribute('id');
                                    optionText = child.firstChild.nodeValue;
                                    assembly = document.createElement('option');
                                    assembly.setAttribute("value", optionValue);
                                    if (assemblyId == optionValue) {
                                        assembly.setAttribute("selected", "selected");
                                    }
                                    assembly.appendChild(document.createTextNode(optionText));
                                    category.appendChild(assembly);
                                }
                                htmlNode.appendChild(category);
                            } else {
                                assemblyId = node.firstChild.nodeValue;
                            }
                        }
                    }
                } else {
                    htmlNode.innerHTML = httpResponse.responseText;
                }
            });
        }
        this.http.send('action=bf_katalog_get_assembly&' + $args);
    }
}

/* END custom events */