//Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 15th, 06'

function GetE( elementId )
{
	return document.getElementById( elementId )  ;
}

function createAjaxObj(){
var httprequest=false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
	}
	else if (window.ActiveXObject){ // if IE
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
		try{
			httprequest=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){}
		}
	}
	return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
	if (this.ajaxobj){
		this.filetype=filetype
		this.ajaxobj.onreadystatechange=callbackfunc
		this.ajaxobj.open('GET', url+"?"+parameters, true)
		this.ajaxobj.send(null)
	}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (this.ajaxobj){
		this.filetype=filetype
		this.ajaxobj.onreadystatechange = callbackfunc;
		this.ajaxobj.open('POST', url, true);
		this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajaxobj.setRequestHeader("Content-length", parameters.length);
		this.ajaxobj.setRequestHeader("Connection", "close");
		this.ajaxobj.send(parameters);
	}
}

function processGet(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var temp_text = ""; // Tijdelijke text variabele (hier staat de string met de content in
			if (myfiletype=="xml") { // het XML object
				rss_items=myajax.responseXML.getElementsByTagName("item")
				//Cycle through RSS XML object and store each peice of an item inside a corresponding array
				temp_text += "<UL style='list-style-position:outside;'>";
				for (var i=0; i<rss_items.length; i++){
					temp_text += "<LI style='padding-bottom:3px;'><a href='"+rss_items[i].getElementsByTagName("link")[0].firstChild.nodeValue+"'>" +rss_items[i].getElementsByTagName("title")[0].firstChild.nodeValue +"</a><br />";
					temp_text += Left(rss_items[i].getElementsByTagName("description")[0].firstChild.nodeValue,100)+"...";
					temp_text += "</LI>";
				}
				temp_text += "</UL>";
			} else {
				temp_text = "No news items.";
			}
			GetE('rss_data').innerHTML = temp_text; // De HTML in de DIV zetten
		}
	}
}

function processGetImage(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var temp_text = ""; // Tijdelijke text variabele (hier staat de string met de content in
			if (myfiletype=="xml") { // het XML object
				items=myajax.responseXML.getElementsByTagName("item");
				temp_text += "<table width='97%' cellpadding='2'>";
				for (var i=0; i<items.length; i++){
					temp_text += "<tr width='100%'><td rowspan='2' width='25' nowrap='nowrap' align='left'><img src='http://www.urbaextra.net/paradiso/images/td_nav_right.gif' alt='' border='0' /></td><td colspan='2' style='padding-bottom:5px; padding-top:10px;'>";
					temp_text += "<a href='"+items[i].getElementsByTagName("link")[0].firstChild.nodeValue+"' title='"+items[i].getElementsByTagName("title")[0].firstChild.nodeValue+"'>";
					temp_text += items[i].getElementsByTagName("title")[0].firstChild.nodeValue;
					temp_text += "</a></td></tr><tr>";
					myNode = items[i].getElementsByTagName("enclosure")[0].firstChild;
					if (myNode != null) {
						temp_text += "<td align='left' valign='top' style='border-bottom:1px #003366 solid; padding-bottom:5px;'>";
						temp_text += "<a href='"+items[i].getElementsByTagName("link")[0].firstChild.nodeValue+"' title='"+items[i].getElementsByTagName("title")[0].firstChild.nodeValue+"'>";
						temp_text += "<img src='"+myNode.nodeValue+"' align='right' border='0'></a>";
						temp_text += "</td><td align='left' style='border-bottom:1px #003366 solid; padding-bottom:5px;' valign='top' class='description'>";
						temp_text += items[i].getElementsByTagName("description")[0].firstChild.nodeValue;
						temp_text += "<a href='"+items[i].getElementsByTagName("link")[0].firstChild.nodeValue+"' title='"+items[i].getElementsByTagName("title")[0].firstChild.nodeValue+"'>";
						temp_text += "&nbsp;Lees meer &raquo;</a></td></tr>";
					} else {
						temp_text += "<td colspan='2' align='left' style='border-bottom:1px #003366 solid; padding-bottom:5px;' valign='top' class='description'>";
						temp_text += items[i].getElementsByTagName("description")[0].firstChild.nodeValue;
						temp_text += "<a href='"+items[i].getElementsByTagName("link")[0].firstChild.nodeValue+"' title='"+items[i].getElementsByTagName("title")[0].firstChild.nodeValue+"'>";
						temp_text += "&nbsp;Lees meer &raquo;</a></td></tr>";
					}
				}
				temp_text += "</table>";
			} else {
				temp_text = "Er kunnen geen nieuws items getoond worden";
			}
			GetE('rss_data').innerHTML=temp_text;
		}
	}
}

function Left(str, n){
   if (n <= 0)
       return "";
   else if (n > String(str).length)
       return str;
   else
       return String(str).substring(0,n);
}

//ACCESSIBLE VARIABLES (for use within your callback functions):
//1) ajaxpack.ajaxobj //points to the current ajax object
//2) ajaxpack.filetype //The expected file type of the external file ("txt" or "xml")
//3) ajaxpack.basedomain //The root domain executing this ajax script, taking into account the possible "www" prefix.
//4) ajaxpack.addrandomnumber //Set to 0 or 1. When set to 1, a random number will be added to the end of the query string of GET requests to bust file caching of the external file in IE. See docs for more info.

//ACCESSIBLE FUNCTIONS:
//1) ajaxpack.getAjaxRequest(url, parameters, callbackfunc, filetype)
//2) ajaxpack.postAjaxRequest(url, parameters, callbackfunc, filetype)

///////////END OF ROUTINE HERE////////////////////////


