if (!w) var w = null;

// -----------------------------------------------------
var popup = null;

function LoginPopUp() {
	
	if(popup) {
		popup.destroy();
	}

	popup = new Window(
		'price_editor', {
			className: 'silver',
			width: 450,
			minHeight: 0,
			height: 100,
			zIndex: 999,
			showEffect: Element.show,
			hideEffect: Element.hide,
			minimizable: false,
			maximizable: false,
			resizable: false,
			runInlineScripts: true,
			title: '<b><font style="font-size: 12px;">ESPACE RESERVE ADHERENTS</font></b>'
		}
	);

	var onCloseObserver = {
		onShow: function(e, w) {
			if (w == popup)
			{
				popup.updateHeight();
			}
		},
		onClose: function(e, w) {
			if (w == popup)
			{		
				popup = null;
			}
		}
	}

	Windows.addObserver(onCloseObserver);

	popup.setDestroyOnClose();

	popup.setAjaxContent('/home/showpopup', { method: 'post'},true);
	
	popup.showCenter();	
	popup.updateHeight();
	
}


function hidePopup(name,id) {
	popup.destroy();
	popup = null;
}


// -----------------------------------------------------
function hideRadioButtons()
{
	window.opener.document.getElementById('document_send_out_1').checked = false;
	window.opener.document.getElementById('document_send_out_2').checked = false;
}

// -----------------------------------------------------
function deleteItem(id)
{
	hide_sendMail();
	document.getElementById(id).parentNode.removeChild(document.getElementById(id));
}

// -----------------------------------------------------
function hideDelIcon()
{
	document.getElementById('del_icon').parentNode.removeChild(document.getElementById('del_icon'));
}

// -----------------------------------------------------
function showDelIcon(item_id)
{
	if (document.getElementById('del_icon')==null) {
	document.getElementById(item_id).innerHTML +=
	"<img id='del_icon' onclick=deleteItem('"+item_id+"') title='Delete' style='cursor: pointer' src='/public/images/admin/delete.png'>";
		olditem = item_id;
	} else {
		if (olditem != item_id) {
			hideDelIcon();
			showDelIcon(item_id);
		}
	}
}

// -----------------------------------------------------
function addSingleItemList(id, parent, item_name, caption)
{
	var value 		=	document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text			=	document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	var single_id	=	item_name+value;
	
	if (document.getElementById(item_name)==null) {
		document.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id='"+item_name+"' onmousemove=showDelIcon('"+item_name+"')>"+
		"<input type=hidden name="+parent+" value="+value+">"+text+"</div>";
	} else {
		alert(caption+' already exists!!!');
	}
}

// -----------------------------------------------------
function addMultiItemList(id, parent, item_name)
{	
	
	var value		=	document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text			=	document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	var multi_id	=	item_name+value;
	
	if (document.getElementById(multi_id)==null) {
		document.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id="+multi_id+" onmousemove=showDelIcon('"+multi_id+"')>"+
		"<input type=hidden name="+parent+"[] value="+value+">"+text+"</div>";
	} else {
		alert(text+' already exists!!!');
	}
}
// -----------------------------------------------------
function document_sort(id, document_search, document_search_theme, search_type)
{
	var value =	document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var value_order_dir = document.getElementById('search_sort_dir').options[document.getElementById('search_sort_dir').selectedIndex].value;
	
	var order_dir = null;
	var order = null;
	
	if (value == 1) { order='document_titre'; }
	if (value == 2) { order='document_insert'; }
	if (value == 3) { order='format_nom'; }
	if (value == 4) { order='origine_nom'; }
	if (value == 5) { order='document_ref_snpa'; }
	if (value == 6) { order='document_emetteur_1'; }
	
		if (value_order_dir==1) { order_dir = 'asc'; } else {order_dir = 'desc'; }
		
		document.location.href = '/admin/document/search?&search_sort='+value+'&search_sort_dir='+value_order_dir+'&document_search='+
			document_search+'&document_search_theme='+document_search_theme+'&search_type='+
			search_type+'&order='+order+'&order_dir='+order_dir;
}

// -----------------------------------------------------
function documentation_sort(id, index, document_search, document_search_theme, search_type)
{
	var value =	document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var value_order_dir = document.getElementById('search_sort_dir').options[document.getElementById('search_sort_dir').selectedIndex].value;

	var order_dir = null;
	var order = null;

	if (value == 1) { order='document_titre'; }
	if (value == 2) { order='document_insert'; }
	if (value == 3) { order='format_nom'; }
	if (value == 4) { order='origine_nom'; }
	if (value == 5) { order='document_ref_snpa'; }
	if (value == 6) { order='document_emetteur_1'; }

	if (value_order_dir==1) { order_dir = 'asc'; } else { order_dir = 'desc'; }
	
	document.location.href = '/documentation/search?index='+index+'&search_sort='+value+'&search_sort_dir='+value_order_dir+'&document_search='+
		document_search+'&document_search_theme='+document_search_theme+'&search_type='+
		search_type+'&order='+order+'&order_dir='+order_dir;
}

// -----------------------------------------------------
function search_by_diffusion(id, parent)
{
	var text = document.getElementById(id).options[document.getElementById(id).selectedIndex].text;

	regexp = new RegExp("\\[.*\\]");
	text = text.replace(regexp,"");

	window.opener.document.location.href='/admin/document/search?document_search='+text+'&document_search_theme=0&document_search_date=0&search_type=3';
}


// -----------------------------------------------------
function addDocumentationWord(id, parent)
{

	var text	=	document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	
	if (window.opener.document.getElementById('document_search').value == "") {
		window.opener.document.getElementById('document_search').value += text;
	} else {
		window.opener.document.getElementById('document_search').value += ","+text;
	}
}


// -----------------------------------------------------
function addType(id, obj) 
{
	var value = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text  = document.getElementById(id).options[document.getElementById(id).selectedIndex].text;

	if (obj)
	{
		if (obj.getElementById('type_item')==null) {
			 obj.getElementById('type').innerHTML += 
			"<div style='cursor: pointer' id='type_item' onmousemove=showDelIcon('type_item')> <input type=hidden name=type value="+value+
			">"+text+"</div>";
		} else {
			alert('Type already exists!!!');
		}
	}
	else {
		if (document.getElementById('type_item')==null) {
			 document.getElementById('type').innerHTML += 
			"<div style='cursor: pointer' id='type_item' onmousemove=showDelIcon('type_item')> <input type=hidden name=type value="+value+
			">"+text+"</div>";
		} else {
			alert('Type already exists!!!');
		}
	}
}

// -----------------------------------------------------
function addTheme(id, obj)
{
	var value 		= document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text  		= document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	var theme_id 	= "theme_"+value;
	
	if (obj.getElementById(theme_id)==null) {
		obj.getElementById('theme').innerHTML +=
		"<div style='cursor: pointer' id="+theme_id+" onmousemove=showDelIcon('theme_"+value+"')> <input type=hidden name=theme[] value="+value+
		">"+text+"</div>";
	} else {
		alert(text+' already exists!!!');
	}
}

// -----------------------------------------------------
function addSnpaDocument(id, obj)
{
	var value		= document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text			= document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	var snpa_id		= "snpa_document_"+value;
	
	if (obj.getElementById(snpa_id)==null) {
		obj.getElementById('snpa_documents').innerHTML +=
			"<div style='cursor: pointer' id="+snpa_id+" onmousemove=showDelIcon('snpa_document_"+value+"')> <input type=hidden name=snpa_document[] value="+value+
			">"+text+"</div>";
	} else {
		alert(text+' already exists!!!');
	}
}

// -----------------------------------------------------
function addGroupe(id, obj)
{
	var value 		= document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text  		= document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	var groupe_id 	= "groupe_"+value;
	
	if (obj.getElementById(groupe_id)==null) {
		obj.getElementById('group').innerHTML += 
			"<div style='cursor: pointer' id="+groupe_id+" onmousemove=showDelIcon('groupe_"+value+"')> <input type=hidden name=groupe[] value="+value+">"+
			text+"</div>";
	} else {
		alert(text+' already exists!!!');
	}
}

// -----------------------------------------------------
function addSingleItem(value, text, parent, item_name, caption, obj)
{
	var single_id	=	item_name+value;
	
	if (obj.getElementById(single_id)==null) {
		obj.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id='"+single_id+"' onmousemove=showDelIcon('"+single_id+"')>"+
		"<input type=hidden name="+parent+"[] value="+value+">"+text+"</div>";
	} else {

	}
}

// -----------------------------------------------------
function addContact(obj)
{

	var id 		= obj.options[obj.selectedIndex].value;

	var arr = document.getElementsByName('contact_id_'+id);
	for (var i=0;i<arr.length;i++)
	{
		var p = arr[i].value.split("|");
		addSingleItem(p[0], p[1], 'agenda_contacts','agenda_contact_','',window.opener.document);
	}
	
}

// -----------------------------------------------------
function addDocumentContact(obj)
{

	var id 		= obj.options[obj.selectedIndex].value;

	var arr = document.getElementsByName('contact_id_'+id);
	for (var i=0;i<arr.length;i++)
	{
		var p = arr[i].value.split("|");
		addSingleItem(p[0], p[1], 'document_contacts','document_contact_','',window.opener.document);
	}
	
}

// -----------------------------------------------------
function addMultiItemListByObj_doc_compl(parent, item, id, titre, obj)
{
	var multi_id = item+'_'+id;
	
	if (obj.getElementById(multi_id) == null) {
		obj.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id="+multi_id+" onmousemove=showDelIcon('"+multi_id+"')>"+
			"<input type=hidden name=document_complementaires[] value="+id+">"+titre+"</div>";
	} else {
		alert(titre+' already exists!!!');
	}
}

// -----------------------------------------------------
function addMultiItemListByObj_doc_peres(parent, item, id, titre, obj)
{
	var multi_id = item+'_'+id;
	
	if (obj.getElementById(multi_id) == null) {
		obj.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id="+multi_id+" onmousemove=showDelIcon('"+multi_id+"')>"+
			"<input type=hidden name=document_peres[] value="+id+">"+titre+"</div>";
	} else
		alert(titre+' already exists!!!');
}

// -----------------------------------------------------
function addMultiItemListByObj_agenda(parent, item, id, ref_snpa, titre, obj)
{
	var multi_id = item+'_'+id;
	
	if (obj.getElementById(multi_id) == null) {
		obj.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id="+multi_id+" onmousemove=showDelIcon('"+multi_id+"')>"+
			"<input type=hidden name=snpa_document[] value="+id+">"+ref_snpa+"&nbsp;&nbsp;&nbsp;"+titre+"</div>";
	} else {
		alert(titre+' already exists!!!');
	}
}

// -----------------------------------------------------
function addMultiItemListByObj_new(parent, item, id, titre, obj)
{
	
	var multi_id = item+'_item_'+id;
	
	if (obj.getElementById(multi_id) == null) {
	obj.getElementById(parent).innerHTML +=
	"<div style='cursor:pointer' id="+multi_id+" onmousemove=showDelIcon('"+multi_id+"')>"+
		"<input type=hidden name="+parent+"[] value="+id+">"+titre+"</div>";
	} else {
		alert(titre+' already exists!!!');
	}
}

// -----------------------------------------------------
function addMultiItemListByObj(id, parent, item_name, obj)
{
	var value		=	document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text			=	document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	var multi_id	=	item_name+value;
	
	if (obj.getElementById(multi_id)==null) {
		obj.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id="+multi_id+" onmousemove=showDelIcon('"+multi_id+"')>"+
		"<input type=hidden name="+parent+"[] value="+value+">"+text+"</div>";
	} else {
		alert(text+' already exists!!!');
	}
}

// -----------------------------------------------------
function addSingleItemListByObj(id, parent, item_name, caption, obj)
{
	var value 		=	document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var text			=	document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
	var single_id	=	item_name+value;
	
	if (obj.getElementById(item_name)==null) {
		obj.getElementById(parent).innerHTML +=
		"<div style='cursor:pointer' id='"+item_name+"' onmousemove=showDelIcon('"+item_name+"')>"+
		"<input type=hidden name="+parent+" value="+value+">"+text+"</div>";
	} else {
		alert(caption+' already exists!!!');
	}
}

function jswindow_search(url) {
	hide_sendMail();
	w = window.open(url,'popup','width=400,height=410,menubar=no,location=no,resizable=yes,scrollbars=no,status=no,left=800');
	w.focus();
}

function jswindow(url) {
	hide_sendMail();
	w = window.open(url,'popup','width=250,height=295,menubar=no,location=no,resizable=yes,scrollbars=no,status=no,left=800');
	w.focus();
}

function jswindowdoc(url) {
	w = window.open(url,'popup','width=250,height=295,menubar=no,location=no,resizable=yes,scrollbars=no,status=no,left=800');
	w.focus();
}
