
/*
 * TEXTAREA
 */
function limiterTextarea(champ, longueur_max, champ_compteur)
{
	var len = champ.value.length;
	champ_compteur.value = len+' / '+longueur_max+' caractères';
	if (len > longueur_max)
	{
		window.alert(longueur_max + ' caractères au maximum !');
		champ.value = champ.value.substr(0, longueur_max);
	}
}


// Add the selected items from the source to destination list
function addSrcToDestList() {
	var len = window.document.forms[0].elements['destList[]'].length;
	for(var i = 0; i < window.document.forms[0].elements['srcList[]'].length; i++) {
		if ((window.document.forms[0].elements['srcList[]'].options[i] != null) && (window.document.forms[0].elements['srcList[]'].options[i].selected)) {
			var found = false;
			for(var count = 0; count < len; count++) {
				if (window.document.forms[0].elements['destList[]'].options[count] != null) {
					if (window.document.forms[0].elements['srcList[]'].options[i].text == window.document.forms[0].elements['destList[]'].options[count].text) {
						found = true;
						break;
					}
				}
			}// l utilisateur ne peut choisir que 5 metiers aux max

			if ((found != true) && (window.document.forms[0].elements['destList[]'].length<5)) {
				window.document.forms[0].elements['destList[]'].options[len] = new Option(window.document.forms[0].elements['srcList[]'].options[i].text);
				window.document.forms[0].elements['destList[]'].options[len].value = window.document.forms[0].elements['srcList[]'].options[i].value;
				//window.document.forms[0].elements['destList[]'].options[len].value = new Option(window.document.forms[0].elements['srcList[]'].options[i].text);
				len++;
			}
		}
	}
}

// Deletes from the destination list.
function deleteFromDestList() {
	var len = window.document.forms[0].elements['destList[]'].options.length;
	for(var i = (len-1); i >= 0; i--) {
		if ((window.document.forms[0].elements['destList[]'].options[i] != null) && (window.document.forms[0].elements['destList[]'].options[i].selected == true)){
			//inserer la valeur dans la liste source
			var found = false;
			var len = window.document.forms[0].elements['srcList[]'].length;
			for(var count = 0; count < len; count++) {
				if (window.document.forms[0].elements['srcList[]'].options[count] != null) {
					if (window.document.forms[0].elements['destList[]'].options[i].text == window.document.forms[0].elements['srcList[]'].options[count].text) {
						found = true;
						break;
					}
				}
			}
			if (found != true)  {
				window.document.forms[0].elements['srcList[]'].options[len] = new Option(window.document.forms[0].elements['destList[]'].options[i].text);
				len++;
			}
			window.document.forms[0].elements['destList[]'].options[i] = null;
		}
	}
}

// fonction qui lit les metiers depuis la select List destList et remplit au max 5 metiers dans 5 champs hidden
// dont les noms : metier1, ...metier9
function getListMetiers() {
	var len = window.document.forms[0].elements['destList[]'].length;
	for(var i = 0; i < len; i++) {
		switch(i){
			case 0 : window.document.forms[0].metier1.value=window.document.forms[0].elements['destList[]'].options[i].value;
			break;
			case 1 : window.document.forms[0].metier2.value=window.document.forms[0].elements['destList[]'].options[i].value;
			break;
			case 2 : window.document.forms[0].metier3.value=window.document.forms[0].elements['destList[]'].options[i].value;
			break;
			case 3 : window.document.forms[0].metier4.value=window.document.forms[0].elements['destList[]'].options[i].value;
			break;
			case 4 : window.document.forms[0].metier5.value=window.document.forms[0].elements['destList[]'].options[i].value;
			break;
		}
	}
}

//fonction d activation et desactivation du champs durée du temps de travail.
function tpsTravail(param){
	if(param != '0'){
		//desactiver la duree du temps de travail
		window.document.forms[0].elements["dureeTravail_heures"].value= window.document.forms[0].elements["duree_tps_trav_heures"].value;
		window.document.forms[0].elements["dureeTravail_minutes"].value= window.document.forms[0].elements["duree_tps_trav_minutes"].value;
	}
	else{
		window.document.forms[0].elements["dureeTravail_heures"].disabled=false;
		window.document.forms[0].elements["dureeTravail_minutes"].disabled=false;
	}
}
function verif_submit(){
	if (! entier_valeur_valide(document.saisieop.nbrePoste, 1, 999))
		return false;
	getListMetiers_Form(document.saisieop);
	// Teste si c'est un code fiche ou non
	if (!isNaN(document.saisieop.intitulePoste.value)) {
		document.saisieop.intitulePoste.value = document.saisieop.intitulePoste.value.toUpperCase();
	}
	return true;
}

function visible_and_hide(ident){
	if(ident.style.display == 'none'){
		ident.style.display = 'block';
	}
	else{ident.style.display = 'none';}
}


function multilist_changePage (sGabari){
	var sVal = document.getElementById('pager_perso_select').value;
	if ( parseInt(sVal)!='' ) {
		var sURL = sGabari.replace('%d', parseInt(sVal));
		document.location.href='/'+sURL;
	}
}


function popup_mentions_legales() {
	window.open('/mentionslegales/', 'popup', 'width=800,height=300,scrollbars=yes');
}
function popup_aide() {
	window.open('/aide/', 'popup', 'width=800,height=300,scrollbars=yes');
}


function exportOffre (idOffre, typeExport) {
	document.location.href="/page.php?controller=export_offres&details=1&offres="+idOffre+"&format="+typeExport;
}

function setParentLocation(sURL) {
	opener.document.location.href=sURL;
}
