Index: .hgtags
===================================================================
--- .hgtags	(revision 497)
+++ .hgtags	(revision 497)
@@ -0,0 +1,5 @@
+4db49915d825571c1e81da3ba2273229f3736b02 Root_modularisierung
+93b9a5dddb8b2976c128481c696eac44acc64fa7 Root_elementtree
+cb0978becec474f6e9d62dfce6aa1fb7ef31c99c Root_metalify-1
+df6952ac93e9a517dc6936a9ff0f6447dfd43a63 Root_integrate_imageArchive
+ead830ce45d61a215ee451f9d6ab804bec525012 Root_roc_1
Index: .project
===================================================================
--- .project	(revision 77)
+++ .project	(revision 77)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>documentViewer</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.python.pydev.pythonNature</nature>
+	</natures>
+</projectDescription>
Index: .pydevproject
===================================================================
--- .pydevproject	(revision 139)
+++ .pydevproject	(revision 139)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?>
+
+<pydev_project>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
+</pydev_project>
Index: MpdlXmlTextServer.py
===================================================================
--- MpdlXmlTextServer.py	(revision 496)
+++ MpdlXmlTextServer.py	(revision 451)
@@ -2,7 +2,8 @@
 from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 
-
 from Ft.Xml import EMPTY_NAMESPACE, Parse
-
+from Ft.Xml.Domlette import NonvalidatingReader
+
+import md5
 import sys
 import logging
@@ -11,5 +12,4 @@
 from documentViewer import getTextFromNode, serializeNode
 
-
 class MpdlXmlTextServer(SimpleItem):
     """TextServer implementation for MPDL-XML eXist server"""
@@ -22,5 +22,7 @@
     manage_changeMpdlXmlTextServerForm = PageTemplateFile("zpt/manage_changeMpdlXmlTextServer", globals())
         
-    def __init__(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40):
+    def __init__(self,id,title="",serverUrl="http://mpdl-test.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40):
+    #def __init__(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/", serverName=None, timeout=40):    
+        
         """constructor"""
         self.id=id
@@ -31,10 +33,8 @@
         else:
             self.serverUrl = "http://%s/mpdl/interface/"%serverName
-
         
     def getHttpData(self, url, data=None):
         """returns result from url+data HTTP request"""
         return documentViewer.getHttpData(url,data,timeout=self.timeout)
-
     
     def getServerData(self, method, data=None):
@@ -43,14 +43,15 @@
         return documentViewer.getHttpData(url,data,timeout=self.timeout)
 
-
-    def getSearch(self, pn=1, pageinfo=None,  docinfo=None, query=None, queryType=None, lemma=None):
+    def getSearch(self, pageinfo=None,  docinfo=None):
         """get search list"""
         docpath = docinfo['textURLPath'] 
         url = docinfo['url']
-        logging.debug("documentViewer (gettoc) docpath: %s"%(docpath))
-        logging.debug("documentViewer (gettoc) url: %s"%(url))
         pagesize = pageinfo['queryPageSize']
-        pn = pageinfo['searchPN']
-        sn = pageinfo['sn']
+        pn = pageinfo.get('searchPN',1)
+        #sn = pageinfo['sn']
+        s = pageinfo['s']
+        highlightElementPos =pageinfo ['highlightElementPos']
+        highlightElement = pageinfo ['highlightElement']
+        
         highlightQuery = pageinfo['highlightQuery']
         query =pageinfo['query']
@@ -58,12 +59,26 @@
         viewMode=  pageinfo['viewMode']
         tocMode = pageinfo['tocMode']
+        characterNormalization = pageinfo['characterNormalization']
+        #optionToggle = pageinfo['optionToggle']
         tocPN = pageinfo['tocPN']
         selfurl = self.absolute_url()
-        
-        data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&highlightQuery=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode,highlightQuery))
-        #page=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&highlightQuery=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode,highlightQuery) ,outputUnicode=False)                
-        
+        data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&s=%s&viewMode=%s&characterNormalization=%s&highlightElementPos=%s&highlightElement=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, s, viewMode,characterNormalization, highlightElementPos, highlightElement, urllib.quote(highlightQuery)))
+        #data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&characterNormalization=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,characterNormalization, urllib.quote(highlightQuery)))
         pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)
         pagedom = Parse(pagexml)
+        
+        """
+        pagedivs = pagedom.xpath("//div[@class='queryResultHits']") 
+        if (pagedivs == pagedom.xpath("//div[@class='queryResultHits']")):
+            if len(pagedivs)>0:
+                docinfo['queryResultHits'] = int(getTextFromNode(pagedivs[0]))
+                s = getTextFromNode(pagedivs[0])
+                s1 = int(s)/10+1
+                try:
+                    docinfo['queryResultHits'] = int(s1)
+                    logging.debug("SEARCH ENTRIES: %s"%(s1))
+                except:
+                    docinfo['queryResultHits'] = 0
+        """
         if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"):   
             pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
@@ -77,6 +92,7 @@
                         if href.startswith('page-fragment.xql'):
                             selfurl = self.absolute_url()            
-                            pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,query,pagesize,pn,tocMode,pn,tocPN))
+                            pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN, characterNormalization))
                             hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)                                           
+                #logging.debug("PUREXML :%s"%(serializeNode(pagenode)))
                 return serializeNode(pagenode)        
         if (queryType=="fulltextMorph"):
@@ -91,10 +107,10 @@
                         if href.startswith('page-fragment.xql'):
                             selfurl = self.absolute_url()       
-                            pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,query,pagesize,pn,tocMode,pn,tocPN))
+                            pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN,characterNormalization))
                             hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)  
                         if href.startswith('../lt/lemma.xql'):
-                            hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma_New'%(selfurl))        
+                            hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_query'%(selfurl))        
                             l.setAttributeNS(None, 'target', '_blank')
-                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;")
+                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=300,height=400,top=180, left=400, scrollbars=1'); return false;")
                             l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')  
                 pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']")                
@@ -109,39 +125,83 @@
                     if hrefNode:
                         href = hrefNode.nodeValue
-                        hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s'%(viewMode,tocMode,tocPN,pn))             
+                        hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s&characterNormalization=%s'%(viewMode,tocMode,tocPN,pn,characterNormalization))             
                         if href.startswith('../lt/lex.xql'):
-                            hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_voc'%selfurl)         
+                            hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_lex'%selfurl)         
                             l.setAttributeNS(None, 'target', '_blank')
                             l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;")
                             l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')
                         if href.startswith('../lt/lemma.xql'):
-                            hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%selfurl)        
+                            hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%(selfurl))        
                             l.setAttributeNS(None, 'target', '_blank')
-                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;")
+                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=300,height=400,top=180, left=400, scrollbars=1'); return false;")
                             l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')
                 return serializeNode(pagenode)      
         return "no text here"   
-                       
-    def getNumPages(self, docinfo):
-        """get list of pages from fulltext and put in docinfo"""
-        if 'numPages' in docinfo:
-            # already there
-            return docinfo
-        
-        xquery = '//pb'
-        text = self.getServerData("xquery.xql","document=%s&xquery=%s"%(docinfo['textURLPath'],xquery))
-        #text = self.template.fulltextclient.eval("/mpdl/interface/xquery.xql", "document=%s&xquery=%s"%(docinfo['textURLPath'],xquery))
-        docinfo['numPages'] = text.count("<pb ")
-        return docinfo
-       
-    def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None, highlightQuery=None,sn=None, viewMode=None, tocMode=None, tocPN=None):
+           
+    def getGisPlaces(self, docinfo=None, pageinfo=None):
+        """ Show all Gis Places of whole Page"""
+        xpath='//place'
+        docpath = docinfo.get('textURLPath',None)
+        if not docpath:
+            return None
+
+        url = docinfo['url']
+        selfurl = self.absolute_url()
+        pn = pageinfo['current']
+        hrefList=[]
+        myList= ""
+        text=self.getServerData("xpath.xql", "document=%s&xpath=%s&pn=%s"%(docinfo['textURLPath'],xpath,pn))
+        dom = Parse(text)
+        result = dom.xpath("//result/resultPage/place")
+        for l in result:
+            hrefNode= l.getAttributeNodeNS(None, u"id")
+            href= hrefNode.nodeValue
+            hrefList.append(href)
+            myList = ",".join(hrefList)
+        #logging.debug("getGisPlaces :%s"%(myList))                             
+        return myList
+    
+    def getAllGisPlaces (self, docinfo=None, pageinfo=None):
+        """Show all Gis Places of whole Book """
+        xpath ='//echo:place'
+        docpath =docinfo['textURLPath']
+        url = docinfo['url']
+        selfurl =self.absolute_url()
+        pn =pageinfo['current']
+        hrefList=[]
+        myList=""
+        text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'],xpath))
+        dom =Parse(text)
+        result = dom.xpath("//result/resultPage/place")
+        
+        for l in result:
+            hrefNode = l.getAttributeNodeNS(None, u"id")
+            href= hrefNode.nodeValue
+            hrefList.append(href)
+            myList = ",".join(hrefList)
+            #logging.debug("getALLGisPlaces :%s"%(myList))
+        return myList
+          
+           
+    def getTextPage(self, mode="text_dict", pn=1, docinfo=None, pageinfo=None):
         """returns single page from fulltext"""
         docpath = docinfo['textURLPath']
         path = docinfo['textURLPath']
-        url = docinfo['url']
-        viewMode= pageinfo['viewMode']
+        url = docinfo.get('url',None)
+        name = docinfo.get('name',None)
+        pn =pageinfo['current']
+        #sn = pageinfo['sn']
+        s = pageinfo['s']
+        highlightElementPos =pageinfo ['highlightElementPos']
+        highlightElement = pageinfo ['highlightElement']
+        #optionToggle =pageinfo ['optionToggle']
+        highlightQuery = pageinfo['highlightQuery']
+        #mode = pageinfo ['viewMode']
         tocMode = pageinfo['tocMode']
+        xpointer = pageinfo['xpointer']
+        characterNormalization=pageinfo['characterNormalization']
         tocPN = pageinfo['tocPN']
         selfurl = self.absolute_url()   
+        
         if mode == "text_dict":
             textmode = "textPollux"
@@ -149,16 +209,108 @@
             textmode = mode
         
-        textParam = "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn)
+        textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s&xpointer=%s&options=withIdentifier"%(docpath,textmode,pn,characterNormalization, xpointer)
         if highlightQuery is not None:
-            textParam +="&highlightQuery=%s&sn=%s"%(highlightQuery,sn)           
+            #textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)
+            textParam +="&highlightQuery=%s&s=%s&highlightElement=%s&highlightElementPos=%s"%(urllib.quote(highlightQuery),s, highlightElement, highlightElementPos)           
         
         pagexml = self.getServerData("page-fragment.xql",textParam)
-        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)
-        
-        pagedom = Parse(pagexml)
+        dom = Parse(pagexml)
+        #dom = NonvalidatingReader.parseStream(pagexml)
+        
+        #original Pages
+        pagedivs = dom.xpath("//div[@class='pageNumberOrig']")       
+        
+        """if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
+            if len(pagedivs)>0:
+                docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
+                logging.debug("ORIGINAL PAGE: %s"%(docinfo['pageNumberOrig']))
+        
+        #original Pages Norm
+        pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
+        if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
+            if len(pagedivs)>0:
+                docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])
+                logging.debug("ORIGINAL PAGE NORM: %s"%(docinfo['pageNumberOrigNorm']))
+        """
+        #figureEntries
+        pagedivs = dom.xpath("//div[@class='countFigureEntries']")
+        if pagedivs == dom.xpath("//div[@class='countFigureEntries']"):
+            if len(pagedivs)>0:
+                docinfo['countFigureEntries'] = getTextFromNode(pagedivs[0])
+                s = getTextFromNode(pagedivs[0])
+                if s=='0':
+                    try:
+                        docinfo['countFigureEntries'] = int(s)
+                    except:
+                        docinfo['countFigureEntries'] = 0
+                else:
+                    s1 = int(s)/30+1
+                    try:
+                        docinfo['countFigureEntries'] = int(s1)
+                    except:
+                        docinfo['countFigureEntries'] = 0      
+        
+        #allPlaces
+        pagedivs = dom.xpath("//div[@class='countPlaces']")
+        if pagedivs == dom.xpath("//div[@class='countPlaces']"):
+            if len(pagedivs)>0:
+                docinfo['countPlaces']= getTextFromNode(pagedivs[0])
+                s = getTextFromNode(pagedivs[0])
+                try:
+                    docinfo['countPlaces'] = int(s)
+                except:
+                    docinfo['countPlaces'] = 0
+        
+        #tocEntries
+        pagedivs = dom.xpath("//div[@class='countTocEntries']")
+        if pagedivs == dom.xpath("//div[@class='countTocEntries']"):
+            if len(pagedivs)>0:
+                docinfo['countTocEntries'] = int(getTextFromNode(pagedivs[0]))
+                s = getTextFromNode(pagedivs[0])
+                if s=='0':
+                    try:
+                        docinfo['countTocEntries'] = int(s)
+                    except:
+                        docinfo['countTocEntries'] = 0
+                else:
+                    s1 = int(s)/30+1
+                    try:
+                        docinfo['countTocEntries'] = int(s1)
+                    except:
+                        docinfo['countTocEntries'] = 0
+        
+        #numTextPages
+        pagedivs = dom.xpath("//div[@class='countPages']")
+        if pagedivs == dom.xpath("//div[@class='countPages']"):
+            if len(pagedivs)>0:
+                docinfo['numPages'] = getTextFromNode(pagedivs[0])
+                s = getTextFromNode(pagedivs[0])
+                
+                try:
+                    docinfo['numPages'] = int(s)
+                    #logging.debug("PAGE NUMBER: %s"%(s))
+                
+                    np = docinfo['numPages']
+                    pageinfo['end'] = min(pageinfo['end'], np)
+                    pageinfo['numgroups'] = int(np / pageinfo['groupsize'])
+                    if np % pageinfo['groupsize'] > 0:
+                        pageinfo['numgroups'] += 1                
+                except:
+                    docinfo['numPages'] = 0
+                  
+        else:
+         #no full text -- init to 0
+            docinfo['pageNumberOrig'] = 0
+            docinfo['countFigureEntries'] = 0
+            docinfo['countPlaces'] = 0
+            docinfo['countTocEntries'] = 0
+            docinfo['numPages'] = 0
+            docinfo['pageNumberOrigNorm'] = 0
+        #return docinfo
+        
         # plain text mode
         if mode == "text":
             # first div contains text
-            pagedivs = pagedom.xpath("/div")
+            pagedivs = dom.xpath("/div")
             if len(pagedivs) > 0:      
                 pagenode = pagedivs[0]
@@ -169,15 +321,31 @@
                         href= hrefNode.nodeValue
                         if href.startswith('#note-'):
-                            hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))
+                            hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))
+                        #if href.startswith():
                 return serializeNode(pagenode)
         if mode == "xml":
               # first div contains text
-              pagedivs = pagedom.xpath("/div")
+              pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:
                   pagenode = pagedivs[0]
                   return serializeNode(pagenode)
+        if mode == "gis":
+              # first div contains text
+              pagedivs = dom.xpath("/div")
+              if len(pagedivs) > 0:
+                  pagenode = pagedivs[0]
+                  links =pagenode.xpath("//a")
+                  for l in links:
+                      hrefNode =l.getAttributeNodeNS(None, u"href")
+                      if hrefNode:
+                          href=hrefNode.nodeValue
+                          if href.startswith('http://mappit.mpiwg-berlin.mpg.de'):
+                              hrefNode.nodeValue =href.replace('db/REST/db/chgis/mpdl','db/RESTdb/db/mpdl/%s'%name)
+                              l.setAttributeNS(None, 'target', '_blank') 
+                  return serializeNode(pagenode)
+                    
         if mode == "pureXml":
               # first div contains text
-              pagedivs = pagedom.xpath("/div")
+              pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:
                   pagenode = pagedivs[0]
@@ -186,37 +354,69 @@
         if mode == "text_dict":
             # first div contains text
-            pagedivs = pagedom.xpath("/div")
+            #mode = pageinfo ['viewMode']
+            pagedivs = dom.xpath("/div")
             if len(pagedivs) > 0:
                 pagenode = pagedivs[0]
                 # check all a-tags
                 links = pagenode.xpath("//a")
+                
                 for l in links:
                     hrefNode = l.getAttributeNodeNS(None, u"href")
+                    
                     if hrefNode:
                         # is link with href
                         href = hrefNode.nodeValue
-                        if href.startswith('lt/lex.xql'):
+                        if href.startswith('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql'):
                             # is pollux link
                             selfurl = self.absolute_url()
                             # change href
-                            hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl)
+                            hrefNode.nodeValue = href.replace('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql','%s/head_main_voc'%selfurl)
                             # add target
                             l.setAttributeNS(None, 'target', '_blank')
-                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")
-                            l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')      
-                        if href.startswith('lt/lemma.xql'):    
+                            #l.setAttributeNS(None, 'onclick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=no, scrollbars=1'); return false;")
+                            #l.setAttributeNS(None, "ondblclick", "popupWin.focus();")
+                            #window.open("this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=yes, scrollbars=1'"); return false;") 
+                                                          
+                        if href.startswith('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql'):    
                             selfurl = self.absolute_url()
-                            hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl)
+                            hrefNode.nodeValue = href.replace('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql','%s/head_main_lemma'%selfurl)
                             l.setAttributeNS(None, 'target', '_blank')
-                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")
-                            l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')   
+                            l.setAttributeNS(None, 'onclick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=300,height=400,top=180, left=700, toolbar=no, scrollbars=1'); return false;")
+                            l.setAttributeNS(None, 'ondblclick', 'popupWin.focus();')   
+                    
                         if href.startswith('#note-'):
-                            hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))    
+                            hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text_dict&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))  
+                              
                 return serializeNode(pagenode)
         return "no text here"
-
-    def getTranslate(self, query=None, language=None):
+    
+    def getOrigPages(self, docinfo=None, pageinfo=None):
+        docpath = docinfo['textURLPath']
+        pn =pageinfo['current']
+        selfurl = self.absolute_url()   
+        pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
+        dom = Parse(pagexml)
+        pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
+        if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
+            if len(pagedivs)>0:
+                docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])        
+                return docinfo['pageNumberOrig']
+    
+    def getOrigPagesNorm(self, docinfo=None, pageinfo=None):
+        docpath = docinfo['textURLPath']
+        pn =pageinfo['current']
+        selfurl = self.absolute_url()   
+        pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
+        dom = Parse(pagexml)
+        pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
+        if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
+            if len(pagedivs)>0:
+                docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])        
+                return docinfo['pageNumberOrigNorm']
+
+                
+    def getTranslate(self, word=None, language=None, display=None):
         """translate into another languages"""
-        data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
+        data = self.getServerData("lt/wordInfo.xql","language="+str(language)+"&word="+urllib.quote(word)+"&display="+urllib.quote(display)+"&output=html")
         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
         return data
@@ -224,16 +424,19 @@
     def getLemma(self, lemma=None, language=None):
         """simular words lemma """
-        data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(lemma))
-        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma)))
+        data = self.getServerData("lt/lemma.xql","language="+str(language)+"&lemma="+urllib.quote(lemma)+"&output=html")
         return data
     
-    def getLemmaNew(self, query=None, language=None):
+    def getLemmaQuery(self, query=None, language=None):
         """simular words lemma """
-        data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(query))
-        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query)))
+        data = self.getServerData("lt/lemma.xql","language="+str(language)+"&query="+urllib.quote(query)+"&output=html")
         return data
-
+    
+    def getLex(self, query=None, language=None):
+        #simular words lemma
+        data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
+        return data
+    
     def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1):
-         """number of"""
+         #number of
          docpath = docinfo['textURLPath'] 
          pagesize = pageinfo['queryPageSize']
@@ -244,16 +447,13 @@
          tocDiv = None
          
-         pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn))
-         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn) ,outputUnicode=False)
+         pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn))
          pagedom = Parse(pagexml)
          numdivs = pagedom.xpath("//div[@class='queryResultHits']")
          tocSearch = int(getTextFromNode(numdivs[0]))
          tc=int((tocSearch/10)+1)
-         logging.debug("documentViewer (gettoc) tc: %s"%(tc))
          return tc
-
+    
     def getToc(self, mode="text", docinfo=None):
         """loads table of contents and stores in docinfo"""
-        logging.debug("documentViewer (gettoc) mode: %s"%(mode))
         if mode == "none":
             return docinfo        
@@ -275,5 +475,5 @@
         
         pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
-        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)
+        
         # post-processing downloaded xml
         pagedom = Parse(pagexml)
@@ -299,14 +499,16 @@
         selfurl = self.absolute_url()  
         viewMode=  pageinfo['viewMode']
+        characterNormalization = pageinfo ['characterNormalization']
+        #optionToggle =pageinfo ['optionToggle']
         tocMode = pageinfo['tocMode']
         tocPN = pageinfo['tocPN']  
         
-        data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))  
-
+        data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm"%(docpath,queryType, pagesize, pn))  
         page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl,url, viewMode, tocMode, tocPN))
         text = page.replace('mode=image','mode=texttool')
         return text
     
-    def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
+    def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
+    #def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):
         """change settings"""
         self.title=title
@@ -322,5 +524,6 @@
     return pt()
 
-def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
+def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
+#def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):    
     """add zogiimage"""
     newObj = MpdlXmlTextServer(id,title,serverUrl,timeout)
@@ -328,5 +531,2 @@
     if RESPONSE is not None:
         RESPONSE.redirect('manage_main')
-
-
-    
Index: css/docuviewer.css
===================================================================
--- css/docuviewer.css	(revision 21)
+++ css/docuviewer.css	(revision 21)
@@ -0,0 +1,10 @@
+.thumb {
+	padding: 3px;
+}
+.thumbsel {
+	padding: 2px;
+	border: 1px solid blue;
+}
+.thumbcap {
+	color: black;
+}
Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 496)
+++ documentViewer.py	(revision 452)
@@ -6,6 +6,7 @@
 from AccessControl import getSecurityManager
 from Globals import package_home
-
-from Ft.Xml import EMPTY_NAMESPACE, Parse
+from Products.zogiLib.zogiLib import browserCheck
+
+from Ft.Xml import EMPTY_NAMESPACE, Parse 
 import Ft.Xml.Domlette
 import os.path
@@ -17,4 +18,6 @@
 import urlparse 
 import cStringIO
+import re
+import string
 
 def logger(txt,method,txt2):
@@ -41,13 +44,76 @@
     return rc
 
-def serializeNode(node, encoding='utf-8'):
+def serializeNode(node, encoding="utf-8"):
     """returns a string containing node as XML"""
-    buf = cStringIO.StringIO()
-    Ft.Xml.Domlette.Print(node, stream=buf, encoding=encoding)
-    s = buf.getvalue()
-    buf.close()
+    stream = cStringIO.StringIO()
+    #logging.debug("BUF: %s"%(stream))
+    Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding)
+    s = stream.getvalue()
+    #logging.debug("BUF: %s"%(s))
+    stream.close()
     return s
 
-        
+def browserCheck(self):
+    """check the browsers request to find out the browser type"""
+    bt = {}
+    ua = self.REQUEST.get_header("HTTP_USER_AGENT")
+    bt['ua'] = ua
+    bt['isIE'] = False
+    bt['isN4'] = False
+    bt['versFirefox']=""
+    bt['versIE']=""
+    bt['versSafariChrome']=""
+    bt['versOpera']=""
+    
+    if string.find(ua, 'MSIE') > -1:
+        bt['isIE'] = True
+    else:
+        bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1)
+    # Safari oder Chrome identification    
+    try:
+        nav = ua[string.find(ua, '('):]
+        nav1=ua[string.find(ua,')'):]
+        nav2=nav1[string.find(nav1,'('):]
+        nav3=nav2[string.find(nav2,')'):]
+        ie = string.split(nav, "; ")[1]
+        ie1 =string.split(nav1, " ")[2]
+        ie2 =string.split(nav3, " ")[1]
+        ie3 =string.split(nav3, " ")[2]
+        if string.find(ie3, "Safari") >-1:
+            bt['versSafariChrome']=string.split(ie2, "/")[1]
+    except: pass
+    # IE identification
+    try:
+        nav = ua[string.find(ua, '('):]
+        ie = string.split(nav, "; ")[1]
+        if string.find(ie, "MSIE") > -1:
+            bt['versIE'] = string.split(ie, " ")[1]
+    except:pass
+    # Firefox identification
+    try:
+        nav = ua[string.find(ua, '('):]
+        nav1=ua[string.find(ua,')'):]
+        if string.find(ie1, "Firefox") >-1:
+            nav5= string.split(ie1, "/")[1]
+            logging.debug("FIREFOX: %s"%(nav5))
+            bt['versFirefox']=nav5[0:3]                   
+    except:pass
+    #Opera identification
+    try:
+        if string.find(ua,"Opera") >-1:
+            nav = ua[string.find(ua, '('):]
+            nav1=nav[string.find(nav,')'):]
+            bt['versOpera']=string.split(nav1,"/")[2]
+    except:pass
+    
+    bt['isMac'] = string.find(ua, 'Macintosh') > -1
+    bt['isWin'] = string.find(ua, 'Windows') > -1
+    bt['isIEWin'] = bt['isIE'] and bt['isWin']
+    bt['isIEMac'] = bt['isIE'] and bt['isMac']
+    bt['staticHTML'] = False
+
+    return bt
+
+       
 def getParentDir(path):
     """returns pathname shortened by one"""
@@ -98,6 +164,4 @@
     #return None
 
-
-
 ##
 ## documentViewer class
@@ -118,7 +182,10 @@
     toc_figures = PageTemplateFile('zpt/toc_figures', globals())
     page_main_images = PageTemplateFile('zpt/page_main_images', globals())
+    page_main_double = PageTemplateFile('zpt/page_main_double', globals())
     page_main_text = PageTemplateFile('zpt/page_main_text', globals())
     page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals())
+    page_main_gis =PageTemplateFile ('zpt/page_main_gis', globals())
     page_main_xml = PageTemplateFile('zpt/page_main_xml', globals())
+    page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', globals())
     head_main = PageTemplateFile('zpt/head_main', globals())
     docuviewer_css = PageTemplateFile('css/docuviewer.css', globals())
@@ -165,16 +232,28 @@
         return self.template.fulltextclient.getTextPage(**args)
 
+    def getOrigPages(self, **args):
+        """get page"""
+        return self.template.fulltextclient.getOrigPages(**args)
+    
+    def getOrigPagesNorm(self, **args):
+        """get page"""
+        return self.template.fulltextclient.getOrigPagesNorm(**args)
+
     def getQuery(self, **args):
-        """get query"""
+        """get query in search"""
         return self.template.fulltextclient.getQuery(**args)
-
+     
     def getSearch(self, **args):
         """get search"""
         return self.template.fulltextclient.getSearch(**args)
-
-    def getNumPages(self, docinfo):
-        """get numpages"""
-        return self.template.fulltextclient.getNumPages(docinfo)
-
+    
+    def getGisPlaces(self, **args):
+        """get gis places"""
+        return self.template.fulltextclient.getGisPlaces(**args)
+ 
+    def getAllGisPlaces(self, **args):
+        """get all gis places """
+        return self.template.fulltextclient.getAllGisPlaces(**args)
+       
     def getTranslate(self, **args):
         """get translate"""
@@ -184,4 +263,12 @@
         """get lemma"""
         return self.template.fulltextclient.getLemma(**args)
+
+    def getLemmaQuery(self, **args):
+        """get query"""
+        return self.template.fulltextclient.getLemmaQuery(**args)
+
+    def getLex(self, **args):
+        """get lex"""
+        return self.template.fulltextclient.getLex(**args)
 
     def getToc(self, **args):
@@ -214,9 +301,11 @@
             
         docinfo = self.getDocinfo(mode=mode,url=url)
-        pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo)
+        #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo)
+        pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo)
+        ''' ZDES '''
         pt = getattr(self.template, 'thumbs_main_rss')
         
         if viewMode=="auto": # automodus gewaehlt
-            if docinfo.has_key("textURL") or docinfo.has_key('textURLPath'): #texturl gesetzt und textViewer konfiguriert
+            if docinfo.has_key("textURL") or docinfo.get('textURLPath',None): #texturl gesetzt und textViewer konfiguriert
                 viewMode="text"
             else:
@@ -226,5 +315,5 @@
   
     security.declareProtected('View','index_html')
-    def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None, query=None, querySearch=None):
+    def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None):
         '''
         view it
@@ -233,4 +322,5 @@
         @param viewMode: if images display images, if text display text, default is auto (text,images or auto)
         @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none)
+        @param characterNormalization type of text display (reg, norm, none)
         @param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph, fulltextMorphLemma)
         '''
@@ -253,12 +343,16 @@
             
         if viewMode=="auto": # automodus gewaehlt
-            if docinfo.has_key('textURL') or docinfo.has_key('textURLPath'): #texturl gesetzt und textViewer konfiguriert
+            if docinfo.has_key('textURL') or docinfo.get('textURLPath',None): #texturl gesetzt und textViewer konfiguriert
                 viewMode="text_dict"
             else:
                 viewMode="images"
                 
-        pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo,viewMode=viewMode,tocMode=tocMode)
-        
-        pt = getattr(self.template, 'viewer_main')               
+        pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo,viewMode=viewMode,tocMode=tocMode)
+        
+        if (docinfo.get('textURLPath',None)):
+            page = self.getTextPage(docinfo=docinfo, pageinfo=pageinfo)
+            pageinfo['textPage'] = page
+        tt = getattr(self, 'template')   
+        pt = getattr(tt, 'viewer_main')               
         return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk))
   
@@ -272,6 +366,12 @@
             ret+="mk=%s"%m
         return ret
-
-
+    
+    
+    def getBrowser(self):
+        """getBrowser the version of browser """
+        bt = browserCheck(self)
+        logging.debug("BROWSER VERSION: %s"%(bt))
+        return bt
+        
     def findDigilibUrl(self):
         """try to get the digilib URL from zogilib"""
@@ -291,39 +391,46 @@
             return style
     
-    def getLink(self,param=None,val=None):
-        """link to documentviewer with parameter param set to val"""
-        params=self.REQUEST.form.copy()
+    def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&'):
+        """returns URL to documentviewer with parameter param set to val or from dict params"""
+        # copy existing request params
+        urlParams=self.REQUEST.form.copy()
+        # change single param
         if param is not None:
             if val is None:
-                if params.has_key(param):
-                    del params[param]
+                if urlParams.has_key(param):
+                    del urlParams[param]
             else:
-                params[param] = str(val)
+                urlParams[param] = str(val)
                 
-        if params.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath
-                params["mode"] = "imagepath"
-                params["url"] = getParentDir(params["url"])
+        # change more params
+        if params is not None:
+            for k in params.keys():
+                v = params[k]
+                if v is None:
+                    # val=None removes param
+                    if urlParams.has_key(k):
+                        del urlParams[k]
+                        
+                else:
+                    urlParams[k] = v
+
+        # FIXME: does this belong here?
+        if urlParams.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath
+                urlParams["mode"] = "imagepath"
+                urlParams["url"] = getParentDir(urlParams["url"])
                 
-        # quote values and assemble into query string
-        #ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()])
-        ps = urllib.urlencode(params)
-        url=self.REQUEST['URL1']+"?"+ps
+        # quote values and assemble into query string (not escaping '/')
+        ps = paramSep.join(["%s=%s"%(k,urllib.quote_plus(v,'/')) for (k, v) in urlParams.items()])
+        #ps = urllib.urlencode(urlParams)
+        if baseUrl is None:
+            baseUrl = self.REQUEST['URL1']
+            
+        url = "%s?%s"%(baseUrl, ps)
         return url
 
-    def getLinkAmp(self,param=None,val=None):
+
+    def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None):
         """link to documentviewer with parameter param set to val"""
-        params=self.REQUEST.form.copy()
-        if param is not None:
-            if val is None:
-                if params.has_key(param):
-                    del params[param]
-            else:
-                params[param] = str(val)
-                
-        # quote values and assemble into query string
-        logging.debug("XYXXXXX: %s"%repr(params.items()))
-        ps = "&amp;".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()])
-        url=self.REQUEST['URL1']+"?"+ps
-        return url
+        return self.getLink(param, val, params, baseUrl, '&amp;')
     
     def getInfo_xml(self,url,mode):
@@ -337,4 +444,18 @@
         return pt(docinfo=docinfo)
 
+    def getOptionToggle(self, newState=None, optionName='text_options_open', initialState=True):
+        """returns new option state"""
+        if not self.REQUEST.SESSION.has_key(optionName):
+            # not in session -- initial
+            opt = {'lastState': newState, 'state': initialState}
+        else:
+            opt = self.REQUEST.SESSION.get(optionName)
+            if opt['lastState'] != newState:
+                # state in session has changed -- toggle
+                opt['state'] = not opt['state']
+                opt['lastState'] = newState
+        
+        self.REQUEST.SESSION[optionName] = opt
+        return opt['state']
     
     def isAccessible(self, docinfo):
@@ -348,4 +469,5 @@
             # only local access -- only logged in users
             user = getSecurityManager().getUser()
+            logging.debug("documentViewer (accessOK) user=%s ip=%s"%(user,self.REQUEST.getClientAddr()))
             if user is not None:
                 #print "user: ", user
@@ -354,5 +476,5 @@
                 return False
         
-        logging.debug("documentViewer (accessOK) unknown access type %s"%access)
+        logging.error("documentViewer (accessOK) unknown access type %s"%access)
         return False
     
@@ -388,8 +510,18 @@
         return docinfo
     
-            
-    def getIndexMeta(self, url):
-        """returns dom of index.meta document at url"""
-        dom = None
+    def getIndexMetaPath(self,url):
+        """gib nur den Pfad zurueck"""
+        regexp = re.compile(r".*(experimental|permanent)/(.*)")
+        regpath = regexp.match(url)
+        if (regpath==None):
+            return ""
+        logging.debug("(getDomFromIndexMeta): URLXAXA: %s"%regpath.group(2))            
+        return ("/mpiwg/online/"+regpath.group(1)+"/"+regpath.group(2))
+     
+    
+    
+    def getIndexMetaUrl(self,url):
+        """returns utr  of index.meta document at url"""
+      
         metaUrl = None
         if url.startswith("http://"):
@@ -402,6 +534,13 @@
             if not metaUrl.endswith("index.meta"):
                 metaUrl += "/index.meta"
+        
+        return metaUrl
+    
+    def getDomFromIndexMeta(self, url):
+        """get dom from index meta"""
+        dom = None
+        metaUrl = self.getIndexMetaUrl(url)
                 
-        logging.debug("(getIndexMeta): METAURL: %s"%metaUrl)
+        logging.debug("(getDomFromIndexMeta): METAURL: %s"%metaUrl)
         txt=getHttpData(metaUrl)
         if txt is None:
@@ -443,5 +582,5 @@
             for x in range(cut):
                 path=getParentDir(path)
-            dom = self.getIndexMeta(path)
+            dom = self.getDomFromIndexMeta(path)
        
         acctype = dom.xpath("//access-conditions/access/@type")
@@ -457,5 +596,5 @@
     def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None,cut=0):
         """gets bibliographical info from the index.meta file at path or given by dom"""
-        logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path))
+        #logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path))
         
         if docinfo is None:
@@ -465,7 +604,9 @@
             for x in range(cut):
                 path=getParentDir(path)
-            dom = self.getIndexMeta(path)
-        
-        logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path))
+            dom = self.getDomFromIndexMeta(path)
+        
+        docinfo['indexMetaPath']=self.getIndexMetaPath(path);
+        
+        #logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path))
         # put in all raw bib fields as dict "bib"
         bib = dom.xpath("//bib/*")
@@ -487,4 +628,6 @@
         docinfo['bib_type'] = bibtype
         bibmap=metaData.generateMappingForType(bibtype)
+        #logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap))
+        #logging.debug("documentViewer (getbibinfofromindexmeta) bibtype:"+repr(bibtype))
         # if there is no mapping bibmap is empty (mapping sometimes has empty fields)
         if len(bibmap) > 0 and len(bibmap['author'][0]) > 0:
@@ -498,12 +641,66 @@
                 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0])
             except: pass
-            logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype)
+            #logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype)
             try:
                 docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0])
             except:
                 docinfo['lang']=''
-
+            try:
+                docinfo['city']=getTextFromNode(dom.xpath("//bib/city")[0])
+            except:
+                docinfo['city']=''
+            try:
+                docinfo['number_of_pages']=getTextFromNode(dom.xpath("//bib/number_of_pages")[0])
+            except:
+                docinfo['number_of_pages']=''
+            try:
+                docinfo['series_volume']=getTextFromNode(dom.xpath("//bib/series_volume")[0])
+            except:
+                docinfo['series_volume']=''
+            try:
+                docinfo['number_of_volumes']=getTextFromNode(dom.xpath("//bib/number_of_volumes")[0])
+            except:
+                docinfo['number_of_volumes']=''
+            try:
+                docinfo['translator']=getTextFromNode(dom.xpath("//bib/translator")[0])
+            except:
+                docinfo['translator']=''
+            try:
+                docinfo['edition']=getTextFromNode(dom.xpath("//bib/edition")[0])
+            except:
+                docinfo['edition']=''
+            try:
+                docinfo['series_author']=getTextFromNode(dom.xpath("//bib/series_author")[0])
+            except:
+                docinfo['series_author']=''
+            try:
+                docinfo['publisher']=getTextFromNode(dom.xpath("//bib/publisher")[0])
+            except:
+                docinfo['publisher']=''
+            try:
+                docinfo['series_title']=getTextFromNode(dom.xpath("//bib/series_title")[0])
+            except:
+                docinfo['series_title']=''
+            try:
+                docinfo['isbn_issn']=getTextFromNode(dom.xpath("//bib/isbn_issn")[0])
+            except:
+                docinfo['isbn_issn']=''           
+        #logging.debug("I NEED BIBTEX %s"%docinfo)
         return docinfo
     
+    
+    def getNameFromIndexMeta(self,path,docinfo=None,dom=None,cut=0):
+        """gets name info from the index.meta file at path or given by dom"""
+        if docinfo is None:
+            docinfo = {}
+        
+        if dom is None:
+            for x in range(cut):
+                path=getParentDir(path)
+            dom = self.getDomFromIndexMeta(path)
+
+        docinfo['name']=getTextFromNode(dom.xpath("/resource/name")[0])
+        logging.debug("documentViewer docinfo[name] %s"%docinfo['name'])
+        return docinfo
     
     def getDocinfoFromTextTool(self, url, dom=None, docinfo=None):
@@ -515,5 +712,5 @@
             docinfo['lang'] = '' # default keine Sprache gesetzt
         if dom is None:
-            dom = self.getIndexMeta(url)
+            dom = self.getDomFromIndexMeta(url)
         
         archivePath = None
@@ -581,5 +778,18 @@
             
             docinfo['textURL'] = textUrl
-    
+        
+
+            #TODO: hack-DW for annalen
+            if (textUrl is not None) and (textUrl.startswith("/permanent/einstein/annalen")):
+                textUrl=textUrl.replace("/permanent/einstein/annalen/","/diverse/de/") 
+                splitted=textUrl.split("/fulltext")
+                textUrl=splitted[0]+".xml"
+                textUrlkurz = string.split(textUrl, ".")[0]
+                docinfo['textURLPathkurz'] = textUrlkurz
+                docinfo['textURLPath'] = textUrl
+                logging.debug("hack")
+                logging.debug(textUrl)
+            
+            
         # new style text-url-path
         textUrls = dom.xpath("//texttool/text-url-path")
@@ -587,10 +797,16 @@
             textUrl = getTextFromNode(textUrls[0])
             docinfo['textURLPath'] = textUrl
-            if not docinfo['imagePath']:
+            textUrlkurz = string.split(textUrl, ".")[0]
+            docinfo['textURLPathkurz'] = textUrlkurz
+            #if not docinfo['imagePath']:
                 # text-only, no page images
-                docinfo = self.getNumPages(docinfo)
+                #docinfo = self.getNumTextPages(docinfo)
+                  
          
         presentationUrls = dom.xpath("//texttool/presentation")
         docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom)   # get info von bib tag
+        #docinfo = self.getDownloadfromDocinfoToBibtex(url, docinfo=docinfo, dom=dom)
+        docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom)
+        
         
         if presentationUrls and (len(presentationUrls) > 0): # ueberschreibe diese durch presentation informationen 
@@ -646,4 +862,5 @@
         #path ist the path to the images it assumes that the index.meta file is one level higher.
         docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)
+        #docinfo = self.getDownloadfromDocinfoToBibtex(pathorig,docinfo=docinfo,cut=cut+1)
         docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)
         return docinfo
@@ -671,6 +888,11 @@
             logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode)
             raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode))
-                        
+                
+        # FIXME: fake texturlpath 
+        if not docinfo.has_key('textURLPath'):
+            docinfo['textURLPath'] = None
+        
         logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo)
+        #logging.debug("documentViewer (getdocinfo) docinfo: %s"%)
         self.REQUEST.SESSION['docinfo'] = docinfo
         return docinfo
@@ -680,4 +902,5 @@
         pageinfo = {}
         current = getInt(current)
+    
         pageinfo['current'] = current
         rows = int(rows or self.thumbrows)
@@ -699,12 +922,20 @@
         pageinfo['viewMode'] = viewMode
         pageinfo['tocMode'] = tocMode
-        pageinfo['query'] = self.REQUEST.get('query',' ')
-        pageinfo['queryType'] = self.REQUEST.get('queryType',' ')
+        pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
+        #pageinfo['optionToggle'] = self.REQUEST.get('optionToggle','1')
+        pageinfo['query'] = self.REQUEST.get('query','') 
+        pageinfo['queryType'] = self.REQUEST.get('queryType','')
         pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext')
         pageinfo['textPN'] = self.REQUEST.get('textPN','1')
         pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','')
+        
+        pageinfo ['highlightElementPos'] = self.REQUEST.get('highlightElementPos','')
+        pageinfo ['highlightElement'] = self.REQUEST.get('highlightElement','')
+        
+        pageinfo ['xpointer'] = self.REQUEST.get('xpointer','')
+        
         pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
         pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')
-        pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')
+        pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')     
         toc = int (pageinfo['tocPN'])
         pageinfo['textPages'] =int (toc)
@@ -720,5 +951,6 @@
             pageinfo['tocPN'] = min (tocPages,toc)                    
         pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
-        pageinfo['sn'] =self.REQUEST.get('sn','')
+        #pageinfo['sn'] =self.REQUEST.get('sn','')
+        pageinfo['s'] =self.REQUEST.get('s','')
         return pageinfo
     
Index: version.txt
===================================================================
--- version.txt	(revision 495)
+++ version.txt	(revision 408)
@@ -1,1 +1,1 @@
-DocumentViewer 0.5.1
+DocumentViewer 0.6.0
Index: zpt/addDocumentViewer.zpt
===================================================================
--- zpt/addDocumentViewer.zpt	(revision 87)
+++ zpt/addDocumentViewer.zpt	(revision 87)
@@ -0,0 +1,12 @@
+<h1 tal:replace="structure here/manage_page_header">Header</h1>
+	<h2>Add an Document Viewer</h2>
+		<form action="manage_AddDocumentViewer">
+		<p class="form-label">Id<input name="id"></p>
+		<p class="form-optional">Title<input size="80" name="title"></p>
+		<p class="form-label">Image scaler URL<input size="80" name="imageScalerUrl" value="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?"></p>
+		<p class="form-optional">Text server name<input size="80" name="textServerName" value="mpdl-proto.mpiwg-berlin.mpg.de"></p>
+		
+		<p><input type="submit" value="add"></p>
+		</form>
+			
+<h1 tal:replace="structure here/manage_page_footer">Footer</h1>
Index: zpt/addDocumentViewerTemplate.zpt
===================================================================
--- zpt/addDocumentViewerTemplate.zpt	(revision 23)
+++ zpt/addDocumentViewerTemplate.zpt	(revision 23)
@@ -0,0 +1,8 @@
+<h1 tal:replace="structure here/manage_page_header">Header</h1>
+	<h2>Document Viewer Template</h2>
+    <p>Add DocumentViewer template <code>viewer_main</code>.</p>
+    <form action="manage_addDocumentViewerTemplate">
+    <p><input type="submit" value="add"></p>
+    </form>
+    
+<h1 tal:replace="structure here/manage_page_footer">Footer</h1>
Index: zpt/changeDocumentViewer.zpt
===================================================================
--- zpt/changeDocumentViewer.zpt	(revision 87)
+++ zpt/changeDocumentViewer.zpt	(revision 87)
@@ -0,0 +1,24 @@
+<div tal:replace="structure here/manage_page_header">Header</div>
+<!-- ZOPE management tabs -->
+<h2 tal:define="manage_tabs_message options/manage_tabs_message | nothing"
+    tal:replace="structure here/manage_tabs">Tabs</h2>
+<!-- end of ZOPE management tabs -->
+		<form action="changeDocumentViewer">
+		
+		<p class="form-optional">Title</p>
+        <p class="form-element"><input size="80" tal:attributes="value here/title" name="title"></p>
+        <p class="form-text">The image scaler URL and text server URL have to be configured in the <tt>zogilib</tt> and <tt>fulltextclient</tt>
+        objects in the <tt>template</tt> folder.</p>
+        <p class="form-optional">Thumbnail rows</p>
+        <p class="form-element"><input size="3" tal:attributes="value here/thumbrows | default" name="thumbrows"></p>
+        <p class="form-optional">Thumbnail columns</p>
+        <p class="form-element"><input size="3" tal:attributes="value here/thumbcols | default" name="thumbcols"></p>
+        <p class="form-optional">Authorized groups</p>
+        <p class="form-element"><input size="80" tal:attributes="value python:','.join(getattr(here,'authgroups', []))" name="authgroups"></p>
+        <p class="form-text">Access groups (separated by ',') that are considered local, i.e. when a ressource restricts access
+        to one of these groups, local access to the ressource is granted.</p>
+		
+		<p><input type="submit" value="change"></p>
+		</form>
+			
+<div tal:replace="structure here/manage_page_footer">Footer</div>
Index: zpt/head_main.zpt
===================================================================
--- zpt/head_main.zpt	(revision 122)
+++ zpt/head_main.zpt	(revision 122)
@@ -0,0 +1,6 @@
+<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode python:options.get('viewMode','images')">
+  <span tal:condition="not:exists:docinfo/author">(no bibliographical information)</span>
+  <tal:y tal:condition="exists:docinfo/author">
+    <b tal:content="docinfo/author"/>,<i tal:content="docinfo/title"/><i tal:condition="exists:docinfo/year" tal:content="string:,${docinfo/year}"/>
+  </tal:y>
+</tal:block>
Index: zpt/info_xml.zpt
===================================================================
--- zpt/info_xml.zpt	(revision 58)
+++ zpt/info_xml.zpt	(revision 58)
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<document-parameters xmlns:tal="http://xml.zope.org/namespaces/tal" tal:define="docinfo options/docinfo">
+  <parameter tal:repeat="info docinfo" tal:attributes="name info; value python:docinfo[info]"/>
+</document-parameters>
Index: zpt/page_main_gis.zpt
===================================================================
--- zpt/page_main_gis.zpt	(revision 420)
+++ zpt/page_main_gis.zpt	(revision 420)
@@ -0,0 +1,3 @@
+<tal:block tal:define="pageinfo python:options.get('pageinfo',None); docinfo python:options.get('docinfo',None) ;highlightQuery python:pageinfo.get('highlightQuery','');sn python:pageinfo.get('sn',''); characterNormalization python:pageinfo.get('characterNormalization',''); optionToggle python:pageinfo.get('optionToggle','');">
+  <div tal:content="structure python:pageinfo['textPage']"></div>
+</tal:block>
Index: zpt/page_main_images.zpt
===================================================================
--- zpt/page_main_images.zpt	(revision 122)
+++ zpt/page_main_images.zpt	(revision 122)
@@ -0,0 +1,3 @@
+<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo; mk python:options.get('mk','')">
+ <iframe height="100%" width="100%" tal:attributes="src string:${here/template/zogilib/absolute_url}?fn=${docinfo/imagePath}&pn=${pageinfo/current}&$mk"/>
+</tal:block>
Index: zpt/page_main_pureXml.zpt
===================================================================
--- zpt/page_main_pureXml.zpt	(revision 495)
+++ zpt/page_main_pureXml.zpt	(revision 448)
@@ -1,4 +1,3 @@
-
-<tal:block tal:define="pageinfo python:options.get('pageinfo',None); docinfo python:options.get('docinfo',None)   ">
-  <div tal:content="structure python:here.getTextPage(mode='pureXml',pn=pageinfo['current'],docinfo=docinfo,   pageinfo=pageinfo)"></div>
+<tal:block tal:define="pageinfo python:options.get('pageinfo',None); docinfo python:options.get('docinfo',None) ;highlightQuery python:pageinfo.get('highlightQuery','');s python:pageinfo.get('s','');optionToggle python:pageinfo.get('optionToggle','');  ">
+  <div tal:content="structure python:pageinfo['textPage']"></div>
 </tal:block>
Index: zpt/page_main_text.zpt
===================================================================
--- zpt/page_main_text.zpt	(revision 495)
+++ zpt/page_main_text.zpt	(revision 448)
@@ -1,16 +1,10 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-  <!--  block used for definitions and scripts in head -->
-  <metal:block metal:define-macro="head">
-  </metal:block>
-</head>
-<body>
-  <!-- block used for main content area -->
-  <metal:block metal:define-macro="main" tal:define="pageinfo python:options.get('pageinfo',None); docinfo python:options.get('docinfo',None) ;highlightQuery python:pageinfo.get('highlightQuery','');sn python:pageinfo.get('sn','')">
-    <div tal:content="structure python:here.getTextPage(mode='text',pn=pageinfo['current'],docinfo=docinfo, highlightQuery=highlightQuery, sn=sn, pageinfo=pageinfo)"></div>
-  </metal:block>
-</body>
-</html>
+<tal:block tal:define="pageinfo python:options.get('pageinfo',None); 
+                       docinfo python:options.get('docinfo',None);
+                       highlightQuery python:pageinfo.get('highlightQuery','');
+                       s python:pageinfo.get('s','');
+                       pn python:pageinfo.get('pn',1);
+                       characterNormalization python:pageinfo.get('characterNormalization','');
+                       optionToggle python:pageinfo.get('optionToggle','');">
+  <div tal:content="structure python:pageinfo['textPage']"></div>
+  
+</tal:block>
Index: zpt/page_main_text_dict.zpt
===================================================================
--- zpt/page_main_text_dict.zpt	(revision 495)
+++ zpt/page_main_text_dict.zpt	(revision 422)
@@ -1,16 +1,3 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-  <!--  block used for definitions and scripts in head -->
-  <metal:block metal:define-macro="head">
-  </metal:block>
-</head>
-<body>
-  <!-- block used for main content area -->
-  <metal:block metal:define-macro="main" tal:define="pageinfo options/pageinfo; docinfo options/docinfo; highlightQuery pageinfo/highlightQuery|nothing; sn pageinfo/sn|nothing">
-    <div tal:content="structure python:here.getTextPage(mode='text_dict',pn=pageinfo['current'],docinfo=docinfo,highlightQuery=highlightQuery,sn=sn,pageinfo=pageinfo)"/>
-  </metal:block>
-</body>
-</html>
+<tal:block tal:define="pageinfo python:options.get('pageinfo',None); docinfo python:options.get('docinfo',None) ;highlightQuery python:pageinfo.get('highlightQuery','');sn python:pageinfo.get('sn','');characterNormalization python:pageinfo.get('characterNormalization','');optionToggle python:pageinfo.get('optionToggle','');">
+  <div tal:content="structure python:pageinfo['textPage']"></div>
+</tal:block>
Index: zpt/page_main_xml.zpt
===================================================================
--- zpt/page_main_xml.zpt	(revision 448)
+++ zpt/page_main_xml.zpt	(revision 448)
@@ -0,0 +1,3 @@
+<tal:block tal:define="pageinfo python:options.get('pageinfo',None); docinfo python:options.get('docinfo',None) ;highlightQuery python:pageinfo.get('highlightQuery','');s python:pageinfo.get('s','');optionToggle python:pageinfo.get('optionToggle',''); mode python:pageinfo.get('mode', 'xml') ">
+  <div tal:content="structure python:pageinfo['textPage']"></div>
+</tal:block>
Index: zpt/thumbs_main_rss.zpt
===================================================================
--- zpt/thumbs_main_rss.zpt	(revision 72)
+++ zpt/thumbs_main_rss.zpt	(revision 72)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<rss version="2.0" 
+     xmlns:media="http://search.yahoo.com/mrss"
+     xmlns:tal="http://xml.zope.org/namespaces/tal">
+
+<channel tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode options/viewMode; start pageinfo/start; end pageinfo/end; rows pageinfo/rows; cols pageinfo/cols;  current pageinfo/current; grpsize pageinfo/groupsize; pages docinfo/numPages">
+ 
+    <item tal:repeat="idx python:range(1,pages)">
+      <title tal:content="string:$idx">title</title>
+      <link tal:content="structure python:here.getLinkAmp(param='pn',val=idx)">link</link>
+    
+      <media:thumbnail tal:attributes="url string:${docinfo/imageURL}&amp;pn=$idx&amp;dw=100&amp;dh=100"/>
+      <media:content tal:attributes="url string:${docinfo/imageURL}&amp;pn=$idx&amp;dw=800&amp;dh=800"/>
+
+  </item>
+
+</channel>
+</rss>
Index: zpt/toc_figures.zpt
===================================================================
--- zpt/toc_figures.zpt	(revision 122)
+++ zpt/toc_figures.zpt	(revision 122)
@@ -0,0 +1,14 @@
+<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo;  
+  pn python:int(pageinfo['tocPN']); tocsize python:int(docinfo['tocSize_figures']); grpsize python:int(pageinfo['tocPageSize']);
+  maxpn python:int(tocsize/grpsize);">
+  <div class="thumbruler">
+    <span tal:condition="python:(pn>1)">
+      <a tal:attributes="href python:here.getLink(param='tocPN',val=pn-1)">&lt;</a>
+    </span>
+    <span tal:content="string:$pn of $maxpn"/>
+    <span>
+    <a tal:attributes="href python:here.getLink(param='tocPN',val=pn+1)">&gt;</a>
+  </span>
+</div>
+  <div tal:content="structure python:here.getTocPage(mode='figures',pageinfo=pageinfo,docinfo=docinfo)"/>
+</tal:block>
Index: zpt/toc_text.zpt
===================================================================
--- zpt/toc_text.zpt	(revision 122)
+++ zpt/toc_text.zpt	(revision 122)
@@ -0,0 +1,14 @@
+<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo;  
+  pn python:int(pageinfo['tocPN']); tocsize python:int(docinfo['tocSize_text']); grpsize python:int(pageinfo['tocPageSize']);
+  maxpn python:int(tocsize/grpsize);">
+  <div class="thumbruler">
+    <span tal:condition="python:(pn>1)">
+      <a tal:attributes="href python:here.getLink(param='tocPN',val=pn-1)">&lt;</a>
+    </span>
+    <span tal:content="string:$pn of $tocsize"/>
+    <span>
+    <a tal:attributes="href python:here.getLink(param='tocPN',val=pn+1)">&gt;</a>
+  </span>
+</div>
+  <div tal:content="structure python:here.getTocPage(mode='text',pageinfo=pageinfo,docinfo=docinfo)"/>
+</tal:block>
Index: zpt/toc_thumbs.zpt
===================================================================
--- zpt/toc_thumbs.zpt	(revision 122)
+++ zpt/toc_thumbs.zpt	(revision 122)
@@ -0,0 +1,31 @@
+<div tal:define="docinfo options/docinfo; pageinfo options/pageinfo;  
+  start pageinfo/start; end pageinfo/end; rows pageinfo/rows; cols pageinfo/cols;
+  current pageinfo/current; grpsize pageinfo/groupsize">
+
+<div class="thumbruler">
+  <span tal:condition="python:(start>1)">
+    <a tal:attributes="href python:here.getLink(param='start',val=max(start-grpsize,1))">&lt;</a>
+  </span>
+  <select tal:attributes="onChange python:'location.href=\''+here.getLink(param='start',val=None)+'&start=\'+this.options[this.selectedIndex].value'">
+    <option tal:repeat="grp python:range(pageinfo['numgroups'])" 
+      tal:attributes="selected python:(start==grp*grpsize+1); value python:(grp*grpsize+1)"
+      tal:content="python:(grp*grpsize+1)"/>
+  </select>
+  <span tal:condition="python:(start+grpsize<int(docinfo['numPages']))">
+    <a tal:attributes="href python:here.getLink(param='start',val=start+grpsize)">&gt;</a>
+  </span>
+</div>
+<table>
+  <tr tal:repeat="row python:range(rows)">
+    <tal:block tal:repeat="idx python:range(start+row*cols,start+(row+1)*cols)">
+      <td align="center" tal:condition="python:(idx<=end)"
+		  	tal:attributes="class python:here.getStyle(idx,current,'thumb')">
+		<a tal:attributes="href python:here.getLink(param='pn',val=idx)">
+		  <img class="thumbimg" border="0" tal:attributes="src string:${docinfo/imageURL}&pn=$idx&dw=100&dh=100"/>
+		  <div class="thumbcap" tal:content="idx"/>
+		</a>
+	  </td>
+    </tal:block>
+  </tr>
+</table>
+</div>
Index: zpt/viewer_main.zpt
===================================================================
--- zpt/viewer_main.zpt	(revision 495)
+++ zpt/viewer_main.zpt	(revision 122)
@@ -2,28 +2,26 @@
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
- tal:define="docinfo options/docinfo; pageinfo options/pageinfo; global viewMode pageinfo/viewMode; tocMode pageinfo/tocMode;
- body_onload nothing">
+ tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode; tocMode pageinfo/tocMode">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <link rel="stylesheet" href="template/docuviewer_css" type="text/css">
-  <metal:block metal:use-macro="python:path('here/template/page_main_%s/macros/head'%viewMode)"/>
 </head>
-<body tal:condition="docinfo/numPages" tal:attributes="onload body_onload">
-  <metal:block metal:use-macro="here/template/head_main/macros/main"/>
-  <tal:block tal:condition="python:here.isAccessible(docinfo)">
-  <table border="0" width="100%" height="100%">
-    <tr>
-      <td width="300px" valign="top">
-        <metal:block metal:use-macro="python:path('here/template/toc_%s/macros/main'%tocMode)"/> 
-      </td>
-      <td width="100%" valign="top">
-        <metal:block metal:use-macro="python:path('here/template/page_main_%s/macros/main'%viewMode)"/>
-      </td>
-    </tr>
-  </table>
-  </tal:block>
-  <tal:block tal:condition="not:python:here.isAccessible(docinfo)">
-    <div class="errortext">Sorry, access to this document is restricted.</div>
-  </tal:block>
+<body tal:condition="docinfo/numPages">
+<div tal:replace="structure python:here.template.head_main(docinfo=docinfo,viewMode=viewMode,pageinfo=pageinfo)"/>
+<tal:block tal:condition="python:here.isAccessible(docinfo)">
+<table border="0" width="100%" height="100%">
+  <tr>
+    <td width="300px" valign="top">
+      <tal:block tal:replace="structure python:getattr(here.template, 'toc_%s'%tocMode)(docinfo=docinfo,pageinfo=pageinfo)"/> 
+    </td>
+    <td width="100%" valign="top">
+      <tal:block tal:content="structure python:getattr(here.template, 'page_main_%s'%viewMode)(docinfo=docinfo,pageinfo=pageinfo,mk=options['mk'])"/>
+    </td>
+  </tr>
+</table>
+</tal:block>
+<tal:block tal:condition="not:python:here.isAccessible(docinfo)">
+<div class="errortext">Sorry, access to this document is restricted.</div>
+</tal:block>
 </body>
 <body tal:condition="not:docinfo/numPages">
