/****************************************************************************
* Copyright 2009:                                                           *
*    This software belongs to netoffice ab!                                 *
*    The Code below may not be sold or used (either)                        *
*    directly or indirectly) without the prior written consent              *
*    of netoffice ab.                                                       *
*                                                                           *
*    There is NO WARRANTY OF ANY KIND associated with this                  *
*    software, either written or implied.                                   *
*                                                                           *
****************************************************************************/

function GetLastNewsBanner(url)
{
	var preTitle = "<p><br><br><b>";
	var postTitle = "</b><br>";
	var postBanner = "</p>";
	var xmlContent;
	var tmpStr;
	
	xmlContent = LoadXmlFile(url);
	//alert(xmlContent.xml);
	
	if (xmlContent == null) {
		return ("Ett fel har uppstått, nyhet kan inte läsas!");
	}
	else {
		//alert(xmlContent.getElementsByTagName("published")[0].childNodes[0].nodeValue);
		//alert(xmlContent.getElementsByTagName("title")[0].childNodes[0].nodeValue);
		//alert(xmlContent.getElementsByTagName("body")[0].childNodes[0].nodeValue);
		if (xmlContent.getElementsByTagName("body")[0].childNodes[0].nodeValue.length < 61) {
			tmpStr = preTitle + xmlContent.getElementsByTagName("published")[0].childNodes[0].nodeValue + " - ";
			tmpStr += xmlContent.getElementsByTagName("title")[0].childNodes[0].nodeValue + postTitle;
			tmpStr += xmlContent.getElementsByTagName("body")[0].childNodes[0].nodeValue + postBanner;
			return tmpStr;
		}
		else {
			tmpStr = preTitle + xmlContent.getElementsByTagName("published")[0].childNodes[0].nodeValue + " - ";
			tmpStr += xmlContent.getElementsByTagName("title")[0].childNodes[0].nodeValue + postTitle;
			tmpStr += xmlContent.getElementsByTagName("body")[0].childNodes[0].nodeValue.substring(0,59) + "..." + postBanner;
			return tmpStr;
		}
	}

}//End Func

function GetAllNews(url)
{
	var preTitle = "<br><b>";
	var postTitle = "</b><br>";
	var postBody = "<br>";
	var postNews ="<br><hr>";
	
	var xmlContent;
	var tmpStr = "";
	var nNodes;
	var dNode;
	var dNode1;
	var i;
	var strSource;
	                                                                        	
	xmlContent = LoadXmlFile(url);
	//alert(xmlContent.xml);
	
	if (xmlContent == null) {
		return ("Ett fel har uppstått, nyheter kan inte läsas!");
	}
	else {
		nNodes=xmlContent.getElementsByTagName("news");
		for (i=0;i<nNodes.length;i++) {
			//Get the source
			strSource = nNodes[i].attributes.getNamedItem("source").nodeValue;
			//Get the title
			tmpStr += preTitle;
			dNode=nNodes[i].getElementsByTagName("published");
			if (dNode[0].firstChild != null)
				tmpStr += dNode[0].firstChild.nodeValue;
			else
				tmpStr += "<i>datum</i>";
			dNode=nNodes[i].getElementsByTagName("title");
			if (dNode[0].firstChild != null)
				tmpStr += " - " + dNode[0].firstChild.nodeValue + postTitle;
			else
				tmpStr += " - titel saknas" + postTitle;
			//Get news body
			dNode=nNodes[i].getElementsByTagName("body");
			if (dNode[0].firstChild != null)
				tmpStr += dNode[0].firstChild.nodeValue + postBody;
			else
				tmpStr += "text saknas" + postBody;
			//Get link
			dNode=nNodes[i].getElementsByTagName("link");
			if (dNode[0].firstChild != null) {
				dNode1=dNode[0].getElementsByTagName("url");
				if (dNode1[0].firstChild != null) {
					//alert("URL: " + dNode1[0].firstChild.nodeValue);
					tmpStr += '<a href="one_news.html?src=' + strSource + '&url=' + dNode1[0].firstChild.nodeValue + '"  target="_blank"><img id="screenV" name="screenV" class="imgCnav" alt="" src="img/nav2.gif">';
					dNode1=dNode[0].getElementsByTagName("text");
					if (dNode1[0].firstChild != null)
						//alert("Läs mer om " + dNode1[0].firstChild.nodeValue);
						tmpStr += 'Läs mer om ' + dNode1[0].firstChild.nodeValue + '</a><br>' + postNews;
					else
						//alert("Läs mer om...");
						tmpStr += 'Läs mer om...</a><br>' + postNews;
				}
			}
		}
		return tmpStr;
		//<a href="news.html"><img class="imgCnav" alt="" src="img/nav2.gif"> Läs mer...</a><br>
	}
}//End Func

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function LoadXmlFile(url)
{
	var xmlhttp;

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
		// The browser does not support XMLHTTP
		return null;
	}
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		//Return xml document object
		return xmlhttp.responseXML;
	}
	else {
		return null;
	}
}//End Func

function slPlanTrip(when)
{
	var preStr = "http://reseplanerare.sl.se/bin/query.exe/sn?REQ0HafasSearchForw=1&REQ0JourneyStopsZ0ID=A=2@O=Stockholm, Valla Torg 81@X=18052721@Y=59293639@U=174@L=990014809@B=1@p=1257841204@l=netoffice ab - Valla Torg 81&REQ0JourneyStopsS0A=255&REQ0JourneyStopsS0G=";
	var goNow = "&start=yes&;REQ0JourneyTime=+0:05";
	var goLater ="&go";
	var strUrl;
	
	if (goFromDest.value != '') {
		strUrl = preStr + goFromDest.value;
		if (when == 'now')
			strUrl += goNow;
		else
			strUrl += goLater;
	}
	else {
		strUrl = preStr + 'Tcentralen';
		if (when == 'now')
			strUrl += goNow;
		else
			strUrl += goLater;
	}
	
	var load = window.open(strUrl);
	return false;
}//End Func


