/**
 * Copyright 2009-2011 | Fabrice Creuzot (luigifab) <code~luigifab~info>
 * (2.3.3) http://www.luigifab.info/apijs
 *
 * This program is free software, you can redistribute it or modify
 * it under the terms of the GNU General Public License (GPL) as published
 * by the free software foundation, either version 2 of the license, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but without any warranty, without even the implied warranty of
 * merchantability or fitness for a particular purpose. See the
 * GNU General Public License (GPL) for more details.
 */
function Dialogue() {
	this.offset = 0;
	this.hiddenPage = false;
	this.dialogType = null;
	this.image = null;
	this.timer = null;
	this.callback = null;
	this.params = null;
	this.fragment = null;
	this.elemA = null;
	this.elemB = null;
	this.elemC = null;
	this.elemD = null;
	this.dialogInformation = function (title, text, icon) {
		if ((typeof title === 'string') && (typeof text === 'string')) {
			this.setupDialogue('information', icon);
			this.htmlParent(false);
			this.htmlTitle(title);
			this.htmlParagraph(text);
			this.htmlButtonOk();
			this.showDialogue();
			document.getElementById('box').lastChild.lastChild.focus();
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogInformation[br]➩ (string) title : ' + title + '[br]➩ (string) text : ' + text + '[br]➩ (string) icon : ' + icon + '[/pre]');
		}
	};
	this.dialogConfirmation = function (title, text, callback, params, icon) {
		if ((typeof title === 'string') && (typeof text === 'string') && (typeof callback === 'function')) {
			this.setupDialogue('confirmation', icon);
			this.htmlParent(false);
			this.htmlTitle(title);
			this.htmlParagraph(text);
			this.htmlButtonConfirm('button');
			this.callback = callback;
			this.params = params;
			this.showDialogue();
			document.getElementById('box').lastChild.firstChild.focus();
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogConfirmation[br]➩ (string) title : ' + title + '[br]➩ (string) text : ' + text + '[br]➩ (function) callback : ' + callback + '[br]➩ (object) params : ' + params + '[br]➩ (string) icon : ' + icon + '[/pre]');
		}
	};
	this.dialogFormOptions = function (title, text, callback, params, action, icon) {
		if ((typeof title === 'string') && (typeof text === 'string') && (typeof callback === 'function') && (typeof action === 'string')) {
			this.setupDialogue('options', icon);
			this.htmlFormParent(action);
			this.htmlTitle(title);
			this.htmlParagraph(text);
			this.htmlButtonConfirm('submit');
			this.callback = callback;
			this.params = params;
			this.showDialogue();
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogFormOptions[br]➩ (string) title : ' + title + '[br]➩ (string) text : ' + text + '[br]➩ (function) callback : ' + callback + '[br]➩ (object) params : ' + params + '[br]➩ (string) action : ' + action + '[br]➩ (string) icon : ' + icon + '[/pre]');
		}
	};
	this.dialogFormUpload = function (title, text, data, key, icon) {
		if ((typeof title === 'string') && (typeof text === 'string') && (typeof key === 'string') && (typeof data === 'string')) {
			this.setupDialogue('upload', icon);
			this.htmlFormParent(apijs.config.dialogue.fileUpload, 'multipart/form-data', 'iframeUpload-' + key);
			this.htmlTitle(title);
			this.htmlParagraph(text);
			this.htmlFormUpload(data, key);
			this.htmlButtonConfirm('submit');
			this.showDialogue();
			document.getElementById('box').getElementsByTagName('input')[0].focus();
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogFormUpload[br]➩ (string) title : ' + title + '[br]➩ (string) text : ' + text + '[br]➩ (string) data : ' + data + '[br]➩ (string) key : ' + key + '[br]➩ (string) icon : ' + icon + '[/pre]');
		}
	};
	this.dialogProgress = function (title, text, time) {
		if ((typeof title === 'string') && (typeof text === 'string')) {
			this.setupDialogue('progress');
			this.htmlParent(false);
			this.htmlTitle(title);
			this.htmlParagraph(text);
			this.htmlProgressBar();
			this.showDialogue();
			this.timer = window.setTimeout(apijs.dialogue.htmlLinkReload, (typeof time === 'number') ? time : 15000);
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogProgress[br]➩ (string) title : ' + title + '[br]➩ (string) text : ' + text + '[br]➩ (number) time : ' + time + '[/pre]');
		}
	};
	this.dialogWaiting = function (title, text, time) {
		if ((typeof title === 'string') && (typeof text === 'string')) {
			this.setupDialogue('waiting');
			this.htmlParent(false);
			this.htmlTitle(title);
			this.htmlParagraph(text);
			this.showDialogue();
			this.timer = window.setTimeout(apijs.dialogue.htmlLinkReload, (typeof time === 'number') ? time : 5000);
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogWaiting[br]➩ (string) title : ' + title + '[br]➩ (string) text : ' + text + '[br]➩ (number) time : ' + time + '[/pre]');
		}
	};
	this.dialogPhoto = function (width, height, url, name, date, legend, slideshow) {
		if ((typeof width === 'number') && (typeof height === 'number') && (typeof url === 'string') && (typeof name === 'string') && (typeof date === 'string') && (typeof legend === 'string')) {
			if ((typeof slideshow === 'boolean') && (slideshow === true)) {
				this.setupDialogue('photo slideshow');
				this.htmlParent(true);
			}
			else {
				this.setupDialogue('photo');
				this.htmlParent(false);
			}
			this.htmlPhoto(width, height, url, name, date, legend);
			this.htmlButtonClose();
			this.htmlButtonNavigation();
			this.showDialogue();
			this.loadImage(width, height, url);
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogPhoto[br]➩ (number) width : ' + width + '[br]➩ (number) height : ' + height + '[br]➩ (string) url : ' + url + '[br]➩ (string) name : ' + name + '[br]➩ (string) date : ' + date + '[br]➩ (string) legend : ' + legend + '[/pre]');
		}
	};
	this.dialogVideo = function (url, name, date, legend, slideshow) {
		if ((typeof url === 'string') && (typeof name === 'string') && (typeof legend === 'string') && (typeof legend === 'string')) {
			if ((typeof slideshow === 'boolean') && (slideshow === true)) {
				this.setupDialogue('video slideshow');
				this.htmlParent(true);
			}
			else {
				this.setupDialogue('video');
				this.htmlParent(false);
			}
			this.htmlVideo(url, name, date, legend);
			this.htmlButtonClose();
			this.htmlButtonNavigation();
			this.showDialogue();
		}
		else if (apijs.config.debug) {
			this.dialogInformation(apijs.i18n.translate('debugInvalidCall'), '[pre]TheDialogue » dialogVideo[br]➩ (string) url : ' + url + '[br]➩ (string) name : ' + name + '[br]➩ (string) date : ' + date + '[br]➩ (string) legend : ' + legend + '[/pre]');
		}
	};
	this.actionClose = function (all) {
		if (all) {
			apijs.dialogue.deleteDialogue(true);
			apijs.dialogue.showPage();
		}
		else {
			apijs.dialogue.deleteDialogue(false);
		}
	};
	this.actionConfirm = function () {
		if (this.dialogType.indexOf('confirmation') > -1) {
			this.dialogType += ' lock';
			if (apijs.config.dialogue.savingDialog) {
				this.dialogWaiting(document.getElementById('box').firstChild.firstChild.nodeValue, apijs.i18n.translate('operationInProgress'));
			}
			else {
				this.elemA = document.createElement('p');
				this.elemA.setAttribute('class', 'saving');
				this.elemA.appendChild(document.createTextNode(apijs.i18n.translate('operationInProgress')));
				document.getElementById('box').removeChild(document.getElementById('box').lastChild);
				document.getElementById('box').lastChild.setAttribute('class', 'novisible');
				document.getElementById('box').appendChild(this.elemA);
				this.timer = window.setTimeout(apijs.dialogue.htmlLinkReload, 5000);
			}
			if (apijs.config.dialogue.savingTime > 500) {
				window.setTimeout(function () {
					if (typeof apijs.dialogue.callback === 'function')
						apijs.dialogue.callback(apijs.dialogue.params);
				}, apijs.config.dialogue.savingTime);
			}
			else {
				apijs.dialogue.callback(apijs.dialogue.params);
			}
		}
		else if (this.dialogType.indexOf('options') > -1) {
			if (apijs.dialogue.callback(apijs.dialogue.clone(apijs.dialogue.params)) === true) {
				this.dialogType += ' lock';
				this.elemA = document.createElement('p');
				this.elemA.setAttribute('class', 'saving');
				this.elemA.appendChild(document.createTextNode(apijs.i18n.translate('operationInProgress')));
				document.getElementById('box').removeChild(document.getElementById('box').lastChild);
				document.getElementById('box').lastChild.setAttribute('class', 'novisible');
				document.getElementById('box').appendChild(this.elemA);
				this.timer = window.setTimeout(apijs.dialogue.htmlLinkReload, 5000);
				if (apijs.config.dialogue.savingTime > 500) {
					window.setTimeout(function () {
						if (document.getElementById('box') && (document.getElementById('box').nodeName.toLowerCase() === 'form'))
							document.getElementById('box').submit();
					}, apijs.config.dialogue.savingTime);
					return false;
				}
				else {
					return true;
				}
			}
			else {
				return false;
			}
		}
		else if (this.dialogType.indexOf('upload') > -1) {
			this.dialogType += ' lock';
			if ((typeof Upload === 'function') && (apijs.upload instanceof Upload))
				return apijs.upload.actionConfirm();
			else if (apijs.config.debug)
				this.dialogInformation(apijs.i18n.translate('debugInvalidUse'), '[pre]TheDialogue » actionConfirm[br]➩ TheUpload ' + apijs.i18n.translate('debugNotExist') + '[/pre]');
		}
	};
	this.actionKey = function (ev) {
		if (apijs.config.debugkey) {
			ev.preventDefault();
			apijs.dialogue.dialogInformation(apijs.i18n.translate('debugKeyDetected'), '[pre]TheDialogue » actionKey[br]' + apijs.i18n.translate('debugKeyCode', ev.keyCode) + '[/pre]');
		}
		else if ((ev.keyCode !== 27) && (ev.keyCode !== 35) && (ev.keyCode !== 36) && (ev.keyCode !== 37) && (ev.keyCode !== 39)) {
			return;
		}
		else if (ev.keyCode === 27) {
			if ((apijs.dialogue.dialogType.indexOf('waiting') > -1) || (apijs.dialogue.dialogType.indexOf('progress') > -1) ||
			 (apijs.dialogue.dialogType.indexOf('lock') > -1)) {
				ev.preventDefault();
			}
			else {
				ev.preventDefault();
				apijs.dialogue.actionClose(true);
			}
		}
		else if (apijs.dialogue.dialogType.indexOf('slideshow') > -1) {
			if (ev.keyCode === 35) {
				ev.preventDefault();
				apijs.slideshow.actionLast();
			}
			else if (ev.keyCode === 36) {
				ev.preventDefault();
				apijs.slideshow.actionFirst();
			}
			else if (ev.keyCode === 37) {
				ev.preventDefault();
				apijs.slideshow.actionPrev();
			}
			else if (ev.keyCode === 39) {
				ev.preventDefault();
				apijs.slideshow.actionNext();
			}
		}
	};
	this.setupDialogue = function (type, icon) {
		var actionHidden = false, actionShow = false, id = null;
		if (this.dialogType !== null) {
			if (this.dialogType.indexOf('slideshow') > -1) {
					if (!this.hiddenPage && apijs.config.dialogue.hiddenPage)
						actionHidden = true;
					else if (this.hiddenPage && !apijs.config.dialogue.hiddenPage)
						actionShow = true;
			}
			else {
				if (!this.hiddenPage && apijs.config.dialogue.hiddenPage)
					actionHidden = true;
				else if (this.hiddenPage && !apijs.config.dialogue.hiddenPage)
					actionShow = true;
			}
		}
		else {
			if (type.indexOf('slideshow') > -1) {
				if (!this.hiddenPage && apijs.config.slideshow.hiddenPage)
					actionHidden = true;
			}
			else {
				if (!this.hiddenPage && apijs.config.dialogue.hiddenPage)
					actionHidden = true;
			}
		}
		if ((this.dialogType !== null) && (this.dialogType.indexOf('slideshow') > -1)) {
			this.deleteDialogue(false);
			document.getElementById('dialogue').setAttribute('class', document.getElementById('dialogue').getAttribute('class').replace(' slideshow', ''));
		}
		else if (this.dialogType !== null) {
			this.deleteDialogue(false);
		}
		if (actionHidden) {
			if ((window.pageYOffset > 0) || (this.offset > 0))
				this.offset = window.pageYOffset;
			for (id in apijs.config.dialogue.blocks) if (apijs.config.dialogue.blocks.hasOwnProperty(id))
				document.getElementById(apijs.config.dialogue.blocks[id]).setAttribute('class', 'nodisplay');
		}
		else if (actionShow) {
			this.showPage();
		}
		if (apijs.config.navigator)
			document.addEventListener('keydown', apijs.dialogue.actionKey, false);
		this.dialogType = (typeof icon !== 'string') ? type : (type + ' ' + icon);
		this.hiddenPage = (actionHidden || this.hiddenPage) ? true : false;
		this.fragment = document.createDocumentFragment();
	};
	this.showDialogue = function () {
		if (document.getElementById('dialogue')) {
			this.fragment.firstChild.setAttribute('class', this.fragment.firstChild.getAttribute('class').replace('init', 'actif'));
			document.getElementById('dialogue').appendChild(this.fragment.firstChild.firstChild);
		}
		else if (!apijs.config.transition) {
			this.fragment.firstChild.setAttribute('class', this.fragment.firstChild.getAttribute('class').replace('init', 'actif'));
			document.getElementsByTagName('body')[0].appendChild(this.fragment);
		}
		else {
			document.getElementsByTagName('body')[0].appendChild(this.fragment);
			window.setTimeout(function () { document.getElementById('dialogue').setAttribute('class', document.getElementById('dialogue').getAttribute('class').replace('init', 'actif')); }, 1);
		}
	};
	this.deleteDialogue = function (all) {
		if (this.timer)
			clearTimeout(this.timer);
		if (apijs.config.navigator)
			document.removeEventListener('keydown', apijs.dialogue.actionKey, false);
		if (apijs.config.navigator && (document.getElementById('dialogue').getElementsByTagName('video').length > 0)) {
			if (typeof document.getElementById('dialogue').getElementsByTagName('video')[0].pause === 'function')
				document.getElementById('dialogue').getElementsByTagName('video')[0].pause();
		}
		if (apijs.config.transition && all) {
			document.getElementById('dialogue').setAttribute('class', document.getElementById('dialogue').getAttribute('class').replace('actif', 'deleting lock'));
			window.setTimeout(function () {
				if (document.getElementById('dialogue'))
					document.getElementById('dialogue').parentNode.removeChild(document.getElementById('dialogue'));
			}, 400);
		}
		else if (all) {
			document.getElementById('dialogue').parentNode.removeChild(document.getElementById('dialogue'));
		}
		else {
			document.getElementById('box').parentNode.removeChild(document.getElementById('box'));
		}
		this.dialogType = null;
		this.image = null;
		this.timer = null;
		this.fragment = null;
		this.elemA = null;
		this.elemB = null;
		this.elemC = null;
		this.elemD = null;
	};
	this.showPage = function () {
		if (document.getElementById('iframeUpload'))
			document.getElementById('iframeUpload').parentNode.removeChild(document.getElementById('iframeUpload'));
		if (this.hiddenPage) {
			for (var id in apijs.config.dialogue.blocks) if (apijs.config.dialogue.blocks.hasOwnProperty(id))
				document.getElementById(apijs.config.dialogue.blocks[id]).removeAttribute('class');
			window.scrollBy(0, this.offset);
		}
		this.offset = 0;
		this.hiddenPage = false;
		this.callback = null;
		this.params = null;
	};
	this.checkSize = function (width, height) {
		if ((width > (window.innerWidth - 150)) || (height > (window.innerHeight - 100)))
			return true;
		else
			return false;
	};
	this.updateSize = function (width, height, url) {
		var infoMedia = null, infoWindow = null, mimeTypes = null;
		infoMedia = { width: width, height: height, id: url.slice((url.lastIndexOf('/') + 1), url.lastIndexOf('.')), mime: null };
		infoWindow = { width: window.innerWidth, height: window.innerHeight };
		mimeTypes = {
			ogv: 'video/ogg', webm: 'video/webm',
			jpg: 'image/jpeg', jpeg: 'image/jpeg',
			tif: 'image/tiff', tiff: 'image/tiff',
			png: 'image/png', svg: 'image/svg+xml'
		};
		infoMedia.mime = url.slice(url.lastIndexOf('.') + 1);
		if (infoMedia.mime in mimeTypes)
			infoMedia.mime = mimeTypes[infoMedia.mime];
		if (this.checkSize(width, height)) {
			infoWindow.width -= 150;
			infoWindow.height -= 100;
			if (infoMedia.width > infoWindow.width) {
				infoMedia.height = Math.floor(infoMedia.height * (infoWindow.width / infoMedia.width));
				infoMedia.width = infoWindow.width;
				if (infoMedia.height > infoWindow.height) {
					infoMedia.width = Math.floor(infoMedia.width * (infoWindow.height / infoMedia.height));
					infoMedia.height = infoWindow.height;
				}
			}
			else if (infoMedia.height > infoWindow.height) {
				infoMedia.width = Math.floor(infoMedia.width * (infoWindow.height / infoMedia.height));
				infoMedia.height = infoWindow.height;
				if (infoMedia.width > infoWindow.width) {
					infoMedia.height = Math.floor(infoMedia.height * (infoWindow.width / infoMedia.width));
					infoMedia.width = infoWindow.width;
				}
			}
		}
		this.fragment.firstChild.firstChild.style.width = infoMedia.width + 'px';
		this.fragment.firstChild.firstChild.style.marginLeft = parseInt(-(infoMedia.width + 20) / 2, 10) + 'px';
		this.fragment.firstChild.firstChild.style.marginTop = parseInt(-(infoMedia.height + 50) / 2, 10) + 'px';
		return infoMedia;
	};
	this.loadImage = function (width, height, url) {
		if (apijs.config.navigator && apijs.config.dialogue.showLoader) {
			this.image = new Image(width, height);
			this.image.src = url;
			this.image.addEventListener('load', function () {
				if (document.getElementById('topho')) {
					document.getElementById('topho').removeAttribute('class');
					document.getElementById('topho').setAttribute('src', apijs.dialogue.image.src);
				}
			}, false);
			this.image.addEventListener('error', function () {
				if (document.getElementById('topho')) {
					if (document.getElementById('topho').getAttribute('class').indexOf('resized') > -1) {
						var img = document.getElementById('topho').cloneNode(true);
						document.getElementById('topho').parentNode.parentNode.removeChild(document.getElementById('topho').parentNode);
						document.getElementById('box').firstChild.firstChild.appendChild(img);
					}
					if (apijs.config.dialogue.savePhoto)
						document.getElementById('box').firstChild.lastChild.removeChild(document.getElementById('box').firstChild.lastChild.lastChild);
					document.getElementById('topho').setAttribute('class', 'error_' + apijs.config.lang);
				}
			}, false);
		}
		else {
			document.getElementById('topho').removeAttribute('class');
			document.getElementById('topho').setAttribute('src', url);
		}
	};
	this.clone = function (object) {
		if ((object === null) || (typeof object !== 'object'))
			return object;
		var key = null, newObject = new object.constructor();
		for (var key in object)
			newObject[key] = apijs.dialogue.clone(object[key]);
		return newObject;
	};
	this.htmlParent = function (slideshow) {
		this.elemA = document.createElement('div');
		this.elemA.setAttribute('class', ((slideshow) ? 'init slideshow' : 'init'));
		this.elemA.setAttribute('id', 'dialogue');
		this.elemB = document.createElement('div');
		this.elemB.setAttribute('class', this.dialogType);
		this.elemB.setAttribute('id', 'box');
		this.elemA.appendChild(this.elemB);
		this.fragment.appendChild(this.elemA);
	};
	this.htmlFormParent = function (action, enctype, target) {
		this.elemA = document.createElement('div');
		this.elemA.setAttribute('class', 'init');
		this.elemA.setAttribute('id', 'dialogue');
		this.elemB = document.createElement('form');
		this.elemB.setAttribute('action', action);
		this.elemB.setAttribute('method', 'post');
		if (typeof enctype === 'string')
			this.elemB.setAttribute('enctype', enctype);
		if (typeof target === 'string')
			this.elemB.setAttribute('target', target);
		this.elemB.setAttribute('onsubmit', 'return apijs.dialogue.actionConfirm();');
		this.elemB.setAttribute('class', this.dialogType);
		this.elemB.setAttribute('id', 'box');
		this.elemA.appendChild(this.elemB);
		this.fragment.appendChild(this.elemA);
	};
	this.htmlTitle = function (title) {
		this.elemA = document.createElement('h1');
		this.elemA.appendChild(document.createTextNode(title));
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlParagraph = function (data) {
		var bbcode = new BBcode();
		bbcode.init(data);
		bbcode.exec();
		this.fragment.firstChild.firstChild.appendChild(bbcode.getDomFragment());
	};
	this.htmlButtonOk = function () {
		this.elemA = document.createElement('div');
		this.elemA.setAttribute('class', 'control');
			this.elemB = document.createElement('button');
			this.elemB.setAttribute('type', 'button');
			this.elemB.setAttribute('onclick', 'apijs.dialogue.actionClose(true);');
			this.elemB.setAttribute('class', 'confirm');
			this.elemB.appendChild(document.createTextNode(apijs.i18n.translate('buttonOk')));
		this.elemA.appendChild(this.elemB);
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlButtonConfirm = function (type) {
		this.elemA = document.createElement('div');
		this.elemA.setAttribute('class', 'control');
			this.elemB = document.createElement('button');
			this.elemB.setAttribute('type', type);
			this.elemB.setAttribute('class', 'confirm');
			if (type !== 'submit')
				this.elemB.setAttribute('onclick', 'apijs.dialogue.actionConfirm();');
			this.elemB.appendChild(document.createTextNode(apijs.i18n.translate('buttonConfirm')));
		this.elemA.appendChild(this.elemB);
			this.elemB = document.createElement('button');
			this.elemB.setAttribute('type', 'button');
			this.elemB.setAttribute('class', 'cancel');
			this.elemB.setAttribute('onclick', 'apijs.dialogue.actionClose(true);');
			this.elemB.appendChild(document.createTextNode(apijs.i18n.translate('buttonCancel')));
		this.elemA.appendChild(this.elemB);
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlButtonNavigation = function () {
		var txt = ((apijs.config.dialogue.imagePrev === null) || (apijs.config.dialogue.imageNext === null)) ? true : false;
		this.elemA = document.createElement('div');
		this.elemA.setAttribute('class', 'navigation ' + ((txt) ? 'txt' : 'img'));
			this.elemB = document.createElement('button');
			this.elemB.setAttribute('type', 'button');
			this.elemB.setAttribute('disabled', 'disabled');
			this.elemB.setAttribute('onclick', 'apijs.slideshow.actionPrev();');
			this.elemB.setAttribute('id', 'prev');
			if (txt) {
				this.elemB.appendChild(document.createTextNode(apijs.i18n.translate('buttonPrev')));
			}
			else {
				this.elemC = document.createElement('img');
				this.elemC.setAttribute('src', apijs.config.dialogue.imagePrev.src);
				this.elemC.setAttribute('width', apijs.config.dialogue.imagePrev.width);
				this.elemC.setAttribute('height', apijs.config.dialogue.imagePrev.height);
				this.elemC.setAttribute('alt', apijs.i18n.translate('buttonPrev'));
				this.elemB.appendChild(this.elemC);
			}
		this.elemA.appendChild(this.elemB);
			this.elemB = document.createElement('button');
			this.elemB.setAttribute('type', 'button');
			this.elemB.setAttribute('disabled', 'disabled');
			this.elemB.setAttribute('onclick', 'apijs.slideshow.actionNext();');
			this.elemB.setAttribute('id', 'next');
			if (txt) {
				this.elemB.appendChild(document.createTextNode(apijs.i18n.translate('buttonNext')));
			}
			else {
				this.elemC = document.createElement('img');
				this.elemC.setAttribute('src', apijs.config.dialogue.imageNext.src);
				this.elemC.setAttribute('width', apijs.config.dialogue.imageNext.width);
				this.elemC.setAttribute('height', apijs.config.dialogue.imageNext.height);
				this.elemC.setAttribute('alt', apijs.i18n.translate('buttonNext'));
				this.elemB.appendChild(this.elemC);
			}
		this.elemA.appendChild(this.elemB);
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlButtonClose = function () {
		this.elemA = document.createElement('div');
		this.elemA.setAttribute('class', 'close');
			this.elemB = document.createElement('button');
			this.elemB.setAttribute('type', 'button');
			this.elemB.setAttribute('onclick', 'apijs.dialogue.actionClose(true);');
			this.elemB.setAttribute('class', 'close');
			if (apijs.config.dialogue.imageClose !== null) {
				this.elemC = document.createElement('img');
				this.elemC.setAttribute('src', apijs.config.dialogue.imageClose.src);
				this.elemC.setAttribute('width', apijs.config.dialogue.imageClose.width);
				this.elemC.setAttribute('height', apijs.config.dialogue.imageClose.height);
				this.elemC.setAttribute('alt', apijs.i18n.translate('buttonClose'));
				this.elemB.appendChild(this.elemC);
			}
			else {
				this.elemB.appendChild(document.createTextNode(apijs.i18n.translate('buttonClose')));
			}
		this.elemA.appendChild(this.elemB);
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlLinkReload = function () {
		this.elemA = document.createElement('p');
		this.elemA.setAttribute('class', 'reload');
		this.elemA.appendChild(document.createTextNode(apijs.i18n.translate('operationTooLong')));
			this.elemB = document.createElement('a');
			this.elemB.setAttribute('href', location.href);
			this.elemB.appendChild(document.createTextNode(apijs.i18n.translate('reloadLink')));
		this.elemA.appendChild(this.elemB);
		this.elemA.appendChild(document.createTextNode('.'));
			this.elemB = document.createElement('br');
		this.elemA.appendChild(this.elemB);
		this.elemA.appendChild(document.createTextNode(apijs.i18n.translate('warningLostChange')));
		document.getElementById('box').appendChild(this.elemA);
	};
	this.htmlFormUpload = function (data, key) {
		this.elemA = document.createElement('iframe');
		if (apijs.config.navigator)
			this.elemA.setAttribute('src', apijs.config.dialogue.imageUpload.src);
		this.elemA.setAttribute('name', 'iframeUpload-' + key);
		this.elemA.setAttribute('id', 'iframeUpload');
		document.getElementsByTagName('body')[0].appendChild(this.elemA);
		this.elemA = document.createElement('div');
			this.elemB = document.createElement('input');
			this.elemB.setAttribute('type', 'file');
			this.elemB.setAttribute('name', data);
			this.elemB.setAttribute('onchange', "document.getElementById('box').lastChild.firstChild.focus();");
		this.elemA.appendChild(this.elemB);
			this.elemB = document.createElement('input');
			this.elemB.setAttribute('type', 'hidden');
			this.elemB.setAttribute('name', 'APC_UPLOAD_PROGRESS');
			this.elemB.setAttribute('value', key);
		this.elemA.appendChild(this.elemB);
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlProgressBar = function () {
		this.elemA = document.createElement('object');
		this.elemA.setAttribute('data', apijs.config.dialogue.imageUpload.src);
		this.elemA.setAttribute('type', 'image/svg+xml');
		this.elemA.setAttribute('width', apijs.config.dialogue.imageUpload.width);
		this.elemA.setAttribute('height', apijs.config.dialogue.imageUpload.height);
		this.elemA.setAttribute('id', 'progressbar');
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlPhoto = function (width, height, url, name, date, legend) {
		var infoPhoto = this.updateSize(width, height, url);
		this.elemA = document.createElement('dl');
			this.elemB = document.createElement('dt');
				if (this.checkSize(width, height)) {
					this.elemC = document.createElement('a');
					this.elemC.setAttribute('href', url);
					this.elemC.setAttribute('onclick', 'window.open(this.href); this.blur(); return false;');
						this.elemD = document.createElement('img');
						this.elemD.setAttribute('width', infoPhoto.width);
						this.elemD.setAttribute('height', infoPhoto.height);
						this.elemD.setAttribute('class', 'loading resized');
						this.elemD.setAttribute('id', 'topho');
					this.elemC.appendChild(this.elemD);
					this.elemC.appendChild(document.createElement('span'));
				}
				else {
					this.elemC = document.createElement('img');
					this.elemC.setAttribute('width', infoPhoto.width);
					this.elemC.setAttribute('height', infoPhoto.height);
					this.elemC.setAttribute('class', 'loading');
					this.elemC.setAttribute('id', 'topho');
				}
			this.elemB.appendChild(this.elemC);
		this.elemA.appendChild(this.elemB);
			this.elemB = document.createElement('dd');
				if ((name !== 'false') || (date !== 'false')) {
					this.elemC = document.createElement('span');
					if ((name !== 'false') && (name !== 'auto') && (date !== 'false'))
						this.elemC.appendChild(document.createTextNode(name + ' (' + date + ')'));
					else if ((name !== 'false') && (name !== 'auto'))
						this.elemC.appendChild(document.createTextNode(name));
					else if ((name === 'auto') && (date !== 'false'))
						this.elemC.appendChild(document.createTextNode(infoPhoto.id + ' (' + date + ')'));
					else if (name === 'auto')
						this.elemC.appendChild(document.createTextNode(infoPhoto.id));
					else if (date !== 'false')
						this.elemC.appendChild(document.createTextNode('(' + date + ')'));
					this.elemB.appendChild(this.elemC);
				}
				this.elemB.appendChild(document.createTextNode(' ' + legend + ' '));
				if (apijs.config.dialogue.savePhoto) {
					this.elemC = document.createElement('a');
					this.elemC.setAttribute('href', apijs.config.dialogue.filePhoto + '?id=' + infoPhoto.id);
					this.elemC.setAttribute('type', infoPhoto.mime);
					this.elemC.setAttribute('class', 'download');
					this.elemC.appendChild(document.createTextNode(apijs.i18n.translate('downloadLink')));
					this.elemB.appendChild(this.elemC);
				}
		this.elemA.appendChild(this.elemB);
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
	this.htmlVideo = function (url, name, date, legend) {
		var novideo = null, infoVideo = this.updateSize(apijs.config.dialogue.videoWidth, apijs.config.dialogue.videoHeight, url);
		this.elemA = document.createElement('dl');
			this.elemB = document.createElement('dt');
				this.elemC = document.createElement('video');
				this.elemC.setAttribute('src', url);
				this.elemC.setAttribute('width', infoVideo.width);
				this.elemC.setAttribute('height', infoVideo.height);
				this.elemC.setAttribute('controls', 'controls');
				if (apijs.config.dialogue.autoPlay)
					this.elemC.setAttribute('autoplay', 'autoplay');
				if (!apijs.config.navigator || (typeof this.elemC.pause !== 'function')) {
					novideo = new BBcode();
					novideo.init(apijs.i18n.translate('browserNoVideo'));
					novideo.exec();
					this.elemC.appendChild(novideo.getDomFragment());
					this.elemC.style.width = infoVideo.width;
					this.elemC.style.height = infoVideo.height;
				}
			this.elemB.appendChild(this.elemC);
		this.elemA.appendChild(this.elemB);
			this.elemB = document.createElement('dd');
				if ((name !== 'false') || (date !== 'false')) {
					this.elemC = document.createElement('span');
					if ((name !== 'false') && (name !== 'auto') && (date !== 'false'))
						this.elemC.appendChild(document.createTextNode(name + ' (' + date + ')'));
					else if ((name !== 'false') && (name !== 'auto'))
						this.elemC.appendChild(document.createTextNode(name));
					else if ((name === 'auto') && (date !== 'false'))
						this.elemC.appendChild(document.createTextNode(infoVideo.id + ' (' + date + ')'));
					else if (name === 'auto')
						this.elemC.appendChild(document.createTextNode(infoVideo.id));
					else if (date !== 'false')
						this.elemC.appendChild(document.createTextNode('(' + date + ')'));
					this.elemB.appendChild(this.elemC);
				}
				this.elemB.appendChild(document.createTextNode(' ' + legend + ' '));
				if (apijs.config.dialogue.saveVideo) {
					this.elemC = document.createElement('a');
					this.elemC.setAttribute('href', apijs.config.dialogue.fileVideo + '?id=' + infoVideo.id);
					this.elemC.setAttribute('type', infoVideo.mime);
					this.elemC.setAttribute('class', 'download');
					this.elemC.appendChild(document.createTextNode(apijs.i18n.translate('downloadLink')));
					this.elemB.appendChild(this.elemC);
				}
		this.elemA.appendChild(this.elemB);
		this.fragment.firstChild.firstChild.appendChild(this.elemA);
	};
}
function Slideshow() {
	this.media = null;
	this.totals = null;
	this.presentation = null;
	this.init = function () {
		this.media = { album: null, number: null, first: null, prev: null, next: null, last: null };
		this.totals = [];
		this.presentation = [];
		for (var i = 0, j = 0, id = null; document.getElementById(apijs.config.slideshow.ids + '.' + i) !== null; i++) {
			id = apijs.config.slideshow.ids + '.' + i + '.999';
			this.presentation[i] = (document.getElementById(id)) ? 0 : false;
			if (document.getElementById(id)) {
				if (apijs.config.navigator)
					document.getElementById(id).addEventListener('click', apijs.slideshow.showMedia, false);
				else
					document.getElementById(id).setAttribute('onclick', "apijs.slideshow.showMedia(this.getAttribute('id')); return false;");
			}
			for (j = 0; document.getElementById(apijs.config.slideshow.ids + '.' + i + '.' + j) !== null; j++) {
				id = apijs.config.slideshow.ids + '.' + i + '.' + j;
				if (apijs.config.navigator) {
					if (apijs.config.slideshow.hoverload && (this.presentation[i] !== false)) {
						document.getElementById(id).addEventListener('click', apijs.slideshow.showMedia, false);
						document.getElementById(id).addEventListener('mouseover', apijs.slideshow.showMedia, false);
					}
					else {
						document.getElementById(id).addEventListener('click', apijs.slideshow.showMedia, false);
					}
				}
				else {
					if (apijs.config.slideshow.hoverload && (this.presentation[i] !== false)) {
						document.getElementById(id).setAttribute('onclick', "apijs.slideshow.showMedia(this.getAttribute('id')); return false;");
						document.getElementById(id).setAttribute('onmouseover', "apijs.slideshow.showMedia(this.getAttribute('id')); return false;");
					}
					else {
						document.getElementById(id).setAttribute('onclick', "apijs.slideshow.showMedia(this.getAttribute('id')); return false;");
					}
				}
				this.totals[i] = j;
			}
		}
	};
	this.showMedia = function (ev) {
		var thisMedia = { id: null, url: null, alt: null, num: 0, name: null, date: null, legend: null, width: null, height: null }, tmp = null;
		if (typeof ev !== 'string') {
			ev.preventDefault();
			thisMedia.id = this.getAttribute('id');
			thisMedia.url = this.getAttribute('href');
			thisMedia.alt = this.firstChild.getAttribute('alt').split('|');
			tmp = thisMedia.id.split('.');
			thisMedia.album = parseInt(tmp[1], 10);
			thisMedia.number = parseInt(tmp[2], 10);
		}
		else {
			thisMedia.id = ev;
			thisMedia.url = document.getElementById(thisMedia.id).getAttribute('href');
			thisMedia.alt = document.getElementById(thisMedia.id).firstChild.getAttribute('alt').split('|');
			tmp = thisMedia.id.split('.');
			thisMedia.album = parseInt(tmp[1], 10);
			thisMedia.number = parseInt(tmp[2], 10);
		}
		if ((apijs.slideshow.presentation[thisMedia.album] !== false) && ((thisMedia.alt.length > 1) || (thisMedia.alt.length < 7))) {
			if ((typeof ev !== 'string') && this.firstChild.hasAttribute('class') && (this.firstChild.getAttribute('class').indexOf('actif') > -1))
				return;
			if ((apijs.dialogue.dialogType === null) && ((thisMedia.alt.length === 6) || (thisMedia.alt.length === 4)))
				apijs.slideshow.updatePresentation(thisMedia);
			else if ((apijs.dialogue.dialogType === null) && ((thisMedia.alt.length === 5) || (thisMedia.alt.length === 3))) {
				thisMedia.number = apijs.slideshow.presentation[thisMedia.album];
				apijs.slideshow.showDialogue(thisMedia);
			}
			else {
				apijs.slideshow.updatePresentation(thisMedia);
				apijs.slideshow.showDialogue(thisMedia);
			}
		}
		else if ((thisMedia.alt.length === 5) || (thisMedia.alt.length === 3))
			apijs.slideshow.showDialogue(thisMedia);
		else if (apijs.config.debug)
			apijs.dialogue.dialogInformation(apijs.i18n.translate('debugInvalidUse'), '[pre]TheSlideshow » showMedia[br]' + apijs.i18n.translate('debugNotRecognizedAltAttribute') + '[/pre]');
	};
	this.updatePresentation = function (thisMedia) {
		var id = null, tag = null, i = 0;
		if ((thisMedia.alt.length === 6) && (thisMedia.alt[0].length > 0) && (thisMedia.alt[1].length > 0) && (thisMedia.alt[2].length > 0) &&
		 (thisMedia.alt[3].length > 0) && (thisMedia.alt[4].length > 0)) {
			id = apijs.config.slideshow.ids + '.' + thisMedia.album;
			document.getElementById(id + '.999').setAttribute('href', document.getElementById(thisMedia.id).getAttribute('href'));
			document.getElementById(id + '.999').firstChild.setAttribute('src', thisMedia.alt.shift());
			document.getElementById(id + '.999').firstChild.setAttribute('alt', thisMedia.alt.join('|'));
			for (tag = document.getElementById(id).getElementsByTagName('img'), i = 0; i < tag.length; i++) {
				if (tag[i].hasAttribute('class') && (tag[i].getAttribute('class').indexOf('actif') > -1))
					tag[i].removeAttribute('class');
			}
			document.getElementById(thisMedia.id).firstChild.setAttribute('class', 'actif');
			this.presentation[thisMedia.album] = thisMedia.number;
		}
		else if (apijs.config.debug && (thisMedia.alt.length === 6)) {
			apijs.dialogue.dialogInformation(apijs.i18n.translate('debugInvalidAltAttribute'), '[pre]TheSlideshow » changePhoto[br]➩ (string) url : ' + thisMedia.alt[0] + '[br]➩ (number) width : ' + thisMedia.alt[1] + '[br]➩ (number) height : ' + thisMedia.alt[2] + '[br]➩ (string) date : ' + thisMedia.alt[3] + '[br]➩ (string) legend : ' + thisMedia.alt[4] + '[/pre]');
		}
		else if ((thisMedia.alt.length === 4) && (thisMedia.alt[0].length > 0) && (thisMedia.alt[1].length > 0) && (thisMedia.alt[2].length > 0)) {
			id = apijs.config.slideshow.ids + '.' + thisMedia.album;
			document.getElementById(id + '.999').setAttribute('href', document.getElementById(thisMedia.id).getAttribute('href'));
			document.getElementById(id + '.999').firstChild.setAttribute('src', thisMedia.alt.shift());
			document.getElementById(id + '.999').firstChild.setAttribute('alt', thisMedia.alt.join('|'));
			for (tag = document.getElementById(id).getElementsByTagName('img'), i = 0; i < tag.length; i++) {
				if (tag[i].hasAttribute('class') && (tag[i].getAttribute('class').indexOf('actif') > -1))
					tag[i].removeAttribute('class');
			}
			document.getElementById(thisMedia.id).firstChild.setAttribute('class', 'actif');
			this.presentation[thisMedia.album] = thisMedia.number;
		}
		else if (apijs.config.debug && (thisMedia.alt.length === 4)) {
			apijs.dialogue.dialogInformation(apijs.i18n.translate('debugInvalidAltAttribute'), '[pre]TheSlideshow » changePhoto[br]➩ (string) url : ' + thisMedia.alt[0] + '[br]➩ (string) date : ' + thisMedia.alt[1] + '[br]➩ (string) legend : ' + thisMedia.alt[2] + '[/pre]');
		}
	};
	this.showDialogue = function (thisMedia) {
		if ((thisMedia.alt.length === 5) && (thisMedia.alt[0].length > 0) && (thisMedia.alt[1].length > 0) && (thisMedia.alt[2].length > 0) &&
		 (thisMedia.alt[3].length > 0)) {
			thisMedia.name = thisMedia.alt[2];
			thisMedia.date = thisMedia.alt[3];
			thisMedia.legend = thisMedia.alt[4];
			thisMedia.width = parseInt(thisMedia.alt[0], 10);
			thisMedia.height = parseInt(thisMedia.alt[1], 10);
			if (apijs.dialogue.dialogType !== null)
				apijs.dialogue.actionClose(false);
			apijs.dialogue.dialogPhoto(thisMedia.width, thisMedia.height, thisMedia.url, thisMedia.name, thisMedia.date, thisMedia.legend, true);
			this.showNavigation(thisMedia.album, thisMedia.number);
		}
		else if (apijs.config.debug && (thisMedia.alt.length === 5)) {
			apijs.dialogue.dialogInformation(apijs.i18n.translate('debugInvalidAltAttribute'), '[pre]TheSlideshow » showMedia[br]➩ (number) width : ' + thisMedia.alt[0] + '[br]➩ (number) height : ' + thisMedia.alt[1] + '[br]➩ (string) date : ' + thisMedia.alt[2] + '[br]➩ (string) legend : ' + thisMedia.alt[3] + '[/pre]');
		}
		else if ((thisMedia.alt.length === 3) && (thisMedia.alt[0].length > 0) && (thisMedia.alt[1].length > 0)) {
			thisMedia.name = thisMedia.alt[0];
			thisMedia.date = thisMedia.alt[1];
			thisMedia.legend = thisMedia.alt[2];
			if (apijs.dialogue.dialogType !== null)
				apijs.dialogue.actionClose(false);
			apijs.dialogue.dialogVideo(thisMedia.url, thisMedia.name, thisMedia.date, thisMedia.legend, true);
			this.showNavigation(thisMedia.album, thisMedia.number);
		}
		else if (apijs.config.debug && (thisMedia.alt.length === 3)) {
			apijs.dialogue.dialogInformation(apijs.i18n.translate('debugInvalidAltAttribute'), '[pre]TheSlideshow » showMedia[br]➩ (string) date : ' + thisMedia.alt[0] + '[br]➩ (string) legend : ' + thisMedia.alt[1] + '[/pre]');
		}
	};
	this.showNavigation = function (album, number) {
		if ((apijs.dialogue.dialogType.indexOf('photo') > -1) || (apijs.dialogue.dialogType.indexOf('video') > -1)) {
			this.media.album = album;
			this.media.number = number;
			this.media.first = apijs.config.slideshow.ids + '.' + this.media.album + '.0';
			this.media.prev = apijs.config.slideshow.ids + '.' + this.media.album + '.' + (this.media.number - 1);
			this.media.next = apijs.config.slideshow.ids + '.' + this.media.album + '.' + (this.media.number + 1);
			this.media.last = apijs.config.slideshow.ids + '.' + this.media.album + '.' + this.totals[this.media.album];
			if (document.getElementById(this.media.prev))
				document.getElementById('prev').removeAttribute('disabled');
			else
				this.media.prev = null;
			if (document.getElementById(this.media.next))
				document.getElementById('next').removeAttribute('disabled');
			else
				this.media.next = null;
		}
	};
	this.actionFirst = function () {
		if ((this.media !== null) && (this.media.number > 0) && (this.media.number <= this.totals[this.media.album]))
			this.showMedia(this.media.first);
	};
	this.actionPrev = function () {
		if ((this.media !== null) && (this.media.prev !== null) && (this.media.number > 0))
			this.showMedia(this.media.prev);
	};
	this.actionNext = function () {
		if ((this.media !== null) && (this.media.next !== null) && (this.media.number < this.totals[this.media.album]))
			this.showMedia(this.media.next);
	};
	this.actionLast = function () {
		if ((this.media !== null) && (this.media.number >= 0) && (this.media.number < this.totals[this.media.album]))
			this.showMedia(this.media.last);
	};
}
function BBcode() {
	this.bbcode = null;
	this.object = null;
	this.fragment = null;
	this.init = function (data) {
		this.object = { tag: 'div', content: [] };
		this.object['class'] = 'bbcode';
		if (data[0] !== '[')
			this.bbcode = '[p]' + data + '[/p]';
		else
			this.bbcode = data;
	};
	this.exec = function () {
		this.readData(this.bbcode, 0);
		this.fragment = document.createDocumentFragment();
		this.fragment.appendChild(this.createDomFragment(this.object));
	};
	this.readData = function (data, level) {
		var element = null, attributes = null, content = null, text = null, other = null, cut = 0;
		if ((data[0] !== '[') && ((cut = data.search(/\[([a-z1-6]+)(?: [a-z:]+=["'][^"']*["'])*\]/)) > -1)) {
			text = data.slice(0, cut);
			this.readData(text, level);
			other = data.slice(cut);
			if ((cut = other.indexOf('[/' + RegExp.$1 + ']')) > -1) {
				element = other.slice(0, cut + RegExp.$1.length + 3);
				other = other.slice(cut + RegExp.$1.length + 3);
				this.readData(element, level);
			}
			if (/^(\[(?:area|br|col|hr|iframe|img|input|param)(?: [a-z:]+=["'][^"']*["'])*\])/.test(other)) {
				element = other.slice(0, RegExp.$1.length);
				other = other.slice(RegExp.$1.length);
				this.readData(element, level);
			}
			if (other.length > 0)
				this.readData(other, level);
		}
		else if (/^\[(area|br|col|hr|iframe|img|input|param)((?: [a-z:]+=["'][^"']*["'])*)\]/.test(data)) {
			element = RegExp.$1;
			attributes = RegExp.$2;
			other = data.slice(2 + element.length + attributes.length);
			this.addElement(element, attributes, level);
			if (other.length > 0)
				this.readData(other, level);
		}
		else if (/^\[([a-z1-6]+)((?: [a-z:]+=["'][^"']*["'])*)\]/.test(data)) {
			element = RegExp.$1;
			attributes = RegExp.$2;
			cut = data.indexOf('[/' + element + ']');
			content = data.slice(2 + element.length + attributes.length, cut);
			other = data.slice(3 + element.length + cut);
			this.addElement(element, attributes, level);
			this.readData(content, level + 1);
			if (other.length > 0)
				this.readData(other, level);
		}
		else {
			this.addElement(data, null, level);
		}
	};
	this.addElement = function (data, attributes, level) {
		var directlink = null, attr = null, name = null, value = null;
		directlink = this.getContentNode(this.object, 0, level);
		if (attributes !== null) {
			if (directlink.hasOwnProperty('content'))
				directlink.content.push({ tag: data });
			else
				directlink.content = [{ tag: data }];
			if (attributes.length > 5) {
				attributes = attributes.slice(1, -1).split(/["'] /);
				for (attr in attributes) if (attributes.hasOwnProperty(attr)) {
					name = attributes[attr].slice(0, attributes[attr].indexOf('='));
					value = attributes[attr].slice(attributes[attr].indexOf('=') + 2);
					if (directlink.hasOwnProperty('content'))
						directlink.content[directlink.content.length - 1][name] = value;
					else
						directlink[name] = value;
				}
			}
		}
		else {
			if (directlink.hasOwnProperty('content'))
				directlink.content.push({ text: data });
			else
				directlink.content = [{ text: data }];
		}
	};
	this.getContentNode = function (dom, level, maxlevel) {
		if ((dom.content.length < 1) || (maxlevel < 1))
			return dom;
		for (var i = dom.content.length - 1; i >= 0; i--) {
			if (dom.content[i].hasOwnProperty('content') && (++level < maxlevel))
				return this.getContentNode(dom.content[i], level, maxlevel);
			else
				return dom.content[i];
		}
	};
	this.getDomFragment = function () {
		return this.fragment;
	};
	this.createDomFragment = function (data) {
		var tag = null, attr = null, elem = 0;
		if (data.hasOwnProperty('tag'))
			tag = document.createElement(data.tag);
		else
			return document.createTextNode(data.text);
		for (attr in data) if (data.hasOwnProperty(attr)) {
			if (attr === 'text')
				tag.appendChild(document.createTextNode(data[attr]));
			if ((attr !== 'tag') && (attr !== 'text') && (attr !== 'content'))
				tag.setAttribute(attr, data[attr]);
			if ((data.tag === 'a') && (attr === 'class') && (data[attr].indexOf('popup') > -1) && (typeof openTab === 'function')) {
				if (apijs.config.navigator)
					tag.addEventListener('click', openTab, false);
				else
					tag.setAttribute('onclick', 'window.open(this.href); return false;');
			}
		}
		if (data.hasOwnProperty('content')) {
			for (elem = 0; elem < data.content.length; elem++)
				tag.appendChild(this.createDomFragment(data.content[elem]));
		}
		return tag;
	};
}
function Internationalization() {
	this.data = [];
	this.data.de = {
		buttonOk: "Ok",
		buttonCancel: "Abbrechen",
		buttonConfirm: "Bestätigen",
		buttonClose: "Ende",
		buttonPrev: "Previous",
		buttonNext: "Next",
		downloadLink: "Laden",
		operationTooLong: "This operation is too long ? ",
		warningLostChange: "Achtung : alle laufenden änderungen werden verloren.",
		reloadLink: "Seite nochmal laden",
		operationInProgress: "Laufende Aktion...",
		savingInProgress: "Saving...",
		browserNoVideo: "[p]Your browser doesn't support the <video> element.[br]Remember to upgrade your browser.[/p][ul][li][a href='http://www.google.com/chrome?hl=en' class='popup']Chrome 3.0+[/a][/li][li][a href='http://www.mozilla-europe.org/en/firefox/' class='popup']Firefox 3.5+[/a][/li][li][a href='http://www.konqueror.org/' class='popup']Konqueror 4.4+[/a][/li][li][a href='http://www.opera.com/' class='popup']Opera 10.50+[/a][/li][li][a href='http://www.apple.com/safari/' class='popup']Safari 3.1+[/a][/li][/ul]",
		debugInvalidCall: "(debug) Invalid call",
		debugInvalidUse: "(debug) Invalid use",
		debugUnknownAction: "(debug) Unknown action",
		debugKeyDetected: "(debug) Key detected",
		debugKeyCode: "Code of the seizure key : §",
		debugInvalidAltAttribute: "(debug) Invalid alt attribute",
		debugNotRecognizedAltAttribute: "The alt attribute of the image wasn't recognized",
		debugNotExist: "doesn't exist (unlikely error)"
	};
	this.data.en = {
		buttonOk: "Ok",
		buttonCancel: "Cancel",
		buttonConfirm: "Confirm",
		buttonClose: "Close",
		buttonPrev: "Previous",
		buttonNext: "Next",
		downloadLink: "Download",
		operationTooLong: "This operation is too long ? ",
		warningLostChange: "Warning : all changes in progress will be lost.",
		reloadLink: "Reload this page",
		operationInProgress: "Operation in progress...",
		savingInProgress: "Saving...",
		browserNoVideo: "[p]Your browser doesn't support the <video> element.[br]Remember to upgrade your browser.[/p][ul][li][a href='http://www.google.com/chrome?hl=en' class='popup']Chrome 3.0+[/a][/li][li][a href='http://www.mozilla-europe.org/en/firefox/' class='popup']Firefox 3.5+[/a][/li][li][a href='http://www.konqueror.org/' class='popup']Konqueror 4.4+[/a][/li][li][a href='http://www.opera.com/' class='popup']Opera 10.50+[/a][/li][li][a href='http://www.apple.com/safari/' class='popup']Safari 3.1+[/a][/li][/ul]",
		debugInvalidCall: "(debug) Invalid call",
		debugInvalidUse: "(debug) Invalid use",
		debugUnknownAction: "(debug) Unknown action",
		debugKeyDetected: "(debug) Key detected",
		debugKeyCode: "Code of the seizure key : §",
		debugInvalidAltAttribute: "(debug) Invalid alt attribute",
		debugNotRecognizedAltAttribute: "The alt attribute of the image wasn't recognized",
		debugNotExist: "doesn't exist (unlikely error)"
	};
	this.data.fr = {
		buttonOk: "Ok",
		buttonCancel: "Annuler",
		buttonConfirm: "Valider",
		buttonClose: "Fermer",
		buttonPrev: "Précédent",
		buttonNext: "Suivant",
		downloadLink: "Télécharger",
		operationTooLong: "Cette opération prend trop de temps ? ",
		warningLostChange: "Attention : toutes les modifications en cours seront perdues.",
		reloadLink: "Rechargez la page",
		operationInProgress: "Opération en cours...",
		savingInProgress: "Enregistrement en cours...",
		browserNoVideo: "[p]Votre navigateur ne supporte pas l'élément <video>.[br]Pensez à mettre à jour votre navigateur.[/p][ul][li][a href='http://www.google.com/chrome?hl=fr' class='popup']Chrome 3.0+[/a][/li][li][a href='http://www.mozilla-europe.org/fr/firefox/' class='popup']Firefox 3.5+[/a][/li][li][a href='http://www.konqueror.org/' class='popup']Konqueror 4.4+[/a][/li][li][a href='http://www.opera.com/' class='popup']Opera 10.50+[/a][/li][li][a href='http://www.apple.com/fr/safari/' class='popup']Safari 3.1+[/a][/li][/ul]",
		debugInvalidCall: "(debug) Appel invalide",
		debugInvalidUse: "(debug) Utilisation invalide",
		debugUnknownAction: "(debug) Action inconnue",
		debugKeyDetected: "(debug) Touche détectée",
		debugKeyCode: "Code de la touche saisie : §",
		debugInvalidAltAttribute: "(debug) Attribut alt invalide",
		debugNotRecognizedAltAttribute: "L'attribut alt de l'image n'a pas été reconnu",
		debugNotExist: "n'existe pas (erreur improbable)"
	};
	this.init = function () {
		if (apijs.config.autolang) {
			var autolang = null;
			if (document.getElementsByTagName('html')[0].getAttribute('xml:lang'))
				autolang = document.getElementsByTagName('html')[0].getAttribute('xml:lang').slice(0, 2);
			else if (document.getElementsByTagName('html')[0].getAttribute('lang'))
				autolang = document.getElementsByTagName('html')[0].getAttribute('lang').slice(0, 2);
			if ((typeof autolang === 'string') && (autolang in this.data))
				apijs.config.lang = autolang;
			else if ((typeof apijs.config.lang !== 'string') || !(apijs.config.lang in this.data))
				apijs.config.lang = 'en';
		}
		else if ((typeof apijs.config.lang !== 'string') || !(apijs.config.lang in this.data)) {
			apijs.config.lang = 'en';
		}
	};
	this.changeLang = function (lang) {
		if ((typeof lang === 'string') && (lang in this.data)) {
			apijs.config.lang = lang;
			return true;
		}
		else {
			return false;
		}
	};
	this.translate = function (word) {
		if (typeof this.data[apijs.config.lang][word] !== 'string') {
			return word;
		}
		else if (arguments.length > 1) {
			for (var data = this.data[apijs.config.lang][word].split('§'), i = 0, arg = 1, translation = ''; i < data.length; i++) {
				if (arg < arguments.length)
					translation += data[i] + arguments[arg++];
				else
					translation += data[i];
			}
			return translation;
		}
		else {
			return this.data[apijs.config.lang][word];
		}
	};
}
/**
 * Copyright 2010-2011 | Dacrydium
 * (1.2.0) http://www.dacrydium.fr/
 *
 * This program is free software, you can redistribute it or modify
 * it under the terms of the GNU General Public License (GPL) as published
 * by the free software foundation, either version 2 of the license, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but without any warranty, without even the implied warranty of
 * merchantability or fitness for a particular purpose. See the
 * GNU General Public License (GPL) for more details.
 */
var Translator = new Translate({"Please select an option.":"S\u00e9lectionnez une option","This is a required field.":"Ce champ est obligatoire.","Please enter a valid number in this field.":"Veuillez saisir un nombre valide.","Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.":"Seuls les chiffres sont autoris\u00e9s dans ce champ. \u00c9vitez les espaces ou autres caract\u00e8res tels que les points ou les virgules.","Please use letters only (a-z) in this field.":"Veuillez utiliser uniquement des lettres (a-z) dans ce champ.","Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.":"Veuillez utiliser uniquement des lettres (a-z), des chiffres (0-9) ou underscore (_) dans ce champ, en commen\u00e7ant par une lettre.","Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.":"Veuillez utiliser uniquement des lettres (a-z) ou des chiffres (0-9) dans ce champ. Les espaces et autres caract\u00e8res ne sont pas autoris\u00e9s.","Please use only letters (a-z) or numbers (0-9) or spaces and # only in this field.":"Veuillez utiliser uniquement des lettres (a-z), des chiffres (0-9), des espaces ou des di\u00e8ses (#) dans ce champ.","Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.":"Veuillez saisir un num\u00e9ro de t\u00e9l\u00e9phone valide.","Please enter a valid date.":"Veuillez saisir une date valide.","Please enter a valid email address. For example johndoe@domain.com.":"Veuillez saisir une adresse email valide. Par exemple gerard.manvussat@domaine.com","Please enter 6 or more characters.":"Veuillez saisir au moins 6 caract\u00e8res.","Please make sure your passwords match.":"V\u00e9rifiez que vos mots de passe concordent.","Please enter a valid URL. http:\/\/ is required":"Veuillez saisir une URL valide. Elle doit commencer par http:\/\/","Please enter a valid URL. For example http:\/\/www.example.com or www.example.com":"Veuillez saisir une URL valide. Par exemple http:\/\/www.exemple.com ou www.exemple.com","Please enter a valid social security number. For example 123-45-6789.":"Veuillez saisir un num\u00e9ro de s\u00e9curit\u00e9 sociale valide. Par exemple 123-45-6789.","Please enter a valid zip code. For example 90602 or 90602-1234.":"Veuillez saisir un code postal valide. Par exemple 92100.","Please enter a valid zip code.":"Veuillez saisir un code postal valide.","Please use this date format: dd\/mm\/yyyy. For example 17\/03\/2006 for the 17th of March, 2006.":"Veuillez utiliser ce format de date : jj\/mm\/aaaa. Par exemple, 21\/12\/2012 pour le 21 D\u00e9cembre 2012.","Please enter a valid $ amount. For example $100.00.":"Veuillez saisir un montant valide. Par exemple 100.00 \u20ac.","Please select one of the above options.":"Veuillez choisir une des options ci-dessus.","Please select one of the options.":"Veuillez choisir une des options.","Please select State\/Province.":"Veuillez choisir un \u00e9tat\/province.","Please enter valid password.":"Veuillez saisir un mot de passe valide.","Please enter 6 or more characters. Leading or trailing spaces will be ignored.":"Veuillez saisir au moins 6 caract\u00e8res. Les espaces en d\u00e9but ou en fin de cha\u00eene seront ignor\u00e9s.","Please use letters only (a-z or A-Z) in this field.":"Veuillez utiliser uniquement des lettres (a-z ou A-Z) dans ce champ.","Please enter a number greater than 0 in this field.":"Veuillez saisir un nombre sup\u00e9rieur \u00e0 0 dans ce champ.","Please enter a valid credit card number.":"Veuillez saisir un num\u00e9ro de carte bancaire valide.","Please wait, loading...":"Veuillez patienter, chargement en cours...","Please choose to register or to checkout as a guest":"Choisissez de vous enregistrer ou de passer votre commande en tant qu'invit\u00e9","Error: Passwords do not match":"Erreur : les mots de passe sont diff\u00e9rents","Your order cannot be completed at this time as there is no shipping methods available for it. Please make necessary changes in your shipping address.":"Vous ne pouvez pas continuer votre commande car aucun mode de livraison n'est disponible pour votre adresse.","Please specify shipping method.":"Choisissez un mode de livraison.","Your order cannot be completed at this time as there is no payment methods available for it.":"Vous ne pouvez pas continuer votre commande car aucun mode de paiement n'est disponible.","Please specify payment method.":"Choisissez un mode de paiement.","Credit card number doesn't match credit card type":"Le num\u00e9ro de carte ne correspond pas au type de carte.","Card type does not match credit card number":"Le type de carte ne correspond pas au num\u00e9ro de carte.","Please enter a valid credit card verification number.":"Veuillez saisir un num\u00e9ro de v\u00e9rification de carte bancaire valide.","Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.":"Utilisez uniquement des lettres (a-z ou A-Z), des chiffres (0-9) ou des underscores (_) dans ce champ. Le premier caract\u00e8re doit \u00eatre une lettre.","Please input a valid CSS-length. For example 100px or 77pt or 20em or .5ex or 50%":"Veuillez saisir une dimension CSS valide. Par exemple 100px ou 77pt ou 20em ou .5ex ou 50%","Maximum length exceeded.":"D\u00e9passement de la longueur maximum","Your session has been expired, you will be relogged in now.":"Votre session a expir\u00e9, veuillez vous connecter \u00e0 nouveau.","Incorrect credit card expiration date":"Date d'expiration de carte incorrecte","This date is a required value.":"Cette date est obligatoire."});
var apijs = null, genericForm = null;
var prog = { tab: 'Product', friendForm: null };
apijs = {
	i18n: null,
	dialogue: null,
	slideshow: null,
	upload: null,
	config: {
		lang: 'fr',
		debug: false,
		debugkey: false,
		navigator: true,
		transition: true,
		autolang: true,
		dialogue: {
			blocks: [],
			hiddenPage: false,
			savingDialog: false,
			savingTime: 750,
			showLoader: true,
			autoPlay: false,
			savePhoto: false,
			saveVideo: false,
			videoWidth: 640,
			videoHeight: 480,
			imagePrev: null,
			imageNext: null,
			imageClose: { src: 'http://www.curling.fr/skin/frontend/dacrydium/curling/images/dialogue/close.png', width: 60, height: 22 },
			imageUpload: null,
			filePhoto: null,
			fileVideo: null,
			fileUpload: null
		},
		slideshow: {
			ids: 'diaporama',
			hiddenPage: false,
			hoverload: false
		},
		productsList: ['listMen', 'listWomen', 'upsell', 'related', 'crosssell']
	}
};
function number_format(number, decimals, dec_point, thousands_sep) {
	var s, n, prec, sep, dec, toFixedFix;
	s = '';
	n = !isFinite(+number) ? 0 : +number;
	prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
	sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
	dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
	toFixedFix = function (n, prec) {
		var k = Math.pow(10, prec);
		return '' + Math.round(n * k) / k;
	};
	s = ((prec) ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
	if (s[0].length > 3)
		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	}
	return s.join(dec);
}
if ((navigator.userAgent.indexOf('MSIE') < 0) || (navigator.userAgent.indexOf('MSIE 9') > -1)) {
	window.addEventListener('load', start, false);
}
else if (navigator.userAgent.indexOf('MSIE 8') > -1) {
	apijs.config.navigator = false;
	apijs.config.transition = false;
	document.createElement('video');
	window.innerWidth = document.documentElement.clientWidth;
	window.innerHeight = document.documentElement.clientHeight;
	window.attachEvent('onload', start);
}
else {
	window.attachEvent('onload', function () {
		if (document.getElementById('theProduct') || ((apijs.config.productsList.length > 0) && document.getElementById(apijs.config.productsList[0]))) {
			for (var tag = document.getElementById('goTab').getElementsByTagName('button'), i = 0; i < document.getElementById('goTab').getElementsByTagName('button').length; i++)
				Event.observe(tag[i], 'click', showTabIE);
			if (document.getElementById('goSize2'))
				Event.observe(document.getElementById('goSize2'), 'click', showTabIE);
		}
	});
}
function start() {
	for (var tag = document.getElementsByTagName('a'), i = 0; i < tag.length; i++) {
		if (apijs.config.navigator && tag[i].hasAttribute('class') && (tag[i].getAttribute('class').indexOf('popup') > -1))
			tag[i].addEventListener('click', openTab, false);
		else if (tag[i].hasAttribute('class') && (tag[i].getAttribute('class').indexOf('popup') > -1))
			tag[i].setAttribute('onclick', 'window.open(this.href); return false;');
	}
	if ((typeof Internationalization === 'function') && (typeof BBcode === 'function') && (typeof Dialogue === 'function') && (typeof Slideshow === 'function')) {
		if ((typeof document.getElementsByTagName('body')[0].style.transitionDuration !== 'string') &&
		 (typeof document.getElementsByTagName('body')[0].style.MozTransitionDuration !== 'string') &&
		 (typeof document.getElementsByTagName('body')[0].style.webkitTransitionDuration !== 'string')) {
			apijs.config.transition = false;
		}
		if (apijs.config.navigator || (navigator.userAgent.indexOf('MSIE 8') > -1)) {
			try {
				apijs.i18n = new Internationalization();
				apijs.i18n.init();
				apijs.dialogue = new Dialogue();
				if (document.getElementById('diaporama.0'))
					apijs.slideshow = new Slideshow();
					apijs.slideshow.init();
			}
			catch (e) { }
		}
	}
	if (document.getElementById('genericForm'))
		genericForm = new VarienForm('genericForm');
	if (document.getElementById('theProduct') || ((apijs.config.productsList.length > 0) && document.getElementById(apijs.config.productsList[0])))
		initProduct();
	if (document.getElementById('formLogin') || document.getElementById('formSearch') || document.getElementById('formNewsletter'))
		initForms();
	if ((document.getElementsByClassName('deleteAddress').length > 0) || (document.getElementsByClassName('deleteProduct').length > 0))
		initConfirms();
	if (document.getElementsByClassName('focus').length > 0)
		document.getElementsByClassName('focus')[0].focus();
	if (document.getElementById('friend') && (apijs.config.navigator || (navigator.userAgent.indexOf('MSIE 8') > -1))) {
		Event.observe(document.getElementById('friend'), 'click', function (ev) {
			apijs.dialogue.dialogFormOptions('Envoyer à un ami', document.getElementById('friendInput').getAttribute('value'), checkFormFriend, null, document.getElementById('friendAction').getAttribute('value'), 'friend');
			document.getElementById('box').getElementsByTagName('input')[0].focus();
			Event.stop(ev);
		});
	}
}
function checkFormFriend() {
	if (prog.friendForm === null)
		prog.friendForm = new VarienForm('box');
	return prog.friendForm.validator.validate();
}
function openTab(ev) {
	ev.preventDefault();
	window.open(this.href);
}
function initForms() {
	apijs.i18n.data.de['formLogin'] = "Identifiant";
	apijs.i18n.data.de['formSearch'] = "Search";
	apijs.i18n.data.de['formMail'] = "Email address";
	apijs.i18n.data.de['confirmNewsletter'] = "En vous abonnant à la newsletter vous acceptez les [a href='http://www.curling.fr/cgu.html' class='popup nostyle']conditions générales d'utilisations[/a].";
	apijs.i18n.data.en['formLogin'] = "Identifiant";
	apijs.i18n.data.en['formSearch'] = "Search";
	apijs.i18n.data.en['formMail'] = "Email address";
	apijs.i18n.data.en['confirmNewsletter'] = "En vous abonnant à la newsletter vous acceptez les [a href='http://www.curling.fr/cgu.html' class='popup nostyle']conditions générales d'utilisations[/a].";
	apijs.i18n.data.fr['formLogin'] = "Identifiant";
	apijs.i18n.data.fr['formSearch'] = "Rechercher";
	apijs.i18n.data.fr['formMail'] = "Adresse email";
	apijs.i18n.data.fr['confirmNewsletter'] = "En vous abonnant à la newsletter vous acceptez les [a href='http://www.curling.fr/cgu.html' class='popup nostyle']conditions générales d'utilisations[/a].";
	if (document.getElementById('formLoginNANA')) {
		if ((document.getElementById('loginUsername').value.length < 1) || (document.getElementById('loginPassword').value.length < 1)) {
			document.getElementById('loginUsername').value = apijs.i18n.translate('formLogin');
			document.getElementById('loginPassword').value = '******';
		}
		Event.observe(document.getElementById('formLogin'), 'submit', function (ev) {
			if (document.getElementById('loginUsername').value === apijs.i18n.translate('formLogin')) {
				Event.stop(ev);
				document.getElementById('loginUsername').focus();
			}
		});
		Event.observe(document.getElementById('loginUsername'), 'focus', function () {
			if (document.getElementById('loginUsername').value === apijs.i18n.translate('formLogin'))
				document.getElementById('loginUsername').value = '';
		});
		Event.observe(document.getElementById('loginPassword'), 'focus', function () {
			if (document.getElementById('loginPassword').value === '******')
				document.getElementById('loginPassword').value = '';
		});
		Event.observe(document.getElementById('loginUsername'), 'blur', function () {
			if (document.getElementById('loginUsername').value.length < 1) {
				document.getElementById('loginUsername').value = apijs.i18n.translate('formLogin');
				document.getElementById('loginPassword').value = '******';
			}
		});
		Event.observe(document.getElementById('loginPassword'), 'blur', function () {
			if (document.getElementById('loginPassword').value.length < 1)
				document.getElementById('loginPassword').value = '******';
		});
	}
	if (document.getElementById('formSearchNANA')) {
		if (document.getElementById('searchText').value.length < 1)
			document.getElementById('searchText').value = apijs.i18n.translate('formSearch');
		Event.observe(document.getElementById('formSearch'), 'submit', function (ev) {
			if (document.getElementById('searchText').value === apijs.i18n.translate('formSearch')) {
				Event.stop(ev);
				document.getElementById('searchText').focus();
			}
		});
		Event.observe(document.getElementById('searchText'), 'focus', function () {
			if (document.getElementById('searchText').value === apijs.i18n.translate('formSearch'))
				document.getElementById('searchText').value = '';
		});
		Event.observe(document.getElementById('searchText'), 'blur', function () {
			if (document.getElementById('searchText').value.length < 1)
				document.getElementById('searchText').value = apijs.i18n.translate('formSearch');
		});
	}
	if (document.getElementById('formNewsletter')) {
		Event.observe(document.getElementById('formNewsletter'), 'submit', function (ev) {
			Event.stop(ev);
			if (document.getElementById('newsletterMail').value === apijs.i18n.translate('formMail'))
				document.getElementById('newsletterMail').focus();
			else if (document.getElementById('newsletterMail').value.length > 0)
				apijs.dialogue.dialogConfirmation('Newsletter', apijs.i18n.translate('confirmNewsletter'), confirmNewsletter, null, this.getAttribute('href'));
		});
	}
}
function confirmNewsletter() {
	document.getElementById('formNewsletter').submit();
}
function initConfirms() {
	apijs.i18n.data.de['titleDelete'] = "Abbau";
	apijs.i18n.data.de['deleteProduct'] = "Sind Sie sicher, dass Sie dieses Produkt löschen möchten ?[br]Achtung, diese Aktion ist nicht rückgängig";
	apijs.i18n.data.de['deleteAddress'] = "Sind Sie sicher, dass Sie diese Anschrift löschen möchten ?[br]Achtung, diese Aktion ist nicht rückgängig";
	apijs.i18n.data.en['titleDelete'] = "Deleting";
	apijs.i18n.data.en['deleteProduct'] = "Are you sure you want to delete this article ?[br]Be careful, you can't cancel this operation.";
	apijs.i18n.data.en['deleteAddress'] = "Are you sure you want to delete this address ?[br]Be careful, you can't cancel this operation.";
	apijs.i18n.data.fr['titleDelete'] = "Suppression";
	apijs.i18n.data.fr['deleteProduct'] = "Êtes-vous certain(e) de vouloir supprimer cet article ?[br]Attention, cette opération n'est pas annulable.";
	apijs.i18n.data.fr['deleteAddress'] = "Êtes-vous certain(e) de vouloir supprimer cette adresse ?[br]Attention, cette opération n'est pas annulable.";
	for (tag = document.getElementsByClassName('deleteProduct'), i = 0; i < tag.length; i++) {
		Event.observe(tag[i], 'click', function (ev) {
			Event.stop(ev);
			apijs.dialogue.dialogConfirmation(apijs.i18n.translate('titleDelete'), apijs.i18n.translate('deleteProduct'), deleteProduct, this.getAttribute('id'));
		});
	}
	for (tag = document.getElementsByClassName('deleteAddress'), i = 0; i < tag.length; i++) {
		Event.observe(tag[i], 'click', function (ev) {
			Event.stop(ev);
			apijs.dialogue.dialogConfirmation(apijs.i18n.translate('titleDelete'), apijs.i18n.translate('deleteAddress'), deleteAddress, this.getAttribute('id'));
		});
	}
}
function deleteProduct(id) {
	location.href = document.getElementById(id).getAttribute('href');
}
function deleteAddress(id) {
	location.href = document.getElementById(id).getAttribute('href');
}
function initProduct() {
	if (document.getElementById('theProduct'))
		genericForm = new VarienForm('theProduct');
	if (document.getElementById('quantityLess') && document.getElementById('quantityMore')) {
		document.getElementById('quantityLess').removeAttribute('class');
		document.getElementById('quantityMore').removeAttribute('class');
		document.getElementById('quantityMore').removeAttribute('disabled');
		Event.observe(document.getElementById('quantityLess'), 'click', updateQuantityProduct);
		Event.observe(document.getElementById('quantityMore'), 'click', updateQuantityProduct);
		if (document.getElementById('initialPrice'))
			updatePriceProduct();
	}
	if (document.getElementById('goTab')) {
		for (var tag = document.getElementById('goTab').getElementsByTagName('button'), i = 0; i < document.getElementById('goTab').getElementsByTagName('button').length; i++)
			Event.observe(tag[i], 'click', showTab);
		if (document.getElementById('goSize2'))
			Event.observe(document.getElementById('goSize2'), 'click', showTab);
	}
	for (var id in apijs.config.productsList) if (apijs.config.productsList.hasOwnProperty(id)) {
		id = apijs.config.productsList[id];
		if (document.getElementById(id) && (document.getElementById(id).getElementsByTagName('li').length > document.getElementById(id + 'Show').value)) {
			document.getElementById(id + 'Prev').setAttribute('class', 'prev');
			document.getElementById(id + 'Next').setAttribute('class', 'next');
			document.getElementById(id + 'Next').removeAttribute('disabled');
			Event.observe(document.getElementById(id + 'Prev'), 'click', listPrev);
			Event.observe(document.getElementById(id + 'Next'), 'click', listNext);
		}
	}
}
function updateQuantityProduct() {
	var i = parseInt(document.getElementById('quantity').value, 10);
	if (isNaN(i) || (i < 1))
		document.getElementById('quantity').value = '1';
	else if ((this.getAttribute('id') === 'quantityLess') && (i > 1))
		document.getElementById('quantity').value = i - 1;
	else if ((this.getAttribute('id') === 'quantityMore') && (i < 99))
		document.getElementById('quantity').value = i + 1;
	updatePriceProduct();
}
function listNext() {
	var id = null, show = 0, offset = 0;
	id = this.getAttribute('id').slice(0, -4);
	show = parseInt(document.getElementById(id + 'Show').value, 10);
	offset = parseInt(document.getElementById(id + 'Offset').value, 10);
	document.getElementById(id).getElementsByTagName('li')[offset].setAttribute('class', 'nodisplay');
	document.getElementById(id).getElementsByTagName('li')[show + offset].removeAttribute('class');
	offset++;
	if (document.getElementById(id + 'Prev').hasAttribute('disabled'))
		document.getElementById(id + 'Prev').removeAttribute('disabled');
	if ((show + offset) >= document.getElementById(id).getElementsByTagName('li').length)
		document.getElementById(id + 'Next').setAttribute('disabled', 'disabled');
	document.getElementById(id + 'Offset').value = offset;
}
function listPrev() {
	var id = null, show = 0, offset = 0;
	id = this.getAttribute('id').slice(0, -4);
	show = parseInt(document.getElementById(id + 'Show').value, 10);
	offset = parseInt(document.getElementById(id + 'Offset').value, 10) - 1;
	if (document.getElementById(id + 'Next').hasAttribute('disabled'))
		document.getElementById(id + 'Next').removeAttribute('disabled');
	document.getElementById(id).getElementsByTagName('li')[offset].removeAttribute('class');
	document.getElementById(id).getElementsByTagName('li')[show + offset].setAttribute('class', 'nodisplay');
	if (offset < 1)
		document.getElementById(id + 'Prev').setAttribute('disabled', 'disabled');
	document.getElementById(id + 'Offset').value = offset;
}
function showTab() {
	document.getElementById('go' + prog.tab).removeAttribute('class');
	document.getElementById('tab' + prog.tab).setAttribute('class', 'nodisplay');
	prog.tab = (this.getAttribute('id') !== 'goSize2') ? this.getAttribute('id').slice(2) : 'Size';
	document.getElementById('go' + prog.tab).setAttribute('class', 'actif');
	document.getElementById('tab' + prog.tab).setAttribute('class', 'tab');
}
function showTabIE() {
	document.getElementById('go' + prog.tab).className = '';
	document.getElementById('tab' + prog.tab).className = 'nodisplay';
	prog.tab = (this.getAttribute('id') !== 'goSize2') ? this.getAttribute('id').slice(2) : 'Size';
	document.getElementById('go' + prog.tab).className = 'actif';
	document.getElementById('tab' + prog.tab).className = 'tab';
}
function updatePriceProduct() {
	var i = 0, unitPrice = 0, totalPrice = 0, price = 0, index = 0;
	i = parseInt(document.getElementById('quantity').value, 10);
	if (document.getElementById('initialPrice').getAttribute('value').match(/^[0-9]/)) {
		price = document.getElementById('initialPrice').getAttribute('value').replace(/(\u00a0)|(\u2009)/, '|');
		unitPrice = price.slice(0, price.lastIndexOf('|'));
		totalPrice = parseFloat(unitPrice.replace(',', '.'), 10) * parseFloat(document.getElementById('quantity').value, 10);
		totalPrice = number_format(totalPrice, 2, ',', '\u2009') + '\u00a0' + price.slice((price.lastIndexOf('|') + 1));
	}
	else {
		index = document.getElementById('initialPrice').getAttribute('value').search(/[0-9]/);
		price = document.getElementById('initialPrice').getAttribute('value').slice(0, index) + '|' + document.getElementById('initialPrice').getAttribute('value').slice(index);
		unitPrice = price.slice(price.lastIndexOf('|') + 1);
		totalPrice = parseFloat(unitPrice.replace(',', '.'), 10) * parseFloat(document.getElementById('quantity').value, 10);
		totalPrice = price.slice(0, price.lastIndexOf('|')) + '\u2009' + number_format(totalPrice, 2, ',', '\u2009');
	}
	document.getElementById('finalPrice').firstChild.replaceData(0, document.getElementById('finalPrice').firstChild.data.length, totalPrice);
}

