//_________________________________________________________________________________________________Menu
var Menu = {
  maxMenuItems:10, height:20, width:120, iHeight:18, iWidth:110, spacing:1, padding:1, iSpacing:1, iPadding:1, distance:-2,
  horizontal:true, speed:120, timeout:4000, gap:1, MENUBAR:1, lastOpened:'',
  animations:new Array(), 
  info:function() { this.timer=0;this.open=0;this.animation=null },
  open:function(divElement) { 
  	var Top
	var Left
	var correction=trueSize(Menu.padding+Menu.spacing*2)
	var mNum=parseInt(divElement.substring(2,divElement.indexOf('o')))	
    if (Menu.animations[divElement]) { 
      if ((Menu.animations[divElement].open==0) && (!Menu.animations[divElement].animation.active)) {
        if (Menu.horizontal) {
          Top=measurements.scrollPos.y+trueSize(Menu.gap+Menu.height)+correction
          Left=measurements.scrollPos.x+parseInt(parseInt(X.N[Menu.MENUBAR].A['POSITION'])*Width()/100)+(mNum*trueSize(Menu.width))+(correction*mNum)
          animation.targets[divElement].path=animation.slideToPath(Left,Top,Left,-200,80,1.3).reverse()
        } else { // vertical
          Top=measurements.scrollPos.y+Menu.gap+parseInt(parseInt(X.N[Menu.MENUBAR].A['POSITION'])*Height()/100)+(trueSize(Menu.height)*(mNum-1))+(correction*mNum)
          Left=measurements.scrollPos.x+trueSize(Menu.width+Menu.gap)+correction
          animation.targets[divElement].path=animation.slideToPath(Left,Top,-400,Top,80,1.3).reverse()
        }
        animation.targets[divElement].statement=''
        animation.targets[divElement].animate(Menu.speed)
        Menu.animations[divElement].open=1
      }
      Menu.touch(divElement)
	  Menu.lastOpened=divElement
	  setTimeout("Menu.close_all()",500)
    } 
  },
  close:function(divElement) { 
  	var Top
	var Left
	var correction=Menu.padding+Menu.spacing*2
	var mNum=parseInt(divElement.substring(2,divElement.indexOf('o')))
    if (Menu.animations[divElement]) {
      if (Menu.animations[divElement].timer) { clearTimeout(Menu.animations[divElement].timer);Menu.animations[divElement].timer=0 }
      if ((Menu.animations[divElement].open) && (!Menu.animations[divElement].animation.active)) {
        if (Menu.horizontal) {
          Top=trueSize(Menu.gap+Menu.height)+correction
          Left=parseInt(parseInt(X.N[Menu.MENUBAR].A['POSITION'])*Width()/100)+(mNum*trueSize(Menu.width))+(correction*mNum)
          animation.targets[divElement].path=animation.slideToPath(Left,Top,Left,-200,80,1.3)
        } else { // vertical
          Top=Menu.gap+parseInt(parseInt(X.N[Menu.MENUBAR].A['POSITION'])*Height()/100)+(trueSize(Menu.height)*(mNum-1))+(correction*mNum)
          Left=trueSize(Menu.width+Menu.gap)+correction
          animation.targets[divElement].path=animation.slideToPath(Left,Top,-400,Top,80,1.3)
        }
        animation.targets[divElement].statement='hide("'+divElement+'")'
        animation.targets[divElement].animate(Menu.speed)
        Menu.animations[divElement].open=0
      }  
    }
  },
  close_all:function() { 
    for (var divE in Menu.animations) if ((divE!=Menu.lastOpened) && (Menu.animations[divE].open==1)) Menu.close(divE) 
  },
  touch:function(divElement) {
    if (Menu.animations[divElement]) {
      if (Menu.animations[divElement].timer) clearTimeout(Menu.animations[divElement].timer)
      Menu.animations[divElement].timer=setTimeout("Menu.close('"+divElement+"')",Menu.timeout)
    }
  },
  click:function(divElement,action) { 
    if (animation.targets[divElement]) Menu.close(divElement)
    switch (action.length) {
      case 2: 
      case 3:
	  case 6:clickLink('CELL',action,'CURRENT');break
      default: if (action.substr(0,11)=='javascript:') eval(action.substr(11))
               else window.top.location=action
    }
  },
  move:function() { 
    if (X.N[Menu.MENUBAR].A['ACTIVE']=='N') return
    var mTop
	var mLeft
	var oTop
	var oLeft
	var correction=trueSize(Menu.padding+Menu.spacing*2)
	var offset
	if (Menu.horizontal) {
	  offset=parseInt(parseInt(X.N[Menu.MENUBAR].A['POSITION'])*Width()/100)
      for (var m=0;m<Menu.maxMenuItems;m++) {
	    mTop=measurements.scrollPos.y+trueSize(Menu.gap)
	    mLeft=measurements.scrollPos.x+offset+(m*trueSize(Menu.width))+(correction*m)
	    move('MM'+m,mLeft,mTop) 
	    move('MM'+m+'o',-400,-400)
	  }
	} else {
	  offset=parseInt(parseInt(X.N[Menu.MENUBAR].A['POSITION'])*Height()/100)
      for (var m=0;m<Menu.maxMenuItems;m++) {
	    mTop=measurements.scrollPos.y+offset+(m*trueSize(Menu.height))+(correction*m)
	    mLeft=measurements.scrollPos.x+trueSize(Menu.gap)
	    move('MM'+m,mLeft,(mTop+(Menu.distance*m)))
	    move('MM'+m+'o',-400,-400)
	  }
	}
  },
  prepare:function() {
    var html 
    for (var m=0;m<Menu.maxMenuItems;m++) html+='<div id=MM'+m+'o style="position:absolute;top:0;left:0"></div><div id=MM'+m+' style="position:absolute;top:0;left:0"></div>'
    document.write(html)  
    for (var mBar in X.N) if (X.N[mBar].T=='MENUBAR') Menu.MENUBAR=mBar
  },  
  build:function() { 
	var mHtml 
	var oHtml
    var count=0
    var aniDiv=new Array()
    var onClick
    var onMouseover
	var optionId
	var Path=new Array()
	var inUse
	if (X.N[Menu.MENUBAR].A['ACTIVE']=='N') {
// Clear other divElements
      for (var dEle=0;dEle<Menu.maxMenuItems;dEle++) redefine('MM'+dEle,"")
	  return
	}
    for (var menu in X.N[Menu.MENUBAR].N) if (menu<=Menu.maxMenuItems) { 
      inUse=menu
      oHtml='<table class=menuoption cellpadding='+trueSize(Menu.iPadding)+' cellspacing='+trueSize(Menu.iSpacing)+'>'
      for (var option in X.N[Menu.MENUBAR].N[menu].N) {
	    optionId='m'+menu+':'+option
        onClick=''
        if (X.N[Menu.MENUBAR].N[menu].N[option].A) 
          if (X.N[Menu.MENUBAR].N[menu].N[option].A['LINK']) onClick='onclick=Menu.click("'+optionId+'","'+X.N[Menu.MENUBAR].N[menu].N[option].A['LINK']+'")'
        oHtml+='\n<tr><td class="off" onMouseOver="this.className=\'on\';Menu.touch(\'MM'+menu+'o\')" onMouseOut=this.className="off" '+onClick+' width='+trueSize(Menu.iWidth)+' height='+trueSize(Menu.iHeight)+'>'+X.N[Menu.MENUBAR].N[menu].N[option].V
        aniDiv['MM'+menu+'o']=1
      }
      oHtml+='</table>'

      onClick=''
      if (aniDiv['MM'+menu+'o']) onClick='onClick=Menu.close(\'MM'+menu+'o\')'      
	  if (X.N[Menu.MENUBAR].N[menu].A!=null) {
        if (X.N[Menu.MENUBAR].N[menu].A['LINK']) onClick='onclick=Menu.click("'+menu+'","'+X.N[Menu.MENUBAR].N[menu].A['LINK']+'")'
	  }
      onMouseover=''
      if (aniDiv['MM'+menu+'o']) onMouseover='Menu.open(\'MM'+menu+'o\')'
      mHtml='<table class=mainmenu cellpadding='+trueSize(Menu.padding)+' cellspacing='+trueSize(Menu.spacing)+'"><tr><td class="off" onMouseOver="this.className=\'on\';'+onMouseover+'" onMouseOut=this.className="off" '+onClick+' width='+trueSize(Menu.width)+' height='+trueSize(Menu.height)+'>'+X.N[Menu.MENUBAR].N[menu].V
		
	  redefine('MM'+menu,mHtml)
      redefine('MM'+menu+'o',oHtml)
// Clear other divElements
      for (var dEle=(inUse+1);dEle<Menu.maxMenuItems;dEle++) redefine('MM'+dEle,"")
    }	
	Menu.animations=new Array()
    for (var A in aniDiv) {
      Menu.animations[A]=new Menu.info()
      Menu.animations[A].animation=new animation.define(A,false,'MOVE')
    }	
  },
  systemMenu:function(cell) {
    var html='<table class=emenu style="background-color:brown" cellspacing=1 cellpadding=2>\
<tr><td class=off onMouseOver=javascript:this.className="on" onMouseOut=javascript:this.className="off" onClick=javascript:paginaEditor.start()>Algemeen\
<tr><td class=off onMouseOver=javascript:this.className="on" onMouseOut=javascript:this.className="off" onClick=javascript:menuEditor.start()>Menu\
<tr><td class=off onMouseOver=javascript:this.className="on" onMouseOut=javascript:this.className="off" onClick=javascript:cellenEditor.start('+cell+')>Cellen\
<tr><td class=off onMouseOver=javascript:this.className="on" onMouseOut=javascript:this.className="off" onClick=javascript:Cms.saveWork()>Publiceren\
<tr><td class=off onMouseOver=javascript:this.className="on" onMouseOut=javascript:this.className="off" onClick=javascript:user_logout()>Afmelden</table>'
    redefine('sysmenu',html)
    move('sysmenu',parseInt(measurements.scrollPos.x+Width()-(Width()/9)),parseInt(measurements.scrollPos.y+10)) 
    show('sysmenu')
    window.status='Celnummer: '+measurements.matrixPos.x+''+measurements.matrixPos.y
  }
}
//_________________________________________________________________________________________________Cms
var Cms = {
  something:null,  
  saveHeader:function() {
    var XML=""
	var http=""+window.top.location
    XML='<CELLSITE '+Cms.attrString(X.A)+'>'+
	  '\n<METATAGS>'+Cms.Resolve(X.N[0])+'\n</METATAGS>'+
	  '\n<MENUBAR '+Cms.attrString(X.N[1].A)+'>'+Cms.Resolve(X.N[1])+'\n</MENUBAR>\n</CELLSITE>'
    document.forms.interface.cmd.value='headerupdate'
    document.forms.interface.content.value=XML
    document.forms.interface.pos.value=global.filenumber
	if (http.search(/\?/)==-1) document.forms.interface.callbackurl.value=http
	else document.forms.interface.callbackurl.value=http.substring(0,http.search(/\?/))
    document.forms.interface.callbackurl.value+='?index='+global.filenumber+'&cell='+measurements.matrixPos.x+measurements.matrixPos.y
    document.forms.interface.submit()
  },
  saveWork:function() {
    var XML=""
	var http=""+window.top.location
	var menuXML=""
    for (var cell in X.N[global.cTag].N) if (X.N[global.cTag].N[cell].T=="CELL") { 
      if (X.N[global.cTag].N[cell].A["HIDDEN"]!="V") { // If a cell is to be removed - do not process it
        XML+="\n<CELL"+Cms.attrString(X.N[global.cTag].N[cell].A)+">"+
          Cms.Resolve(X.N[global.cTag].N[cell])+"\n</CELL>" 
      }
    } 
    for (var cmp in X.N) if (X.N[cmp].T=="MENUBAR") menuXML+="\n<MENUBAR"+Cms.attrString(X.N[cmp].A)+">"+Cms.Resolve(X.N[cmp])+"\n</MENUBAR>" 
    document.forms.interface.cmd.value='cellupdate'
    document.forms.interface.content.value=XML
    document.forms.interface.morecontent.value=menuXML
    document.forms.interface.pos.value=global.filenumber
	if (http.search(/\?/)==-1) document.forms.interface.callbackurl.value=http
	else document.forms.interface.callbackurl.value=http.substring(0,http.search(/\?/))
    document.forms.interface.callbackurl.value+='?index='+global.filenumber+'&cell='+measurements.matrixPos.x+measurements.matrixPos.y
    document.forms.interface.submit()
  },
  attrString:function(Arr) { 
    var attrStr=''
    for (var A in Arr) attrStr+=' '+A+'="'+Arr[A]+'"'
    return attrStr
  },
  hasValue:function(Val) { return (Val)?(Val.replace(/\r\n/g,'¬').replace(/</g,'«').replace(/>/g,'»')):"" },
  startNewline:function(Val) { return (Val)?"":"\n" },
  Resolve:function(Node) {
    var XML=""
    for (var subNode in Node.N)  XML+="\n<"+Node.N[subNode].T+this.attrString(Node.N[subNode].A)+">"+this.hasValue(Node.N[subNode].V)+this.Resolve(Node.N[subNode])+this.startNewline(Node.N[subNode].V)+"</"+Node.N[subNode].T+">"
    return XML
  }  
}
