/**
 * Copyright (c) 2006 IBM. All Rights Reserved.
 */
if (typeof wpf_io == "undefined")
{
var wpf_io = {
// Simplified data access method using same interface as dojo.io.bind.
bind: function(opts) {
    var method = (opts.formNode && opts.formNode.method) || "GET";
    var isPost = method.toLowerCase() == "post";    
    var url = opts.url || opts.formNode.action;    
    var qs;
    if (opts.formNode)
    {
        qs = this.serializeForm(opts.formNode);    
        if (qs && !isPost)
        {
            var sep = "?";
            if (url.indexOf("?") >= 0)
                sep = "&";
            url += sep + qs;
        }
    }
    var xh = this.getXMLHTTP();
    xh.onreadystatechange = function() { 
        if (xh.readyState == 4 && xh.responseText)
        {
            opts.load(null, xh.responseText, null);
        }
    };

    xh.open(isPost ? "POST" : "GET", url, true);  
    xh.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");  
    xh.send(isPost ? qs : null);
},
    
PROGIDS: ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],

getXMLHTTP: function() {
    var xh = null;
    var err = null;
    try { xh = new XMLHttpRequest(); if (xh) return xh; } catch(e) { }    
    for (var i = 0; !xh && i < this.PROGIDS.length; ++i) {
        var progid = this.PROGIDS[i];
        try { xh = new ActiveXObject(progid); } catch(e) { err = e; }
    }
    if (xh) this.PROGIDS = [progid];
    else throw(err);
    return xh;
},

serializeForm: function(form) {
    var q = [];
    for (var i = 0; i < form.elements.length; i++) {
        var vals = this.serializeElement(form.elements[i]);
        if (vals && vals.length > 0)
            q.push(vals.join("&"));
    }
    return q.join("&");
},

serializeElement: function(el) {
    var vals = [];
    if (!el.type) return vals;
    switch (el.type.toLowerCase()) {
    case 'text':    
    case 'textarea':
    case 'hidden':
    case 'password':    
    case 'submit':
        vals.push(encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value));
        break;        
    case 'checkbox':
    case 'radio':
        if (el.checked)
            vals.push(encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value));
        break;
    case 'select-one':
    case 'select-multiple':
        for (var i = 0; i < el.options.length; i++) {
            if (el.options[i].selected)
                vals.push(encodeURIComponent(el.name) + "=" + encodeURIComponent(el.options[i].value));
        }
        break;    
    }
    return vals;  
}
}
}