
// http://www.platypus.st/home/nosuzuki/sample_code/URLencode.js.txt

  function URLencode(str){
   var i, encoded_str, char_code, padded_str;
         encoded_str = "";
  for (i = 0; i < str.length; i++){
             char_code = str.charCodeAt(i);
      if (char_code == 0x20){
                // space -> "+"
          encoded_str += "+";}
      else { // else 1
          if ( ((char_code >= 0x30) && (char_code <= 0x39)) || ((char_code >= 0x41) && (char_code <= 0x5a)) || ((char_code >= 0x61) && (char_code <= 0x7a))){
                     // no escape
                     encoded_str += str.charAt(i);
            }
          else { // else 2
              if ( char_code > 0xffff ) {
                          // for UTF-8
                          padded_str = "0" + char_code.toString(16);
                          encoded_str += "%" + padded_str.substr(padded_str.length - 6, 2) + "%" + padded_str.substr(padded_str.length - 4, 2) + "%" + padded_str.substr(padded_str.lenght - 2, 2);
                             }
                else if ( char_code > 0xff ) {
                          // for JIS, EUC or SJIS
                          padded_str = "0" + char_code.toString(16);
                          encoded_str += "%" + padded_str.substr(padded_str.length - 4, 2) + "%" + padded_str.substr(padded_str.lenght - 2, 2);
                             }
                    else {
                          // for ascii
                          padded_str = "0" + char_code.toString(16);
                          encoded_str += "%" + padded_str.substr(padded_str.length - 2, 2);
                             }
                      } // else 2
                } // else 1
        } // for
        return encoded_str;
}


function aclog (url, arg) {
  var from = URLencode((document.referrer == parent.location) ? top.document.referrer : document.referrer);
  var now  = new Date();
  var time = "" + now.getMonth() + now.getDay() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds();
  var code = "<script type='text/javascript' src='/aclog2/log/" + time + "/?ref=" + from  + ";url=" + URLencode(url) + ";arg=" + URLencode(arg || '') + "'></script>";
  document.write(code);
}


