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

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

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

			// check if we need to laod the content??
			var contentdivtoupdate = $('#updatemyboxcontent_'+boxid);
			if (contentdivtoupdate.length && (contentdivtoupdate.html() == '' || contentdivtoupdate.html() == null)) {
				$.post(contentRequestUri, function(data){
					contentdivtoupdate.html(data);
					updateBoxViewSettings(boxid, newstate);
				});
			} else {
				updateBoxViewSettings(boxid, newstate);
			}
		}

		return false;
	} else {
		// standard boxes case
		if (box.html() == '<div class="menu">&nbsp;</div>' || box.html() == '<DIV class=menu>&nbsp;</DIV>' || box.html() == '' || box.html() == null) {
			$.post(contentRequestUri, function(data){
				$('#box_'+boxid).html(data);
				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.is(":visible")?"open":"close");
	} 
	$.post(basehref + 'layout/lib/boxes/save_box_view.comp', {boxid: currentboxid, boxopen: boxstatus, forumid:forumid });
}
