// ------------------------------------------------------------------------------------------
// De Kommunale Nøgletal - Initialiseringer og funktioner til udvælgelsessiden
// ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
// Faste initialiseringer
// ------------------------------------------------------------------------------------------

   var iXvsMax     = [1,2,3];

   var i = 0;
   var j = 0;
   var k = 0;

   var ntCntKom  = 0;
   var ntCntAmt  = 0;
   var ntCntNog  = 0;
   var ntCntAar  = 0;
   var ntCntTot  = 0;
   var ntCntOld  = 0;
   var ntCntMaxHtml = 20000;
   var ntCntMaxSave = 250000;
   var ntCntMax     = ntCntMaxHtml;

   var ntMaxKomTop = 400;
   var ntMaxKom    = 0;
   var ntMaxKom2   = 0;
   var ntMaxNogTop = 400;
   var ntMaxNog    = 0;
   var ntMaxNog2   = 0;

   var ntBegAar    = 1993;
   var ntSenAar    = 0;
   var ntSeneste5  = 0;

   var ntPreKom    = "x";
   var ntPreKomNr  = 0;
   var ntPreKomNrCnt = 0;
   var ntPreKomNrValue = 0;

   var ntPreNog    = "x";
   var ntPreNogNr  = 0;

   var ntUdvIndex       = 0;
   var ntUdvBasis       = 0;
   var ntUdvBasisIndex  = 0;
   var ntSortIndex      = 0;
   var ntSortBasis      = 0;
   var ntSortBasisIndex = 0;
   var ntPrisIndex      = 0;
   var ntPrisBasis      = 0;
   var ntPrisBasisIndex = 0;
   var ntSaveAs         = 0;

   var ntListKom  = "";
   var ntListNog  = "";
   var ntListAar  = "";
   var ntListSpec = "";

   var ntInfoUdv     = "";
   var ntInfoSort    = "";
   var ntInfoPris    = "";
   var ntInfoPeri    = "";
   var ntInfoPeriCnt = 0;
   var ntInfoSpec    = "";
   var ntInfoSpecCnt = 0;
   var ntInfoStatus  = "0 x 0 x 0 = 0 (max "+ntCntMax+")";

   var ntHighl_kom   = 0;
   var ntSelKomFirst = 0;
   var ntSelNogFirst = 0;

   var ntKomIndex    = new Array(ntMaxKomTop);
   var ntKomIndexInv = new Array(ntMaxKomTop);

   var ntNogIndex    = new Array(ntMaxNogTop);
   var ntNogIndexInv = new Array(ntMaxNogTop);

// ------------------------------------------------------------------------------------------
   function nwInit() {
// ------------------------------------------------------------------------------------------

     ntPreNogNr  = 0;
     ntMaxKom     = document.ntForm.ntSelKomMan.length;
     ntMaxKomPre  = document.ntForm.ntSelKomPre.length;
     ntMaxNog     = document.ntForm.ntSelNogMan.length;
     ntMaxNogPre  = document.ntForm.ntSelNogPre.length;
     ntMaxKomHigh = document.ntForm.ntSelKomHigh.length;

     k=0;
     for ( j=0; j<ntMaxKom; j++ ) {
       if ( document.ntForm.ntSelKomMan.options[j].value > -1 ) {
         k=k+1;
         ntKomIndex[k] = j;
         ntKomIndexInv[j] = k;
         ntMaxKom2=ntMaxKom2+1;
       }
     }

     k=0;
     for ( j=0; j<ntMaxNog; j++ ) {
       if ( document.ntForm.ntSelNogMan.options[j].value > -1 ) {
         k=k+1;
         ntNogIndex[k] = j;
         ntNogIndexInv[j] = k;
         ntMaxNog2=ntMaxNog2+1;
       }
     }

//   nwMark1(0,0);
//   nwMark1(1,0);
//   nwMark2(0,0);
//   nwMark2(1,0);
/*
     ntSelKomFirst = 0;
     for ( i=ntMaxKom-1; i>=0; i-- ) {
       if ( document.ntForm.ntSelKomMan.options[i].value > 0 &&
         document.ntForm.ntSelKomMan.options[i].selected )
         ntSelKomFirst = i;
     }
     if ( ntSelKomFirst > 0 ) {
       document.ntForm.ntSelKomMan.selectedIndex = ntSelKomFirst;
     }

     ntSelNogFirst = 0;
     for ( i=ntMaxNog-1; i>=0; i-- ) {
       if ( document.ntForm.ntSelNogMan.options[i].value > 0 &&
         document.ntForm.ntSelNogMan.options[i].selected )
         ntSelNogFirst = i;
     }
     if ( ntSelNogFirst > 0 ) {
       document.ntForm.ntSelNogMan.selectedIndex = ntSelNogFirst;
     }
*/
     nwMark3(0,0);
     nwStatus(1);
     nwMark3(3,1);
     nwMark3(5,1);
     nwMark3(7,1);
     nwMark3(9,1);

     // Initialiser eventuelle URL-overførte markeringer af kommuner, nøgletal og præsentation
//   nwInitFromUrl();
   }

// ------------------------------------------------------------------------------------------
   function nwDoWithMarked(pAction) {
// ------------------------------------------------------------------------------------------

//   var nwUrl      = "http://www.salsaloca.dk/im/nwIndex06B.html#Xbbd59FYbbb43FZbbjkooCopFF";
     var nwUrl      = "http://www.noegletal.dk/nwIndex06B.html#Xbbd59FYbbb43FZbbjkooCopFF";
     var nwUrlTitle = "De Kommunale Nøgletal - "+ntCntKom+"x"+ntCntNog+"x"+ntCntAar;

     if ( pAction == 0 ) {
       if ( navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4 ) {
         window.external.AddFavorite(nwUrl,nwUrlTitle);
       }
       else {
         var msg = "Don't forget to bookmark us!";
         if ( navigator.appName == "Netscape" ) msg = msg+" (CTRL-D)";
         alert(msg);
       }
     }
     else if ( pAction == 1 ) {
       var nwEmailEmne = "Et link til De Kommunale Nøgletal";
       var nwLineBreak = String.fromCharCode(10)+String.fromCharCode(13);
       var nwLineBreak = " %A0%B0 ";
       alert(nwLineBreak);
//  zz var nwEmailMsg  = "Til ... \n\nDu er blevet betænkt med et særligt link til Økonomi- og Indenrigsministeriets Kommunale Nøgletal: \n\n"+nwUrl;
//     var nwEmailMsg  = "xTil ... '%0D' '%0D' Du er blevet betænkt med et særligt link til Økonomi- og Indenrigsministeriets Kommunale Nøgletal: '%0D' '%0D' "+nwUrl;
//     var nwEmailMsg  = "zTil ..."+nwLineBreak+"Du er blevet betænkt med et særligt link til Økonomi- og Indenrigsministeriets Kommunale Nøgletal: "+nwLineBreak+" "+nwUrl;
       var nwEmailMsg  = "yTil ..."+nwLineBreak+"Du er blevet betænkt med et særligt link til Økonomi- og Indenrigsministeriets Kommunale Nøgletal:"+nwLineBreak+nwUrl;

       window.location.href = "mailto:"+"?subject="+nwEmailEmne+"&body="+escape(nwEmailMsg)
     }
   }

// ------------------------------------------------------------------------------------------
   function nwMark1(pManu,pStatus) {
// ------------------------------------------------------------------------------------------

     if ( !pManu ) {

       ntPreKomNr = document.ntForm.ntSelKomPre.options[document.ntForm.ntSelKomPre.selectedIndex].value;
       if ( ntPreKomNr > 0 ) {

         for ( i=ntMaxKom-1; i>=0; i-- ) {
           for ( j=0; j<ntPreKomMax; j++ ) {

             if ( ntPreKomArr[j][0] == ntPreKomNr ) {
               if ( ntPreKomArr[j][2].indexOf(','+document.ntForm.ntSelKomMan.options[i].value+',') > -1 ) {
                 document.ntForm.ntSelKomMan.options[i].selected = true;
               }
               else {
                 document.ntForm.ntSelKomMan.options[i].selected = false;
               }
             }
           }
         }
       }
       else {
         document.ntForm.ntSelKomPre.selectedIndex = 0;
       }

       document.ntForm.ntSelKomMan.options[0].selected = !document.ntForm.ntSelKomMan.options[0].selected;
       document.ntForm.ntSelKomMan.options[0].selected = !document.ntForm.ntSelKomMan.options[0].selected;
       document.ntForm.ntSelKomMan.focus();
     }

     else {
       for ( i=ntMaxKom-1; i>=0; i-- ) {
         if ( document.ntForm.ntSelKomMan.options[i].value < 1 &&
           document.ntForm.ntSelKomMan.options[i].selected ) {
           document.ntForm.ntSelKomMan.options[i].selected = false;
         }
       }
       ntPreKomNr = 0;
       document.ntForm.ntSelKomPre.options[0].selected = true;
     }

     nwStatus(pStatus);
   }

// ------------------------------------------------------------------------------------------
   function nwMark2(pManu,pStatus) {
// ------------------------------------------------------------------------------------------

     if ( !pManu ) {

       ntPreNogNr = document.ntForm.ntSelNogPre.options[document.ntForm.ntSelNogPre.selectedIndex].value;
       if ( ntPreNogNr > 0 ) {

         for ( i=ntMaxNog-1; i>=0; i-- ) {

           for ( j=0; j<ntPreNogMax; j++ ) {

             if ( ntPreNogArr[j][0] == ntPreNogNr ) {
               if ( ntPreNogNr == 960 && document.ntForm.ntSelNogMan.options[i].value > 0 ||
                 ntPreNogArr[j][1].indexOf(','+document.ntForm.ntSelNogMan.options[i].value+',') > -1 ) {
                 document.ntForm.ntSelNogMan.options[i].selected = true;
               }
               else {
                 document.ntForm.ntSelNogMan.options[i].selected = false;
               }
             }
           }
         }
       }
       else {
         document.ntForm.ntSelNogPre.selectedIndex = 0;
       }

       document.ntForm.ntSelNogMan.options[0].selected = !document.ntForm.ntSelNogMan.options[0].selected;
       document.ntForm.ntSelNogMan.options[0].selected = !document.ntForm.ntSelNogMan.options[0].selected;
       document.ntForm.ntSelNogMan.focus();
     }

     else {
       for ( i=ntMaxNog-1; i>=0; i-- ) {
         if ( document.ntForm.ntSelNogMan.options[i].value < 1 &&
           document.ntForm.ntSelNogMan.options[i].selected ) {
           document.ntForm.ntSelNogMan.options[i].selected = false;
         }
       }
       ntPreNogNr = 0;
       document.ntForm.ntSelNogPre.options[0].selected = true;
     }

     nwStatus(pStatus);
   }

// ------------------------------------------------------------------------------------------
   function nwMark3(pSpec,pStatus) {
// ------------------------------------------------------------------------------------------

     ntUdvBasis       = document.ntForm.ntUdvBasis.options[document.ntForm.ntUdvBasis.selectedIndex].value;
     ntUdvBasisIndex  = ntUdvBasis-ntBegAar;
     ntUdvIndex       = document.ntForm.ntUdv.selectedIndex;

     ntSortBasis      = document.ntForm.ntSortBasis.options[document.ntForm.ntSortBasis.selectedIndex].value;
     ntSortBasisIndex = ntSortBasis-ntBegAar;
     ntSortIndex      = document.ntForm.ntSort.selectedIndex;

     if ( ntUdvik ) {
       ntPrisBasis      = document.ntForm.ntPrisBasis.options[document.ntForm.ntPrisBasis.selectedIndex].value;
       ntPrisBasisIndex = ntPrisBasis-ntBegAar;
       ntPrisIndex      = document.ntForm.ntPris.selectedIndex;
     }

     nwCnt("Aar");

     if ( pSpec == 1 || pSpec == 0 ) {

       if ( ntUdvIndex == 0 ) {
         document.ntForm.ntUdvBasis.disabled = true;
         document.ntForm.ntUdvBasis.selectedIndex = 0;

         for ( i=0; i<ntMaxAar; i++ ) {
//         alert('zzz nwMark3a: '+i);
           if ( ntUdvik ) {
             if ( ( document.ntForm.ntSort.options[0].selected || i != ntSortBasisIndex ) &&
                  ( document.ntForm.ntPris.options[0].selected || i != ntPrisBasisIndex ) )
               document.ntForm.ntPeri[i].disabled = false;
           }
           else {
             if ( document.ntForm.ntSort.options[0].selected || i != ntSortBasisIndex )
               document.ntForm.ntPeri[i].disabled = false;
           }
         }
       }
       else {
         document.ntForm.ntUdvBasis.disabled = false;

         for ( i=0; i<ntMaxAar; i++ ) {
//         alert('zzz nwMark3b: '+i);
           if ( ntUdvBasis != 0 && i == ntUdvBasisIndex ) {
             document.ntForm.ntPeri[i].disabled = true;
           }
         }
       }
     }

     else if ( pSpec == 2 || pSpec == 0 ) {

       for ( i=0; i<ntMaxAar; i++ ) {
//       alert('zzz nwMark3c: '+i);
         if ( ntUdvBasis == 0 || i != ntUdvBasisIndex ) {
           if ( ntUdvik ) {
             if ( ( document.ntForm.ntSort.options[0].selected || i != ntSortBasisIndex ) &&
                  ( document.ntForm.ntPris.options[0].selected || i != ntPrisBasisIndex ) )
               document.ntForm.ntPeri[i].disabled = false;
           }
           else {
             if ( document.ntForm.ntSort.options[0].selected || i != ntSortBasisIndex )
               document.ntForm.ntPeri[i].disabled = false;
           }
         }
         else if ( document.ntForm.ntPeri[i].checked ) {
           document.ntForm.ntPeri[ntUdvBasisIndex].disabled = true;
         }
       }
       nwTestFravalgt("Udv");
     }

     else if ( pSpec == 3 || pSpec == 0 ) {

       if ( ntSortIndex == 0) {
         document.ntForm.ntSortBasis.disabled = true;
         document.ntForm.ntSortBasis.selectedIndex = 0;

         if ( document.ntForm.ntSelKomHigh.options[0].selected ) {
           document.ntForm.ntKommuneInddel.disabled = false;
           document.ntForm.ntKunGennemsnit.disabled = false;
         }

         for ( i=0; i<ntMaxAar; i++ ) {
//         alert('zzz nwMark3d: '+i);
           if ( ntUdvik ) {
             if ( ( document.ntForm.ntUdv.options[0].selected || i != ntUdvBasisIndex ) &&
                  ( document.ntForm.ntPris.options[0].selected || i != ntPrisBasisIndex ) )
               document.ntForm.ntPeri[i].disabled = false;
           }
           else {
             if ( document.ntForm.ntUdv.options[0].selected || i != ntUdvBasisIndex )
               document.ntForm.ntPeri[i].disabled = false;
           }
         }
       }

       else {
         document.ntForm.ntSortBasis.disabled = false;

         for ( i=0; i<ntMaxAar; i++ ) {
//         alert('zzz nwMark3e: '+i);
           if ( ntSortBasis != 0 && i == ntSortBasisIndex ) {
             document.ntForm.ntPeri[i].disabled = true;
           }
         }

         if ( !document.ntForm.ntKommuneInddel.checked ) {
           document.ntForm.ntKommuneInddel.disabled = true;
         }
         else {
           document.ntForm.ntSort.selectedIndex = 0;
           document.ntForm.ntSortBasis.selectedIndex = 0;
           document.ntForm.ntSortBasis.disabled = true;
           alert("Du kan ikke få kommuneinddelte oplysninger sorteret");
           return;
         }

         if ( !document.ntForm.ntKunGennemsnit.checked ) {
           document.ntForm.ntKunGennemsnit.disabled = true;
         }
         else {
           document.ntForm.ntSort.selectedIndex = 0;
           document.ntForm.ntSortBasis.selectedIndex = 0;
           document.ntForm.ntSortBasis.disabled = true;
           alert("Du kan ikke vælge alene gennemsnit og at få oplysningerne sorteret");
           return;
         }

       }

     }
     else if ( pSpec == 4 || pSpec == 0 ) {

       for ( i=0; i<ntMaxAar; i++ ) {
//       alert('zzz nwMark3f: '+i);
         if ( ntSortBasis == 0 || i != ntSortBasisIndex ) {
           if ( ntUdvik ) {
             if ( ( document.ntForm.ntUdv.options[0].selected || i != ntUdvBasisIndex ) &&
                  ( document.ntForm.ntPris.options[0].selected || i != ntPrisBasisIndex ) )
               document.ntForm.ntPeri[i].disabled = false;
           }
           else {
             if ( document.ntForm.ntUdv.options[0].selected || i != ntUdvBasisIndex )
               document.ntForm.ntPeri[i].disabled = false;
           }
         }
         else if ( document.ntForm.ntPeri[i].checked ) {
           document.ntForm.ntPeri[ntSortBasisIndex].disabled = true;
         }
       }
       nwTestFravalgt("Sort");

     }

     else if ( pSpec == 5 || pSpec == 0 ) {

       if ( ntUdvik ) {
         if ( ntPrisIndex == 0 ) {
           document.ntForm.ntPrisBasis.disabled = true;
           document.ntForm.ntPrisBasis.selectedIndex = 0;

           for ( i=0; i<ntMaxAar; i++ ) {
//           alert('zzz nwMark3g: '+i);
             if ( ( document.ntForm.ntUdv.options[0].selected || i != ntUdvBasisIndex ) &&
                  ( document.ntForm.ntSort.options[0].selected || i != ntSortBasisIndex ) )
               document.ntForm.ntPeri[i].disabled = false;
           }
         }
         else {
           document.ntForm.ntPrisBasis.disabled = false;

           for ( i=0; i<ntMaxAar; i++ ) {
//           alert('zzz nwMark3h: '+i);
             if ( ntPrisBasis != 0 && i == ntPrisBasisIndex ) {
               document.ntForm.ntPeri[i].disabled = true;
             }
           }
         }

       }
     }

     else if ( pSpec == 6 || pSpec == 0 ) {

       if ( ntUdvik ) {

         for ( i=0; i<ntMaxAar; i++ ) {
//         alert('zzz nwMark3i: '+i);
           if ( ntPrisBasis == 0 || i != ntPrisBasisIndex ) {
             if ( ( document.ntForm.ntUdv.options[0].selected || i != ntUdvBasisIndex ) &&
                  ( document.ntForm.ntSort.options[0].selected || i != ntSortBasisIndex ) ) {
               document.ntForm.ntPeri[i].disabled = false;
             }
           }
           else if ( document.ntForm.ntPeri[i].checked ) {
             document.ntForm.ntPeri[ntPrisBasisIndex].disabled = true;
           }
         }
         nwTestFravalgt("Pris");
       }

     }

     else if ( pSpec == 7 || pSpec == 0 ) {

       ntHighl_kom = document.ntForm.ntSelKomHigh.value;

       if ( ntHighl_kom > 0 ) {
         if ( !document.ntForm.ntKommuneInddel.checked ) {
           document.ntForm.ntKommuneInddel.disabled = true;
         }
         else {
           document.ntForm.ntSelKomHigh.selectedIndex = 0;
           alert("Du kan ikke få fremhævet en kommune og samtidig ønske en bestemt kommune fremhævet");
         }

         if ( !document.ntForm.ntKunGennemsnit.checked ) {
           document.ntForm.ntKunGennemsnit.disabled = true;
         }
         else {
           document.ntForm.ntSelKomHigh.selectedIndex = 0;
           alert("Du kan ikke få fremhævet en kommune og samtidig ønske kun at se gennemsnit");
         }

         ntHighl_kom = document.ntForm.ntSelKomHigh.value;
         for ( i=0; i<ntMaxKom; i++ ) {
           if ( ntHighl_kom > 1 &&
             document.ntForm.ntSelKomMan.options[i].value == ntHighl_kom &&
             !document.ntForm.ntSelKomMan.options[i].selected )
             alert("Den kommune eller det område, som du har ønsket fremhævet, er ikke en af de markerede");
         }
       }
       else {
         document.ntForm.ntSelKomHigh.selectedIndex = 0;
         // zz document.ntForm.ntSelKomHigh.focus();

         if ( document.ntForm.ntSort.options[0].selected ) {
           document.ntForm.ntKommuneInddel.disabled = false;
           document.ntForm.ntKunGennemsnit.disabled = false;
         }
       }

       if ( document.ntForm.ntKunGennemsnit.checked || document.ntForm.ntKommuneInddel.checked ) {
         document.ntForm.ntSelKomHigh.disabled = true;
         document.ntForm.ntSort.disabled = true;
       }
       else {
         document.ntForm.ntSelKomHigh.disabled = false;
         document.ntForm.ntSort.disabled = false;
       }

       if ( !document.ntForm.ntSort.options[0].selected ||
         !document.ntForm.ntSelKomHigh.options[0].selected ||
         document.ntForm.ntKommuneInddel.checked )
         document.ntForm.ntKunGennemsnit.disabled = true;
       else
         document.ntForm.ntKunGennemsnit.disabled = false;

       if ( !document.ntForm.ntSort.options[0].selected ||
         !document.ntForm.ntSelKomHigh.options[0].selected ||
         document.ntForm.ntKunGennemsnit.checked )
         document.ntForm.ntKommuneInddel.disabled = true;
       else
         document.ntForm.ntKommuneInddel.disabled = false;
     }

     else if ( pSpec == 8 || pSpec == 0 ) {

       if ( ntUdvBasis > 0 && document.ntForm.ntPeri[ntUdvBasisIndex].checked ) {
         document.ntForm.ntPeri[ntUdvBasisIndex].disabled = true;
       }
       if ( ntSortBasis > 0 && document.ntForm.ntPeri[ntSortBasisIndex].checked ) {
         document.ntForm.ntPeri[ntSortBasisIndex].disabled = true;
       }
       nwTestFravalgt("Udv");
       nwTestFravalgt("Sort");
       nwTestFravalgt("Pris");

     }

     else if ( pSpec == 9 || pSpec == 0 ) {

       ntSaveAs = document.ntForm.ntSaveAs.value;
       if ( ntSaveAs == 0  ) ntCntMax = ntCntMaxHtml;
       else ntCntMax = ntCntMaxSave;

     }
//         alert('zzz nwMark3i: '+i);

     nwTestCntAar("Vxt");
     nwTestCntAar("Index");
     nwStatus(pStatus);
   }

// ------------------------------------------------------------------------------------------
   function nwMarkAll() {
// ------------------------------------------------------------------------------------------

     nwCnt("Aar");

     if ( ntCntAar < ntMaxAar ) {
       for ( i=0; i<ntMaxAar; i++ ) {
//       alert('zzz nwMarkAll.a: '+i);
         document.ntForm.ntPeri[i].checked = true;
         document.ntForm.ntPeri[i].disabled = false;
       }
     }
     else {
       for ( i=0; i<ntMaxAar; i++ ) {
//       alert('zzz nwMarkAll.b: '+i);
         document.ntForm.ntPeri[i].checked = false;
         document.ntForm.ntPeri[i].disabled = false;
       }
     }

     nwStatus(1);
   }

// ------------------------------------------------------------------------------------------
   function nwMarkRecent() {
// ------------------------------------------------------------------------------------------

     nwCnt("Aar");

//   Bestem om netop de seneste fem år er markeret
     ntSeneste = 10;
     for ( i=0; i<ntMaxAar; i++ ) {
//     alert('zzz nwMarkRecent.a: '+i);
       if ( i < ntMaxAar-5 && document.ntForm.ntPeri[i].checked ) ntSeneste = 5;
       if ( i >= ntMaxAar-5 && !document.ntForm.ntPeri[i].checked ) ntSeneste = 5;
     }

//   Marker enten de seneste fem eller 10 og afmarker de øvrige
     for ( i=0; i<ntMaxAar; i++ ) {
//     alert('zzz nwMarkRecent.b: '+i);
       if ( i < ntMaxAar-ntSeneste ) {
         document.ntForm.ntPeri[i].checked = false;
       }
       else {
         document.ntForm.ntPeri[i].checked = true;
       }
       document.ntForm.ntPeri[i].disabled = false;
     }

     nwStatus(1);
   }

// ------------------------------------------------------------------------------------------
   function nwSend(pSend) {
// ------------------------------------------------------------------------------------------

//   Udvælgelseskontrol

     ntListKom = "";
     ntCntKom = 0;
     ntCntAmt = 0;
     for ( i=0; i<ntMaxKom; i++ ) {
       if ( document.ntForm.ntSelKomMan.options[i].selected && document.ntForm.ntSelKomMan.options[i].value > 0 ) {
         ntCntKom = ntCntKom+1;
         if ( ntAmter.indexOf(','+document.ntForm.ntSelKomMan.options[i].value+',') > -1 )
           ntCntAmt = ntCntAmt+1;

         if ( ntCntKom == 1 ) {
           ntListKom = document.ntForm.ntSelKomMan.options[i].value;
         }
         else {
           ntListKom = ntListKom+","+document.ntForm.ntSelKomMan.options[i].value;
         }
       }
     }

//   Undersøg om den valgte mængde kommuner udgør den foruddefinerede kommunegruppe, der sidst blev valgt
     ntPreKomNrValue = document.ntForm.ntPreKomNr.value;
     for ( i=0; i<ntPreKomMax; i++ ) {
       if ( ntPreKomArr[i][0] == ntPreKomNrValue && ntPreKomNr == 0 && ntPreKomArr[i][1] == ntCntKom ) {

         ntPreKomNrCnt = 0;
         for ( j=0; j<ntMaxKom; j++ ) {
           if ( document.ntForm.ntSelKomMan.options[j].selected &&
             ntPreKomArr[i][2].indexOf(','+document.ntForm.ntSelKomMan.options[j].value+',') > -1 ) {
             ntPreKomNrCnt = ntPreKomNrCnt+1;
           }
         }
         if ( ntPreKomNrCnt == ntCntKom ) {
           ntPreKomNr = ntPreKomNrValue;
         }
       }
     }

     ntListNog = "";
     ntCntNog = 0;
     for ( i=0; i<ntMaxNog; i++ ) {
       if ( document.ntForm.ntSelNogMan.options[i].selected && document.ntForm.ntSelNogMan.options[i].value > 0 ) {
         ntCntNog = ntCntNog+1;
         if ( ntCntNog == 1 ) {
           ntListNog = document.ntForm.ntSelNogMan.options[i].value;
         }
         else {
           ntListNog = ntListNog+","+document.ntForm.ntSelNogMan.options[i].value;
         }
       }
     }

     ntCntAar = 0;
//   nwCnt("Aar");
     ntListAar = "";
     for ( i=0; i<ntMaxAar; i++ ) {
//     alert('zzz nwSend.a: '+i);
       if ( document.ntForm.ntPeri[i].checked ) {
         ntCntAar = ntCntAar+1;
         if ( ntCntAar == 1 ) {
           ntListAar = document.ntForm.ntPeri[i].value;
         }
         else {
           ntListAar = ntListAar+","+document.ntForm.ntPeri[i].value;
         }
       }
     }

     ntPreKom = "x";
     for ( i=0; i<ntMaxKomPre; i++ ) {
       if ( document.ntForm.ntSelKomPre.options[i].selected &&
         document.ntForm.ntSelKomPre.options[i].value > 0 ) {
         ntPreKom = document.ntForm.ntSelKomPre.options[i].text;
       }
     }

     ntPreNog = "x";
     for ( i=0; i<ntMaxNogPre; i++ ) {
       if ( document.ntForm.ntSelNogPre.options[i].selected &&
         document.ntForm.ntSelNogPre.options[i].value > 0 ) {
         ntPreNog = document.ntForm.ntSelNogPre.options[i].text;
       }
     }

     if ( ntCntKom == 0 ) {
       alert("Marker mindst en kommune eller område");
       return;
     }

     if ( ntCntNog == 0 ) {
       alert("Marker mindst et nøgletal");
       return;
     }

     if ( ntCntAar == 0 ) {
       alert("Marker mindst et år");
       return;
     }

     if ( ntCntTot > ntCntMax ) {
       alert("Du har nu markeret svarende til "+ntCntTot+" nøgletal (kommuner x nøgletal x år),\nmen du kan højst hente "+ntCntMax+" nøgletal ad gangen.\n\nFjern kommuner, nøgletal og/eller år indtil du ikke overstiger de "+ntCntMax);
       return;
     }

     if ( ntCntKom == 1 && !document.ntForm.ntSort.options[0].selected ) {
       alert("Sortering ikke mulig med kun en valgt kommune eller område");
       return;
     }

     if ( document.ntForm.ntKunGennemsnit.checked && ntCntKom - ntCntAmt < 2 ) {
       alert("Du skal vælge mindst to egentlige kommuner (ikke amtsgennemsnit eller større områder),\nfor at vælge kun at se gennemsnit for de valgte kommuner");
       return;
     }

     if ( !document.ntForm.ntUdv.options[0].selected && document.ntForm.ntUdvBasis.options[0].selected ) {
       alert("Basisår for udvikling er ikke valgt");
       return;
     }

     nwTestCntAar("Vxt");
     nwTestCntAar("Index");

     if ( !document.ntForm.ntSort.options[0].selected && document.ntForm.ntSortBasis.options[0].selected ) {
       alert("Basisår for sortering er ikke valgt");
       return;
     }

     if ( ntUdvik ) {
       if ( !document.ntForm.ntPris.options[0].selected && document.ntForm.ntPrisBasis.options[0].selected ) {
         alert("Basisår for prisudvikling er ikke valgt");
         return;
       }
     }

     if ( !document.ntForm.ntUdv.options[0].selected ) {
       ntUdvBasis = document.ntForm.ntUdvBasis.options[document.ntForm.ntUdvBasis.selectedIndex].value;
       ntUdvBasisIndex = ntUdvBasis-ntBegAar;
       if ( !document.ntForm.ntPeri[ntUdvBasisIndex].checked ) {
         alert("Du har bedt om at se udviklingen i forhold til "+ntUdvBasis+",\nog derfor kan året ikke været fravalgt");
         return;
       }
     }

     if ( !document.ntForm.ntSort.options[0].selected ) {
       ntSortBasis = document.ntForm.ntSortBasis.options[document.ntForm.ntSortBasis.selectedIndex].value;
       ntSortBasisIndex = ntSortBasis-ntBegAar;
       if ( !document.ntForm.ntPeri[ntSortBasisIndex].checked ) {
         alert("Du har bedt om at få data sorteret i forhold til "+ntSortBasis+",\nog derfor kan året ikke været fravalgt");
         return;
       }
     }

     if ( ntUdvik ) {
       if ( !document.ntForm.ntPris.options[0].selected ) {
         ntPrisBasis = document.ntForm.ntPrisBasis.options[document.ntForm.ntPrisBasis.selectedIndex].value;
         ntPrisBasisIndex = ntPrisBasis-ntBegAar;
         if ( !document.ntForm.ntPeri[ntPrisBasisIndex].checked ) {
           alert("Du har bedt om at se udgifter i faste priser i forhold til "+ntPrisBasis+",\nog derfor kan året ikke været fravalgt");
           return;
         }
       }
     }

     ntHighl_kom = document.ntForm.ntSelKomHigh.value;
     if ( ntHighl_kom > 0 ) {
       for ( i=0; i<ntMaxKom; i++ ) {
         if ( ntHighl_kom > 1 &&
           document.ntForm.ntSelKomMan.options[i].value == ntHighl_kom &&
           !document.ntForm.ntSelKomMan.options[i].selected ) {
           alert("Den kommune eller det område, som du har ønsket fremhævet, er ikke en af de markerede");
           return;
         }
       }
     }

//   Udvælgelsesinfo

     if ( document.ntForm.ntUdv.options[0].selected ) {
       ntInfoUdv = "nøgletallene ubehandlet";
     }
     else if ( document.ntForm.ntUdv.options[1].selected ) {
       ntInfoUdv = "absolut vækst med basis i "+document.ntForm.ntUdvBasis.options[document.ntForm.ntUdvBasis.selectedIndex].value;
     }
     else if ( document.ntForm.ntUdv.options[2].selected ) {
       ntInfoUdv = "procentuel vækst med basis i "+document.ntForm.ntUdvBasis.options[document.ntForm.ntUdvBasis.selectedIndex].value;
     }
     else if ( document.ntForm.ntUdv.options[3].selected ) {
       ntInfoUdv = "index-tal med basis i "+document.ntForm.ntUdvBasis.options[document.ntForm.ntUdvBasis.selectedIndex].value;
     }

     if ( document.ntForm.ntSort.options[0].selected ) {
       ntInfoSort = "usorteret";
     }
     else if ( document.ntForm.ntSort.options[1].selected ) {
       ntInfoSort = "faldende i forh. t. værdien i "+document.ntForm.ntSortBasis.options[document.ntForm.ntSortBasis.selectedIndex].value;
     }
     else if ( document.ntForm.ntSort.options[2].selected ) {
       ntInfoSort = "stigende i forh. t. værdien i "+document.ntForm.ntSortBasis.options[document.ntForm.ntSortBasis.selectedIndex].value;
     }
     else if ( document.ntForm.ntSort.options[3].selected) {
       ntInfoSort = "for de 10 bedst/dårligt placerede i forh. t. værdien i "+document.ntForm.ntSortBasis.options[document.ntForm.ntSortBasis.selectedIndex].value;
     }

     ntInfoPris = "<endnu ikke medtaget facilitet>";
     if ( ntUdvik ) {
       if ( document.ntForm.ntPris.options[0].selected ) {
         ntInfoPris = "i løbende priser";
       }
       else if ( document.ntForm.ntPris.options[1].selected ) {
         ntInfoPris = "i faste priser i forhold til værdien i "+document.ntForm.ntPrisBasis.options[document.ntForm.ntPrisBasis.selectedIndex].value;
       }
     }

     ntInfoPeri    = "";
     ntInfoSpec    = "ingen specielle faciliteter";
     ntInfoPeriCnt = 0;
     ntInfoSpecCnt = 0;

     for ( i=0; i<ntMaxAar; i++ ) {
//     alert('zzz nwSend.b: '+i);
       if ( document.ntForm.ntPeri[i].checked ) {
         ntInfoPeriCnt = ntInfoPeriCnt+1;
         if ( ntInfoPeriCnt == 1 ) {
           ntInfoPeri = "at se data for "+document.ntForm.ntPeri[i].value;
         }
         else {
           ntInfoPeri = ntInfoPeri+","+document.ntForm.ntPeri[i].value;
         }
       }
     }

     if ( document.ntForm.ntKommuneInddel.checked ) {
       ntInfoSpecCnt = ntInfoSpecCnt+1;
       ntInfoSpec = "at kommuneinddele";
     }

     if ( document.ntForm.ntKunGennemsnit.checked ) {
       ntInfoSpecCnt = ntInfoSpecCnt+1;
       if ( ntInfoSpecCnt == 1 ) {
         ntInfoSpec = "kun at se gennemsnit";
       }
     }

     if ( !document.ntForm.ntSaveAs.options[0].selected ) {
       ntInfoSpecCnt = ntInfoSpecCnt+1;
       if ( ntInfoSpecCnt == 1 ) {
         ntInfoSpec = "at få data returneret som en af fire tekstfiltyper";
       }
       else {
         ntInfoSpec = ntInfoSpec+"\n... at få data returneret som en af fire tekstfiltyper";
       }
     }

     if ( !document.ntForm.ntSelKomHigh.options[0].selected ) {
       ntInfoSpecCnt = ntInfoSpecCnt+1;
       if ( ntInfoSpecCnt == 1 ) {
         ntInfoSpec = "at fremhæve "+document.ntForm.ntSelKomHigh.options[document.ntForm.ntSelKomHigh.selectedIndex].value;
       }
       else {
         ntInfoSpec = ntInfoSpec+"\n... at fremhæve "+document.ntForm.ntSelKomHigh.options[document.ntForm.ntSelKomHigh.selectedIndex].value;
       }
     }

//   Send (evt) forespørgsel
     if ( pSend == 1 ) {
       alert("Du har valgt ..."+
         "\n... disse kommuner: "+ntListKom+
         "\n... disse nøgletal: "+ntListNog+
         "\n... at vise "+ntInfoUdv+
         "\n... at vise data "+ntInfoSort+
         "\n... at vise udgifter i "+ntInfoPris+
         "\n... "+ntInfoPeri+
         "\n... "+ntInfoSpec);
       return;
     }

     document.ntForm.ntListKom.value = ntListKom;
     document.ntForm.ntListNog.value = ntListNog;
     document.ntForm.ntListAar.value = ntListAar;

     document.ntForm.ntPreKom.value = ntPreKom;
     document.ntForm.ntPreNog.value = ntPreNog;

     document.ntForm.ntPreKomNr.value = ntPreKomNr;
     document.ntForm.ntPreNogNr.value = ntPreNogNr;

     document.ntForm.ntUserResol.value = screen.height+'x'+screen.width;
     document.ntForm.ntUserAppl.value  = navigator.appVersion;
     document.ntForm.ntUserAgent.value = navigator.userAgent;

     if ( document.ntForm.ntUdv.options[0].selected )
       document.ntForm.ntUdvBasis.disabled = false;
     if ( document.ntForm.ntSort.options[0].selected )
       document.ntForm.ntSortBasis.disabled = false;
     if ( ntUdvik ) {
       if ( document.ntForm.ntPris.options[0].selected )
         document.ntForm.ntPrisBasis.disabled = false;
     }
     if ( document.ntForm.ntSelKomHigh.options[0].selected )
       document.ntForm.ntSelKomHigh.disabled = false;

     if ( document.ntForm.ntKunGennemsnit.checked ) {
       document.ntForm.ntVisKunGns.value = 1;
     }
     else {
       document.ntForm.ntVisKunGns.value = 0;
     }
     if ( document.ntForm.ntKommuneInddel.checked ) {
       document.ntForm.ntKomInddel.value = 1;
     }
     else {
       document.ntForm.ntKomInddel.value = 0;
     }

     if ( !document.ntForm.ntSelKomHigh.options[0].selected ) {
       document.ntForm.ntHighlight.value = 1;
       document.ntForm.ntHighl_kom.value = ntHighl_kom;
     }
     else {
       document.ntForm.ntHighlight.value = 0;
       document.ntForm.ntHighl_kom.value = 0;
     }

     if ( document.ntForm.ntKommuneInddel.checked || document.ntForm.ntKunGennemsnit.checked ) {
       document.ntForm.ntSort.disabled = false;
       document.ntForm.ntSort.options[0].selected = true;
     }

     if ( pSend == 3 || pSend == 6 )
       document.ntForm.ntCommand.value = "RapPrv";

     if ( ntPlatf == 'prv' )
       document.ntForm.action = "http://localhost:9080/noegletal/servlet/nctrlman.aReqManager";

     document.ntForm.submit();
   }

// ------------------------------------------------------------------------------------------
   function nwSendAdm(pSend) {
// ------------------------------------------------------------------------------------------

     document.ntForm.ntUserResol.value = screen.height+'x'+screen.width;
     document.ntForm.ntUserAppl.value  = navigator.appVersion;
     document.ntForm.ntUserAgent.value = navigator.userAgent;

     // Tidligere anvendt løsning
     /*
     document.ntForm.action = "servlet/nctrlman.aReqManager";
     if ( pSend == 2 || pSend == 3 )
       document.ntForm.action = "noegletal/servlet/nctrlman.aReqManager";
     */
     if ( pSend == 3 )
       document.ntForm.ntCommand.value = "AdmPrv";

//   document.ntForm.submit();
   }

// ------------------------------------------------------------------------------------------
   function nwSendTest(pSend) {
// ------------------------------------------------------------------------------------------

     // Til brug for test af VAJ
     /*
     if ( pSend == 1 ) document.ntForm.action = "http://localhost:8080/servlet/HelloWorldServlet";
     if ( pSend == 2 ) document.ntForm.action = "http://localhost:8080/servlet/TestServlet";
     document.ntForm.submit();
     */
   }

// ------------------------------------------------------------------------------------------
   function nwStatus(pAlert) {
// ------------------------------------------------------------------------------------------

     nwCnt("Kom");
     nwCnt("Nog");
     nwCnt("Aar");

     ntCntTot = ntCntKom * ntCntNog * ntCntAar;
     ntCntOldKopi = ntCntOld;
     ntCntOld = ntCntTot;

     if ( ntSaveAs == 0 )
       ntInfoStatus = ""+ntCntKom+" x "+ntCntNog+" x "+ntCntAar+" = "+ntCntTot+" (max "+ntCntMax+")";
     else
       ntInfoStatus = ""+ntCntKom+" x "+ntCntNog+" x "+ntCntAar+" = "+ntCntTot+" (max "+ntCntMax+" i fil)";

     if ( pAlert ) {
       nwWriteStatus(ntInfoStatus);

       if ( ntCntTot > ntCntMax ) {
         if ( ntCntTot > ntCntOldKopi ) {
           alert("Du har nu markeret svarende til "+ntCntTot+" nøgletal (kommuner x nøgletal x år),\nmen du kan højst hente "+ntCntMax+" nøgletal ad gangen.\n\nFjern kommuner, nøgletal og/eller år indtil du ikke overstiger de "+ntCntMax);
           return;
         }
       }
     }
   }

// ------------------------------------------------------------------------------------------
   function nwReset() {
// ------------------------------------------------------------------------------------------

     document.ntForm.ntSelKomPre.options[0].selected = true;
     document.ntForm.ntSelNogPre.options[0].selected = true;

     document.ntForm.ntSelKomMan.selectedIndex = 0;
     for ( i=ntMaxKom-1; i>=0; i-- ) {
       document.ntForm.ntSelKomMan.options[i].selected = false;
     }

     document.ntForm.ntSelNogMan.selectedIndex = 0;
     for ( i=ntMaxNog-1; i>=0; i-- ) {
       document.ntForm.ntSelNogMan.options[i].selected = false;
     }

     for ( i=0; i<ntMaxAar; i++ ) {
       document.ntForm.ntPeri[i].checked = false;
       document.ntForm.ntPeri[i].disabled = false;
     }
     // Initialisering før Kommuinalreformen
     if ( ntMaxAar == 14 ) {
       for ( i=8; i<ntMaxAar; i++ ) {
         document.ntForm.ntPeri[i].checked = true;
         document.ntForm.ntPeri[i].disabled = false;
       }
     }
     // Initialisering efter Kommuinalreformen
     // Fjern -1 herunder, når også 2010 skal vises default
     else {
       for ( i=14; i<ntMaxAar-1; i++ ) {
         document.ntForm.ntPeri[i].checked = true;
         document.ntForm.ntPeri[i].disabled = false;
       }
     }

     // zz hvorfor er denne ikke med? document.ntForm.ntUdv.disabled = false;
     document.ntForm.ntUdv.options[0].selected = true;

     document.ntForm.ntUdvBasis.disabled = false;
     document.ntForm.ntUdvBasis.options[0].selected = true;
     document.ntForm.ntUdvBasis.disabled = true;

     document.ntForm.ntSort.disabled = false;
     document.ntForm.ntSort.options[0].selected = true;

     document.ntForm.ntSortBasis.disabled = false;
     document.ntForm.ntSortBasis.options[0].selected = true;
     document.ntForm.ntSortBasis.disabled = true;

     if ( ntUdvik ) {
       document.ntForm.ntPris.disabled = false;
       document.ntForm.ntPris.options[0].selected = true;

       document.ntForm.ntPrisBasis.disabled = false;
       document.ntForm.ntPrisBasis.options[0].selected = true;
       document.ntForm.ntPrisBasis.disabled = true;
     }

     document.ntForm.ntSelKomHigh.disabled = false;
     document.ntForm.ntSelKomHigh[0].selected = true;

     document.ntForm.ntKunGennemsnit.disabled = false;
     document.ntForm.ntKunGennemsnit.checked = false;

     document.ntForm.ntKommuneInddel.disabled = false;
     document.ntForm.ntKommuneInddel.checked = false;

     document.ntForm.ntSaveAs.disabled = false;
     document.ntForm.ntSaveAs.options[0].selected = true;

     nwStatus(1);
   }

// ------------------------------------------------------------------------------------------
   function nwWriteText(text,id) {
// ------------------------------------------------------------------------------------------

     if ( document.getElementById ) {
       x = document.getElementById(id);
       x.innerHTML = '';
       x.innerHTML = text;
     }
     else if ( document.all ) {
       x = document.all[id];
       x.innerHTML = text;
     }
     else if ( document.layers ) {
       x = document.layers[id];
       x.document.open();
       x.document.write(text);
       x.document.close();
     }
   }

// ------------------------------------------------------------------------------------------
   function nwWriteStatus(pStatus) {
// ------------------------------------------------------------------------------------------

     document.ntForm.ntStatusFelt.value = pStatus;
   }

// ------------------------------------------------------------------------------------------
   function nwWriteMax() {
// ------------------------------------------------------------------------------------------

     document.write("(max&nbsp;"+ntCntMax+")");
   }

// ------------------------------------------------------------------------------------------
   function nwInitOnload() {
// ------------------------------------------------------------------------------------------

     window.setTimeout('nwInit();',500);
   }

// ------------------------------------------------------------------------------------------
   function nwCnt(pSubject) {
// ------------------------------------------------------------------------------------------

     if ( pSubject == "Kom" ) {
       ntCntKom = 0;
       for ( i=0; i<ntMaxKom; i++ ) {
         if ( document.ntForm.ntSelKomMan.options[i].selected && document.ntForm.ntSelKomMan.options[i].value > 0 ) {
           ntCntKom = ntCntKom+1;
         }
       }
     }

     else if ( pSubject == "Nog" ) {
       ntCntNog = 0;
       for ( i=0; i<ntMaxNog; i++ ) {
         if ( document.ntForm.ntSelNogMan.options[i].selected && document.ntForm.ntSelNogMan.options[i].value > 0 ) {
           ntCntNog = ntCntNog+1;
         }
       }
     }

     else if ( pSubject == "Aar" ) {
       ntCntAar = 0;
       for ( i=0; i<ntMaxAar; i++ ) {
//       alert('zzz nwCnt: '+i);
         if ( document.ntForm.ntPeri[i].checked ) {
           ntCntAar = ntCntAar+1;
           ntSenAar = ntBegAar+i;
         }
       }
     }
   }

// ------------------------------------------------------------------------------------------
   function nwTestFravalgt(pSubject) {
// ------------------------------------------------------------------------------------------

     if ( pSubject == "Udv" ) {
       if ( ntUdvBasis > 0 && !document.ntForm.ntPeri[ntUdvBasisIndex].checked ) {
         alert("Du har bedt om at se udviklingen i forhold til "+ntUdvBasis+",\nmen har fravalgt dette år");
         document.ntForm.ntUdvBasis.selectedIndex = 0;
         return;
       }
     }
     else if ( pSubject == "Sort" ) {
       if ( ntSortBasis > 0 && !document.ntForm.ntPeri[ntSortBasisIndex].checked ) {
         alert("Du har bedt om at se data sorteret forhold til "+ntSortBasis+",\nmen har fravalgt dette år");
         document.ntForm.ntSortBasis.selectedIndex = 0;
         return;
       }
     }
     else if ( pSubject == "Pris" ) {
       if ( ntUdvik ) {
         if ( ntPrisBasis > 0 && !document.ntForm.ntPeri[ntPrisBasisIndex].checked ) {
           alert("Du har bedt om at se data i faste priser i forhold til "+ntPrisBasis+",\nmen har fravalgt dette år");
           document.ntForm.ntPrisBasis.selectedIndex = 0;
           return;
         }
       }
     }
   }

// ------------------------------------------------------------------------------------------
   function nwTestCntAar(pSubject) {
// ------------------------------------------------------------------------------------------

     if ( pSubject == "Vxt" ) {
       if ( ntUdvIndex == 1 || ntUdvIndex == 2 ) {
         if ( document.ntForm.ntUdvBasis.options[document.ntForm.ntUdvBasis.selectedIndex].value >= ntSenAar ) {

           document.ntForm.ntPeri[ntUdvBasisIndex].disabled = false;
           document.ntForm.ntUdvBasis.selectedIndex = 0;
           alert("For at se absolut eller procentuel vækst i et nøgletal\nmå basisåret ikke være det seneste år af dem du har valgt");
           return;
         }
       }
     }

     else if ( pSubject == "Index" ) {
       if ( ntUdvIndex == 3 ) {
         if ( ntCntAar < 2 ) {
           document.ntForm.ntUdv.selectedIndex = 0;
           document.ntForm.ntUdvBasis.selectedIndex = 0;
           document.ntForm.ntUdvBasis.disabled = true;
           alert("For at se nøgletallene som index-tal skal du vælge at se data for mindst to år");
           return;
         }
       }
     }
   }

// Slut

