var msg = '';

function validEmail(adrs) 
{
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(adrs)) {
		valid = true
	} else {
		valid = false
	}
	return (valid)
}

function checkNext(f)
{
	if (document.forms[f].autoNext.value == '') {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function checkBtETP_DATA(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct2" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct3" :
			if (b.form.th_prenom.value.length > 0) {
				b.form.th_prenom.value = b.form.th_prenom.value.toUpperCase();
			} else {
				msg = msg + "Indiquez un prénom\n";
			}
			if (b.form.th_jour.options[b.form.th_jour.selectedIndex].value == '') {
					msg = msg + "Indiquez un jour\n";
			}
			if (b.form.th_mois.options[b.form.th_mois.selectedIndex].value == '') {
				msg = msg + "Indiquez un mois\n";
			}
			if (b.form.th_year.options[b.form.th_year.selectedIndex].value == '') {
				msg = msg + "Indiquez une année\n";
			}
			if (b.form.th_hour.options[b.form.th_hour.selectedIndex].value == '') {
				msg = msg + "Indiquez une heure\n";
			}
			if (b.form.th_min.options[b.form.th_min.selectedIndex].value == '') {
				msg = msg + "Indiquez les minutes\n";
			}
			if (msg.length == 0) {
				if (b.form.th_pays.value == 'FRANCE') {
					b.form.autoNext.value = 'ETP_DPTS';
				} else {
					b.form.autoNext.value = 'ETP_ELOC';
				}
			}
		break;
	}
}

function checkBtETP_DPTS(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct2" :
			radioClic = false;
			e = b.form.th_dpts;
			for (i=0;i<e.length;i++) {
				if (e[i].checked) {
					radioClic = true;
				}
			}
			if (!radioClic) {
				msg = "Vous devez sélectionner un département\n";
			}	
			if (e[3].checked &&  b.form.sl_dpt.options[b.form.sl_dpt.selectedIndex].value == '') {
				msg = msg + "Indiquez le numéro de département\n";
			}
			if (msg.length == 0) {
				if (e[3].checked) {
					b.form.th_dpt.value = b.form.sl_dpt.options[b.form.sl_dpt.selectedIndex].value;
					b.form.autoNext.value = 'ETP_FLOC';
				} 
				if (e[0].checked) {	// DOM TOM
					b.form.th_dpt.value = '97';
					b.form.autoNext.value = 'ETP_FLOC';
				}
				if (e[1].checked) {	// MONACO
					b.form.th_dpt.value = '98';
					b.form.th_local.value = 'MONACO';
					b.form.autoNext.value = next;
				}
				if (e[2].checked) {	// PARIS
					b.form.th_dpt.value = '75';
					b.form.th_local.value = 'PARIS';
					b.form.autoNext.value = next;
				}
			}
		break;
	}
}

function checkBtETP_LOC(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct2" :
			if (b.form.th_local.options[b.form.th_local.selectedIndex].value == '') {
				msg = msg + "Indiquez une ville\n";
			}
			if (msg.length == 0) {
				b.form.autoNext.value = next;
			}
		break;
	}
}



function checkBtETP_VPAY(b,next)
{
	//alert('debut');
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct2" :
			radioClic = false;
			e = b.form.vd_modePay;
			for (i=0;i<e.length;i++) {
				if (e[i].checked) {
					radioClic = true;
				}
			}
			if (!radioClic) {
				msg = "Vous devez sélectionner un mode de paiement\n";
			}
			if (!validEmail(b.form.vd_mail.value)) {
				msg = msg + "Votre adresse email est incorrecte\n";
			}
			//alert(msg);
			if (msg.length == 0) {
				if (e[0].checked) b.form.autoNext.value = 'ETP_VCHQ';
				if (e[1].checked) b.form.autoNext.value = 'ETP_VCBS';
				//if (e[2].checked) b.form.autoNext.value = 'ETP_VTEL';
				b.form.autoNext.value = 'ETP_VCBS'; // Modif FO pour forcer la CB
			}
		break;
	}
}

function checkBtETP_MPAY(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct2" :
			radioClic = false;

			e = b.form.th_modePay;
			for (i=0;i<e.length;i++) {
				if (e[i].checked) {
					radioClic = true;
				}
			}
			if (!radioClic) {
				msg = "Vous devez sélectionner un mode de paiement\n";
			}

			if (!validEmail(b.form.th_mail.value)) {
				msg = msg + "Votre adresse email est incorrecte\n";
			}
			
			if (msg.length == 0) {
				if (e[0].checked) b.form.autoNext.value = 'ETP_FCBS';
				if (e[1].checked) b.form.autoNext.value = 'ETP_FCHQ';
				//if (e[2].checked) b.form.autoNext.value = 'ETP_FTEL';
				b.form.autoNext.value = 'ETP_FCBS'; // Modif FO pour forcer la CB
			}
		break;
	}
}

function checkBtETP_APAY(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct2" :
			if (!validEmail(b.form.th_mail.value)) {
				msg = msg + "Votre adresse email est incorrecte\n";
			}
			
			if (msg.length == 0) {
				b.form.autoNext.value = 'ETP_FTEL';
			}
		break;
	}
}

function checkBtETP_VMEL(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			b.form.autoNext.value = next;
		break;
		case "autoBtAct2" :
			if (!validEmail(b.form.vd_mail.value)) {
				msg = msg + "Votre adresse email est incorrecte\n";
			}
			
			if (msg.length == 0) {
				b.form.autoNext.value = 'ETP_VTEL';
			}
		break;
	}
}

function checkBtETP_MINI(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			if (!validEmail(b.form.th_mail.value)) {
				msg = msg + "Votre adresse email est incorrecte\n";
			}
			
			if (msg.length == 0) {
				b.form.autoNext.value = next;
			}
		break;
	}
}

function checkBtETP_MINISTAR(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			if (!validEmail(b.form.vd_mail.value)) {
				msg = msg + "Votre adresse email est incorrecte\n";
			}
			
			if (msg.length == 0) {
				b.form.autoNext.value = next;
			}
		break;
	}
}

function checkBtETP_RCMD(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			if (b.form.rt_commande.value.length != 9) {
				msg = "Le numéro de commande doit comporter 9 chiffres\n";
			} 
	
			if (isNaN(b.form.rt_commande.value)) {
				msg = msg + "Le numéro de commande ne doit comporter que des chiffres";
			}
	
		if (msg.length == 0) {
			b.form.autoNext.value = next;
		}
		break;
	}
}

function checkBtETP_STAR(b,next)
{
	msg = '';
	switch(b.name) {
		case "autoBtAct1" :
			radioClic = false;
			e = b.form.vd_prenom;
			if(isNaN(e.length)) {	// Il n'y a qu'un radio bouton ce n'est pas un tableau
				lg = 1;
				if (e.checked) {
					radioClic = true;
				}
			} else {
				lg = e.length;
				for (i=0;i<lg;i++) {
					if (e[i].checked) {
						radioClic = true;
					}
				}
			}
			
			if (!radioClic) {
				msg = "Vous devez sélectionner une vedette\n";
			}
			
			if (msg.length == 0) {
				b.form.autoNext.value = next;
			}
		break;
	}
}