﻿// JScript File
var nodeList;
var top=null;
var subTop;
var content;
var bottom;
var guestbook;
var blog;
var current=null;
var selectedNode=null;
var updates=1
function uiInit(langid){

    if (langid!=null){
        if (langid >= 0) configLang=langid;
    }
    var counter=0
    document.title=configTitle;
    var parent=document.getElementById("content")
    top=htmlAddElement(parent, "div", null, "topmenu");
    var elem=null;
    if(configLang==63){
        elem=htmlAddElement(top, "div", null, "bueng");
        elem.title="Click for English page !"
        elem.onclick=function(){
      window.location="english.htm";
    }
    }else{
        elem=htmlAddElement(top, "div", null, "buswe");
        elem.title="Click for Swedish page (Svenska) !"
        elem.onclick=function(){
      window.location="index.htm";
    }
    }
    subTop=htmlAddElement(top, "div", null, "topmenuSubMenu");
    if(configUseHeadline) headline=htmlAddElement(top, "div", null, "headline");
    nodeList=getNodes(urlHttp+"getNodes.asp?all=0")
    if (nodeList == null) nodeList=getNodes(urlHttp+"getNodes.asp?all=0")
     for (var i = 0; i < nodeList.length; i++){
        var left=(counter*configLeft)+conOffLeft;
        nodeList[i].Create (top, left+configOffset,"topmenubutton")
        counter++
     }
    content=htmlAddElement(parent, "div", null, "content")
    bottom=htmlAddElement(parent, "div", null, "bottom")
    if (configAdress !=null) bottom.innerHTML=configAdress;
    bottom.style.top=content.offsetHeight+configHeight;
    configInit();
    uiShow(null,"1", null)
 }



function uiShow(id,firstpage, name){
var isfirst=firstpage;
setScrollTop()
var id=(id==null) ? 1:id
var querystring=null;
var prefix=new Date().getTime();
var node=(firstpage==1) ? null : getParentNode(id, nodeList);
var parent=0;
updates++
if (node !=null){
    if (current ==null || current.id != node.id) {
       node.ParentNodeClicked()
       node.CreateChilds()
    }
    node=getNode(id, nodeList)
}else{
querystring=GetQueryString(document.location.href)
if (querystring !=null){
    node=getFirstpageWithName(nodeList,querystring)
    }
    if(node==null){
    node = getFirstpage(nodeList)
    }
    
    if (configLang >=0) parent=configLang;
    if (node.parent == parent){
    node.ParentNodeClicked();
    node.CreateChilds();
    }else{
    var temp=getNode(node.parent, nodeList)
    temp.ParentNodeClicked();
    temp.CreateChilds();
    }
    id=node.id;
    firstpage=0;
}
if (node==null || node.template==0){
var xml = xmlLoad(urlHttp+"getHtml.asp?firstpage="+firstpage+"&id="+id+"&UPD="+prefix);
var txt="";
if (xml !=null){
    var mypage = xmlXPath(xmlXPath(xml, "/root")[0], "page")
     if (mypage.length > 0){
        txt=(mypage[0].text==null) ? null:mypage[0].text
        if(txt==null) txt=mypage[0].childNodes[0].nodeValue
        if(txt==null) txt="";
    }
    }
    
        while ( txt.indexOf("&lt;") > 0 || txt.indexOf("&gt;") > 0 || txt.indexOf("&#39;") > 0){
        txt = txt.replace("&lt;" , "<");
        txt = txt.replace("&gt;", ">");
         txt = txt.replace("&#39;", "'");
    }
    name=(name==null) ? mypage[0].getAttribute("name"):name
    
    if(configUseHeadline)headline.innerHTML=name;
    
    if(firstpage==1) {
        var pid=(mypage[0].getAttribute("id")==null) ? null: mypage[0].getAttribute("id");
        if (pid !=null){
            node=getNode(pid, nodeList);
            node.ParentNodeClicked();
            node.CreateChilds();
        }
    }else{
        content.style.top=148;
    }
    
    content.innerHTML="<div id='htmllayer'>"+unescape(txt)+"</div>"
    //headline.innerHTML=name;
    if(name=="Home" || name=="Hem" || isfirst==1) {
        content.style.top=134;
        initRssNews();
    }
   }else if(node.template==1){
    content.style.top=148;
    guestbook=new NoteBook(content, unloadGuestbook);
    guestbook.Show();
   }else if(node.template==2){
   content.style.top=148;
   blog=new Blog(content);
    blog.Show("0");
   }else if(node.template==3){
   content.style.top=148;
    blog=new Blog(content);
    blog.Show("1");
   }
    uiSetContentHeight ()
}

function uiSetContentHeight (){
 var elem=document.getElementById("htmllayer")
    var contentheight= parseInt(elem.offsetHeight);
    if (contentheight > 500){
        content.style.height=contentheight+configOffset
         bottom.style.top=content.offsetHeight+configHeight
    }else{
     content.style.height=500
        bottom.style.top=content.offsetHeight+configHeight
    }
}