Guest User

Untitled

a guest
Feb 25th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en">
  4.     <head>
  5.         <meta charset="utf-8" />
  6.         <title>German Tax Generator</title>
  7.         <meta name="author" content="JavaScript: Jonas Pfeil">
  8.         <meta name="author" content="Original: Martin Wolters">
  9.         <script>
  10.             var MIXFACT=256;
  11.             //Code from http://www.naden.de/blog/zufallszahlen-in-javascript-mit-mathrandom
  12.             function rrand(min, max) {
  13.                 if(min > max) {
  14.                     return -1;
  15.                 }
  16.                 if(min == max) {
  17.                     return min;
  18.                 }
  19.                 var r;
  20.                 do {
  21.                     r = Math.random();
  22.                 }
  23.                 while(r == 1.0);
  24.                 return min + parseInt(r * (max-min+1));
  25.             }
  26.             function checksum(id) {
  27.                 var out;
  28.                 var i, sum = 0, prod = 10;
  29.  
  30.                 for(i = 0; i < 10; i++) {
  31.                     sum = (id[i] + prod) % 10;
  32.                     if(sum == 0)
  33.                         sum = 10;
  34.                     prod = (sum * 2) % 11;
  35.                 }
  36.                 out = 11 - prod;
  37.                 if(out == 10)
  38.                     out = 0;
  39.                 return out;
  40.             }
  41.             function mix(id) {
  42.                 var i, pos1, pos2;
  43.                 var buf;
  44.                 for(i = 0; i < MIXFACT; i++) {
  45.                     pos1 = rrand(0,9);
  46.                     do {
  47.                         pos2 = rrand(0,9);
  48.                     } while(pos1 == pos2);
  49.                     buf = id[pos1];
  50.                     id[pos1] = id[pos2];
  51.                     id[pos2] = buf;
  52.                 }
  53.                 pos1 = rrand(0,9);
  54.                 do {
  55.                     pos2 = rrand(0,9);
  56.                 } while(pos1 == pos2);
  57.                 id[pos1] = id[pos2];
  58.             }
  59.             function generateTaxId(){
  60.                 var id=[0,1,2,3,4,5,6,7,8,9];
  61.                 mix(id);
  62.                 var ret="";
  63.                 for(var i=0;i<10;++i)
  64.                     ret+=id[i];
  65.                 ret+=checksum(id);
  66.                 return ret;
  67.             }
  68.         </script>
  69.         <style>
  70.             #license
  71.             {
  72.                 display:none;
  73.                 width:12cm;
  74.                 text-align:justify;
  75.             }
  76.         </style>
  77.     </head>
  78.     <body>
  79.         <input type="text"><input type="button" onclick="this.previousSibling.value=generateTaxId()" value="Generate Tax ID"><br>
  80.         <input type="button" onclick="this.nextSibling.style.display='block'" value="License"><div id="license">
  81.             <p>Copyright (C) 2012 Martin Wolters, Jonas Pfeil</p>
  82.             <p>This program is free software; you can redistribute it and/or
  83.             modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl-2.0.txt">GNU General Public License</a>
  84.             as published by the Free Software Foundation; either version 2
  85.             of the License, or (at your option) any later version.</p>
  86.        
  87.             <p>This program is distributed in the hope that it will be useful,
  88.             but WITHOUT ANY WARRANTY; without even the implied warranty of
  89.             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  90.             GNU General Public License for more details.</p>
  91.        
  92.             <p>You should have received a copy of the GNU General Public License
  93.             along with this program; if not, write to <br>
  94.             the Free Software Foundation, Inc.<br>
  95.             51 Franklin Street, Fifth Floor<br>
  96.             Boston, MA  02110-1301, USA</p>
  97.         </div>
  98.     </body>
  99. </html>
Add Comment
Please, Sign In to add comment