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 afficher(aDivId)
{
	document.getElementById(aDivId).style.display	=	'block';	
}

function cacher(aDivId)
{
	document.getElementById(aDivId).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_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 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 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=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}*/

function string_generator(nb_caract)
{
	var pass = '';
	var chaine="abcdefghijklmnopqrstuvwxyz0123456789";
	
	for(i=1;i<=parseInt(nb_caract);i++)
	{
		var nbalea=Math.floor(Math.random()*chaine.length);//génération d'un nombre aléatoire entre 0 et la longueur de la chaine
		pass+=chaine.charAt(nbalea);//sélection du caractère correspondant
	} 
	return pass;
	/*
	var chaine = Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
	var pass = '';
	var nb, u;
	for (u=1; u <= nb_caract; u++) {
	nb = chaine.length;
	nb = Math.round(Math.random()*chaine.length);
	pass += chaine[nb];
	}
	return pass;
	*/
}

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];
}

function turnAutocompleteOff()
{
	try {
		var inputs = document.getElementsByTagName('INPUT');
		for (var i = 0; i < inputs.length; i++) {
			inputs[i].setAttribute('autocomplete', 'off');
		}
	} catch (e) {}
}

String.prototype.sans_accents = function()
{
	var ch = this.replace(/é|è|ê|ë/g, "e");
	ch = ch.replace(/à|â|ä/g, "a");
	ch = ch.replace(/ç/g, "c");
	ch = ch.replace(/î|ï/g, "i");
	ch = ch.replace(/ô|ö/g, "o");
	ch = ch.replace(/ù|û|ü/g, "u");
	ch = ch.replace(/À|Â|Ä|Å/g, "A");
	ch = ch.replace(/Ç/g, "C");
	ch = ch.replace(/É|È|Ê|Ë/g, "E");
	ch = ch.replace(/Ô|Ö/g, "O");
	ch = ch.replace(/Ù|Û|Ü/g, "U");
	ch = ch.replace(/ /g, '_');
	ch = ch.replace(/"/g, '');
	ch = ch.replace(/'/g, '');
	ch = ch.replace('www.', '')
	ch = ch.replace('.', '')
	ch = ch.replace(',', '')
	ch = ch.replace(';', '')
	return ch;
}

function genere_password(aChamps)
{
	var cars="az0erty2ui3op4qs5df6gh7jk8lm9wxcvbn";
	var long=cars.length;
	wpas="";
	taille=8;
	for(i=0;i < taille;i++)
	{
		wpos=Math.round(Math.random()*long);
		wpas+=cars.substring(wpos,wpos+1);
	}
	$(aChamps).value = wpas;
}
