function Query(){ 
	this.connect = this.getConnection(); // create connection
}
Query.prototype.getConnection = function (){ //gets connection
	var XML = null;
	
	try { XML = new XMLHttpRequest();}
		catch(e) { XML = null; }  
	try { if(!XML) XML = new ActiveXObject("Msxml2.XMLHTTP"); }
  		catch(e) { XML = null; }  
	try { if(!XML) XML = new ActiveXObject("Microsoft.XMLHTTP");}
  		catch(e) { XML = null; } 
  	return XML;
}
Query.prototype.fetch = function(url, query, method,ReturnData){ //fetches query via url with array 'query' with method and wheither to 																   return data (ReturnData) or not
  method = method || "GET";
  ReturnData = ReturnData || true;
  
  if(method=="GET"){  // GET Data via GET Method
	this.url = url + "?" +this.ParseQueryString(query);
  	this.connect.open(method,this.url , false );
  	this.connect.send(null);
  }
  if(method=="POST"){ // POST Data via POST Method
	   this.url = url;
	   this.connect.open(method, this.url, false );
  	   this.connect.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	   this.connect.send(this.ParseQueryString(query));
  }  
  
  if(this.connect.readyState ==4 && ReturnData){
  	this.output = this.getOutput(); // if state is good get data
  }
}

Query.prototype.getResponseXML = function(){ // if data is xml return
	return this.connect.responseXML;	
}

Query.prototype.getResponseText = function(){ // if data is text return
	return this.connect.responseText;	
}

Query.prototype.getOutput = function(){ // gets data if ReturnData is true
	var Type = this.connect.getResponseHeader("Content-Type"); // is Data XML or Text
	if (Type == 'text/xml') { 
		return this.getResponseXML();
	} else if (Type == 'text/plain') {
		return this.getResponseText();
	}	
}

Query.prototype.RawData = function(){ // get Raw Data output , returns entire xml for XML sheet.
	if ( isIE ){
			return this.connect.responseXML.xml; // return XML in IE
	}else{
		return ( new XMLSerializer().serializeToString(this.connect.responseXML) );  // Returns XML in Non IE browsers
	}	
}

Query.prototype.ParseQueryString = function(array){ // Create query string from Array and returns it
	var QueryParam = new Array();
	 for (var key in array) {
		QueryParam.push( key+"="+encodeURIComponent(array[key]) )
	 }	 
	 return QueryParam.join("&");
}

Query.prototype.field = function (Name){
	if(this.output!=undefined){
		return this.output.getElementsByTagName(Name) || ''; // Returns specific tags from XML sheet
	}else{
	    return '';	
	}
}
