var xmlobj=null;
var data=new Array();
// send http request
function sendRequest(doc){
    // check for existing requests
    if(xmlobj!=null&&xmlobj.readyState!=0&&xmlobj.readyState!=4){
        xmlobj.abort();
    }
    try{
        // instantiate object for Mozilla, Nestcape, etc.
        xmlobj=new XMLHttpRequest();
    }
    catch(e){
        try{
            // instantiate object for Internet Explorer
            xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e){
            // Ajax is not supported by the browser
            xmlobj=null;
            return false;
        }
    }
    // assign state handler
    xmlobj.onreadystatechange=stateChecker;
    // open socket connection
    xmlobj.open('GET',doc,true);
    // send GET request
    xmlobj.send(null);
}
// check request status
function stateChecker(){
    // if request is completed
    if(xmlobj.readyState==4){
        // if status == 200 display text file
        if(xmlobj.status==200){
            // read XML data
            data=xmlobj.responseXML.getElementsByTagName('message');
			 // display XML data
            displayData();
        }
        else{
            alert('Failed to get response :'+ xmlobj.statusText);
        }
    }
}
// create data container
function createDataContainer(){
    var div=document.getElementById('quotes');
    if(div){return};
    var div=document.createElement('div');
    div.setAttribute('id','quotes');
    document.getElementsByTagName('body')[0].appendChild(div);
}
// display data at a given time interval
function displayData(){
    // reset data container
    document.getElementById('quotes').innerHTML='';
	var j=Math.floor(Math.random()*data.length)
	document.getElementById('quotes').innerHTML=data[j].getElementsByTagName('quote')[0].firstChild.nodeValue;
    // update headlines each 1 hour
    setTimeout("sendRequest('news.xml')",5*800);
}



window.onload=function(){
    // check if browser is DOM compatible
    if(document.getElementById&&document.getElementsByTagName&&document.createElement){
        // load XML file
        sendRequest('news.xml');
		//sendRequest1('image_slider.xml');
    }
}
