/*
** master.js
**
** (c) 2001 Michael L. Jaegers <michael@jaegers.net>
**
** JavaScript Module for WWW.Jaegers.Net
**
** This Script will be loaded by *.html. It's basic 
** functions are the lights (on mouseover) functionality.
**
*/

/*
* Global part 
*/

/*
* Check value for the counter 
*/
var lon = 0; // light
var cok = 0; // counter (gif)
var idc = 0; // ID Counter

/*
* Function declarations
*/

/*
* light(u)
*
* change light bulb
*/
/*function light(u) {
  // change the numbered light
  n=document.images[lon].src;
  document.images[lon].src=n.replace(".gif", "g.gif");
  lon = u;
  n=document.images[lon].src;
  document.images[lon].src=n.replace("g.gif", ".gif");
}*/

/*
* unlight(u)
*
* set light on
*/
function light(u) {
	src = document.images[u].src;
	document.images[u].src = src.replace("g.gif", ".gif");
}

/*
* light(u)
*
* set light off
*/
function unlight(u) {
	src = document.images[u].src;
	document.images[u].src = src.replace(".gif", "g.gif");
}

/*
* otimg()
*
* other image
*/

function otimge() {
 document.images[10].src="/counter/bad_referer.gif";
}

function otimgc() {
 if (cok==0) {
  document.images[10].src="/cgi-bin/counter.pl?3";
  cok=1;
 }
}

/*
* showDate()
*
* displays the current date
*/

function num2txt (n) {
  switch (n) {
    case 0 : return "0";
    case 1 : return "1st";
    case 2 : return "2nd";
    case 3 : return "3rd";
    case 21 : return "21st";
    case 22 : return "22nd";
    case 23 : return "23rd";
    case 31 : return "31st";
    default : return n+"th";
  }
}

function showDate() {
  var d = new Date();
  var w = new Array("Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur");  
  var m = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  document.write(w[d.getDay()]+"day,<br>"+num2txt(d.getDate())+" "+m[d.getMonth()]+" "+d.getFullYear());
}                

/*
* vote
*
*/

function vote() {
  document.write("<p><font size=-2>Please vote for my site. It's just one click for you and 100 hit's for me...</font></p>");
  document.write('<p><A HREF="http://www.exclusiv-topsites.de/cgi-local/topsites/cheating.cgi?click=990542764=&MEGALISTE-1037K" target="_new">TOP 2500</A></p>');
  
  if (document.URL.match("humor")) {
    document.write('<p><A HREF="http://click.listinus.de/topsite.php?id=18667" TARGET="_new"><IMG SRC="http://icon.listinus.de/topicon.php?id=18667" ALT="Listinus Toplisten" BORDER="0" WIDTH="100" height="50"></A></p>');
  };
}

/*
* Cookie
*
*/

function doCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function setCookie(B, W) {
  var j = new Date();
  var A = new Date(j.getTime()+1000*60*60*24*365);
  doCookie(B, W, A.toGMTString(), "/");
}

function getCookie(B, W) {
  if (document.cookie) {
    var S = document.cookie.indexOf(B+"=");    
    if (S != -1) {
      S += 1+B.length;
      var E = S+1;      
      while (document.cookie.charAt(E) != ";" && E < document.cookie.length) {
        E++;                                       
      }
      W = document.cookie.substring(S,E);
    }    
  } else {
    setCookie(B, W);
  }
  return W;
}      

/*
* getsid()
*
* SessionID
*
*/

function getsid() {
  var c = getCookie("Zaehler", 0);
  if (idc == 0) {
    c++;
    setCookie("Zaehler", c);
    idc = c;
  }
  var i = getCookie("ID", "-");  
  if (i == "-") {
    var n = new Date();
    i = n.valueOf();
    setCookie("ID", i)
  }  
  return i;
}

function writesid() {
  var i = getsid();
  var c = getCookie("Zaehler", 0);
  var o = getCookie("OID", "-");
  //document.writeln(o+"-"+c+"-"+i);
  //document.images[2].src="/name.gif?"+i+"-"+escape(c)+"-"+escape(o);
}

function getidc() {
  return getCookie("Zaehler");
}

function setnewID (n) {
  if (n != "") {
    if (getCookie("OID", "-") == "-") {
      setCookie("OID", getCookie("ID", "-"));
    }
    setCookie("ID", n);
  }
}

function gid () {
  //return unescape(getCookie("ID", "-"));
  return unescape(getsid());
}

function track (p) {
  document.images[p].src=document.images[p].src.replace(/$/, "?"+getsid());
}


/*
* Ticker
*/

var toffset = 0;
var tnews = "";
var tbuf = "";
var twidth = 50;

function initTicker(w, t) {

  tnews = t;  
  for (i = 1; i < w; i++) tbuf += " ";
  twidth = w;
  ticker();
}
  
function ticker() {
    
  tbuf = tbuf + tnews.charAt(toffset);
  if (tbuf.length > twidth) tbuf = tbuf.substr(1, twidth);
  document.TickerForm.Ticker.value = tbuf;
  toffset++; 
  if (toffset >= tnews.length) {
    toffset = 0;
  }

  setTimeout("ticker()", 300)

}
