function trim(aString) 
{
	var regExpBeginning = /^\s+/;
	var regExpEnd       = /\s+$/;
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

function verif_date(date)
{
	var e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");			
	if (!e.test(date)) // On teste l'expression régulière pour valider la forme de la date
	{
		return false;
	}	
	return true;
}

function affiche_div(nom_el)
{
	monElement = document.getElementById(nom_el);
	if (monElement.style.display == 'none')
		monElement.style.display = 'block';
	else
		monElement.style.display = 'none';
}

function affiche_div_membre(id, nb_membre)
{
	nom		=	navigator.appName;
	version	=	navigator.appVersion;
	ie4 = (nom == 'Microsoft Internet Explorer' && version.substr(0, 1) >= 4 ) ? 1:0
	if (!ie4)
	{
		document.getElementById("div_fiche").style.height	=	"0px";
		document.getElementById("div_lien_ville").style.top	=	"248px";
	}
	
	for(var i=0; i < nb_membre; i++)
	{
		j	=	i+1;
		/*myVerticalSlide.toggle();
		$('myVerticalSlide_'+i).toggle();*/
		monElement = document.getElementById('fiche_'+i);
		if(i == id && id != -1)
		{
			if (monElement.style.display == 'none')
			{
				monElement.style.display = 'block';
				MM_swapImage('img_'+i,'','images/membre_on_'+j+'.jpg',1);
			}
			else
			{
				monElement.style.display = 'none';
				MM_swapImage('img_'+i,'','images/membre_off_'+j+'.jpg',1);
			}
		}
		else
		{
			
			monElement.style.display = 'none';	
			MM_swapImage('img_'+i,'','images/membre_off_'+j+'.jpg',1);
		}
	}
}

function affiche_cache_div(nom_el, aEtat)
{
	monElement = document.getElementById(nom_el);
	if(aEtat == 1)
	{
		monElement.style.display = 'block';
	}
	else
	{
		monElement.style.display = 'none';
	}
}

function formcheck_date(el){
    if (!verif_date(el.value)) {
	//	alert("dqsdqsd");
        el.errors.push("La date n'est pas au format JJ/MM/AAAA");
        return false;
    } else {
        return true;
    }
}

function formcheck_password(el)
{
	if($('confirm_password').value != '' && $('confirm_password').value != $('password').value)
	{
		el.errors.push("La confirmation ne correspond pas au mot de passe.");
		return false;
	}
	else
	{
		return true;
	}
}

function telecharger(aChemin, aFichier, aDestFileName)
{
	if (aDestFileName == undefined)
		aDestFileName	=	aFichier;
	window.location.href	=	"includes/telecharger.php?chemin=" + aChemin + "&fichier=" + aFichier + "&nom=" + aDestFileName;
}

function telecharger_admin(aChemin, aFichier, aDestFileName)
{
	if (aDestFileName == undefined)
		aDestFileName	=	aFichier;
	window.location.href	=	"../includes/telecharger.php?chemin=" + aChemin + "&fichier=" + aFichier + "&nom=" + aDestFileName;
}


function telecharger_sauvegarde(aChemin, aFichier, aCandidat_id, aFichier_id, aDestFileName)
{
	if (aDestFileName == undefined)
		aDestFileName	=	aFichier;
	//alert(aCandidat_id+' '+aFichier_id)
	window.location.href	=	"includes/telecharger_sauvegarde.php?chemin=" + aChemin + "&fichier=" + aFichier + "&nom=" + aDestFileName+ "&candidat_id=" + aCandidat_id + "&fichier_id=" + aFichier_id;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=document.getElementById(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function chargement(num)
{
	//Affiche un image de chargement
	MM_findObj('img_chargement'+num).style.display='inline';	
}

function stop_chargement(num)
{
	//Stoppe l\'image de chargement
	MM_findObj('img_chargement'+num).style.display='none';		
}

function init_loading()
{
	$('img_transparent').style.display		=	'block';
}

function stop_loading()
{
	$('img_transparent').style.display		=	'none';
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function get_valeur(aName, aType)
{
	var retour	=	null;
	if (MM_findObj(aName))
	{
		if (aType == "radio")
		{	
			val	=	MM_findObj(aName);
			for (il=0; il < val.length; il++)
			{
				if (val[il].checked)
					retour	=	val[il].value;
			}
		}
		else if (aType == "checkbox")
		{
			return val.checked;
		}
		else
			retour	=	MM_findObj(aName).value;
	}
	return retour;
}
/*
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

*/


function rnt_autocompleter_decoupe(aValue)
{
	return aValue.replace("' />", "").split("<span id='");
}

function rnt_autocompleter_value(aChampsLabelName, aChampsIdName)
{
	// SDS Développement<span id='2' />
	var valeur		=	document.getElementById(aChampsLabelName).value;
	var tab			=	rnt_autocompleter_decoupe(valeur);
	document.getElementById(aChampsLabelName).value		=	tab[0];
	if (aChampsIdName)
		document.getElementById(aChampsIdName).value		=	tab[1];
}

