﻿// JavaScript Document


// Bilder laden:
var XMLBilder = {
    xml:'',
    data:[],
	
	loadXML:function()
    {
		
        if (window.ActiveXObject)
        {
            this.xml = new ActiveXObject("Microsoft.XMLDOM");
            this.xml.async = false;
            this.xml.load(LoadText);
            this.loadHash();
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            this.xml = document.implementation.createDocument("","",null);
            this.xml.async = false;
            this.xml.onload = this.loadHash;
            this.xml.load(LoadText);
        }
        else
        {
            alert("Kann XML-Datei nicht öffnen.");
        }
    },
	
	loadHash:function()
    {
        var bilder = XMLBilder.xml.documentElement.childNodes;
        for (var i=0; i<bilder.length; i++)
        {
            if (bilder[i].nodeType != 1) continue;
            var childs = bilder[i].childNodes;
            for (var j=0; j<childs.length; j++)
            { 
                if (childs[j].nodeType != 1) bilder[i].removeChild(childs[j]);
            }
            XMLBilder.data[XMLBilder.data.length] = {
                "titel" : childs[0].firstChild.nodeValue,
                "technik" : childs[1].firstChild.nodeValue,
                "jahr"  : childs[2].firstChild.nodeValue,
				"groesse"  : childs[3].firstChild.nodeValue
            };
        }
    },
	
	printBook:function(i)
    {
        this.cleanBook();
        var i = (i) ? i : 0;
        var html  = document.getElementById("Bildtext");
        var left  = html.getElementsByTagName("div")[0];
        var right = html.getElementsByTagName("div")[1];
		var middle = html.getElementsByTagName("div")[2];
		
        //this.setTag('img',left,XMLBuchladen.data[i].Image,"src");
        this.setTag('span',left,XMLBilder.data[i].titel);
        this.setTag('span',right,XMLBilder.data[i].technik);
        this.setTag('span',middle,XMLBilder.data[i].jahr);
		this.setTag('span',middle," - " + XMLBilder.data[i].groesse);
    },
	
	setTag:function(elm, item, data, attr)
    {
        var tmp = item;
        var elm = document.createElement(elm);
        tmp.appendChild(elm);
        //if (attr)
        //{
            //if (attr == "href")
            //{
            //    var a = document.createElement("a");
            //    a.setAttribute(attr, data);
            //    a.appendChild(
            //        document.createTextNode("Galileo Books")
            //    );
            //    elm.appendChild(a); 
            //}
            //else 
			//elm.setAttribute(attr, data);
        //}
        //else
        //{
            elm.appendChild(
                document.createTextNode(
                    (data)?data:""
                )
            );
        //}
    },
	
	cleanBook:function()
    {
        var html = document.getElementById("Bildtext");
        var arry = [
            html.getElementsByTagName("div")[0],
            html.getElementsByTagName("div")[1],
			html.getElementsByTagName("div")[2]
        ];
        for (i in arry)
        {
            while(arry[i].firstChild)
            {
                arry[i].removeChild(arry[i].firstChild);
            }       
        }
    },
	
	//setOption:function()
    //{
		//i = 3;
        //this.printBook(i);
    //}
}

function holeArgument() {
  var argumente = new Object();
  var suche = location.search.substring(1);
  var paare = suche.split("&");
  for (var i=0; i<paare.length; i++) {
    var pos = paare[i].indexOf('=');
	if (pos == -1) continue;
	var argName = paare[i].substring(0, pos);
	var wert = paare[i].substring(pos + 1);
	  //argumente[argName] = unescape(value);
	argumente[argName] = decodeURIComponent(wert);
  }
  return argumente;
}



// Submenu laden:
var XMLSubmenu = {

    xml:'',
    data:[],
	
	loadXML:function()
    {
        if (window.ActiveXObject)
        {
            this.xml = new ActiveXObject("Microsoft.XMLDOM");
            this.xml.async = false;
            this.xml.load("submenu.xml");
            this.loadHash();
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            this.xml = document.implementation.createDocument("","",null);
            this.xml.async = false;
            this.xml.onload = this.loadHash;
            this.xml.load("submenu.xml");
        }
        else
        {
            alert("Kann XML-Datei nicht öffnen.");
        }
    },
	
	loadHash:function()
    {
        var submenu = XMLSubmenu.xml.documentElement.childNodes;
        for (var i=0; i<bilder.length; i++)
        {
            if (submenu[i].nodeType != 1) continue;
            var childs = submenu[i].childNodes;
            for (var j=0; j<childs.length; j++)
            { 
                if (childs[j].nodeType != 1) submenu[i].removeChild(childs[j]);
            }
            XMLSubmenu.data[XMLSubmenu.data.length] = {
				"Link" : submenu[i].getAttribute("link"),
                "Titel" : childs[0].firstChild.nodeValue,
                "Kategorie" : childs[1].firstChild.nodeValue
            };
        }
    },
	
	printBook:function(i)
    {
        this.cleanBook();
        var i = (i) ? i : 0;
        var DIVsubmenu  = document.getElementById("DIVsubmenu");
        var DIV = html.getElementsByTagName("div")[0];
        //var right = html.getElementsByTagName("div")[1];
		//var middle = html.getElementsByTagName("div")[2];
		
        //this.setTag('img',left,XMLBuchladen.data[i].Image,"src");
		this.setTag('span',DIV,XMLSubmenu.data[i].Link,"href");
        this.setTag('span',DIV,XMLSubmenu.data[i].Titel);
        this.setTag('span',DIV,XMLSubmenu.data[i].Kategorie);
    },
	
	setTag:function(elm, item, data, attr)
    {
        var tmp = item;
        var elm = document.createElement(elm);
        tmp.appendChild(elm);
        if (attr)
          {
            if (attr == "href")
            {
                var a = document.createElement("a");
                a.setAttribute(attr, data);
                a.appendChild(
                    document.createTextNode("Galileo Books")
                );
                elm.appendChild(a); 
            }
            else 
			elm.setAttribute(attr, data);
        }
        else
        {
            elm.appendChild(
                document.createTextNode(
                    (data)?data:""
                )
            );
        }
    },
	
	cleanBook:function()
    {
        var html = document.getElementById("DIVsubmenu");
        var arry = [
            html.getElementsByTagName("div")[0],
        ];
        for (i in arry)
        {
            while(arry[i].firstChild)
            {
                arry[i].removeChild(arry[i].firstChild);
            }       
        }
    },
	
}
