function XFAModel(){
	this.layout = null;
	this.record = null;
}

function JXML(ele){
	this.element = ele;
	this.generateECMA = generateECMA;
}

function generateECMA() {
	var obj = this.element;
    for (var i = 0; i < obj.getChildNodes().getLength(); i++) {
        var child = obj.getChildNodes().item(i);
        if (child.getNodeType() == 1) {
        	var childXML = new JXML(child);
            var childName = child.getNodeName();
            if (childName in this) {
                if (this[childName] instanceof Array) {
                    var cArr = this[childName];
                    cArr[cArr.length] = childXML;
                } else {
                    var cArr = new Array();
                    cArr[0] = this[childName];
                    cArr[1] = childXML;
                }
                this[childName] = cArr;
            } else {
                this[childName] = childXML;
            }
            childXML.generateECMA();
        }
    }
}

Object.defineProperty(JXML.prototype, "resolveNode", {value: function(stringParam) {
	    var strArr = stringParam.split(".");
	    var tempNode = this.element;
	    for (var z = 0; z < strArr.length; z++) {
	        var val = strArr[z].replace(/[#]+/, '');
	        var searchInt = 0;
	        if (val.indexOf("[") !== -1) {
	            var searchStr = val.substring(val.indexOf("[") + 1, val.length - 1);
	            val = val.substring(0, val.indexOf("["));
	            searchInt = parseInt(searchStr);
	        }
	        tempNode = tempNode.getElementsByTagName(val).item(searchInt);
	    }
	    var find = new JXML(tempNode);
	    return find;
	    
	}, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, 'getAttribute', {value: function(atrName) {
        return this.element.getAttribute(atrName);
    }, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, "setAttribute", {value: function(atrName, atrValue) {
        this.element.setAttribute(atrName.atrValue);
    }, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, "removeAttribute", {value: function(stringParam) {
        this.element.removeAttribute(stringParam);
    }, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, "append", {value: function(newNode) {
        this.element.appendChild(newNode);
    }, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, "clone", {value: function(boolParam) {
        return this.element.cloneNode(boolParam);
    }, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, "remove", {value: function(nodeToRemove) {
        this.element.removeChild(nodeToRemove);
    }, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, "insert", {value: function(newNode, beforeNode) {
        //
    }, configurable: true, enumerable: true, writable: true});

Object.defineProperty(JXML.prototype, "item", {value: function(intParam) {
        //implement later
    }, configurable: true, enumerable: true, writable: true});
    
Object.defineProperty(JXML.prototype, "access", {get: function() {
	        return this.element.getAttribute("access");
	    }, set: function(newValue) {
	        this.element.setAttribute("access", newValue);
	    }, configurable: true, enumerable: true});
	    
Object.defineProperty(JXML.prototype, "accessKey", {get: function() {
        return this.element.getAttribute("accessKey");
    }, set: function(newValue) {
        this.element.setAttribute("accessKey", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "anchorType", {get: function() {
        return this.element.getAttribute("anchorType");
    }, set: function(newValue) {
        this.element.setAttribute("anchorType", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "borderColor", {get: function() {
        return this.element.getAttribute("borderColor");
    }, set: function(newValue) {
        this.element.setAttribute("borderColor", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "borderWidth", {get: function() {
        return this.element.getAttribute("borderWidth");
    }, set: function(newValue) {
        this.element.setAttribute("borderWidth", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "colSpan", {get: function() {
        return this.element.getAttribute("colSpan");
    }, set: function(newValue) {
        this.element.setAttribute("colSpan", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "editValue", {get: function() {
        return this.element.getAttribute("editValue");
    }, set: function(newValue) {
        this.element.setAttribute("editValue", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "fillColor", {get: function() {
        return this.element.getAttribute("fillColor");
    }, set: function(newValue) {
        this.element.setAttribute("fillColor", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "fontColor", {get: function() {
        return this.element.getAttribute("fontColor");
    }, set: function(newValue) {
        this.element.setAttribute("fontColor", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "formatMessage", {get: function() {
        return this.element.getAttribute("formatMessage");
    }, set: function(newValue) {
        this.element.setAttribute("formatMessage", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "formattedValue", {get: function() {
        return this.element.getAttribute("formattedValue");
    }, set: function(newValue) {
        this.element.setAttribute("formattedValue", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "h", {get: function() {
        return this.element.getAttribute("h");
    }, set: function(newValue) {
        this.element.setAttribute("h", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "hAlign", {get: function() {
        return this.element.getAttribute("hAlign");
    }, set: function(newValue) {
        this.element.setAttribute("hAlign", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "locale", {get: function() {
        return this.element.getAttribute("locale");
    }, set: function(newValue) {
        this.element.setAttribute("locale", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "mandatory", {get: function() {
        return this.element.getAttribute("mandatory");
    }, set: function(newValue) {
        this.element.setAttribute("mandatory", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "mandatoryMessage", {get: function() {
        return this.element.getAttribute("mandatoryMessage");
    }, set: function(newValue) {
        this.element.setAttribute("mandatoryMessage", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "maxH", {get: function() {
        return this.element.getAttribute("maxH");
    }, set: function(newValue) {
        this.element.setAttribute("maxH", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "maxW", {get: function() {
        return this.element.getAttribute("maxW");
    }, set: function(newValue) {
        this.element.setAttribute("maxW", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "minH", {get: function() {
        return this.element.getAttribute("minH");
    }, set: function(newValue) {
        this.setAttribute("minH", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "minW", {get: function() {
        return this.element.getAttribute("minW");
    }, set: function(newValue) {
        this.element.setAttribute("minW", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "parentSubform", {get: function() {
        return this.element.getAttribute("parentSubform");
    }, set: function(newValue) {
        this.element.setAttribute("parentSubform", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "presence", {get: function() {
        return this.element.getAttribute("presence");
    }, set: function(newValue) {
        this.element.setAttribute("presence", newValue);
       
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "rawValue", {get: function() {
        var parentEle = this.element.getParentNode();
        if(parentEle.getAttribute("className").equals("exclGroup")){
            var cur = this.element.getAttributes().getNamedItem("rawValue");
            var itemsLen = this.element.getElementsByTagName("items").length;
            if(cur!=null && itemsLen>0){
                return this.element.getElementsByTagName("items").item(0).getTextContent();
            }
        }
        return this.element.getAttribute("rawValue");
        
    }, set: function(newValue) {
        print("rawvalue called")
        this.element.setAttribute("rawValue", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "relevant", {get: function() {
        return this.element.getAttribute("relevant");
    }, set: function(newValue) {
        this.element.setAttribute("relevant", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "rotate", {get: function() {
        return this.element.getAttribute("rotate");
    }, set: function(newValue) {
        this.element.setAttribute("rotate", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "selectedIndex", {get: function() {
        return this.element.getAttribute("selectedIndex");
    }, set: function(newValue) {
        this.element.setAttribute("selectedIndex", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "use", {get: function() {
        return this.element.getAttribute("use");
    }, set: function(newValue) {
        this.element.setAttribute("use", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "usehref", {get: function() {
        return this.element.getAttribute("usehref");
    }, set: function(newValue) {
        this.element.setAttribute("usehref", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "validationMessage", {get: function() {
        return this.element.getAttribute("validationMessage");
    }, set: function(newValue) {
        this.element.setAttribute("validationMessage", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "vAlign", {get: function() {
        return this.element.getAttribute("vAlign");
    }, set: function(newValue) {
        this.element.setAttribute("vAlign", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "w", {get: function() {
        return this.element.getAttribute("w");
    }, set: function(newValue) {
        this.element.setAttribute("w", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "x", {get: function() {
        return this.element.getAttribute("x");
    }, set: function(newValue) {
        this.element.setAttribute("x", newValue);
    }, configurable: true, enumerable: true});
    
Object.defineProperty(JXML.prototype, "y", {get: function() {
        return this.element.getAttribute("y");
    }, set: function(newValue) {
        this.element.setAttribute("y", newValue);
    }, configurable: true, enumerable: true});
