/*-------------------------------GLOBAL VARIABLES------------------------------------*/

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

/*-----------------------------------------------------------------------------------------------*/

//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

function getBrowserInfo() {
  if (checkIt('konqueror')) {
    browser = "Konqueror";
    OS = "Linux";
  }
  else if (checkIt('safari')) browser 	= "Safari"
  else if (checkIt('omniweb')) browser 	= "OmniWeb"
  else if (checkIt('opera')) browser 		= "Opera"
  else if (checkIt('webtv')) browser 		= "WebTV";
  else if (checkIt('icab')) browser 		= "iCab"
  else if (checkIt('msie')) browser 		= "Internet Explorer"
  else if (!checkIt('compatible')) {
    browser = "Netscape Navigator"
    version = detect.charAt(8);
  }
  else browser = "An unknown browser";

  if (!version) version = detect.charAt(place + thestring.length);

  if (!OS) {
    if (checkIt('linux')) OS 		= "Linux";
    else if (checkIt('x11')) OS 	= "Unix";
    else if (checkIt('mac')) OS 	= "Mac"
    else if (checkIt('win')) OS 	= "Windows"
    else OS 								= "an unknown operating system";
  }
}

function checkIt(string) {
  place = detect.indexOf(string) + 1;
  thestring = string;
  return place;
}

Event.observe(window, 'load', getBrowserInfo, false);

/*-----------------------------------------------------------------------------------------------*/

function closeLightboxIframe() {
  // see lightbox-iframe.js - activate method
  parent.LBIFRAME_IS_ON = false;

  var selects = parent.document.getElementsByTagName('select');
  for(i = 0; i < selects.length; i++) {
    selects[i].style.visibility = 'visible';
  }


  if(browser == "Internet Explorer"){
    bod = parent.document.getElementsByTagName('body')[0];
    bod.style.height = 'auto';

    htm = parent.document.getElementsByTagName('html')[0];
    htm.style.height = 'auto';
    htm.style.overflow = 'scroll';

    parent.window.scrollTo(0, parent.yPos);
  }

  // see http://www.findmotive.com/2006/08/23/lightbox-using-iframes-instead-of-ajax/
  var t = parent.document.getElementById('lightboxIFrame');
  var i = parent.document.getElementById('overlayIFrame');
  var c = parent.document.getElementById('lbContent');
  c.parentNode.removeChild(c);
  t.style.display = "none";
  i.style.display = "none";
}

// Called within a lightbox iframe, closes it and invokes special 'register success' event on the parent window
function ajax_register_success(){
  // Apparently, this page "deleting itself" ends the current JS execution

  if(parent.registered_success){

    // The parent will have to catch this on their own with a
    // Repeated FREAKING timeout, because there doesn't seem
    // to be any reasonable way to call code on the parent that
    // would allow a new iframe to come up.

    parent.registered_success_flag = true;

    try {
      closeLightboxIframe();
    }
    catch(e){

    }
  }
  else {
    parent.location.reload(true);
  }
}