if(com==undefined) var com = {};
if(com.dc==undefined) com.dc = {};

com.dc.ajax = new Ajax();

function Ajax(){
	//this.exploer = false;//not necessary
}

Ajax.prototype.request = function(path, method, sync, xml) {
	method = method || "GET";//default GET
	sync = sync || false;//default sync, not async
	xml = xml || "";//avoid sending out a null
	
	//debug.debug("request()path: "+path+", method: "+method+", sync: "+sync+", xml: "+xml);
	var xmlDoc;
	
	try{
		var xmlhttp = this.getXMLHttp();
		var exploer = false;
		if (!xmlhttp){
			//alert('Your browser does not support multiple page print!');
			return;
		}
		xmlhttp.open(method, path, sync);
		var mimeType = (xmlhttp.overrideMimeType) ? true: false;
		if (mimeType){
			exploer = false;
			xmlhttp.overrideMimeType("text/xml;charset=UTF-8");
		}
		else{
			exploer = true;
			xmlhttp.setRequestHeader("content-type","text/xml; charset=UTF-8");
		}	
		xmlhttp.send("");	
		if(exploer){
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = "false";
			xmlDoc.loadXML(xmlhttp.responseText);
		}else{
			xmlDoc = xmlhttp.responseXML;
		}	
	}catch (e){
		//debug.error("request()exception:"+e);
	}finally{	
	}
	return xmlDoc;
};

Ajax.prototype.getXMLHttp = function(){
	var obj;
	try{
		if (window.XMLHttpRequest){
			// If IE7, Mozilla, Safari, etc: Use native object
			obj = new XMLHttpRequest();
		}
		else if (window.ActiveXObject){
			// ...otherwise, use the ActiveX control for IE5.x and IE6
			try{
				obj = new ActiveXObject("MSXML2.ServerXMLHTTP");
			}
			catch (err){
				obj = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}catch (e){
		//debug.error("getXMLHttp()exception:"+e);
	}finally{	
	}
	return obj;
};
Ajax.prototype.parseXml = function(str){
	var xmlDoc;
	if (window.XMLHttpRequest){ // code for IE7, Firefox, Opera, etc.
		xmlDoc = this.parseFromString(str, "text/xml");
	}else { // code for IE6, IE5
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.loadXML(str);
	}	
	//debug.debug("xmlDoc:" + xmlDoc);
	return xmlDoc;
};
Ajax.prototype.parseFromString = function(str, contentType) {
	if (typeof ActiveXObject != "undefined") {
		var d = new ActiveXObject("MSXML.DomDocument");
		d.loadXML(str);
		return d;
	}else if (typeof XMLHttpRequest != "undefined") {
		var req = new XMLHttpRequest;
		req.open("GET", "data:" + (contentType || "application/xml") +";charset=utf-8," + encodeURIComponent(str), false);
		if (req.overrideMimeType) {
		   req.overrideMimeType(contentType);
		}
		req.send(null);
		return req.responseXML;
	}
}

