/**
 * AJAX - Yana Bridge for plugin "guestbook"
 *
 * This file was generated automatically by the Yana-SDK code generator.
 *
 * @package     plugins
 */

/**
 * «constructor» "YanaGuestbook"
 *
 * @access      public
 * @package     plugins
 * @subpackage  guestbook
 * @param       string  id
 */
function YanaGuestbook ($id)
{
    if ($id && typeof $id != 'string') {
        alert('Wrong argument type for argument 1 in constructor YanaGuestbook(). String expected, found "'+(typeof $id)+'" instead.');
        return;
    } else if (!$id) {
        $id = "yana_stdout";
    }

    if (!src) {
        var src = window.location.href;
    }

    if (AjaxRequest) {
        this.http = new AjaxRequest(src);
        if (!document.getElementById($id)) {
            alert('Invalid id in constructor YanaGuestbook(). The container "'+$id+'" was not found.');
        } else {
            this.http.setTarget($id);
        }
    } else {
        alert('Unable to create new instance of "YanaGuestbook". A required class "AjaxRequest" was not found.');
    }
}

/**
 * call YANA-function by name
 *
 * @param   string  $func     name of function to execute
 * @param   string  $args     (optional) params passed to the function call
 * @param   string  $handler  (optional) reference to a function that serves as a custom event handler
 * @name    YanaGuestbook::callFunctionByName()
 */
YanaGuestbook.prototype.callFunctionByName = function($func, $args, $handler)
{
    if ($func && typeof $func  != 'string') {
        alert('Wrong argument type for argument 1 in method YanaGuestbook.callFunctionByName(). String expected, found "'+(typeof $func)+'" instead.');
        return;
    } else if ($args && typeof $args  != 'string') {
        alert('Wrong argument type for argument 2 in method YanaGuestbook.callFunctionByName(). String expected, found "'+(typeof $args)+'" instead.');
        return;
    } else if ($handler && typeof $handler != 'Function' && typeof $handler != 'function') {
        alert('Wrong argument type for argument 3 in method YanaGuestbook.callFunctionByName(). Function expected, found "'+(typeof $handler)+'" instead.');
        return;
    } else {
        if ($handler) {
            this.http.setHandler($handler);
        } else {
            this.http.setHandler(function (httpResponse, htmlNode)
            {
                // put event handling code here !
                // See this example:
                htmlNode.innerHTML = httpResponse.responseText;
                // this will re-initialize the page (when needed)
                if (document.body.onload) {
                    document.body.onload();
                }                
            });
        }
        this.http.send('action=' + escape($func) + '&' + $args);
    }
}

/* BEGIN custom events */

/**
 * call a PHP function via AJAX
 *
 * @static
 * @access  public
 * @param   string  $func  function name
 * @param   string  $id    dataset-id
 * @param   string  $args  function arguments
 */
YanaGuestbook.prototype.guestbookRequest = function ($func, $id, $args, $form)
{
    var guestbook = new YanaGuestbook($id);
    if (typeof $form == 'string') {
        var o = document.getElementById($form);
        if (typeof o != 'undefined' && typeof o.elements  != 'undefined') {
            for (var i = 0; i < o.elements.length; i++)
            {
                if (o.elements[i].name) {
                    $args += '&' + escape(o.elements[i].name.toLowerCase()) + '=' + escape(o.elements[i].value);
                }
            }
        }
    }
    guestbook.callFunctionByName($func, $args);
}

/* END custom events */
/**
 * Yana Framework 3.0.0RC1
 * Copyright © 2008  Thomas Meyer  http://www.yanaframework.net
 * Copyright Hinweise dürfen NICHT entfernen werden!
 * Copyright notices may NOT be removed!
 */
