window.addEvent('domready',function(){
	$("save").addEvent("click",function(){
		var checkok = true;
		var checked=new Array();
		$$(".required").each(function(field){
			if(field.className.match("allmost")) {
				field.className.split(" ").each(function(className){
					if(className.match("allmost") && !checked.contains(className)) {
						var boxok=false;
						var boxtype="";
						$$("."+className).each(function(box){
							if(!checked.contains(className)) {
								if(box.checked) {
									boxok=true;
									boxtype="checkbox";
								}
								else if(box.type=="text" && box.value && box.value!="" && box.value!=0) boxok=true;
							}
						});
						checked.push(className);
						if(!boxok){
							
							$$("."+className).getParent().getParent().setStyle("border","1px solid #f00");
							checkok=false;
						}
					}
				});
			}
			else if(!field.value || field.value=="" || field.value==0) {
				field.setStyle("border-color","red");
				checkok=false;
			}
		});
		if(checkok==true) this.form.submit();
		else alert("Les champs marqués d'un * sont obligatoire !");
	});
	$$(".required").addEvent("focus",function(){
		this.setStyle("border-color","");
		this.getParent().getParent().setStyle("border","");
	});
	$$(".cp").addEvent("blur",function(){
		var cp=parseFloat(this.value);
		if(isNaN(cp) || cp<1000 || cp>98000) {
			this.value="";
			alert("Code postal incorrect !");
		}		
	});
	
	$$(".email").addEvent("blur",function(){
		with (this) {
			apos=value.indexOf("@");
			dotpos=value.lastIndexOf(".");
			if (apos<1||dotpos-apos<2) {
				alert("Adresse email incorrecte !");
				value="";
			}
		}	
	});	
});