/*
name:   v2.js
desc:   ZonkBoard JavaScript Library
date:   October 19, 2002
update: November 10, 2002
notes:  None.
*/

// Init some globals.
var c;
var d;
var stopped = false;
var gcCount = 0;
var dest;

// Eliminate leading and trailing spaces.
function trim(inputString) {
  s = inputString.toString();
  s = s.replace(/^ +/, '').replace(/ +$/, '');
  return s;
}

// Gets a value from a cookie.
function gv(h) {
  var dc = document.cookie;
  var p = h + "=";
  var j = dc.indexOf("; " + p);
  if (j == -1) {
    j = dc.indexOf(p);
    if (j != 0) return null;
  } else j += 2;
  var end = document.cookie.indexOf(";", j);
  if (end == -1) end = dc.length;
  return unescape(dc.substring(j + p.length, end));
}

// Call the check process, which will set a new cookie if a new messages has been posted.
function gc() {
  if (!stopped) {
    zonkImg = new Image();
    zonkImg.src = "index.cfm?fuseaction=zonk.check&sitename=" + c + "&r=" + Math.random();
    ++gcCount;
    if (gcCount >= 60) stopped = true;
    setTimeout("gc()", 20000);
  }
}

// Check the cookie value.  If it has changes since the timer was started, reload the page.
function cc() {
  if (!stopped) {
    var bd = "index.cfm?fuseaction=zonk." + dest + "&sitename=";
    if (gv("MSG" + c) != d && gv("MSG" + c) != null) {
      if (document.images)
        window.location.replace(bd + c + "&r=" + Math.random());
      else
        window.location.href = bd + c + "&r=" + Math.random();
    }
    else setTimeout("cc()", 2000);
  }
}

// Base function that gets the intelligent refresh going.
function startTimer(a, b, x) {
  c = a;
  d = b;
  b = gv(a);
  gc();
  dest = x;
  cc();
  a = gv(b);
}

// Stops the timer.
function stopTimer() {
  stopped = true;
}

// Checks for an e-mail address.
function checkMail(str) {
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  return filter.test(str);
}

// Clears a form field if the value is the default.
function clearField(fieldname) {
  if (fieldname.defaultValue == fieldname.value) fieldname.value = "";
}

// Puts the default back into a field if it is blank.
function resetField(fieldname) {
  if (fieldname.value == "") fieldname.value = fieldname.defaultValue;
}

// Insert the WMP code so we can get the player ID, if available.
function insertWMP() {
  if (navigator.appName == "Microsoft Internet Explorer")
    document.writeln('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" id="WMP" width="0" height="0"></object>');
  else
    document.writeln('<embed type="application/x-mplayer2" name="WMP" width="0" height="0"></embed>');
}

function NSShow() {
  if (typeof(document.WMP) == "object")
    document.zbform.wmpid.value = document.WMP.GetClientID();
  return;
}

function checkWMP() {
  if (navigator.appName == "Microsoft Internet Explorer")
    if(typeof(document.WMP) == "object" && typeof(document.WMP.ClientID) == "string") document.zbform.wmpid.value = document.WMP.ClientID;
  else setTimeout("NSShow()", 100);
}
