﻿Type.registerNamespace("Dabs.Ajax.Utilities");


/*
Creates an associative array/object of current querystring params
Use QueryString.getValue() as a case insensitive way of retrieving qs params
Requests for non-existent params will return undefined
*/
Dabs.Ajax.Utilities.QueryString = function(){
    this.initialise();
}

Dabs.Ajax.Utilities.QueryString.prototype = {
    initialise: function(){
        // returns the current URL's querystring parameters as an associative array/object
        var qsPairs = location.search.replace(/\?/,"").split("&");
        this._queryStringCollection = new Object();
        
        for(i=0;i<qsPairs.length;i++)
        {
            this._queryStringCollection[qsPairs[i].split("=")[0].toUpperCase()] = qsPairs[i].split("=")[1];
        }
    },
    
    getValue: function(key){
        return this._queryStringCollection[key.toUpperCase()];
    },
    
    dispose: function(){
        this._queryStringCollection = null;
    }
}

Dabs.Ajax.Utilities.QueryString.registerClass('Dabs.Ajax.Utilities.QueryString',null,Sys.IDisposable)


/*
    Creates a scrollable white div at the top left of a page.
    Use DebugPanel.writeLine to write debug text to the panel
    Use Debug.clear to remove all debug text from the panel
*/
Dabs.Ajax.Utilities.DebugPanel = function(){

    this.initialise();
    
}

Dabs.Ajax.Utilities.DebugPanel.prototype = {
    initialise: function(){
        var body = document.getElementsByTagName("body")[0];
        this._panel = document.createElement("div");
        this._panel.style.width = "500px";
        this._panel.style.height = "200px";
        this._panel.style.overflow = "auto";
        this._panel.style.position = "absolute";
        this._panel.style.top = 0;
        this._panel.style.left = 0;
        this._panel.style.backgroundColor = "white";
        this._panel.style.display = "block";
        this._panel.style.filter = "alpha(opacity=85)";
        this._panel.style.MozOpacity = "0.85";
        this._panel.style.opacity = "0.85";
        body.appendChild(this._panel);
    },
    
    writeLine: function(text){
        this._panel.innerHTML += "<br />" + text;
    },
    
    clear: function(){
        this._panel.innerHTML = "";
    },
    
    dispose: function(){
    
    }
}

Dabs.Ajax.Utilities.DebugPanel.registerClass('Dabs.Ajax.Utilities.DebugPanel',null,Sys.IDisposable)
