// JavaScript Document

function ch_img(elt)
{
	img_link = document.images[elt.name].src.split('/');
	if(img_link[5] != elt.name+'.jpg')
	{
		document.images[elt.name].src = 'img/'+elt.name+'.jpg';
		elt.onmouseout = function() { document.images[elt.name].src = 'img/'+elt.name+'_off.jpg';}	
		name = elt.name.split('1')[0] == 'bouton'?"bouton2":"bouton1";
		elt.onclick = function() { document.images[elt.name].src = 'img/'+elt.name+'.jpg'; elt.onmouseout = function(){}; document.images[name].src = 'img/'+name+'_off.jpg';  }
	}
	

}

var word = '';
function fn_validateForm(elt)
{
	var vword = /^[a-zA-Z0-9]+(([\'\,\.\-\_éèêï ])+[a-zA-Z0-9]*)*$/;
	
	
	if(elt.value != '')
	if(elt.id.split('_')[1] != 'tel')
	if(!elt.value.match(vword))
		elt.value = word;
	else
		word = elt.value;
	else
	if(!elt.value.match(/^[0-9]*$/))
		elt.value = word;
	else
		word = elt.value;
	
}


function fn_submitForm(param)
{
	var vmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{0,4}$/;
		crt=0;
	param = param.split('|');
	for(var i=0; i<param.length; i++)
	{
		if(document.getElementById(param[i]).value=='')
		{
			str = param[i].split('_');
			alert('le champs '+str[1]+' est vide!');
			break;
		}
		else
		{
			str = param[i].split('_');
			if(str[1] == 'email' && !document.getElementById(param[i]).value.match(vmail))
			{
				alert('le champs '+str[1]+' est non valide');
				document.getElementById(param[i]).focus();
				break;
			}
			else if(str[1] == 'tel' && !document.getElementById(param[i]).value.match(/^[0-9]{8,}$/)){
				
					alert('le champs '+str[1]+' est non valide --au minimun 8 chiffres--');
					document.getElementById(param[i]).focus();
					break;
			}else if(str[1] == 'ConfirmerMotDePasse' && (document.getElementById('_motDePasse').value != document.getElementById(param[i]).value)) {
				alert('les mots de passe ne correspondent pas');
				break;
			}
			else
					crt++;
		}
	}
	
	if(crt == param.length)
		document.getElementById('form').submit();
}

function showNotation(elt)
{
	if(elt.checked)
		document.getElementById('notation').style.visibility = 'visible';
	else
		document.getElementById('notation').style.visibility = 'hidden';
		
}

function _enable(id)
{
	id = id.split('|');
	
	if(document.getElementById(id[0]).disabled)
	{
		document.getElementById(id[0]).disabled = false;
		document.getElementById(id[1]).disabled = true;
	}
}

