/**
 * AjaxDell
 * 
 * Copyright (c) 2006 iComm International
 */

/**  
 * Class responsable for processing AjaxDell.
 * @constructor
 * @author Wendell Tan Malpas
 */
 
var isAjaxDellCrossDomain = false;
 
function AjaxDell() {
  var xmlHTTP, bComplete = false;
	
	if (!isAjaxDellCrossDomain) {
		try { xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { 
			try { xmlHTTP = new ActiveXObject(" Microsoft.XMLHTTP"); } catch (e) { 
				try { xmlHTTP = new XMLHttpRequest(); } catch (e) { 
					xmlHTTP = false; 
				}
			}
		}
		if (!xmlHTTP) return null;
	} else {
		xmlHTTP = new XMLHTTP();
		xmlHTTP.setAPI = "http://apps.autoterminal.com/php.server/"
	}
  
  this.connect = function(sURL, sMethod, sVars, fnDone) {
	    if (!xmlHTTP) return false;
	    bComplete = false;
	    sMethod = sMethod.toUpperCase();
		try {
	      if (sMethod == "GET") {
	        xmlHTTP.open(sMethod, sURL+"?"+sVars, true);
	        sVars = "";
	      } else {
	        xmlHTTP.open (sMethod, sURL, true);
	        xmlHTTP.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
	        xmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	      }
	      
	      xmlHTTP.onreadystatechange = function(){
						if (xmlHTTP.readyState == 4 && !bComplete) {
							bComplete = true;
							fnDone(xmlHTTP);
							if (xmlHTTP.status == 404) alert("Request URL does not exist");
							else if (!xmlHTTP.status == 200) alert("Error: status code is " + xmlHTTP.status);
						}
							
					};
	      xmlHTTP.send(sVars);
	    } catch(z) { 
			alert(z);
	    	return false; 
	    }
	    
	 return true;
   };
   return this;
}