Unexpected runtime error

The runtime has encountered an unexpected error.

Error source

Page Name:/Sitemap.xsp
Control Id: computedField1
Property: value

Exception

Error while executing JavaScript computed expression
Script interpreter error, line=30, col=41: 'hdoc' is null

Javascript code

   1: nview  = database.getView("(NavigatorParent)");
   2: text="";
   3: i=0;
   4: 
   5: function NavDok(ndoc){
   6: 	try{
   7: 	
   8: 	pdoc = database.getDocumentByUNID(ndoc.getParentDocumentUNID());
   9: 	
  10: 	if(pdoc!=null & doc.getItemValueString("imNav")=="1"){
  11: 						
  12: 		text+="<li><a href='/" + @ReplaceSubstring(database.getFilePath(),"\\","/") + "/Inhalt/" + pdoc.getItemValueString("URLTitel") + "'>" + ndoc.getItemValueString("Label") + "</a>"; 
  13: 		
  14: 		ndoc = nview.getDocumentByKey("NL" + ndoc.getUniversalID()); 
  15:   		if(ndoc != null){
  16:   			text+="<ul class='eb2'>";
  17:     		while(ndoc != null){
  18:     			NavDok(ndoc);
  19:    				ndoc = nview.getDocumentByKey("TL" + ndoc.getUniversalID());
  20:     		}
  21:    			text+= "</ul>";
  22:   		}				
  23: 		text+= "</li>\n";
  24: 	}}catch(e){
  25: 	}
  26: }
  27: 
  28: doc   = nview.getDocumentByKey("TL/");
  29: hdoc  = database.getView("(Homepage)").getFirstDocument();
  30: ndoc  = navigator.getDocumentByKey(hdoc.getUniversalID());
  31: if(ndoc == null) 
  32: text+="<li><a href='/" + @ReplaceSubstring(database.getFilePath(),"\\","/") + "/Inhalt/" + hdoc.getItemValueString("UrlTitel") + "'>" + hdoc.getItemValueString("Subject") + "</a>"; 
  33: 		
  34: 
  35: while(doc != null){
  36: 	i=0;
  37: 	NavDok(doc);
  38:   	doc = nview.getDocumentByKey("TL" + doc.getUniversalID()); 
  39: }
  40: 
  41: text

Stack Trace