/* 
Usage :
1. Include this file in your page.
2. Create Object of this class e.g. 
	-->> var pal = new PcomAjax();
3. Call load method with your URL and callback function. eg. 
	-->> pal.load('http://wsd1r.petersons.com/GradChannel/code/submajor.asp?sponsor=1&temp=smajor&submajor=76',callBackFunc);
4. To get any development errors add &debug=true to your url and you can see your error.
*/ 
	
function PcomAjax(){

	this._xResp=null;					// Response object
	
	var _self=this; //to have self reference 
	
	this.debug=function(d){
		if ((new RegExp(/debug=true/)).test(window.location)){
			alert('Error from PcomAjax Library:\n\n'+d);
		}
	};	
	
	this.createReqObj=function(){
		this._xReq = null;
		if(window.XMLHttpRequest) {
			// _xReq.setRequestHeader('content-type', 'text/xml');
			this._xReq = new XMLHttpRequest();
			this._AX=false;  
		} else if(window.ActiveXObject) {
			this._xReq = new ActiveXObject("Microsoft.XMLHTTP");
			this._AX=true;
		}
		return this._xReq;
	}
	
	this.createReqObj();

	this.processXReqChange=function() { 
		if(_self._xReq.readyState == 4) {
			if(_self._xReq.status == 200) {
			    try{ //Assume XML document 
				    _self._xResp= _self._xReq.responseXML.documentElement;
				}catch(ex){ 
				    //gosh error 
				}finally{
				    if (_self._xResp == null) {
				        try{_self._xResp=_self._xReq.responseText;}catch(ex){}
				    }
				}

				if(typeof(_self.callback)=='function'){
					_self.callback(_self._xResp);(_self._xResp);
					
				}else{
					
					_self.debug('Call back method not present.');
				}
				
			} else {
				_self.debug('There was a problem retrieving the XML data:\n' + self._xReq.statusText);
		    }
		}
	}
	
	this.load=function(url,cb) {
		this.callback=cb;
		try{
			this._xReq.onreadystatechange = this.processXReqChange;
			this._xReq.open("GET", url, true); 
			if (this._AX){//Active X for IE
				this._xReq.send(); 
			}else {
				this._xReq.send(null);
			}
		}catch(ex){
			alert(ex);
		}
	}
}




