function loginPopup(url) {
  var login = new FORK.Cookie("loginSBI");
  if (!login.open) {
    window.open(url, 'WhatsHot', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=575,height=595');
    login.open = 1;
    login.store(1, '/');
  }
}

function loginPopupSBI() {
  loginPopup('http://login.sitesell.com/whats-hot-sbi.html');
}

function loginPopup5P() {
  loginPopup('http://login.sitesell.com/whats-hot-5p.html');
}

function isXhrSupported() {
  // IE6 does not have the global XMLHttpRequest object but IE7 does
  // typeof XMLHttpRequest is 'function' in Firefox 3 and 'object' in Safari 3
  return (typeof XMLHttpRequest == 'function' ||
          (typeof XMLHttpRequest == 'object' && XMLHttpRequest));
}

function isJsonSupported() {
  return (typeof JSON == 'object' && JSON);
}

function isBrowserSupported() {
  //return false; // Uncomment this line to see "old browser message" in any browser
  return isXhrSupported() && isJsonSupported();
}

function showUnsupportedBrowserMessage(popup) {
  var mainContentWrapper = document.getElementById('normalContent');
  document.getElementById('fivePillarLogo').style.visibility = "hidden";
  mainContentWrapper.style.display = 'none';
  var div = document.createElement('div');
  div.id = "unsupportedBrowserMessage";
  div.style.textAlign = 'left';
  div.style.padding="5px";
  div.style.marginBottom = div.style.top = "-55px";
  div.style.position = "relative";
  div.innerHTML = 
  '<form action="#" onclick="return false;"><p style="text-align:right;"><input type="submit" value="Continue with login" onclick="hideUnsupportedBrowserMessageAndSubmit(\''+popup+'\');return false;"></p></form>' +
  '<p style="margin-bottom: 12px;"><strong>Dear SBIer,</strong></p>' +
  '<p>You are receiving this (weekly) reminder because you are using an outdated browser. (See the NOTE at the end of this e-mail for details.)</p>' +
  '<p>We all get attached to our browsers and tend to delay upgrading until "later."  But here\'s why this message is important...</p>' +
  '<p>Site Build It! software advances constantly.  To give you <em>fast,</em> cutting edge functionality with the click of a button, and the best user experience possible, our tech team uses advanced JavaScript and Ajax.</p>' +
  '<p>Internet Explorer 7 and other older browsers do not interpret advanced programming well.  Their performance is slow and unstable.  Upgrading will result in fast and stable behavior, not only in SBI!, but in many other advanced programming environments, such as Google AdSense.</p>' +
  '<p>In short, you need what is called a "modern browser" to handle "modern Web software."</p>' +
  '<p>Please upgrade to the latest version of one of the following browsers...</p>' +
  '<ul>'+
    '<li>Firefox</li>' +
    '<li>Google Chrome</li>' +
    '<li>Safari</li>' +
    '<li>Internet Explorer</li>' +
  '</ul>' +
  '<div class="calloutBox">' +
      '<strong>Important Notices:</strong>' +
      '<ol>' +
          '<li>Beginning October 1, 2011, we\'ll follow Google\'s lead. That means that we will  support the current and previous major releases of Chrome, Firefox, Internet Explorer and Safari on a rolling basis. Each time a new version is released, we\'ll begin supporting that version and stop supporting the third-oldest version.</li>' +
          '<li>We recommend that you do NOT use Internet Explorer due its weaker performance, but if you prefer to continue using it, please upgrade to the newest version.</li>' +
      '</ol>' +
  '</div>' +
  '<p>You will rejoice at the difference, not just at SBI!, but at every other site that uses advanced Web programming.  More and more major sites are using this type of programming.  So take advantage of it and upgrade now.</p>' +
  '<p>It\'s easy and simple to do.  You automatically keep all your favorites, for example.  It\'s also easy to switch to a different browser since they all offer the ability to import each other\'s bookmarks/favorites.</p>' +
  '<ul>'+
    '<li><a href="http://getfirefox.com/">Download the latest version of Firefox by clicking here</a>.</li>'+
    '<li><a href="http://www.google.com/chrome/">Download the latest version of Google Chrome by clicking here</a>.</li>'+
    '<li><a href="http://www.apple.com/safari/download/">Download the latest version of Safari by clicking here</a>.</li>'+
    '<li><a href="http://www.microsoft.com/windows/internet-explorer/">Download the latest version of Internet Explorer by clicking here</a>.</li>'+
  '</ul>' +
  '<p>What do you do with all that saved time?  Easy!  Grow your business faster.  After all, time is money.</p>' +
  '<p>All the best,<br>Your SiteSell Support Team</p>' +
  '<hr>' +
  '<p>* NOTE: Outdated browsers are Firefox 3 (or below), Internet Explorer 7 (or below), Safari 3 (or below), and Chrome 11 (or below).</p>' +
  '<form action="#" onclick="return false;"><p style="text-align:center;margin-top:24px;"><input type="submit" value="Continue with login" onclick="hideUnsupportedBrowserMessageAndSubmit(\''+popup+'\');return false;"></p></form>';
  
  mainContentWrapper.parentNode.appendChild(div);
}

function hideUnsupportedBrowserMessageAndSubmit(popup) {
  // document.getElementById('mainContentWrapper').style.display = '';
  // var ubm = document.getElementById('unsupportedBrowserMessage');
  // ubm.parentNode.removeChild(ubm);
  window[popup]();
  document.forms.loginForm.submit();
}

function setButton(button) {
  document.forms.loginForm.elements.button.value = button.value;
}

function login(button, popup) {
  setButton(button);
  var supportCookie = new FORK.Cookie("browserSupport");
  if (!supportCookie.open && !isBrowserSupported()) {
    showUnsupportedBrowserMessage(popup);
    supportCookie.open = 1;
    supportCookie.store(7, '/');
    return false;
  }
  else {
    window[popup]();
    return true;   
  }
}

function login5P(button) {
  setButton(button);
  loginPopup5P();
  return true;
  // Eventually when 5P phasing out IE6 then this function is just the following line.
  //return login(button, 'loginPopup5P');
}

function loginSBI(button) {
  return login(button, 'loginPopupSBI');
}

