	var feed = new Object();

	feed.AddFeed = function( feedUrl, feedType, feedTarget, feedTitle )
		{
		var templatea= "<script> function $$targetMouse(){var undef; var el = document.getElementById(\"$$target\");if (el==undef) { el = document.createElement(\"DIV\"); el.className= \"unpopped\"; el.id=\"$$target\"; el.innerHTML = \"<p onclick=\\\"$$targetMouse()\\\"><b>$$title</b>(close)</p><div id=\\\"$$targetcontent\\\" class=\\\"poppedcontent\\\"></div>\"; document.body.appendChild(el);} if (el.className==\"unpopped\"){var $$targetRender= new feed.FeedRender(\"$$url\",\"$$type\",\"$$targetcontent\");el.className=\"popped\";}else{el.className=\"unpopped\";}}</script><a href=\"#\" onclick=\"$$targetMouse()\" style=\"text-decoration:none\"><img src=\"rss3.jpg\" style=\"border:none;margin-right:5px;\" onmouseover=\"src='rss3a.jpg';\" onmouseout=\"src='rss3.jpg';\"/></a>";
		var outputa = templatea.replace(/\$\$target/g,feedTarget);
		outputa = outputa.replace(/\$\$type/g,feedType);
		outputa = outputa.replace(/\$\$url/g,feedUrl);
		outputa = outputa.replace(/\$\$title/g,feedTitle);
		document.write(outputa);
		}

	feed.FeedRender = function( feedUrl, feedType, feedTarget, feedTitle )
		{
		this.xmlUrl = "cgi-bin/gm.cgi?thomas=doget&ref="+feedUrl;
		// this.xmlUrl = feedUrl;
		this.xslUrl = (feedType == "rdf") ? "rdf2htmlFragment.xsl": ((feedType == "atom")? "atom03.xsl":"rss2htmlFragment.xsl");
		this.xslLoaded = false;
		this.http = false;
		this.xslDoc = null;
		this.htmlTarget = feedTarget;
		this.htmlTitle = feedTitle;
		this.loadXsl();
		}

	feed.FeedRender.prototype = {
		loadXsl:function()
			{
			this.http = this.getHTTPObject();
			if (this.http)
				{
				if (window.XSLTProcessor) 
					{
					this.xslDoc = document.implementation.createDocument("","",null);
					this.xslDoc.async = false;
					this.xslDoc.load(this.xslUrl);
					this.onXslLoad();
					}
				else if(window.ActiveXObject) 
					{// Microsoft
					this.xslDoc= new ActiveXObject("Microsoft.XMLDOM");
					this.xslDoc.async=false; 
					this.xslDoc.load(this.xslUrl);
					this.onXslLoad();
					}
				}
			},
		
		onXslLoad:function() 
			{ // flag that the xsl is loaded
			this.xslLoaded = true;
			this.loadRss();
			},  
 
		transformRssXml:function() 
			{
			
			if (this.http.readyState != 4) return ;
			this.xmlOut=null;
			document.getElementById(this.htmlTarget).innerHTML = "";  
			try
				{
				if (window.XSLTProcessor)
					{  // Mozilla/Gecko
	    				this.xsltProcessor = new XSLTProcessor();
	        			this.xsltProcessor.importStylesheet(this.xslDoc);
	        
	        			this.xmlOut = this.xsltProcessor.transformToFragment(this.http.responseXML, document);
					document.getElementById(this.htmlTarget).appendChild(this.xmlOut);
	    				}
	    			else if(window.ActiveXObject)
					{
	           			this.xmlOut= this.http.responseXML.transformNode(this.xslDoc); 
					document.getElementById(this.htmlTarget).innerHTML=this.xmlOut; 
					}
	    
				//Fix up encoded HTML as XSL seems incapable of doing this reliably
	    			
	    			this.aDivs=document.getElementsByTagName("div");  //get all the divs 
	    			for(var i=0;i<this.aDivs.length;i++)
					{
	        			if(this.aDivs[i].getAttribute("name")=="newsItemContent") 
						{//check if it has encoded content
	            					if (typeof(this.aDivs[i].textContent) == "undefined")
	              						this.aDivs[i].innerHTML=this.aDivs[i].innerText;
	            					else
	              						this.aDivs[i].innerHTML=this.aDivs[i].textContent ;
	        				}
	    				}
				}
			catch(e)
				{
			     	this.noLoadMsg();
				}   
			},

		loadRss:function() 
		   	{
			if ((this.http) && (this.xslLoaded)) 
				{
  				this.http.open("GET", this.xmlUrl , true);
				var loader=this;
 	  			this.http.onreadystatechange = function() { loader.transformRssXml.call(loader);}
	  			this.http.send(null);
				}
			else
				{
				this.noLoadMsg();
				}
			},	  


		getHTTPObject:function() 
			{
			var xmlhttp;
    			try 
				{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    				} 
    			catch (e1) 
				{
				try 
					{
        				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      					} 
      				catch (e2) 
					{
        				xmlhttp = null;
      					}
    				}
			if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
				{
    				try 
					{
					xmlhttp = new XMLHttpRequest();
    					} 
    				catch (e3) 
					{
      					xmlhttp = null;
    					}
				}
			return xmlhttp;
			},

		noLoadMsg:function()
			{
			document.getElementById(this.htmlTarget).innerHTML = "Unable to load news, try it with IE or Firefox if you can (and if you are not already using one of these).</br></br><a href='http://www.daymap.net/news'>Click here to view Daymap news</a>";
			}
	}

