/* All content copyright © 2003 Tatler Software. */

var Opera = (navigator.userAgent.indexOf("Opera") != -1);
var Opera7  = (parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf("Opera")+6)) >= 7);
var NS45    = (NS4 && (parseFloat(navigator.appVersion) >= 4.5));
var isDHTML = (NS4 || IE4 || DOM || Opera7);
var homStat = "Return home";
var galStat = "View report gallery";
//var capStat = "View screen captures";
var demStat = "Run online demo";
var verStat = "Version features and fixes";
//var newStat = "New features coming soon";
var dwnStat = "Product downloads";
var purStat = "Purchase license key";
var sptStat = "FAQs and support";
var manStat = "View the User's Guide";
var feeStat = "Contact Tatler Software";
var mgaStat = "Manage your account";
var tgtFram = "_parent,_self,_top";
var cnt = sum = 0;
var win = window; 
var navRdy,moDelay,lastID,iniChk,focFld,docref;

function navLink(txt,lnk) {
  if (txt || lnk) window.status = (window[txt+'Stat']) ? eval(txt+'Stat') : lnk.href;
  else window.status = "";
  return true;
}

function getBgColor(id) {
  var style = (document.classes) ?  document.classes[id].all : null;
  var bgCol = (style) ? style.backgroundColor : "transparent";
  return bgCol;
}

function getOffset(el) {
  var offset = new Array(0,0);
  while (el) {
    offset[0] += el.offsetLeft;
    offset[1] += el.offsetTop;
    el = el.offsetParent;
  }
  return offset;
}

function getCoords(img) {
  var imgObj = document.images[img];
  if (imgObj && imgObj.y) {
    var coords = new Array(0,0);
    coords[0] = document.images[img].x;
    coords[1] = document.images[img].y;
  }
  else coords = getOffset(imgObj);
  return coords;
}

function loadPage(url,tgt,win) {
//  if (win) {
//    if (window['newWin'] && !newWin.closed && newWin.open) newWin.location.href = url;
//    else newWin = window.open(url,"newWin");
//    setTimeout("if(newWin) newWin.focus()",100);
//  }
  if (win) {
    var obj = window[tgt];
    if (obj && !obj.closed && obj.open) obj.location.href = url;
    else window[tgt] = window.open(url,tgt);
    if(window[tgt] && window.focus) setTimeout("window['"+tgt+"'].focus()",100);
  }
  else if (tgt && tgt != "null") { 
    if (tgt.indexOf("_") != -1) tgt = tgt.substring(1);
    eval(tgt).location = url;
  }
  else document.location = url;
}

function navEvent(lyr,typ,idx) {
  if (!navRdy) return false;
  var ovrDiv = (DOM) ? document.getElementById(lyr+"_Over") : document.all[lyr+"_Over"];
  var lnk = document.links[idx];
  var tgt = lnk.target;
  if (moDelay) clearTimeout(moDelay);
  if (typ == 3) {
    lastEl = (DOM) ? document.getElementById(lyr+"_Down") : document.all[lyr+"_Down"];
    if (lastEl) {
      lastEl.style.visibility = "visible";
      setTimeout('lastEl.style.visibility="hidden"',50);
//      if (tgt == "_blank" || tgt == "new") loadPage(lnk.href,tgt,1);
//      else setTimeout('loadPage("'+lnk.href+'","'+tgt+'")',60);
      if (!tgt || tgtFram.indexOf(tgt) != -1) setTimeout('loadPage("'+lnk.href+'","'+tgt+'")',60);
      else loadPage(lnk.href,tgt,1);
    }
  }
  if (lyr == lastID) return false;
  if (typ == 2) {
    if (ovrDiv) {
      ovrDiv.style.visibility = "visible"
      ovrDiv.style.cursor = (document.all) ? "hand" : "pointer";
      lnk.onmouseover();
    }
    lastID == lyr;
  }
  else {
    if (ovrDiv) {
      var filter = (IE4 && !Opera && ovrDiv.filters.blendTrans);
      if (filter) ovrDiv.filters.blendTrans.apply();
      ovrDiv.style.visibility = "hidden";
      if (filter) ovrDiv.filters.blendTrans.play();
    }
    moDelay = setTimeout('window.status = ""',100);
  }
  return true;
}

function ns4Event(e) {
  if (!navRdy) return false;
  var evt,lyr,num,lnk,tgt;
  evt = e.target;
  lyr = document.layers[evt.name+"_Over"];
  if (lyr) {
    num = evt.name.substring(3);
    lnk = document.links[num];
    lyr.visibility = (e.type == "mouseover") ? "visible" : (e.type == "mouseout") ? "hidden" : "";
    if (e.type == "mouseout") {
      if (lnk.onmouseout) lnk.onmouseout(e);
      else window.status = "";
    }
    else if (e.type == "mouseover") {
      lastID = num;
      if (lnk.onmouseover) lnk.onmouseover(e);
      else window.status = lnk.href;
    }
  }
  else if (e.type == "mousedown") {
    lnk = document.links[lastID];
    tgt = lnk.target;
    lastEl = document.layers['lyr'+lastID+'_Down'];
    lastEl.visibility = "visible";
    setTimeout("lastEl.visibility = 'hidden'",50);
//    if (tgt == "_blank" || tgt == "new") loadPage(lnk.href,tgt,1);
//    else setTimeout('loadPage("'+lnk.href+'","'+tgt+'")',60);
    if (!tgt || tgtFram.indexOf(tgt) != -1) setTimeout('loadPage("'+lnk.href+'","'+tgt+'")',60);
    else loadPage(lnk.href,tgt,1);
    return false;
  } 
  return true;
}

function initWin() {
  winW = (window.innerWidth || (document.body && document.body.clientWidth));
  winH = (window.innerHeight || (document.body && document.body.clientHeight));
}

function initPage() {
  if (iniChk) return;
  iniChk = 1;
  initWin();
  setTimeout("initMenu()",10);
  if (win.focus && win.curPage && document.forms[0]) {
    var el0 = "Account Logon|Create Account|Update Account"; 
    var lic = "Create License|Trial License";
    if (el0.indexOf(curPage) != -1) {
      if (document.forms[0].elements[1] && document.forms[0].elements[1].type.toLowerCase()=="text") focFld = document.forms[0].elements[1];
      if (document.forms[0].elements[0] && document.forms[0].elements[0].type.toLowerCase()=="text") focFld = document.forms[0].elements[0]; 
      if (curPage == "Create Account") docref = document.signup;
      else if (curPage == "Update Account") docref = document.sub1Form;
    }
    else if (lic.indexOf(curPage) != -1) focFld = document.forms[0].elements.r000domain;
    else if (curPage == "Payment") focFld = document.forms[0].elements.cardName; 
    if (focFld) setTimeout("focFld.focus()",100);
  }
}

function getLabels() {
  var j = 0;
  var len = navMenu.length;
  navImg = new Array();
  navLbl = new Array();
  for (var i=0; i<len; i+=4) {
    if (navMenu[i+3] != curPage) {
      navImg[j] = navMenu[i];
      navLbl[j] = navMenu[i+3];          
      j++;
    }
  }
}  

function initMenu(ovr,dwn) {  
  if (!capable || (NS4 && !NS45)) return;
  var lyrHTML,divHTML,lnkHREF,curStyl,visited,bas,cls,lnk,txt,bgC,img,tgt,pos,l,n,v,x,y,z;
  getLabels();
  bas = (initMenu.arguments.length == 0);
  cls = (dwn) ? "Down" : (ovr) ? "Over" : "Link";
  if (!window['sum']) sum = navLbl.length;
  for (var i=0; i<sum; i++) {
    lnk = document.links[i];
    txt = navLbl[i];
    bgC = getBgColor('nav'+cls);
    tgt = (lnk.target) ? ' target="'+lnk.target+'"' : '';
    pos = getCoords(navImg[i]);
    l = "lyr"+i;
    n = (dwn) ? "lyr"+i+"_Down" : (ovr) ? "lyr"+i+"_Over" : "lyr"+i+"_Link";
    z = (dwn) ? 3 : (ovr) ? 2 : 1;
    v = (bas) ? "visible" : "hidden";
    x = (NS4) ? (pos) ? pos[0] : lnk.x : (capable) ? pos[0] : 0;
    y = (NS4) ? (pos) ? pos[1] : lnk.y : (capable && pos[1]) ? pos[1] : (getOffset(lnk).y-5);
    if (NS4) {
      lyrHTML = '<layer id="lyr'+i+'"><table border="0" cellspacing="0" cellpadding="4" width="140"><tr><td><table border="0" cellspacing="1" cellpadding="0" width="100%"><tr><td align="center"><a href="'+lnk.href+'"'+tgt+'" class="nav'+cls+'">'+navLbl[i]+'<\/a><\/td><\/tr><tr><td><\/td><\/tr><\/table><\/td><\/tr><\/table><\/layer>';
      document.layers[n] = new Layer(100);
      var lyr = document.layers[n];
      lyr.x = x;
      lyr.y = y;
      lyr.document.open();
      lyr.document.writeln(lyrHTML);
      lyr.document.close();
      lyr.visibility = v;
      lyr.bgColor = (bgC) ? bgC : null;
      lyr.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN);
      lyr.onmouseover = ns4Event;
      lyr.onmouseout = ns4Event;
      lyr.onmousedown = ns4Event;
    }
    else {
      var navDiv = document.createElement('DIV');
      posX = (navDiv) ? 0 : x; 
      posY = (navDiv) ? 0 : y; 
      lnkHREF  = (bas) ? '<div id="'+l+'"><a class="nav'+cls+'" href="'+lnk.href+'"'+tgt+'">'+navLbl[i]+'<\/a><\/div>' : '<div id="'+l+'" class="nav'+cls+'">'+navLbl[i]+'<\/div>';
      divHTML  = '<div id="'+n+'" class="nav'+cls+'" style="position:absolute; visibility:'+v+';';
      divHTML += ' width:140px; height:auto; left:'+posX+'px; top:'+posY+'px; z-index:'+z+'"';
      divHTML += (!dwn) ? ' onmouseout="navEvent(\''+l+'\',1,\''+i+'\')" onmouseover="navEvent(\''+l+'\',2,\''+i+'\')" onclick="navEvent(\''+l+'\',3,\''+i+'\')">' : '>';
      divHTML += '<table border="0" cellspacing="0" cellpadding="4" width="140"><tr><td><table border="0" cellspacing="1" cellpadding="0" width="100%"><tr><td align="center">'+lnkHREF+'<\/td><\/tr><tr><td><\/td><\/tr><\/table><\/td><\/tr><\/table><\/div>';
      if (navDiv) {
        navDiv.style.position = 'absolute';
        navDiv.style.left = x+'px';
        navDiv.style.top = y+'px';
        navDiv.innerHTML = divHTML;
        document.body.appendChild(navDiv);
      }
      else if (document.body.insertAdjacentHTML) document.body.insertAdjacentHTML('beforeEnd',divHTML);
      curStyl = (lnk.currentStyle) ? lnk.currentStyle.color : null;    
      if (IE4 && !Opera && curStyl) {
        if (bas) {
          visited = (document.styleSheets[0].rules) ? document.styleSheets[0].rules[15].style.color : null; 
          if (visited) {
            if (curStyl != visited) document.all[n].style.filter = "dropShadow(color=#193F53,offX=1,offY=1)"; 
            else document.all[n].style.filter = "dropShadow(color=#193F53,offX=-1,offY=-1)";    
          }
        }
        else if (ovr) document.all[n].style.filter = "dropShadow(color=#193F53,offX=1,offY=1) dropShadow(color=#245B77,offX=-1,offY=-1) blendTrans(duration=0.5)";
      }
    }
    cnt++;
  }
  if (cnt == sum) initMenu(1);
  else if (cnt == (sum * 2)) initMenu(0,1);
  else navRdy = 1;
}

function restore() {
  cnt = sum = 0;  
  initMenu();
}

function resize() {
  if (NS4 && !NS45) return;
  var sizedW = (window.outerWidth) ? window.outerWidth : (document.body.clientWidth) ? document.body.clientWidth : 0;
  var sizedH = (window.outerHeight) ? window.outerHeight : (document.body.clientHeight) ? document.body.clientHeight : 0;
  if (NS45 && winW && winH && (sizedW != winW || sizedH != winH)) setTimeout("restore()",100);
  winW = sizedW;
  winH = sizedH;
}