/*
 *		D2 - javascript for node editing - (C) 1999 Tuomas Salo
 *		Tuomo sääti ikkunoiden korkeuksia 31.10.2003
 *		[exxon]
 */


	function open_tree(num,tpl) {
		
		var n = window.open('/mp/tree?activenode=' + num +
												'&showactive=1&grantmask=1' +
												'&OPEN=' + num + '&tpl=' + tpl,
												'',
												'width=600,height=500,scrollbars=yes,resizable=yes');
		n.focus();
	}

	function open_node_edit() {
		
    var args = open_node_edit.arguments;
			
		var num = args[0]; // the form object
		var type = args[1];
		var params = '';
		if(args.length>2) {
			params = '&' + args[2];
		}
		
		window.POPUP_PROPERLY_CLOSED=1;

		 win('/mp/u?A=EDIT&num='+num+'&TYPE='+type+params,
			 'TOKEN' + num,
             634,
             570,
             'scrollbars=yes,resizable=yes');

//		var n = window.open('/mp/u?A=EDIT&num='+num+'&TYPE='+type+params,
//												'',
//												'width=634,height=517,scrollbars=yes,resizable=yes');
//		n.focus();
	}

	function new_node() {
		
		// If the user creates a new node, then clicks the close button on the
		// node edit window, we must destroy the newly-created node. First set
		// POPUP_PROPERLY_CLOSED to zero. The ensure_proper_closing() function is
		// triggered in popup window's onUnload event. If the popup window is
		// closed properly (that is, by clicking one of the buttons down there),
		// POPUP_PROPERLY_CLOSED will be true.

    var args = new_node.arguments;
			
		var dd = args[0]; // the dropdown
		var extra_args = args[1];
		
    if(!extra_args) {
      extra_args='';
    } else {
      extra_args = '&' + extra_args;
    }


		window.POPUP_PROPERLY_CLOSED=0;	// Will be set by buttons().
		window.POPUP_NUM=0;							// Will be set in the popup window.


		var s=dd;


		// Vanhantyyppinen
		if(dd.options) {
			s = dd.options[dd.selectedIndex].value;
			dd.selectedIndex = 0;
		}

		if(s=='')
			return false;

		var parent = s.substring(0,s.indexOf(','));
		var type = s.substring(s.indexOf(',')+1);
		
		var n = window.open('/mp/u?A=NEW&num='+parent+'&TYPE='+type+extra_args,
												'',
												'width=634,height=570,scrollbars=yes,resizable=yes');
		n.focus();
		return true;
	}

	function ensure_proper_closing() {
		
		// See new_node().
		
		if(window.POPUP_PROPERLY_CLOSED==1)
			return true;
		document.location.href='/mp/u?A=DEL&num=' + window.POPUP_NUM + '&GOTO=' + escape(document.location.href);
		return true;

	}


