function setAll(fobj, prefix, check) {
	for(var i = 0;i < fobj.elements.length;i++)	{
		if (fobj.elements[i].type == "checkbox" && fobj.elements[i].name.substr(0, prefix.length) == prefix) {
			if (check == 'inverse') { fobj.elements[i].checked = !fobj.elements[i].checked; }
			else { fobj.elements[i].checked = check; }
		}
	}
}

var lightboxOverlayOnclick;
function lightboxOverlay(url) {
	var size = getViewportSize();
	width = size[0]-40;
	height = size[1]-40;
	

	// The lightbox
	Lightbox.position();
	Lightbox.fx.overlay.start(0.8);
	//Lightbox.fx.overlay.set(0.8);
	Lightbox.setup(true);
	lightboxOverlayOnclick = Lightbox.overlay.onclick;
	Lightbox.overlay.onclick = lightboxOverlayClose.bind();

	// FX objects for the resize and fade of the content
	var theBoxFx = new Fx.Styles('TheBox', {duration: 500, transition: Fx.Transitions.linear});
	var theInnerFx = new Fx.Style('TheInnerBox', 'opacity', {duration:250});
	theInnerFx.set(0);
	
	// Default values for TheBox
	var theBox = document.getElementById("TheBox");
	theBox.style.width = "80px";
	theBox.style.height = "80px";
	theBox.style.marginLeft = "-40px";
	theBox.style.marginTop = "-"+((height/2)+5)+"px";
	theBox.style.display = '';
	
	// Some flashy graphics
	theBoxFx.start({
		'width' : [80, width],
		'margin-left' : [-40, ((width/2)-width)-5]
	}).chain(function(){
		theBoxFx.start({
			'height' : [80, height]
		}).chain(function(){
			theInnerFx.start(0, 1);	
		});
	});
	
	// Set Iframe
	var iframe = document.getElementById("TheInnerBox");
	iframe.style.width = width+"px";
	iframe.style.height = height+"px";	
	iframe.src = url;

}

function lightboxOverlayClose() {
	var theBox = document.getElementById("TheBox");
	theBox.style.display = 'none';
	Lightbox.overlay.onclick = lightboxOverlayOnclick;
	Lightbox.overlay.onclick();
}

function getViewportSize() {
    var size = [0, 0];

    if (typeof window.innerWidth != 'undefined') {
        size = [
            window.innerWidth,
            window.innerHeight
        ];
    } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        size = [
            document.documentElement.clientWidth,
            document.documentElement.clientHeight
        ];
    } else {
        size = [
            document.getElementsByTagName('body')[0].clientWidth,
            document.getElementsByTagName('body')[0].clientHeight
        ];
    }
    return size;
}
