/* This is a duplicate file from index.js but we simply translate labels*/
/* 
	Son: Please make sure to update to the latest version (where is the latest
	version? to be defined)													  
*/

String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); };
var DA = DOMAssistant;
var TDM = {
	Config: {
		Init: {
			Postal_Code_Pattern: /^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}[0-9]{1}$/,
			Email_Pattern: /^[a-zA-Z\'0-9]+([._\-][a-zA-Z\'0-9]+)*@([a-zA-Z0-9]+([._\-][a-zA-Z0-9]+))+$/,
			CurrentTab: 0,
			CurrentView: {},
			TypographyWeights: ['weight_1', 'weight_2', '', 'weight_4', 'weight_5'],
			TypographyCurrentSize: 2
		},
		Selectors: {
			Opened: "opened",
			Closed: "closed",
			CloseText: "Fermer X",
			CloseTitle: "Fermer la fen\u00EAtre",
			Selected: "selected",
			Current: "current",
			Hover: "hover",
			FirstChild: "child_1",
			DropDownMenu: "interaction_dd_menu",
			FontResize: "action_font-resize",
			FontSizeDecrease: "font-size_decrease",
			FontSizeIncrease: "font-size_increase",
			FontSizeDecreaseText: "R\u00E9duire la taille",
			FontSizeIncreaseText: "Augmenter la taille",
			RequiredField: "required_field",
			ValidateRequiredFields: "validate_required_fields",
			UserRatingSystem: "user_rating_system",
			ScriptBasedSubmit: "script_based_submit",
			ScriptBasedClose: "script_based_close",
			AverageUserRating: "average_user_rating",
			RatingSystem: "rating_system",
			OpenResourceOnNewWindow: "open_resource_on_new_window",
			Warning: "warning",
			Error: "error",
			ErrorMessage: "error_message",
			ErrorMessageGlobal: "Please fill out all the (<span class=\"required\">*</span>) required fields.",
			IsSet: "isset",
			IsSelected: "isselected",
			IsChecked: "ischecked",
			PatternEmail: "patternemail",
			PatternEmailMultiple: "patternemailmultiple",
			IdenticalEmail: "identicalemail",
			IdenticalPassword: "identicalpassword",
			Validate: "validate",
			EmailAddress: "E-mail address",
			Previous: "prev",
			Next: "next",
			IAdvisory: "i_advisory",
			InfoAdvisory: "info_advisory",
			Bookmark: "action_bookmark",
			BookmarkText: ["Ajouter aux favoris", "Bookmark Page", "Add Bookmark"],
			BookmarkTextUA: {
				Opera: "Press CTRL-D to bookmark this page",
				WebKit: "Press Command/Cmd + D to bookmark this page"
			},
			Controls: "controls",
			ContentBrowser: "content_browser",
			ContentViewActions: "content_view_actions"
		},
		Messages: {	}
	},

	Utils: {
		Tabbing: function (datas, actions, init_view) {
			var is_init_set = false;
			for (var j=0; j<datas.length; j++) {
				if (j === init_view || "#"+datas[j].id === init_view) {
					TDM.Config.Init.CurrentTab = j;

					TDM.Utils.Open(DA.$(datas[j]));
					DA.$(actions[j]).addClass(TDM.Config.Selectors.Selected);
					if ("#"+datas[j].id === init_view) {
						location.hash = DA.$(actions[j]).parentNode.parentNode.id;
					}
					is_init_set = true;
				}
				else {
					TDM.Utils.Close(DA.$(datas[j]));
				}
			}

			if (!is_init_set) {
				TDM.Config.Init.CurrentTab = 0;
				TDM.Utils.ShowObject(datas, actions, TDM.Config.Init.CurrentTab);
			}

			for (var i=0; i<actions.length; i++) {
				DA.$(actions[i]).addEvent("click", function (i) {
					return function (e) {
		        		TDM.Utils.ShowObject(datas, actions, i);
		        		if ( DOMAssistant.preventDefault(e)) { DOMAssistant.preventDefault(e); }
		        	};
				}(i));
			}
		},

		ShowObject: function (datas, actions, change_id) {
			TDM.Utils.Close(datas[TDM.Config.Init.CurrentTab]);
			DA.$(actions[TDM.Config.Init.CurrentTab]).removeClass(TDM.Config.Selectors.Selected);
			TDM.Config.Init.CurrentTab = change_id;
			TDM.Utils.Open(datas[TDM.Config.Init.CurrentTab]);
			DA.$(actions[TDM.Config.Init.CurrentTab]).addClass(TDM.Config.Selectors.Selected);

			///////////////////////////////////////////////////////////////////////////
			// BEGIN: ELLE 
			
			var selectedId = DA.$(datas[TDM.Config.Init.CurrentTab]).id;
			DA.$(actions[TDM.Config.Init.CurrentTab]).parentNode.className = "";
			DA.$(DA.$(actions[TDM.Config.Init.CurrentTab]).parentNode).addClass("actions");
			DA.$(DA.$(actions[TDM.Config.Init.CurrentTab]).parentNode).addClass(selectedId);

			// END: ELLE			
			///////////////////////////////////////////////////////////////////////////
		},

		ShowHide: function ($datas, $actions, return_switch) {
			var counter = 0;
			$actions.each(function (){
				DA.$(this).addEvent("click", function (i) {
					return function (e) {
						if ($datas[i].hasClass(TDM.Config.Selectors.Opened)) {
							TDM.Utils.Close($datas[i]);
						}
						else {
							TDM.Utils.Open($datas[i]);
						}

						if (return_switch === false) {
							if ( DOMAssistant.preventDefault(e)) { DOMAssistant.preventDefault(e); }
						}
					};
				}(counter));
				counter++;
			});
		},

		Close: function (obj) {
			obj.removeClass(TDM.Config.Selectors.Opened);
			obj.addClass(TDM.Config.Selectors.Closed);
		},

		Open: function (obj) {
			obj.removeClass(TDM.Config.Selectors.Closed);
			obj.addClass(TDM.Config.Selectors.Opened);
		},

		OpenResourceOnNewWindow: function () {
			var els = DA.$('.'+TDM.Config.Selectors.OpenResourceOnNewWindow);

			if (els.length > 0) {
				for (var i=0; i < els.length; i++) {
					var el = els[i];

					DA.$(el).addEvent('click', function (_this) {
						return function (e){
							if (_this.href !== undefined) {
								window.open(_this.href);
								_this.href = "#";
								return false;
							}
						};
					}(el));

					DA.$(el).addEvent('keypress', function (_this) {
						return function (e){
							if (_this.href !== undefined) {
								window.open(_this.href);
								_this.href = "#";
								return false;
							}
						};
					}(el));
				}
			}
		},

		RatingSystem: function (form, rating_width) { //extend this method to do all selects
			var ul = document.createElement("ul");
			var p = document.createElement("p");
			DA.$(ul).addClass(TDM.Config.Selectors.RatingSystem);

			var select = DA.$('#'+form+' .'+TDM.Config.Selectors.UserRatingSystem+' select')[0];
			var options = DA.$(select).elmsByTag('option');
			var selected_option = '';

			var current_selection = document.createElement("li");
			DA.$(current_selection).addClass(TDM.Config.Selectors.Current);
			var current_selection_textCDATA = document.createTextNode("Current Selection");
			current_selection.appendChild(current_selection_textCDATA);
			ul.appendChild(current_selection);

			var node = '';
			for (var j=0; j<options.length; j++) {
				node = options[j];
				if (node.nodeName.toLowerCase() === "option") {
					var li = document.createElement("li");
					var textCDATA = document.createTextNode(node.text);

					///////// BEGIN: ELLE /////////////////
					var a = document.createElement("a");
					a.href = "#";
					DA.$(a).addClass(node.id);
					a.title = node.title;
					///////// END: ELLE /////////////////

					DA.$(a).addEvent('click', function (selectElement, optionIndex, selectedOption, currentSelection) {
						return function () {
							selectElement.selectedIndex = -1;
							selectElement.selectedIndex = optionIndex;
							currentSelection.style.width = rating_width*(optionIndex+1) + 'px';

							var script_based_submit = DA.$('#'+form+'.'+TDM.Config.Selectors.ScriptBasedSubmit);

							if (script_based_submit.length > 0) {
								script_based_submit[0].submit();
							}
							else {
								return false;
							}
						};
					}(select, j, selected_option, current_selection));

					a.appendChild(textCDATA);
					li.appendChild(a);
					ul.appendChild(li);
				}
			}
			ul.id = select.id;

			DA.$(select).parentNode.insertBefore(ul, select.nextSibling);

			if (DA.$('.'+TDM.Config.Selectors.AverageUserRating).length > 0) {
				DA.$('#'+form+' .'+TDM.Config.Selectors.RatingSystem+' .'+TDM.Config.Selectors.Current)[0].style.width = DA.$('.'+TDM.Config.Selectors.AverageUserRating)[0].value * rating_width + "px";
			}
		},

		ValidateRequiredFields: function ($form_element) {
			$form_element.addClass('vrf_init');
			$form_element.addEvent('submit', function (_this) {
				return function (e) {
					var r_v = true;
					var required_fields = DA.$('#'+_this.id+' *[class*='+TDM.Config.Selectors.Validate+'_]');
					var error_message_elements = DA.$('#'+_this.id+' .'+TDM.Config.Selectors.ErrorMessage);
					if (error_message_elements) {
						error_message_elements.each(function (){
							DA.$(this).remove();
						});
					}
					required_fields.each(function () {
						DA.$(this).removeClass(TDM.Config.Selectors.Error);

						var required_field_classes = DA.$(this).className.split(" ");
						for (var c=0; c<required_field_classes.length; c++) {
							var v_re = required_field_classes[c].match(new RegExp('^'+TDM.Config.Selectors.Validate+'_([^_]+)_(.+)'));
							if (v_re) {
								var checktype = v_re[1];
								var fieldname = v_re[2];
								for (var v=0; v<TDM.Config.ValidationFunctionList.length; v++) {
									if (TDM.Config.ValidationFunctionList[v].checktype === checktype) {
										if(!TDM.Config.ValidationFunctionList[v].func(TDM.Utils.GetFormControlValue(DA.$(this)), required_field_classes[c])) {
											TDM.Utils.Set.ErrorClass(DA.$(this));
											TDM.Utils.Set.ErrorMessage(DA.$(this), checktype+'_'+fieldname, TDM.Config.ValidationFunctionList[v].error);
											r_v = false;
										}
									}
								}
							}
						}
					});
					location.hash = '#' + _this.id;

					if (!r_v) {
						TDM.Utils.Set.ErrorMessageGlobal(_this, TDM.Config.Selectors.ErrorMessageGlobal);
					}
					return r_v && true;
				};
			}($form_element));
		},

		GetFormControlValue: function (el) {
//			console.log(el.type);
		
			switch (el.nodeName.toLowerCase()) {
				case 'input':
					switch(el.type) {
						case 'text': case 'password':
//							console.log("el.value: "+el.value);
							return el.value;
							break;

						case 'radio':
							return el.checked;
							break;

						case 'checkbox':
							return el.checked;
							break;

						default:
							return 'foo';
							break;
					}
					break;

				case 'textarea':
					return el.value;
					break;
					
				case 'select':
					return el.selectIndex;
					break;

				default:
					return 'bar';
					break;
			}
		},

		ValidateField: {
			IsSet: function (str) {
				if (str.length > 0) {
					var r_v = true;
				}
				return r_v || false;
			},
			IsChecked: function (b, element_class) {
				//console.log("b: "+b);
				//console.log("element_class: "+element_class);

				elements = DA.$("form ."+element_class);

				alert(elements);
//console.log("elements: "+elements);
				elements.each(function () {
//					console.log("each element: "+$(this));
					if($(this).checked) {
						var r_v = true;
					}
				});
	
				return r_v || false;			
			},
			IsSelected: function (str) {
				if (str != "-1") {
					var r_v = true;
				}
				return r_v || false;			
			},
			Pattern: {
				Email: function (str) {
					if (TDM.Config.Init.Email_Pattern.test(str.trim())) {
						var r_v = true;
					}
					return r_v || false;
				},
				EmailMultiple: function (str) {
					multiple_emails = str.split(" ");
					var r_v = true;
					for (var y=0; y<multiple_emails.length; y++) {
						if (!TDM.Config.Init.Email_Pattern.test(multiple_emails[y])) {
							r_v = false;
						}
					}
					return r_v || false;
				},

				PostalCode: function (str) {
					if (TDM.Config.Init.Postal_Code_Pattern.test(str)) {
						var r_v = true;
					}
					return r_v || false;
				}
			},
			Identical: function (str_x, str_y) {
				if (str_x.toLowerCase() === str_y.toLowerCase()) {
					var r_v = true;
				}
				return r_v || false;
			},
			IdenticalField: function (str, element_class) {
				var elements = DA.$("form ."+element_class);
				var r_v = true;

				if (elements[0].value.toLowerCase() != elements[1].value.toLowerCase()) {
					r_v = false;
				}
				return r_v || false;
			}
		},
		Set: {
			ErrorClass: function (el) {
				el.addClass(TDM.Config.Selectors.Error);

				el.addEvent('focus', function () {
					el.removeClass(TDM.Config.Selectors.Error);
				});
			},
			ErrorMessage: function (el, error_message_value, default_error) {
				var error_message_text = TDM.Config.Messages.Errors[error_message_value] ? TDM.Config.Messages.Errors[error_message_value] : default_error;
				var error_message = document.createElement("em");
				var error_message_textCDATA = document.createTextNode(error_message_text);

				DA.$(error_message).addClass(TDM.Config.Selectors.ErrorMessage);
				error_message.appendChild(error_message_textCDATA);

				el.parentNode.insertBefore(error_message, el.nextSibling);
			},
			ErrorMessageGlobal: function (el, default_error) {
				var modifyClass = TDM.Utils.ClassName;
				var settings = TDM.Config.Selectors;

				var error_message_global_text = TDM.Config.Messages.Errors.error_message_global_value ? TDM.Config.Messages.Errors.error_message_global_value : default_error;
				var error_message_global = document.createElement("p");

				error_message_global.id = "error_message_global";
				DA.$(error_message_global).addContent(error_message_global_text);

				DA.$(error_message_global).addClass(TDM.Config.Selectors.ErrorMessage);

				var fieldset_zero = el.getElementsByTagName('fieldset')[0];

				var fcn = fieldset_zero.childNodes;
				for (var i=0; i<fcn.length; i++) {
					if (fcn[i].nodeType === 1) {
						fieldset_zero.insertBefore(error_message_global, fcn[i]);
						break;
					}
				}
			}
		},

		WindowPrint: function (actions) {
			actions.each(function () {
				DA.$(this).addEvent('click', function () {
					window.print();
				});
				DA.$(this).addEvent('keypress', function () {
					window.print();
				});
			});
		},

		InputValueTip: function ($input, valueText) { 
			$input.setAttributes({value : valueText});
			$input.addEvent ('focus', function (_this) {
				return function (e) {
					if (_this[0].value === valueText) {_this.setAttributes({value : ""});}
				}; 
			}($input));
		
			$input.addEvent ('blur', function (_this) { 
				return function (e) {
					if (_this[0].value === "") {
						_this.setAttributes({value : valueText});
					}
				};
			}($input));
		},

		ElementTitle: function (els) {
			els.each(function () {
				$(this).addEvent('mouseover', function (el) {
					
					return function (e) {
						el.addClass(TDM.Config.Selectors.IAdvisory);
						
						div = document.createElement('div');
						div.className = TDM.Config.Selectors.InfoAdvisory;
						span = document.createElement('span');
						span.appendChild(document.createTextNode(el.title));
						span.className = "caption";
						div.appendChild(span);
						document.body.appendChild(div);
						
						el.title = '';

						//e = e || event; //This might not be necessary
						//console.log("mouseover");
						el.addEvent('mousemove', MousePosition = function (e) {
					//		mouseX = e.pageX || e.clientX + document.body.scrollLeft;
					//		mouseY = e.pageY || e.clientY + document.body.scrollTop;
/*							
							if (DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].style.left != mouseX+"px") {
								DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].style.left = mouseX+"px";
							}
							if (DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].style.top != mouseY+"px") {
								DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].style.top = mouseY+"px";
							}*/
						});

						mouseX = e.pageX || e.clientX + document.body.scrollLeft;
						mouseY = e.pageY || e.clientY + document.body.scrollTop;
						DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].style.left = mouseX+"px";
						DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].style.top = mouseY+"px";
					};
				
				}($(this)));

				$(this).addEvent('mouseout', function (el) {
					return function (e) {
						el.title = DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].textContent || DA.$('.'+TDM.Config.Selectors.InfoAdvisory)[0].innerText;
						DA.$('.'+TDM.Config.Selectors.IAdvisory).removeClass(TDM.Config.Selectors.IAdvisory);
						DA.$('.'+TDM.Config.Selectors.InfoAdvisory).remove();

					//	el.removeEvent('mousemove', MousePosition);
					};
				}($(this)));

			});
		},

		InitHover: function (el, hover_class) {
			hover_class = hover_class || TDM.Config.Selectors.Hover;
			for (var i=0; i<el.length; i++) {
				node = el[i];
				$(node).addEvent('mouseover', function () { $(this).addClass(hover_class); });
				$(node).addEvent('mouseout', function () { $(this).removeClass(hover_class); });
			}
		},

		TypographyResize: function (container, parent, index) { 
			li = document.createElement("li");
			li.className = TDM.Config.Selectors.FontResize;
			ul = document.createElement("ul");
			li_1 = document.createElement("li");
			li_2 = document.createElement("li");
			a_1 = document.createElement("a");
			a_2 = document.createElement("a");

			li_1.className = TDM.Config.Selectors.FontSizeDecrease;
			li_2.className = TDM.Config.Selectors.FontSizeIncrease;
			a_1.title = TDM.Config.Selectors.FontSizeDecreaseText;
			a_1.title = TDM.Config.Selectors.FontSizeDecreaseText;
			
			a_1.appendChild(document.createTextNode(TDM.Config.Selectors.FontSizeDecreaseText));
			a_2.appendChild(document.createTextNode(TDM.Config.Selectors.FontSizeIncreaseText));
			a_1.title = TDM.Config.Selectors.FontSizeDecreaseText;
			a_2.title = TDM.Config.Selectors.FontSizeIncreaseText;
			li_1.appendChild(a_1);
			li_2.appendChild(a_2);
			ul.appendChild(li_1);
			ul.appendChild(li_2);
			li.appendChild(ul);
			
			TDM.Utils.InsertNode(parent, index, li);

			DA.$("."+TDM.Config.Selectors.FontSizeDecrease+" a").each(function () {
				DA.$(this).addEvent('click', function (c) {
					return function (e) {
						c.removeClass(TDM.Config.Init.TypographyWeights[TDM.Config.Init.TypographyCurrentSize]);
						if (TDM.Config.Init.TypographyCurrentSize > 0) {
							TDM.Config.Init.TypographyCurrentSize--;
						}
						c.addClass(TDM.Config.Init.TypographyWeights[TDM.Config.Init.TypographyCurrentSize]);
					};
				}(container));				
			});
			DA.$("."+TDM.Config.Selectors.FontSizeIncrease+" a").each(function () {
				DA.$(this).addEvent('click', function (c) {
					return function (e) {
						c.removeClass(TDM.Config.Init.TypographyWeights[TDM.Config.Init.TypographyCurrentSize]);
						if (TDM.Config.Init.TypographyCurrentSize < TDM.Config.Init.TypographyWeights.length - 1) {
							TDM.Config.Init.TypographyCurrentSize++;
						}
						c.addClass(TDM.Config.Init.TypographyWeights[TDM.Config.Init.TypographyCurrentSize]);
					};
				}(container));				
			});
		},

		Bookmark: function () {
			DA.$("."+TDM.Config.Selectors.Bookmark+" a").each(function () {
				DA.$(this).addEvent('click', function () {
					if (window.sidebar) {
						window.sidebar.addPanel(document.title, location, '');
					}
					else {
						if(window.external) {
							window.external.AddFavorite(location, document.title);
						}
						else {
							if(window.opera && window.print) {
								alert(TDM.Config.Selectors.BookmarkTextUA.Presto);
							}
							else {
								if (navigator.userAgent.toLowerCase().indexOf('webkit') != -1){
									alert(alert(TDM.Config.Selectors.BookmarkTextUA.WebKit)); 
								}
							}
						}
					}
				});
			});
		},

		InsertNode: function (parent, index, node) {
			children = parent.childNodes;
			j=-1;
			for (var k=0; k<children.length; k++) {
				if (children[k].nodeType === 1) {
					j++;
					if (index == j) {
/*
						if (j == 0) {
							$(node).addClass(TDM.Config.Selectors.FirstChild);
						}
*/
						parent.insertBefore(node.cloneNode(true), children[k]);
						break;
					}
				}
			}			
			if (index > j) {
				parent.appendChild(node.cloneNode(true));	
			}	
		},

		FigureView: function (el, specific_legend) {
			var counter = 0;
			el.each(function () {
					$(this).addEvent('click', function (_this, counter) {
					return function (e) {		
						if (document.getElementById('figure_container')) {
							removed_element = document.getElementsByTagName('body')[0].removeChild(document.getElementById('figure_container'));
						}

						var figure_overlay = document.createElement("div");
						figure_overlay.id = "figure_overlay";
						var arrayPageSize = TDM.Utils.GetPageSize();
						figure_overlay.style.width = arrayPageSize[0] + "px";
						figure_overlay.style.height = arrayPageSize[1] + "px";

						var figure_container = document.createElement("div");
						figure_container.id = "figure_container";
						figure_container.className = TDM.Config.Selectors.Opened;
	
						var figure_image = document.createElement('img');
						figure_image.src = _this.href; //should be an absolute URL
						figure_image.alt = '';


						var figure_caption = document.createElement("strong");
						figure_caption.className = "figure_caption";

						////////////// ELLE //////////////////						
						if (specific_legend != null) {
							var figure_caption_textCDATA = DA.$(specific_legend)[counter];
						} else {
							var figure_caption_textCDATA = DA.$('.legend')[counter];
						}
						////////////// ELLE //////////////////						

						figure_caption_textCDATA = figure_caption_textCDATA.textContent || figure_caption_textCDATA.innerText;
						figure_caption_textCDATA = document.createTextNode(figure_caption_textCDATA);
						figure_caption.appendChild(figure_caption_textCDATA);

						var figure_container_close = document.createElement('span');
						var figure_container_close_textCDATA = document.createTextNode(TDM.Config.Selectors.CloseText);
						figure_container_close.className = "script_based_close";
						figure_container_close.title = TDM.Config.Selectors.CloseTitle;
						figure_container_close.appendChild(figure_container_close_textCDATA);

						var figure_c_data = document.createElement('div');
						figure_c_data.id = "figure_c_data";
						var figure_c_description = document.createElement('div');
						figure_c_description.id = "figure_c_description";

						var arrayPageScroll = TDM.Utils.GetPageScroll();
						var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
						var lightboxLeft = arrayPageScroll[0];
						figure_container.style.position = "absolute";
						figure_container.style.top = lightboxTop + "px";
						figure_container.style.left = lightboxLeft + "px";

						figure_c_data.appendChild(figure_image);
						figure_c_description.appendChild(figure_caption);
						figure_c_description.appendChild(figure_container_close);

						figure_container.appendChild(figure_c_data);
						figure_container.appendChild(figure_c_description);


						element_body = document.getElementsByTagName('body')[0];
						document.body.appendChild(figure_overlay);
						document.body.appendChild(figure_container);										

						document.getElementById('figure_c_data').getElementsByTagName('img')[0].onload = function () {
							document.getElementById('figure_c_description').style.width = document.getElementById('figure_c_data').style.width = document.getElementById('figure_c_data').getElementsByTagName('img')[0].offsetWidth + "px";
						}

						DA.$("#figure_container .script_based_close").addEvent('click', function () {
							if (document.getElementById('figure_container')) {
								removed_element_overlay = document.body.removeChild(document.getElementById('figure_overlay'));
								removed_element_container = document.body.removeChild(document.getElementById('figure_container'));
							}
						});

						////////////// ELLE //////////////////
						DA.$("#figure_overlay").addEvent('click', function () {
							if (document.getElementById('figure_container')) {
								removed_element_overlay = document.body.removeChild(document.getElementById('figure_overlay'));
								removed_element_container = document.body.removeChild(document.getElementById('figure_container'));
							}
						});
						////////////// ELLE //////////////////						

						try {
							e.preventDefault();
						} catch(err) {
							try {
								window.event.returnValue = false;
							} catch(err2) {
								alert(err2);	
							}
						}
					};
				}($(this), counter));
				counter++;
			});
			return false;
		},

		GetPageSize: function () {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else {
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) {
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			if(xScroll < windowWidth){
				pageWidth = xScroll;
			} else {
				pageWidth = windowWidth;
			}

			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		},

		GetPageScroll: function () {
			var xScroll, yScroll;

			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		},

		ContentBrowser: function (parent, datas, limit) {
			TDM.Config.Init.CurrentView[parent] = 0;

			div = document.createElement("div");
			ul = document.createElement("ul");
			li_1 = document.createElement("li");
			li_2 = document.createElement("li");
			div.className = TDM.Config.Selectors.ContentBrowser;
			ul.className = TDM.Config.Selectors.Controls;
			li_1.className = TDM.Config.Selectors.Previous;
			li_2.className = TDM.Config.Selectors.Next;
			ul.appendChild(li_1);
			ul.appendChild(li_2);
			div.appendChild(ul);

			var actions='';
			if (DA.$('#'+parent+' ul.'+TDM.Config.Selectors.ContentViewActions+' li').length > 0) {
				actions =  DA.$('#'+parent+' ul.'+TDM.Config.Selectors.ContentViewActions+' li');
			}
			else {
				ul = document.createElement("ul");
				ul.className = TDM.Config.Selectors.ContentViewActions;
				for (var i=0; i<datas.length; i++) {
					var li = document.createElement("li");
					var a = document.createElement("a");
					a.href = '#'+parent+"_"+i;
					var a_textCDATA = document.createTextNode(i);
					a.appendChild(a_textCDATA);
					li.appendChild(a);
					ul.appendChild(li);
				}

				DA.$$(parent).appendChild(ul);

				actions = DA.$('#'+parent+' ul.'+TDM.Config.Selectors.ContentViewActions+' li');
			}

			DA.$('#'+parent).addContent(div);

			for (var j=TDM.Config.Init.CurrentView[parent]; j<datas.length; j++) {
				if (j < limit) {
					datas[j].className += ' '+TDM.Config.Selectors.Opened;
					actions[j].className += ' '+TDM.Config.Selectors.Selected;
				}
				else {
					datas[j].className += ' '+TDM.Config.Selectors.Closed;
				}
			}

			prev = DA.$('#'+parent+' ul.'+TDM.Config.Selectors.Controls+' li.'+TDM.Config.Selectors.Previous);
			next = DA.$('#'+parent+' ul.'+TDM.Config.Selectors.Controls+' li.'+TDM.Config.Selectors.Next);

			prev[0].style.display = 'none';

			prev.addEvent('click', function (parent, datas, limit, direction, _this) {
				return function (e) {
					TDM.Utils.ContentController(parent, datas, limit, direction, _this);

					next = DA.$('#'+parent+' ul.'+TDM.Config.Selectors.Controls+' li.'+TDM.Config.Selectors.Next);
					_this[0].style.display = 'block';
					next[0].style.display = 'block';

					if (TDM.Config.Init.CurrentView[parent] <= 0) {
						_this[0].style.display = 'none';
					}
				};
			}(parent, datas, limit, -1, prev));

			next.addEvent('click', function (parent, datas, limit, direction, _this) {
				return function (e) {
					TDM.Utils.ContentController(parent, datas, limit, direction, _this);

					prev = DA.$('#'+parent+' ul.'+TDM.Config.Selectors.Controls+' li.'+TDM.Config.Selectors.Previous);
					prev[0].style.display = 'block';
					_this[0].style.display = 'block';

					if (TDM.Config.Init.CurrentView[parent] >= datas.length-limit) {
						_this[0].style.display = 'none';
					}
				};
			}(parent, datas, limit, 1, next));

			prev = next = null;
		},

		ContentController: function (parent, datas, limit, direction, _this) {
			var content_view_top = TDM.Config.Init.CurrentView[parent];
			content_view_top = content_view_top+direction;

			if (content_view_top <= 0) {
				content_view_top = 0;
			}
			if (content_view_top >= datas.length-limit) {
				content_view_top = datas.length-limit;
			}

			datas.each(function () {
				DA.$(this).removeClass(TDM.Config.Selectors.Closed);
				DA.$(this).removeClass(TDM.Config.Selectors.Opened);
			});

			for (var j=0; j<datas.length; j++) {
				if (content_view_top <= j && j < content_view_top+limit) {
					datas[j].className += ' '+TDM.Config.Selectors.Opened;
				}
				else {
					datas[j].className += ' '+TDM.Config.Selectors.Closed;
				}
			}
			TDM.Config.Init.CurrentView[parent] = content_view_top;
		}
	}
};

TDM.Config.ValidationFunctionList = [
	{"checktype":TDM.Config.Selectors.IsSet, "func":TDM.Utils.ValidateField.IsSet, "error":"error: not set"},
	{"checktype":TDM.Config.Selectors.IsSelected, "func":TDM.Utils.ValidateField.IsSelected, "error":"error: not selected"},
	{"checktype":TDM.Config.Selectors.IsChecked, "func":TDM.Utils.ValidateField.IsChecked, "error":"error: not checked"},
	{"checktype":TDM.Config.Selectors.PatternEmail, "func":TDM.Utils.ValidateField.Pattern.Email, "error":"error: incorrect email format"},
	{"checktype":TDM.Config.Selectors.PatternEmailMultiple, "func":TDM.Utils.ValidateField.Pattern.EmailMultiple, "error":"error: seperate by space AND check pattern"},
	{"checktype":TDM.Config.Selectors.IdenticalEmail, "func":TDM.Utils.ValidateField.IdenticalField, "error":"error: unidentical emails"},
	{"checktype":TDM.Config.Selectors.IdenticalPassword, "func":TDM.Utils.ValidateField.IdenticalField, "error":"error: unidentical password"}
];

function Go() {
	TDM.Utils.OpenResourceOnNewWindow();
};
