function boxopenclose (boxid,contentRequestUri) {
	box = $('box_'+boxid);
	box_custom_open = $('layoutedbox_'+boxid+'_open');
	box_custom_closed = $('layoutedbox_'+boxid+'_closed');

	if (!box && !box_custom_open && !box_custom_closed) {
		// yay box doesnt exist!
		return false;
	}

	if (box_custom_open || box_custom_closed) {
		// custom boxes case
		var newstate = box_custom_open.style.display == 'none' ? "open" : "close";
		if (newstate == 'close') {
			box_custom_open.style.display = 'none';
			box_custom_closed.style.display = 'block';
			updateBoxViewSettings(boxid, newstate);
		} else {
			box_custom_open.style.display = 'block';
			box_custom_closed.style.display = 'none';

			// check if we need to laod the content??
			var contentdivtoupdate = $('updatemyboxcontent_'+boxid);
			if (contentdivtoupdate && contentdivtoupdate.innerHTML == '') {
				new Ajax.Updater(contentdivtoupdate, contentRequestUri, { 
					method: 'post',
					onComplete: function () {
						updateBoxViewSettings(boxid, newstate);
					}					
				});
			} else {
				updateBoxViewSettings(boxid, newstate);
			}
		}

		return false;
	} else {
		// standard boxes case
		if (box.innerHTML == '<div class="menu">&nbsp;</div>' || box.innerHTML == '<DIV class=menu>&nbsp;</DIV>' || box.innerHTML == '') {
			new Ajax.Updater('box_'+boxid, contentRequestUri, { 
				method: 'post',
				onComplete: function () {
					box.toggle();
					$('boxOpenImg_'+boxid).toggle();
					$('boxCloseImg_'+boxid).toggle();
					updateBoxViewSettings(boxid);
				}
			});
		} else {
			box.toggle();
			$('boxOpenImg_'+boxid).toggle();
			$('boxCloseImg_'+boxid).toggle();
			updateBoxViewSettings(boxid);
		}
		return false;
	}
}


function updateBoxViewSettings (currentboxid, boxstatus) {
	if (!boxstatus)	{
		var box = $('box_'+currentboxid);
		boxstatus = (box.visible()?"open":"close");
	} 
	
	new Ajax.Updater('', basehref + 'layout/lib/boxes/save_box_view.comp', { method: 'post',
		parameters: {boxid: currentboxid, boxopen: boxstatus, forumid:forumid }
	});
}
