	/*
 * Gestion du moteur de recherche
 * # remplacement des champs de formulaire pour customisation
 * # validation formulaire
 * # calendrier et gestion de la date
 * /!\ necessite sof_datas.js pour fonctionner
 */

// init namespace (A  utiliser pour eviter toute collision)
if(!SOF) {var SOF = {};}

// gestion de la date
SOF.today = new Date();
SOF.day = SOF.today.getDate();
SOF.month = SOF.today.getMonth() + 1;
SOF.year = SOF.today.getFullYear();

// données pour les scripts de cette page
SOF.datasDatesForms = {
	'dates': {
		'start': {'d': '', 'm': '', 'y': ''},
		'end': {'d': '', 'm': '', 'y': ''}
	},
	
	'fields': {
	  'ar_theme': {
	   'replaceBy': 'select'
	  },
	  'ar_destination': {
	   'replaceBy': 'select'
	  },
	  'ar_periode': {
	   'replaceBy': 'select'
	  },
	  'theme': {
	   'replaceBy': 'select'
	  },
	  'destination': {
	   'replaceBy': 'select'
	  },
	  'periode': {
	   'replaceBy': 'select'
	  }
	},
	
	'required': {
		'msg': function(id) {return SOF[$$L][id + 'ErrorMsg']},
		'test': function(o) {
			if(SOF[$$L]['defaults'] && SOF[$$L]['defaults'][o.id]) {
				return o.value == SOF[$$L]['defaults'][o.id] ? false : !/^\s*$/.test(o.value);
			} else {
				return !/^\s*$/.test(o.value);
			}
		}
	},
	
	'empty': function(o) {
		return /^\s*$/.test(o.value);
	},
	
	'scroll': {
		'upDown': 28,
		'borders': 2,
		'limit': 30,
		'itemH': 14,
		'nbItems': 15,
		'animDelay': 30,
		'animSlow': 6
	}
};

if(!$$DF) {var $$DF = SOF.datasDatesForms;}

// remplacements formulaires
SOF.niceforms = {
	onSubmitTasks: {},
	onErrorMsg: {},
	enableFields: false,	
	imgTree: (document.location.href.match(/fichehotel/))?'fichehotel/sof':'commun',
	
	init: function() {
		var search = Box.nodes.get('#search')[0];
		var contact = Box.nodes.get('#contact')[0];
		var garantie = Box.nodes.get('#garantie')[0];
		if(!search && !contact && !garantie) {return;}
		var o, f, g, l;
		for(var id in $$DF.fields) {
			if($$DF.fields[id].onPage && !Box.nodes.hasClass(document.body, $$DF.fields[id].onPage)) { continue; }

			if($$DF.fields[id].group) {
				g = Box.nodes.get('input[name=' + id + ']');
				if(!g.length) {continue;}
				SOF.niceforms.replace(g, id, $$DF.fields[id].replaceBy);
				if($$DF.fields[id].replaceBy == 'checkbox') {SOF.niceforms.enableFields = true;}
			} else {
				o = Box.nodes.get('#' + id)[0];
				if(!o || (o.type && o.type == 'hidden')) {continue;}
				if($$DF.fields[id].replaceBy) {
					SOF.niceforms.replace(o, id, $$DF.fields[id].replaceBy);
				} else {
					if($$DF.fields[id].action) {$$DF.fields[id].action(o);}
				}
        if($$DF.fields[id].source) {SOF.niceforms.requestSource(id);}//prise en compte de la source
        if($$DF.fields[id].offres) {SOF.niceforms.requestOffres(id);}//prise en compte des offres
				if($$DF.fields[id].checkDates) {
					var c = $$DF.fields[id].checkDates;
					$$DF.dates[c[1]][c[0]] = id;
					$$DF.calendar.targets[c[1]][c[0]] = id;
				}
				if($$DF.fields[id].calendar) {$$DF.calendar.isPresent = true;}
			}
			if($$DF.fields[id].check) {
				if(!$$DF.fields[id].applyOn || $$DF.fields[id].applyOn && $$DF.fields[id].applyOn.indexOf(document.body.className) > -1) {
          SOF.niceforms.onSubmitTasks[id] = $$DF.fields[id].check;
        }
			}
		}

		o = null; f = null; g = null; // nettoyage
	},
	
	onSubmit: function(e, f) {
		var o, n = 0, condition = true, field;
		SOF.niceforms.onErrorMsg = {};
		for(var id in SOF.niceforms.onSubmitTasks) {
		  if ($$DF.fields[id].pseudoId)
			   o = Box.nodes.get('#' + $$DF.fields[id].pseudoId)[0];
			else
			   o = Box.nodes.get('#' + id)[0];
			if($$DF.fields[id].conditionField && $$DF.fields[id].conditionType) {
				field = Box.nodes.get('#' + $$DF.fields[id].conditionField)[0];
				condition = $$DF[$$DF.fields[id].conditionType](field);
			}
			// validation de champs multiples à base de jumeau (twin) - Pascal A. le 11/09/07
      if ($$DF.fields[id].twin && $$DF.fields[id].verif) {
				twin = $$DF.fields[id].twin;
				verif = $$DF.fields[id].verif;
				if (verif == "empty") {
				  if($$DF[SOF.niceforms.onSubmitTasks[id]].test(o) == false && Box.nodes.get('#' + twin)[0].value == "") {
            SOF.niceforms.onErrorMsg[id] = SOF[$$L].errorMsg[id];
            n++;
          }
				} else {
				  if($$DF[SOF.niceforms.onSubmitTasks[id]].test(o) == false && Box.nodes.get('#' + twin)[0].value == verif) {
            SOF.niceforms.onErrorMsg[id] = SOF[$$L].errorMsg[id];
            n++;
          }
				}
			}	else {
  			if($$DF[SOF.niceforms.onSubmitTasks[id]].test(o) == false) {
  				SOF.niceforms.onErrorMsg[id] = SOF[$$L].errorMsg[id];
  				if(condition) {n++;}
  			}
  		}
		}
		if(n > 0) {
      SOF.niceforms.onError(f, n);
			e.preventDefault();
		}
		else {
			// Seulement pour les pages offres de noheto
			var change_offre = Box.nodes.get('#offres_participant')[0];
			if (change_offre) {
				change_offre.id = "hotel_ou_ville";
				change_offre.name = "hotel_ou_ville";
				var val_CH = Box.nodes.get('#val-offres_participant')[0];
				val_CH.id = "val-hotel_ou_ville";
				var val_OP = Box.nodes.get('#val-offres_pays')[0];
				val_OP.id = "val-nom_pays";
				val_OP = Box.nodes.get('#offres_pays')[0];
				val_OP.id = "nom_pays";
				val_OP.name = "nom_pays";
			}
			// FIN : Seulement pour les pages offres de noheto
			// Seulement pour la page site_touristique
			var config = Box.nodes.get('#SA_config')[0];
			if (config && config.value < 2)
				config.value = 2;
			// FIN : Seulement pour la page site_touristique
		}
		if(n < 1 && SOF.niceforms.enableFields) {
			var fs = Box.nodes.get('input[type=checkbox]');
			for(var i = 0, f; f = fs[i]; i++) {
				if(f.disabled) {f.disabled = false;}
			}
			fs = null; f = null; // nettoyage
		}
		o = null; // nettoyage
	},
	
	onError: function(f, n) {
		var d = Box.nodes.get('#search-error')[0];
		if(d) {d.parentNode.removeChild(d);}
		var intro = n > 1 ? SOF[$$L].errorMsg.introP : SOF[$$L].errorMsg.introS;
		var insert = '<div id="search-error"><p>' + intro + '</p><ol>';
		for(var id in SOF.niceforms.onErrorMsg) {
			insert += '<li><a href="#" class="focus-' + id + '">' + SOF.niceforms.onErrorMsg[id] + '</a></li>';
		}
		insert += '</ol><a href="#" class="close"><img alt="" src="/imagerie/commun/search_error_close.gif" /></a></div>';
		Box.nodes.insert(insert, f, 'before', {
			'tag': 'div',
			'click': function(e) {SOF.niceforms.onErrorClose(e, f);}
		});
		// si necessaire, recalculer la hauteur de la popup et ajuster le scroll
		if(SOF.fakePopups && $$DP.stateH) {SOF.fakePopups.recompute();}
		d = null; // nettoyage
	},
	
	onErrorClose: function(e, f) {
		var t = e.target || e.srcElement;
		if(t.nodeName.toLowerCase() == 'img') {t = t.parentNode;}
		if(t.nodeName.toLowerCase() == 'a') {
			var id = t.className.replace('focus-', '');
			e.preventDefault();
			f.parentNode.removeChild(Box.nodes.get('#search-error')[0]);
			if(id != 'close') {
				var o = Box.nodes.get('#' + id)[0];
				if (o) {
  				if(o.type && o.type == 'hidden') {o = Box.nodes.get('a', Box.nodes.get('#' + id + '-rpl'))[0];}
  				o.focus();
				}
			}
		}
		// si necessaire, recalculer la hauteur de la popup et ajuster le scroll
		if(SOF.fakePopups && $$DP.stateH) {SOF.fakePopups.recompute();}
		t = null; o = null; // nettoyage
	},
	
	onFocus: function(n) {
		while((n = n.parentNode) && n.id.indexOf('-rpl') == -1);
		Box.nodes.addClass(n, 'focus') || Box.nodes.removeClass(n, 'focus');
		n = null; // nettoyage
	},
	
	clearValue: function(e) {
		var n = e.target || e.srcElement;
		if(n.form.id) {return;}
		if(n.value == SOF[$$L]['defaults'][n.id]) {n.value = '';}
		n = null; // nettoyage
	},
	
	restoreValue: function(e) {
		var n = e.target || e.srcElement;
		if(n.form.id) {return;}
		if(n.value == '') {n.value = SOF[$$L]['defaults'][n.id];}
		n = null; // nettoyage
	},
	resetValue: function(e, thetarget) {
    // BEGIN : PA 20071001 reset to 'default' value
	  $$DF.fields[thetarget].index = 0;
		$$DF.fields[thetarget].display.innerHTML = $$DF.fields[thetarget].val[0];
		// END : PA 20071001 reset to 'default' value
	},
	resetVal: function(thetarget) {
    // BEGIN : PA 20071001 reset to 'default' value
	  $$DF.fields[thetarget].index = 0;
		$$DF.fields[thetarget].display.innerHTML = $$DF.fields[thetarget].val[0];
		// END : PA 20071001 reset to 'default' value
	},
	
	request: function(id) {
		var r = $$DF.fields[id];
		var page = location.href;
			page = page.substring(page.lastIndexOf('/') + 1);
			page = page.replace('.shtml', '');
			page = page.replace('#', '');
		var url = r.ajax.url;
		if(r.ajax.url.indexOf('{LANG}')) {url = url.replace("{LANG}", $$L);}
		if(r.ajax.url.indexOf('{FILE}')) {url = url.replace("{FILE}", r.field.value);}
		url += '?lang=' + $$L + '&page=' + page + '&GC_country=' + r.field.value;
		if(r.field.value) {
			Box.ajax({
				'type': 'GET',
				'url': url,
				'onSuccess': SOF.niceforms.requestExe,
				'onSuccessDatas': {'target': r.ajax.target, 'item': r.ajax.item, 'page': page}
			});
		}
		r = null // nettoyage
	},
  
	requestSource: function(id) {
		var r = $$DF.fields[id];
		var page = location.href;
			page = page.substring(page.lastIndexOf('/') + 1);
			page = page.replace('.shtml', '');
			page = page.replace('#', '');
		var url = r.source.url;
		if(r.source.url.indexOf('{LANG}')) {url = url.replace("{LANG}", $$L);}
		if(r.source.url.indexOf('{FILE}')) {url = url.replace("{FILE}", r.field.value);}
		url += '?lang=' + $$L + '&page=' + page + '&GC_country=' + r.field.value;
		Box.ajax({
			'type': 'GET',
			'url': url,
			'onSuccess': SOF.niceforms.requestExe,
			'onSuccessDatas': {'target': r.source.target, 'item': r.source.item, 'page': page}
		});
		r = null // nettoyage
	},
	
	participants: function(id) {
		var r = $$DF.fields[id];
		var page = page2 = location.href;
			page = page.substring(page.lastIndexOf('/') + 1);
			var nom_fich = page;
			page = page.replace('.shtml', '');
			page = page.replace('#', '');
		var url = r.ajax_offre.url;
		var root = page2.replace(nom_fich, '');
		if(url.indexOf('{ADDR}')) {url = url.replace("{ADDR}", root);}
		if(url.indexOf('{OFFRE}')) {url = url.replace("{OFFRE}", page);}
		url += '?pays=' + r.field.value;
		Box.ajax({
			'type': 'GET',
			'url': url,
			'onSuccess': SOF.niceforms.requestExeParticipants,
			'onSuccessDatas': {'target': r.ajax_offre.target, 'item': r.ajax_offre.item, 'pays': r.field.value}
		});
		r = null // nettoyage
	},
	
	requestOffres: function(id) {
		var r = $$DF.fields[id];
		var page = page2 = location.href;
			page = page.substring(page.lastIndexOf('/') + 1);
			var nom_fich = page;
			page = page.replace('.shtml', '');
			page = page.replace('#', '');
		var url = r.offres.url;
		var root = page2.replace(nom_fich, '');
		if(url.indexOf('{ADDR}')) {url = url.replace("{ADDR}", root);}
		if(url.indexOf('{OFFRE}')) {url = url.replace("{OFFRE}", page);}
		Box.ajax({
			'type': 'GET',
			'url': url,
			'onSuccess': SOF.niceforms.requestExeOffre,
			'onSuccessDatas': {'target': r.offres.target, 'item': r.offres.item, 'page': page}
		});
		r = null // nettoyage
	},
	
	requestExeParticipants: function(d, p) {
		var l = Box.nodes.get(p.item, d);
		var c = Box.nodes.get('ol', Box.nodes.get('#' + p.target + '-rpl'))[0];
		var v = Box.nodes.get('#val-' + p.target)[0];
		if(!l || !c || !v) {return;}
		c.innerHTML = '';
		v.innerHTML = '';
		var r = $$DF.fields[p.target];
		r.end = l.length;
		r.index = -1;
		if(Box.nodes.hasClass(r.main, 'disabled')) {
			Box.nodes.removeClass(r.main, 'disabled');
			r.img.src = '/imagerie/'+SOF.niceforms.imgTree+'/fleche_select.gif';
		}
		var insert = '';
		for(var i = 0; i < l.length; i++) {
			if(Box.nodes.attribute(l[i].parentNode, 'cgi') != p.pays) {continue;}			
			r.val[i] = l[i].firstChild.nodeValue;
			r.cgi[i] = Box.nodes.attribute(l[i], 'cgi');
			insert += '<li><a href="#" class="' + i + '" tabindex="-1">' + l[i].firstChild.nodeValue + '</a></li>';
		}
		Box.nodes.insert(insert, c, 'last', {
			'tag': 'a',
			'click': function(e) {SOF.niceforms.manage.select(e, p.target, false);}
		});
		// actualisation du scroll
		if(r.scroll) {r.scroll.main.parentNode.removeChild(r.scroll.main);}
		if(parseInt(r.list.scrollHeight / $$DF.scroll.itemH) > $$DF.scroll.nbItems) {SOF.scroller.create(p.target);}
		l = null; c = null; r = null; v = null; // nettoyage
	},
	
	requestExeOffre: function(d, p) {
		var l = Box.nodes.get(p.item, d);
		var c = Box.nodes.get('ol', Box.nodes.get('#' + p.target + '-rpl'))[0];
		var v = Box.nodes.get('#val-' + p.target)[0];
		if(!l || !c || !v) {return;}
		c.innerHTML = '';
		v.innerHTML = '';
		var r = $$DF.fields[p.target];
		r.end = l.length;
		r.index = -1;
		if(Box.nodes.hasClass(r.main, 'disabled')) {
			Box.nodes.removeClass(r.main, 'disabled');
			r.img.src = '/imagerie/'+SOF.niceforms.imgTree+'/fleche_select.gif';
		}
		var insert = '';
		for(var i = 0; i < l.length; i++) {			
			r.val[i] = Box.nodes.attribute(l[i], 'nom');
			r.cgi[i] = Box.nodes.attribute(l[i], 'cgi');
			insert += '<li><a href="#" class="' + i + '" tabindex="-1">' + r.val[i] + '</a></li>';
		}
		Box.nodes.insert(insert, c, 'last', {
			'tag': 'a',
			'click': function(e) {SOF.niceforms.manage.select(e, p.target, false);}
		});
		// actualisation du scroll
		if(r.scroll) {r.scroll.main.parentNode.removeChild(r.scroll.main);}
		if(parseInt(r.list.scrollHeight / $$DF.scroll.itemH) > $$DF.scroll.nbItems) {SOF.scroller.create(p.target);}
		l = null; c = null; r = null; v = null; // nettoyage
	},

	requestExe: function(d, p) {
		var l = Box.nodes.get(p.item, d);
		var c = Box.nodes.get('ol', Box.nodes.get('#' + p.target + '-rpl'))[0];
		var v = Box.nodes.get('#val-' + p.target)[0];
		if(!l || !c || !v) {return;}
		c.innerHTML = '';
		v.innerHTML = '';
		var r = $$DF.fields[p.target];
		r.end = l.length;
		r.index = -1;
		if(Box.nodes.hasClass(r.main, 'disabled')) {
			Box.nodes.removeClass(r.main, 'disabled');
			r.img.src = '/imagerie/'+SOF.niceforms.imgTree+'/fleche_select.gif';
		}
		var insert = '';
		for(var i = 0; i < l.length; i++) {			
			if(Box.nodes.attribute(l[i].parentNode, 'url') != p.page) {continue;}
			r.val[i] = l[i].firstChild.nodeValue;
			r.cgi[i] = Box.nodes.attribute(l[i], 'cgi');
			insert += '<li><a href="#" class="' + i + '" tabindex="-1">' + l[i].firstChild.nodeValue + '</a></li>';
		}
		Box.nodes.insert(insert, c, 'last', {
			'tag': 'a',
			'click': function(e) {SOF.niceforms.manage.select(e, p.target, false);}
		});
		// actualisation du scroll
		if(r.scroll) {r.scroll.main.parentNode.removeChild(r.scroll.main);}
		if(parseInt(r.list.scrollHeight / $$DF.scroll.itemH) > $$DF.scroll.nbItems) {SOF.scroller.create(p.target);}
		l = null; c = null; r = null; v = null; // nettoyage
	},
	
	trimThalassa: function(o) {
		switch($$DF.dureeSejour.value) {
			case '2':
				Box.nodes.get('#RA1')[0].value = "FWEWEB";
				Box.nodes.get('#RA2')[0].value = "FAWWEB";
				break;
			case '6':
				Box.nodes.get('#RA1')[0].value = "FCUWEB";
				Box.nodes.get('#RA2')[0].value = "FACWEB";
				break;
			case '7':
				Box.nodes.get('#RA1')[0].value = "FC7WEB";
				Box.nodes.get('#RA2')[0].value = "FA7WEB";
				break;
			default:
				Box.nodes.get('#RA1')[0].value = "FWEWEB";
				Box.nodes.get('#RA2')[0].value = "FAWWEB";
				break;
		}
		var l = Box.nodes.get('li', [$$DF.fields[o.target].list]), i = 0, hide = true, inner;
		var d = 'duree-' + $$DF.dureeSejour.value;
		while(l[i]) {
			inner = l[i].innerHTML.toLowerCase();
			if(inner.indexOf('</span>') > -1) {
				inner = inner.replace(/<\/?span>/g, '');
				hide = o.datas[d].indexOf(inner) > -1 ? false : true;
				hide ? Box.nodes.addClass(l[i], 'hide') : Box.nodes.removeClass(l[i], 'hide');
				i++;
				continue;
			}
			hide ? Box.nodes.addClass(l[i], 'hide') : Box.nodes.removeClass(l[i], 'hide');
			i++;
		}
	},
	
	addStates: function(id, onStates) {
		if($$DF.fields[id].applyOn && document.body.className.indexOf($$DF.fields[id].applyOn) < 0) {return;}
		var c = $$DF.fields[id].cible;
		var r = $$DF.fields[c];
		var v = $$DF.fields[id].field.value;
		var verif = Box.nodes.get('#' + c + '-rpl')[0];
		if(verif) {
			verif = verif.parentNode;
			verif.parentNode.removeChild(verif);
			// si necessaire, recalculer la hauteur de la popup et ajuster le scroll
			if(SOF.fakePopups && $$DP.stateH) {SOF.fakePopups.recompute();}
		}
		if(onStates && onStates.indexOf('[' + v + ']') == -1) {return;}
		if(SOF[$$L].states[v]) {
			var insert = '', items = '';
			r.start = 0; r.end = SOF[$$L].states[v].cgi.length; r.index = 0; r.val = SOF[$$L].states[v].val; r.cgi = SOF[$$L].states[v].cgi;
			for(var i = 0; i < SOF[$$L].states[v].cgi.length; i++) {
				items += '<li><a href="#" class="val-' + i + '" tabindex="-1">' + r.val[i] + '</a></li>';
			}
			insert += '<div class="field etat">';
			insert += '<label for="' + c + '">' + SOF[$$L].label[c] + '</label>';
			insert += '<input type="hidden" id="' + c + '" name="' + c + '" value="" />';
			insert += '<div id="' + c + '-rpl" class="js-select">';
			insert += '<div class="open-close"><a href="#"><img alt="' + SOF[$$L].alt.openSelect + '" src="/imagerie/'+SOF.niceforms.imgTree+'/fleche_select.gif" /></a></div>';
			insert += '<div class="current"><span id="val-' + c + '"></span></div>';
			insert += '<ol class="hidden">';
			insert += items;
			insert += '</ol>';
			insert += '</div>';
			insert += '</div>';
			Box.nodes.insert(insert, $$DF.fields[id].main.parentNode, 'after', {
				'tag': 'a',
				'click': function(e) {SOF.niceforms.manage.select(e, c, false);},
				'keydown': function(e) {SOF.niceforms.manage.select(e, c, true);},
				'focus': function() {SOF.niceforms.onFocus(this);},
				'blur': function() {SOF.niceforms.onFocus(this);}
			});
			r.main = Box.nodes.get('#' + c + '-rpl')[0];
			r.display = Box.nodes.get('#val-' + c)[0];
			r.field = Box.nodes.prev(r.main);
			r.list = Box.nodes.get('ol', [r.main])[0];
			r.img = Box.nodes.get('img', [r.main])[0];
			l = Box.nodes.get('label[for=' + c + ']')[0];
			if(l) {Box.events.add(l, 'click', function(e) {SOF.niceforms.manage.label(e, this, c, 'select');});}
			if(parseInt(r.list.offsetHeight / $$DF.scroll.itemH) > $$DF.scroll.nbItems) {SOF.scroller.create(c);}
			// si nécessaire, recalculer la hauteur de la popup et ajuster le scroll
			if(SOF.fakePopups && $$DP.stateH) {SOF.fakePopups.recompute();}
			if(r.openDir && r.openDir == 'up') {r.list.style.top = '-' + r.list.offsetHeight + 'px';}
		}
		r = null; verif = null; // nettoyage
	},
	
	changeDestination: function() {
		var v;
		if($$DF.fields.topSelect.field) {
			v = $$DF.fields.topSelect.val[$$DF.fields.topSelect.index];
			v = v == SOF[$$L].defaults.topSelect ? SOF[$$L].defaults.hotel_ou_ville : v;
		} else if($$DF.fields.destination.field) {
			v = $$DF.fields.destination.field.value;
		} else {
			return;
		}
		Box.nodes.get('#hotel_ou_ville')[0].value = v;
		Box.nodes.get('#hotel_ou_ville')[0].focus();
	},
	
	tooltip: function(id) {
		Box.nodes.addClass($$DF.fields[id].tooltipE, 'hidden') || Box.nodes.removeClass($$DF.fields[id].tooltipE, 'hidden');
	},
	
	replace: function(o, id, type) {
		if($$DF.fields[id].group && $$DF.fields[id].replaceBy == 'checkbox') {type = 'checkboxGroup';}
		SOF.niceforms.create[type](o, id);
	},
	classExtract: function(str, srch)	{
		var retour = "-1", num = "", temp = "";
		if (str.indexOf(srch) > -1)	{
			for (var i = str.indexOf(srch)+4; i < str.length; i++)	{
				temp = str.charAt(i);
				if (temp != " ")
					num += temp.toString();
				else
					continue;
			}
			retour = num;
		}
		return retour;
	},	
	create: {
		select: function(o, id) {
      var r = $$DF.fields[id];
			var insert = '', items = '', l, minify = '';
      /*correction@20071112*/if(Box.nodes.hasClass(o, 'standalone')) {r.standalone = true;}/*END correction@20071112*/
			if(o.name) {r.name = o.name;}
			if(o.type == 'select-one') {
				r.start = o.selectedIndex; r.end = o.length; r.index = o.selectedIndex; r.val = []; r.cgi = []; var h;
				for(var i = 0; i < o.length; i++) {
					r.val[i] = o[i].innerHTML;
					r.cgi[i] = o[i].value;
					h = i == 0 && !r.val[i] ? ' class="hide"' : '';
					// BEGIN : PA 20070928 - Initialyse empty select option with 'default' tag
          if(Box.nodes.attribute(o, 'default') == 'empty')
					   h = ' class="hide"';
					// END : PA 20070928 - Initialyse empty select option with 'default' tag
					if(Box.nodes.hasClass(o[i], 'title')) {
						items += '<li' + h + '><span>' + r.val[i] + '</span></li>';
					} else {
						items += '<li' + h + '><a href="#" class="val-' + i + '" tabindex="-1">' + r.val[i].replace('\\', '') + '</a></li>';
					}
					if(r.dureeSejour) {
						r.dureeSejour[r.dureeSejour.length] = o[i].className ? Number(o[i].className.match(/\d+/)[0]) : '';
					}
					if(r.codeMarque) {
						r.codeMarque[r.codeMarque.length] = o[i].className ? o[i].className.replace('marque-', '') : '';
					}
				}
			} else {
			if(r.checkDuree) {
				var m_index = SOF.niceforms.classExtract(o.className, 'min-');
				m_index = parseInt(m_index);
				if(m_index > -1) {
					r.start = m_index;
					SOF.dates.dureeSejourMin = r.start;
				}
				m_index = SOF.niceforms.classExtract(o.className, 'max-');
				m_index = parseInt(m_index);
				if(m_index > -1) {r.end = m_index;}
				if (SOF.dates.weekend) {r.end = SOF.dates.ldow;}
				if(r.end < 7) {minify = ' minify';}
			}
/*				correction@20071112*/
				if(r.checkStart) {
					var tmp = o.className.match(/\d+/g);
					if(tmp) {
						if(tmp.length == 1) {
							SOF.dates.current.d = SOF.dates.current.d + Number(tmp[0]);
							SOF.dates.current = SOF.dates.getCorrect(SOF.dates.current);
						} else if(tmp.length >= 3) {
							SOF.dates.current.d = Number(tmp[0]);
							SOF.dates.current.m = Number(tmp[1]);
							SOF.dates.current.y = Number(tmp[2]);
						}
						r.index = SOF.dates.current.d - 1;
						$$DF.fields[r.checkStart[0]].index = SOF.dates.current.m - 1;
						var c = 0, year = SOF.dates.current.y;
						while(year < SOF.dates.current.y) {year++; c++;}
						$$DF.fields[r.checkStart[1]].index = c;
						if(tmp.length == 6) {
							SOF.dates.limitMax.d = Number(tmp[3]);
							SOF.dates.limitMax.m = Number(tmp[4]);
							SOF.dates.limitMax.y = Number(tmp[5]);
						}
					}
				}
/*				END correction@20071112*/
			r.val = SOF.dates.range(r.start, r.end);
			r.cgi = SOF.dates.range(r.start, r.end, 'cgi');
			var additionnalClass = '';
			if(r.noValuePossible && location.href.indexOf(r.noValuePossible) > -1) {
				r.val.unshift('-');
				r.cgi.unshift('');
				r.index = 0;
				additionnalClass = ' empty';
			}
			// BEGIN : PA 20071001 no defaults dates for 'destination' 
			if(r.noValuePossible2 && location.href.indexOf(r.noValuePossible2) > -1) {
				r.val.unshift('-');
				r.cgi.unshift('');
				r.index = 0;
				additionnalClass = ' empty';
			}
			// END : PA 20071001 no defaults dates for 'destination' 
			for(var i = 0; i < r.val.length; i++) {
				if(additionnalClass && i > 0) {additionnalClass = '';}
				items += '<li><a href="#" class="val-' + i + additionnalClass + '" tabindex="-1">' + r.val[i] + '</a></li>';
			}
			}
			// BEGIN : PA 20071129 Manipulation d'un évènement "OnChange" sur le tag
			var MyOnChange = "";
			if (Box.nodes.attribute(o, "OnChange")) {
				MyOnChange = Box.nodes.attribute(o, "OnChange");
				MyOnChange = MyOnChange.toString();
				//alert(o.id+" : \""+MyOnChange+"\"");
				if (MyOnChange.lastIndexOf("anonymous") > 0)
				{
					MyOnChange = MyOnChange.substring(23);
					MyOnChange = MyOnChange.substring(0, MyOnChange.length-2);
				}
				//alert(o.id+" : \""+MyOnChange+"\"");
			}
			// END : PA 20071129 Manipulation d'un évènement "OnChange" sur le tag 
			
			var disabled = r.disabled ? ' disabled' : '';
			insert += '<input type="hidden" id="' + r.name + '" name="' + r.name + '" value="' + r.cgi[r.index] + '" />';
			insert += '<div id="' + id + '-rpl" class="js-select' + disabled + minify + '">';
			disabled = r.disabled ? 'fleche_select_disabled' : 'fleche_select';
			insert += '<div class="open-close"><a href="#"><img alt="' + SOF[$$L].alt.openSelect + '" src="/imagerie/'+SOF.niceforms.imgTree+'/' + disabled + '.gif" /></a></div>';
			insert += '<div class="current"><span id="val-' + id + '">' + r.val[r.index] + '</span></div>';
			insert += '<ol class="hidden">';
			insert += items;
			insert += '</ol>';
			if(r.tooltip) {insert += '<div id="' + id + '-tip" class="tooltip hidden"><span>' + r.tooltip + '</span></div>';}
			insert += '</div>';
			Box.nodes.insert(insert, o, 'after', {
				'tag': 'a',
				'click': function(e) {
							SOF.niceforms.manage.select(e, id, false);
							if (MyOnChange.length > 0)
								eval(MyOnChange);
				},
				'keydown': function(e) {
							SOF.niceforms.manage.select(e, id, true);
				},
				'focus': function() {SOF.niceforms.onFocus(this);},
				'blur': function() {SOF.niceforms.onFocus(this);}
			});
			o.parentNode.removeChild(o);
			r.main = Box.nodes.get('#' + id + '-rpl')[0];
			r.display = Box.nodes.get('#val-' + id)[0];
			r.field = Box.nodes.prev(r.main);
			r.list = Box.nodes.get('ol', [r.main])[0];
			r.img = Box.nodes.get('img', [r.main])[0];
			if(r.tooltip) {
				r.tooltipE = Box.nodes.get('#' + id + '-tip')[0];
				r.tooltipE.style.top = '-' + (r.tooltipE.offsetHeight + 2) + 'px';
				Box.events.add(r.main, 'mouseover', function() {SOF.niceforms.tooltip(id);});
				Box.events.add(r.main, 'mouseout', function() {SOF.niceforms.tooltip(id);});
			}
			l = Box.nodes.get('label[for=' + id + ']')[0];
			if(l) {Box.events.add(l, 'click', function(e) {SOF.niceforms.manage.label(e, this, id, 'select');});}
			if(r.codeMarque) {r.codeMarqueField = Box.nodes.next(r.main);}
			
			//alert("offsetHeight "+r.list.offsetHeight+", itemH "+$$DF.scroll.itemH+", nbItems "+$$DF.scroll.nbItems);
			if(parseInt(r.list.offsetHeight / $$DF.scroll.itemH) > $$DF.scroll.nbItems) {SOF.scroller.create(id);}
			if(r.openDir && r.openDir == 'up') {r.list.style.top = '-' + r.list.offsetHeight + 'px';}
			r = null; l = null; // nettoyage
		},
		checkbox: function(o, id) {
			var r = $$DF.fields[id];
			var l = Box.nodes.next(o), insert = '', checked;
			if(l) {Box.events.add(l, 'click', function(e) {SOF.niceforms.manage.label(e, this, id, 'checkbox');});}
			checked = o.checked ? 'checked' : 'notchecked';
			insert += '<input type="hidden" id="' + id + '" name="' + id + '" value="' + r['default'] + '" />';
			insert += '<div id="' + id + '-rpl" class="js-checkbox"><a href="#" class="' + checked + '"></a></div>';
			Box.nodes.insert(insert, o, 'after', {
				'tag': 'a',
				'click': function(e) {SOF.niceforms.manage.checkbox(e, id, false);},
				'keydown': function(e) {SOF.niceforms.manage.checkbox(e, id, true);}
			});
			r.main = Box.nodes.get('#' + id + '-rpl')[0];
			r.field = Box.nodes.prev(r.main);
			if(o.checked) {r.field.value = SOF[$$L]['checkValue']['y'];}
			o.parentNode.removeChild(o);
			r = null; l = null; // nettoyage
		},
		checkboxGroup: function(g, id) {
			var r = $$DF.fields[id], l, checked;
			for(var i = 0, gi; gi = g[i]; i++) {
				l = Box.nodes.next(gi);
				if(l) {Box.events.add(l, 'click', function(e) {SOF.niceforms.manage.label(e, this, Box.nodes.attribute(this, 'for'), 'checkboxGroup');});}
				if(gi.checked) {
					checked = 'checked';
				} else {
					checked = 'notchecked';
				}
				insert = '<div id="' + gi.id + '-rpl" class="js-checkbox"><a href="#" class="' + checked + '"></a></div>';
				Box.nodes.insert(insert, gi, 'after', {
					'tag': 'a',
					'click': function(e) {SOF.niceforms.manage.checkbox(e, id, false);},
					'keydown': function(e) {SOF.niceforms.manage.checkbox(e, id, true);}
				});
				r.group[r.group.length] = Box.nodes.get('#' + gi.id + '-rpl')[0];
				Box.nodes.addClass(gi, 'hidden');
				gi.disabled = true;
			}
			r = null; l = null; // nettoyage
		},
		radio: function(g, id) {
			var r = $$DF.fields[id], l, checked;
			var insert = '<input type="hidden" name="' + id + '" value="" />';
			Box.nodes.insert(insert, g[0], 'before');
			r.field = Box.nodes.prev(g[0]);
			for(var i = 0, gi; gi = g[i]; i++) {
				l = Box.nodes.next(gi);
				if(l) {Box.events.add(l, 'click', function(e) {SOF.niceforms.manage.label(e, this, id, 'radio');});}
				if(gi.checked) {
					checked = 'checked';
					r.field.value = gi.value;
				} else {
					checked = 'notchecked';
				}
				insert = '<div id="' + gi.id + '-rpl" class="js-radio val-' + gi.value + '"><a href="#" class="' + checked + '"></a></div>';
				Box.nodes.insert(insert, gi, 'after', {
					'tag': 'a',
					'click': function(e) {SOF.niceforms.manage.radio(e, id, false);},
					'keydown': function(e) {SOF.niceforms.manage.radio(e, id, true);}
				});
				r.group[r.group.length] = Box.nodes.get('#' + gi.id + '-rpl')[0];
				if(gi.checked) {r.last = Box.nodes.get('a', [r.group[r.group.length - 1]])[0];}
				gi.parentNode.removeChild(gi);
			}
			r = null; l = null; // nettoyage
		}
	},
	
	manage: {
		label: function(e, n, id, type) {
			var t = e.target || e.srcElement;
			if(t.nodeName.toLowerCase() == 'a' || n.nodeName.toLowerCase() != 'label') {return;}
			e.preventDefault();
			var a;
			if(type == 'select') {
				a = Box.nodes.get('a', [$$DF.fields[id].main])[0];
				a.focus();
			} else if(type == 'checkbox') {
				$$DF.fields[id].field.value = $$DF.fields[id].field.value == '0' ? '1' : '0';
				a = Box.nodes.get('a', [Box.nodes.prev(n)])[0];
				Box.nodes.swapClass(a, 'checked', 'notchecked') || Box.nodes.swapClass(a, 'notchecked', 'checked');
				a.focus();
			} else if(type == 'checkboxGroup') {
				var c = Box.nodes.get('#' + id)[0];
				c.checked = c.checked ? false : true;
				a = Box.nodes.get('a', [Box.nodes.prev(n)])[0];
				Box.nodes.swapClass(a, 'checked', 'notchecked') || Box.nodes.swapClass(a, 'notchecked', 'checked');
				a.focus();
			} else if(type == 'radio') {
				if($$DF.fields[id].last) {Box.nodes.swapClass($$DF.fields[id].last, 'checked', 'notchecked');}
				a = Box.nodes.get('a', [Box.nodes.prev(n)])[0];
				if(Box.nodes.hasClass(a, 'notchecked')) {
					Box.nodes.swapClass(a, 'notchecked', 'checked');
					$$DF.fields[id].field.value = a.parentNode.className.replace(/^.+val-/, '');
					$$DF.fields[id].last = a;
					if($$DF.fields[id].action) {$$DF.fields[id].action();}
				}
			}
			t = null; a = null; // nettoyage
		},
		getTarget: function(e, id) {
			var t = e.target || e.srcElement;
			var limit = id ? $$DF.fields[id].main : document.body;
			while(t.nodeName.toLowerCase() != 'a' && t  != limit) {t = t.parentNode;}
			if(t.nodeName.toLowerCase() != 'a') {t = null;}
			return t;
		},
		getKey: function(e) {
			return e.which || e.keyCode;
		},
		checkbox: function(e, id, keyboard) {
			var t = SOF.niceforms.manage.getTarget(e, id), c;
			if(!t) {return;}
			var k = SOF.niceforms.manage.getKey(e);
			if(!keyboard || k == 32) {
				if(Box.nodes.hasClass(t, 'checked')) {
					Box.nodes.swapClass(t, 'checked', 'notchecked');
					if(!$$DF.fields[id].group) {
						if (!isNaN(parseFloat(Box.nodes.get('#'+id)[0].value)))
							$$DF.fields[id].field.value = 0;
						else
							$$DF.fields[id].field.value = SOF[$$L]['checkValue']['n'];
					} else {
						c = Box.nodes.prev(t.parentNode);
						c.checked = false;
					}
				} else {
					Box.nodes.swapClass(t, 'notchecked', 'checked');
					if(!$$DF.fields[id].group) {
						if (!isNaN(parseFloat(Box.nodes.get('#'+id)[0].value)))
							$$DF.fields[id].field.value = 1;
						else
							$$DF.fields[id].field.value = SOF[$$L]['checkValue']['y'];
					} else {
						c = Box.nodes.prev(t.parentNode);
						c.checked = true;
					}
				}
				if($$DF.fields[id].action) {$$DF.fields[id].action();}
				e.preventDefault();
			}
			t = null; c = null; // nettoyage
		},
		radio: function(e, id, keyboard) {
			var t = SOF.niceforms.manage.getTarget(e);
			if(!t) {return;}
			var k = SOF.niceforms.manage.getKey(e);
			if(!keyboard || k == 32) {
				if($$DF.fields[id].last) {Box.nodes.swapClass($$DF.fields[id].last, 'checked', 'notchecked');}
				if(Box.nodes.hasClass(t, 'notchecked')) {
					Box.nodes.swapClass(t, 'notchecked', 'checked');
					$$DF.fields[id].field.value = t.parentNode.className.replace(/^.+val-/, '');
					$$DF.fields[id].last = t;
				}
				if($$DF.fields[id].action) {$$DF.fields[id].action();}
				e.preventDefault();
			}
			t = null; // nettoyage
		},
		select: function(e, id, keyboard) {
		
				//	alert("choisi "+e+") : "+id);

			var t = SOF.niceforms.manage.getTarget(e, id);
			if(!t) {return;}
			$$DF.lastKeySelect = null;
			var r = $$DF.fields[id];
			
			
			var k = SOF.niceforms.manage.getKey(e);
			if(Box.nodes.hasClass(r.main, 'disabled')) {if(k != 9) {e.preventDefault();} return;}
			if(keyboard) {
				$$DF.lastKeySelect = k;
				if($$DF.lastSelect) {Box.nodes.addClass($$DF.lastSelect, 'hidden');}
				if($$DF.lastImg) {$$DF.lastImg.alt = SOF[$$L].titleOpenSelect;}
				if($$DF.lastField) {Box.nodes.removeClass($$DF.lastField, 'active');}
				if(k == 40) {
					r.index = r.index >= r.val.length - 1 ? r.val.length - 1 : r.index + 1;
					e.preventDefault();
				} else if(k == 38) {
					r.index = r.index <= 0 ? 0 : r.index - 1;
					e.preventDefault();
				} else if(k == 13) {
					if(r.scroll) {SOF.scroller.toggle();}
					e.preventDefault();
				} else {
					if(r.scroll) {SOF.scroller.toggle();}
					return;
				}
			} else {
				if($$DF.lastSelect && $$DF.lastSelect != r.list) {Box.nodes.addClass($$DF.lastSelect, 'hidden');}
				if($$DF.lastImg && $$DF.lastImg != r.img) {$$DF.lastImg.alt = SOF[$$L].alt.openSelect;}
				$$DF.lastSelect = r.list;
				$$DF.lastImg = r.img;
				if(Box.nodes.attribute(r.img, 'alt') == SOF[$$L].alt.closeSelect) {
					Box.nodes.addClass(r.list, 'hidden');
					if($$DF.lastField) {
						Box.nodes.removeClass($$DF.lastField, 'active');
						$$DF.lastField = null;
					}
					if(r.scroll) {SOF.scroller.toggle(id);}
					r.img.alt = SOF[$$L].alt.openSelect;
				} else {
					Box.nodes.removeClass(r.list, 'hidden');
					if($$DF.lastField) {Box.nodes.removeClass($$DF.lastField, 'active');}
					$$DF.lastField = r.list.parentNode.parentNode;
					Box.nodes.addClass($$DF.lastField, 'active');
					if(r.scroll) {SOF.scroller.toggle(id);}
					r.img.alt = SOF[$$L].alt.closeSelect;
				}
				if(t.className) {
					r.index = t.className.replace('val-', '');
					r.index = Number(r.index.replace(' empty', ''));
				}
				e.preventDefault();
			}
			if(keyboard || t.className) {
				if(r.dureeSejour) {
					$$DF.dureeSejour.value = r.dureeSejour[r.index];
					SOF.dates.dureeSejour = r.dureeSejour[r.index];
					SOF.dates.updateDuree();
					SOF.dates.control('start');
				}
				//alert(r.field.name+" index "+r.cgi[r.index]);
				if(r.codeMarqueField) {r.codeMarqueField.value = r.codeMarque[r.index];}
				r.display.innerHTML = r.index < 0 ? '' : r.val[r.index];
				r.field.value = r.index < 0 ? '' : r.cgi[r.index];
				if(r.noValuePossible && r.val[r.index] == '-') {
					SOF.dates.reset('start');
				} else if(r.action) {
					r.action();
				}
				if(r.ajax) {SOF.niceforms.request(id);}
				if(r.ajax_offre) {SOF.niceforms.participants(id);}
				if($$DF.dayOfWeek) {$$DF.dayOfWeek.innerHTML = '(' + SOF.dates.dayOfWeek('start') + ')';}
			}
			r = null; t = null; // nettoyage
		}
	},
	update: {
		select: function(id, value) {
			var r = $$DF.fields[id];
			// trouver l'index de la valeur dans les valeurs du select
			var index = null;
			for (var i=r.start; i<r.end && index==null; i++){
			   if (r.cgi[i].toLowerCase() == value.toLowerCase()) index=i;
			}
			// mise a jour du display (affichage) et du champ (valeur hidden)
			if (index!=null){
				r.index=index;
				if(r.dureeSejour) {
					$$DF.dureeSejour.value = r.dureeSejour[index];
					SOF.dates.dureeSejour = r.dureeSejour[index];
					SOF.dates.updateDuree();
					SOF.dates.control('start');
				}
				if(r.codeMarqueField) {r.codeMarqueField.value = r.codeMarque[index];}
				r.display.innerHTML = r.val[index];
				r.field.value = r.cgi[index];
				if(r.action) {r.action();}
				if(r.ajax) {SOF.niceforms.request(id);}
				if($$DF.dayOfWeek) {$$DF.dayOfWeek.innerHTML = '(' + SOF.dates.dayOfWeek('start') + ')';}
			}
		}
	}
};

// scroller sur les listes
SOF.scroller = {
	create: function(id) {
		var r = $$DF.fields[id], insert = '';
		Box.nodes.addClass(r.list, 'scrolled');
		insert += '<div class="scroller">';
		insert += '<a class="scroller-up" href="#"><img src="/imagerie/'+SOF.niceforms.imgTree+'/scroll_up.gif" alt="' + SOF[$$L].alt.scrollUp + '" /></a>';
		insert += '<a class="scroller-down" href="#"><img src="/imagerie/'+SOF.niceforms.imgTree+'/scroll_down.gif" alt="' + SOF[$$L].alt.scrollDown + '" /></a>';
		insert += '<span class="scroller-state"></span>';
		insert += '</div>';
		Box.nodes.insert(insert, r.main, 'last');
		r.scroll = {};
		r.scroll.main = Box.nodes.get('div.scroller', [r.main])[0];
		r.scroll.upDown = Box.nodes.get('a', [r.scroll.main]);
		r.scroll.span = Box.nodes.get('span', [r.scroll.main])[0];
		r.scroll.target = Box.nodes.get('li', [r.list])[0];
		if(Box.nodes.hasClass(r.scroll.target, 'hide')) {r.scroll.target = Box.nodes.next(r.scroll.target);}
		r.scroll.mask = r.list.offsetHeight - $$DF.scroll.borders;
		r.scroll.dispo = r.scroll.mask - $$DF.scroll.upDown;
		r.scroll.full = r.list.scrollHeight;
		// New nurun
		r.scroll.dim = Math.ceil(r.scroll.mask / r.scroll.full * r.scroll.dispo);
		//r.scroll.min = Math.floor(r.scroll.dispo * r.scroll.dispo / r.scroll.full);
		//r.scroll.max = Math.ceil(r.scroll.dispo * r.scroll.dispo / r.scroll.full);
		r.scroll.left = r.list.offsetWidth - r.scroll.main.offsetWidth - $$DF.scroll.borders;
		// New nurun
		r.scroll.amount = r.scroll.dispo - Math.ceil(r.scroll.dispo / r.scroll.dim);
		//r.scroll.amount = r.scroll.dispo - Math.ceil(r.scroll.dispo / r.scroll.min);
		r.scroll.main.style.height = r.scroll.mask + 'px';
		r.scroll.main.style.left = '-10000px';
		if(r.openDir && r.openDir == 'up') {r.scroll.main.style.top = '-' + (r.list.offsetHeight - 1) + 'px';}
		// New nurun
		r.scroll.span.style.height = r.scroll.dim + 'px';
		//r.scroll.span.style.height = r.scroll.max + 'px';
		r.scroll.span.style.top = '0';
		r.scroll.target.style.marginTop = '0';
		Box.events.add(r.scroll.upDown[0], 'click', function(e) {
			SOF.scroller.exe(e, id);
		});
		Box.events.add(r.scroll.upDown[1], 'click', function(e) {
			SOF.scroller.exe(e, id);
		});
		Box.events.add(r.scroll.main, 'click', function(e) {
			SOF.scroller.exe(e, id);
		});
		// coordonnées maximum pour drag'n'drop
		// New nurun
		var maxY = r.scroll.dispo - r.scroll.dim;
		//var maxY = r.scroll.dispo - r.scroll.max;
		// init Drag'n'drop
		Box.drag.init(r.scroll.span, null, 0, 0, 0, maxY);
		r.scroll.span.onDrag = function(nx, ny) {SOF.scroller.dragMove(id, ny);}
		r = null; //nettoyage
	},
	dragMove: function(id, ny) {
		var r = $$DF.fields[id].scroll;
		var top = Math.round(ny / r.dispo * r.full);
		if(top > (r.full - r.mask)) {top = r.full - r.mask;}
		r.target.style.marginTop = - top + 'px';
		r = null; //nettoyage
	},
	exe: function(e, id) {
		var t = e.target || e.srcElement, r = $$DF.fields[id].scroll;
		// cas d'un clic sur une zone pouvant contenir la scrollbar
		if(t.nodeName.toLowerCase() == 'div' && Box.nodes.hasClass(t, 'scroller')) {
			var c = Box.events.getXY(e).y - (Box.nodes.findPos(t)[1] + $$DF.scroll.upDown / 2),
				top = parseInt(r.span.style.top),
				move = c - top < 0 ? top - c : c - top - r.dim,
				amount = Math.round(move / r.dispo * r.full);
			if(c - top > 0) {
				SOF.scroller.startDown(id, amount);
			} else {
				SOF.scroller.startUp(id, amount);
			}
		}
		// fin cas
		while(t.nodeName.toLowerCase() != 'a' && t != r.main) {t = t.parentNode;}
		var top = Math.abs(parseInt(r.target.style.marginTop));
		if(t == r.upDown[0] && !r.inAnim) {
			// New nurun
			SOF.scroller.startUp(id);
			/*
			var to = top - r.amount <= 0 ? 0 : top - r.amount;
			if(to < $$DF.scroll.limit) {to = 0;}
			r.inAnim = true;
			SOF.scroller.objectUp(to, id);
			var scroll = Math.ceil(to / r.full * r.dispo);
			if((scroll <= 0) || (to == 0 && scroll != 0)) {scroll = 0;}
			r.inAnim1 = true;
			SOF.scroller.barUp(scroll, id);
			*/
		} else if(t == r.upDown[1] && !r.inAnim) {
			// New nurun
			SOF.scroller.startDown(id);
			/*
			var to = (top + r.mask + r.amount) > r.full ? r.full - r.mask : top + r.amount;
			if(r.full - to - r.mask < $$DF.scroll.limit) {to = r.full - r.mask;}
			r.inAnim = true;
			SOF.scroller.objectDown(to, id);
			var scroll = Math.ceil(to / r.full * r.dispo);
			if((scroll + r.max > r.dispo) || (to == r.full - r.mask)) {scroll = r.dispo - r.max;}
			r.inAnim1 = true;
			SOF.scroller.barDown(scroll, id);
			*/
		}
		e.preventDefault();
		t = null; r = null; // nettoyage
	},
	startDown: function(id, move) {
		var r = $$DF.fields[id].scroll,
			top = Math.abs(parseInt(r.target.style.marginTop)),
			amount = move || r.amount,
			to = top - amount <= 0 ? 0 : top - amount;
		var to = (top + r.mask + amount) > r.full ? r.full - r.mask : top + amount;
		if(r.full - to - r.mask < $$DF.scroll.limit) {to = r.full - r.mask;}
		r.inAnim = true;
		SOF.scroller.objectDown(to, id);
		var scroll = parseInt(r.span.style.top) - Math.ceil(r.dispo * (top - to) / r.full);		
		if((scroll + r.dim > r.dispo) || (to == r.full - r.mask)) {scroll = r.dispo - r.dim;}
		r.inAnim1 = true;
		SOF.scroller.barDown(scroll, id);
		r = null; // nettoyage
	},
	startUp: function(id, move) {
		var r = $$DF.fields[id].scroll,
			top = Math.abs(parseInt(r.target.style.marginTop)),
			amount = move || r.amount,
			to = (top + r.mask + amount) > r.full ? r.full - r.mask : top + amount;
		var to = top - amount <= 0 ? 0 : top - amount;
		if(to < $$DF.scroll.limit) {to = 0;}
		r.inAnim = true;
		SOF.scroller.objectUp(to, id);
		var scroll = parseInt(r.span.style.top) - Math.ceil(r.dispo * (top - to) / r.full);
		if((scroll < 0) || (to == 0 && scroll != 0)) {scroll = 0;}
		r.inAnim1 = true;
		SOF.scroller.barUp(scroll, id);
		r = null; // nettoyage
	},
	objectDown: function(to, id) {
		var top = Math.abs(parseInt($$DF.fields[id].scroll.target.style.marginTop));
		if(top >= to) {
			$$DF.fields[id].scroll.target.style.marginTop = - to + 'px';
			clearTimeout($$DF.fields[id].scroll.timer);
			$$DF.fields[id].scroll.timer = null;
			$$DF.fields[id].scroll.inAnim = false;
		} else {
			$$DF.fields[id].scroll.target.style.marginTop = - (top + Math.ceil((to - top) / $$DF.scroll.animSlow)) + 'px';
			$$DF.fields[id].scroll.timer = setTimeout(function() {SOF.scroller.objectDown(to, id)}, $$DF.scroll.animDelay);
		}
	},
	objectUp: function(to, id) {
		var top = Math.abs(parseInt($$DF.fields[id].scroll.target.style.marginTop));
		if(top <= to) {
			$$DF.fields[id].scroll.target.style.marginTop = - to + 'px';
			clearTimeout($$DF.fields[id].scroll.timer);
			$$DF.fields[id].scroll.timer = null;
			$$DF.fields[id].scroll.inAnim = false;
		} else {
			$$DF.fields[id].scroll.target.style.marginTop = - (top + Math.floor((to - top) / $$DF.scroll.animSlow)) + 'px';
			$$DF.fields[id].scroll.timer = setTimeout(function() {SOF.scroller.objectUp(to, id)}, $$DF.scroll.animDelay);
		}
	},
	barDown: function(to, id) {
		var top = Math.abs(parseInt($$DF.fields[id].scroll.span.style.top));
		if(top >= to) {
			$$DF.fields[id].scroll.span.style.top = to + 'px';
			clearTimeout($$DF.fields[id].scroll.timer1);
			$$DF.fields[id].scroll.timer1 = null;
			$$DF.fields[id].scroll.inAnim1 = false;
		} else {
			$$DF.fields[id].scroll.span.style.top = top + Math.ceil((to - top) / $$DF.scroll.animSlow) + 'px';
			$$DF.fields[id].scroll.timer1 = setTimeout(function() {SOF.scroller.barDown(to, id)}, $$DF.scroll.animDelay);
		}
	},
	barUp: function(to, id) {
		var top = Math.abs(parseInt($$DF.fields[id].scroll.span.style.top));
		if(top <= to) {
			$$DF.fields[id].scroll.span.style.top = to + 'px';
			clearTimeout($$DF.fields[id].scroll.timer1);
			$$DF.fields[id].scroll.timer1 = null;
			$$DF.fields[id].scroll.inAnim1 = false;
		} else {
			$$DF.fields[id].scroll.span.style.top = top + Math.floor((to - top) / $$DF.scroll.animSlow) + 'px';
			$$DF.fields[id].scroll.timer1 = setTimeout(function() {SOF.scroller.barUp(to, id)}, $$DF.scroll.animDelay);
		}
	},
	toggle: function(id) {
		if(!id) {
			if($$DF.lastScroll) {
				$$DF.lastScroll.style.left = '-10000px';
				$$DF.lastScroll = null;
			}
		} else {
			if($$DF.fields[id].scroll.main.style.left == '-10000px') {
				$$DF.fields[id].scroll.main.style.left = $$DF.fields[id].scroll.left + 'px';
				if($$DF.lastScroll) {SOF.scroller.toggle();}
				$$DF.lastScroll = $$DF.fields[id].scroll.main;
			} else {
				$$DF.fields[id].scroll.main.style.left = '-10000px';
				$$DF.lastScroll = null;
			}
		}
	}
};


// fermeture des listes et du calendrier sur un clic externe
Box.events.add(document, 'click', function(e) {
	var t = e.target || e.srcElement, verif = false;
	while(t != document.documentElement) {
		if(Box.nodes.hasClass(t, 'open-calendar') || Box.nodes.hasClass(t, 'close-calendar')) {return;}
		if(Box.nodes.attribute(t, 'id') == 'calendar' || Box.nodes.hasClass(t, 'js-select')) {verif = true; break;}
		t = t.parentNode;
	}
	if(verif) {return;}
	if($$DF.lastSelect && $$DF.lastImg) {
		Box.nodes.addClass($$DF.lastSelect, 'hidden');
		if($$DF.lastScroll) {SOF.scroller.toggle();}
		$$DF.lastImg.alt = SOF[$$L].alt.openSelect;
	}
	if($$DF.lastField) {
		Box.nodes.removeClass($$DF.lastField, 'active');
		$$DF.lastField = null;
	}
	t = null; // nettoyage
});


// chargement des fonctions
Box.events.load(SOF.niceforms.init);

// déchargement (nettoyage variables)
Box.events.add(window, 'unload', function() {
	$$DF = null;
	SOF.datasDatesForms = null;
});



