var xmlDocLink;
var xmlDocInst;
var xmlDocMod;
var pyHelp;	//Hjälpavsn
var pyLinkList;	//Länklista
var pyModList;	//Modullista
var pyOvrList;	//Ovrigtlista
var instMods = ""; 	//Installerade moduler
var os;


//Kolla OS och länka till olika CSS
function getOs(){
//	alert(navigator.platform+", "+navigator.appVersion);
	//XP
	if((navigator.userAgent.indexOf('NT 5.1') != -1) &&  (navigator.userAgent.indexOf('Win') != -1)){
	 os = "xp";
	}else if(navigator.userAgent.indexOf('Win') != -1){ 
		os = "other";
	}
}

function setCSS(){
	if(os == "xp"){
		document.write('<link rel="stylesheet" type="text/css" href="css/win_xp.css">');
	}else{ 
		document.write('<link rel="stylesheet" type="text/css" href="css/win_oth.css">');
	}
}

//Ladda XMLfiler
function loadXMLNetscape(){
//Ladda Länkar
	xmlDocLink = document.implementation.createDocument("", "", null);
	xmlDocLink.async=false;
	xmlDocLink.load("lankar.xml");
	getLinkList();

//Ladda installerade Moduler	
	xmlDocInst = document.implementation.createDocument("", "", null);
	xmlDocInst.async=false;
	xmlDocInst.load("instmods.xml");
	getInstList();

//Ladda Moduler	
	xmlDocMod = document.implementation.createDocument("", "", null);
	xmlDocMod.async=false;
	xmlDocMod.load("moduler.xml");
	getModulList();
	
//Ladda Övrigt	
	xmlDocOvr = document.implementation.createDocument("", "", null);
	xmlDocOvr.async=false;
	xmlDocOvr.load("ovrigt.xml");
	getOvrList();	
}

//Ladda XMLfiler
function loadXML(){
//Ladda Länkar
	xmlDocLink = new ActiveXObject("Microsoft.XMLDOM");
	xmlDocLink.async=false;
	xmlDocLink.load("lankar.xml");
	getLinkList();

//Ladda installerade Moduler	
	xmlDocInst = new ActiveXObject("Microsoft.XMLDOM");
	xmlDocInst.async=false;
	xmlDocInst.load("instmods.xml");
	getInstList();

//Ladda Moduler	
	xmlDocMod = new ActiveXObject("Microsoft.XMLDOM");
	xmlDocMod.async=false;
	xmlDocMod.load("moduler.xml");
	getModulList();
	
//Ladda Övrigt	
	xmlDocOvr = new ActiveXObject("Microsoft.XMLDOM");
	xmlDocOvr.async=false;
	xmlDocOvr.load("ovrigt.xml");
	getOvrList();	
}

//Länkar
function getLinkList(){
	var linkname_nodes = xmlDocLink.getElementsByTagName("NAMN"); 
	var n_links = linkname_nodes.length; 
	pyLinkList = "<br><table border='0' cellpadding='3' cellspacing='0' width='160'>";
	//Rubrikrad
	pyLinkList += "<tr>";
	pyLinkList += "<td class='rubrik'>"+ xmlDocLink.getElementsByTagName("RUBRIK")[0].firstChild.nodeValue;
	pyLinkList += "</td></tr>";
	for (i = 0; i < n_links; i++){
		pyLinkList += "<tr>";
		pyLinkList += "<td><a href='" + xmlDocLink.getElementsByTagName("URL")[i].firstChild.nodeValue + "' target='_blank' class='lista'>";
		pyLinkList += xmlDocLink.getElementsByTagName("NAMN")[i].firstChild.nodeValue;
		pyLinkList += "</a></td></tr>";
	}
	pyLinkList += "</table>";
}

//Alla Pyramidmoduler
function getModulList(){

	var modname_nodes = xmlDocMod.getElementsByTagName("NAMN"); 
	var n_modules = modname_nodes.length; 
	pyModList = "<br><table border='0' cellpadding='2' cellspacing='0'>";
	//Rubrikrad
	pyModList += "<tr>";
	pyModList += "<td class='rubrik'>"+ xmlDocMod.getElementsByTagName("RUBRIK")[0].firstChild.nodeValue;
	pyModList += "</td></tr>";
	for (i = 0; i < n_modules; i++){
		pyModList += "<tr>";
		pyModList += "<td id='"+ xmlDocMod.getElementsByTagName("KOD")[i].firstChild.nodeValue + "' nowrap>";
		pyModList += "<a href='../" + xmlDocMod.getElementsByTagName("FIL")[i].firstChild.nodeValue + "' target='f1_main'";
		//Finns modulen installerad, markera med bild
		if(instMods.indexOf(xmlDocMod.getElementsByTagName("KOD")[i].firstChild.nodeValue) != -1){			
			pyModList += " class='instmoduler'><img src='img/inst.gif' border='0' align='middle' title='Modulen är installerad'>";
		}else{
			pyModList += " class='moduler'><img src='img/uninst.gif' border='0' align='middle'>";			
		}
		pyModList += xmlDocMod.getElementsByTagName("NAMN")[i].firstChild.nodeValue;
		pyModList += "</a></td></tr>";
	}
	pyModList += "</table>";
}

//Installerade Pyramidmoduler
function getInstList(){

	var instmod_nodes = xmlDocInst.getElementsByTagName("KOD"); 
	var n_inst = instmod_nodes.length; 
	
	//Bygg upp sträng som innehåller alla installerade modulers systemkod
	for (i = 0; i < n_inst; i++){
		instMods += xmlDocInst.getElementsByTagName("KOD")[i].firstChild.nodeValue +",";
	}
}

//Övrig lista
function getOvrList(){

	var rowname_nodes = xmlDocOvr.getElementsByTagName("NAMN"); 
	var n_rows = rowname_nodes.length; 
	pyOvrList = "<br><table border='0' cellpadding='3' cellspacing='0' width='160'>";
	//Rubrikrad
	pyOvrList += "<tr>";
	pyOvrList += "<td class='rubrik'>"+ xmlDocOvr.getElementsByTagName("RUBRIK")[0].firstChild.nodeValue;
	pyOvrList += "</td></tr>";
	for (i = 0; i < n_rows; i++){
		pyOvrList += "<tr><td>";
		pyOvrList += "<a href='../" + xmlDocOvr.getElementsByTagName("FIL")[i].firstChild.nodeValue + "' target='f1_main' class='lista'>";
		pyOvrList += xmlDocOvr.getElementsByTagName("NAMN")[i].firstChild.nodeValue;
		pyOvrList += "</a></td></tr>";
	}
	pyOvrList += "</table>";
}

//Att använda F1-hjälpen
pyHelp = "<br><table border='0' cellpadding='3' cellspacing='0' width='160'>";
pyHelp += "<tr><td class='rubrik'>F1-hjälp</td></tr>";
pyHelp += "<tr><td>";
pyHelp += "<a href='../help_pdf/hlpstart.pdf' target='f1_main' class='lista'>Så använder du F1-hjälp</a>";	
pyHelp += "</td></tr></table>";
