//' Version :
//' ---------
//'
//' 1.05 / 2009-03-30 / JA => Modif methode BrowserCheck (prise en compte ie8)
//' 1.04 / 2006-11-25 / DB => Modif methode BrowserCheck (prise en compte ie7)
//' 1.03 / 2003-10-03 / PL => Ajout de la classe 'compareNumber' et 'changeUser'
//' 1.02 / 2003-06-12 / PL => Ajout de la classe 'BrowserCheck'
//' 1.01 / 2003-04-15 / PL => Ajout de la classe 'CliCheck'
//' 1.00 / 2003-04-11 / PL => Création

//' Classe BrowserCheck
function BrowserCheck() {
	this.ver		= navigator.appVersion;
	this.agent		= navigator.userAgent;
	this.dom		= document.getElementById ?												1 : 0;
	this.ie4		= (document.all && !this.dom) ?										1 : 0;
	this.ie5		= (this.ver.indexOf("MSIE 5") > -1 && this.dom) ?	1 : 0;
	this.ie6		= (this.ver.indexOf("MSIE 6") > -1 && this.dom) ?	1 : 0;
	this.ie7		= (this.ver.indexOf("MSIE 7") > -1 && this.dom) ?	1 : 0;
	this.ie8		= (this.ver.indexOf("MSIE 8") > -1 && this.dom) ?	1 : 0;
	this.ie			= this.ie4 || this.ie5 || this.ie6 || this.ie7 || this.ie8 ;
	this.mac		= this.agent.indexOf("Mac") > -1 ?								1 : 0;
	this.opera5		= this.agent.indexOf("Opera 5") > -1 ?						1 : 0;
	this.ns6		= (this.dom && parseInt(this.ver) >= 5) ?					1 : 0; 
	this.ns4		= (document.layers && !this.dom) ?								1 : 0;
	this.bw			= (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom);
	return this;
}

//' Classe CliCheck
function CliCheck(pPrefix, pLengthMin, pLengthMax) {
  this.prefix			= pPrefix;
  this.lengthMin		= pLengthMin;
  this.lengthMax		= pLengthMax;
  this.isPrefixValid		= new Function("pCli", "return (pCli.substr(0, this.prefix.length) == this.prefix);");
  this.isLengthValid		= new Function("pCli", "return (pCli.length >= this.lengthMin && pCli.length <= this.lengthMax);");
  this.isForbidden		= new Function("return (this.lengthMin == 0 && this.lengthMax == 0);");
}

//' Contrôle de la saisie du préfixe et de chiffres
function changeCli(pTarget, pPrefix, pRequired) {
	if (pRequired+''	== "undefined") pRequired == false;
	if (pPrefix+''		== "undefined") pPrefix		== "";
	var vValue = pTarget.value;
	if (pRequired) {
		if (vValue.substr(0, pPrefix.length) != pPrefix) {
			pTarget.value = pPrefix;
		}
	}
	else {
		for (var i = 0; i < pPrefix.length && i < vValue.length; i++) {
			if (vValue.substr(i, 1) != pPrefix.substr(i, 1)) {
				if (vValue.length <= pPrefix.length)
					pTarget.value = vValue.substr(0, i);
				else
					pTarget.value = vValue.substr(0, i) + pPrefix.substr(i, 1)+ vValue.substr(i, vValue.length-i);
				break;
			}
		}
	}//'(pRequired)
	field2Number(pTarget);
}
//' Contrôle de la saisie du UserPin
function changeUser(pTarget) {
	if (pTarget.value.charAt(0) == '9') pTarget.value = '';
	field2Number(pTarget);
}
//' Contrôle de la saisie de chiffres
function field2Number(pTarget) {
	var vValue = pTarget.value;
	var vNewValue = "", bConvert = false;
	for (var i = 0; i < vValue.length; i++) {
		var vChar = vValue.charAt(i);
		if (vChar >= '0' && vChar <= '9')
			vNewValue += vChar;
		else
			bConvert = true;
	}
	if (bConvert) pTarget.value = vNewValue;
}
//' Compare 2 nombres, 0 si égals
function compareNumber(pNumber1, pNumber2) {
	var vPrecision = Math.pow(10, 5);
	return Math.round(pNumber1*vPrecision) - Math.round(pNumber2*vPrecision);
}
