﻿/**
 * AjaxDell
 * 
 * Copyright (c) 2006 iComm International
 */

/**  
 * Class responsable for processing AjaxDell.
 * @constructor
 * @author Wendell Tan Malpas
 */
function AjaxDell() {
  var xmlHTTP, bComplete = false;

  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;
  
  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);
									        }
								       };
	      xmlHTTP.send(sVars);
	    } catch(z) { 
	    	return false; 
	    }
	    
	 return true;
   };

   return this;
}