

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

	var message="Le courriel est invalide"
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert(message)
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert(message)
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert(message)
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		alert(message)
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert(message)
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		alert(message)
		return false
	}

	if (str.indexOf(" ")!=-1){
		alert(message)
		return false
	}

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(str) == false) {
		alert(message)
		return false
	}

	return true					
}

//Radio Button Validation
//copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
//you may copy this function but please keep the copyright notice with it
function valButton(btn) {
	var cnt = -1;
	for (var i=btn.length-1; i > -1; i--) {
		if (btn[i].checked) {cnt = i; i = -1;}
	}
	if (cnt > -1) return btn[cnt].value;
	else return null;
}

function validate (count) {
	
	for (var i = 1; i <= count; i++) {
		var q = document.getElementsByName('q'+i);
		if (q && valButton(q)==null){
			var message="Une réponse à la question "+i+" est nécessaire";
			alert(message);
			return false;
		}
	}
	
	var courriel = document.form1.courriel;

	if ((courriel.value==null)||(courriel.value=="")){
		var message="Le courriel est invalide"
		alert(message);
		courriel.focus();
		return false;
	}
	if (echeck(courriel.value)==false){
		courriel.value="";
		courriel.focus();
		return false;
	}
	
	var message="Les résultats de votre questionnaire ont été envoyés à votre courriel"
	alert(message);
	return true;
}



