
function trim(string)
{
	return string.replace(/(^\s*)|(\s*$)/g,'');
}
//OBLIGATION
function ValidationTexte(idChamp){
	champ=document.getElementById(idChamp);
	if(!champ)
		return true;
	if(trim(champ.value)==""){
		return false;
	}
	return true;
}
function ValidationChampCheckObligatoire(nameChamp)
{
 	var leschamps=document.getElementsByName(nameChamp);
 	if(leschamps.length==0){
 		return true;
 	}
 	for(vi=0;vi<leschamps.length;vi++)
 	{
 		if(leschamps[vi].checked==true && leschamps[vi].value!="")
 			return true;
 	}
 	return false;
}


//FORMAT DES CHAMPS
function ValidationChampMail(idChamp)
{
	champ=document.getElementById(idChamp);
	if(!champ)
		return true;
	if(trim(champ.value)=="")
		return true;
	if (!champ.value) {
	    return false;
	}
	if(champ.value=="")
		return true;
	adresse = champ.value;
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+1);
	if ((place > -1)&&(adresse.length >2)&&(point > 1))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function ValidationChampDate(idChamp)
{
	champ=document.getElementById(idChamp);
	if(!champ)
		return true;
	if(trim(champ.value)=="")
		return true;
    if (champ.value)
    {
        if(Date.parse(champ.value))
        	return true;

    }
    return false;
}
function ValidationChampNum(idChamp)
{
	champ=document.getElementById(idChamp);
	if(!champ)
		return true;
	if(trim(champ.value)=="")
		return true;
    if (champ.value)
    {
    	m=Number(champ.value);
        if(!isNaN(m))
        	return true;

    }
    return false;
}
function ValidationChampUrl(idChamp)
{
	champ=document.getElementById(idChamp);
	if(!champ)
		return true;
	if(trim(champ.value)=="")
		return true;
    if (!champ.value) {
	    return false;
	}
	if(champ.value=="")
		return true;
    adresse = champ.value;
	var place = adresse.indexOf("www.",0);
	var point = adresse.lastIndexOf(".");
	if ((place > -1)&&(adresse.length >2)&&(point > 3))
	{
		return true;
	}
    else
	{
		return false;
	}
}
function ValidationChampFichier(nameChamp,format)
{
 	if(!document.getElementById(nameChamp) || document.getElementById(nameChamp).value=="")
 		return true;
 	var fich=document.getElementById(nameChamp).value;
 	var tabFich=fich.split('.');
 	var extFich=tabFich[tabFich.length-1];
 	var tabSplit=format.split(',');
 	for(vi=0;vi<tabSplit.length;vi++)
 	{
		if(extFich.toLowerCase()==tabSplit[vi].toLowerCase())
			return true;
 	}
 	return false;
}



//GESTION DES COMMUNES
var champVilleEnCours="";
function SelectionVille(ch,horscg)
{
	champVilleEnCours=ch;
	window.open('/web/php/form/choixCommune.php?horscg=' + horscg,'Commune','toolbar=no,scrollbars=yes,directories=no,status=no,menubar=no,copyhistory=no,resizable=no,width=500,height=400');
}
function setCommune(insee,nom)
{
	document.getElementById('in_'+champVilleEnCours).value=insee;
	document.getElementById('p_'+champVilleEnCours).innerHTML=nom;
	document.getElementById('p_'+champVilleEnCours).style.display='';
}
function SearchCommune()
{
	if(document.getElementById('tbCode').value!="" || document.getElementById('tbNom').value!="")
		__doPostBack('frm', 'Search','');
	else
		alert('Vous devez remplir le code ou le nom de la commune.');
}
function selectCommune(insee,nom)
{
	window.opener.setCommune(insee,nom);
	window.close();
}

//GESTION DES ETAPES
var oldEtape=1;
function ChangeEtape(newEtape){
	var bTest=true;
	if(newEtape>oldEtape)
		eval("bTest=ValidationEtape"+oldEtape+"();");
	if(bTest==true){
		document.getElementById('aEtape_'+newEtape).style.display='none';
		document.getElementById('spanEtape_'+newEtape).style.display='';
		
		document.getElementById('aEtape_'+oldEtape).style.display='';
		document.getElementById('spanEtape_'+oldEtape).style.display='none';
	
		document.getElementById('Etape_'+oldEtape).style.display='none';
		document.getElementById('Etape_'+newEtape).style.display='';
		oldEtape=newEtape;
	}
}

