
var loaded_containers = new Array();
var phpsessid = "";

function ajaxFunction(url, id, on_right_url, on_right_id, on_right_url2, on_right_id2, on_wrong_msg, no_animation)
{


	var xmlHttp;


	function login(){
		if(xmlHttp.readyState==4){
			if(xmlHttp.responseText.match("retval=0")){
				alert(on_wrong_msg);
			}else{
				on_right_url = on_right_url + '&PHPSESSID=' + xmlHttp.responseText;
				on_right_url2 = on_right_url2 + '&PHPSESSID=' + xmlHttp.responseText;
				ajaxFunction(on_right_url, on_right_id);
				ajaxFunction(on_right_url2, on_right_id2);
				phpsessid = xmlHttp.responseText;
			}
		}
	}


	function logout(){
		phpsessid = "";
		ajaxFunction(on_right_url, on_right_id);
		ajaxFunction(on_right_url2, on_right_id2);
	}



try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }


	//alert(url + " - " + id);

	if(url == "reload"){
		ajaxFunction(loaded_containers[id], id);
		return;
	}

	if(id == "new"){
		newwindow = window.open(url);
		newwindow.focus();
	}else if(id == "universe" || id == "rss") {
		window.open(url, "_self");
	}else if(id == ""){
		/* do nothing */	
	}else if(id == "login"){
		xmlHttp.onreadystatechange=login;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else if(id == "logout"){
		logout();
	}else{
		jback[1] = loaded_containers[id];

		if(phpsessid != ""){
			url = url + '&PHPSESSID=' + phpsessid;
		}

		if(no_animation != "1"){
			document.getElementById(id).innerHTML='<table border=0 width=100% height=100%><tr><td width=100% height=100% valign=middle align=middle><img src=img/icons/searching_animation2.gif> loading module...</td></tr></table>';
		}
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4){
			//document.getElementById(id).appendChild(document.createTextNode(xmlHttp.responseText));
			document.getElementById(id).innerHTML=xmlHttp.responseText;
			
			resize_divs();
			
			if(id == "main"){
				delete(loaded_containers['news']);
				delete(loaded_containers['prod']);
				delete(loaded_containers['dl']);
				loaded_containers[id] = url;
			}else{
				loaded_containers[id] = url;
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}


}

function resize_divs(){
	/* A little Ajax-Bug, that the shadow-divs arent resize at a page load */
	//document.getElementById('leftshadow').style.height = document.body.scrollHeight;
	//document.getElementById('rightshadow').style.height = document.body.scrollHeight;
	//alert(document.body.scrollHeight);

	document.getElementById('leftshadow').style.height = document.getElementById('page').offsetHeight;
	document.getElementById('rightshadow').style.height = document.getElementById('page').offsetHeight;
//	alert(document.getElementById('main').offsetHeight);
}


function jback(){
	for (var Eigenschaft in back[1]){
		ajaxFunction(back[1][Eigenschaft], Eigenschaft);
	}
}


function change_lang(lang){
	var la = "lang=" + lang;

	for (var Eigenschaft in loaded_containers){
		match = Eigenschaft.match(/^\d*$/);
		if (match == null) {
			loaded_containers[Eigenschaft] = loaded_containers[Eigenschaft].replace(/lang\=../g, la);
			ajaxFunction(loaded_containers[Eigenschaft], Eigenschaft);
			//alert(loaded_containers[Eigenschaft] + " - " + Eigenschaft);
		}
	}

}


function open_new_window(addr) {
  mywindow = window.open(addr, "Files", "width=904,height=574,dependent=yes,location=no,menubar=no,scrollbars=no,status=no,toolbar=no");
  mywindow.focus();
}





