var clog = function(str) {
	if(window.console) console.log(str);	
}

Element.implement({
	duplicate: function(){
		elClone = this.clone();
		elClone.inject(this, 'before');
		return elClone;
	},
	clearInputChilds: function() {
		els = this.getElements('INPUT');
		els.each(function(el) {
			el.set('value','');
		});
		return this;
	},
	clearSelectChilds: function() {
		els = this.getElements('SELECT');
		els.each(function(el) {
			el.selectedIndex = 0;
		});
		return this;
	},
	centerHPosition: function(el) {
		if(!el) {
			el = window;			
		} else {
			el = $('el');
		}		
		x = window.getSize().x - this.getSize().x;
		x = Math.floor(x / 2);
		this.setStyle('left', x + 'px');
	}
});

Hash.implement({ 
	sort:function(fn){ 
	        var out = {}, 
	                keysToSort = this.getKeys(), 
	                m = this.getLength(); 
	        (typeof fn == 'function') ? keysToSort.sort(fn) : keysToSort.sort(); 
	        for (var i=0; i<m; i++){ 
	                out[keysToSort[i]] = this[keysToSort[i]]; 
	        } 
	        return $H(out); 

	} 
});

// Menu Class

var Menu = new Class({
    initialize: function(el){
        this._el = el;
        this._nodes = [];
        
        var els = this._el.getChildren('li');
        els.each(function(item, index){
        	var node = new MenuNode(item, null);
        	this._nodes.push(node);
        }, this);
    }
});

// MenuNode Class

var MenuNode = new Class({
    initialize: function(el, parentNode){
	 	this._el = el;
	 	this._parentNode = parentNode;
	 	this._nodes = [];	 	
	 	
	 	this._link = el.getChildren("a");	 	
	 	this._leaves = el.getChildren("ul");
	 		 	
	 	if(this._leaves.length > 0) {
	 		this._leaves = this._leaves[0];
	 		this._link.addEvent('click', this._onLinkClick.bind(this));	
	 		this._initChilds();
	 	} else {
	 		this._leaves = null;
	 	}
	 	
	 	if(this._el.hasClass("open")) {
	 		this.openParents();
	 	}
	},
	toggle: function() {
		if(this._leaves == null) return;
		
		if(this._leaves.hasClass('menuleavesopen')) {
			this.close();
		} else {
			this.open();
		}			
	},
	open: function() {
		if(this._leaves == null) return;
		this._leaves.addClass('menuleavesopen');
		this._link.addClass('open');
	},
	close: function() {
		if(this._leaves == null) return;
		this._leaves.removeClass('menuleavesopen');
		this._link.removeClass('open');
	},
	openParents: function() {
		this.open();
		if(this._parentNode != null) {
			this._parentNode.openParents();	
		}
	},
	_initChilds: function() {
		var els = this._leaves.getChildren('li');
        els.each(function(item, index){
        	var node = new MenuNode(item, this);
        	this._nodes.push(node);
        }, this);
	},
	_onLinkClick: function() {
		this.toggle();
	}
});

// MenuH Class

var MenuH = new Class({
    initialize: function(el){
        this._el = el;
        this._nodes = [];
        this._
        
        var els = this._el.getChildren('li');
        els.each(function(item, index){
        	var node = new MenuHNode(item, null, this);
        	this._nodes.push(node);
        }, this);
    }
});

//MenuHNode Class

var MenuHNode = new Class({
    initialize: function(el, parentNode, parentMenu){
	 	this._el = el;
	 	this._parentNode = parentNode;
	 	this._parentMenu = parentMenu;
	 	this._nodes = [];	 	
	 	
	 	this._link = el.getChildren("a");	

	 	this._leaves = el.getChildren("ul");
	 		 	
	 	if(this._leaves.length > 0) {
	 		this._leaves = this._leaves[0];
	 		this._el.addEvent('mouseenter', this._onElEnter.bind(this));	
	 		this._el.addEvent('mouseleave', this._onElLeave.bind(this));	
	 		this._initChilds();
	 	} else {
	 		this._leaves = null;
	 	}
	},
	_initChilds: function() {
		var els = this._leaves.getChildren('li');
        els.each(function(item, index){
        	var node = new MenuHNode(item, this, this._parentMenu);
        	this._nodes.push(node);
        }, this);
	},
	_onElEnter: function() {
		this.open();
	},
	_onElLeave: function() {
		this.close();
	},
	open: function() {
		if(this._leaves == null) return;
		this._leaves.addClass('menuleavesopen');
	},
	close: function() {
		if(this._leaves == null) return;
		this._leaves.removeClass('menuleavesopen');		
	}
});

// Static Init

var Site = new Class();
Site.menus = [];
Site.uri = new URI();
Site.navTo = function(url, field, target) {
	if(field) {
		url += $(field).value;
	}
	if(target) {
		frame = $(target);
		a = 0;
		while ((a < window.parent.frames.length) && (!frame)){
			tframe = window.parent.frames[a];			
			if(tframe.name == target) {
				frame = tframe;
			}
			a++;
		}
		if(frame) {
			if(frame.location) { // Frame
				frame.location.href = url;
			} else { // iFrame
				frame.src = url;
			}
			
		}
	} else {		
		window.location.href = url;
	}
}

Site.submitTo = function(formid, url) {
	form = $(formid);
	form.set('action', url);
	form.submit();
}

Site.submitValid = function(formid) {
	if(!$(formid).validateur) {
		$(formid).validateur = new FormCheck(formid);
	}
	if($(formid).validateur.validate())
		$(formid).submit();	
}

Site.popup = function(url, width, height) {
	rnd = Math.random()*100000000;
	rnd = Math.round(rnd);
	opened = window.open(url,'popup' + rnd,'toolbar=0,status=0,width=' + width + ',height=' + height);
	if(!opened) window.location = url;
}

Site.sortData = new Hash();

Site.pushSortData = function(id, data) {	
	Site.sortData.set(id, data);
	btn = $('saveorderbtn');
	style = 'inline-block';
	if(Browser.Engine.trident) {
		style = 'inline';
	}
	if(btn && btn.getStyle('display') != style) {
		btn.setStyle('display', style);
		btn.morph({
			'opacity':[0,1]
		});
	}
}

Site.saveSortData = function(posturl, navurl) {
	var jSonRequest = new Request.JSON({url: posturl});
	jSonRequest.post({'data' : JSON.encode(Site.sortData)});
	
	var myFx = new Fx.Morph($('saveorderbtn'), {
		onComplete: function(){
			$('saveorderbtn').setStyle('display', 'none');
			if(navurl) Site.navTo(navurl);
		}
	});
	Site.sortData = new Hash();
	myFx.start({'opacity':[1,0]});
}

// Validateur de formulaires
Form.Validator.add('equalField', {
	errorMsg: function(element, props){
	    if ($type(props.equalField))
	        return 'Les saisies ne sont pas identiques.';
	    else return '';
	},
	test: function(element, props){
		return element.value == $(props.equalField).value;
	}
});

Form.Validator.add('validate-one-required-torop', {
	errorMsg: Form.Validator.getMsg.pass('oneRequired'),
	test: function(element, props){
		var p = document.id(props['validate-one-required']) || element.getParent('.group-required');
		return p.getElements('input').some(function(el){
			if (['checkbox', 'radio'].contains(el.get('type'))) return el.get('checked');
			return el.get('value');
		});
	}
});

var FormCheck = new Class({
    initialize: function(formEl, errorEl){
    	formEl = $(formEl);
    	if(errorEl) {
        	this._errorEl = $(errorEl);
    	} else {
    		this._errorEl = formEl.getElement('.erreurs');
    	}
        
        var options = {
    			evaluateFieldsOnBlur: false,
    			evaluateFieldsOnChange: false,
    			useTitles: true,
    			onElementFail: this._onElementFail.bind(this)    			
    	}
        
        this._validator = new Form.Validator(formEl, options);
    },
	validate: function() {
		this._reset();
    	res = this._validator.validate();
    	if(res) {
    		this._reset();
    	} else {
    		this._scroll();
    	}
    	return res;
    },
    _onElementFail: function(el, errors) {
    	if(!this._errorEl)
    		return;
		this._errorEl.setStyle('display', 'block');
		this._currentEl = el;
    	errors.each(function(item, index){
    		var validator = this._validator.getValidator(item);    		
    		var error = '<strong>' + this._currentEl.get('title') + '</strong> : ' + validator.getError(this._currentEl);
    		new Element('li').set('html',error).injectInside( this._errorEl);
        }, this);
    },
	_reset: function() {
		if(!this._errorEl)
    		return;
		this._errorEl.setStyle('display', 'none');		
		this._errorEl.getChildren().each(function(item, index) {
			item.dispose();
		});
	},
	_scroll: function() {
		if(!this._errorEl)
    		return;
		dest = this._errorEl.getCoordinates().top-30;
		new Fx.Scroll(window, {}).start(0,dest);
	}
});

Form.Validator.addAllThese(
[
	['validate-minutes', {
			errorMsg: 'Minutes invalides',
				test: function(element){
						if (Form.Validator.getValidator('IsEmpty').test(element)) return true;
						return Form.Validator.getValidator('IsEmpty').test(element) || (/^([0-5]\d)$/).test(element.get('value'));
					}
				}],
	['validate-hours', {
		errorMsg: 'Heures invalides',
			test: function(element){
					if (Form.Validator.getValidator('IsEmpty').test(element)) return true;
					return Form.Validator.getValidator('IsEmpty').test(element) || (/^(\d|1\d|2[0-3])$/).test(element.get('value'));
				}
			}],
	['validate-required-check', {
				errorMsg: function(element, props){
					if(props.errorMsg)return props.errorMsg;
					return props.useTitle ? element.get('title') : Form.Validator.getMsg('requiredChk');
				},
				test: function(element, props){
					return !!element.checked;
				}
			}],
	['validate-numeric', {
		errorMsg: Form.Validator.getMsg.pass('numeric'),
		test: function(element){
			return Form.Validator.getValidator('IsEmpty').test(element) ||
				(/^-?(?:0$0(?=\d*\.)|[1-9]|0)\d*((\.|\,)\d+)?$/).test(element.get('value'));
		}
	}],
	['minValue', {
		errorMsg: function(element, props){
			if ($type(props.minValue))
				return 'La valeur doit être supérieure à ' + props.minValue;
			else return '';
		},
		test: function(element, props){
			return Form.Validator.getValidator('IsEmpty').test(element) ||
				(element.get('value').toFloat() >= props.minValue);
		}
	}],
	['maxValue', {
		errorMsg: function(element, props){
			if ($type(props.maxValue))
				return 'La valeur doit être inférieure à ' + props.maxValue;
			else return '';
		},
		test: function(element, props){
			return Form.Validator.getValidator('IsEmpty').test(element) ||
				(element.get('value').toFloat() <= props.maxValue);
		}
	}]
]);

var FieldEan = new Class({
    initialize: function(el){
		if(!el) return;
        this._el = el;
        this._el.addEvent('keyup', this._onKeyUp.bind(this));
    },
    _onKeyUp: function(event) {
    	value = this._el.get('value');
    	value = value.replace('&', '1');
    	value = value.replace('é', '2');
    	value = value.replace('"', '3');
    	value = value.replace('\'', '4');
    	value = value.replace('(', '5');
    	value = value.replace('-', '6');
    	value = value.replace('è', '7');
    	value = value.replace('_', '8');
    	value = value.replace('ç', '9');
    	value = value.replace('à', '0');
    	value = value.toUpperCase();
   		this._el.set('value', value);
    }
});

var FieldOff = new Class({
    initialize: function(el){
		if(!el) return;
        this._el = el;
        this._cbClick = this._onClick.bind(this);
        this._el.addEvent('focus', this._cbClick);
    },
    _onClick: function() {    	
    	if(!this._el.hasClass('field_off')) return;
    	this._el.set('value','');
    	this._el.removeClass('field_off');
    	this._el.removeEvent('focus', this._cbClick);
    	elclone = this._el.clone(false, true);
    	
    	if(this._el.hasClass('field_password')) {
    		elclone.set('type','password');
    	}
    	elclone.replaces(this._el);
    	this._el = elclone;
    	this._focus.delay(100, this);
    },
    _focus: function() {
    	this._el.focus();
    }
});

var TabControl = new Class({
    initialize: function(onglets, panels){
		this._onglets = onglets;
		this._panels = panels;
		this._tabs = [];
		this._currentPanel = null;
		
		this._onglets.each(function(item, index){
			this._addTab(item, index);
        }, this);
    },
    _addTab: function(onglet, index) {
    	panel = this._panels[index];
    	onglet.addEvent('click', this._onClick.bind(this, index));
    	if(index == 0) {
    		this._currentPanel = panel;
    	} else {
    		panel.setStyle('display', 'none');
    	}
    },
    _onClick: function(index) {    	
    	if(!this._panels[index])return;
    	panel = this._panels[index];
    	this._currentPanel.setStyle('display', 'none');
    	panel.setStyle('display', 'block');
    	this._currentPanel = panel;
    }
});

var SelectNav = new Class({
    initialize: function(el){
		if(!el) return;
        this._el = el;
        this._cbClick = this._onClick.bind(this);
        this._el.addEvent('change', this._cbClick);	
    },
    _onClick: function() {
    	Site.navTo(this._el.get('value'));
    }
});

var SelectAllOnClick = new Class({
    initialize: function(el){
		if(!el) return;
        this._el = el;
        this._cbClick = this._onClick.bind(this);
        this._el.addEvent('click', this._cbClick);	
    },
    _onClick: function() {
    	this._el.select();
    }
});

var CheckGroup = new Class({
	initialize: function(el){
		if(!el) return;
        this._el = el;        
        this._els = $$("INPUT[name='" + el.value + "']");
        this._cbClick = this._onClick.bind(this);
        this._el.addEvent('click', this._cbClick);
        this._onClick();
    },
    _onClick: function() {
    	this._els.each(function(item, index){
    		item.checked = this._el.checked;        	
        }, this);
    }
});

var CountDown = new Class({
	initialize: function(el){
		if(!el) return;
        this._el = el;
        this._el.setStyle('visibility', 'visible');
        this._ts = $time();
        this._interval = el.get('text');
        if(this._el.hasClass('cdfulltext')) {
        	this._timerFullText();
            this._timerFullText.periodical(1000, this);
        } else {
        	this._timerShortText();
            this._timerShortText.periodical(1000, this);
        }        
    },
    _timerFullText: function() {
    	diff = this._interval - Math.round(($time() - this._ts) / 1000);
    	if(diff < 0) {
    		this._el.set('text', 'Terminé');
    	}
    	str = "";
    	jours = Math.floor(diff / 86400);
    	if(jours > 0) {
    		str += jours;
    		if(jours > 1) {
    			str += "jours ";
    		} else {
    			str += "jour ";
    		}
    		diff -= jours * 86400;
    	}
    	heures = Math.floor(diff / 3600);
    	if(heures > 0) {
    		str += heures;
    		if(heures > 1) {
    			str += "heures ";
    		} else {
    			str += "heure ";
    		}
    		diff -= heures * 3600;
    	}
    	minutes = Math.floor(diff / 60);
    	if(minutes > 0) {
    		str += minutes;
    		if(minutes > 1) {
    			str += "minutes ";
    		} else {
    			str += "minute ";
    		}
    		diff -= minutes * 60;
    	}
    	if(diff > 0) {
    		str += diff;
    		if(minutes > 1) {
    			str += "secondes ";
    		} else {
    			str += "seconde ";
    		}
    	}
    	this._el.set('text', str);
    },
    _timerShortText: function() {
    	diff = this._interval - Math.round(($time() - this._ts) / 1000);
    	if(diff < 0) {
    		this._el.set('text', 'Terminé');
    	}
    	str = "";
    	jours = Math.floor(diff / 86400);
    	if(jours > 0) {
    		str += jours + "j ";
    		diff -= jours * 86400;
    	}
    	heures = Math.floor(diff / 3600);
    	if(heures > 0) {
    		str += heures + "h ";
    		diff -= heures * 3600;
    	}
    	minutes = Math.floor(diff / 60);
    	if(minutes > 0) {
    		str += minutes + "m ";
    		diff -= minutes * 60;
    	}
    	if(diff > 0) {
    		str += diff + "s ";
    	}
    	this._el.set('text', str);
    }
});

var FormItemList = new Class({
	_values: new Hash(),
	_options: new Hash(),
	_name: '',
	_uiUpdateEnabled: false,
	_added: null,	
	initialize: function(el){
		if(!el) return;
        this._el = el;
        this._name = el.get('title');
        this.elAddZone = this._el.getElement('.jsformitemlist_addzone');
        this.elList = this._el.getElement('.jsformitemlist_items');
        this.elSelect = this.elAddZone.getElement('SELECT');

        this._initData();

        this.elSelect.addEvent('click', this._onSelectClick.bind(this));
    },
    _initData: function() {
    	elData = this._el.getElements('.jsformitemlist_data');
    	json = elData.get('text').toString();
    	obj = JSON.decode(json);
    	elData.destroy();
    	this._options = new Hash(obj.options);
    	
    	obj.values.each(function(value){
    		this.addValue(value);
        }, this);
    	
    	this._uiUpdateEnabled = true;
    	this._uiUpdate();
    },
    _onItemClick: function(event, item) {
    	value = item.getElement('INPUT').get('value');
    	this.removeValue(value); 
    },
    _onSelectClick: function() {    	
    	i = this.elSelect.selectedIndex;
    	if(i == 0)return;
    	
    	opt = this.elSelect.options[i];
    	if(opt) this.addValue(opt.value);
    },
    _uiUpdate: function() {
    	if(!this._uiUpdateEnabled)return;    	
    	this.elSelect.selectedIndex = 0;
    	
    	this._options = this._options.sort();
    	this._values = this._values.sort();
    	
    	for(i = this.elSelect.options.length;i>0;i--) {    
    		this.elSelect.remove(i);
    	}
    	
    	this._options.each(function(value, key){
    		var opt = new Element('OPTION', {
        	    'value': key
        	});
        	opt.set('text', value);
        	this.elSelect.adopt(opt);
        }, this);
    	
    	this.elList.empty();
    	
    	this._values.each(function(value, key){
    		li = this._createLi(key, value);
    		this.elList.addEvent('click', this._onSelectClick.bind(this));
    		this.elList.adopt(li);
    		if(this._added == key) {    			
    			li.fade('hide');
    			li.fade('in');
    			this._added = null;
    		}
        }, this);
    },
    _createLi: function(value, label) {
    	li = new Element('LI');
    	li.addEvent('click', this._onItemClick.bindWithEvent(this, li));
    	input = new Element('INPUT', {
    		'type': 'hidden',
    		'name': this._name + '[]',
    		'value': value
    	});
    	a = new Element('A', {
    		'href': 'javascript:void(0)',
    		'class': 'ico16 ico16_close',
    		'text': label
    	});
    	return li.adopt(input).adopt(a);
    },
    addValue: function(value) {
		label = this._options.get(value);		
		if(label) {
			this._values.set(value, label);
			this._options.erase(value);
		}
		this._added = value;
		this._uiUpdate();
    },
    removeValue: function(value) {    	
    	label = this._values.get(value);
		if(label) {
			this._options.set(value, label);
			this._values.erase(value);
		}
		this._uiUpdate();
    }
});

var DisablePaste = new Class({
	initialize: function(el){
		if(!el) return;
        this._el = $(el);        
        this._el.addEvent('contextmenu', this._onContext.bind(this));
        this._el.addEvent('keydown', this._onKeydown.bind(this));
    },
    _onContext: function(e) {    	
    	e.stop();
    },
    _onKeydown: function(e) {
    	if(e.control && !e.alt) e.stop();
    }
});

var OverPanel = new Class({
    initialize: function(sensorEl){
		if(!sensorEl) return;
        this._sensorEl = sensorEl;
        this._el = $(sensorEl.get('rel'));
        if(!this._el) return;
        
        this._sensorEl.addEvent('mouseenter', this._onEnter.bind(this));
        this._sensorEl.addEvent('mouseleave', this._onLeave.bind(this));
        
        this._el.addEvent('mouseenter', this._onEnter.bind(this));
        this._el.addEvent('mouseleave', this._onLeave.bind(this));
        this._el.inject(document.body);
        
        this._hideTimer = null;
        
        this._tween = new Fx.Tween(this._el);
        this._tween.set('opacity', 0);
        this._el.setStyle('display', 'block');
        
        options = {
 				relativeTo: this._sensorEl,        				
	 				position: 'bottomLeft'
 				}
    	this._el.position(options);
        
    },
    _onEnter: function() {
    	$clear(this._hideTimer);
    	this._tween.cancel();
    	this._el.setStyle('z-index', OverPanel.zindex++);    
    	this._tween.set('opacity', 1);
    },
    _onLeave: function() {    	
    	this._hideTimer = this._hide.delay(300, this);
    },
    _hide: function() {
    	this._tween.start('opacity', 0);
    }
});

OverPanel.zindex = 100;

var AjaxPanel = new Class({
	_options: new Hash(),
    initialize: function(el){
		if(!el) return;
        this._el = el;
        this._el.setStyle('visibility', 'visible');
        
        json = this._el.get('text').toString();
    	obj = JSON.decode(json);
    	this._options = new Hash(obj);
    	loadingstr = 'Chargement...';
    	if(this._options.get('title')) {
    		loadingstr = this._options.get('title');
    	}
    	
    	this._el.set('text', loadingstr);
    	this.load();
    },
    load: function() {
    	var req = new Request.HTML({update:this._el});
    	req.get(this._options.get('src'));
    }
});


var AjaxProxy  = new Class({
	initialize: function(){	},
	get: function(url, confirmMsg) {
		if(!this._doConfirm(confirmMsg))return;		
		var request = this._getRequest(url);
		request.get({__context:'json'});
		
	},
	_doConfirm: function(confirmMsg) {
		if(!confirmMsg)return true;
		return confirm(confirmMsg);
	},
	_getRequest: function(url) {
		return new Request.JSON({url: url, onSuccess: this._onSuccessRequest.bind(this)});
	},
	_onSuccessRequest: function(data) {
		alert(JSON.encode(data));
	}
});

var ajax = new AjaxProxy();

var toggleTree = function(lnk) {
	el = lnk.getParent();
	if(!el)return;
	el = el.getParent();
	if(!el)return;
	el = el.getElement('ul');
	
	if(el.getStyle('display') == 'none') {
		el.setStyle('display', 'block');
		lnk.removeClass('ico22_plus');
		lnk.addClass('ico22_minus');
	} else {
		el.setStyle('display', 'none');
		lnk.addClass('ico22_plus');
		lnk.removeClass('ico22_minus');
	}
}

//** INIT **//
MooTools.lang.setLanguage("fr-FR");

var init_jsdatepicker = function() {
	var els = $$('.jsdatepicker');
   	els.each(function(item, index){
   		if(!item.datepicker) {
	   		toggler = item.getElement('.datepicker');
	   		input = item.getElement('.datepickerinput');
	   		options = {
	   				'toggler' : toggler,
	   				'prefill' : false, 
	   				'startMonday' : true,
	   				'format' : 	'%x',
	   				'disallowUserInput' : true
	   		};
	   		item.datepicker = new CalendarEightysix(input, options);
   		}
    }); 
}

window.addEvent('domready', function() {
    var els = $$('.menuroot');
    els.each(function(item, index){
    	var menu = new Menu(item);
    	Site.menus.push(menu);
    });
    
    var els = $$('.menuhroot');
    els.each(function(item, index){
    	var menu = new MenuH(item);
    	Site.menus.push(menu);
    });
    
   	var myTips = new Tips($$('.toolTip'), {
   		timeOut: 700,
   		maxTitleChars: 50,
   		maxOpacity: 0.7
   	});	
   	
   	var els = $$('.field_off');
   	els.each(function(item, index){
    	var field = new FieldOff(item);
    });
   	
   	var els = $$('.field_ean');
   	els.each(function(item, index){
    	var field = new FieldEan(item);
    });
   	
   	var els = $$('.selectallonclick');
   	els.each(function(item, index){
    	var field = new SelectAllOnClick(item);
    });
   	
   	var els = $$('.jscaroussel');
   	els.each(function(item, index){
   		var slides = item.getElements('.slide');
   		var buttons = item.getElements('.button');
   		if(slides.length > 1) {
	   		new SimpleCarousel(item, slides, buttons, {
	   	   		slideInterval: 3000,
	   	   		rotateAction: 'click'
	   	   	});
   		} else {
   			var buttons = item.getElement('.buttons');
   			buttons.setStyle('display', 'none');
   		}
    });
   	
   	var els = $$('.overpanel_sensor');
   	els.each(function(item, index){
    	var overpanel = new OverPanel(item);
    });
   	
   	var els = $$('.checkgroup');
   	els.each(function(item, index){
    	var checkgroup = new CheckGroup(item);
    }); 
   	
   	var els = $$('.jscountdown');
   	els.each(function(item, index){
    	var cd = new CountDown(item);
    });   	
   	
   	init_jsdatepicker(); 

   	var els = $$('.jsformitemlist');
    els.each(function(item, index){
    	var cd = new FormItemList(item);
    });
    
    var els = $$('.jsdisablepaste');
    els.each(function(item, index){
    	var cd = new DisablePaste(item);
    }); 
    
    var els = $$('.jsselectnav');
    els.each(function(item, index){
    	var cd = new SelectNav(item);
    });
    
    var els = $$('.jsajaxpanel');
    els.each(function(item, index){
    	var cd = new AjaxPanel(item);
    });  
});


