﻿if(!window["ElemObjectHash"])
    var ElemObjectHash = new Hashtable();
///Elem Object is a base class that allows Html Objects to be accessed via DOM objects
ElemObject = function ElemObject(ElemId, DivElem) {
    this.ID = ElemId;
    this.Id = ElemId;
    this.Object = document.getElementById(ElemId);
    if (this.Object) {
        this.Object.setAttribute('GetElemObjJSRaw', "ElemObjectHash.get('" + this.Id + "')");
        this.Object.setAttribute('GetElemObjJS', "javascript:eval(ElemObjectHash.get('" + this.Id + "'))");
    }
    else if (DivElem) {
        DivElem.setAttribute('GetElemObjJS', "ElemObjectHash.get('" + this.Id + "')");
    }
    this.GetObject = function() {
        if (this.Object != document.getElementById(ElemId)) {
            this.Object = document.getElementById(ElemId);
            this.Object.setAttribute('GetElemObjJS', "ElemObjectHash.get('" + this.Id + "')");
        }
        return this.Object;
    };
    this.ChildNodes = function() { return this.Object.ChildNodes; }
    this.getElementInParentByTagAndName = function(id, attr, tag, elemname) {
        return jQuery('#' + id).find(tag + '[' + attr + '=' + elemname + ']').get(0);
    };
    this.getElementInParentByTagAndName = function(id, attr, elemname) {
        return jQuery('#' + id).find('[' + attr + '=' + elemname + ']').get(0);
    };
    this.GetElemByTagAndName = function(tag, elemname) {
        return this.getElementInParentByTagAndName(this.ID, 'elemName', tag, elemname);
    };
    ElemObjectHash.put(this.Id, this);
    this.GetJS = "javascript:ElemObjectHash.get('" + this.Id + "')";
    var getJS = this.GetJS;
    this.GetJSRaw = "ElemObjectHash.get('" + this.Id + "')";
    this.callThis = function(oFuncName) {
        return function() { eval(getJS + '.' + oFuncName + '()'); };
    };
    this.GetElemChild = function(tag, name) {
        return this.getElementInParentByTagAndName(this.ID, 'elemName', tag, name);
    };
    this.GetElemChild = function(name) {
        return this.getElementInParentByTagAndName(this.ID, 'elemName', name);
    };

    this.jQuery = function() {
        return jQuery('#' + this.ID);
    };
    this.jQueryChildren = function(filter) {
        return jQuery('#' + this.ID).find(filter);
    }
}
