function openPopup(url, nom, width, height, scrollbar) {
  options = 'resizable=no,toolbar=no,directories=no,menubar=no,scrollbars='+ scrollbar + ',status=no,screenX=100,screenY=100,top=100,left=100,width='+ width + ',height=' + height;

	var win = window.open(url,nom, options);
	win.close();
	win = window.open(url,nom, options);
}

function openPopupHere( url, nom, width, height, scrollbar )
{
	options = 'resizable=no,toolbar=no,directories=no,menubar=no,scrollbars='+ scrollbar + ',status=no,width='+ width + ',height=' + height;
	options += ',left='+(getXPosCal(nom) - width)+',top='+(getYPosCal(nom) - height);
	var dp = window.open( url, nom, options );
	dp.focus();
}

function getXPosCal(m) {
var im
im = document.images[m]
if(document.all || document.getElementById)	{
	xPos = eval(im).offsetLeft;
	elt = eval(im).offsetParent;
	while (elt != null) {
		xPos += elt.offsetLeft;elt = elt.offsetParent;}
} else {xPos = eval(im).x;}
return (xPos+15);
}

function getYPosCal(m) {
var im
im = document.images[m]
if(document.all || document.getElementById)	{
	yPos = eval(im).offsetTop;
	elt = eval(im).offsetParent;
	while (elt != null) {
		yPos += elt.offsetTop;elt = elt.offsetParent;}
} else {yPos = eval(im).y;}
return yPos;
}


function setFieldValue(value, targetFormName, targetFieldName) {
	document.forms[targetFormName].elements[targetFieldName].value = value;
}

function setSelectValue(val, targetFormName, targetFieldName) {
	var field = document.forms[targetFormName].elements[targetFieldName];
	if ( field.options ) {
		for (i=0; i<field.options.length;i++) {
			if (field.options[i].value == val)
				field.selectedIndex = i ;
		}
	}
}

function setFieldValuePopup(value, targetFormName, targetFieldName) {
  window.opener.setFieldValue(value, targetFormName, targetFieldName);
  window.close();
}

function openCommune(formName, deptFieldName, comFieldName, url, width, height, scrollbar, dispLib) {
	var completeUrl = url + '?dept=' + document.forms[formName].elements[deptFieldName].value;
	completeUrl += '&form=' + formName;
	completeUrl += '&depField=' + deptFieldName;
	completeUrl += '&comField=' + comFieldName;
	completeUrl += '&dispLib=' + dispLib;
	openPopup(completeUrl, 'commune', width, height, scrollbar);
}

function selectAllCheckBoxes(formName) {
	for (i = 0; i < document.forms[formName].length; i++) {
	var e = document.forms[formName].elements[i];
	if (e.type == 'checkbox') {
			e.checked = true;
		}
	}
}

function deselectAllCheckBoxes(formName) {
	for (i = 0; i < document.forms[formName].length; i++) {
	var e = document.forms[formName].elements[i];
		if (e.type == 'checkbox') {
			e.checked = false;
		}
	}
}
