function isnbr(str){
	var ch="";
	for(i=0;i<str.length;i++){
		ch=str.substring(i,i+1);
		if(ch!=0 & ch!=1 & ch!=2 & ch!=3 & ch!=4 & ch!=5 & ch!=6 & ch!=7 & ch!=8 & ch!=9){
			return(false);
		}
	}
	return(true);
}
function phnbr(nbr){
	var ch="";
	var chn=0;
	var pls=false;
	for(i=0;i<nbr.length;i++){
		ch=nbr.substring(i,i+1);
		if(ch=="0" | ch=="1" | ch=="2" | ch=="3" | ch=="4" | ch=="5" | ch=="6" | ch=="7" | ch=="8" | ch=="9"){
			chn++;
		}else{
			if(ch!=" "){
				if(chn==0&ch=="+"&!pls){
					pls=true;
				}else{
					return(false);
				}
			}
		}
	}
	return(chn>5);
}
function validate(d,m,y){
	if(y<1930 | y>1994){
		return(false);
	}
	b=(!(y%100==0) & (y%4==0));
	d31=(m==1 | m==3 | m==5 | m==7 | m==8 | m==10 | m==12);
	d30=(m==4 | m==6 | m==9 | m==11);
	return((d31 & d<32 & d>0)|(d30 & d<31 & d>0)|(b & m==2 & d<30 & d>0)|(!b & m==2 & d<29 & d>0));
}
function ckml(mail){
	if(mail==""){
		return("insert your E-mail");
	}else{
		tst=0;
		for(i=0;i<mail.length;i++){
			ch=mail.substring(i,i+1);
			switch(tst){
			case 0:
				if(ch!="." & ch!="@"){
					tst=1;
				}else{
					tst=-1;
				}
			break;
			case -1:
				return("insert a valid E-mail");
			break;
			case 1:
				if(ch=="@"){
					tst=2;
				}
			break;
			case 2:
				if(ch!="." & ch!="@"){
					tst=3;
				}else{
					tst=-1;
				}
			break;
			case 3:
				if(ch=="."){
					tst=4;
				}else{
					if(ch=='@'){
						tst=-1;
					}
				}
			break;
			case 4:
				if(ch!="." & ch!="@"){
					tst=5;
				}else{
					tst=-1;
				}
			break;
			case 5:
				if(ch=="@"){
					tst=-1;
				}else{
					if(ch=="."){
						tst=4;
					}
				}
			break;
			}
		}
		if(tst!=5){
			return("insert a valid E-mail");
		}
	}
	return("valid");
}

function chck(){
	var ok;
	var message;
	if(!window.fields){
		return(true);
	}
	if(fields["obligation"]){
		ok=true;
		for(i=0;i<fields["obligation"].length&ok;i++){
			if(window.document.getElementById(fields["obligation"][i]["id"]).value==""){
				message="fill the "+fields["obligation"][i]["name"]+" field";
				window.document.getElementById(fields["obligation"][i]["id"]).focus();
				ok=false;
			}
		}
		if(!ok){
			alert(message);
			return(false);
		}
	}
	if(fields["email"]){
		ok=true;
		for(j=0;j<fields["email"].length&ok;j++){
			if(ckml(window.document.getElementById(fields["email"][j]["id"]).value)!="valid"){
				message=ckml(window.document.getElementById(fields["email"][j]["id"]).value)+" in the "+fields["email"][j]["name"]+" field";
				window.document.getElementById(fields["email"][j]["id"]).focus();
				ok=false;
			}
		}
		if(!ok){
			alert(message);
			return(false);
		}
	}
	if(fields["password"]){
		ok=true;
		for(i=0;i<fields["password"].length&ok;i++){
			if(window.document.getElementById(fields["password"][i][1]["id"]).value.length<fields["pass_length"]){
				ok=false;
				message="the "+fields["password"][i][1]["name"]+" must have more than "+(fields["pass_length"]-1)+" character";
				window.document.getElementById(fields["password"][i][1]["id"]).focus();
			}else	if(window.document.getElementById(fields["password"][i][1]["id"]).value!=window.document.getElementById(fields["password"][i][2]["id"]).value){
				message="the "+fields["password"][i][1]["name"]+" and "+fields["password"][i][1]["name"]+" are not the same";
				window.document.getElementById(fields["password"][i][2]["id"]).focus();
				ok=false;
			}
		}
		if(!ok){
			alert(message);
			return(false);
		}
	}
	if(fields["phone"]){
		ok=true;
		for(j=0;j<fields["phone"].length&ok;j++){
			if(!phnbr(window.document.getElementById(fields["phone"][j]["id"]).value)==true){
				message="the "+fields["phone"][j]["name"]+" field must be a correct phone number";
				window.document.getElementById(fields["phone"][j]["id"]).focus();
				ok=false;
			}
		}
		if(!ok){
			alert(message);
			return(false);
		}
	}
	return(true);
}