//negor added "howtocheck"
function selectMe(x) {
//temp testing
//alert("intra"+isOK);

hideCLayer();

//negora
if(selectMe.arguments[1]!=null) 
{ // on a un doisieme argument, qui et la fonction de validation
	howtocheck=selectMe.arguments[1];
	document.all['TXT'].onchange=howtocheck;
	toCheck=document.all['TXT'];
//	alert(howtocheck+","+toCheck);
	if(selectMe.arguments[2]!=null)
		minLen=selectMe.arguments[2];
	else minLen=1;
	if(selectMe.arguments[3]!=null)
		maxLen=selectMe.arguments[3];
	else //on a une seule chiffre, on le fait minLen
		maxLen=-1;
}
else 
	{
	howtocheck=empty;
	document.all['TXT'].onchange=howtocheck;
	maxLen=-1;
	minLen=1;
//temp testing
//alert("fara functie"+isOK);
	}
	// on n'a pas une fonction de validation pour le input, alors on le laisse comme ca
//end negora

BD=document.body.clientWidth;

var r=document.body.createTextRange();
r.moveToPoint(window.event.x, window.event.y);

document.all['GETTER'].style.pixelLeft=r.offsetLeft+10+document.body.scrollLeft;
document.all['GETTER'].style.pixelTop=r.offsetTop+15+document.body.scrollTop;
document.all['TXT'].value=x.innerHTML;

a=document.all['GETTER'].style.pixelLeft+document.all['GETTER'].clientWidth-BD;

if(a>0)
	document.all['GETTER'].style.pixelLeft-=a+10;

//document.recalc();
//HD=document.body.clientHeight+document.body.scrollTop;

//alert(document.all['GETTER'].style.pixelTop+document.all['GETTER'].offsetHeight);

if(document.all['GETTER'].style.pixelTop+document.all['GETTER'].offsetHeight>document.body.clientHeight+document.body.scrollTop)
	document.all['GETTER'].style.top=document.all['GETTER'].style.pixelTop-document.all['GETTER'].offsetHeight-r.boundingHeight;

document.all['GETTER'].style.visibility="visible";
document.recalc();
//document.all['TXT'].focus();
document.all['TXT'].select();
el=x;

}

function selectCMe(x,nam) {

hideGLayer();

nnam=nam;

BD=document.body.clientWidth;

var r=document.body.createTextRange();
r.moveToPoint(window.event.x, window.event.y);


document.all['C_GETTER'].style.left=r.offsetLeft+10+document.body.scrollLeft;
document.all['C_GETTER'].style.top=r.offsetTop+15+document.body.scrollTop;

var a=document.all['C_GETTER'].offsetLeft+document.all['C_GETTER'].offsetWidth-document.body.clientWidth;

a=document.all['C_GETTER'].style.pixelLeft+document.all['GETTER'].clientWidth-BD;

if(a>0)
	document.all['C_GETTER'].style.pixelLeft-=a+10;

//document.recalc();
//HD=document.body.clientHeight+document.body.scrollTop;

//alert(document.all['GETTER'].style.pixelTop+document.all['GETTER'].offsetHeight);

if(document.all['C_GETTER'].style.pixelTop+document.all['C_GETTER'].offsetHeight>document.body.clientHeight+document.body.scrollTop)
	document.all['C_GETTER'].style.top=document.all['C_GETTER'].style.pixelTop-document.all['GETTER'].offsetHeight-r.boundingHeight;


n=document.all['CHC'].options.length;

for(i=0;i<n;i++)
{
	document.all['CHC'].options.remove(0);
}

n=document.all[nam].options.length;

for(i=0;i<n;i++)
{
	oOption = document.createElement("OPTION");
	document.all['CHC'].options.add(oOption)
	oOption.innerText = document.all[nam].options(i).innerText;
	
	if(oOption.innerText==x.innerHTML)
		oOption.selected=true;
}

document.all['C_GETTER'].style.visibility="visible";
document.recalc();
//document.all['CHC'].select();
el=x;

}

function hideCLayer()
{
	document.all['C_GETTER'].style.visibility="hidden";
}

function hideGLayer()
{
	document.all['GETTER'].style.visibility="hidden";
}

function setText(x)
{
  x.filters[0].Apply(); 
//negora plus IFul
//toCheck=document.all['TXT'];
//temp testing
//alert("intra in setText"+isOK+"cu functia"+howtocheck);

howtocheck(); // on verifie l'integrité du input quand on fait le submit par "enter"
//temp testing
//alert("am apelat howtocheck:"+howtocheck+"si ie"+isOK);

if(isOK) {
		x.innerHTML=document.all['TXT'].value;
		document.all['_'+x.id].value=document.all['TXT'].value;
		hideGLayer();
	}
	else {
	}

x.filters[0].Play(); 

	return false;
}

function setCText(x,nam)
{

  x.filters[0].Apply(); 

	x.innerHTML=document.all['CHC'].options(document.all['CHC'].selectedIndex).innerHTML;

	n=document.all[nnam].options.length;

	for(i=0;i<n;i++)
	{
  	  document.all[nnam].options(i).selected=document.all['CHC'].options(i).selected;
	}
	hideCLayer();

  x.filters[0].Play(); 
}



function showLayer()
{
				document.all["profile"].style.visibility = "visible";

				screenWidth = document.body.clientWidth + 18;
				document.all['profile'].style.pixelLeft = screenWidth-200;
				document.all['profile'].style.pixelTop = 36;

}
function hideLayer()
{
				document.all["profile"].style.visibility = "hidden";
}

// negora's functions
var toCheck; //l'object sur le quel on fait la verification. ne modifier pas d'ici!!
var isOK; //si la validation a ete succesful ou pas.
var maxLen; //il n'y a pas une limite superrieure -> -1
var minLen; //il n'y a pas une limite inferrieure -> 1

function asignMinMax(argArray)
{
	if(argArray[0]!=null) toCheck=argArray[0];
	//si on a un argument, c'est l'object sur lequel on doit travailler
	if(argArray[1]!=null) minLen=argArray[1];
	if(argArray[2]!=null) maxLen=argArray[2];
	//else maxLen=-1;
	//il n'est pas necessaire de faire le premiere argument maxLen car on envoye 2 parametres de netscape
}

function check_chiffres() // tous les caracteres de la saisie de text sont des chiffres
{
	inType='chiffres';
	asignMinMax(arguments);
	tmp=toCheck.value;
	if(!check_length(tmp,minLen,maxLen,inType)) return isOK;
	i=0;
	while(((tmp.charAt(i)>='0' && tmp.charAt(i)<='9')||(tmp.charAt(i)=='.'))&&i<tmp.length) {
		i++;
	}
	if (i==tmp.length) {
		isOK=true;
		return isOK;
	}
	else {
		toCheck.value="Que des "+inType+" !!";
		alert("Attention, ce champ ne doit comporter que des "+inType+"!!");
		toCheck.select();
		isOK=false;
		return isOK;
	}
}
function check_lettres()
{
	inType='lettres';
	asignMinMax(arguments);
	tmp=toCheck.value;
	if(!check_length(tmp,minLen,maxLen,inType)) return isOK;
	i=0;
	while(!(tmp.charAt(i)>='0' && tmp.charAt(i)<='9')&&i<tmp.length) {
		i++;
	}
	if (i==tmp.length) {
		isOK=true;
		return isOK;
	}
	else {
		toCheck.value="Que des "+inType+" !!";
		alert("Attention, ce champ ne doit comporter que des "+inType+"!!");
		toCheck.select();
		isOK=false;
		return isOK;
	}
}

function check_CAPS() {
	inType='lettres majuscules';
	asignMinMax(arguments);
	tmp=toCheck.value;
	if(!check_length(tmp,minLen,maxLen,inType)) return isOK;
	i=0;
	while(!(tmp.charAt(i)>='0' && tmp.charAt(i)<='9')&&i<tmp.length) {
		i++;
	}
	if ((i==tmp.length)) 
	{
		make_CAPS();
	}
	else {
		toCheck.value="Que des "+inType+" !!";
		alert("Attention, ce champ ne doit comporter que des "+inType+"!!");
		toCheck.select();
		isOK=false;
		return isOK;
	}
}
function check_firstCAPS() {
	inType='lettres';
	asignMinMax(arguments);
	tmp=toCheck.value;
	if(!check_length(tmp,minLen,maxLen,inType)) return isOK;
	i=0;
	while(!(tmp.charAt(i)>='0' && tmp.charAt(i)<='9')&&i<tmp.length) {
		i++;
	}
	if ((i==tmp.length)) {
		tt = tmp.substring(1,tmp.length);
		toCheck.value=tmp.charAt(0).toUpperCase()+tt.toLowerCase();
		isOK=true;
		return isOK;
	}
	else {
		toCheck.value="Que des "+inType+" !!";
		alert("Attention, ce champ ne doit comporter que des "+inType+"!!");
		toCheck.select();
		isOK=false;
		return isOK;
	}
}

function make_CAPS() {
	inType='lettres';
	asignMinMax(arguments);
	tmp=toCheck.value;
	if(!check_length(tmp,minLen,maxLen,inType)) return isOK;
	toCheck.value=tmp.toUpperCase();
	isOK=true;
	return isOK;
}

function check_length(str,min,max,input)
{
	if(min>max&&max>0)
	{
		aux=min;
		min=max;
		max=aux;
	}
	if(min>0&&max<0&&str.length<min)
	{
		alert("Attention, ce champ ne doit comporter au moins "+min+" "+input);
		toCheck.value='';
		isOK=false;
		return isOK;
	}
	if(min==max&&str.length!=max) //longeur exacte
	{
		alert("Attention, ce champ doit comporter exactement "+max+" "+input);
		toCheck.value='';
		isOK=false;
		return isOK;
	}
	if(max>0&&(str.length>max||str.length<min)) //maximum maxLen caracteres
	{
		alert("Attention, ce champ ne doit comporter qu'entre "+min+" et "+max+" "+input);
		toCheck.value='';
		isOK=false;
		return isOK;
	}
	return true;
}

function check_DATE()
{
	inType='caracters en format jj/mm/aa';
	asignMinMax(arguments);
	minLen=8;
	maxLen=8;
	tmp=toCheck.value;
	if(!check_length(tmp,minLen,maxLen,inType)) return isOK;
	if((tmp.charAt(2)!='/' && tmp.charAt(2)!='\\')||(tmp.charAt(5)!='/' && tmp.charAt(5)!='\\'))
	{
		alert("Attention, vous devez respecter le format!! jj/mm/aa");
		isOK=false;
		return isOK;
	}
	i=0;
	jj=tmp.substring(0,2);
	mm=tmp.substring(3,5);
	aa=tmp.substring(6,8);
	tmpstr=jj+mm+aa;
	while(tmpstr.charAt(i)>='0' && tmpstr.charAt(i)<='9' && i<tmpstr.length) {
		i++;
	}
	if(i==tmpstr.length)
	{
		if((parseInt(jj)<1 || parseInt(jj)>31) || (parseInt(mm)<1 || parseInt(mm)>12))
		{
			alert("Attention, le jour doit être entre 01 et 31 et le mois entre 01 et 12");
			isOK=false;
			return isOK;
		}
		toCheck.value=tmp.substring(0,2)+'/'+tmp.substring(3,5)+'/'+tmp.substring(6,8);
		isOK=true;
		return isOK;
	}
	else 
	{
		toCheck.value="Que des "+inType+" !!";
		alert("Attention, ce champ ne doit comporter que des "+inType+"!!");
		toCheck.select();
		isOK=false;
		return isOK;
	}
}

function empty()
{
	isOK=true;
	return isOK;
}

function check_email(email)
{
var saisie,saisie1,saisie2,saisie3;
   saisie = email.indexOf("@");
   if (saisie!=(-1)) {
      longueur = email.length;
      saisie1 = email.substring(saisie+1,longueur);
      saisie2 = saisie1.indexOf(".");
      longueur = saisie1.length;
      saisie3 = saisie1.substring(saisie2+1,longueur);
      if (saisie2==(-1)) { alert("Votre email est invalide !"); return false; }
      else {
         if (saisie3 == "") { alert("Votre email est invalide !"); return false; }
         else return true;
      }
   }
   else { alert("Votre email est invalide !"); return false; }
}