//for SELECT, TEXT TEXTAREA

//----- CONSTRUCTOR -----//
function BaseInput(id)
{
	this.id = id;
	this.value = null;
	this.valid = false;
	
	this.div_error = null;
	this.error = null;
	
	this.min = null;
	this.max = null;
	
	this.minRange = null;
	this.maxRange = null;
}


//----- METHODS -----//
BaseInput.prototype.addError = function(div_error,error)
{
	this.div_error = div_error;
	this.error = error;
}


//----- VERIFY -----//
BaseInput.prototype.verifyEmpty = function()
{
	this.value = $("#" + this.id).val();
	
	if(removeSpaces(this.value) == "")
		this.valid = false;
	else
		this.valid = true;
	
	this.displayMessage(this.valid);
	return this.valid;
}
BaseInput.prototype.verifyLength = function(min,max)
{
	this.min = min;
	this.max = max;
	this.value = $("#" + this.id).val();
	
	if((this.min != null && this.value.length < this.min) || (this.max != null && this.value.length > this.max))
		this.valid = false;
	else
		this.valid = true;
	
	this.displayMessage(this.valid);
	return this.valid;
}
BaseInput.prototype.verifyRange = function(minRange,maxRange)
{
	this.minRange = minRange;
	this.maxRange = maxRange;
	this.value = parseInt($("#" + this.id).val());
	
	if(isNaN(this.value) || (this.minRange != null && this.value < this.minRange) || (this.maxRange != null && this.value > this.maxRange))
		this.valid = false;
	else
		this.valid = true;
	
	this.displayMessage(this.valid);
	return this.valid;
}
BaseInput.prototype.verifyEmail = function()
{
	this.value = $("#" + this.id).val();
	
	if(checkEmail(this.value))
		this.valid = true;
	else
		this.valid = false;
	
	this.displayMessage(this.valid);
	return this.valid;
}


//----- MESSAGE -----//
BaseInput.prototype.displayMessage = function(empty)
{
	var div = $("#" + this.div_error);
	if(empty)
		div.html("");
	else
		div.html(this.error);
}
BaseInput.prototype.hideMessage = function()
{
	this.displayMessage(true);
}


//----- FONCTIONS -----//
//remove the space of a string to be sure it's not only space
function removeSpaces(string)
{
	var result = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++) result += splitstring[i];
	return result;
}