

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function addOptionWithAdditional(attributes,targetObj,option){
	if(option != null && option != undefined && attributes != null && attributes != undefined && attributes.subAttributes.length>0){
		var subAttrs = attributes.subAttributes;
			targetObj.options.length = subAttrs.length+1;
			targetObj.disabled = false;
			targetObj.enabled = true;					
			targetObj.options[0] = option;
			for(var i = 0;i<subAttrs.length;i++){		
				var subAttr = subAttrs[i];		
				targetObj.options[i+1] = new Option(subAttr.value ,subAttr.property);
				
			}									
	}else{
		targetObj.options.length = 0;
	}
}

function addOption(attributes,targetObj){
	
	if(attributes != null && attributes != undefined && attributes.subAttributes.length>0){
		var subAttrs = attributes.subAttributes;
		targetObj.options.length = subAttrs.length;
		targetObj.disabled = false;
		targetObj.enabled = true;		
		for(var i = 0;i<subAttrs.length;i++){		
			var subAttr = subAttrs[i];		
			targetObj.options[i] = new Option(subAttr.value ,subAttr.property);
			
		}								
	}else{
		targetObj.options.length = 0;
	}
}




/////////////////////////////////////////////


function buildResultSet(rxo){
	var resultSet = new ResultSet();
	var formElement = rxo.getElementsByTagName("form");	
	var formObject;

	
	for(j = 0;j<formElement.length;j++){
		formObject = new FormObject();
		formObject.className = formElement[j].getAttribute("class")
		var attributes = formElement[j].getElementsByTagName("attribute");
		
		
		for(i = 0;i<attributes.length;i++){	
			formObject.addAttribute(makeAttribute(attributes[i]));		
		}
		resultSet.formList.push(formObject);
		
	}
	return resultSet;
	
}

function makeAttribute(attribute){	
	var attributeObject = new AttributeObject();		

	var subAttrs = attribute.getElementsByTagName("attribute");
	if(subAttrs.length > 0){		

		 attributeObject.property = attribute.getAttribute("property");
		 attributeObject.returnType = attribute.getAttribute("returnType");	

		 for(j = 0;j<subAttrs.length;j++){		 	
			var subAttributeObject = new AttributeObject();		
		 	subAttributeObject = makeAttribute(subAttrs[j])
		 	attributeObject.addSubAttribute(subAttributeObject);			 
		 }		 
	}else{
			
		
		attributeObject.property = attribute.getAttribute("property");
		attributeObject.returnType = attribute.getAttribute("returnType");
		try{
			attributeObject.value = attribute.firstChild.data;					
		}catch (e){
			attributeObject.value = "";
		}
			
	}
	return	attributeObject;
}

function ResultSet(){
	this.formList = new Array();
}

function FormObject(){
	this.className;
	this.attrs = new Array();
	this.index = new Array();
}

FormObject.prototype.addAttribute = function ( attribute ){	
	if( !(attribute instanceof AttributeObject) )
		return false;	
	this.attrs.push( attribute );
	this.index[ attribute.property ] = this.attrs.length - 1 ;
	
}

FormObject.prototype.getAttrByProp = function ( prop ){
	return this.attrs[ this.index[ prop ] ];
}

function AttributeObject(){
	this.property;
	this.returnType;
	this.value;
	this.subAttributes = new Array();
	this.index = new Array();	
}

AttributeObject.prototype.addSubAttribute = function ( subAttribute ){
	if( !(subAttribute instanceof AttributeObject) )
		return false;
	
	this.subAttributes.push( subAttribute );
	this.index[ subAttribute.property ] = this.subAttributes.length - 1 ;
}

AttributeObject.prototype.getSubAttrByProp = function ( prop ){
	return this.subAttributes[ this.index[ prop ] ];
}

AttributeObject.prototype.toString = function ( prop ){
	return "property:"+this.property+" - returnType:"+this.returnType+" - value:"+this.value;
}



ResultSet.prototype.getFormByClass = function ( id ){
	try{
		for( var index in this.formList )
			if( this.formList[index].id == id )
				return this.formList[index];
		return null;
	}catch( e ){
		alert( e.message );
		return null;
	}
}



