
var IE = /*@cc_on!@*/false;
var timeservice = null;

function DaRequest(type) {
    this.type = type;
    this.method = "GET";
    this.url = "";
    this.vars = "";
    this.where = "";
    this.func_done = null;
    this.post_load = null;
}

function xmh_loaddiv(url, where, post_load) {
    var req = new DaRequest();
    var conn = new DaConn();
    req.url = url;
    req.where = where;
    req.func_done = darequest_loaddiv;
    req.post_load = post_load;
    conn.connect(req);
}

function darequest_loaddiv(xmlhttp) {
    var where = document.getElementById(this.where);
    where.innerHTML = xmlhttp.responseText;
    if (this.post_load) this.post_load();
}

function widget_init(widget_name, div_name) {
    var widget = registered_widgets_o[widget_name];
    if (! widget) { throw("Unknown widget"); }
    widget = new widget();
    widget.init(div_name);
    initialized_widgets_o[div_name] = widget;
    widget.build();
    return widget;
}

function widget_start(div_name) {
    var widget = initialized_widgets_o[div_name];
    if (! widget) { throw("Unknown widget"); }
    widget.start();
}

function timeservice_init() {
    timeservice = new TimeService();
    timeservice.init();
}

function timeservice_start() {
    timeservice.start();
}

function set_class(obj, class_name) {
    if (IE) {
        obj.setAttribute("class", class_name);
        obj.setAttribute("className", class_name);
    } else {
        obj.setAttribute("class", class_name);
    }
}

function bind(toObject, methodName){
    return function(){toObject[methodName]()}
}

function toArray(arrayLike) {
    var arr = [];
    for(var i = 0; i < arrayLike.length; i++) {
        arr.push(arrayLike[i]);
    }
    return arr;
}

function callback(func, opts) {
    var cb = function() {
        var args = opts.args ? opts.args : [];
        var bind = opts.bind ? opts.bind : this;
        var fargs = opts.supressArgs === true ? [] : toArray(arguments);
        func.apply(bind, fargs.concat(args));
    }
    return cb;
}

function DaConn()
{
    var xmlhttp, bComplete = false;
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { try { xmlhttp = new XMLHttpRequest(); }
    catch (e) { xmlhttp = false; }}}
    if (!xmlhttp) return null;
    this.connect = function(req)
    {
        if (!xmlhttp) return false;
        bComplete = false;
        var method = req.method.toUpperCase();
        var url = req.url;
        var vars = req.vars;
        try {
            if (method == "GET") {
                if (vars) url = url + "?" + vars;
                xmlhttp.open(method, url, true);
                vars = "";
            } else {
                xmlhttp.open(method, url, true);
                xmlhttp.setRequestHeader("Method", "POST " + url + " HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            }
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && !bComplete) {
                    bComplete = true;
                    //req.func_done(xmlhttp);
                    req.xmlhttp = xmlhttp;
                    req.func_done(req);
                }
            }
            xmlhttp.send(vars);
        }
        catch(z) { return false; }
        return true;
    }
    return this;
}

