function setCheckboxes(name,action) {

elem = document.getElementsByName(name);

	for (i=0;i<elem.length;i++) {
	document.getElementsByName(name)[i].checked=action;
	}
	
return true;

}

function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
  
}

function Remplace(str,find,rep){
while(str.indexOf(find) > -1){str = str.replace(find,rep)} 
return(str);
}

function PopUpCover(myname,mypict,w,h,features) { 

  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;  

win = window.open('',myname,settings);
win.window.focus();
win.document.write( "<html><head><title>"+name+"</title>\n" );
win.document.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>" );
win.document.write( "<a href='javascript:window.close();'><img src='"+mypict+"' border=0></a>" );
win.document.write( "</body></html>" );
}

function prevWindow(t,w,h,features) {

  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open("",t,settings);
  win.window.focus();

}

function isblank(s) {


for (var i = 0; i < s.length; i++) {
	var c = s.charAt(i);
	
		
	if ((c != ' ') && (c !='\n') && (c != '')) return false;
	}	
	return true;
}
							
//Teste la validite de l'adresse email. La variable email correspond au nom du champ ˆ tester
									
function checkMail(f) {
	var x = $(f).email.value;
	
	if (x) {
	
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) return true;
		else return false;
		}
	else return false;
	
	}




//Teste et envoie un retour si certains champs obligatoires sont vides

function retour_vide(f, field, tr) {
	e = $(f)[field].value;
	
	if ((e == "") || (e == null) || isblank(e)) {
		return tr + '\n';
	}
	
	else return "";
	
	}

function verify(f,type) {
	var retour;
	var empty_fields = "";
	var errors = "";
	form = f.getAttribute('id');
	
	
	empty_fields += retour_vide(form, 'nom', 'Nom');
	empty_fields += retour_vide(form, 'prenom', 'Prenom');
	empty_fields += retour_vide(form, 'email', 'Adresse Email');
	
	if (type == "contact") {
	empty_fields += retour_vide(form, 'destinataire', 'Destinataire');
	empty_fields += retour_vide(form, 'sujet', 'Sujet');
	empty_fields += retour_vide(form, 'message', 'Message');
	}
	
	
	if (!checkMail(form) || retour_vide(form, 'email', 'Adresse Email') != "") {
		errors+= "Adresse Email non valide. \n";
		}
	
	//En cas d'erreur, affiche un message d'alerte.
	
	if (!empty_fields && !errors) {  return true;
	
	
	
	 }
	else {
	
	
	retour = "Le formulaire contient des erreurs. Veuillez les corriger et revalider.\n\n";
	}							
	if (empty_fields) {

	
		retour += "Les champs obligatoires suivants sont vides :\n";
								
		retour += empty_fields + "\n";
		}
	
if (errors) {
	retour += "\n" + errors;
	}
	
if (retour) {
alert(retour);
}

return false;	
}
