// JavaScript Document

// (To configure see options below Copyright message)

///////////////////////////////////////////////////////////////////////////
// JavaScript Password System (JPS)  -  Password Entry                   //
//                                                                       //
//  Copyright (C) 1997 P.J.Wise & A.J.Chee                               //
//                                                                       //
//  This program is free software; you can redistribute it and/or modify //
//  it under the terms of the GNU General Public License as published by //
//  the Free Software Foundation; either version 2 of the License, or    //
//  (at your option) any later version.                                  //
//                                                                       //
//  This program is distributed in the hope that it will be useful,      //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of       //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
//  GNU General Public License for more details.                         //
//                                                                       //
//  You should have received a copy of the GNU General Public License    //
//  along with this program; if not, write to the Free Software          //
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            //
//-----------------------------------------------------------------------//
//  Comments, Suggestions etc. about this program should be sent to:-    //
//                     jps@bloodaxe.demon.co.uk                          //
//  or check out:-                                                       //
//            <URL:http://www.bloodaxe.demon.co.uk/JPS/>                 //
///////////////////////////////////////////////////////////////////////////

//OPTIONS-------------------------------------------------------------------

// change code every 'n' "DAYS","WEEKS","MONTHS"
changetype="DAYS";
changen=1;

// Pass-code override if "-1" then changetype and n used otherwise this
// specific code used until changed manually
codeoverride = 1;

// Base URL setting (converted to <BASEURL><PASSCODE>/)
baseurl = "../barcode/download/";

//ENDOPTIONS-----------------------------------------------------------------
// Nothing below this line should need to be altered, until <BODY> reached

  function passEncode(form)
  {
    pEncode(form.password.value);
  }

  function pEncode(passwd)
  {
    var Key = getKey();
    var Ret = encode (passwd, Key);
    location = baseurl + Ret + "/";
  }

  function getKey()
  {
    if (codeoverride == -1)
    {
      var months = new Array();
      months[0]=31;
      months[1]=28;
      months[2]=31;
      months[3]=30;
      months[4]=31;
      months[5]=30;
      months[6]=31;
      months[7]=31;
      months[8]=30;
      months[9]=31;
      months[10]=30;
      months[11]=31;

      var dater = new Date();
      var Key = 0;
      for (var count = 0; count < dater.getMonth();count++)
      {
        Key = Key + months[count];
      }
      Key += dater.getDate();

      if (changetype == "DAYS")
      {
        Key = Key / changen;
      }else if (changetype == "WEEKS"){
        Key = Key / 7;
        Key = Key / changen;
      }else{
        Key = dater.getMonth() + ((dater.getYear() % 100) * 12);
        Key = Key / changen;
      }
      dater = null;
    }else{
      Key = codeoverride;
    }
    Key = Math.floor(Key);
    return (Key);
  }

  function encode (OrigString, CipherVal)
  { 
    Ref="0123456789abcdefghijklmnopqrstuvwxyz._~ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    CipherVal = parseInt(CipherVal);
    var Temp="";
    for (Count=0; Count < OrigString.length; Count++) 
    {
      var TempChar = OrigString.substring (Count, Count+1);
      var Conv = cton(TempChar);
      var Cipher=Conv^CipherVal^Count;

      Cipher=ntoc(Cipher%Ref.length);
      Temp += Cipher;
    }
    return (Temp);
  }

  function cton (Char) 
  {
    return (Ref.indexOf(Char));
  }

  function ntoc (Val) 
  {
    return (Ref.substring(Val, Val+1));
  }

//This code catches the query string if the user submitted by hitting
//return, and forces the password encoding
if ((qmark = location.search) != ""){
  pEncode(qmark.substring(qmark.indexOf("=")+1,qmark.length));
}

// -->