var savedomain;
var savepath; 
var timerID;
var timerset=false;
var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;

function getWHCookieHeight(wh)
{
  if (wh == null) return null;
  var a = "h=";
  var s = wh.indexOf(a);
  if (s < 0) return null;
  return wh.substring(s+2, wh.length);
}

function getWHCookieWidth(wh)
{
  if (wh == null) return null;
  var a = "w=";
  var s = wh.indexOf(a);
  if (s < 0) return null;
  var e = wh.indexOf("&", s+2);
  if (e < 0) return null;
  return wh.substring(s+2, e);
}

function getCookieByName(n) {
  var a = n + "=";
  var al = n.length;
  var s = document.cookie.indexOf(a);
  if (s < 0) return null;
  var e = document.cookie.indexOf(";", s+al);
  if (e > 0) {
     return document.cookie.substring(s, e);
  } else {
     return document.cookie.substring(s);
  }
}

function handleResize() 
{
  if (savedomain != null && savepath != null) {
    if (isMinNS4) {
      setWHCookie(savedomain, savepath);
    }
    if (isMinIE4) {
      if (timerset == true) {
        window.clearTimeout(timerID);
      }
      timerID = setTimeout('setWHCookie(savedomain, savepath)', 1000);
      timerset = true; 
    }
  }
}

function ourOnload() 
{
  if (isMinNS4) {
    window.captureEvents(Event.RESIZE);
    window.onresize = handleResize;
  }
  if (isMinIE4) {
    window.onresize = handleResize;
  }
}

function setWHCookie(domain, path) 
{
  savedomain = domain;
  savepath = path;
  window.onload=ourOnload;
  if (!isMinIE4 && !isMinNS4) {
    return;
  }
  var wh = getCookieByName("WH");
  var cookiedh = getWHCookieHeight(wh);
  var cookiedw = getWHCookieWidth(wh);
  var currh = 0;
  var currw = 0; 
  if (isMinIE4) { 
    currh = document.body.offsetHeight;
    currw = document.body.offsetWidth;
  } else {
    currw = window.innerWidth;
    currh = window.innerHeight;
  }
  var dowh = false;
  if ((currh != cookiedh || currw != cookiedw) && (currh != null && currw != null)) {
    dowh = true; 
  }
  if (dowh) {
    wh = "WH=" + "w=" + currw + "&" + "h=" + currh ;
    wh += (path? ("; path=" + path) : "");
    wh += (domain? ("; domain=" + domain) : "");
    document.cookie = wh;
  }
  timerset = false; 
}
window.onload=ourOnload;


