smenu = new Array();
jptmpmenu = new Array();
jpmenu = new Array();

submenuHentID = 0;
subRun = 0;
subsToEval = '';
WhatHasRun = '';
 
function printR(arr)
{
	tmparr = '';
	for (arri = 0; arri < arr.length; arri++)
		tmparr += arr[arri] + ",";
 
	return tmparr;
}
 
function SMenu_Add(parentID, pageID, pageTitle, pageAccess, pageURL)
{
	smenu[smenu.length] = Array(parentID, pageID, pageTitle, pageAccess, pageURL);
}
function JPMenu_Add(parentID, pageID, pageTitle, pageAccess, pageURL)
{
	jptmpmenu[jptmpmenu.length] = Array(parentID, pageID, pageTitle, pageAccess, pageURL);
}

function JPMenu_Make(parent, backtrack)
{
	bArr = backtrack.split("|");
 
	if (parent == 0)
	{
		j = 0;
		while (j < jptmpmenu.length)
		{
			if (jptmpmenu[j][0] == 0)
			{
				jpmenu[jpmenu.length] = Array(jptmpmenu[j][1], jptmpmenu[j][2], Array(), jptmpmenu[j][3], jptmpmenu[j][4]);
				tmpPageID = jptmpmenu[j][1];
				//jptmpmenu.splice(j,1);
				JPMenu_Make(tmpPageID, jpmenu.length-1 + "");
				//j--;
				
			}
			j++;
		}
	}
	else if (bArr.length == 1)
	{
 
		k = 0;
		while (k < jptmpmenu.length)
		{
			if (jptmpmenu[k][0] == parent)
			{
 
				jpmenu[bArr[0]][2][jpmenu[bArr[0]][2].length] = Array(jptmpmenu[k][1], jptmpmenu[k][2], Array(), jptmpmenu[k][3], jptmpmenu[k][4]);
				tmpPageID = jptmpmenu[k][1];
				//jptmpmenu.splice(k,1);
				JPMenu_Make(tmpPageID,  backtrack + "|" + (jpmenu[bArr[0]][2].length-1));
				//k--;
			}
			k++;
		}		
	}
	else if (bArr.length == 2)
	{
 
		m = 0;
		while (m < jptmpmenu.length)
		{
			if (jptmpmenu[m][0] == parent)
			{
 
				jpmenu[bArr[0]][2][bArr[1]][2][jpmenu[bArr[0]][2][bArr[1]][2].length] = Array(jptmpmenu[m][1], jptmpmenu[m][2], Array(), jptmpmenu[m][3], jptmpmenu[m][4]);
				tmpPageID = jptmpmenu[m][1];
				//jptmpmenu.splice(m,1);
				JPMenu_Make(tmpPageID,  backtrack + "|" + (jpmenu[bArr[0]][2][bArr[1]][2].length-1));
				//m--;
			}
			m++;
		}		
	}
 
	else if (bArr.length == 3)
	{
 
		n = 0;
		while (n < jptmpmenu.length)
		{
			if (jptmpmenu[n][0] == parent)
			{
 
				jpmenu[bArr[0]][2][bArr[1]][2][bArr[2]][2][jpmenu[bArr[0]][2][bArr[1]][2][bArr[2]][2].length] = Array(jptmpmenu[n][1], jptmpmenu[n][2], Array(), jptmpmenu[n][3], jptmpmenu[n][4]);
				tmpPageID = jptmpmenu[n][1];
				//jptmpmenu.splice(n,1);
				JPMenu_Make(tmpPageID,  backtrack + "|" + (jpmenu[bArr[0]][2][bArr[1]][2][bArr[2]][2].length-1));
				//n--;
			}
			n++;
		}		
	}
 
}

function visSpeciale() {
	

	gotoID = '';
	behId=document.getElementById("behandling").options[document.getElementById("behandling").selectedIndex].value;
	if(behId==""){
		alert('Vælg speciale');
	}
	else 
	{
		spcId=document.getElementById("speciale").options[document.getElementById("speciale").selectedIndex].value;
 
		if(spcId)
		{
			gotoID = spcId;
			gotoTxt = document.getElementById("speciale").options[document.getElementById("speciale").selectedIndex].text;
		}
		
		if(spcId=='' && behId!='')
		{
			gotoID = behId;
			gotoTxt = document.getElementById("behandling").options[document.getElementById("behandling").selectedIndex].text;
		}

		/*		
		gotoTxt = gotoTxt.toLowerCase();
		gotoTxt = gotoTxt.replace('æ','ae');		
		gotoTxt = gotoTxt.replace('ø','oe');				
		gotoTxt = gotoTxt.replace('å','aa');						
		gotoTxt = gotoTxt.replace('?','');														
		gotoTxt = gotoTxt.replace('.','');																
		gotoTxt = gotoTxt.replace(',','');		
		gotoTxt = gotoTxt.replace('?','');				
		gotoTxt = gotoTxt.replace(/\s/gi,'_');
		gotoTxt = gotoTxt.replace(/ /gi,'');
		
		window.location.href='/' + gotoTxt + '.386.aspx?recordid354='+gotoID;
		*/
		window.location.href = '/' + gotoID;
		/*
		if(spcId){
			window.location.href='/page354.aspx?recordid354='+spcId;
		}
		
		if(spcId=='' && behId!=''){
			window.location.href='/page354.aspx?recordid354='+behId;
		}
		*/
 
	}
 
}
 
function behandling_skift() 
{
	document.getElementById('findbehandling2').innerHTML = '<select name="speciale" id="speciale"><option value="">Henter... Vent venligst...</option></select>';	
	
	
	if (jpmenu.length > 0)
		writeSubs();
	else
	{
		//xmlhttpPost('/page357.aspx?', false);		
		xmlhttpPost('/wdc_webserv/specialer_js.ashx?', false);		
	}
	
}
 
function writeSubs()
{
	slc2 = '';
	slc = '';
	slc2 += '<select name="speciale" id="speciale">';
	slc2 += '<option value="">Vælg behandling</option>';

	slcId=document.getElementById("behandling").options[document.getElementById("behandling").selectedIndex].value;
	pos1 = slcId.lastIndexOf('=');
	if (pos1 > 0)
	{
		slcId = slcId.substr(pos1+1);
	}	

	
	for (k = 0; k < jpmenu.length; k++)
	{
		if (jpmenu[k][0] == slcId)
		{
			for (k2 = 0; k2 < jpmenu[k][2].length; k2++)
			{
				slc2 += '<option value="'+jpmenu[k][2][k2][4]+'.386.aspx?recordid354='+jpmenu[k][2][k2][0]+'&pid='+slcId+'&pid2='+jpmenu[k][2][k2][0]+'&pid3=-1">' + jpmenu[k][2][k2][1] + '</option>';  							
				
				for (k3 = 0; k3 < jpmenu[k][2][k2][2].length; k3++)
				{
					slc2 += '<option value="'+jpmenu[k][2][k2][2][k3][4]+'.386.aspx?recordid354='+jpmenu[k][2][k2][2][k3][0]+'&pid='+slcId+'&pid2='+jpmenu[k][2][k2][0]+'&pid3='+jpmenu[k][2][k2][2][k3][0]+'">&nbsp;&nbsp;&rarr;&nbsp;&nbsp;' + jpmenu[k][2][k2][2][k3][1] + '</option>';  												
					for (k4 = 0; k4 < jpmenu[k][2][k2][2][k3][2].length; k4++)
					{
						slc2 += '<option value="'+jpmenu[k][2][k2][2][k3][2][k4][4]+'.386.aspx?recordid354='+jpmenu[k][2][k2][2][k3][2][k4][0]+'&pid='+slcId+'&pid2='+jpmenu[k][2][k2][0]+'&pid3='+jpmenu[k][2][k2][2][k3][0]+'">&nbsp;&nbsp;&nbsp;&nbsp;&rarr;&nbsp;&nbsp;' + jpmenu[k][2][k2][2][k3][2][k4][1] + '</option>';  																		
					}
		
				}
			}
		}
	}	

	slc2 += '</select>';
	document.getElementById('findbehandling2').innerHTML = slc2;	
}
 
function updatepage(strB, runSubs)
{
	//smenu = new Array();
	//alert(strB);
	eval(strB);
	
	JPMenu_Make(0, "");	
	
	writeSubs();
}
 
function xmlhttpPost(strURL, runSubs) 
{

    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL + '&rndkey=' + Math.floor(Math.random()*10000000000), true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, runSubs);
        }
    }
    self.xmlHttpReq.send();
}
 
 
function SMenu_Start()
{
	slc = '';
	slc += '<select id="behandling" name="behandling" onChange="behandling_skift();">';
	slc += '<option value="">Vælg speciale</option>';
	//slc2 += '<select>';

	for (k = 0; k < smenu.length; k++)
	{
		slc += '<option value="'+smenu[k][4]+'.386.aspx?pid='+smenu[k][1]+'&pid2=-1&pid3=-1&recordid354='+smenu[k][1]+'">' + smenu[k][2] + '</option>';  
	}
	//slc2 += '</select>';
	slc += '</select>';

	document.getElementById('findbehandling').innerHTML = slc;

	Tangora.Layout.Resize(); 
}


function topMenu_spec()
{
//alert(document.getElementById('topMenu'));
var tjek = document.getElementById('topMenu');

	if(tjek){
		slc = '';
		slc += '';
		//slc += '<option value="">Vælg speciale</option>';
	
	  end=smenu.length-1;
	  
		for (k = 0; k < smenu.length; k++)
		{
			slc += '&nbsp; • &nbsp;<a href="'+smenu[k][4]+'.386.aspx?pid='+smenu[k][1]+'&pid2=-1&pid3=-1&recordid354='+smenu[k][1]+'">' + smenu[k][2] + '</a>';  
	    

	    if(k==end){
			
			document.getElementById('topMenu').style.display='block';
			}
		}
		slc += '';
	
		document.getElementById('topMenu').innerHTML = slc;
	  

		Tangora.Layout.Resize(); 
		
		
	}
}


/*var lysavis = false;
var container = false;


function ScrollMessage() {
var tjek = document.getElementById('topMenu');
if(tjek){
    lysavis=document.getElementById('lysAvisen');
		lysavis.style.left = 883 + 'px';  
    action = window.setInterval("Glide()",5)
}
}

function Glide() {
    lysavis.style.left = lysavis.offsetLeft - 1 + "px";
    if (lysavis.offsetLeft<=0-lysavis.offsetWidth-10) 
    {
		lysavis.style.left = 883 + 'px'; 

    }

}
	*/







Tangora.Events.AddHandler(window, "onload", SMenu_Start);
Tangora.Events.AddHandler(window, "onload", topMenu_spec);

