function Form(form){
	
	
	var _this = this;	
	this.form = document.getElementById(form);
	this.field = new Array();
	this.iserror = false;
	this.receivefunction;
	
	this.enter = function(e){
		
		if (e){
			if (e.keyCode == 13){
				_this.send();
			}
		}else{
			if (window.event){
				if (window.event.keyCode == 13){
					_this.send();
				}
			}
		}
		
	}
	
	this.form.onkeypress = this.enter;
		
	this.addField = function(_id,_type,_error){
		
		//alert (this.form.elements[_id].type);
		
		if (_type != "hidden"){
		
			this.form.elements[_id].value = this.form.elements[_id].name;
		}
		
		var value = this.form.elements[_id].value;
		
		if (this.form.elements[_id].value != ""){
			
			this.form.elements[_id].onfocus = function(){
				
				if (this.form.elements[_id].type == "textarea"){
					
					this.form.onkeypress = null
					
				}else{				
					this.form.onkeypress = _this.enter
					
				}
				
				if (this.value == value){
					this.value="";	
				}
				
			}
			
			this.form.elements[_id].onblur = function(){
				
				if (this.value == ""){
					this.value=value;
				}
				
			}
	
			

		}
		
		this.field.push({id:_id,type:_type, value:this.form.elements[_id].value, error:_error});	
	}
	
	this.addPassword = function(_id,_max,_error){
		this.field.push({id:_id,type:"pass",max:_max,error:_error});	
	}
	
	this.addBlocError = function(_id){		
		this.blocError = document.getElementById(_id);
	}
	
	this.addReceiveFunction = function(_function){		
		this.receivefunction = _function;
	}
		
	
	this.isEmail = function(email){
		var format = /^[^@]+@(([\w\-]+\.){1,4}[a-zA-Z]{2,4}|(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5]))$/;		
		return (format.test(email));
	}
	
	this.isEmpty = function (str){
		
		str = str.replace(/ /g,'');
		str = str.replace(/\n/g,'');
		
		if (str == ""){
			
			return false;	
		}else{
			return true;	
		}
	}
	
	this.checkForm = function(){
		
		
		//this.isEmpty(this.form.elements['comments'].value);
		
		this.msg = null;
		
		
		
		for (var i=0; i < this.field.length; i++){
			if (this.field[i].type == "text"){
							
				
				if (!this.isEmpty(this.form.elements[this.field[i].id].value) || this.form.elements[this.field[i].id].value == this.field[i].value){
					this.msg = 	this.field[i].error;
					if (this.field[i].error != ""){
						this.form.elements[this.field[i].id].focus();
					}
					break
				}else if (this.field[i].type == "pass"){
					
					
				}
			}else if(this.field[i].type == "pass"){
				if (this.form.elements[this.field[i].id].value.length<this.field[i].max){
					
					this.msg = 	this.field[i].error;
					this.form.elements[this.field[i].id].focus();
					break;
						
				}
				
			}else if (this.field[i].type == "email"){
				if (!this.isEmail(this.form.elements[this.field[i].id].value)){
					this.msg = 	this.field[i].error;
					this.form.elements[this.field[i].id].focus();
					break
				}
			}else if (this.field[i].type == "list"){
				if (this.form.elements[this.field[i].id].value == "null"){
					this.msg = 	this.field[i].error;
					this.form.elements[this.field[i].id].focus();
					break
				}
			}
		}
		
		if (this.msg){			
			this.iserror = true;
			return false;	
		}else{
			return true;
		}
	}
	
	
	
	
	this.send = function(){
		
		
		
		if (this.checkForm()){
			
			this.sendRequest();
			
			
		}else{
			
			this.displayError(this.msg);
			
		}
		
	}
	
	
	this.displayError = function(msg){
		
		this.blocError.className="error"; 
		this.blocError.innerHTML = msg;

		if (!this.blocError.style.marginTop){
			positionTween = new Tween(this.blocError.style,'marginTop',Tween.regulatEaseOut,-5,10,0.2,'px');
			positionTween.start();
			opacityTween = new OpacityTween(this.blocError,Tween.regulatEaseOut, 0, 100, 0.2);
			opacityTween.start();
			
		}
		
		
		
		
	}
	
	
	this.sendRequest= function(){
		
		var xhr_object = null;

		if(window.XMLHttpRequest)
		   xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
		   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { 
		   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		   return;
		}
				
		var method   = "POST";		
		var filename = "inc/"+this.form.id+".php";	
		var data = "";
		
		for (var i=0; i < this.field.length; i++){
			
				data += (this.field[i].id+"="+this.form.elements[this.field[i].id].value);
				data +="&";
		}
		
		
		xhr_object.open(method, filename, true);
		
		var _this = this;
		
		xhr_object.onreadystatechange = function() {
		   if(xhr_object.readyState == 4) {
			   
			 if (xhr_object.responseText == true){
				_this.receivefunction();		
			 }else{
				_this.displayError(xhr_object.responseText);
			 }
		   }
		}
		
		
		if(method == "POST")
			xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xhr_object.send(data);		

	}

	
	
	
	
	
}