/* ********************************************************************************
*
* Author: Aouse Al-Rawi
* Library: Ajax
* Date: 2008
*
* ********************************************************************************/






/* ********************************************************************************
*
* Class: Ajax
* Description: Ajax class definition
*
* ********************************************************************************/
function ajaxObject(url,callBack,parameters,method,postParams){
this.url = url;
this.date = new Date();
this.timestamp = this.date.getTime();
this.xhrObj;
this.callBack = 'this.'+callBack;
this.callBackParams = parameters;
this.method = method;
this.postParams = postParams;
}
/* ************************** End *************************************************/




/* ********************************************************************************
*
* Method: StartAjax
* Description: Get the XHR Object and set the callback function
*
* ********************************************************************************/
ajaxObject.prototype.startAjax = function(){
if(window.XMLHttpRequest)
  {
	this.xhrObj = new XMLHttpRequest();
	this.xhrObj.onreadystatechange = eval(this.callBack);
	
	if(this.method=='GET')
	  {
	    this.xhrObj.open(this.method,this.url+'&timestamp='+this.timestamp,true);
	    this.xhrObj.send(null);
	  }
	else
      {
		this.xhrObj.open(this.method,this.url,true);
	    this.xhrObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		this.xhrObj.setRequestHeader("Content-length", this.postParams.length);
		this.xhrObj.setRequestHeader("Connection", "close");
		this.xhrObj.send(this.postParams);
	  }  
  }
else if(window.ActiveXObject)
  {
    
	this.xhrObj = new ActiveXObject("Microsoft.XMLHTTP")
	this.xhrObj.onreadystatechange = eval(this.callBack);
	this.xhrObj.open(this.method,this.url+'&timestamp='+this.timestamp,true);
	this.xhrObj.send();
	
  }

}
/* ************************** End *************************************************/




/* ********************************************************************************
*
* Method: getFeed
* Description: Get an xml feed, display it as HTML using the parameters given
*
* ********************************************************************************/
ajaxObject.prototype.getFeed = function(){
var feedContainer = document.getElementById('jdFeed');
  if(ajaxHandle.xhrObj.readyState==4)
    {
	  if(ajaxHandle.xhrObj.status == 200)
      {
		 var blogXml = ajaxHandle.xhrObj.responseXML;
		 var length = blogXml.getElementsByTagName(ajaxHandle.callBackParams[0]);
		 //alert(length.length);
		 for(var i=0;i<length.length;i++)
		   {
			 var title = length[i].getElementsByTagName(ajaxHandle.callBackParams[1]);
			 var link = length[i].getElementsByTagName(ajaxHandle.callBackParams[2]);
			 var feed = document.createElement('li');
			 var feedLink = document.createElement('a');
			 
			 feedLink.setAttribute('href',link.item(0).firstChild.nodeValue);
			 feedLink.setAttribute('title','Read the "'+title.item(0).firstChild.nodeValue+'" post');
			 feedText = document.createTextNode(title.item(0).firstChild.nodeValue);
			 feedLink.appendChild(feedText);
			 feed.appendChild(feedLink);
			 feedContainer.appendChild(feed);
		   }
		}
    }
 }
/* ************************** End *************************************************/



/* ********************************************************************************
*
* Method: makeForm
* Description: Get an xml feed, construct a form from it
*
* ********************************************************************************/
ajaxObject.prototype.getFeedDoForm = function(){
var feedContainer = document.getElementById('jdFeed');
var somestring="";
  if(ajaxHandle.xhrObj.readyState==4)
    {
	  if(ajaxHandle.xhrObj.status == 200)
      {
		 var blogXml = ajaxHandle.xhrObj.responseXML;
		 var length = blogXml.getElementsByTagName(ajaxHandle.callBackParams[1][0]);
		 for(var i=0;i<length.length;i++)
		   {
			 
			 somestring = '&';
			 for(var x=1;x<ajaxHandle.callBackParams[0].length;x++)
			 {
			   var xmlvalue = length[i].getElementsByTagName(ajaxHandle.callBackParams[1][x]);
			   somestring+=ajaxHandle.callBackParams[0][x]+'='+xmlvalue.item(0).firstChild.nodeValue+'&';
			 }
			 
			   somestring+='newsparent=newsfeed_RSS';
			   postHolder[i]=somestring;
		   }
		  
		 callThis();  
		}
		
    }
 }

/* ************************** End *************************************************/

/* ********************************************************************************
*
* Method: nothing
* Description: dummy function
*
* ********************************************************************************/
ajaxObject.prototype.nothing = function(){
  if(ajaxHandleSecond.xhrObj.readyState==4)
    {
	  if(ajaxHandleSecond.xhrObj.status == 200)
      {
		//Do nothing...
	  }
    }
 }

/* ************************** End *************************************************/


