DepotImmat.prototype.constructor = DepotImmat;

function DepotImmat(immat,codifvin,is_pro)
{
	this.StatusImmat = (immat!='');
	this.StatusCodifvin = (codifvin!='');
	if (is_pro==null)
		this.is_pro = 0;
	else
		this.is_pro = is_pro;
}

DepotImmat.prototype.check_immat = function(_id) {
	var str = document.getElementById(_id).value.toUpperCase().replace(/[^A-Z0-9]/g,'');
	this.StatusImmat = str.match(/^[0-9]{1,4}[A-Z]{1,3}[0-9][0-9AB][0-9]?$|^[A-Z]{1,2}[0-9]{1,3}[A-Z]$|^[A-Z]{2}[0-9]{3}[A-Z]{2}([0-9][0-9AB][0-9]?)?$/);
	if (str.match(/^[0-9]{1,4}[A-Z]{1,3}[0-9][0-9AB][0-9]?$/))
		this.StatusImmat = this.StatusImmat && (!str.match(/[OUI]/)) && (!str.match(/[0-9]WW[0-9]/));
	if (this.StatusImmat)
	{
		//document.getElementById('debug').innerHTML = (this.StatusImmat?'immat OK':'immat KO')+' - '+(this.StatusCodifvin?'codifvin OK':'codifvin KO');
		document.getElementById('advice_'+_id).className = 'validation-advice';
		document.getElementById(_id).className = document.getElementById(_id).className.replace(/ validation-failed/,'');
	}
	else
	{
		//document.getElementById('debug').innerHTML = (this.StatusImmat?'immat OK':'immat KO')+' - '+(this.StatusCodifvin?'codifvin OK':'codifvin KO');
		document.getElementById('advice_'+_id).className += ' error';
		document.getElementById(_id).className += ' validation-failed';
	}
	if (document.getElementById('VerifLast_'+_id)!=null) document.getElementById('VerifLast_'+_id).className = 'validation-advice';
	if (document.getElementById('WarnImmatCombinaison')!=null) document.getElementById('WarnImmatCombinaison').className = 'DisplayNone';
	return this.StatusImmat;
}

DepotImmat.prototype.check_codifvin = function(_id) {
	if (this.is_pro)
	{
		this.StatusCodifvin = true;
		return true;
	}
	this.StatusCodifvin = document.getElementById(_id).value.toUpperCase().match(/^[A-Z0-9]{3}$/);
	if (this.StatusCodifvin)
	{
		//document.getElementById('debug').innerHTML = (this.StatusImmat?'immat OK':'immat KO')+' - '+(this.StatusCodifvin?'codifvin OK':'codifvin KO');
		document.getElementById('advice_'+_id).className = 'validation-advice';
		document.getElementById(_id).className = document.getElementById(_id).className.replace(/ validation-failed/,'');
	}
	else
	{
		//document.getElementById('debug').innerHTML = (this.StatusImmat?'immat OK':'immat KO')+' - '+(this.StatusCodifvin?'codifvin OK':'codifvin KO');
		document.getElementById('advice_'+_id).className += ' error';
		document.getElementById(_id).className += ' validation-failed';
	}
	if (document.getElementById('VerifLast_'+_id)!=null) document.getElementById('VerifLast_'+_id).className = 'validation-advice';
	if (document.getElementById('WarnImmatCombinaison')!=null) document.getElementById('WarnImmatCombinaison').className = 'DisplayNone';
	return this.StatusCodifvin;
}

DepotImmat.prototype.check_all = function() {
	this.check_immat('w_ve_ve_regnumber');
	this.check_codifvin('IdNum');
	return (this.StatusCodifvin && this.StatusImmat);
}
