function popUpWin(WinURL,w,h) {
  if (! w) {
	w=570;
  } 
  if (! h) {
	h=480;
  }
  w=window.open(WinURL, "Popup","height="+h+",width="+w+",resizable,scrollbars,status");
  w.focus();
  return false;
}

function getCookie(Name) {
  var search = Name + "="
  if (document.cookie.length > 0) { // if there are any cookies
    offset = document.cookie.indexOf(search) 
    if (offset != -1) { // if cookie exists 
      offset += search.length 
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset) 
      // set index of end of cookie value
      if ((end == -1) || (end == "")) // null string is to fix JS bug on NS3.0 Mac
        end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    } else {
      return "";
    }
  } else {
    return "";
  }
}

function setCookie(name, value, expire, path) {
  document.cookie = name + "=" + escape(value)
  + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) +
  ((path) ? "; path=" + path : "");
}

function updateReferrer(r) {
  var expires = new Date();
  cameFrom=getCookie("referrer");
  if (cameFrom == '') {
    if (r == '')
      r = '-';
    expires.setTime(expires.getTime() + (3650 * 24 * 60 * 60 * 1000));
    setCookie("referrer",r,expires,"/");
  }
}

function saveLandingInfo(r,l) {
  var expires = new Date();
  landedAt=getCookie("landing");
  cameFrom=getCookie("referrer");
  if (cameFrom == '') {
    if (l == '')
      l = '-';
	if (r == '')
      r = '-';
    expires.setTime(expires.getTime() + (3650 * 24 * 60 * 60 * 1000));
	setCookie("referrer",r,expires,"/");
    setCookie("landing",l,expires,"/");
  }
}

saveLandingInfo(document.referrer,document.URL);
