﻿function Element(clientId) {
    
    this.element;
    this.clientId;
    this.id;


    this.registerObject = function(clientId) {
        this.element = document.getElementById(clientId);
        this.clientId = clientId;

        var split = clientId.split("_");

        this.id = split[split.length - 1];
    };

    if (clientId != null)
        this.registerObject(clientId);
}

function Elements() {
    this.elements = new Array();

    this.registerElement = function(clientId)
    {
        if (!this.findClientId(clientId)) {
            this.elements[this.elements.length] = new Element(clientId);
        }
    };

    this.findId = function(id)
    {
        for( var i = 0; i < this.elements.length; i++ )
        {
            if (this.elements[i].id.toLowerCase() == id.toLowerCase())
                return this.elements[i];
        }
        
        return null;
    };

    this.findClientId = function(clientId) {
        for (var i = 0; i < this.elements.length; i++) {
            if (this.elements[i].clientId.toLowerCase() == clientId.toLowerCase())
                return this.elements[i];
        }
        return null;
    };
}

var swRegistry = new Elements();

function sw$(id)
{
    var ret = swRegistry.findId(id);

    if (ret != null) return $(ret.element);

    return $(id);
}
function registerAspElement(clientId)
{
    swRegistry.registerElement(clientId);
}

$(document).ready(function() {
    var items = $(".aspElement");
    for (var i = 0; i < items.length; i++) {
        registerAspElement(items[i].id);
    }

});