var rssXMLTHHP;
function ajaxInit(){
	this.loadAjax = function(myurl,str){
		this.xmlHttp=GetXmlHttpObject();
		if(this.xmlHttp==null){
			return;	
		}
		this.url=myurl;
		this.url+="?ndate="+str;
		this.url+="&sid="+Math.random();
		this.xmlHttp.open("GET",this.url,true);
		this.xmlHttp.setRequestHeader("Cache-Control", "no-cache");
		var myRequest = this;
		this.xmlHttp.onreadystatechange=function(){
			if(myRequest.xmlHttp.readyState==4){
				processRSS(myRequest.xmlHttp.responseXML);
			}
		}
		this.xmlHttp.send(null);
	}
}
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
		xmlHttp=new XMLHttpRequest();
	} catch(e){
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function getRSS(){
	var newsfeed = new ajaxInit();
	//var blogfeed = new ajaxInit();
	var techfeed = new ajaxInit();
	newsfeed.loadAjax("/hpinfo/news.xml","");
	//blogfeed.loadAjax("rss/blogs.xml","");
	techfeed.loadAjax("/hpinfo/presskits.xml","");
 
}
function processRSS(rssxml){
	RSS = new RSS2Channel(rssxml);
	showRSS(RSS);
}
function RSS2Channel(rssxml){
	this.title;
	this.link;
	this.description;
	this.language;
	this.copyright;
	this.managingEditor;
	this.webMaster;
	this.pubDate;
	this.lastBuildDate;
	this.generator;
	this.docs;
	this.ttl;
	this.rating;
	this.category;
	this.image;
	this.items = new Array();
	var chanElement = rssxml.getElementsByTagName("channel")[0];
	var itemElements = rssxml.getElementsByTagName("item");
	for(var i=0;i<itemElements.length;i++){
		Item = new RSS2Item(itemElements[i]);
		this.items.push(Item);
	}
	var properties = new Array("title","link","description","language","copyright","managingEditor","webMaster","pubDate","lastBuildDate","generator","docs","ttl","rating");
	var tmpElement = null;
	for(var i=0;i<properties.length;i++){
		tmpElement=chanElement.getElementsByTagName(properties[i])[0];
		if(tmpElement!=null){
			eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");	
		}
	}
	this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
	this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
}
function RSS2Category(catElement){
	if(catElement==null){
		this.domain=null;
		this.value=null
	} else {
		this.domain=catElement.getAttribute("domain");
		this.value=catElement.childNodes[0].nodeValue;
	}
}
function RSS2Image(imgElement){
	if(imgElement==null){
		this.url=null;
		this.link=null;
		this.width=null;
		this.height=null;
		this.description=null;
	} else {
		imgAttribs = new Array("url","title","link","width","height","description");
		for(var i=0; i<imgAttribs.length; i++){
			if(imgElement.getAttribute(imgAttribs[i])!=null){
				eval("this."+imgAttribs[i]+"=imgElement.getAttribute("+imgAttribs[i]+")");	
			}
		}
	}
}
function RSS2Item(itemxml){
	this.title;
	this.link;
	this.description;
	this.author;
	this.comments;
	this.pubDate;
	this.category;
	this.enclosure;
	this.guid;
	this.source;
	var properties = new Array("title","link","description","author","comments","pubDate");
	var tmpElement = null;
	for(var i=0;i<properties.length;i++){
		tmpElement = itemxml.getElementsByTagName(properties[i])[0];
		if(tmpElement!=null){
			eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");	
		}
	}
	this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
	this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
	this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
	this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
}
function RSS2Enclosure(encElement){
	if(encElement==null){
		this.url=null;
		this.length=null;
		this.type=null;
	} else {
		this.url = encElement.getAttribute("url");
		this.length = encElement.getAttribute("length");
		this.type = encElement.getAttribute("type");
	}
}
function RSS2Guid(guidElement){
	if(guidElement==null){
		this.isPermaLink=null;	
		this.value=null;
	} else {
		this.isPermaLink=guidElement.getAttribute("isPermaLink");
		this.value=guidElement.childNodes[0].nodeValue;
	}
}
function RSS2Source(souElement){
	if(souElement==null){
		this.url=null;
		this.value=null;
	} else {
		this.url = souElement = souElement.getAttribute("url");
		this.value = souElement.childNodes[0].nodeValue;
	}
}
function showRSS(RSS){
	var whichFeed;
	if((RSS.title).indexOf('Blogs')!=-1){
		whichFeed = "b_";	
		moreLink = "<span class='rss_link'><a href='http://www.hpl.hp.com/research/about/blogs.html?jumpid=reg_R1002_USEN'>&raquo;&nbsp;More</a></span>";
	} else if ((RSS.title).indexOf('News')!=-1){
		whichFeed = "n_";
		moreLink = "<span class='rss_link'><a href='http://www.hpl.hp.com/news/'>&raquo;&nbsp;More</a></span>";
	} else {
		whichFeed = "t_";
		moreLink = "<span class='rss_link'><a href='http://www.hpl.hp.com/techreports/'>&raquo;&nbsp;More</a></span>";
	}
	var startItemTag = "<div id='"+whichFeed+"item' class='rss_item'>";
	var startTitle = "<div id='"+whichFeed+"item_title'><li>&raquo;<a href='";
	var startLink = "<div id='"+whichFeed+"item_link' class='rss_link'>";
	//var startDescription = "<div id='"+whichFeed+"item_description'><p>";
	var endTag = "</div>";
	var theDesc;
	var theTitle;
	var theLink;
	var linkRE = /<a href=".+>([^<]+)<\/a>/;
	var properties = new Array("title","link","description","pubDate","copyright");
	document.getElementById(whichFeed+"chan_items").innerHTML = "";
	//for(var i=0;i<RSS.items.length;i++){
	for(var i=0;i<8;i++){

		/*theDesc = (RSS.items[i].description.replace(linkRE, "$1"));
		if(theDesc.length >= 500){
			theDesc = (theDesc).substr(0,51);
			if((theDesc.indexOf("<b>")!=-1)||(theDesc.indexOf("<strong>")!=-1)){
				theDesc = theDesc.substr(0,42);												  
			}
			theDesc = theDesc.substr(0,theDesc.lastIndexOf(" "));
			theDesc += "...";
		} else {
			theDesc = RSS.items[i].description;	
		}
		theDesc = theDesc.replace("<br>","");
		theDesc = theDesc.replace("<br />","");*/
		if(RSS.items[i].title.length >= 250){
			theTitle = (RSS.items[i].title).substr(0,33);	
			theTitle = theTitle.substr(0,theTitle.lastIndexOf(" "));
			theTitle += "...";
		} else {
			theTitle = RSS.items[i].title;
		}
		theTitle = theTitle.replace("<br>","");
		theTitle = theTitle.replace("<br />","");
		item_html = startItemTag;
		item_html += (RSS.items[i].title==null)? "" : startTitle + RSS.items[i].link + "'>" + theTitle + "</a></li>" + endTag;
		//item_html += (RSS.items[i].description==null)? "" : startDescription + theDesc + "</p>" + endTag;
		item_html += endTag;
		document.getElementById(whichFeed+"chan_items").innerHTML += item_html;
	}
	/*document.getElementById(whichFeed+"morelink").innerHTML += moreLink;*/
	return true;
}

