registerNamespace("no.follesoe.jonas");

no.follesoe.jonas.Bussorakel = function(p_elSource, p_args, p_namespace)
{        
    no.follesoe.jonas.Bussorakel.initializeBase(this, arguments);
 
    var spm;
        
    this.initialize = function(p_objScope)
    {
        no.follesoe.jonas.Bussorakel.getBaseMethod(this, "initialize", "Web.Bindings.Base").call(this, p_objScope);

        var div = document.createElement("div");
        var icon = document.createElement("img");
        spm = document.createElement("textarea");                              
                                        
        icon.className = "icon";
        icon.src = "http://localhost/LiveGadgets/Bussorakel/Icon.png";
        icon.alt = "Klikk for å spørre...";
        icon.attachEvent("onclick", askQuestion);
                

        
        div.appendChild(spm);
        divRight.appendChild(icon);
        
        p_elSource.appendChild(div);            
    }
    no.follesoe.jonas.Bussorakel.registerBaseMethod(this, "initialize");

    this.dispose = function(p_objScope)
    {
        no.follesoe.jonas.Bussorakel.getBaseMethod(this, "dispose", "Web.Bindings.Base").call(this, p_objScope);    
    }
    no.follesoe.jonas.Bussorakel.registerBaseMethod(this, "dispose");
    
    function askQuestion()
    {           
        url = "http://localhost/LiveGadgets/Bussorakel/BussorakelService.asmx/Ask?question=" + spm.innerText;
        spm.innerText = "Vennligst vent...";
        var request = Web.Network.createRequest(
                                Web.Network.Type.XMLGet,
                                url,
                                null,
                                receiveResponse,
                                Web.Utility.Prioritizer.Priorities.High);
        request.execute();
    }            
        
    function receiveResponse(response)
    {
        var root = response.responseXML.documentElement;
        if(root)
        {
            spm.innerText = root.childNodes[0].nodeValue; 
        }       
    }
}
no.follesoe.jonas.Bussorakel.registerClass("no.follesoe.jonas.Bussorakel", "Web.Bindings.Base");