
function setDispatch(dispatch, formName)
{
	var form;
	
	if (typeof(formName) == 'undefined')
	{
		form = document.forms[0];
	}
	else
	{
		form = document.getElementsByName(formName)[0];
	}
	
	form.dispatch.value = dispatch;
}

function replaceLinks(tableId) {

	var oTable = $(tableId);
	if (oTable != null) {
		var theads = oTable.getElementsByTagName('thead');
		if (theads != null) {
			ajaxifyLinks(theads[0].getElementsByTagName('a'));
		}
		
		var pagelinks = document.getElementsByClassName('pagelinks');

		if ((pagelinks != null) && (pagelinks.length > 0)) {
			var pagelinks = pagelinks[0].getElementsByTagName('a');
			ajaxifyLinks(pagelinks);
		}
	}
}

function ajaxifyLinks(links) {

	if (links != null) {
		for (i=0; i < links.length; i++) {
			links[i].onclick = function() {
				ajaxAnywhere.getAJAX(this.href); 
				return false;
			}
		}
	}
}

/**
 * Fonctions liées au module Mission
 */
var Mission = {
	
	/**
	 * Fonctions Ajax
	 */
	 Ajax : {
	 	onAddConnaissanceInformatiques : function() {
	 		document.forms[0].dispatch.value = 'onAddConnaissanceInformatique';	
			ajaxAnywhere.formName            = 'editionMissionForm';
			ajaxAnywhere.submitAJAX();
		},
		
		onAddConnaissanceLinguistiques : function() {
			document.forms[0].dispatch.value = 'onAddConnaissanceLinguistique';	
			ajaxAnywhere.formName            = 'editionMissionForm';
			ajaxAnywhere.submitAJAX();
		},
		
		onDeleteConnaissanceInformatique : function(index) {
			document.forms[0].dispatch.value = 'onDeleteConnaissanceInformatique';	
			document.forms[0].itemAjax.value = index;	
			ajaxAnywhere.formName            = 'editionMissionForm';
			ajaxAnywhere.submitAJAX();
		},
		
		onPlanificationAvtPostMission : function(itemChoisi) {
			document.forms[0].dispatch.value = 'onPlanificationAvtPostMission';	
			document.forms[0].itemAjax.value = itemChoisi;	
			ajaxAnywhere.formName            = 'editionMissionForm';
			ajaxAnywhere.submitAJAX();
		},
		
		onPlanificationPostMission : function(itemChoisi) {
			document.forms[0].dispatch.value = 'onPlanificationPostMission';	
			document.forms[0].itemAjax.value = itemChoisi;	
			ajaxAnywhere.formName            = 'editionMissionForm';
			ajaxAnywhere.submitAJAX();
		},
		
		onDeleteConnaissanceLinguistique : function(index) {
			document.forms[0].dispatch.value = 'onDeleteConnaissanceLinguistique';	
			document.forms[0].itemAjax.value = index;	
			ajaxAnywhere.formName            = 'editionMissionForm';
			ajaxAnywhere.submitAJAX();
		}
	 },
	 
	/**
	 * Fonctions utiles
	 */
	Utils : {
	  	onChangeLangueIndexed : function(index) {
			if ($F('autre_langue_' + index) == -2) {
				$('langue_label_' + index).show();
				$('langue_value_' + index).show();
			} else {
				$('langue_label_' + index).hide();
				$('langue_value_' + index).hide();
			}
		},
		onChangeLangue : function() {
			if ($F('autre_langue_id') == -2) {
				$('langue_label_id').show();
				$('langue_value_id').show();
			} else {
				$('langue_label_id').hide();
				$('langue_value_id').hide();
			}
		}
	}
};

/**
 * Fonctions liées au module candidat
 */
var Candidat = {

	/**
	 * Fonctions ajax
	 */
	Ajax : {
		onAjouterConnaissanceInformatique : function() {
			document.forms[0].dispatch.value = 'onAjouterConnaissanceInformatique';	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onEffacerConnaissanceInformatique : function(index) {
			document.forms[0].dispatch.value = 'onEffacerConnaissanceInformatique';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},
	
		onAjouterConnaissanceLinguistique : function() {
			document.forms[0].dispatch.value = 'onAjouterConnaissanceLinguistique';	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onEffacerConnaissanceLinguistique : function(index) {
			document.forms[0].dispatch.value = 'onEffacerConnaissanceLinguistique';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onAjouterFormation : function() {
			document.forms[0].dispatch.value = 'onAjouterFormation';	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onModifierFormation : function(index) {
			document.forms[0].dispatch.value = 'onModifierFormation';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onEffacerFormation : function(index) {
			document.forms[0].dispatch.value = 'onEffacerFormation';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onAjouterExperience : function() {
			document.forms[0].dispatch.value = 'onAjouterExperience';	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onModifierExperience : function(index) {
			document.forms[0].dispatch.value = 'onModifierExperience';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onAjouterTest : function() {
			document.forms[0].dispatch.value = 'onAjouterTest';	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onModifierTest : function(index) {
			document.forms[0].dispatch.value = 'onModifierTest';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onEffacerTest : function(index) {
			document.forms[0].dispatch.value = 'onEffacerTest';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'editionCandidatForm';
			ajaxAnywhere.submitAJAX();
		},

		onAjouterEvenement : function() {
			document.forms[0].dispatch.value = 'onAjouterEvenement';	
			ajaxAnywhere.formName            = 'visualisationCandidatForm';
			ajaxAnywhere.submitAJAX();
		},
				
		onEffacerEvenement : function(index) {
			document.forms[0].dispatch.value = 'onEffacerEvenement';	
			document.forms[0].ajaxInfo.value = index;	
			ajaxAnywhere.formName            = 'visualisationCandidatForm';
			ajaxAnywhere.submitAJAX();
		}
	},

	/**
	 * Fonctions Utils
	 */
	Utils : {
		onChangeDiplome : function() {
			if ($F('editableFormation_diplome_id') == -2) {
				$('formation_intituleDiplome_label').show();
				$('formation_intituleDiplome_text').show();
			} else {
				$('formation_intituleDiplome_label').hide();
				$('formation_intituleDiplome_text').hide();
			}
		},

		onChangePoste : function(val) {
												
			if ($F('editableExperience_poste_id') == -2) {
				$('experience_intitulePoste_label').show();
				$('experience_intitulePoste_text').show();
			} else {
				$('experience_intitulePoste_label').hide();
				$('experience_intitulePoste_text').hide();
			}
		},

		onChangeLangue : function() {
			if ($F('connaissancesLinguistiques_liste_id') == -2) {
				$('connaissancesLinguistiques_intituleLangue_text').show();
				$('connaissancesLinguistiques_intituleLangueLabel_label').show();
			} else {
				Field.clear('connaissancesLinguistiques_intituleLangue_text');
				$('connaissancesLinguistiques_intituleLangue_text').hide();
				$('connaissancesLinguistiques_intituleLangueLabel_label').hide();
			}
		},
		
		onChangeLangueIndexed : function(index) {
			if ($F('connaissancesLinguistiques_liste_' + index) == -2) {
				$('connaissancesLinguistiques_intituleLangue_' + index).show();
				$('connaissancesLinguistiques_intituleLangueLabel_' + index).show();
			} else {
				Field.clear('connaissancesLinguistiques_intituleLangue_' + index);
				$('connaissancesLinguistiques_intituleLangue_' + index).hide();
				$('connaissancesLinguistiques_intituleLangueLabel_' + index).hide();
			}
		},

		onChangeMobilite : function(val) {
												
			if (val == 1) {
				$('mobilite_text').enable();
			} else if (val == 0) {
				$('mobilite_text').disable();
			}
		},
		
		onAttachementCV : function() {								
			document.forms[0].dispatch.value = 'onAttachementCV';
			document.forms[0].submit();
		},
		
		onAttachementPhoto : function() {								
			document.forms[0].dispatch.value = 'onAttachementPhoto';
			document.forms[0].submit();
		}	
	}
};

/**
 * Fonctions liées au module candidature
 */
var Candidature = {

	/**
	 * Fonctions ajax
	 */
	Ajax : {
		onAjouterEvenement : function() {
			document.forms[0].dispatch.value = 'onAjouterEvenement';	
			ajaxAnywhere.formName            = 'visualisationCandidatureForm';
			ajaxAnywhere.submitAJAX();
		}
	}	
};
