// CHECK FORM 2.1
var f
var C_All = false
var C_Champs = new Array()
var C_Boutons = new Array()
var C_Radios = new Array()
var C_Mail = new Array()
var C_Tel = new Array()
var C_Num = new Array()
var C_Size = new Array()
var C_Url = ""

function Alerte(Qui,Msg){
alert(Msg)
f[Qui].focus()
}

function AlerteRadio(Qui,Msg){
alert(Msg)
f[Qui][1].focus()
f[Qui][1].checked=true
}

function chkMail(e){
if (f[C_Mail[e]].value.length > 0){
	s = f[C_Mail[e]].value.split(/@/);
	if((s.length != 2) || s[0] == '' || s[1] == ''){ Alerte(C_Mail[e],'Invalid e-mail address.\nPlease type in a valid e-mail address.\n\nEx: \"User@Domain\".');  return(false)}
}
return(true)
}


function chkNum(e){
T = C_Num[e][0]
n = f[T].value.length
if (n>0) {
for(i=0;i<n;i++)
{
	s = f[T].value.charAt(i);
	if (!((s >= 0) && (s <= 9)))
	{
	Alerte(T,'Invalid '+C_Num[e][1]+'\n\nPlease include only numbers.');
	return(false);
	}
}
if (!chkSize(T,C_Num[e][1],C_Num[e][2])) return(false)
}
return(true);
}


function chkTel(e){
T = C_Tel[e][0]
n = f[T].value.length
if (n>0) {
for(i=0;i<n;i++)
{
	s = f[T].value.charAt(i);
	if( !((s >= 0) && (s <= 9)) && (s != ' ') && (s != '-') && (s != '+') && (s != '.')
	&& (s != '/') && (s != '(') && (s != ')'))
	{
	Alerte(T,'Error !\nInvalid '+C_Tel[e][1]+'. \n\nPlease include only numbers, spaces, brackets, "/", "-", "." and "+".');
	return(false);
	}
}
if (!chkSize(T,C_Tel[e][1],C_Tel[e][2])) return(false)
}
return(true);
}


function chkSize(Nom,Champ,Size){
if (f[Nom].value.length<Size) { Alerte(Nom,'Please, type at least '+Size+' characters in the '+Champ+' field.'); return(false) }
return(true)
}


function chkChamps(e){
n = C_Champs[e].length
for (i=1;i<n;i++) if (f[C_Champs[e][i]].value.length==0) { Alerte(C_Champs[e][i],C_Champs[e][0]); return(false) }
return(true)
}


function chkAll(){
n = f.length
for (i=0;i<n;i++) if (f[i].value=="") { Alerte(i,"Please fill out all the fields."); return(false)}
return(true)
}


function chkBoutons(e){
n = C_Boutons[e].length
for (i=1;i<n;i++) if (!f[C_Boutons[e][i]].checked) { Alerte(C_Boutons[e][i],C_Boutons[e][0]); return(false) }
return(true)
}


function chkRadios(e){
n = C_Radios[e][1].length
n = f[C_Radios[e][1]].length
for (i=0;i<n;i++)
	{
	if (f[C_Radios[e][1]][i].checked)
		{
		return(true);
		}
	}
AlerteRadio(C_Radios[e][1], C_Radios[e][0]);
return(false)
}


function checkform(ff){
f=ff
if (C_All) if (!chkAll()) return(false)
if ((nc = C_Champs.length)>0) { for (j=0;j<nc;j++) { if (!chkChamps(j)) return(false) } }
if ((nc = C_Mail.length)>0) { for (j=0;j<nc;j++) { if (!chkMail(j)) return(false) } }
if ((nc = C_Tel.length)>0) { for (j=0;j<nc;j++) { if (!chkTel(j)) return(false) } }
if ((nc = C_Num.length)>0) { for (j=0;j<nc;j++) { if (!chkNum(j)) return(false) } }
if ((nc = C_Size.length)>0) { for (j=0;j<nc;j++) { if (!chkSize(C_Size[j][0],C_Size[j][1],C_Size[j][2])) return(false) } }
if ((nc = C_Boutons.length)>0) { for (j=0;j<nc;j++) { if (!chkBoutons(j)) return(false) } }
if ((nc = C_Radios.length)>0) { for (j=0;j<nc;j++) { if (!chkRadios(j)) return(false) } }
if (C_Url!="") { setTimeout('window.location = C_Url',1500) }
return(true)
}