function OpenForm(strForm,width,height) {
	w = (width) ? width : '800';
	h = (height) ? height : '600';

	var win = window.open(strForm,"","resizable=yes,toolbar=no,scrollbars=yes,status=yes,menubar=yes,fullscreen=no,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
}

function OpenForm2(strForm,width,height) {
	w = (width) ? width : '800';
	h = (height) ? height : '600';

	var win = window.open(strForm,"","toolbar=no,scrollbars=yes,status=yes,menubar=no,fullscreen=no,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
}

function OpenBV(url) {
	var win = window.open(url,"","toolbar=no,scrollbars=no,status=yes,menubar=no,fullscreen=no,height=600,width=800");
  	onerror = null;
 	win.focus();
 	win.moveTo(0, 0);
}

function OpenBVDemo(url) {
	var win = window.open(url,"","toolbar=no,scrollbars=no,status=yes,menubar=no,fullscreen=no,height=590,width=750");
  	onerror = null;
 	win.focus();
 	win.moveTo((top.screen.width-750)/2,(top.screen.height-590)/2)
}

function OpenDoc(url) {

	w = 1000;
	h = 600;

	var win = window.open("/stat/stat_doc.aspx?doc=" + url, "", "resizable=yes,toolbar=yes,status=yes,menubar=yes,fullscreen=no,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2);
 	
}

function OpenLink(identifiant) {

	w = 600;
	h = 490;

	var win = window.open("/redirectToUrl.aspx?l1=" + identifiant, "", "resizable=yes,toolbar=yes,status=yes,menubar=yes,fullscreen=no,scrollbars=yes,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2);

}

function ArticlePrint(url) {

	w = 750;
	h = 600;

	var win = window.open(url, "", "toolbar=no,status=yes,scrollbars=yes,menubar=yes,fullscreen=no,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	win.moveTo(0,0);
 	
}

function OpenWindow(url) {

	w = 750;
	h = 600;

	var win = window.open(url, "", "toolbar=no,status=yes,scrollbars=yes,menubar=yes,fullscreen=no, resizable=yes,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2);
}

function ValidForm(){
	
	oForm = document.forms[0];
	frmName = oForm.name;
	
	// Vérifier si les champs obligatoires ont été remplis
	for (i=0; i < document.forms[frmName].length; ++i){
		
		elem = document.forms[frmName].elements[i];
		
		// traitement des checkbox
		if ((elem.type == 'checkbox' || elem.type == 'radio') && elem.required == 1){
		
			strNomGroupe = document.forms(frmName).elements(i).name;
			booVerif = 0;
			booGroupe = true;
			
			// Vérifier si un des boutons du groupe est sélectionné
			while (booGroupe){
				if (document.forms(frmName).elements(i).checked){
					booVerif = 1;
				}
				i++;
				// Vérifier si le prochain élement fait partie du groupe
				if (strNomGroupe != document.forms(frmName).elements(i).name){
					booGroupe = false;
					--i;
				}
			}

			// Sortir de la boucle for si aucune sélection	pour le groupe
			if (booVerif == 0){
				elem.focus();
				alert('Le champ ' + elem.alias + ' est obligatoire');
				return
			}

		}
		
		if (elem.required == 1 && elem.value == 0){
			elem.focus();
			alert('Le champ ' + elem.alias + ' est obligatoire');
			return;
		}
		
		if (elem.data == 'mail')
		{
			if (!checkMail(elem))
			{
				alert('Le champ ' + elem.alias + ' est incorrecte');
				elem.focus();
				return;
			}
		}
	}
	/*
	if (ValidMail() == false){
		return;
	}	
	*/
	//oForm.submit();
	__doPostBack('lnkValidForm', '');

}	

//Pre contrôle de l'email
function checkMail(field) {
	var str= field.value;
	var filter = /^.+@.+\..{2,3}$/
	if (filter.test(str))
		return true;
	else
		return false;
}		


function ShowCommunes()
{
	sCommune = document.forms[0].elements['commune'].value;
	
	if (sCommune.length > 0)
	{
		OpenForm('/plafonds/plafonds_communes.aspx?commune=' + sCommune,500,400);
	}
	else
	{
		alert('Vous devez saisir une commune');
	}
	
}

function popupHome(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=250');");
}
