function MWJSCrypt (OrigString, SeedIn) { 

    // ----------- DO NOT EVER change the value of "Ref" ----------- // 
    Ref="0123456789abcdefghijklmnopqrstuvwxyz._~ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
    // ----------- DO NOT EVER change the value of "Ref" ----------- // 

    var CipherVal = parseInt(SeedIn);// converts SeedIn to an integer value 
    if ( isNaN(CipherVal))  
    {    // error if SeedIn is not a number. 
      throw new Error("function MWJScrpyt parameter("+SeedIn+") is not a number."); 
      return(""); 
      } else { if ( (CipherVal < 1) || (CipherVal > 99999999))  
        { 
          // error if SeedIn is not a number. 
          throw new Error("function MWJScrpyt parameter("+SeedIn+") seed range error."); 
          return("");    } 
          else { 
            var Temp=""; 
            for (Count=0; Count < OrigString.length; Count++) { 
              // loops until end of password 
              var TempChar = OrigString.substring (Count, Count+1); //get 1 char 
              var Conv = Ref.indexOf(TempChar); // returns index of ref    
              var Cipher=Conv^CipherVal; // logical 'or' 
              var NewCipher = Cipher % Ref.length; // mod by length of Ref 
              Cipher=Ref.substring(NewCipher, NewCipher+1) ;// call to function                
              Temp += Cipher;// adds the new chars one by one 
            } 
            return (Temp);// returns the encrypted password 
          } 
        }       
      } 

      function urlDecode(str){ 
        str=str.replace(new RegExp('\\+','g'),' '); 
        return unescape(str); 
      } 
      function urlEncode(str){ 
        str=escape(str); 
        str=str.replace(new RegExp('\\+','g'),'%2B'); 
        return str.replace(new RegExp('%20','g'),'+'); 
      } 

      var END_OF_INPUT = -1; 

      var base64Chars = new Array( 
        'A','B','C','D','E','F','G','H', 
        'I','J','K','L','M','N','O','P', 
        'Q','R','S','T','U','V','W','X', 
        'Y','Z','a','b','c','d','e','f', 
        'g','h','i','j','k','l','m','n', 
        'o','p','q','r','s','t','u','v', 
        'w','x','y','z','0','1','2','3',
        '4','5','6','7','8','9','+','/' 
      ); 

      var reverseBase64Chars = new Array(); 
      for (var i=0; i < base64Chars.length; i++){ 
        reverseBase64Chars[base64Chars[i]] = i; 
      } 

      var base64Str; 
      var base64Count; 
      // Ok 
      function setBase64Str(str){ 
        base64Str = str; 
        base64Count = 0; 
      } 
      // Ok 
      function readBase64(){     
        if (!base64Str) return END_OF_INPUT; 
        if (base64Count >= base64Str.length) return END_OF_INPUT; 
        var c = base64Str.charCodeAt(base64Count) & 0xff; 
        base64Count++; 
        return c; 
      } 
      // Ok 
      function encodeBase64(str){ 
        setBase64Str(str); 
        var result = ''; 
        var inBuffer = new Array(3); 
        var lineCount = 0; 
        var done = false; 
        while (!done && (inBuffer[0] = readBase64()) != END_OF_INPUT){ 
          inBuffer[1] = readBase64(); 
          inBuffer[2] = readBase64(); 
          result += (base64Chars[ inBuffer[0] >> 2 ]); 
          if (inBuffer[1] != END_OF_INPUT){ 
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]); 
            if (inBuffer[2] != END_OF_INPUT){ 
              result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]); 
              result += (base64Chars [inBuffer[2] & 0x3F]); 
            } else { 
              result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]); 
              result += ('='); 
              done = true; 
            } 
          } else { 
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]); 
            result += ('='); 
            result += ('='); 
            done = true; 
          } 

        } 
        return result; 
      } 
      // Ok 
      function readReverseBase64(){    
        if (!base64Str) return END_OF_INPUT; 
        while (true){       
          if (base64Count >= base64Str.length) return END_OF_INPUT; 
          var nextCharacter = base64Str.charAt(base64Count); 
          base64Count++; 
          if (reverseBase64Chars[nextCharacter]){ 
            return reverseBase64Chars[nextCharacter]; 
          } 
          if (nextCharacter == 'A') return 0; 
        } 
        return END_OF_INPUT; 
      }
      // Ok 
      function ntos(n){ 
        n=n.toString(16); 
        if (n.length == 1) n="0"+n; 
        n="%"+n; 
        return unescape(n); 
      } 
      // Ok 
      function decodeBase64(str){ 
        setBase64Str(str); 
        var result = ""; 
        var inBuffer = new Array(4); 
        var done = false; 
        while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT 
        && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){ 
          inBuffer[2] = readReverseBase64(); 
          inBuffer[3] = readReverseBase64(); 
          result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4)); 
          if (inBuffer[2] != END_OF_INPUT){ 
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2)); 
            if (inBuffer[3] != END_OF_INPUT){ 
              result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3])); 
            } else { 
              done = true; 
            } 
          } else { 
            done = true; 
          } 
        } 
        return result; 
      } 
      /* ------------------------------------------------------------ */ 



      function MWB64Crypt (OrigString, SeedIn) { 
        // ----------- DO NOT EVER change the value of "RefURLChar" ----------- // 
        RefURLChar="0123456789+/=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
        // ----------- DO NOT EVER change the value of "RefURLChar" ----------- // 
        var CipherVal = parseInt(SeedIn);// converts SeedIn to an integer value 
        if ( isNaN(CipherVal))  
        {    // error if SeedIn is not a number. 
          throw new Error("function MWB64Crypt parameter("+SeedIn+") is not a number."); 
          return(""); 
          } else { if ( (CipherVal < 1) || (CipherVal > 99999999))  
            { 
              // error if SeedIn is not a number. 
              throw new Error("function MWB64Crypt parameter("+SeedIn+") seed range error."); 
              return("");    } 
              else { 
                var Temp=""; 
                for (Count=0; Count < OrigString.length; Count++) { 
                  // loops until end of password 
                  var TempChar = OrigString.substring (Count, Count+1); //get 1 char 
                  var Conv = RefURLChar.indexOf(TempChar); // returns index of RefURLChar  
                  if ( Conv == -1 ){ 
                    // error if password has invalid characters 
                    document.writeln("<b>*** Error!! ***</b><br/>"+ 
                    "Password contains invalid character."); 
                    throw new Error("function MWB64Crypt, Password"+ 
                    " contains invalid character."); 
                    return("");    } 
                    var Cipher=Conv + CipherVal;
                    var NewCipher = Cipher % RefURLChar.length; // mod by length of RefURLChar 
                    Cipher=RefURLChar.substring(NewCipher, NewCipher+1) ;// call to function                
                    if (Cipher == "+"){Cipher = "~";}// Plus causes problems in query strings 
                    Temp += Cipher;// adds the new chars one by one 
                  } 
                  return (Temp);// returns the encrypted password 
                } 
              }       
            }  

            function getDate(){ 
              /* 
              * This function formats and returns a timestamp in the format: 
              *       2005-11-15T10:49:50.GMT-6.00 
              *       YYYY-MM-DDTHH:MM:SS.GMTzzzzz 
              *          zzzzz can be in the format:  
              *                      GMT+HH.MM  
              *                      GMT-HH.MM  
              *      or a valid timezone label like CST, PST, MST ect...    
              */ 
              var now = new Date(); // reference to object date 
              var timezonehours = now.getTimezoneOffset() / 60 * -1;  
              var timestamp = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate()+"T"+ 
              now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()+".GMT"+timezonehours+".00"; 

              return timestamp; 
            }   

            function QSBuild(OrigString){ 
              var now = new Date();  
              var time = now.getHours() + now.getMinutes() + now.getSeconds(); // retrieve time from server 
              var date = now.getMonth() + now.getDay() + now.getFullYear(); //retrieve the date 
              // build a "seed" that is always 4 chars long using the current date and time.... 
              var origseed = "0040" + (date + time) ;  
              var seed = origseed.substr(origseed.length-4,4); 
              // first pass encoding, Base64... 
              var queryStringB64 = encodeBase64(OrigString); 
              // second pass encoding 
              var queryStringB64URLE = MWB64Crypt (queryStringB64, seed); 
              var finalQS = seed+queryStringB64URLE; 
              return(finalQS) 
            } 
            //********************************************************************************** 
            //* the Javascript above this point should not be modified  
            //********************************************************************************** 


            function dynamicLink(userid) { 
              /*  
              * This is a sample of how to build an automatic login URL for CustomPoint. 
              */ 

              /*  
              * This particular sample includes user prompts. 
              * The prompts are not required and are only used to test the login. 
              */ 
              var password = 'Universal2010';
              var account = 'universal';


              // generate an "seed" for encrypting the password using the date and time 
              var now = new Date(); // reference to object date 
              var time = now.getHours() + now.getMinutes() + now.getSeconds(); // retrieve time from server 
              var date = now.getMonth() + now.getDay() + now.getYear(); //retrieve the date

              var seed = (date + time) ;  

              // call function to encrypt password... 
              var epassword = MWJSCrypt (password, seed); 

              // build the url with the query string parameters... 
              var urlRoot = "https://custompoint.rrd.com/xs2/"; 

              var queryString = "Option=6&username="+userid+ 
              "&password="+epassword+ 
              "&account="+account+ 
              "&datetime="+seed+
              "&URL=windowclose.htm"+
              "&ReturnText=Logout"+

              "&Module=CO"+

              "&tstamp="+getDate(); 
              
              if (userid == 'quickfind')
              {
                // queryString += "&CustRef1=Innova"+
                // "&failureAction=AUP"+
                // "&profileID=Innova";
              }


              // call funtcion to do the double encoding...                  
              var newQueryString ="?mw="+QSBuild(queryString);  

              // alert(urlRoot + '?' + queryString); //before encryption
              // return false;

              // redirect to CustomPoint 
              //window.location = urlRoot + newQueryString ;   
				window.open(urlRoot + newQueryString, 'orderform');
            } 