// QOmenuIPhone

// ToDo:
//  1. Define where to put menu button (or select for PDA): Header, center
//  2. Define where to put iphone menu container (before header)
//  3. Define main Page areas: iPhoneMenusContainer, Header, TopHint, MenuLeft, Main, Footer
//  4. Define where to activate iPhone or PDA menu

//-- PDA or iPhone

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();


//-- PDA

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+'">';
  //-noFormQO 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)">';
 //QOmenu notDisabled html+='<option value="" disabled></option>';
 html+='<option value="" 0disabled> &nbsp; Menu </option>';
 //var options=customMenuPDAhtmlOptions(CustomMenu);
 var options=CustomMenu;
 //alert(options.length+'\n'+options);
 var menuI=null;
 for (i=0; i<options.length; 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[1]==null || menuI[1]=='') continue;
  if (menuI[0]==null || menuI[0]=='') continue;

  url=menuI[1];
  if (url==null || url=='') continue;
  //=labelText=HTML2Text(menuI.Label);
  labelText=menuI[0];
  if (labelText==null || 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>';
  //-noFormQO html+='</form>';
 //document.write('</span>');
 return html;
};


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;
  };
};


// -- 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';

  var buttonHTML=CustomMenuPDAiPhoneHtml(CustomMenu,formname,PDApageParameterIn);
  var htmlMenu=CustomMenuiPhoneHtml(CustomMenu,formname,PDApageParameterIn);

  var div=document.getElementById('iPhoneMenusContainer');
  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=['Menu'];
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';
  return html;
};


function ShowiPhoneMenu (name) {
  //var divContainerId=CustomMenuPDAiPhoneHTMLcontainerDiv+name;
  var divContainerId=CustomMenuiPhoneContainer+name;
  var div=document.getElementById(divContainerId);
  HideMainPage();
  if (div) div.style.display='inline';
};

function HideiPhoneMenu (name) {
  //var divContainerId=CustomMenuPDAiPhoneHTMLcontainerDiv+name;
  var divContainerId=CustomMenuiPhoneContainer+name;
  var div=document.getElementById(divContainerId);
  if (div) div.style.display='none';
  ShowMainPage();
};


// Page Components
// Header: LogoClient, unnamed QO, Logo
// TopHint: 
// LoadingText
// MenuLeft

// PrintableCommand
// BelowCaption: LogoUser, MenuTop

function HideMainPage () {
  //var header=document.getElementById('Header');
  var header=document.getElementById('TopHintTable');
  var body=document.getElementById('Page');
  //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('Header');
  var header=document.getElementById('TopHintTable');
  var body=document.getElementById('Page');
  //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;
}


//-- HideQOmenu

/*
//var QODivs=['HeaderDiv','MenuLeftDiv','BodyDiv','iPhoneMenuDiv'];
var QODivs=['Header','MenuLeft','PrintableCommand','BelowCaption'];
var PDAhideDivs=['MenuLeft'];
var iPhoneMenuHideDivs['Page'];


function iPhoneMenuShowNZ (menuDivName) {
  var div, divName;
  for (var i=0;i<iPhoneMenuHideDivs.length;i++) {
    divName=iPhoneMenuHideDivs[i];
    div=document.getElementById(divName);
    if (div) div.style.display='none';
  }; 
  divName=menuDivName;
  div=document.getElementById(divName);
  if (div) div.style.display='inline';
};

function iPhoneMenuHideNZ (menuDivName) {
  var div, divName;
  divName=menuDivName;
  div=document.getElementById(divName);
  if (div) div.style.display='none';
  for (var i=0;i<iPhoneMenuHideDivs.length;i++) {
    divName=iPhoneMenuHideDivs[i];
    div=document.getElementById(divName);
    if (div) div.style.display='inline';
  }; 
};

// iPhone menu un DMS_LAYOUT_HEADERTOP component
// iPhone menu un DMS_LAYOUT_TOPHINT component
*/



//-- menuIPhone

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);
 var options=CustomMenu;
 //alert(options.length+'\n'+options);
 var menuI=null;
 var htmle;
 for (i=0; i<options.length; 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[1]==null || menuI[1]=='') continue;
  if (menuI[0]==null || menuI[0]=='') continue;

  url=menuI[1];
  if (url==null || url=='') continue;
  //labelText=HTML2Text(menuI.Label);
  labelText=menuI[0];
   //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!='') {
    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;
};


var iPhoneMenuButtonsDivId='iPhoneMenuButtonDiv';
function SetupCustomMenuPDAiPhone (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 buttonHTML=CustomMenuPDAiPhoneHtml(CustomMenu,formname,PDApageParameterIn);
  var htmlMenu=CustomMenuiPhoneHtml(CustomMenu,formname,PDApageParameterIn);

  var div=document.getElementById('iPhoneMenusContainer');
  if (div!=null) {
    iPhoneSpecific();
    if (CustomMenu.length<1) return;
    //document.write(buttonHTML);
    var menusHTML=div.innerHTML;
    menusHTML+=htmlMenu;
    div.innerHTML=menusHTML;
    var divButtons=document.getElementById(iPhoneMenuButtonsDivId);
    var buttonsHTML=divButtons.innerHTML;
    buttonsHTML+=buttonHTML;
    divButtons.innerHTML=buttonsHTML;
   } else {
    PDAiPhone=false;
    WriteCustomMenuPDA(CustomMenu,formName,PDApageParameterIn);
  }

};




//-- DMS QO Menu


var iPhoneMenuButtonDivId='iPhoneMenuButtonDiv';
var iPhoneMenuDivId='iPhoneMenuDiv';
function QOiPhoneMenuSetup () {
 if (!PDAiPhone) return;
 //WriteCustomMenuPDAiPhone(QOmenu);
 SetupCustomMenuPDAiPhone(QOmenu);
 var divMenuLeft=document.getElementById('MenuLeft');
 if (divMenuLeft) divMenuLeft.style.display='none';
 return;
 
 var menuButtonDiv=document.getElementById(iPhoneMenuButtonDivId);
 var menuDiv=document.getElementById(iPhoneMenuDivId);
 var htmlButton=CustomMenuPDAiPhoneHtml(QOmenu)
 var htmlMenu=CustomMenuiPhoneHtml(QOmenu);
 if (menuButtonDiv) menuButtonDiv.innerHTML=htmlButton;
 if (menuDiv) menuDiv.innerHTML=htmlMenu;
};

function QOpdaMenuSetup () {
 if (!PDA) return;
 var menuButtonDiv=document.getElementById(iPhoneMenuButtonDivId);
 //var menuDiv=document.getElementById(iPhoneMenuDivId);
 //var htmlButton=CustomMenuPDAhtml(QOmenu)
 var htmlMenu=CustomMenuPDAhtml(QOmenu);
//alert(htmlMenu);
 if (menuButtonDiv) menuButtonDiv.innerHTML=htmlMenu;
 //if (menuDiv) menuDiv.innerHTML=htmlMenu;
 var divMenuLeft=document.getElementById('MenuLeft');
 if (divMenuLeft) divMenuLeft.style.display='none';
};

function SetupMenu4PDAiPhone () {
  if (PDAiPhone) {
    QOiPhoneMenuSetup();
   } else if (PDA) {
    QOpdaMenuSetup();
   } else {
    //nothing
  };
};


//-- execute

//PDAiPhone=true;
//PDA=true;
SetupMenu4PDAiPhone();





