
var helpWin;
function helpPopup(which) {
	if (which==null) which = "help_contents_help";
	if ((!helpWin)||(helpWin.closed)) helpWin = window.open('help_text.php?help='+which,'_blank','left=50,top=50,width=500,height=320,resizable=1,scrollbars=1');
	else helpWin.location = 'help_text.php?help='+which;
	return false;
}
function getHelp(which) {
	if ((helpWin)&&(!helpWin.closed)) helpWin.location='help_text.php?help='+which;
}
function closeHelp() {
	if (helpWin) helpWin.close();
}

function pic(photo_id)
  {
    document.getElementById('iL').style.top = yMousePos + "px";
    document.getElementById('iL').style.left = xMousePos + "px"; 
    document.getElementById('iL').style.visibility = "visible";
    document.getElementById('iL').innerHTML ='<img align="top" width="50" border="0" src="images/'+photo_id+'.jpg" alt="" />';
  }
	function expand_layer(sid,show) {
		var sbox = document.getElementById(sid);
		var sbox_img = document.getElementById(sid+"_img");
		var sbox_style = sbox.style;
		if (show===true) {
			sbox_style.display='block';
			if (sbox_img) sbox_img.src = plusminus[1].src;
		}
		else if (show===false) {
			sbox_style.display='none';
			if (sbox_img) sbox_img.src = plusminus[0].src;
		}
		else {
			if ((sbox_style.display=='none')||(sbox_style.display=='')) {
				sbox_style.display='block';
				if (sbox_img) sbox_img.src = plusminus[1].src;
			}
			else {
				sbox_style.display='none';
				if (sbox_img) sbox_img.src = plusminus[0].src;
			}
		}
		//if (!lasttab) lasttab=0;
		//if (window.resize_content_div) resize_content_div(lasttab+1);
		return false;
	}
var menutimeouts = new Array();
var currentmenu = null;
/**
 * Shows a submenu
 *
 * @author John Finlay
 * @param string elementid the id for the dom element you want to show
 */
function show_submenu(elementid, parentid, dir) {
	var pagewidth = document.body.scrollWidth+document.documentElement.scrollLeft;
	var element = document.getElementById(elementid);
	if (element && element.style) {
		element.style.visibility='visible';
		if (dir=="down") {
			var pelement = document.getElementById(parentid);
			if (pelement) {
				element.style.left=pelement.style.left;
//				element.style.right=pelement.style.right;
				var boxright = element.offsetLeft+element.offsetWidth+10;
				if (document.all) {
					pagewidth = document.body.offsetWidth;
//					var pomoc = 15;
					if (textDirection=="rtl") element.style.left = (element.offsetLeft-70)+'px';
				}
				else {
//					var pomoc = 70;
					pagewidth = document.body.scrollWidth+document.documentElement.scrollLeft-70;
					if (textDirection=="rtl") {
//						element.style.width = "220px";
						boxright = element.offsetLeft+element.offsetWidth+10;
					}
				}
				if (boxright > pagewidth) {
					var menuleft = pagewidth-element.offsetWidth;
//					var menuleft = menuleft-pomoc;
					element.style.left = menuleft + "px";
				}
			}
		}
		if (dir=="right") {
			var pelement = document.getElementById(parentid);
			if (pelement) {
				element.style.left=(pelement.offsetLeft+pelement.offsetWidth-40)+"px";
			}
		}

		if (element.offsetLeft < 0) element.style.left = "0px";

		//-- make sure the submenu is the size of the largest child
		var maxwidth = 0;
		var count = element.childNodes.length;
		for(var i=0; i<count; i++) {
			var child = element.childNodes[i];
			if (child.offsetWidth > maxwidth+5) maxwidth = child.offsetWidth;
		}
		if (element.offsetWidth <  maxwidth) {
			element.style.width = maxwidth+"px";
		}

		currentmenu = elementid;
	}
	clearTimeout(menutimeouts[elementid]);
	menutimeouts[elementid] = null;
}

/**
 * changes a CSS class for the given element
 *
 * @author John Finlay
 * @param string elementid the id for the dom element you want to give a new class
 * @param string newclass the name of the new class to apply to the element
 */
function change_class(elementid, newclass) {
	element = document.getElementById(elementid);
	if (element) {
		element.className = newclass;
	}
}

function reply(username, subject) {
	window.open('message.php?to='+username+'&subject='+subject, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}
/**
 * Hides a submenu
 *
 * @author John Finlay
 * @param string elementid the id for the dom element you want to hide
 */
function hide_submenu(elementid) {
	element = document.getElementById(elementid);
	if (element && element.style) {
		element.style.visibility='hidden';
	}
	clearTimeout(menutimeouts[elementid]);
	menutimeouts[elementid] = null;
}

/**
 * Sets a timeout to hide a submenu
 *
 * @author John Finlay
 * @param string elementid the id for the dom element you want to hide
 */
function timeout_submenu(elementid) {
	if (menutimeouts[elementid] == null) {
		tout = setTimeout("hide_submenu('"+elementid+"')", 500);
		menutimeouts[elementid] = tout;
	}
}
function delete_photo(id){
	window.open('editphoto.php?command=delete&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
}
function add_photo(n,type){
	window.open('editphoto.php?command=photo&type='+type+'&id='+n , '_blank', 'width=600, height=500, scrollbars=1, resizable=1');
}
function edit_photo(n){
	window.open('editphoto.php?command=edit&id='+n , '_blank', 'width=600, height=500, scrollbars=1, resizable=1');
}
function undo_photo_change(id, type, key){
	window.open('editphoto.php?command=undo&id='+id+'&type='+type+'&key='+key , '_blank', 'width=600, height=500, scrollbars=1, resizable=1');
}
function add_stem(n){
	window.open('edithead.php?command=stem&id='+n , '_blank', 'width=600, height=500, scrollbars=1, resizable=1');
}
function headEdit(id) {
	window.open('edithead.php?command=edit_head&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}
function non_dispenserEdit(id) {
	window.open('editnon.php?command=edit_non&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}
function headDelete(id) {
	if (confirm('Are you sure you want to mark this item for deletion')) {
		window.open('edithead.php?command=delete&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
		return false;
	}
}
function non_dispenserDelete(id) {
	if (confirm('Are you sure you want to mark this item for deletion')) {
		window.open('editnon.php?command=delete&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
		return false;
	}
}
function headEditEdit(id) {
	window.open('edithead.php?command=editheadedit&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}
function collection_add(id){
	window.open('add.php?where=head&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}	
function non_collection_add(id){
	window.open('add.php?where=nondisp&id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}
function edit(id){
	window.open('add.php?where=head&collection_id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}
function non_edit(id){
	window.open('add.php?where=nondisp&collection_id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
	return false;
}
function collectionDelete(id) {
	if (confirm('Are you sure you want to mark this item for deletion')) {
		window.open('add.php?where=head&command=delete&collection_id='+id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
		return false;
	}
}
function undo(type, id){
	if (confirm('Are you sure you want to remove this?')) {
		window.location = document.URL + '&action=' + type + '&edit_id=' + id;
		return false;
	}
}
