// put document ID into element with id = {selector_name}_id, document name into element with id = {selector_name}
function document_selected_callback(object_id, object_aggregation, object_name, selector_name)
{
	var input_el = document.getElementById(selector_name);
	var input_id_el = document.getElementById(selector_name+'_id');

	if((input_el == null) || (input_id_el == null)) return false;
	input_id_el.value = object_id;
	input_el.value = object_name;
	return true;
}

// create single option in <select> element with id = {selector_name}, document ID is value, document title is option text
function document_selected_callback_option(object_id, object_aggregation, object_name, selector_name)
{
	var select_el = document.getElementById(selector_name);
	if (select_el == null) return false;
//console.log(object_name, object_id);
	select_el.options[0] = new Option(object_name, object_id, true, true);
    select_el.dispatchEvent(new Event("change"));

	return true;
}


function document_select_show(selector_id, show_marker_selectors, callback)
{
	if (callback == null)
		callback = 'document_selected_callback';
	var selector = document.getElementById(selector_id);
	if (!selector) return false;

//	for(i = 0; i < selector.options.length; ++i)
//		selector.options[i] = null;

	var marker_selector_parameter;
	if(show_marker_selectors == true)
		marker_selector_parameter = 1;
	else
		marker_selector_parameter = 0;

	top.doc_select_win = window.open('/intranet/common/folderstree_popup.php?selector_name='+selector_id
	   +'&document_select=1&marker_select=' + marker_selector_parameter + '&folder_select=0&class_select=0&callback=' + callback, 'doc_select_win',
	        'dependent=yes,width=500,height=430,screenX=200,screenY=300,titlebar=yes, scrollbars=yes,status=yes,resizable=yes');
	return false;
}
