
// Menu Functions
// Nicola Zordan, Wednesday 21 February 2001
// Nicola Zordan, 12:39 6/13/2002, Validity Dates.

function MenuItem() {
  this.Label='';
  this.URL='';
  this.Icon='';
  this.FromDate=null;
  this.ToDate=null;
  this.SubMenu=null;
//  return (this);
};
MenuItem.prototype = new MenuItem;

function DateYMD(year,month,day) {
var d=new Date(year,month-1,day)
 return(d);
};

function newMenuItem(Label, URL) {
var m = new MenuItem();
  m.Label=Label;
  m.URL=URL;
//alert(m.Label)
  return(m);
};

function newMenuItemIcon(Label, URL, Icon) {
var m = new newMenuItem(Label,URL);
  m.Icon=Icon;
  return(m);
};

function WriteVerticalMenu (menu) {
var m,n;
 for (n in menu) {
  m=menu[n];
//alert(m);
  document.write('<A HREF="'+m.URL+'">');
  if (m.Icon != '') { document.write('<IMG SRC="'+m.Icon+'" alt="'+m.Label+'">'); };
  document.write(m.Label);
  document.write('</A>'+'<br>');
 };
};
function WriteOrizzontalMenu (menu) {
var m,n;
 for (n in menu) {
  m=menu[n];
  document.write('<A HREF="'+m.URL+'">');
  document.write(m.Label);
  document.write('</A>'+' ');
 };
};
function WriteTableMenu (menu) {
var m,n;
 document.write('<TABLE BORDER="0">');
 for (n in menu) {
  m=menu[n];
  document.write('<TR><TD>');
  document.write('<A HREF="'+m.URL+'">');
  document.write(m.Label);
  document.write('</A>'+'');
  document.write('</TD></TR>');
 };
 document.write('</TABLE>');
};

function WriteMenu (menu) {
// WriteVerticalMenu(menu);
// WriteVerticalCustomMenu (menu);
  if (!PDApage) {
    WriteCustomMenu(menu);
    //WriteCustomMenuPDA(menu);
   } else {
    WriteCustomMenuPDA(menu);
  };
};

function Array2MenuItems (menuArray) {
//Array like [['Label','URL'], ['Label','URL'], ... ['Label','URL']]
var n,menu,m;
  menu= new Array();
  for (n in menuArray) {
//    Menu[menu.length]= newMenuItem(menuArray[n][0],menuArray[n][1]);
    m=menuArray[n];
//alert(m[0]);
    menu[menu.length]= newMenuItem(m[0],m[1]);
  };
  return(menu);
};


function Array4MenuItems (menuArray) {
//alert('Array4MenuItems:'+menuArray.length+'\n\n'+menuArray);
//Array like [['Label','URL',fromDate,toDate], ['Label','URL',fromDate,toDate], ... ['Label','URL',fromDate,toDate]]
var n,menu,m,subMenu,url;
  menu= new Array();
  for (n in menuArray) {
//    Menu[menu.length]= newMenuItem(menuArray[n][0],menuArray[n][1]);
    m=menuArray[n];
//alert(m[0]);
    //menu[menu.length]= newMenuItem(m[0],m[1]);
    subMenu=null;
    url=m[1];
    if (typeof(url)==typeof([])) {
//alert('subMenu array\n'+url);
      subMenu=Array4MenuItems(url);
//alert('subMenu menu\n'+subMenu);
      url='subMenu';
    };
    menu[menu.length]= newMenuItem(m[0],url);
//alert(m[0]+'\n'+m.length+'\n'+m[2]+'\n'+m[3]+'\n'+menu[menu.length-1]);
    if (m.length>2) menu[menu.length-1].FromDate=m[2];
    if (m.length>3) menu[menu.length-1].ToDate=m[3];
    menu[menu.length-1].SubMenu=subMenu;
/*
alert(
menu[menu.length-1].Label +'\n'+
menu[menu.length-1].URL +'\n'+
menu[menu.length-1].Icon +'\n'+
menu[menu.length-1].FromDate +'\n'+
menu[menu.length-1].ToDate +'\n'+
menu[menu.length-1].SubMenu
);
*/
  };
//alert('/Array4MenuItems:'+menu.length+'\n\n'+menu);
  return(menu);
};



var CustomMenuItemBefore, CustomMenuItemAfter;
CustomMenuItemBefore='<table><tr><td>';
CustomMenuItemAfter='</td></tr></table>';
CustomMenuItemURL='';
CustomMenuLabelBefore='<b><font 0face="Arial" onMouseOver="this.color=\'red\'" onMouseOut="this.color=\'\'">';
CustomMenuLabelAfter='</b></font>';

var CustomMenuURLBefore, CustomMenuURLAfter;
CustomMenuURLBefore='';
CustomMenuURLAfter='';

CustomMenuSelectColor='yellow';
CustomMenuCurrentColor='cyan';
function WriteVerticalCustomMenu0 (menu) {
var m,n;
 document.write('<table border="0">');
 for (n in menu) {
  m=menu[n];
//alert(m);
  if (m.Label!='') {
   document.write('<tr><td onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" ');
   if (m.URL == GetURLFileName(document.URL)) 
      { document.write(' bgColor="'+CustomMenuCurrentColor+'" onMouseOut="this.bgColor=\''+CustomMenuCurrentColor+'\'" '); }
     else { document.write(' onMouseOut="this.bgColor=\'\'" '); };
   document.write(' >');
//   document.write('<tr><td onMouseOver="this.bgColor=\'yellow\'" onMouseOut="this.bgColor=\'\'">');
   document.write(CustomMenuItemBefore);
   document.write('<A HREF="'+m.URL+'" '+CustomMenuItemURL+'>');
   if (m.Icon != '') { document.write('<IMG SRC="'+m.Icon+'" alt="'+m.Label+'">'); };
   document.write(CustomMenuLabelBefore+m.Label+CustomMenuLabelAfter);
   document.write('</A>'+'<br>');
   document.write(CustomMenuItemAfter);
   document.write('</td></tr>');
   }
   else {
//   document.write('<br>');
   document.write('<tr><td> &nbsp; </td></tr>');
  };
 };
 document.write('</table>');
};

function IsURLThisPage (URL) {
  //alert(URL+'\n'+GetURLFileName(document.URL));
  if (CustomMenuFrame=='') return (URL==GetURLFileName(document.URL));
  return (URL==GetURLFileName(parent.frames[CustomMenuFrame].document.URL));
};

function URLremoveParameters(url) {
var parameter;
var URLFileName=url;
 parameter=URLFileName.lastIndexOf('?');
 if (parameter>0) {
   URLFileName=URLFileName.substring(0,parameter);
   //alert(URLFileName);
 };
 return URLFileName;
};

function GetURLFileName0 (URL) {
//var d,p,u,URLFileName;
var slash;
 if (URL.substring(0,7)=='file://') 
   { slash=URL.lastIndexOf('\\'); }
  else { slash=URL.lastIndexOf('/'); };
// slash=URL.lastIndexOf('/');
 URLFileName=URL.substring(slash + 1,URL.length);
 if (URLFileName=='') URLFileName='index.htm';
 return (URLFileName);
// return URL.substring(slash + 1,URL.length);
};

function GetURLFileName (URL) {
//var d,p,u,URLFileName;
var slash;
 if (URL.substring(0,7)=='file://') 
   { slash=URL.lastIndexOf('\\'); }
  else { slash=URL.lastIndexOf('/'); };
// slash=URL.lastIndexOf('/');
 URLFileName=URL.substring(slash + 1,URL.length);
 URLFileName=URLremoveParameters(URLFileName);
 if (URLFileName=='') URLFileName='index.htm';
 return (URLFileName);
// return URL.substring(slash + 1,URL.length);
};


var CustomMenuSelectColor='yellow';
var CustomMenuNormalBgColor='';
var CustomMenuLabelBefore='<font face="Arial">';
var CustomMenuLabelAfter='</font>';
var CustomMenuAttributes='';
var CustomMenuCornerTL='corner_tl_silver.gif';
//CustomMenuCornerTL='';
CustomMenuCornerTL='';
var CustomMenuCornerTR='corner_tr_silver.gif';
var CustomMenuCornerBR='corner_br_silver.gif';
var CustomMenuCornerBL='corner_bl_silver.gif';
var CustomMenuFixedWidth=true;
var CustomMenuOrizzontal=false;
CustomMenuFixedWidth=false;
//CustomMenuFixedWidth=true;
//CustomMenuOrizzontal=true;
//var CustomMenuOrizzontalText='';
var CustomMenuText='';
//CustomMenuText='Main orizzontal menu';
//CustomMenuText=' ';
var CustomMenuFrame='';
//CustomMenuFrame='page';
var CustomMenuSpacer='MenuSpacer.gif';
//CustomMenuSpacer='';
//CustomMenuSpacer='image';



function ReloadMenu () {
  location.reload();
//  NoBakground() 
};

//div

//var CustomMenuLocalLinkColor='navy';
var CustomMenuExternalLinkColor='gray';
var CustomMenuExternalLinkTarget='_blank';
//var CustomMenuExternalLinkTarget=''; // no external detection
//var CustomMenuExternalLinkTarget='window2';

var CustomMenuSubmenuIdName='subMenu_';
var CustomMenuSubmenuCount=0;
var CustomMenuSubmenuExpandAll=false;
//CustomMenuSubmenuExpandAll=true;

function CustomMenuHTML (CustomMenu) {
var html='',htmlMenu='';
//function WriteCustomMenu (CustomMenu) {
var Today=new Date(), CustomMenuWritten=0;
var ExternalLink=false;
var subMenuId='';
var subMenusOrizzontalHTML=[];
// document.write('<table border="0" cellspacing="0" cellpadding="0">');
 htmlMenu=htmlMenu+'<table 0border=1 border="0" 0cellspacing="2" cellspacing="0" cellpadding="0">';
 if (CustomMenuOrizzontal) { html=html+'<tr> '; };
 for (var i=0; i<CustomMenu.length-1; i++) {
//alert(Today+'\n'+CustomMenu[i].FromDate+'\n'+CustomMenu[i].ToDate);
//alert((CustomMenu[i].FromDate!=null)+'\n'+(CustomMenu[i].FromDate>Today));

  if (CustomMenu[i].FromDate!=null && CustomMenu[i].FromDate>Today) continue;
  if (CustomMenu[i].ToDate!=null && CustomMenu[i].ToDate<Today) continue;
//  if (CustomMenu[i].ToDate!=null && CustomMenu[i].ToDate<(Today+1)) continue;

   if (!CustomMenuOrizzontal) { html=html+'<tr> '; };

//   document.write('<tr><td ');
   html=html+'<td ';

   CustomMenuWritten=CustomMenuWritten+1;
   //ExternalLink=((CustomMenuExternalLinkTarget!='') && (CustomMenu[i].SubMenu==null) && (CustomMenu[i].URL.substring(0,7).toLowerCase()=='http://'));
   ExternalLink=((CustomMenuExternalLinkTarget!='') && (CustomMenu[i].SubMenu==null) && (CustomMenu[i].URL.substring(0,7).toLowerCase()=='http://' || CustomMenu[i].URL.substring(0,8).toLowerCase()=='https://'));

   if (CustomMenu[i].URL!='' && (CustomMenuFixedWidth || CustomMenuCornerTL=='') && (!CustomMenuOrizzontal)) {
    if (IsURLThisPage(CustomMenu[i].URL)) {
      html=html+'onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuCurrentColor+'\'" bgColor="'+CustomMenuCurrentColor+'"'; 
     }
     else {
      html=html+'onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'; 
     };
   };
   if (CustomMenuOrizzontal) { html=html+' valign="bottom" ';};
   html=html+' >';
//   document.write('  valign="center">');

   if ((CustomMenuCornerTL!='' || CustomMenuOrizzontal)  && CustomMenu[i].URL!='') {
    html=html+'<table 0border=1 border="0" cellspacing="0" cellpadding="0" ';
    if (CustomMenuFixedWidth) { html=html+' width="100%" 0height=40 0height="100%" '; };
    if (CustomMenu[i].URL!='') {
      if (IsURLThisPage(CustomMenu[i].URL)) {
       html=html+'onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuCurrentColor+'\'" bgColor="'+CustomMenuCurrentColor+'"'; 
      }
      else {
       html=html+'onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'; 
      };
    };
    if (CustomMenuOrizzontal) { html=html+' 0height=40 ';};
    html=html+' >';

    html=html+'<tr>';
    html=html+'<td valign="top">';
    if (CustomMenuCornerTL!='') {html=html+'<img src="'+CustomMenuCornerTL+'" border="0" align="left" hspace="0" vspace="0">';};
    html=html+'</td>';

    html=html+'<td rowspan="2" 0valign="center" ';
    if (CustomMenuFixedWidth) { html=html+' width="100%" '; };
    if (CustomMenuOrizzontal) { html=html+' height="100%"  '; };
    if (CustomMenuOrizzontal) { html=html+' valign="bottom" ';}
      else {html=html+' valign="center" ';};
    html=html+' >'; 
   };

   if (CustomMenu[i].URL!='') {
     if (CustomMenu[i].SubMenu==null) {
// Hiperlink to the fill width of the background !!!
    html=html+'<table width="100%" cellpadding="0" cellspacing="0"><tr><td>';
    html=html+CustomMenuURLBefore;
    html=html+'<A HREF="'+CustomMenu[i].URL+'" '+CustomMenuAttributes+' ';
    if (CustomMenuFrame!='') {
      //if (CustomMenu[i].URL.substring(0,7)=='http://') { document.write(' target="_top"')}
      if (ExternalLink) { html=html+' target="_top"';}
       else {html=html+' target="'+CustomMenuFrame+'"';};
      html=html+' onClick="ReloadMenu();"';
     } else {
      if (ExternalLink) { 
       //document.write(' target="_blank"')
       html=html+' target="'+CustomMenuExternalLinkTarget+'"';
      };
    };
    html=html+' >';
      } else {
      // subMenu 
     //TODo: SUBMENU
     // define submenuId to use (global counter)
     subMenuId=CustomMenuSubmenuIdName+CustomMenuSubmenuCount;
     CustomMenuSubmenuCount++;
//alert(subMenuId);
     // write name with onclick to hide/show submenuId
     html=html+'<table width="100%" cellpadding="0" cellspacing="0"><tr><td>';
     html=html+CustomMenuURLBefore;
     html=html+'<A HREF="javascript:ShowHideDiv(\''+subMenuId+'\')" '+CustomMenuAttributes+' ';
     html=html+' >';
     };
   };
// Hiperlink to the fill width of the background !!!
   html=html+'<div 0width="100%">';
   if (CustomMenu[i].Icon!='') {
    html=html+'<IMG SRC="'+CustomMenu[i].Icon+'">';
   };
   if (ExternalLink) { 
     html=html+'<font color="'+CustomMenuExternalLinkColor+'">';
   };
   html=html+CustomMenuLabelBefore;
   html=html+CustomMenu[i].Label;
   html=html+CustomMenuLabelAfter;
   if (ExternalLink) { 
     html=html+'</font>';
   };
// Hiperlink to the fill width of the background !!!
   html=html+'</div>';
   if (CustomMenu[i].URL!='') {
    html=html+'</A>';
    html=html+CustomMenuURLAfter;
// Hiperlink to the fill width of the background !!!
    html=html+'</td></tr></table>';
   };
//   document.write('&nbsp;'); 
//   document.write('<br>');

   if ((CustomMenuCornerTL!='' || CustomMenuOrizzontal) && CustomMenu[i].URL!='') {
    html=html+'</td>';
    html=html+'<td valign="top">';
    if (CustomMenuCornerTR!='') {html=html+'<img src="'+CustomMenuCornerTR+'" border="0" align="right" hspace="0" vspace="0">';};
    html=html+'</td>';
 
    html=html+'</tr><tr>';

    html=html+'<td valign="bottom">';
    if (CustomMenuCornerBL!='') {html=html+'<img src="'+CustomMenuCornerBL+'" border="0" align="left" hspace="0" vspace="0">';};
    html=html+'</td>';

    html=html+'<td valign="bottom">';
    if (CustomMenuCornerBR!='') {html=html+'<img src="'+CustomMenuCornerBR+'" border="0" align="right" hspace="0" vspace="0">';};
    html=html+'</td>';

    html=html+'</tr>';

    html=html+'</table>';
   }
   else {
   };




//   document.write('');
//   document.write('</td></tr>');
   html=html+'</td>';

   if (CustomMenuOrizzontal && CustomMenuSpacer!='') {
     html=html+'<td valign="bottom">';
     html=html+'<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
     html=html+'</td>';
     CustomMenuWritten=CustomMenuWritten+1;
   };

   if (!CustomMenuOrizzontal) { 

 if (!CustomMenuOrizzontal && (i==0)) {
   if (CustomMenuText!='') {
//    document.write('<td rowspan="'+CustomMenuWritten+'" bgColor="'+CustomMenuCurrentColor+'"> '); 
    html=html+'<td rowspan="'+(CustomMenu.length*2)+'" bgColor="'+CustomMenuCurrentColor+'"> '; 
    html=html+CustomMenuText+'&nbsp &nbsp &nbsp '; 
    html=html+'<br>'; 
    html=html+'</td> '; 
   };
 };



     html=html+'</tr> '; 

     if (!CustomMenuOrizzontal && CustomMenuSpacer!='') {
      html=html+'<tr>';
      html=html+'<td valign="bottom">';
      html=html+'<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
      html=html+'</tr>';
      CustomMenuWritten=CustomMenuWritten+1;
     };
   };

/* */
    if (CustomMenu[i].SubMenu!=null) {

     var subMenu=CustomMenu[i].SubMenu;
//alert(subMenuType);
     var subMenuHTML=CustomMenuHTML(subMenu);
     var htmlSubMenu='';

    var subMenuVisible='none';
    if (menuIncludeCurrentPage(subMenu) || CustomMenuSubmenuExpandAll) {
      subMenuVisible='inline';
    };

    //html=html+'subemnu here '+i;
    //html=html+'<table cellpadding="0" cellspacing="0">';
    
    //html=html+'<tr>';
    // html=html+'<td valign="bottom">';
    // html=html+'<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
    //html=html+'</td> '; 
    //html=html+'</tr>';

    //html=html+'<tr>';
    //-html=html+'<tr id="'+subMenuId+'" style="display: none;">';
    //-html=html+'<td 0colspan="3" cellspacing=0 cellpadding=0 style="padding-left: 20">';

   if (!CustomMenuOrizzontal) { 
      htmlSubMenu=htmlSubMenu+'<tr id="'+subMenuId+'" style="display: '+subMenuVisible+';">';
      htmlSubMenu=htmlSubMenu+'<td 0colspan="3" cellspacing=0 cellpadding=0 style="padding-left: 20" align="right">';
    } else {
     //htmlSubMenu=htmlSubMenu+'<td id="'+subMenuId+'" style="display: none;">';
     //htmlSubMenu=htmlSubMenu+'<td id="'+subMenuId+'" style="display: '+subMenuVisible+';" 0colspan="3" cellspacing=0 cellpadding=0 style="padding-left: 20">';
     htmlSubMenu=htmlSubMenu+'<tr id="'+subMenuId+'" style="display: '+subMenuVisible+';">';
//alert('menu '+CustomMenu.length+' * 2 = '+(CustomMenu.length*2)+'\n'+CustomMenu);
//alert('<td cellspacing=0 cellpadding=0 colspan="'+(CustomMenu.length*2)+'" style="padding-bottom: 1">');
     htmlSubMenu=htmlSubMenu+'<td cellspacing=0 cellpadding=0 colspan="'+(CustomMenu.length*2)+'" style="padding-bottom: 1">';
     //---htmlSubMenu=htmlSubMenu+'<td cellspacing=0 cellpadding=0 colspan="'+(100)+'" style="padding-bottom: 1">';
     //htmlSubMenu=htmlSubMenu+'<td 0id="'+subMenuId+'" 0style="display: '+subMenuVisible+';" 0colspan="3" cellspacing=0 cellpadding=0 0style="padding-left: 20" colspan="'+(CustomMenu.length*2)+'" style="padding-bottom: 1">';
     //-htmlSubMenu=htmlSubMenu+'<td id="'+subMenuId+'" style="display: '+subMenuVisible+';" 0colspan="3" cellspacing=0 cellpadding=0 0style="padding-left: 20">';
   };

    //html=html+'<tr id="'+subMenuId+'" style="display: none;">';
    //html=html+'<td 0colspan="3" cellspacing=0 cellpadding=0 style="padding-left: 20">';


     // create div for submenuId with style display: none, marginLeft: xx
//alert('writing id: '+subMenuId);
     //-html=html+'<div id="'+subMenuId+'" style="display: none; 0margin-left: 10">';
     // create HTML for submenu inside div submenuId

     htmlSubMenu=htmlSubMenu+subMenuHTML;

     // close div
     //-html=html+'</div>';

   if (!CustomMenuOrizzontal) { 
     htmlSubMenu=htmlSubMenu+'</td>';
     htmlSubMenu=htmlSubMenu+'</tr>';
    } else {
     htmlSubMenu=htmlSubMenu+'</td>';
     //-htmlSubMenu=htmlSubMenu+'</tr>';
     htmlSubMenu=htmlSubMenu+'</tr>';
//alert(htmlSubMenu);
   };
    //html=html+'</table>';

     //html=html+htmlSubMenu;
     if (!CustomMenuOrizzontal) { 
       html=html+htmlSubMenu;
      } else {
       subMenusOrizzontalHTML[subMenusOrizzontalHTML.length]=htmlSubMenu;
     };

   };
/* */


 };


/* */
 if (CustomMenuOrizzontal) { 
   var orizzontalSubMenusHTML=''
   for (var i=subMenusOrizzontalHTML.length-1;i>=0;i--) {
   //for (var i=0;i<subMenusOrizzontalHTML.length;i++) {
     //-orizzontalSubMenusHTML=orizzontalSubMenusHTML+'<tr>'; 
     //-orizzontalSubMenusHTML=orizzontalSubMenusHTML+'<td colspan="'+(CustomMenu.length*2)+'">'; 
     //orizzontalSubMenusHTML=orizzontalSubMenusHTML+'<table border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 1" 0width="1%"><tr><td > '; 
     orizzontalSubMenusHTML=orizzontalSubMenusHTML+subMenusOrizzontalHTML[i];
     //orizzontalSubMenusHTML=orizzontalSubMenusHTML+'</td></tr></table>'; 
     //--orizzontalSubMenusHTML=orizzontalSubMenusHTML+'</td> '; 
     //--orizzontalSubMenusHTML=orizzontalSubMenusHTML+'</tr> '; 
   };
   //html=html+orizzontalSubMenusHTML;
   html=orizzontalSubMenusHTML+html;
   html=html+'<tr style="display: none">';
 };
/* */

 if (CustomMenuOrizzontal) { 
   html=html+'</tr> '; 

   if (CustomMenuText!='') {
    html=html+'<tr> '; 
    html=html+'<td colspan="'+CustomMenuWritten+'" bgColor="'+CustomMenuCurrentColor+'"> '; 
    html=html+CustomMenuText+'&nbsp'; 
    html=html+'<br>'; 
    html=html+'</td> '; 
    html=html+'</tr> '; 
   }
 };
 htmlMenu=htmlMenu+html+'</table>';
 return htmlMenu;
};

function WriteCustomMenu (CustomMenu) {
  document.write(CustomMenuHTML(CustomMenu));
};


function ShowHideDiv (divId) {
//alert(divId);
  var div=document.getElementById(divId);
//alert(divId+'\n'+div);
  var disBefore=div.style.display;
//alert(divId+'\n'+div+'\n'+visBefore);
  var disAfter='none';
  //var visAfter='hidden';
  if (disBefore=='none') {
    disAfter='inline';
    //visAfter='visible';
  };
  div.style.display=disAfter;
  //div.style.visibility=visAfter;
};

function menuIncludeCurrentPage(menu) {
  var includeCurrentPage=false;
    for (var j=0;j<menu.length;j++) {
      includeCurrentPage=IsURLThisPage(menu[j].URL);
      if (includeCurrentPage) break;
      if (menu[j].SubMenu!=null) {
        includeCurrentPage=includeCurrentPage || menuIncludeCurrentPage(menu[j].SubMenu);
        if (includeCurrentPage) break;
      };
    };
  return includeCurrentPage;
};


// --- PDA ---

//var PDApage=false;
function GetPageParameters () {
  var url=document.URL;
  //var url=window.location+'';
  //alert(document.URL+'\n'+window.location);
  var ParametersPassed=(url.indexOf('?')>=0);
  var ParametersJS='';
  var PathParameter='';
  if (ParametersPassed) {
    ParametersJS=url.substring(document.URL.indexOf('?')+1);
    eval(ParametersJS);
  };
};
GetPageParameters();

var PDA, PDApage;
function UsePDAmenu () {
  isPDAbrowser();
  if (PDA==null || PDA==false) {
  //if (PDApage==null || PDApage==false) {
    PDApage=false; 
   } else {
    PDApage=true;
  };
//alert(PDApage);
};
function isPDAbrowser() {
  var pdaBrowser=false;
  var nav=navigator.userAgent;
  var isCE=(nav.indexOf('Windows CE')>=0);
  var isIPhone=(nav.indexOf('iPhone')>=0);
  pdaBrowser=(pdaBrowser || isCE || isIPhone); 
  var isPocketPC=(nav.indexOf('240x320')>=0);
  pdaBrowser=(pdaBrowser || isPocketPC); 
  var isPhone=false;
  if (!isCE && !isPocketPC) {
    var navMmty=navigator.mimeTypes.length;
    //navigator.mimeTypes[i].type == "text/vnd.wap.wml") 
    //alert('['+nav+']\n['+navMmty+']');
    for (var i=0;i<navigator.mimeTypes.length;i++) {
      if (navigator.mimeTypes[i].type.indexOf('text/vnd.wap.wml')>=0) {
         isPhone=true;
         break;
      }; 
    };
  };
  pdaBrowser=(pdaBrowser || isPhone); 
  //pdaBrowser=(isCE || isPocketPC || isPhone);
  if (pdaBrowser) PDA=true;
  //PDA=true; // test
  return PDA;
};
UsePDAmenu();

var CustomMenuPDAsubmenuIndent='&nbsp;&nbsp;';
function customMenuPDAhtmlOptions(menu,levelIn) {
  var level=levelIn;
  if (level==null) level=0;
  var indent='';
  for (var i=0;i<level;i++) {
    indent=indent+CustomMenuPDAsubmenuIndent;
  };
  var options=[];
  var option;
  for (var i=0;i<menu.length-1;i++) {
    option=menu[i];
    if (level>0) option.Label=indent+option.Label;
    //if (option.SubMenu!=null) option.URL='';
    options[options.length]=option;
    if (option.SubMenu!=null) {
      var submenuOptions=customMenuPDAhtmlOptions(option.SubMenu,level+1);
      for (var j=0;j<submenuOptions.length;j++) {
        options[options.length]=submenuOptions[j];
      };
    };
  };
  options[options.length]=null;
  return options;
};


var PDAmenuCounter=0;
var PDAmenuForm='PDApageMenu';
function CustomMenuPDAhtml (CustomMenu,formName,PDApageParameterIn) {
var html='';
//function WriteCustomMenuPDA (CustomMenu,formName,PDApageParameterIn) {
var Today=new Date(), CustomMenuWritten=0;
var ExternalLink=false;
var formname=formName;
var PDApageParameter=PDApageParameterIn;
var pageParameter='';
var labelText='',url;
 if (CustomMenu.length-1<=0) return;
 //WriteHTMLwork();
 if (PDApageParameter==null) {
   //PDApageParameter='?'+'PDApage='+PDApage+';';
   PDApageParameter='?'+'PDA='+PDA+';';
   //PDApageParameter='?'+'PDA='+'true'+';';
 };
 //if (formname==null) formname=PDAmenuForm;
 if (formname==null) formname=PDAmenuForm+PDAmenuCounter++;
 if (formname==null) formname='menu';
 //document.write('<span>');
 //-noform- html=html+'<form name="'+formname+'">';
  html=html+'<form name="'+formname+'">';
 //document.write('<select name="MenuPDA" >');
 //document.write('<select name="MenuPDA" onChange="window.location=this.form.MenuPDA[this.form.MenuPDA.selectedIndex].value">');
 html=html+'<select name="MenuPDA" onChange="PDAmenuGo(this)">';
 html=html+'<option value="" disabled></option>';
 var options=customMenuPDAhtmlOptions(CustomMenu);
 //alert(options.length+'\n'+options);
 var menuI=null;
 for (i=0; i<options.length-1; i++) {  
  menuI=options[i];
  //alert(i+'. ');
  if (menuI==null) {
    //alert(i+'. is null');
    continue;
  };
//alert(i+'.\n'+menuI.Label+'\n'+menuI.URL+'\n'+menuI.SubMenu);
 //for (i=0; i<CustomMenu.length-1; i++) {
 // menuI=CustomMenu[i];
  if (menuI.FromDate!=null && menuI.FromDate>Today) continue;
  if (menuI.ToDate!=null && menuI.ToDate<Today) continue;

  if (menuI.URL=='') continue;
  if (menuI.Label=='') continue;

  url=menuI.URL;
  if (url=='') continue;
  labelText=HTML2Text(menuI.Label);
  if (labelText=='') continue;

  pageParameter='';
  if (PDApage) {
    pageParameter=PDApageParameter;
  };

  //ExternalLink=((CustomMenuExternalLinkTarget!='') && (menuI.URL.substring(0,7).toLowerCase()=='http://'));
  ExternalLink=((CustomMenuExternalLinkTarget!='') && (menuI.URL.substring(0,7).toLowerCase()=='http://' || menuI.URL.substring(0,8).toLowerCase()=='https://'));
  if (!ExternalLink) {
    url=url+pageParameter;
  };

  //document.write('<option value='+url+'>'+name+'</option>');
  html=html+'<option ';

    if (IsURLThisPage(menuI.URL)) {
      html=html+' selected ';
     }
     else {
      //document.write('onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'); 
     };

   if (url=='' || menuI.SubMenu!=null) {
   //if (menuI.URL=='') {
     html=html+' disabled ';
     url='';
   };

   //document.write(' value="'+menuI.URL+'" ');
   //document.write(' value="'+menuI.URL+pageParameter+'" ');
   html=html+' value="'+url+'" ';
   html=html+' >';

   //document.write(menuI.Label);
   html=html+labelText;
   html=html+'</option>';

 };
 html=html+'</select>';
 ///document.write('<input type="button" value="go" onClick="window.location=this.form.MenuPDA[this.form.MenuPDA.selectedIndex].value">');
 //document.write('<input type="button" value="go" onClick="PDAmenuGo(this.form)" >');
 //-noform- html=html+'</form>';
  html=html+'</form>';
 //document.write('</span>');
 return html;
};

function WriteCustomMenuPDA (CustomMenu,formName,PDApageParameterIn) {
  document.write(CustomMenuPDAhtml(CustomMenu,formName,PDApageParameterIn));
};

function PDAmenuGo(list) {
  //alert(f);
  var location=list[list.selectedIndex].value;
  if (location==null || location=='') {
    alert(list[list.selectedIndex].text+'\n\nis a Sub Menu title \nor has no destination');
    return;
  };
  //var ExternalLink=((CustomMenuExternalLinkTarget!='') && (location.substring(0,7).toLowerCase()=='http://'));
  var ExternalLink=((location.substring(0,7).toLowerCase()=='http://'));
  //alert(ExternalLink+'\n'+location);
  if (ExternalLink) {
    window.open(location);
   } else {
    window.location=location;
  };
};

// --- remove images and HTML from menu ---

var MenuHTMLworkId='MenuHTMLworkSpan';
//document.write('[<span style="{visibility: hidden}" id="'+MenuHTMLworkId+'">A</span>]');

function WriteHTMLwork() {
   if (document.all[MenuHTMLworkId]==undefined) {
     //document.write('[<span style="{visibility: hidden}" id="'+MenuHTMLworkId+'">A</span>]');
     //-document.write(' <span style="{visibility: hidden}" id="'+MenuHTMLworkId+'"></span>');
     document.write(' <span style="visibility: hidden" id="'+MenuHTMLworkId+'"></span>');
   };
};

function HTML2Text0(html) {
  var text='';
  document.all[MenuHTMLworkId].innerHTML=html;
  text=document.all[MenuHTMLworkId].innerText;
  //alert('['+html+']\n['+text+']');
  document.all[MenuHTMLworkId].innerHTML='';
  return text;
};

function HTML2Text1(html) {
  var text=html;
  var middleText='';
  var begin=html.indexOf('<');
  var end=html.lastIndexOf('>');
  if (begin>=0 && end>=0) {
    //text=html.substring(0,begin-1)+' '+html.substr(end+1)
    middleText=
    text=html.substring(0,begin-1)+HTML2Text(middleText+html)+text.substr(end+1)
  };
  //document.all[MenuHTMLworkId].innerHTML=html;
  //text=document.all[MenuHTMLworkId].innerText;
  //document.all[MenuHTMLworkId].innerHTML='';
  //alert('['+html+']\n['+text+']');
  return text;
};

function HTML2Text(html) {
  var text=html;
  var begin=text.indexOf('<');
  var end=text.indexOf('>');
  while (begin>=0 && end>=0 && begin<end) {
    text=text.substring(0,begin)+text.substr(end+1);
    //alert('['+html+']\n['+text+']');
    begin=text.indexOf('<');
    end=text.indexOf('>');
  };
  //alert('['+html+']\n['+text+']');
  return text;
};


// -- XML

var MenuXML2HTML='MenuXML2HTML.xsl';
var MenuXML2MenuArray='MenuXML2Array.xsl';
//var linksXML='menuLinks.xml';

function MenuArray4XML(xmlMenuURL) {
  var url=xmlMenuURL;
  var array=[];
  // Get XML
  // Load XML 
  var xml = new ActiveXObject("Microsoft.XMLDOM");
  xml.async = false;
  xml.load(url);
  // Get XSL to transform menuXML in menuArray
  // Load XSL
  var xsl = new ActiveXObject("Microsoft.XMLDOM");
  xsl.async = false;
  xsl.load(MenuXML2MenuArray);
  // Get menu array
  var arrayJS=xml.transformNode(xsl);
  arrayJS='['+arrayJS+'[null,\'\']'+'];';
  array=eval(arrayJS);
  return array;
};

function Menu4XML(xmlMenuURL) {
  var ma=MenuArray4XML(xmlMenuURL)
  var m=Array4MenuItems(ma);
  return m;
};

function Menu4XMLhtml(xmlMenuURL) {
  var m=Menu4XML(xmlMenuURL);
  var html=CustomMenuHTML(m);
  return html;
};

function WriteMenu4XML(xmlMenuURL) {
  var html=Menu4XMLhtml(xmlMenuURL);
  document.write(html);
  return html;
};

function Menu2XML(menu) {
  var mi,xml='',xmlText;
  xml=xml+'<?xml version="1.0" encoding="UTF-8"?>';
  xml=xml+'<?xml-stylesheet type="text/xsl" href="MenuXML2HTML.xsl"?>';
  xml=xml+'<urlset>';
  for (var i=0;i<menu.length;i++) {
    mi=menu[i];
    xml=xml+'<url>';
     xml=xml+'<name>';
      xml=xml+mi.Label;
     xml=xml+'</name>';
     xml=xml+'<loc>';
      xml=xml+mi.URL;
     xml=xml+'</loc>';
    xml=xml+'</url>';
  };
  xml=xml+'</urlset>';
  xmlText=xml;
  return xmlText;
};

function MenuArray2XML(menuArray) {
  var mi,xml='',xmlText;
  xml=xml+'<?xml version="1.0" encoding="UTF-8"?>';
  xml=xml+'<?xml-stylesheet type="text/xsl" href="MenuXML2HTML.xsl"?>';
  xml=xml+'<urlset>';
  for (var i=0;i<menuArray.length;i++) {
    mi=menuArray[i];
    xml=xml+'<url>';
     xml=xml+'<name>';
      xml=xml+mi[0];
     xml=xml+'</name>';
     xml=xml+'<loc>';
      xml=xml+mi[1];
     xml=xml+'</loc>';
    xml=xml+'</url>';
  };
  xml=xml+'</urlset>';
  xmlText=xml;
  return xmlText;
};

function Text2XML(text) {
  var xml = new ActiveXObject("Microsoft.XMLDOM");
  var parseResult=xml.loadXML(text);
  //alert(parseResult);
  //var xmlText=xml.xml;
  //alert(xmlText);
  return xml;
};


