var showEffects=false;
var isie = navigator.appName == 'Microsoft Internet Explorer';
var isie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

function openWindow(url,width,height){
	window.open(url ,"_blank","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+width+",height="+height);
}

function pngFix(){
	fixPNG();
	//For compatibility
}

function fadePurple(){
	var pagesize = getPageSizeWithScroll();
	var windowsize = getWindowSize();
	var fadepurplebg = document.createElement('div');

	fadepurplebg.className = 'fadePurple';
	fadepurplebg.setAttribute('id','fadePurple');
	
	var divheight;
	
	if(pagesize[1]>document.body.offsetHeight)
		divheight = pagesize[1];
	else if (windowsize[1] > document.body.offsetHeight)
		divheight = windowsize[1];
	else
		divheight = document.body.offsetHeight
	
	fadepurplebg.style.height = divheight+'px';

	document.body.appendChild(fadepurplebg)
}


function removefade(){
	if (showEffects){
		new Effect.Fade('fadepurplebg',{duration:1})
		setTimeout("document.body.removeChild(document.getElementById('fadepurplebg'))",2001)
	} else
		document.body.removeChild(document.getElementById('fadePurple'));
}


function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {
		// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		// all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else {
		// works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}     arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);

	return arrayPageSizeWithScroll;
} 
function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth,myHeight);

}

function showPopup (popuptext,nobackfade,notinviewport){	

	var divid = 'lightbox-contianer'
	var handleid = 'hand_'+Math.floor(Math.random()*555)
	
	var lightboxdiv = document.createElement('div');
	var lightboxtopdiv = document.createElement('div');
	var footerdiv = document.createElement('div');
	var content = document.createElement('div');
	var cleardiv = document.createElement('div');
	
	var lnkclose = document.createElement('a');
	
	lightboxdiv.id = 'lightbox-contianer';
	lightboxtopdiv.id = 'lightbox-header';
	footerdiv.id = 'lightbox-footer'
	cleardiv.id = 'clear';
	
	//lightboxtopdiv.setAttribute('align','center');
	//lightboxdiv.setAttribute('align','center');
	
	lightboxdiv.setAttribute('id',divid);
//	lightboxtopdiv.setAttribute('id','lightboxtopdiv');
	
	lightboxdiv.style.top = notinviewport?'20px':f_scrollTop()+20+'px';
	var offset = isie6?0:355;

//	if(isie)
		lightboxdiv.style.left = (offset+getWindowSize()[0]/2-600)+'px';

	lnkclose.setAttribute('href','#');
	lnkclose.onclick =	function(){
							closePopup(divid)
							removefade();
							return false;
						}

	lnkclose.innerHTML='<img style="float:right; top:5px; left:-7px; position:relative; z-index:99999;" src="/images/button-closelightbox.gif" height="23" width="56" alt="Close" />';

	popuptext = popuptext.replace(/x1x/g,"'"+divid+"'")
	content.innerHTML = popuptext;

	lightboxdiv.appendChild(lightboxtopdiv);

	lightboxtopdiv.appendChild(lnkclose);

	lightboxdiv.appendChild(content);

	lightboxdiv.appendChild(footerdiv);
	lightboxdiv.appendChild(cleardiv);

	//Background should already be here by now, but just in case it's not, put it there.
	if(!document.getElementById('fadePurple') && !nobackfade)
		fadePurple();

	hideElements();

	if (showEffects){
		lightboxdiv.style.display = 'none';
		document.body.appendChild(lightboxdiv);
		new Effect.SlideDown(divid,{duration:1})
	} else {
		document.body.appendChild(lightboxdiv);
	}

	var scriptelements = lightboxtopdiv.getElementsByTagName('script');
	for (i =0;i<scriptelements.length;i++)
		eval(scriptelements[i].innerHTML);

	if(notinviewport)
		document.scrollTo(0,0);

	fixPNG();
	
//	new Draggable(divid,{handle: handleid});

}

function closePopup(divid){
	if (showEffects){
		new Effect.SlideUp(divid,{duration:1})
		setTimeout("document.body.removeChild(document.getElementById('"+divid+"'));",2001)
	} else
		document.body.removeChild(document.getElementById(divid));
		
	showElements();
}

function hideElements(){
	if (navigator.appName == 'Microsoft Internet Explorer'){
		var p = document.getElementsByTagName('select');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
		}
		
		p = document.getElementsByTagName('object');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
			p[i].style.width = "0px";
		}
	} else {
		p = document.getElementsByTagName('embed');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
			p[i].style.width = "0px";
		}
	}	
}

function showElements(){
	if (navigator.appName == 'Microsoft Internet Explorer'){
		var p = document.getElementsByTagName('select');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
		}
		
		p = document.getElementsByTagName('object');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
			p[i].style.width = "";
		}
	} else {
		p = document.getElementsByTagName('embed');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
			p[i].style.width = "";
		}
	}
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
