
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 isBrowserSupported() {
  //return false; // Uncomment this line to see "old browser message" in any browser
  // 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 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<strong>*</strong>.  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 6 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 Site Build It!, 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."  Our recommendation?  Upgrade to the latest version of one of the following browsers (the minimum requirement for each browser is in brackets - the latest update is more advanced than that)...</p>' +
  '<ul><li>Firefox (versions 2 and up)</li><li>Internet Explorer (versions 7 and up)</li><li>Safari (versions 3 and up)</li><li>Google Chrome (versions 1 and up)</li><li>Opera (versions 9.5 and up)</li></ul>' +
  '<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.microsoft.com/windows/internet-explorer/">Download the latest version of Internet Explorer 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.google.com/chrome/">Download the latest version of Google Chrome by clicking here</a>.</li>'+
    '<li><a href="http://www.opera.com/">Download the latest version of Opera 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 1, Internet Explorer 6 (or below), Safari 2 (or below), beta versions of Chrome, and Opera 9.4 (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');
}
