var xmlhttp;
var language;
function getNews(lang, letters, imageWidth)
{
	if ( letters === undefined ) {
		letters = 50;
	}
	if ( imageWidth === undefined ) {
		imageWidth = 150;
	}
	
	if(!lang){
		lang = "de";
	}
	language = lang;
xmlhttp=GetXmlHttpObject()
if (xmlhttp==null)
  {
  alert ("Your browser does not support XML HTTP Request");
  return;
  }
var url="/js/readNews.php";
url=url+"?lang="+lang+"&letters="+letters+"&imageWidth="+imageWidth;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged ;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
//  document.getElementById("searchResults").innerHTML=xmlhttp.responseText;
	if(xmlhttp.responseText.length > 0){
		document.getElementById("newsContent").innerHTML = xmlhttp.responseText;

		if(!readCookie("newsPopup")){
			var newsPopup = document.createElement("div");
			newsPopup.className = "newsPopup";
			newsPopup.id = "newsPopup";
			document.body.appendChild(newsPopup);
			
			if(language == "de"){
				document.getElementById("newsPopup").innerHTML = "Wir haben einige interessante <strong><a href=\"de/aktuelles.php\">Neuigkeiten</a></strong> f&uuml;r Sie.";
			} else {
				document.getElementById("newsPopup").innerHTML = "We've got some interesting <strong><a href=\"aktuelles_en.php\">News</a></strong> for you.";
			}
			writeCookie("newsPopup","false",1000*60*60*24*365);
			Effect.Fade('newsPopup', { duration: 1.5, from: 0, to: 0.9 });
		}
	}
	else {
		// no new messages
	}
  }
}

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 writeCookie(n,w,e) // name , wert, expires
{
 var a = new Date();
 a = new Date(a.getTime() +e);
 document.cookie = n+'='+w+'; expires='+a.toGMTString()+';';
}

function readCookie(n)
{
 a = document.cookie;
 res = '';
 while(a != '')
 {
  cookiename = a.substring(0,a.search('='));
  cookiewert = a.substring(a.search('=')+1,a.search(';'));
  if(cookiewert == '')
  {cookiewert = a.substring(a.search('=')+1,a.length);}

  if(n == cookiename){res = cookiewert;}

  i = a.search(';')+1;
  if(i == 0){i = a.length}
  a = a.substring(i,a.length);
 }
 return(res)
}
