//--- 11/07/2000 --- Jerome CHAGNOUX
//--- Verification of a form ---
//--- These javascripts operates a differents function over form and select box  ---

//--- moveSelect: move elements from one select list to another ---
function moveSelect(formName,from,to)
//--- from, to: integer, name of the two select box.
{
	var index;
	var text;
	var value;
	var l;
	var a;
	var j;
	index=eval("document."+formName+"."+from+".options.selectedIndex");
	while (index>=0)
	{
		text=eval("document."+formName+"."+from+".options["+index+"].text");
		value=eval("document."+formName+"."+from+".options["+index+"].value");
		eval("document."+formName+"."+from+".options["+index+"]=null");
		a = new Option(text,value);
		l=eval("document."+formName+"."+to+".length");
		eval("document."+formName+"."+to+".options["+l+"]= a");
		for (j=0;j<eval("document."+formName+"."+to+".length");j++)
			eval("document."+formName+"."+to+".options["+j+"].selected=false;");
		eval("document."+formName+"."+to+".options["+l+"].selected=true;");
		index=eval("document."+formName+"."+from+".options.selectedIndex");
	}
	if (eval("document."+formName+"."+from+".length")!=0)
	{
		for (j=0;j<eval("document."+formName+"."+from+".length");j++)
			eval("document."+formName+"."+from+".options["+j+"].selected=false;");
		eval("document."+formName+"."+from+".options[0].selected=true;");
	}
}

//--- clearSelect: function, delete all elements of a select list ---
function clearSelect(formName,selectName)
{
	var j;
	for (j=eval("document."+formName+"."+selectName+".length")-1;j>=0;j--)
		eval("document."+formName+"."+selectName+".options["+j+"]=null;");
}

//--- deleteSelect: function, delete the selected items in a list ---
function deleteSelect(formName,listName)
//--- formName: string, name of the form ---
//--- listName: string, name of the list in the form ---
{
	var index;
	var text;
	var value;
	var l;
	var j;
	index=eval("document."+formName+"."+listName+".options.selectedIndex");
	while (index>=0)
	{
		eval("document."+formName+"."+listName+".options["+index+"]=null");
		index=eval("document."+formName+"."+listName+".options.selectedIndex");
	}
	if (eval("document."+formName+"."+listName+".length")!=0)
	{
		for (j=0;j<eval("document."+formName+"."+listName+".length");j++)
			eval("document."+formName+"."+listName+".options["+j+"].selected=false;");
		eval("document."+formName+"."+listName+".options[0].selected=true;");
	}
}

//--- allMultiSelect: function, select all elements of a select list with multiple selection ---
function allMultiSelect(formName,selectName)
{
	var j;
	for (j=0;j<eval("document."+formName+"."+selectName+".length");j++)
		eval("document."+formName+"."+selectName+".options["+j+"].selected=true;");
}

//--- existText: function, verify in a list if a text already exists ---
function existText(myList,myString)
//--- myList: string, representing the list, not the name of the list nor the name of the form ---
//--- myString: string, what we look for ---
{
	var l=myList.length;
	var result=false;
	var j;
	for(j=0;j<l;j++)
	{
		result=(myList.options[j].text==myString);
		if (result)
			break;
	}
	return (result);
}

//--- isOneCheckBox: function, verify if there is at least one checkbox checked ---
function isOneCheckBox(myForm)
{
	var j;
	var l=eval("document."+myForm+".length");
	var result=false;
	for(j=0;j<l;j++)
	{
		result=eval("document."+myForm+".elements["+j+"].checked");
		if (result)
			break;
	}
	return result;
}

//--- upcas: function ---
function upcas(myfield)
{
myfield.value=myfield.value.toUpperCase();
}

//--- upcasPrenom: function ---
function upcasPrenom(myfield)
{
myfield.value=myfield.value.substring(0,1).toUpperCase()+myfield.value.substring(1,myfield.value.length).toLowerCase();
}

function SupprEspace(myfield)
{
	myfield.value=myfield.value.replace(/[ ]/g,"")
}

function upcas2(myfield)
{
   myfield.value=myfield.value.toUpperCase();
}

function upcasPrenom2(myfield)
{
	var reg = new RegExp("[ -.]+", "g");
	var tabprenom = myfield.value.split(reg);
	var prenom_format='';
	
	for(i=0; i< tabprenom.length;i++)
	{
		tabprenom[i]=tabprenom[i].substring(0,1).toUpperCase()+tabprenom[i].substring(1,myfield.value.length).toLowerCase();
		if(i>0) prenom_format+=' ';
		prenom_format+=tabprenom[i];
	}
	
  myfield.value = prenom_format;
}

