
//jQuery's noConflict mode
jQuery.noConflict();

//extension de Jquery pour trouver les positions d'un élément.
jQuery.fn.extend({
	findPos : function() {
		var obj = jQuery(this).get(0);
		var curleft = obj.offsetLeft || 0;
		var curtop = obj.offsetTop || 0;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
		return {x:curleft,y:curtop};
	} 
});

jQuery(document).ready(function(){

	jQuery(".jQdate").datepicker();	

});


//---------------------------------VALIDATION DE FORMULAIRE
function findSubmitForm(form){
	jQuery("#"+form+" input[type=submit]").each(function(e){
		jQuery(this).click(submitClick);
	});
}

var msgError = new Array();
	
function submitClick(e){
	e.preventDefault();
	
	var findError = false;
    var i = 0;
	var max = 'max'
	var min = 'min'
	msgError['jobs_submited'] = new Array();
	msgError['jobs_submited']['champ'] = '';
	msgError['jobs_submited']['erreurFind'] = false;
	msgError['jobs_submited']['erreurInfo'] = new Array();
	msgError['jobs_submited']['erreurInfo']['empty'] = '';
	msgError['jobs_submited']['erreurInfo']['emptyCheck'] = '';
	msgError['jobs_submited']['erreurInfo']['syntaxe'] = '';
	msgError['jobs_submited']['erreurInfo']['checkMin'] = '';
	msgError['jobs_submited']['erreurInfo']['checkMax'] = '';
	
	msgError['jobs_training'] = new Array();
	msgError['jobs_training']['champ'] = 'Formation en alternance';
	msgError['jobs_training']['erreurFind'] = false;
	msgError['jobs_training']['erreurInfo'] = new Array();
	msgError['jobs_training']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_training']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_training']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_training';
	msgError['jobs_training']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_training';
	msgError['jobs_training']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_training';
	
	msgError['jobs_title'] = new Array();
	msgError['jobs_title']['champ'] = 'Intitulé du poste';
	msgError['jobs_title']['erreurFind'] = false;
	msgError['jobs_title']['erreurInfo'] = new Array();
	msgError['jobs_title']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_title']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_title']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_title';
	msgError['jobs_title']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_title';
	msgError['jobs_title']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_title';
	
	msgError['jobs_company'] = new Array();
	msgError['jobs_company']['champ'] = 'Entreprise';
	msgError['jobs_company']['erreurFind'] = false;
	msgError['jobs_company']['erreurInfo'] = new Array();
	msgError['jobs_company']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_company']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_company']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_company';
	msgError['jobs_company']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_company';
	msgError['jobs_company']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_company';
	
	msgError['jobs_location'] = new Array();
	msgError['jobs_location']['champ'] = 'Lieu du stage';
	msgError['jobs_location']['erreurFind'] = false;
	msgError['jobs_location']['erreurInfo'] = new Array();
	msgError['jobs_location']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_location']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_location']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_location';
	msgError['jobs_location']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_location';
	msgError['jobs_location']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_location';
	
	msgError['jobs_level'] = new Array();
	msgError['jobs_level']['champ'] = 'Niveau du stage';
	msgError['jobs_level']['erreurFind'] = false;
	msgError['jobs_level']['erreurInfo'] = new Array();
	msgError['jobs_level']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_level']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_level']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_level';
	msgError['jobs_level']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_level';
	msgError['jobs_level']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_level';
	
	msgError['jobs_scope'] = new Array();
	msgError['jobs_scope']['champ'] = 'Champs d\'application';
	msgError['jobs_scope']['erreurFind'] = false;
	msgError['jobs_scope']['erreurInfo'] = new Array();
	msgError['jobs_scope']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_scope']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_scope']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_scope';
	msgError['jobs_scope']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_scope';
	msgError['jobs_scope']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_scope';
	
	msgError['jobs_scope']['nbCheck'] = new Array();
	msgError['jobs_scope']['nbCheck']['min'] = 1; 
	msgError['jobs_scope']['nbCheck']['max'] = max;
		
	msgError['jobs_datestart'] = new Array();
	msgError['jobs_datestart']['champ'] = 'Date de début proposé';
	msgError['jobs_datestart']['erreurFind'] = false;
	msgError['jobs_datestart']['erreurInfo'] = new Array();
	msgError['jobs_datestart']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_datestart']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_datestart']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_datestart';
	msgError['jobs_datestart']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_datestart';
	msgError['jobs_datestart']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_datestart';
	
	msgError['jobs_duration'] = new Array();
	msgError['jobs_duration']['champ'] = 'Durée proposée';
	msgError['jobs_duration']['erreurFind'] = false;
	msgError['jobs_duration']['erreurInfo'] = new Array();
	msgError['jobs_duration']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_duration']['erreurInfo']['emptyCheck'] = '';
	msgError['jobs_duration']['erreurInfo']['syntaxe'] = '';
	msgError['jobs_duration']['erreurInfo']['checkMin'] = '';
	msgError['jobs_duration']['erreurInfo']['checkMax'] = '';
	
	msgError['jobs_salary'] = new Array();
	msgError['jobs_salary']['champ'] = 'Rémunération brute mensuelle';
	msgError['jobs_salary']['erreurFind'] = false;
	msgError['jobs_salary']['erreurInfo'] = new Array();
	msgError['jobs_salary']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_salary']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_salary']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_salary';
	msgError['jobs_salary']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_salary';
	msgError['jobs_salary']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_salary';
	
	msgError['jobs_bodytext'] = new Array();
	msgError['jobs_bodytext']['champ'] = 'Texte de l\'annonce';
	msgError['jobs_bodytext']['erreurFind'] = false;
	msgError['jobs_bodytext']['erreurInfo'] = new Array();
	msgError['jobs_bodytext']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_bodytext']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_bodytext']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_bodytext';
	msgError['jobs_bodytext']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_bodytext';
	msgError['jobs_bodytext']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_bodytext';
	
	msgError['jobs_contact'] = new Array();
	msgError['jobs_contact']['champ'] = 'Personne ou service à contacter';
	msgError['jobs_contact']['erreurFind'] = false;
	msgError['jobs_contact']['erreurInfo'] = new Array();
	msgError['jobs_contact']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_contact']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_contact']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_contact';
	msgError['jobs_contact']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_contact';
	msgError['jobs_contact']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_contact';
	
	msgError['jobs_address'] = new Array();
	msgError['jobs_address']['champ'] = 'Adresse';
	msgError['jobs_address']['erreurFind'] = false;
	msgError['jobs_address']['erreurInfo'] = new Array();
	msgError['jobs_address']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_address']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_address']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_address';
	msgError['jobs_address']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_address';
	msgError['jobs_address']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_address';
	
	msgError['jobs_cp'] = new Array();
	msgError['jobs_cp']['champ'] = 'Code Postal';
	msgError['jobs_cp']['erreurFind'] = false;
	msgError['jobs_cp']['erreurInfo'] = new Array();
	msgError['jobs_cp']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_cp']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_cp']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_cp';
	msgError['jobs_cp']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_cp';
	msgError['jobs_cp']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_cp';
	
	msgError['jobs_city'] = new Array();
	msgError['jobs_city']['champ'] = 'Ville';
	msgError['jobs_city']['erreurFind'] = false;
	msgError['jobs_city']['erreurInfo'] = new Array();
	msgError['jobs_city']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_city']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_city']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_city';
	msgError['jobs_city']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_city';
	msgError['jobs_city']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_city';
	
	msgError['jobs_phone'] = new Array();
	msgError['jobs_phone']['champ'] = 'Téléphone';
	msgError['jobs_phone']['erreurFind'] = false;
	msgError['jobs_phone']['erreurInfo'] = new Array();
	msgError['jobs_phone']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_phone']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_phone']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_phone';
	msgError['jobs_phone']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_phone';
	msgError['jobs_phone']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_phone';
	
	msgError['jobs_fax'] = new Array();
	msgError['jobs_fax']['champ'] = 'Fax';
	msgError['jobs_fax']['erreurFind'] = false;
	msgError['jobs_fax']['erreurInfo'] = new Array();
	msgError['jobs_fax']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_fax']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_fax']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_fax';
	msgError['jobs_fax']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_fax';
	msgError['jobs_fax']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_fax';
	
	msgError['jobs_email'] = new Array();
	msgError['jobs_email']['champ'] = 'E-mail';
	msgError['jobs_email']['erreurFind'] = false;
	msgError['jobs_email']['erreurInfo'] = new Array();
	msgError['jobs_email']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_email']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_email']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_email';
	msgError['jobs_email']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_email';
	msgError['jobs_email']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_email';
	
	msgError['jobs_site'] = new Array();
	msgError['jobs_site']['champ'] = 'Site à consulter';
	msgError['jobs_site']['erreurFind'] = false;
	msgError['jobs_site']['erreurInfo'] = new Array();
	msgError['jobs_site']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_site']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_site']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_site';
	msgError['jobs_site']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_site';
	msgError['jobs_site']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_site';
	
	msgError['jobs_need_contact'] = new Array();
	msgError['jobs_need_contact']['champ'] = 'Souhaitez-vous être contacté ?';
	msgError['jobs_need_contact']['erreurFind'] = false;
	msgError['jobs_need_contact']['erreurInfo'] = new Array();
	msgError['jobs_need_contact']['erreurInfo']['empty'] = 'Ce champ est obligatoire.';
	msgError['jobs_need_contact']['erreurInfo']['emptyCheck'] = 'Vous devez sélectionner au moins un champ dans la liste.';
	msgError['jobs_need_contact']['erreurInfo']['syntaxe'] = 'Erreur Syntaxe - jobs_need_contact';
	msgError['jobs_need_contact']['erreurInfo']['checkMin'] = 'Erreur CheckMin - jobs_need_contact';
	msgError['jobs_need_contact']['erreurInfo']['checkMax'] = 'Erreur CheckMax - jobs_need_contact';
	
	msgError['jobs_maps_itna'] = new Array();
	msgError['jobs_maps_itna']['champ'] = '';
	msgError['jobs_maps_itna']['erreurFind'] = false;
	msgError['jobs_maps_itna']['erreurInfo'] = new Array();
	msgError['jobs_maps_itna']['erreurInfo']['empty'] = '';
	msgError['jobs_maps_itna']['erreurInfo']['emptyCheck'] = '';
	msgError['jobs_maps_itna']['erreurInfo']['syntaxe'] = '';
	msgError['jobs_maps_itna']['erreurInfo']['checkMin'] = '';
	msgError['jobs_maps_itna']['erreurInfo']['checkMax'] = '';
	
    jQuery(".required").each( function(){
		    if( jQuery(this).val() == '' || jQuery(this).val() == '-1'){
				findError = true;
				jQuery(this).addClass('error');
				jQuery(this).focus( function() { jQuery(this).removeClass('error'); jQuery('#msgErrorAll').hide(); } );
				msgError[jQuery(this).attr('id')]['erreurFind'] = true;
				msgError[jQuery(this).attr('id')]['erreurShow'] = msgError[jQuery(this).attr('id')]['erreurInfo']['empty']
	        }
    });
	
	jQuery(".required-list").each( function(){
		var className = jQuery(this).attr('class');
		cptCheck = 0 ;
		jQuery(this).children('input').each( function () {
			if ( jQuery(this).attr('checked') == true){
				cptCheck++;
			}
		});
		className = className.replace('required-list','').replace('error','').replace(/^\s+/g,'').replace(/\s+$/g,'').replace(' ', '') ;
		if ( msgError[className]['nbCheck']['min'] == 'min'){ msgError[className]['nbCheck']['max'] = 1; }
		if ( msgError[className]['nbCheck']['max'] == 'max'){ msgError[className]['nbCheck']['max'] = cptCheck; }
		if ( msgError[className]['nbCheck']['min'] > cptCheck || msgError[className]['nbCheck']['max'] < cptCheck ){
			findError = true;
			jQuery(this).addClass('error');
			msgError[className]['erreurFind'] = true;
			jQuery(this).children('input').each( function () {
				jQuery(this).focus( function() { jQuery(this).parents('div').removeClass('error'); jQuery('#msgErrorAll').hide(); } );
			});
			if ( msgError[className]['nbCheck']['max'] < cptCheck )
			{
				msgError[className]['erreurShow'] = msgError[className]['erreurInfo']['checkMax'];
			}else{
				msgError[className]['erreurShow'] = msgError[className]['erreurInfo']['checkMin'];
			}
			
			if ( cptCheck == '0' ){
				msgError[className]['erreurShow'] = msgError[className]['erreurInfo']['emptyCheck'];
			}
		}
		
	});

	if (!findError)
		jQuery('form').submit();
	else{
		var msgAlert = '<span class="close"><img src="/fileadmin/templates/img/fermer.gif" alt="fermer" /></span>';
		msgAlert = msgAlert+'<span class="idChamp"><h2>Champ concerné</h2></span>'+'<span class="raison"><h2>Problème rencontré</h2></span>';
		for (msgE in msgError)
		{
			if (msgError[''+msgE+'']['erreurFind']){
				msgAlert = msgAlert+'<span class="idChamp"><h3>'+idToName(msgError[''+msgE+'']['champ'])+'</h3></span>'+'<span class="raison">'+msgError[''+msgE+'']['erreurShow']+'</span>';
			}
		}
		jQuery('#msgError').html(msgAlert);
		jQuery('#msgErrorAll').css("top","0px");
		jQuery('#msgErrorAll').css("left","0px");
		jQuery('#msgErrorAll').css("width",jQuery('#contenuIntra').css('width'));
		jQuery('#msgErrorAll').css("height",jQuery('#contenuIntra').css('height'));
		jQuery('#msgErrorAll').show();
		jQuery('#msgError').css("top",jQuery('.tx-inoffreemploi-pi1').css('top'));
		jQuery('#msgError').css("left",jQuery('.tx-inoffreemploi-pi1').css('left'));
		jQuery('#msgError').css("width",jQuery('.tx-inoffreemploi-pi1').css('width'));
		jQuery('#msgError').show();
		jQuery('#msgErrorAll').click(function (){
			jQuery('#msgError').hide();
			jQuery(this).hide();
		});
		jQuery('#msgError').click(function (){
			jQuery(this).hide();
			jQuery('#msgErrorAll').hide();
		});
	}
}

