//Design By Augustus 2009
//Need custom.js : is_array(para1);
//create frames at 2009
//function to class 2010.02
//xmlobject.SetFilter(arr1,arr2) arr1 is one-dimentional to fitlers,arr2 is two-dimentional to filters values

//notes
//1. new xmlobject;
//2. loadxml
//3. SetFilter
//4. XmlToArray
//5. getArray getRowCount getceilCount getfieldNames

function xmlobject(){
	this.xmlDoc;
/**/if(window.ActiveXObject)
	{
		this.xmlDoc= new ActiveXObject("microsoft.XMLDOM");
		
/**/}
	else
	{
		this.xmlDoc=document.implementation.createDocument("", "", null);
		this.xmlDoc.host=this;
		this.xmlDoc.onload=function(){
			XmlToArray();
				//alert(this.host.xmlDoc.getElementsByTagName("record").length);
		}
	}
	 
	
this.xmlDoc.async=false;
	
	this.loadxml=function(xmlfile){
//		alert(getHTTPPage(xmlfile));

		this.xmlDoc.load(xmlfile);
		
	}
		
	this.records=new Array();
	this.fieldname=new Array();
	this.rowcount;
	this.ceilcount;
	this.recordcount;
	this.filters=new Array();
	this.filtervalues=new Array();
	
	this.XmlToArray=function(){		

		var row=this.xmlDoc.getElementsByTagName("record");

/*		if (this.xmlDoc.documentElement) else{
			alert("Warning:XML file is wrong!");
			return false;
		}*/

		if (row.length==0) return false;

		this.recordcount=this.xmlDoc.getElementsByTagName("recordcount")[0].childNodes[0].nodeValue;

		this.rowcount=row.length;
		this.ceilcount=row[0].childNodes.length;
		
		this.fieldname.length=0;
		for (var i=0;i<this.ceilcount;i++){
			this.fieldname[i]=row[0].childNodes[i].nodeName;		
		}
		
		this.records.length=0;
		var l=0;
		for (var i=0;i<this.rowcount;i++){
			this.records[l]=new Array();
			for (var j=0;j<this.ceilcount;j++){
				var p=in_array(this.fieldname[j],this.filters);				
				if (p>=0){
					if (in_array(row[i].childNodes[j].childNodes[0].nodeValue,this.filtervalues)==-1){
						l--;
						break;
					}				
				}/**/
				
				var node=row[i].childNodes[j].childNodes[0];
				this.records[l][j]=(node?node.nodeValue:"");

			}
			l++;
		}	
	}
	
	this.SetFilter=function(keys,values){
		if (!(is_array(keys) && is_array(values))){
			alert("The parameter must be array!");	
			return false;
		}
		if (!is_array(values[0])){
			alert("The parameter2 must be two-dimentional array!");	
			return false;
		}
		
		this.filters=keys;
		this.filtervalues=values;		
	}
	
	this.getArray=function(){
		return 	this.records;
	}
	
	this.getRowCount=function(){
		return 	this.rowcount;
	}
	
	this.getceilCount=function(){
		return 	this.ceilcount;
	}
	
	this.getFieldNames=function(){
		return 	this.fieldname;	
	}
	
}


