
// 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,formName) {
// WriteVerticalMenu(menu);
// WriteVerticalCustomMenu (menu);
  if (!PDApage) {
    WriteCustomMenu(menu,formName);
    //WriteCustomMenuPDA(menu);
   } else {
    //WriteCustomMenuPDA(menu);
    if (!PDAiPhone) {
      WriteCustomMenuPDA(menu,formName);
     } else {
      WriteCustomMenuPDAiPhone(menu,formName);
    };
  };
};

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];
    if (m==null) continue;
//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';
      //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+='<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+='<tr> '; };

//   document.write('<tr><td ');
   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+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuCurrentColor+'\'" bgColor="'+CustomMenuCurrentColor+'"'; 
     }
     else {
      html+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'; 
     };
   };
   if (CustomMenuOrizzontal) { html+=' valign="bottom" ';};
   html+=' >';
//   document.write('  valign="center">');

   if ((CustomMenuCornerTL!='' || CustomMenuOrizzontal)  && CustomMenu[i].URL!='') {
    html+='<table 0border=1 border="0" cellspacing="0" cellpadding="0" ';
    if (CustomMenuFixedWidth) { html+=' width="100%" 0height=40 0height="100%" '; };
    if (CustomMenu[i].URL!='') {
      if (IsURLThisPage(CustomMenu[i].URL)) {
       html+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuCurrentColor+'\'" bgColor="'+CustomMenuCurrentColor+'"'; 
      }
      else {
       html+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'; 
      };
    };
    if (CustomMenuOrizzontal) { html+=' 0height=40 ';};
    html+=' >';

    html+='<tr>';
    html+='<td valign="top">';
    if (CustomMenuCornerTL!='') {html+='<img src="'+CustomMenuCornerTL+'" border="0" align="left" hspace="0" vspace="0">';};
    html+='</td>';

    html+='<td rowspan="2" 0valign="center" ';
    if (CustomMenuFixedWidth) { html+=' width="100%" '; };
    if (CustomMenuOrizzontal) { html+=' height="100%"  '; };
    if (CustomMenuOrizzontal) { html+=' valign="bottom" ';}
      else {html+=' valign="center" ';};
    html+=' >'; 
   };

   if (CustomMenu[i].URL!='') {
     if (CustomMenu[i].SubMenu==null) {
// Hiperlink to the fill width of the background !!!
    html+='<table width="100%" cellpadding="0" cellspacing="0"><tr><td>';
    html+=CustomMenuURLBefore;
    html+='<A HREF="'+CustomMenu[i].URL+'" '+CustomMenuAttributes+' ';
    if (CustomMenuFrame!='') {
      //if (CustomMenu[i].URL.substring(0,7)=='http://') { document.write(' target="_top"')}
      if (ExternalLink) { html+=' target="_top"';}
       else {html+=' target="'+CustomMenuFrame+'"';};
      html+=' onClick="ReloadMenu();"';
     } else {
      if (ExternalLink) { 
       //document.write(' target="_blank"')
       html+=' target="'+CustomMenuExternalLinkTarget+'"';
      };
    };
    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+='<table width="100%" cellpadding="0" cellspacing="0"><tr><td>';
     html+=CustomMenuURLBefore;
     html+='<A HREF="javascript:ShowHideDiv(\''+subMenuId+'\')" '+CustomMenuAttributes+' ';
     html+=' >';
     };
   };
// Hiperlink to the fill width of the background !!!
   html+='<div 0width="100%">';
   if (CustomMenu[i].Icon!='') {
    html+='<IMG SRC="'+CustomMenu[i].Icon+'">';
   };
   if (ExternalLink) { 
     html+='<font color="'+CustomMenuExternalLinkColor+'">';
   };
   html+=CustomMenuLabelBefore;
   html+=CustomMenu[i].Label;
   html+=CustomMenuLabelAfter;
   if (ExternalLink) { 
     html+='</font>';
   };
// Hiperlink to the fill width of the background !!!
   html+='</div>';
   if (CustomMenu[i].URL!='') {
    html+='</A>';
    html+=CustomMenuURLAfter;
// Hiperlink to the fill width of the background !!!
    html+='</td></tr></table>';
   };
//   document.write('&nbsp;'); 
//   document.write('<br>');

   if ((CustomMenuCornerTL!='' || CustomMenuOrizzontal) && CustomMenu[i].URL!='') {
    html+='</td>';
    html+='<td valign="top">';
    if (CustomMenuCornerTR!='') {html+='<img src="'+CustomMenuCornerTR+'" border="0" align="right" hspace="0" vspace="0">';};
    html+='</td>';
 
    html+='</tr><tr>';

    html+='<td valign="bottom">';
    if (CustomMenuCornerBL!='') {html+='<img src="'+CustomMenuCornerBL+'" border="0" align="left" hspace="0" vspace="0">';};
    html+='</td>';

    html+='<td valign="bottom">';
    if (CustomMenuCornerBR!='') {html+='<img src="'+CustomMenuCornerBR+'" border="0" align="right" hspace="0" vspace="0">';};
    html+='</td>';

    html+='</tr>';

    html+='</table>';
   }
   else {
   };




//   document.write('');
//   document.write('</td></tr>');
   html+='</td>';

   if (CustomMenuOrizzontal && CustomMenuSpacer!='') {
     html+='<td valign="bottom">';
     html+='<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
     html+='</td>';
     CustomMenuWritten=CustomMenuWritten+1;
   };

   if (!CustomMenuOrizzontal) { 

 if (!CustomMenuOrizzontal && (i==0)) {
   if (CustomMenuText!='') {
//    document.write('<td rowspan="'+CustomMenuWritten+'" bgColor="'+CustomMenuCurrentColor+'"> '); 
    html+='<td rowspan="'+(CustomMenu.length*2)+'" bgColor="'+CustomMenuCurrentColor+'"> '; 
    html+=CustomMenuText+'&nbsp &nbsp &nbsp '; 
    html+='<br>'; 
    html+='</td> '; 
   };
 };



     html+='</tr> '; 

     if (!CustomMenuOrizzontal && CustomMenuSpacer!='') {
      html+='<tr>';
      html+='<td valign="bottom">';
      html+='<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
      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+='subemnu here '+i;
    //html+='<table cellpadding="0" cellspacing="0">';
    
    //html+='<tr>';
    // html+='<td valign="bottom">';
    // html+='<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
    //html+='</td> '; 
    //html+='</tr>';

    //html+='<tr>';
    //-html+='<tr id="'+subMenuId+'" style="display: none;">';
    //-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+='<tr id="'+subMenuId+'" style="display: none;">';
    //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+='<div id="'+subMenuId+'" style="display: none; 0margin-left: 10">';
     // create HTML for submenu inside div submenuId

     htmlSubMenu=htmlSubMenu+subMenuHTML;

     // close div
     //-html+='</div>';

   if (!CustomMenuOrizzontal) { 
     htmlSubMenu=htmlSubMenu+'</td>';
     htmlSubMenu=htmlSubMenu+'</tr>';
    } else {
     htmlSubMenu=htmlSubMenu+'</td>';
     //-htmlSubMenu=htmlSubMenu+'</tr>';
     htmlSubMenu=htmlSubMenu+'</tr>';
//alert(htmlSubMenu);
   };
    //html+='</table>';

     //html+=htmlSubMenu;
     if (!CustomMenuOrizzontal) { 
       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+=orizzontalSubMenusHTML;
   html=orizzontalSubMenusHTML+html;
   html+='<tr style="display: none">';
 };
/* */

 if (CustomMenuOrizzontal) { 
   html+='</tr> '; 

   if (CustomMenuText!='') {
    html+='<tr> '; 
    html+='<td colspan="'+CustomMenuWritten+'" bgColor="'+CustomMenuCurrentColor+'"> '; 
    html+=CustomMenuText+'&nbsp'; 
    html+='<br>'; 
    html+='</td> '; 
    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();

function isPDAbrowser0() {
  var pdaBrowser=false;
  //var nav=navigator.userAgent;
  //var isCE=(nav.indexOf('Windows CE')>=0);
  //var isIPhone=(nav.indexOf('iPhone')>=0);
  //var isAndroid=(nav.indexOf('Android')>=0);
  var navData=navigator.userAgent;
  var nav=navData.toUpperCase();
  var isCE=(nav.indexOf('WINDOWS CE')>=0);
  var isIPhone=(nav.indexOf('IPHONE')>=0);
  var isAndroid=(nav.indexOf('ANDROID')>=0);
  PDAiPhone=isIPhone;
  PDAandroid=isAndroid;
   PDAiPhone=(isIPhone || isAndroid);
  //PDAiPhone=(isIPhone || PDAiPhone);
  pdaBrowser=(pdaBrowser || isCE || isIPhone || isAndroid); 
  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;
};


var PDA, PDApage, PDAiPhone, PDAandroid;
function UsePDAmenu () {
  isPDAbrowser();
  if (PDA==null || PDA==false) {
  //if (PDApage==null || PDApage==false) {
    PDApage=false; 
   } else {
    PDApage=true;
  };
//alert(PDApage);
};

var NavsPDA=['WINDOWS CE', '240X320','BLACKBERRY', 'SYMBIAN', 'PALM', 'MINIMO', 'PIE'];
var NavsIPhone=['IPHONE', 'IPOD', 'IPAD', 'ANDROID'];
function checkNavigator(checkArray) {
  var result=false;
  if (checkArray==null) return result;
  var navData=navigator.userAgent;
  var nav=navData.toUpperCase();
  var check;
  for (var i=0;i<checkArray.length;i++) {
    check=checkArray[i];
    check=check.toUpperCase();
    result=(nav.indexOf(check)>=0)
    if (result) return result;
  };
  return result
};

function isPDAbrowser() {
  var checkPDA=checkNavigator(NavsPDA);
  var checkIPhone=checkNavigator(NavsIPhone);
  PDAiPhone=checkIPhone;
  PDA=(checkPDA || checkIPhone);
  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 html;
 //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+='<form name="'+formname+'">';
  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+='<select name="MenuPDA" onChange="PDAmenuGo(this)">';
 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+='<option ';

    if (IsURLThisPage(menuI.URL)) {
      html+=' selected ';
     }
     else {
      //document.write('onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'); 
     };

   if (url=='' || menuI.SubMenu!=null) {
   //if (menuI.URL=='') {
     html+=' disabled ';
     url='';
   };

   //document.write(' value="'+menuI.URL+'" ');
   //document.write(' value="'+menuI.URL+pageParameter+'" ');
   html+=' value="'+url+'" ';
   html+=' >';

   //document.write(menuI.Label);
   html+=labelText;
   html+='</option>';

 };
 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+='</form>';
  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;
};

// -- iPhone


//var iPhoneMetaViewport='<meta name="viewport" content="initial-scale=2, user-scalable=no" />';
//var iPhoneMetaViewport='<meta name="viewport" content="initial-scale=1.5, 0user-scalable=no" />';
var iPhoneMetaViewport='<meta name="viewport" content="initial-scale=1, 0user-scalable=no" />';
function iPhoneSpecific () {
  // view port for default zoom and to avoid keeping standard page scaling
  document.write(iPhoneMetaViewport);
  // remove margins to save space on screen, and diplay menus better
  document.body.style.margin=0;
  //document.body.class='bodyNZiPhone';
  // scroll down after url, to show page, and not waste space on url
  window.scrollTo(0, 1); 
  // hide logo to save space on screen
  var logo=document.getElementById('Logo');
  if (logo!=null) logo.style.display='none';
};


function WriteCustomMenuPDAiPhone (CustomMenu,formName,PDApageParameterIn) {
 var formname=formName;
 if (formname==null && PDAmenuCounter<PDAiPhoneMenus.length) formname=PDAiPhoneMenus[PDAmenuCounter++];
 if (formname==null) formname=PDAiPhoneMenu+PDAmenuCounter++;
 if (formname==null) formname='menu';

 //alert(CustomMenu.length);
 //if (CustomMenu==null || CustomMenu.length<1) return;

  var buttonHTML=CustomMenuPDAiPhoneHtml(CustomMenu,formname,PDApageParameterIn);
//alert(buttonHTML);
  var htmlMenu=CustomMenuiPhoneHtml(CustomMenu,formname,PDApageParameterIn);

  var div=document.getElementById('iPhoneMenusContainer');
//alert(div);
  if (div!=null) {
    iPhoneSpecific();
    if (CustomMenu.length<1) return;
    document.write(buttonHTML);
    var menusHTML=div.innerHTML;
    menusHTML+=htmlMenu;
    div.innerHTML=menusHTML;
   } else {
    PDAiPhone=false;
    WriteCustomMenuPDA(CustomMenu,formName,PDApageParameterIn);
  }

};


var PDAiPhoneMenu='Menu';
//var PDAiPhoneMenus=['Top','Selection'];
var PDAiPhoneMenus=['Main','Selection'];
var CustomMenuPDAiPhoneHTMLcontainerDiv='CustomeMenuPDAiPhoneHTML_';
function CustomMenuPDAiPhoneHtml (CustomMenu,formName,PDApageParameterIn) {
 var formname=formName;
 if (formname==null && PDAmenuCounter<PDAiPhoneMenus.length) formname=PDAiPhoneMenus[PDAmenuCounter++];
 if (formname==null) formname=PDAiPhoneMenu+PDAmenuCounter++;
 if (formname==null) formname='menu';
  var html='';
  html+='<input type="button" value="'+formname+'" onClick="ShowiPhoneMenu(\''+formname+'\')" />\n';
  //-htmlMenu=CustomMenuiPhoneHtml(CustomMenu,formname,PDApageParameterIn);
  //-//html+='<div id="'+CustomMenuPDAiPhoneHTMLcontainerDiv+formname+'" style="display:none">'+htmlMenu+'</div>';
  //-html+=htmlMenu;
  return html;
};


function ShowiPhoneMenu (name) {
  //var divContainerId=CustomMenuPDAiPhoneHTMLcontainerDiv+name;
  var divContainerId=CustomMenuiPhoneContainer+name;
  var div=document.getElementById(divContainerId);
  HideMainPage();
  div.style.display='inline';
};

function HideiPhoneMenu (name) {
  //var divContainerId=CustomMenuPDAiPhoneHTMLcontainerDiv+name;
  var divContainerId=CustomMenuiPhoneContainer+name;
  var div=document.getElementById(divContainerId);
  div.style.display='none';
  ShowMainPage();
};


function HideMainPage () {
  var header=document.getElementById('HeaderPageTable');
  var body=document.getElementById('BodyPageTable');
  var footer=document.getElementById('FooterPageTable');
  if (header!=null) header.style.display='none';
  if (body!=null) body.style.display='none';
  if (footer!=null) footer.style.display='none';
}

function ShowMainPage () {
  var header=document.getElementById('HeaderPageTable');
  var body=document.getElementById('BodyPageTable');
  var footer=document.getElementById('FooterPageTable');
  if (header!=null) header.style.display='inline';
  if (body!=null) body.style.display='inline';
  if (footer!=null) footer.style.display='inline';
}

function StyleMainPage (style,value) {
  var header=document.getElementById('HeaderPageTable');
  var body=document.getElementById('BodyPageTable');
  var footer=document.getElementById('FooterPageTable');
  if (header!=null) header.style[style]=value;
  if (body!=null) body.style[style]=value;
  if (footer!=null) footer.style[style]=value;
}



var CustomMenuiPhoneContainer='iPhoneMenuId_';
function CustomMenuiPhoneHtml (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';

//alert(formname)
 //document.write('<span>');
 //-noform- html+='<form name="'+formname+'">';
  html+='<div id="'+CustomMenuiPhoneContainer+formname+'" class="iPhoneNZmenuContainer" >\n';
 //document.write('<select name="MenuPDA" >');
 //document.write('<select name="MenuPDA" onChange="window.location=this.form.MenuPDA[this.form.MenuPDA.selectedIndex].value">');

/*
 html+='<h1 id="pageTitle" class="h1NZiPhone">'+formname+'</h1>\n';
 //html+='<a id="homeButton" class="buttonNZiPhone" href="javascript:backPageNZ()"> < back </a>\n';
 html+='<a id="homeButton" class="buttonNZiPhone" href="javascript:HideiPhoneMenu(\''+formname+'\')"> < back </a>\n';
 //html+='<a class="buttonNZiPhone" 0class="button" href="javascript:showPageNZ(\'searchForm\')">Search</a>\n';
*/

 //html+='<div id="pageTitle" class="h1NZiPhone">';
 html+='<table id="pageTitle" class="h1NZiPhone" 0border="1" cellspacing="0" cellpadding="0" width="100%">';
 html+='<tr><td width="1">';
 html+='<input type="button" onClick="HideiPhoneMenu(\''+formname+'\')" 0class="buttonNZiPhone" value="< back" align="left" />\n';
 html+='</td><td>';
 html+=formname;
 html+='</td><td width="1" style="visibility:hidden">';
 html+='<input type="button" onClick="HideiPhoneMenu(\''+formname+'\')" 0class="buttonNZiPhone" value="< back" align="left" />\n';
 html+='</td></tr>';
 //html+='</div>\n';
 html+='</table>\n';


 html+='<ul id="MenuPDAiPhone'+formname+'" class="iPhoneNZmenu" >\n';
 //-html+='<li class="liiPhoneNZ"><a class="liiPhoneNZ" href="'+url+'" 0href="javascript:showPageNZ('TheBeatles')">'+text+'</a></li>';
 var options=customMenuPDAhtmlOptions(CustomMenu);
 //alert(options.length+'\n'+options);
 var menuI=null;
 var htmle;
 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;
  if (url=='') url='javascript:HideiPhoneMenu(\''+formname+'\')';
  //labelText=HTML2Text(menuI.Label);
  labelText=menuI.Label;
   //labelText=HTML2Text(labelText);
  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;
  };

  htmle='';

  //document.write('<option value='+url+'>'+name+'</option>');
  //-html+='<li class="liiPhoneNZ"><a class="liaiPhoneNZ" href="'+url+'" 0href="javascript:showPageNZ('TheBeatles')">'+text+'</a></li>';
  htmle+='<li class="liiPhoneNZ">';
  htmle+='<a ';

   if (url=='' || menuI.SubMenu!=null) {
   //if (menuI.URL=='') {
     //-html+=' disabled ';
     url='';
   };

   if (url!='') {
    htmle+='href="';

    if (IsURLThisPage(menuI.URL)) {
      //htmle+='javascript:closeMenuNZ()';
      htmle+='javascript:HideiPhoneMenu(\''+formname+'\')';
     }
     else {
      htmle+=url;
      //document.write('onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'); 
     };

    htmle+='" ';

   };

   //document.write(' value="'+menuI.URL+'" ');
   //document.write(' value="'+menuI.URL+pageParameter+'" ');
   //html+=' value="'+url+'" ';
   htmle+=' 0class="aiPhoneNZ" style="text-decoration:none" >';
   htmle+='<div 0class="liaiPhoneNZ" >';
   htmle+=labelText;
   htmle+='</div>';
   htmle+='</a>';
   htmle+='</li>\n';

//alert(htmle);

   html+=htmle;

 };
 html+='</ul>\n';
 ///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+='</form>';
  html+='</div>\n';
 //document.write('</span>');
 return html;
};




// -- 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;
};


// -- jQueryMenu
// use jQuery to draw the menu

function WriteMenuJQ (menu,formName) {
  if (!PDApage) {
    WriteCustomMenuJQ(menu,formName);
   } else {
    if (!PDAiPhone) {
      WriteCustomMenuPDA(menu,formName);
     } else {
      WriteCustomMenuPDAiPhone(menu,formName);
    };
  };
};


function CustomMenuJQhtml (CustomMenu) {
var html='',htmlMenu='';
//function WriteCustomMenu (CustomMenu) {
var Today=new Date(), CustomMenuWritten=0;
var ExternalLink=false;
var subMenuId='';
var subMenusOrizzontalHTML=[];
// Orizzontal: Tab
// Vertical: 
// 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+='<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+='<tr> '; };

//   document.write('<tr><td ');
   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+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuCurrentColor+'\'" bgColor="'+CustomMenuCurrentColor+'"'; 
     }
     else {
      html+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'; 
     };
   };
   if (CustomMenuOrizzontal) { html+=' valign="bottom" ';};
   html+=' >';
//   document.write('  valign="center">');

   if ((CustomMenuCornerTL!='' || CustomMenuOrizzontal)  && CustomMenu[i].URL!='') {
    html+='<table 0border=1 border="0" cellspacing="0" cellpadding="0" ';
    if (CustomMenuFixedWidth) { html+=' width="100%" 0height=40 0height="100%" '; };
    if (CustomMenu[i].URL!='') {
      if (IsURLThisPage(CustomMenu[i].URL)) {
       html+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuCurrentColor+'\'" bgColor="'+CustomMenuCurrentColor+'"'; 
      }
      else {
       html+='onMouseOver="this.bgColor=\''+CustomMenuSelectColor+'\'" onMouseOut="this.bgColor=\''+CustomMenuNormalBgColor+'\'" bgColor="'+CustomMenuNormalBgColor+'"'; 
      };
    };
    if (CustomMenuOrizzontal) { html+=' 0height=40 ';};
    html+=' >';

    html+='<tr>';
    html+='<td valign="top">';
    if (CustomMenuCornerTL!='') {html+='<img src="'+CustomMenuCornerTL+'" border="0" align="left" hspace="0" vspace="0">';};
    html+='</td>';

    html+='<td rowspan="2" 0valign="center" ';
    if (CustomMenuFixedWidth) { html+=' width="100%" '; };
    if (CustomMenuOrizzontal) { html+=' height="100%"  '; };
    if (CustomMenuOrizzontal) { html+=' valign="bottom" ';}
      else {html+=' valign="center" ';};
    html+=' >'; 
   };

   if (CustomMenu[i].URL!='') {
     if (CustomMenu[i].SubMenu==null) {
// Hiperlink to the fill width of the background !!!
    html+='<table width="100%" cellpadding="0" cellspacing="0"><tr><td>';
    html+=CustomMenuURLBefore;
    html+='<A HREF="'+CustomMenu[i].URL+'" '+CustomMenuAttributes+' ';
    if (CustomMenuFrame!='') {
      //if (CustomMenu[i].URL.substring(0,7)=='http://') { document.write(' target="_top"')}
      if (ExternalLink) { html+=' target="_top"';}
       else {html+=' target="'+CustomMenuFrame+'"';};
      html+=' onClick="ReloadMenu();"';
     } else {
      if (ExternalLink) { 
       //document.write(' target="_blank"')
       html+=' target="'+CustomMenuExternalLinkTarget+'"';
      };
    };
    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+='<table width="100%" cellpadding="0" cellspacing="0"><tr><td>';
     html+=CustomMenuURLBefore;
     html+='<A HREF="javascript:ShowHideDiv(\''+subMenuId+'\')" '+CustomMenuAttributes+' ';
     html+=' >';
     };
   };
// Hiperlink to the fill width of the background !!!
   html+='<div 0width="100%">';
   if (CustomMenu[i].Icon!='') {
    html+='<IMG SRC="'+CustomMenu[i].Icon+'">';
   };
   if (ExternalLink) { 
     html+='<font color="'+CustomMenuExternalLinkColor+'">';
   };
   html+=CustomMenuLabelBefore;
   html+=CustomMenu[i].Label;
   html+=CustomMenuLabelAfter;
   if (ExternalLink) { 
     html+='</font>';
   };
// Hiperlink to the fill width of the background !!!
   html+='</div>';
   if (CustomMenu[i].URL!='') {
    html+='</A>';
    html+=CustomMenuURLAfter;
// Hiperlink to the fill width of the background !!!
    html+='</td></tr></table>';
   };
//   document.write('&nbsp;'); 
//   document.write('<br>');

   if ((CustomMenuCornerTL!='' || CustomMenuOrizzontal) && CustomMenu[i].URL!='') {
    html+='</td>';
    html+='<td valign="top">';
    if (CustomMenuCornerTR!='') {html+='<img src="'+CustomMenuCornerTR+'" border="0" align="right" hspace="0" vspace="0">';};
    html+='</td>';
 
    html+='</tr><tr>';

    html+='<td valign="bottom">';
    if (CustomMenuCornerBL!='') {html+='<img src="'+CustomMenuCornerBL+'" border="0" align="left" hspace="0" vspace="0">';};
    html+='</td>';

    html+='<td valign="bottom">';
    if (CustomMenuCornerBR!='') {html+='<img src="'+CustomMenuCornerBR+'" border="0" align="right" hspace="0" vspace="0">';};
    html+='</td>';

    html+='</tr>';

    html+='</table>';
   }
   else {
   };




//   document.write('');
//   document.write('</td></tr>');
   html+='</td>';

   if (CustomMenuOrizzontal && CustomMenuSpacer!='') {
     html+='<td valign="bottom">';
     html+='<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
     html+='</td>';
     CustomMenuWritten=CustomMenuWritten+1;
   };

   if (!CustomMenuOrizzontal) { 

 if (!CustomMenuOrizzontal && (i==0)) {
   if (CustomMenuText!='') {
//    document.write('<td rowspan="'+CustomMenuWritten+'" bgColor="'+CustomMenuCurrentColor+'"> '); 
    html+='<td rowspan="'+(CustomMenu.length*2)+'" bgColor="'+CustomMenuCurrentColor+'"> '; 
    html+=CustomMenuText+'&nbsp &nbsp &nbsp '; 
    html+='<br>'; 
    html+='</td> '; 
   };
 };



     html+='</tr> '; 

     if (!CustomMenuOrizzontal && CustomMenuSpacer!='') {
      html+='<tr>';
      html+='<td valign="bottom">';
      html+='<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
      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+='subemnu here '+i;
    //html+='<table cellpadding="0" cellspacing="0">';
    
    //html+='<tr>';
    // html+='<td valign="bottom">';
    // html+='<img src="'+CustomMenuSpacer+'" border="0" align="left" hspace="0" vspace="0">';
    //html+='</td> '; 
    //html+='</tr>';

    //html+='<tr>';
    //-html+='<tr id="'+subMenuId+'" style="display: none;">';
    //-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+='<tr id="'+subMenuId+'" style="display: none;">';
    //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+='<div id="'+subMenuId+'" style="display: none; 0margin-left: 10">';
     // create HTML for submenu inside div submenuId

     htmlSubMenu=htmlSubMenu+subMenuHTML;

     // close div
     //-html+='</div>';

   if (!CustomMenuOrizzontal) { 
     htmlSubMenu=htmlSubMenu+'</td>';
     htmlSubMenu=htmlSubMenu+'</tr>';
    } else {
     htmlSubMenu=htmlSubMenu+'</td>';
     //-htmlSubMenu=htmlSubMenu+'</tr>';
     htmlSubMenu=htmlSubMenu+'</tr>';
//alert(htmlSubMenu);
   };
    //html+='</table>';

     //html+=htmlSubMenu;
     if (!CustomMenuOrizzontal) { 
       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+=orizzontalSubMenusHTML;
   html=orizzontalSubMenusHTML+html;
   html+='<tr style="display: none">';
 };
/* */

 if (CustomMenuOrizzontal) { 
   html+='</tr> '; 

   if (CustomMenuText!='') {
    html+='<tr> '; 
    html+='<td colspan="'+CustomMenuWritten+'" bgColor="'+CustomMenuCurrentColor+'"> '; 
    html+=CustomMenuText+'&nbsp'; 
    html+='<br>'; 
    html+='</td> '; 
    html+='</tr> '; 
   }
 };
 htmlMenu=htmlMenu+html+'</table>';
 return htmlMenu;
};

function WriteCustomMenuJQ (CustomMenu) {
  document.write(CustomMenuJQhtml(CustomMenu));
};







