function $(d){
	return document.getElementById(d).value;
}
function $s(d){
	return document.getElementById(d)[document.getElementById(d).selectedIndex].value;
}

function submitForm(){
	if(validForm()){
	document.forms['fInscription'].submit();
	}
	return false();
}
function validForm(){
	
	var msg ='';
	var email = $('email'); // non vide
	var nom = $('nom'); // non vide
	var prenom = $('prenom');	// non vide	
	

	var dnJour = $s('dnJour'); 
	var dnMois = $s('dnMois');
	var dnAn = $s('dnAn');	
	var code_postal = $('code_postal'); // non vide + 5 max
	var langue_souhaitee = $('langue_souhaitee');// non vide
	var sites_connus = $('sites_connus'); /// non vide
	var deja_suivi_cours = $s('deja_suivi_cours');
	var civilite = '';
	var civ = document.getElementsByName('civilite');
	for(var i=0;i<civ.length;i++){
		if(civ[i].checked){
			civilite = civ[i].value;
			break;
		}
	}
	
	// contrôles
	if(civilite==''){msg+='- civilité non renseignée\n';}
	if(!verifmail(email)){msg += '- Adresse email incorrecte\n';}
	if(nom.length<1){msg+= '- Nom non renseigné\n';}
	if(prenom.length<1){msg+= '- Prénom non renseigné\n';}
	if(code_postal.length<1 ||code_postal.length>5){msg+= '- Code postal erronné\n';}
	if(prenom.length<1){msg+= '- Prénom non renseigné\n';}
	if(dnJour .length<1 || dnMois<1 || dnAn <1){ msg+='- Date de naissance erronée\n';}
	
	if(langue_souhaitee.length<1){msg+= '- Langue souhaitée non renseigné\n';}
	if(deja_suivi_cours.length<1){msg+= '- Avez-vous déjà suivi des cours par Internet ?\n';}
	
	if(sites_connus.length<1){msg+= '- De quel site de cours en ligne\navez-vous déjà entendu parler ?\n';}
	if(msg!=''){
		alert(msg);
		return false;
	}
	else {
		return true; //submit
	}
}


function verifmail(email)
	{
	var isNav = (navigator.appName.indexOf("Netscape") !=-1);
		if (isNav){
		
			// vérif validité email par STRING
            var arobase = email.indexOf("@")
            var point = email.lastIndexOf(".")
            if((arobase < 3)||(point + 2 > email.length) ||(point < arobase+4)) { 
              return false;}
            else {                                 	
              return true;}
			}
		else{
			var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/
			return (reg.exec(email)!=null)
		}
}


function demo(url){
	
	options = 'toolbar=no, menubar=no, directories=no, location=no, width=790, height=540';
	if (url.indexOf('chinois')>0){
		options = 'toolbar=no, menubar=no, directories=no, location=no, width=1020, height=620';
	}	
			
	var wDemo = window.open (url,'demonstration',options);
	if (!wDemo){
		alert('un logiciel anti-popup empêche l\'ouverture de la fenêtre de démonstration');
	}	
}
