//################################################
//  add the onload event to create the chat window
//################################################
try {
  //-- create the chat window
  var safari = (navigator.userAgent.indexOf('Safari') != -1);
  if (window.attachEvent) {
	window.attachEvent('onload',createInvalidPop);
  }else if (document.addEventListener) {
	window.addEventListener('load',createInvalidPop,false);
  }
} catch(e) {}


//################################################
//  hide/show the JPOP
//################################################
function hideShowWindow(hide,url) {

	var ref = document.getElementById("iframe1");
	var cover = document.getElementById("coverDiv");
	var bodyRef=(document.compatMode=="CSS1Compat")?document.documentElement:document.body; 

	//ENSURE that we have iframe content to work with before proceeding
	var jPopIsReady = false;
	try{
		var p = ref.contentWindow.document || ref.document;	
		if (typeof ref != "undefined" && typeof cover != "undefined" && typeof bodyRef != "undefined" && typeof p.getElementById('popContent').src != "undefined") {
			jPopIsReady = true;
		}
	}catch(err){
		jPopIsReady = false;
	}

	if (jPopIsReady) {

		  if(hide) {
		    ref.style.display = "none";
		    cover.style.visibility = "hidden";
			cover.style.height = "100%";
		    bodyRef.style.overflow = "auto";
		    //-- add hack to force scrollbars to display in safari
		    var scrollStr = (safari)?"scroll":"auto";
		    bodyRef.style.overflowX = scrollStr;
		    bodyRef.style.overflowY = scrollStr;
    		hideSelects('visible');
		  }
		  else {
		    ref.style.display = "inline";
			cover.style.height = "300%";
		    cover.style.visibility = "visible";
		    bodyRef.style.overflow = "hidden";
		    ref.focus();
		    bodyRef.scrollTop = "0px";
		    bodyRef.scrollLeft = "0px";
			p.getElementById("popContent").src = url;
    		hideSelects('hidden');
		  }
	  	  return true;

	}else{
		return false;
	}
}

//################################################
//  hide all select boxes for IE
//################################################
function hideSelects(action) { 
  if (action!='visible'){action='hidden';}
  if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
    window.status = "hideSelects";
    var sels = document.getElementsByTagName("SELECT");
    for (var S = 0; S < document.forms.length; S++){
      for (var R = 0; R < document.forms[S].length; R++) {
        if (document.forms[S].elements[R].options) {
          document.forms[S].elements[R].style.visibility = action;
        }
      }
    } 
  }
}

//################################################
//
//################################################
function createInvalidPop () {
  var cif = document.createElement("IFRAME");
  cif.id = "iframe1";
  cif.name = "iframe1";
  cif.frameBorder = 0;
  cif.src = location.pathname+"?invalidateme=1";
  cif.allowTransparency = "true";
  cif.className = "iframe1";
  cif.style.width = "500px";
  cif.style.height = "500px";
  cif.style.position = "absolute";
  cif.style.display = "inline";
  cif.style.top = "20px";
  cif.style.left = "20px";
  cif.style.zIndex = "20";
  cif.style.border = "0px";
  cif.style.display = "none";
  document.body.appendChild(cif);
  //-- create cover div for lightbox effect
  var cdiv = document.createElement("DIV");
  cdiv.id = "coverDiv";
  cdiv.style.position = "absolute";
  cdiv.style.top = "0px";
  cdiv.style.left = "0px";
  cdiv.style.zIndex = "1";
  cdiv.style.filter = "alpha(opacity=80)";
  //-- this is only needed for older versions of mozilla
  //cdiv.style.-moz-opacity = ".80";
  cdiv.style.opacity = ".80";
  cdiv.style.background = "#666666";
  cdiv.style.height = "100%";
  cdiv.style.width = "100%";
  cdiv.style.visibility = "hidden";
  document.body.appendChild(cdiv);
}