var gParams = null;

function getPage(file, id, achor)
{
        var url = file;
      
        this.ready = function(res)
        {
                var e = document.getElementById(id);
                if(e != null)
                        e.innerHTML = res.responseText;
                else
                        alert("Fehler! Das Element mit der id '"+id+"' wurde nicht gefunden!");
				if(achor != "")
					window.location.href = '#'+achor;
				
        }

        this.fail = function(res)
        {
                alert("Fehler! Die Datei '"+url+"' konnte nicht geladen werden!");
        }

        new Ajax.Request("../"+url, { onSuccess:this.ready.bind(this), onFailure:this.fail, method:"get" });
}

function clearContent()
{
        document.getElementById("contentBlock").innerHTML = "";
}

function writeInContent(text)
{
        var content = document.getElementById("contentBlock");
        content.innerHTML = content.innerHTML + text;
}


function loadMainMenu(file)
{
        loadFileTo(file, "mainMenuBlock");
}

function loadContent(file, rightFile)
{
		var file_l = file.split('#');
		if(file_l.length == 2)
		{
			var achor = "&achor="+file_l[1]+'#'+file_l[1];
			var url = file_l[0];
		}
		else
		{
			var achor="";
			var url = file;
		}
        if(typeof rightFile == "undefined")
                location.href = "?content="+decodeURI(url)+achor;
        else
                location.href = "?content="+decodeURI(url)+"&subcontent="+decodeURI(rightFile)+achor;
}

function readParams()
{
        var paramString = location.search;
        if (paramString.length == 0)
                return {}
        var paramList = paramString.substr(1).split('&');
        var paramArray = {}
        for (var i = 0; i < paramList.length; i++)
        {
                var paar = paramList[i].split("=");
                paramArray[paar[0]] = paar[1];
        }
        return paramArray;
}

function initPage()
{
        var params = readParams();
		if(typeof params.achor != "undefined")
			var achor = params.achor;
		else
			var achor = "";
			
        if(typeof params.content != "undefined")
                getPage(encodeURI(params.content), "contentBlock", achor);
        else
                getPage("home/home.html", "contentBlock", achor);

        if(typeof params.subcontent != "undefined")
                getPage(encodeURI(params.subcontent), "subContentBlock", "");
        else
                getPage("home/right.html", "subContentBlock", "");

        if(typeof params.mainMenu != "undefined")
                getPage(encodeURI(params.mainMenu), "mainMenuBlock", "");
        else
                getPage("home/mainMenu.html", "mainMenuBlock", "");

        /*if(typeof params.header != "undefined")
                getPage(encodeURI(params.header), "headerBlock", "");
        else
                getPage("home/header.html", "headerBlock", "");*/

        if(typeof params.mainMenu != "undefined")
                getPage(encodeURI(params.footer), "footerBlock", "");
        else
                getPage("home/footer.html", "footerBlock", "");
				
		

        gParams = params;
}













