// Author : SOMARE Ludovic
// Copyright : SOMARE Ludovic @ 2009

/**********************************************************************************************/
/*****************************************CONSTANTS********************************************/
/**********************************************************************************************/
var _moz, _moz2, _moz3, _ie, _ie6, _ie7, _ie8, timer, scrollYSave;
_moz = _moz2 = _moz3 = _ie = _ie6 = _ie7 = _ie8 = timer = false;

if (navigator.appName == "Netscape") _moz = true;
else _ie = true;

if (navigator.userAgent.substr(navigator.userAgent.lastIndexOf("/") + 1, 1) == "2") _moz2 = true;
else if (navigator.userAgent.substr(navigator.userAgent.lastIndexOf("/") + 1, 1) == "3") _moz3 = true;
else if (navigator.appVersion.substring(17,23) == "MSIE 6") _ie6 = true;
else if (navigator.appVersion.substring(17,23) == "MSIE 7") _ie7 = true;
else if (navigator.appVersion.substring(17,23) == "MSIE 8") _ie8 = true;


/**********************************************************************************************/
/**************************************APILLCATIONS********************************************/
/**********************************************************************************************/
var objGlobalContainer = document.getElementById('globalContainer');
var objAppliContainer = document.getElementById('appliContainer');
var objAppliContainerContent = document.getElementById('appliContainerContent');
var objAppliContainerContentChamp = document.getElementById('appliContainerContentChamp');
var objChampSelectorContainer = document.getElementById('champSelectorContainer');
var objChampSelectorUl = document.getElementById('champMenu');
var objChampSelectorTop = false;
var objChampSelectorLeft = false;

function initXsls() {
	//Pos mouse
	document.onmousemove = PosMouse;
	
	//Bug placement global container (margin auto) mal interpreté ... ... ... ... ...
	refreshSizeSreen();
	if (_ie) objGlobalContainer.style.margin += "0 0 0 " + (((clientWidth - (objGlobalContainer.offsetWidth)) / 2) + 1) + "px";
	else if (_moz2) objGlobalContainer.style.width = "998px";
	
	//Init connection
	initConnection();
	
	//Init appli
	initAppli();
	
	//Init champ selector
	if (configChamp == "multi") initChampSelector();
	
	//Init menu
	initMenu();
	
	//window Resize update
	window.onresize = function () {
		//IE (de merde)
		if (_ie) {
			//window.open("index.php?p=" + currentPage, "_parent"); //Ie refresh tout le temps !?!
			return false;
		
		//OTHER
		} else {
			initXsls();
			
			if (galleryStatus) openGallery(arrayGalleryGlobal);
			if (galleryData) initDiapo();
			if (globalMaskStatus) openMask();
		}
	}
	
	return true;
}

//Init appli
function initAppli() {
	//Si e6
	if (_ie6) {
		objAppliContainer.style.display = "none";
		
		openAlert('alertContainerError', 'PROBLEME NAVIGUATEUR', 'Les applications Xsls sont désactivées car votre naviguateur ne les supportes pas !<br /><br />Merci de mettre a jour votre Microsoft Internet Exploreur en version 7 minimun.');
		return false;
	}
	
	//Init help DOM var
	refreshSizeSreen();
	
	//Init appli
	objAppliContainer.style.width = (clientWidth-60) + "px";
	objAppliContainerContent.style.width = (clientWidth-86-60) + "px"; //86 = start + end div width
	objAppliContainer.style.marginLeft = "30px";
	objAppliContainer.style.opacity = 0.85;
	objAlertContainer.style.filter = 'alpha(opacity=85)';
	objAlertContainer.style.position = "fixed";
	objAppliContainer.style.display = "block";
	
	//Config
	if (document.getElementById('appliContainerConfigButton') != null) {
		//Init config
		initConfig();
		
		//init Button config
		document.getElementById('appliContainerConfigButton').onclick = function () { openConfig(this); }
	}
	
	//Chat
	if (document.getElementById('appliContainerChatButton') != null) {
		//Init chat
		initChat();
		
		//init Button chat
		document.getElementById('appliContainerChatButton').onclick = function () {
			//Launch chat
			openChat(this);
			launchChat();
		}
	}
	
	//Gallery
	if (document.getElementById('appliContainerGalleryButton') != null) {		
		//init Button gallery (Button, step)
		document.getElementById('appliContainerGalleryButton').onclick = function () { initGallery(this, false); }
	}
	
	//Movie
	if (document.getElementById('appliContainerMovieButton') != null) {
		//Init movie
		initMovie();
		
		//init Button movie
		document.getElementById('appliContainerMovieButton').onclick = function () { openMovie(this); }
	}
}

//masques les appli
function resetAppli() {
	document.getElementById('configContainer').style.display = "none";
	document.getElementById('chatContainer').style.display = "none";
	document.getElementById('movieContainer').style.display = "none";
	document.getElementById('moviePlayerContainer').style.display = "none";
}

//Init champ selector
function initChampSelector() {
	//Init popup selection champ
	objAppliContainerContentChamp.onmouseover = function () {
		refreshSizeSreen();
		
		objChampSelectorContainer.style.opacity = 0.85;
		objChampSelectorContainer.style.filter = 'alpha(opacity=85)';
		objChampSelectorTop = getOffsetTop(objAppliContainerContentChamp) + 23; //(objAppliContainerContentChamp.offsetHeight)
		objChampSelectorLeft = getOffsetLeft(objAppliContainerContentChamp) + 3;
		
		objChampSelectorContainer.style.left = objChampSelectorLeft + "px";
		objChampSelectorContainer.style.top = objChampSelectorTop + "px";
		objChampSelectorContainer.style.display = "block";
	}
	
	objChampSelectorContainer.onmouseout = function () {
		refreshSizeSreen();
		
		var exitSelector = false;
		
		//test X
		if (Mouse_X < (objChampSelectorLeft + 5) || Mouse_X > ((objChampSelectorLeft + objChampSelectorContainer.offsetWidth) - 10)) exitSelector = true;
		//text Y
		if ((Mouse_Y - scrollY) > ((objChampSelectorTop + objChampSelectorContainer.offsetHeight) - 10)) exitSelector = true;
		
		if (exitSelector) {
			objChampSelectorContainer.style.display = "none";
			objChampSelectorContainer.style.left = "0px";
			objChampSelectorContainer.style.top = "50px";
		}
	}
}


/**********************************************************************************************/
/******************************************MASK************************************************/
/**********************************************************************************************/
var objGlobalMask = document.getElementById('globalMask');
var globalMaskStatus = false;

//open mask
function openMask(bgLink) {
	refreshSizeSreen();
	
	globalMaskStatus = true;
	
	//document.body.style.overflow='hidden';
	objGlobalMask.style.height = clientHeight + "px";
	objGlobalMask.style.opacity = 0.7;
	objGlobalMask.style.filter = 'alpha(opacity=70)';
	
	if (bgLink) objGlobalMask.style.backgroundImage = 'url('+  bgLink + ')';
	
	
	objGlobalMask.style.display = "block";
	
	objGlobalMask.onclick = function () { closeGallery(); }
}

function closeMask() {
	objGlobalMask.style.display = "none";
	globalMaskStatus = false;
}


/**********************************************************************************************/
/******************************************CONFIG**********************************************/
/**********************************************************************************************/
function initConfig() {
	//Init les radio
	array = new Array('autoConnectYes', 'autoConnectNo');
	arraySub = new Array('autoConnect(this)', 'autoConnect(this)');
	initRadio(array, arraySub);
	
	//Init button form
	array = new Array('ConfigUserSave');
	arraySub = new Array(); 
	arraySub[0] = new Array('saveConfig(); closeConfig();');
	initButton(array, arraySub);
	
	//Init button
	document.getElementById('configButton').onclick = function () { closeConfig(); }
	
	//Init current conf
	if (getCookie(prefXsls + "_xslsAutoConnect")) autoConnect(document.getElementById('autoConnectYes'));
	if (getCookie(prefXsls + "_xslsDefaultChamp")) document.getElementById('configDefaultChamp').value = getCookie(prefXsls + "_xslsDefaultChamp");
}

function openConfig(e) {
	refreshSizeSreen();
	var top, left;
	var eConfig = document.getElementById('configContainer');
	
	resetAppli();
	
	eConfig.style.opacity = 0.95;
	eConfig.style.filter = 'alpha(opacity=95)';
	top = 1;
	left = getOffsetLeft(e) + 1;
	
	eConfig.style.left = left + "px";
	eConfig.style.top = top + "px";
	eConfig.style.display = "block";
	
	configStatus = true;
}

function closeConfig() {
	document.getElementById('configContainer').style.display = "none";
	
	configStatus = false;
}

function saveConfig() {
	//Suppresion old cookie
	delCookie(prefXsls + "_xslsDefaultChamp");
	
	setCookie(prefXsls + "_xslsDefaultChamp", document.getElementById('configDefaultChamp').value, 365);
	
	if (document.getElementById('autoConnect').value == 1) getCookieAutoConnect(0);
	else getCookieAutoConnect(1); //Supp cookie _xslsAutoConnect ne fonctionne pas ?!?!?!?!?
	
	openAlert('alertContainerValid', 'CONFIGURATION SAUVEGARDEE', 'Votre configuration a été sauvegardée avec succés !<br /><br /><br />Xsls');
}

function getCookieAutoConnect(delCookie) {
	xhr_object = initXhrObj();
	
	data = "action=autoConnect&delCookie=" + delCookie; 
	xhr_object.open("POST", "php/XMLHttpRequest.php?" + data, true);
	
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState == 4) return true;
	}
		
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xhr_object.send(data);
}


/**********************************************************************************************/
/*******************************************CHAT***********************************************/
/**********************************************************************************************/
//Init chat
function initChat() {
	var array, arraySub;
	
	//Init les elem ayant un bg perso
	array = new Array('ChatWrite');
	initInputOver(array);
	
	//Init select
	array = new Array('chatColor');
	arraySub = new Array(); 
	arraySub[0] = new Array('selectChatColor(this)', false); //[onChange, onClick]
	initSelect(array, arraySub);
	
	//Auto selection suivant cookie color
	document.getElementById('chatColor').value = getCookie(prefXsls + "_xslsColorChat");
	selectChatColor(e);
	
	//Init button
	document.getElementById('chatButton').onclick = function () { closeChat(); }
	
	//Init button form
	document.getElementById('chatForm').action = "javascript:checkFormInsertLineChat();";
	document.getElementById('chatSendContainer').onclick = function () { checkFormInsertLineChat(); }
	
	launchChat();
}

function checkFormInsertLineChat() {
	arrayFormCheck = new Array('ChatWrite');
	arrayFormOptionCheck = new Array();
	arrayFormOptionCheck[0] = new Array('noEmpty');
	
	if (!getCheckForm()) chatInsertLine();
}

function selectChatColor(e) {
	if (e.value != "") e.style.backgroundColor = "#" + e.value;
	
	//Set cookie color
	delCookie(prefXsls + "_xslsColorChat");
	setCookie(prefXsls + "_xslsColorChat", e.value, 365);
}

//Launch chat
function launchChat() {	
	//Update chat content (numUser/userList/data)
	upadteChat();
	
	setTimeout("launchChat()", 7000);
}

//Lancement update
function upadteChat() {
	xhr_object = initXhrObj();
	
	data = "action=countUserLoged"; 
	xhr_object.open("POST", "php/XMLHttpRequest.php?" + data, true);
	
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState == 4) {
			document.getElementById('chatCountUser').innerHTML = xhr_object.responseText;
			
			//USER LIST
			userLoged();
		}
	}
		
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xhr_object.send(data);
}

//Utilisateur connécté
function userLoged() {
	xhr_object = initXhrObj();
	
	data = "action=userLoged"; 
	xhr_object.open("POST", "php/XMLHttpRequest.php?" + data, true);
	
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState == 4) {
			document.getElementById('usersData').innerHTML = xhr_object.responseText;
			
			//CHAT DATA
			chatData();
		}
	}
		
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xhr_object.send(data);
}

//Chat data
function chatData() {
	xhr_object = initXhrObj();
	
	data = "action=chatData";
	xhr_object.open("POST", "php/XMLHttpRequest.php?" + data, true);
	
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState == 4) {
			document.getElementById('chatData').innerHTML = xhr_object.responseText;
			document.getElementById('chatData').scrollTop = 100000000;
		}
	}
		
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xhr_object.send(data);
}

//Chat data
function chatInsertLine() {
	var data;
	xhr_object = initXhrObj();
	
	data = document.getElementById('ChatWrite').value;
	
	//$dataTxt, $user, $color
	data = "action=insertData&data=" + data + "&color=" + document.getElementById('chatColor').value;
	xhr_object.open("POST", "php/XMLHttpRequest.php?" + data, true);
	
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState == 4) {
			chatData();
			document.getElementById('ChatWrite').value = "";
		}
	}
		
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xhr_object.send(data);
}

function forHim(name) {
	document.getElementById('ChatWrite').value = name + " > ";
}

//Open chat
function openChat(e) {
	refreshSizeSreen();
	var top, left;
	var eChat = document.getElementById('chatContainer');
	
	resetAppli();
	
	eChat.style.opacity = 0.95;
	eChat.style.filter = 'alpha(opacity=95)';
	top = 1;
	left = getOffsetLeft(e) + 1;
	
	eChat.style.left = left + "px";
	eChat.style.top = top + "px";
	eChat.style.display = "block";
	
	chatStatus = true;
}

//Ferme le chat
function closeChat() {
	var eChat = document.getElementById('chatContainer');
	eChat.style.display = "none";
	
	chatStatus = false;
}


/**********************************************************************************************/
/****************************************GALLERY***********************************************/
/**********************************************************************************************/
var objGalleryZoomIcon = document.getElementById('galleryZoomIcon');
var objGalleryZoomIconTxt = document.getElementById('galleryZoomIconTxt');
var objGalleryContainer = document.getElementById('galleryContainer');
var objGalleryButtonClose = document.getElementById('galleryButtonClose');
var objGallerySmallImgPrev = document.getElementById('gallerySmallImgPrev');
var objGallerySmallImgContentScroll = document.getElementById('gallerySmallImgContentScroll');
var objGallerySmallImgContent = document.getElementById('gallerySmallImgContent');
var objGallerySmallImgNext = document.getElementById('gallerySmallImgNext');
var objGalleryCategTxt = document.getElementById('galleryCategTxt');
var objGalleryImgContainer = document.getElementById('galleryImgContainer');
var objGalleryImg = document.getElementById('galleryImg');
var objGalleryImgInfoTxt = document.getElementById('galleryImgInfoTxt');

var arrayGalleryGlobal, arrayGalleryCateg, galleryCurrentLine, galleryCurrentCateg, galleryMaxLine, galleryNumSmallByLine, galleryCurrentMoveLigne, galleryCurrentZoom;
arrayGalleryCateg = new Array();

//Init gallery
function initGallery(e, step) {
	resetAppli(); //Close all appli
	openMask('images/appli_gallery_mask_bg.gif'); //Open mask avec bg gallery
	openLoading(); //Open loading
				
	//Get array folder / img
	xhr_object = initXhrObj();
	
	data = "action=getGalleryArray";
	xhr_object.open("POST", "php/XMLHttpRequest.php?" + data, true);
	
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState == 4) {	
			//alert(xhr_object.responseText);
			eval(xhr_object.responseText);
			arrayGalleryGlobal = arrayGallery;
			
			if (!galleryError) {
				//alert(arrayGallery.length);
				openGallery(arrayGallery); //Open gallery
			
			} else {
				if (galleryErro == 'error') openAlert('alertContainerError', 'INITIALISATION XSLS GALLERY', 'Une erreur est survenue pendant l\'initialisation de la Xsls gallery !<br /><br /><br />Xsls');
				else if (galleryErro == 'empty') openAlert('alertContainerAvert', 'XSLS GALLERY', 'Aucune image n\'est disponbile pour le moment !<br /><br /><br />Xsls');
			}
		}
	}
		
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
	xhr_object.send(data);
}

//Open gallery
function openGallery(arrayGallery) {
	var imgGenerated = "";
	galleryStatus = true;
	
	refreshSizeSreen();
	
	//Nombre approx d'image par ligne
	galleryNumSmallByLine = Math.floor((clientWidth - 200) / 150);
	
	//Nombre de ligne dans le container small
	galleryMaxLine = Math.ceil(arrayGallery.length / galleryNumSmallByLine);
	
	//Categ reset
	objGalleryCategTxt.innerHTML = "";
	galleryCurrentCateg = false;
	galleryCurrentMoveLigne = false;
	galleryCurrentZoom = 0;
	
	//Gallery global container
	objGalleryContainer.style.opacity = 1;
	objGalleryContainer.style.filter = 'alpha(opacity=100)';
	objGalleryContainer.style.width = (clientWidth - 150) + 'px';
	objGalleryContainer.style.height = (clientHeight - 150) + "px";
	objGalleryContainer.style.margin = '75px 0px 0px 75px';
	
	//Small img contaienr
	objGallerySmallImgContent.style.width  = (clientWidth - 200) + 'px';
	objGallerySmallImgContent.style.height = (galleryMaxLine * 103) + 'px';
	
	//Img container
	objGalleryImgContainer.style.height  = (clientHeight - 331) + 'px';
	
	//Close button
	objGalleryButtonClose.onclick = function () { closeGallery(); }
	
	//Top button
	objGallerySmallImgPrev.onclick = function () {
		if (!galleryCurrentMoveLigne) {
			var val = objGallerySmallImgContentScroll.scrollTop - 102;
			
			if (val >= 0) {
				moveGallery(val);
				galleryCurrentLine--;
			}
		}
	}
	
	//Bottom button
	objGallerySmallImgNext.onclick = function () {
		if (galleryCurrentLine + 1 <= galleryMaxLine && !galleryCurrentMoveLigne) {
			galleryCurrentLine++;
			var val = objGallerySmallImgContentScroll.scrollTop + 102;
			
			moveGallery(val);
		}
	}
	
	//Ecrit suivant le filter categ les img dans le small container
	getImgForGallery();
	
	//Ecrit la selection catégorie
	getSelectCateg();
	
	//Affichage gallery
	objGalleryContainer.style.display = "block";
	
	//Ferme le loading
	closeLoading();
}

function getImgForGallery() {
	//Resest small img
	objGallerySmallImgContent.innerHTML = "";
	countImg = 0;
	
	//Création des images & categ
	for (i=0; i<arrayGalleryGlobal.length; i++) {
		
		//Création array categ
		for (a=0; a<arrayGalleryGlobal[i]['fileCateg'].length; a++) {
			if (inArray(arrayGalleryCateg, arrayGalleryGlobal[i]['fileCateg'][a]) == "notFind") arrayGalleryCateg[arrayGalleryCateg.length] = arrayGalleryGlobal[i]['fileCateg'][a]; //
		}
		
		//Ajout des photos
		if (!galleryCurrentCateg || (galleryCurrentCateg && inArray(arrayGalleryGlobal[i]['fileCateg'], galleryCurrentCateg)) != "notFind") {
			objGallerySmallImgContent.innerHTML += createImgForGallery(arrayGalleryGlobal[i], i, galleryCurrentCateg);
			countImg++;
		}
	}
	
	//Affichage de la 1er image
	initImgViewGallery(document.getElementById('galleryImg0'));
	galleryCurrentLine = 1;
	moveGallery(0);
	
	return countImg;
}

function switchCateg(categ) {	
	galleryCurrentCateg = categ;
	countImg = getImgForGallery();
	galleryCurrentZoom = 0;
	
	galleryMaxLine = Math.ceil(countImg / galleryNumSmallByLine);
	objGallerySmallImgContent.style.height = (galleryMaxLine * 103) + 'px';
}

function getSelectCateg() {
	for (i=0; i<arrayGalleryCateg.length; i++) {
		if (objGalleryCategTxt.innerHTML != "") objGalleryCategTxt.innerHTML += " - ";
		else objGalleryCategTxt.innerHTML += " Filtrer les images : ";
			
		objGalleryCategTxt.innerHTML += '<a href="#" class="galleryCategLink" onClick="switchCateg(\'' + arrayGalleryCateg[i] + '\');">' + arrayGalleryCateg[i] + '</a>';
	}
}

function createImgForGallery(arrayImg, pos, categFilter) {
	var html = '';
	
	//html += '<div class="gallerySmallImg">';
	html += '<img src="' + arrayImg['fileLink'] + '" title="' + arrayImg['fileName'] + ' (Catégorie : ' + arrayImg['fileCateg'] + ')" id="galleryImg' + pos + '" '
	+ 'onClick="initImgViewGallery(this);" onMouseOver="this.className = \'gallerySmallImgOver\';"  onMouseOut="this.className = \'gallerySmallImg\';" '
	+ 'class="gallerySmallImg" height="85" />';
	//html += '</div>';
	
	return html;
}

function initImgViewGallery(e) {
	if (e != null) {
		//Resize image (if necessary)
		precachingImage = new Image();
		precachingImage.src = e.src;
		arraySize = resizeImage(precachingImage, (clientWidth - 164), (clientHeight - 334));
		
		//Get info
		arrayImg = arrayGalleryGlobal[e.id.replace('galleryImg', '')];
		
		objGalleryImgInfoTxt.innerHTML = arrayImg['fileName']+ ' - ' + Math.round(arrayImg['fileSize']/1000) + 'Ko - Catégorie : ' + arrayImg['fileCateg'] + '';
		
		objGalleryImg.src = e.src;
		objGalleryImg.title = e.title;
		objGalleryImg.width = arraySize[0];
		objGalleryImg.height = arraySize[1];
		
		if (arraySize[2]) {
			objGalleryImg.style.cursor = "pointer";
			objGalleryZoomIcon.onmouseover = function () { objGalleryZoomIcon.style.display = "block"; }
			objGalleryImg.onmouseover = function () { galleryZoomIcon(this); }
			objGalleryImg.onmouseout = function () { objGalleryZoomIcon.style.display = "none"; }
			objGalleryZoomIcon.onclick = objGalleryImg.onclick = function () {
				//Changement de type de zoom
				galleryCurrentZoom = galleryCurrentZoom ^ 1;
			
				//Si zoom moins
				if (!galleryCurrentZoom) {
					arraySize = resizeImage(precachingImage, (clientWidth - 164), (clientHeight - 334));
					objGalleryImg.width = arraySize[0];
					objGalleryImg.height = arraySize[1];
					
					galleryZoomIcon(this);
				
				//Si zoom max
				} else {
					objGalleryImg.width = precachingImage.width;
					objGalleryImg.height = precachingImage.height;
					
					galleryZoomIcon(this);
				}
			}
			
		} else {
			objGalleryImg.style.cursor = "default";
			objGalleryImg.onclick = objGalleryImg.onmouseout = objGalleryImg.onmouseover = function () { return false; }
		}
		
	} else {
		setTimeout("initImgViewGallery(" + e + ")", 100);
	}
}

function galleryZoomIcon(e) {
	var classZoom, txt;
	
	if (!galleryCurrentZoom) {
		classZoom = "galleryZoomIconZoom";
		txt = "Taille réel";
	} else {
		classZoom = "galleryZoomIconUnzoom";
		txt = "Taille réduite";
	}
	
	objGalleryZoomIcon.className = classZoom;
	objGalleryZoomIconTxt.innerHTML = txt;
	
	objGalleryZoomIcon.style.left = ((clientWidth/2) - (150/2)) + "px";
	objGalleryZoomIcon.style.top = (((clientHeight)/2) - (150/2)) + "px";
	objGalleryZoomIcon.style.opacity = 0.6;
	objGalleryZoomIcon.style.filter = 'alpha(opacity=60)';
	objGalleryZoomIcon.style.display = "block";
}

function moveGallery(val) {
	var inc = 0;
	galleryCurrentMoveLigne = true;
	
	if (objGallerySmallImgContentScroll.scrollTop < val) {
		//alert('ok1');
		if (objGallerySmallImgContentScroll.scrollTop - val <= -40) inc = 10;
		else if (objGallerySmallImgContentScroll.scrollTop - val <= -10) inc = 5;
		else inc = 1;
		
		objGallerySmallImgContentScroll.scrollTop = objGallerySmallImgContentScroll.scrollTop + inc;
	}
	
	else if (objGallerySmallImgContentScroll.scrollTop > val) {
		//alert('ok2');
		if (objGallerySmallImgContentScroll.scrollTop - val >= 40) inc = 10;
		else if (objGallerySmallImgContentScroll.scrollTop - val >= 10) inc = 5;
		else inc = 1;
		
		objGallerySmallImgContentScroll.scrollTop = objGallerySmallImgContentScroll.scrollTop - inc;
	
	} else {
		galleryCurrentMoveLigne = false;
		return true;
	}
	
	setTimeout("moveGallery(" + val + ")", 2);
}

//Close gallery
function closeGallery() {
	var opacity = objGalleryContainer.style.opacity * 100;
	
	if (opacity > 0) {
		opacity -= 10;
		
		objGalleryContainer.style.opacity = (opacity/100);
		objGalleryContainer.style.filter = 'alpha(opacity=' + opacity + ')';
		
		//Mask
		if (objGlobalMask.style.opacity > (opacity/100)) {
			objGlobalMask.style.opacity = (opacity/100);
			objGlobalMask.style.filter = 'alpha(opacity=' + opacity + ')';
		}
		
		setTimeout("closeGallery()", 2);
	} else {
		//close mask
		closeMask();
		objGalleryContainer.style.display = "none";
		objGallerySmallImgContentScroll.scrollTop = 0;
		objGallerySmallImgContent.innerHTML = "";
		
		galleryStatus = false;
		
		closeLoading();
	}
}


/**********************************************************************************************/
/******************************************MOVIE***********************************************/
/**********************************************************************************************/
var objMovieSelector = document.getElementById('movieSelector');
var objMovieContainer = document.getElementById('movieContainer');
var objMovieMediaContainer = document.getElementById('movieMediaContainer');
var objMoviePlayerContainer = document.getElementById('moviePlayerContainer');
var objMoviePlayerContent = document.getElementById('moviePlayerContent');
var objMoviePlayerButton = document.getElementById('moviePlayerButton');

//Init movie
function initMovie() {
	//Init button
	document.getElementById('movieButton').onclick = function () { closeMovie(); }
	
	//Init selector movie
	objMovieSelector.onchange = function () { launchMovie(this); }
	
	//Init download button
	objMoviePlayerButton.onclick = function () { if (objMoviePlayerContent.offsetHeight == "5") openMoviePlayer(0, 75); else openMoviePlayer(75, 0); }
}

//Lance une movie
function launchMovie(e) {
	var html = false;
	
	//WINDOWS MEDIA PLAYER
	if (arrayMovies[e.value][1] == 'wmv') {
		html = '<object width="510" height="395" id="mediaObject">'
		+ '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" width="510" height="395" '
		+ 'src="movies/' + arrayMovies[e.value][2] + '/' + arrayMovies[e.value][0] + '.' + arrayMovies[e.value][1] + '" '
		+ 'autostart="1"></embed>'
		+ '</object>';
	
	//QUICKTIME
	} else if (arrayMovies[e.value][1] == 'mp4' || arrayMovies[e.value][1] == 'mpeg' || arrayMovies[e.value][1] == 'mov') {		
		html = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="510" height="395" id="mediaObject">'
		+ '<param name="src" value="movies/' + arrayMovies[e.value][2] + '/' + arrayMovies[e.value][0] + '.' + arrayMovies[e.value][1] + '">'
		+ '<param name="autoplay" value="true">'
		+ '<param name="controller" value="true"><embed width="510" height="395" pluginspage="http://www.apple.com/quicktime/download/" src="movies/' + arrayMovies[e.value][2] + '/' + arrayMovies[e.value][0] + '.' + arrayMovies[e.value][1] + '" type="video/quicktime" controller="true" autoplay="true">'
		+ '</object>';
	
	//DIVX
	} else if (arrayMovies[e.value][1] == 'divx' || arrayMovies[e.value][1] == 'avi') {
		html = '<object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab" width="510" height="395" id="mediaObject">'
		+ '<param name="custommode" value="none" />'
		+ '<param name="autoPlay" value="true" />'
		+ '<param name="src" value="movies/' + arrayMovies[e.value][2] + '/' + arrayMovies[e.value][0] + '.' + arrayMovies[e.value][1] + '" />'
		+ '<param name="disableDimmer" value="true">'
		+ '<embed src="movies/' + arrayMovies[e.value][2] + '/' + arrayMovies[e.value][0] + '.' + arrayMovies[e.value][1] + '" width="510" height="395" align="middle" type="video/divx" custommode="none" autoplay="true" pluginspage="http://go.divx.com/plugin/download/" disabledimmer="true">'
		+ '</embed>';
		+ '</object>';
	}
	
	if (html) {
		objMovieMediaContainer.innerHTML = html;
		document.getElementById('mediaObject').style.zIndex = 1;
	}
	
}

//Open movie
function openMovie(e) {
	refreshSizeSreen();
	
	//Close all appli
	resetAppli();
	
	//Container
	objMovieContainer.style.opacity = 0.95;
	objMovieContainer.style.filter = 'alpha(opacity=95)';
	objMovieContainer.style.left = (getOffsetLeft(e) + 1) + "px";
	objMovieContainer.style.top = "1px";
	objMovieContainer.style.display = "block";
	
	//Download
	objMoviePlayerContainer.style.opacity = 0.95;
	objMoviePlayerContainer.style.filter = 'alpha(opacity=95)';
	objMoviePlayerContainer.style.display = "block";
	objMoviePlayerContainer.style.left = (getOffsetLeft(objMovieContainer) + ((objMovieContainer.offsetWidth - objMoviePlayerContainer.offsetWidth)/2)) + "px";
	objMoviePlayerContainer.style.top = (objMovieContainer.offsetHeight + getOffsetTop(objMovieContainer)) + "px";
	
	movieStatus = true;
}

//Ouvre
function openMoviePlayer(tmp, end) {
	if (tmp < end) tmp += 5;
	else tmp -= 5;
	
	objMoviePlayerContent.style.height = tmp + "px";
	
	if (tmp == end) return true;
	setTimeout("openMoviePlayer(" + tmp + ", " + end + ")", 2);
	
}

//Close movie
function closeMovie() {
	objMovieSelector.value = "";
	objMovieMediaContainer.innerHTML = "";
	objMovieContainer.style.display = "none";
	objMoviePlayerContainer.style.display = "none";
	
	movieStatus = false;
}


/**********************************************************************************************/
/****************************************CONNECTION********************************************/
/**********************************************************************************************/
var objFormConnect = document.getElementById('connectForm'); //form : connection
var objContainerConnect = document.getElementById('connectContainer'); //div : connection
var objFormConnectUser = document.getElementById('connectFormUser'); //form user : connection
var objFormConnectPasswd = document.getElementById('connectFormPasswd'); //form password : connection
var objFormConnectSubmit = document.getElementById('connectSubmit'); //form submit : connection
		
//Init connection
function initConnection() {
	//User form
	if (document.getElementById('connectFormUser') != null) {
		objFormConnectUser.onfocus = function () { if (this.value == "Utilisateur") this.value = ""; }
		objFormConnectUser.onblur = function () { if (this.value == "") this.value = "Utilisateur"; }
		
		//User form
		objFormConnectPasswd.onfocus = function () { if (this.value == "xxxxx") this.value = ""; }
		objFormConnectPasswd.onblur = function () { if (this.value == "") this.value = "xxxxx"; }
		
		//submit form
		objFormConnect.action = "javascript:checkConnection();"; //NE MARCHE PAS ET J AI SAIS PAS PQ !
		objFormConnectSubmit.onclick = function () { checkConnection(); }
	}
}

function checkConnection() {
	if (objFormConnectUser.value != "" && objFormConnectUser.value != "Utilisateur" && objFormConnectPasswd.value != "" && objFormConnectPasswd.value != "xxxxx") {
		objFormConnect.action = "?p=" + currentPage;
		objFormConnect.submit();
	
	} else {
		openAlert('alertContainerError', 'CONNEXION IMPOSSIBLE', 'Merci de saisir les deux champs obligatoires de connexion !<br /><br /><br />Xsls');
	}
}


/**********************************************************************************************/
/*****************************************SUBMENU**********************************************/
/**********************************************************************************************/
var prefixIdMenu = "liMenuHeadLink";

//Init menu
function initMenu() {
	var i, e;
	
	for (i=0; i<arrayMenu.length; i++) {
		if (document.getElementById(prefixIdMenu + arrayMenu[i]) != null) {
			e = document.getElementById(prefixIdMenu + arrayMenu[i]);
			e.onclick = function () {
				initSubMenu(arraySubMenu[inArray(arrayMenu, this.id.substr(14,50))]);
				
				//Positionnement de l'img superieur pour le diapo
				newPosImgDiapo();
				
				return false;
			}
		}
	}
}

//Init sub menu
function initSubMenu(arraySub) {
	var i, e;
	
	for (i=0; i<arraySub.length; i++) {
		if (document.getElementById(arraySub[i]) != null) {
			e = document.getElementById(arraySub[i]);
			
			if (e.style.display == "block")	e.style.display = "none";
			else e.style.display = "block";
		}
	}
}


/**********************************************************************************************/
/******************************************ALERT***********************************************/
/**********************************************************************************************/
var objAlertContainer = document.getElementById('alertContainer');
var objAlertTitle = document.getElementById('alertContainerTitle');
var objAlertTxt = document.getElementById('alertContainerTxt');
var alertStatus = false;

//Ouvre l'erreur de submit
function openAlert(className, title, text, timeClose) {
	if (alertStatus) return false;
	if (timeClose == "" || !timeClose) timeClose = 2000;
	
	refreshSizeSreen();
	
	alertStatus = true;
	
	objAlertTitle.innerHTML = title;
	objAlertTxt.innerHTML = text;
	objAlertContainer.className = className;
	
	//291 / 71 = w / h div error
	objAlertContainer.style.opacity = 1;
	objAlertContainer.style.filter = 'alpha(opacity=100)';
	objAlertContainer.style.left = ((clientWidth/2) - (291/2)) + "px";
	objAlertContainer.style.top = ((clientHeight/2) - (134/2)) + "px";
	objAlertContainer.style.display = "block";
	
	//Ferme l'alert (time to close , 0, opacity start)
	closeAlert(timeClose, 0, 100);
}

//Ferme l'erreur de submit
function closeAlert(closeTime, timeTmp, opacityTmp) {
	//Si l'attente passé
	if (timeTmp == closeTime) {
		//Si l'opacité est a 0
		if (opacityTmp > 0) {
			opacityTmp -= 2;
			
			
			objAlertContainer.style.opacity = opacityTmp/100;
			objAlertContainer.style.filter = 'alpha(opacity=' + opacityTmp + ')';
			
			timer = setTimeout("closeAlert(" + closeTime + ", " + timeTmp + ", " + opacityTmp + ")", 2);
		} else {
			alertStatus = false;
			objAlertContainer.style.display = "none";
			clearTimeout(timer);
		}
	} else {
		timer = setTimeout("closeAlert(" + closeTime + ", " + closeTime + ", " + opacityTmp + ")", closeTime);
	}
}


/**********************************************************************************************/
/******************************************TBL*************************************************/
/**********************************************************************************************/
//Init event over row
function initTblOverRow() {
	var e;
	
	if (arrayTblOver != null) {
		for (i=0; i<arrayTblOver.length; i++) {
			e = document.getElementById(arrayTblOver[i]);
			
			eval ('e.onmouseout = function () { this.className = "' + e.className + '"; }');
			e.onmouseover = function () { this.className = "tblContentOver"; }
		}
	}
}

//Init event over row
function initResultRace(idSelectRace) {
	e = document.getElementById(idSelectRace);
	
	e.onchange = function () { window.open('?p=resultRace&idRace=' + this.value, '_parent'); }
}


/**********************************************************************************************/
/*****************************************ACCUEIL**********************************************/
/**********************************************************************************************/
var timerObj;
var objNextRaceContainer = document.getElementById('modNextRaceTime');
var timerRaceStatus = false;

function initNextRaceTime(raceDate) {
	var date, dateTmp, dateRace, dateRaceTmp, raceInSecondes, raceInMinutes, raceInHours, raceInDays;
	
	date = new Date;
	dateTmp = date.getTime();
	
	if (!timerRaceStatus) {
		timerRaceStatus = true;
		dateRace = new Date();
		dateRace.setTime(Date.parse(raceDate));
		dateRaceTmp = dateRace.getTime();
	} else {
		dateRaceTmp = raceDate;
	}
	
	raceInSecondes -= 1;
	
	raceInSecondes = Math.floor((dateRaceTmp-dateTmp) / 1000);
	raceInMinutes = Math.floor(raceInSecondes / 60);
	raceInHours = Math.floor(raceInMinutes / 60);
	raceInDays = Math.floor(raceInHours / 24);
	
	while (raceInSecondes >= 60) raceInSecondes -= 60;
	while (raceInMinutes >= 60) raceInMinutes -= 60;
	while (raceInHours >= 24) raceInHours -= 24;
	
	if (raceInSecondes < 10) raceInSecondes = "0" + raceInSecondes;
	if (raceInMinutes < 10) raceInMinutes = "0" + raceInMinutes;
	if (raceInHours < 10) raceInHours = "0" + raceInHours;
	
	if (raceInDays == 0) raceInDays = "";
	else raceInDays += " jours et ";
		
	//S compteur à 0
	if (raceInHours == "00" && raceInMinutes == "00" && raceInSecondes == "00") {
		objNextRaceContainer.innerHTML = "Course démarrée";
		return true;
	
	//Sinon
	} else {
		objNextRaceContainer.innerHTML = raceInDays + raceInHours + ":" + raceInMinutes + ":" + raceInSecondes;
	}
	
	timerObj = setTimeout("initNextRaceTime(" + dateRaceTmp + ")", 1000);
}

/**********************************************************************************************/
/*******************************************TEAMS**********************************************/
/**********************************************************************************************/
function initTeamsOver() {
	var e;
	
	if (arrayTeamsOver != null) {
		for (i=0; i<arrayTeamsOver.length; i++) {
			e = document.getElementById(arrayTeamsOver[i]);
			
			eval ('e.onmouseout = function () { this.className = "' + e.className + '"; }');
			e.onmouseover = function () { this.className = "teamOverContainer"; }
		}
	}
}

/**********************************************************************************************/
/******************************************CONTACT*********************************************/
/**********************************************************************************************/
//Init menu partner
function initContact() {
	var array, arraySub;
	
	//Init les elem ayant un bg perso
	array = new Array('ContactLName', 'ContactFName', 'ContactEmail', 'ContactSubject');
	initInputOver(array);
	
	//Init button form
	array = new Array('ContactSave', 'ContactCancel');
	arraySub = new Array(); 
	arraySub[0] = new Array('initFormCheckContact();');
	arraySub[1] = new Array("window.open('?p=contact', '_parent');");
	initButton(array, arraySub);
}

//Init le submit du form Xsls
function initFormCheckContact() {
	var form, i;
	
	form = document.getElementById('formContact');

	arrayFormCheck = new Array('ContactLName', 'ContactFName', 'ContactEmail', 'ContactSubject', 'contactContent');
	arrayFormOptionCheck = new Array();
	arrayFormOptionCheck[0] = new Array('noEmpty', 0, 100);
	arrayFormOptionCheck[1] = new Array('noEmpty', 0, 100);
	arrayFormOptionCheck[2] = new Array('eMail');
	arrayFormOptionCheck[3] = new Array('noEmpty', 0, 255);
	arrayFormOptionCheck[4] = new Array('tinyMceNoEmpty');
	
	//Si pas d"erreur
	if (!getCheckForm()) form.submit();
	else openAlert('alertContainerError', "SAISIE INCORRECT", "Vous n'avez pas saisie tous les champs nécessaires !");
}


/**********************************************************************************************/
/******************************************CALENDAR********************************************/
/**********************************************************************************************/
//Constant var
var timer;
var today = new Date();
var thisDay = today.getDate();
var year = today.getYear();
var month = today.getMonth();
var infoDayStatus = false;
var infoDayEditX = false;
var infoDayEditY = false;
var selectedDay = true;
var objCalendarContainer = document.getElementById('calendarContainer');

//Init calendar
function initCalendar() {
	objCalendarContainer.innerHTML = innerCalendarCode();
}

//Creer en renvoie le calendar en html
function innerCalendarCode() {
	function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) {
		this[0] = m0;
		this[1] = m1;
		this[2] = m2;
		this[3] = m3;
		this[4] = m4;
		this[5] = m5;
		this[6] = m6;
		this[7] = m7;
		this[8] = m8;
		this[9] = m9;
		this[10] = m10;
		this[11] = m11;
	}
	
  function calendar() {
  	var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  	var monthNames = "JanFevMarAvrMaiJuiJuiAouSepOctNovDec";
  	var innerCalendar = "";
  	
  	//Verif année
    if (year <= 200) {
        year += 1900;
    }
    
    //Année bi
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
        monthDays[1] = 29;
    }
		
    //Tableau des infos sup du mois affiché
    if (calendarInfo[year] != null && calendarInfo[year][month + 1] != null) {
    	var arrInfo = calendarInfo[year][month + 1];
    } else {
    	arrInfo = null;
    }
    
    //Nombre de jour dans le mois
    nDays = monthDays[month];
    firstDay = today;
    firstDay.setDate(1);
    
    testMe = firstDay.getDate();
    if (testMe == 2) {
        firstDay.setDate(0);
    }
    
    //Construction du calendar   
    startDay = firstDay.getDay()-1;
    innerCalendar = '<table border="0" cellspacing="1" cellpadding="1" id="calendarTbl">' 
	+ '<tr>'
    + '<th id="calendarThMonthPrev" onMouseOver="this.id=\'calendarThMonthOver\';" onMouseOut="this.id=\'calendarThMonthPrev\';" onClick="getNewMonth(0); newPosImgDiapo(); return false;" title="Mois précédent">&#171;</th>'
    + '<th id="calendarThMonth" colspan="5">' + monthNames.substring(month * 3, (month + 1) * 3) + '. ' + year + '</th>'
    + '<th id="calendarThMonthNext" onMouseOver="this.id=\'calendarThMonthOver\';" onMouseOut="this.id=\'calendarThMonthNext\';" onClick="getNewMonth(1); newPosImgDiapo(); return false;" title="Mois suivant">&#187;</th>'
    + '</th></tr>'
    + '<tr><th class="calendarTh">L</th><th class="calendarTh">M</th><th class="calendarTh">M</th><th class="calendarTh">J</th><th class="calendarTh">V</th><th class="calendarTh">S</th><th class="calendarTh">D</th></tr>'
    + "<tr>";
    column = 0;
	
    //Debute le tableau si 1er jour != lundi
    for (i = 0; i < startDay; i++) {
      innerCalendar += ('<td class="calendar-td-empty">&nbsp;</td>');
      column++;
    }
    
    //continu le tableau avec les jours du mois en cours
    for (i = 1; i <= nDays; i++) {
    	var info = "";
    	var classTd = "";
    	
  		//Si info connu pour ce jour
  		if (arrInfo != null && arrInfo[i] != null) {
  			info = ' onMouseOver="getInfoDay(\'day' + i + '\', Array(' + year + ', ' + (month + 1) + ', ' + i + '));"';
  			classTd = "calendar-td-info";
  			
  			if (thisDay && i == thisDay) {
  			 	classTd = "calendar-td-tooday-info";
  			}
  		
  		} else {
  			info = "";
  			classTd = "calendar-td";
  			
  			if (i == thisDay && selectedDay) {
  			 	classTd = "calendar-td-tooday";
  			}
  		}
      
		innerCalendar += '<td class="' + classTd + '"' + info + ' id="day' + i + '">' + i + '</td>';
      
		column++;
		
		if (column == 7) {
			innerCalendar += "</tr>";
			innerCalendar += "<tr>";
			column = 0;
		}
    }
    
    
    //Fini le tableau si jour de fin n'est pas dimanche
    if (column < 7) {
    	for (i = column; i < 7; i++) {
    		innerCalendar += '<td class="calendar-td-empty">&nbsp;</td>';
        column++;
    	}
    }
    
    innerCalendar += "</table>";
    
    return innerCalendar;
  }

  return calendar();
}

function getNewMonth(type) {
	tooday = new Date();
	
	//Mois suivant
	if (type) {	
		if (month+1 > 11) {
			year = year + 1;
			month = 0;
		} else {
			month = month + 1;
		}
	
	//Mois precedent
	} else {
		if (month-1 < 0) {
			year = year - 1;
			month = 11;
		} else {
			month = month - 1;
		}
	}
	
	//Jour actuel (si mois actuel)
	thisDay = 1;
	selectedDay = false;
	if (tooday.getMonth() == month) {
		thisDay = tooday.getDate();
		selectedDay = true;
	}
	
	
	today = new Date(year, month, thisDay);
	
	objCalendarContainer.innerHTML = innerCalendarCode();
}


//Met en place les div d'info
function getInfoDay(idDay, infoArr) {
	var linkDay = document.getElementById(idDay);
	var infoContener = document.getElementById('calendarInfo');
	var content = "";
	
	if (!infoDayStatus) {
		//Maj du contenu
		for (i=0; i<calendarInfo[infoArr[0]][infoArr[1]][infoArr[2]].length; i++) {
			//Separateur
			if (i) content += '<div class="calendarSepar"></div>';
			
			//Race
			content += '<div class="calendarInfoTitle">' + calendarInfo[infoArr[0]][infoArr[1]][infoArr[2]][i][0] + '</div>';
			content += '<div class="calendarInfoContent">' + calendarInfo[infoArr[0]][infoArr[1]][infoArr[2]][i][1] + '</div>';
			content += '<div class="calendarInfoDate">' + calendarInfo[infoArr[0]][infoArr[1]][infoArr[2]][i][2] + '</div>';
		}
		
		//Affichage
		infoContener.innerHTML = content;
		infoContener.style.opacity = 0.95;
		infoContener.style.filter = 'alpha(opacity=95)';
		infoContener.style.display = "block";
		
		document.getElementById(idDay).onmouseout = function() {
			infoContener.style.display = "none";
			
			infoDayStatus = false;
			clearTimeout(timer);
			return false;
		}
		
		/*
		//onClick
		if (calendarInfo[infoArr[0]][infoArr[1]][infoArr[2]][3]) {
			document.getElementById(idDay).onclick = function() {
				window.open(calendarInfo[infoArr[0]][infoArr[1]][infoArr[2]][3], '_parent');
			}
		}
		*/
		
		//Positionnement du div en Y
		infoContener.style.top = (Mouse_Y + 10) + "px";
		
		//Remise a zero de marqueur de correction
		infoDayEditX = false;
		infoDayEditY = false;
	}
	
	//Position init
	refreshSizeSreen();
	
	//Positionnement du div en X
	infoContener.style.left = (Mouse_X + 10) + "px";
	
	//Positionnement du div en Y
	var hBottom = innerHeight + scrollY;
	var hHelpBottom = (getOffsetTop(infoContener) + infoContener.offsetHeight) - scrollY;
	
	//calcul
	if (hHelpBottom > hBottom) {
		infoDayEditY = true;
		styleTop = (Mouse_Y - scrollTop) - (hHelpBottom - hBottom);
	} else {
		if (!infoDayEditY)
			styleTop = Mouse_Y + 10;
	}
	
	//placement Y
	infoContener.style.top = styleTop + "px";
	
	infoDayStatus = true;
	timer = setTimeout("getInfoDay('" + idDay + "', Array(" + infoArr[0] + "," + infoArr[1] + ", " + infoArr[2] + "))", 2);
}

/***************************************************************************************************************/
/************************************************DIAPORAMA******************************************************/
/***************************************************************************************************************/
var divDiapo = document.getElementById('diaporama');
var imgDiapo = document.getElementById('diaporamaImg');
var imgDiapoOver = document.getElementById('diaporamaImgOver');
var diapoLaunch = false; //Si diapo lancée
var opacityTmp = 0; //depart / en cours de l'opacity de l'element imgDiapoOver
var opacityRefresh = 4; //mili seconde
var imgSwicth = 5000; //mili seconde
var imgDiapoActive; //Image visible
var timer;
var timer2;

//Initialise le diaporama
function initDiapo() {
	//Si aucune image
	if (!galleryData) {
		divDiapo.innerHTML = '<div style="padding-left:27px;">Aucune image</div>';
		return false;
	
	//Si une seul image
	} else if (galleryData.length == 1) {
		imgDiapoOver.style.display = "none";
		return false;
	}
	
	//Init opacity
	imgDiapo.style.opacity = 10;
	imgDiapo.style.filter = 'alpha(opacity=100)';
	
	imgDiapoOver.style.opacity = 0;
	imgDiapoOver.style.filter = 'alpha(opacity=0)';
	imgDiapoOver.style.display = "block";

	//Marqueur diapo lancé
	diapoLaunch = true;
	
	//Positionnement de l'img superieur pour le diapo
	newPosImgDiapo();
	
	//lance le diaporama
	launchDiapo(0);
}

//lance le diaporama
function launchDiapo(changeImg) {
	//Photo aléatoire (chiffre entre 1 et 10)
	var photoCount = parseInt(Math.random() * galleryData.length);	
	
	//Pour contrer le probléme de flash (qd le over est en opacity 0) au moment du changement de la src du 2eme plan imgDiapo
	if (!changeImg) changeImg = 1;
	else {
		changeImg = 0;
		imgDiapo.src = galleryData[photoCount];
	}
	
	//vers visible
	if (opacityTmp == 0) {
		getOpacitySys(0);
		imgDiapoOver.src = galleryData[photoCount];
	
	//vers invisible
	} else getOpacitySys(1);
	
	timer = setTimeout("initDiapo(" + changeImg + ")", imgSwicth);
}

//Gere le systeme opacity pour creer l'effet fondu
function getOpacitySys(type) {
	//Gestion de l'opacité
	if (!type) opacityTmp += 4;
	else opacityTmp -= 4;

	//Application du l'opacité
	imgDiapoOver.style.opacity = opacityTmp/100;
	imgDiapoOver.style.filter = "alpha(opacity=" + opacityTmp + ")";
	
	if ((!type && opacityTmp < 100) || (type && opacityTmp > 0)) {
		timer2 = setTimeout("getOpacitySys(" + type + ")", opacityRefresh);
	} else {
		if (!type) opacityTmp = 100;
		else opacityTmp = 0;
		
		clearTimeout(timer2);
		return true;
	}
}

//Met en position l'image over de la gallery
function newPosImgDiapo() {
	if (imgDiapoOver != null && diapoLaunch) {
		imgDiapoOver.style.top = getOffsetTop(imgDiapo) + "px";
		imgDiapoOver.style.left = getOffsetLeft(imgDiapo) + "px";
	}
}


/***************************************************************************************************************/
/**************************************************LOADING******************************************************/
/***************************************************************************************************************/
var objLoading = document.getElementById('loading');
var objLoadingTxt = document.getElementById('loadingTxt');
var loadingStatus = false;

//Ouvre le loading
function openLoading() {	
	refreshSizeSreen();
	
	loadingStatus = true;

	objLoading.style.left = ((clientWidth/2) - (222/2)) + "px";
	objLoading.style.top = ((clientHeight/2) - (33/2)) + "px";
	
	objLoading.style.opacity = 1;
	objLoading.style.filter = 'alpha(opacity=100)';
	
	objLoadingTxt.innerHTML = "Chargement en cours ...";
	objLoading.style.display = "block";
}

//Ferme le loading
function closeLoading(opacityTmp) {
	opacityTmp -= 6;
	
	objLoadingTxt.innerHTML = "Chargement terminé ...";
	
	if (opacityTmp > 0) {
		objLoading.style.opacity = opacityTmp/100;
		objLoading.style.filter = 'alpha(opacity=' + (opacityTmp) + ')';
		
		timer = setTimeout("closeLoading(" + opacityTmp + ")", 4);
	} else {
		clearTimeout(timer);
		
		objLoading.style.display = "none";
		loadingStatus = false;
	}
}

//Force la fermutre du loading
function forceCloseLoading() {
	clearTimeout(timer);
	loadingStatus = false;
	objLoading.style.opacity = 0;
	objLoading.style.filter = 'alpha(opacity=0)';
	objLoading.style.display = "none";
}



/***************************************************************************************************************/
/**********************************************XMLHttpRequest***************************************************/
/***************************************************************************************************************/
//Function generatrice
function initXhrObj() {
	// Firefox 
	if (window.XMLHttpRequest) 
		xhr_object = new XMLHttpRequest(); 
	
	// Internet Explorer 
	else if (window.ActiveXObject) 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	
	// XMLHttpRequest non supporté par le navigateur 
	else 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest ... "); 
	
	return xhr_object; 
} 


/***************************************************************************************************************/
/*****************************************************AUTRE*****************************************************/
/***************************************************************************************************************/
//Recherche dans un array un valeur
function inArray(array, value) {
	for (var i=0; i<array.length; i++) {
		if (array[i] == value) return i;
	}
	
	return "notFind";
}

//Retourne la clé si valeur connu
function getKeyWithValue(array, value) {
	for (i=0; i<array.length; i++) {
		if (inArray(array[i], value)) return i;
	}
	
	return "notFind"; //string si return = id 0
}

//Verifie la validité d'une date
function chackDateValid(dateArray) {
	var dateTest = new Date(eval(dateArray[2]),eval(dateArray[1])-1,eval(dateArray[0]));
	
	//Bug 2000 test
	var year = dateTest.getYear()
	if ((Math.abs(year) + "").length < 4) year = year + 1900;
	
	return ((dateTest.getDate() == eval(dateArray[0])) && (dateTest.getMonth() == eval(dateArray[1])-1) && (year == eval(dateArray[2])));
}

//Retourne pos mouse
function PosMouse(e){
  var DocRef;
  
  //Tous sauf IE
  if(_moz){                     
    Mouse_X = e.pageX;
    Mouse_Y = e.pageY;
  } else { 
    Mouse_X = event.clientX;
    Mouse_Y = event.clientY;

	  //DOCTYPE sous IE

	  if(_moz) DocRef = document.body;
	  else DocRef = document.documentElement;

	  Mouse_X += DocRef.scrollLeft;
	  Mouse_Y += DocRef.scrollTop;
  }
  
  return false;
}

//Donne l'offset top
function getOffsetTop(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}

//Donne l'offset left
function getOffsetLeft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}


//Met a jour les var de size screen
function refreshSizeSreen() {
	//document.documentElement.clientHeight <- ie taille de la zone dispo
	//document.body.clientHeight <- moz taille de la zone dispo
	
	if (_moz) {
		//Height
		innerHeight = document.height;
		screenHeight = screen.height;
		
		//Width
		innerWidth = window.innerWidth;
		screenWidth = screen.width;
	} else {
		//Height
		
		innerHeight = document.body.offsetHeight;
		screenHeight = window.screen.height;
		
		//Width
		innerWidth = document.body.offsetWidth;
		screenWidth = window.screen.width;
	}
	
	//Client size
	clientHeight = document.documentElement.clientHeight;
	clientWidth = document.documentElement.clientWidth;
	
	//Scrool
	scrollY = document.documentElement.scrollTop;
	scrollX = document.documentElement.scrollLeft;
	
	//alert("clientHeight : " + clientHeight +  " // screen.height : " + screen.height +  " -//- clientWidth : " + clientWidth +  " // screenWidth : " + screenWidth); //  +  +  " //  : "
}

//Resize une image suivant un h&w max
function resizeImage(objImg, maxWidth, maxHeight) {
	//init
	var dH = 0;
	var dW = 0;
	var resize = true;
	
	// On recupere les tailles reelles
	var w = dW = objImg.width;
	var h = dH = objImg.height;
	
	// Si la largeur ou la hauteur depasse la taille maximale
	if ((h >= maxHeight) || (w >= maxWidth)) {
		// Si la largeur et la hauteur depasse la taille maximale
		if ((h >= maxHeight) && (w >= maxWidth)) {
			// On cherche la plus grande valeur
			if (h > w) {
				
				dH = maxHeight;
				// On recalcule la taille proportionnellement
				dW = parseInt((w * dH) / h, 10);
			} else {
				dW = maxWidth;
				// On recalcule la taille proportionnellement
				dH = parseInt((h * dW) / w, 10);
			}
			
			if (dH > maxHeight) {
				dH = maxHeight;
				// On recalcule la taille proportionnellement
				dW = parseInt((w * dH) / h, 10);
			
			} else if (dW > maxWidth) {
				dW = maxWidth;
				// On recalcule la taille proportionnellement
				dH = parseInt((h * dW) / w, 10);
			}
			
			
		} else if ((h > maxHeight) && (w < maxWidth)) {
			dH = maxHeight;
			// On recalcule la taille proportionnellement
			dW = parseInt((w * dH) / h, 10);
		} else if ((h < maxHeight) && (w > maxWidth)) {
			dW = maxWidth;
			// On recalcule la taille proportionnellement
			dH = parseInt((h * dW) / w, 10);
		}
	} else {
		resize = false;
	}
	
	return new Array(dW, dH, resize);
}

//Donne la nouvelle position du scrool Y si changé
function scrollTest() {
	refreshSizeSreen();
	
	if (scrollY != scrollYSave) scrollYSave = scrollY;
	
	setTimeout("scrollTest()", 100);
}

//Créer un cookie
function setCookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	if (expires) expires = expires * 1000 * 60 * 60 * 24;
	
	var expires_date = new Date(today.getTime() + (expires));
	
	document.cookie = name + "=" + escape(value) +
	((expires) ? ";expires=" + expires_date.toGMTString() : "" ) +
	((path) ? ";path=" + path : "" ) +
	((domain) ? ";domain=" + domain : "" ) +
	((secure) ? ";secure" : "" );
}

function getCookie(name) {
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	
	if ((!start) &&	(name != document.cookie.substring(0, name.length))) return null;
	
	if (start == -1) return null;
	var end = document.cookie.indexOf( ";", len );
	
	if (end == -1) end = document.cookie.length;
	
	return unescape(document.cookie.substring(len, end));
}

//Supprime un cookie
function delCookie(name, path, domain) {
	if (getCookie(name)) document.cookie = name + "=" +
	((path) ? ";path=" + path : "") +
	((domain) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


/***********************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************/
/******************************************************************************ADMINITRATION****************************************************************************************************/
/***********************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************/

//Init global var
var arrayFormCheck, arrayFormOptionCheck, arrayFormCheckError, timer;

/***************************************************************************************************************/
/*************************************************PARTNERS******************************************************/
/***************************************************************************************************************/
var objFormPartnersLinkSelect = document.getElementById('parternsSelect');
var objFormPartnerTitle = document.getElementById('PartnersTitle');
var objFormPartnerLink = document.getElementById('PartnersLink');
var objPartnerTitleContainer = document.getElementById('partnersTitleContainer');
var objPartnerLinkContainer = document.getElementById('partnersLinkContainer');
var objPartnerDelContainer = document.getElementById('partnersDelContainer');

//Init partner
function initFormPartners() {
	var array, arraySub;
	
	//Select edit partner
	objFormPartnersLinkSelect.onchange = function () {
		if (this.value != "") window.open('?p=adminPartners&idPartners=' + this.value, '_parent');
	}
	
	//Init les elem ayant un bg perso
	array = new Array('PartnersTitle', 'PartnersLink');
	initInputOver(array);
	
	//Init les radio (function obligatoire : function e.id() {})
	array = new Array('partnersDelYes', 'partnersDelNo');
	arraySub = new Array('partnersDel(this)', 'partnersDel(this)');
	initRadio(array, arraySub);
	
	//Init button form
	array = new Array('PartnersSave', 'PartnersCancel');
	arraySub = new Array(); 
	arraySub[0] = new Array('initFormCheckPartners();');
	arraySub[1] = new Array("window.open('?p=adminPartners', '_parent');");
	initButton(array, arraySub);
	
	//Init add
	objPartnerDelContainer.style.display = "none";
}

//Init le submit du form Xsls
function initFormCheckPartners() {
	var form, i;
	
	form = document.getElementById('formPartners');

	arrayFormCheck = new Array('PartnersTitle', 'PartnersLink');
	arrayFormOptionCheck = new Array();
	arrayFormOptionCheck[0] = new Array('noEmpty', 2, 255);
	arrayFormOptionCheck[1] = new Array('link');
	
	//Si pas d"erreur
	if (!getCheckForm()) form.submit();
	else openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Vous n'avez pas saisie tous les champs nécessaires !");
}

//Init edit partners
function initEditPartners() {
	objFormPartnerTitle.value = arrayPartner[1];
	objFormPartnerLink.value = arrayPartner[2];
	objPartnerDelContainer.style.display = "block";
}

/***************************************************************************************************************/
/************************************************PREQUALIF******************************************************/
/***************************************************************************************************************/
var objFormPrequalSelect = document.getElementById('prequalSelect');
var objFormPrequalType = document.getElementById('prequalType');
var objFormPrequalNumInSerie = document.getElementById('prequalNumInSerie');
var objFormPrequalMaxSeries = document.getElementById('prequalMaxSeries');
var objFormPrequalLimitTime = document.getElementById('prequalLimitTime');
var objFormPrequalAttachRace = document.getElementById('prequalAttachRace');
var objFormPrequalTrack = document.getElementById('PrequalTrack');
var objFormPrequalServer = document.getElementById('PrequalServer');
var objFormPrequalLogsLink = document.getElementById('PrequalLogsLink');
var objFormPrequalGame = document.getElementById('prequalGame');
var objPrequalDelContainer = document.getElementById('prequalDelContainer');

//Init prequal
function initFormPrequal() {
	
	//Select edit partner
	objFormPrequalSelect.onchange = function () { if (this.value != "") window.open('?p=adminPrequal&idPrequal=' + this.value, '_parent'); }
	
	//Init les radio (function obligatoire : function e.id() {})
	array = new Array('prequalDelYes', 'prequalDelNo');
	arraySub = new Array('prequalDel(this)', 'prequalDel(this)');
	initRadio(array, arraySub);
	
	//Init les elem ayant un bg perso
	array = new Array('PrequalTrack', 'PrequalServer', 'PrequalLogsLink');
	initInputOver(array);
	
	//Init button form
	array = new Array('PrequalSave', 'PrequalCancel');
	arraySub = new Array(); 
	arraySub[0] = new Array('initFormCheckPrequal();');
	arraySub[1] = new Array("window.open('?p=adminPrequal', '_parent');");
	initButton(array, arraySub);
}

//Init le submit du form Xsls
function initFormCheckPrequal() {
	var form, i;
	
	form = document.getElementById('formPrequal');

	arrayFormCheck = new Array('PrequalTrack', 'PrequalServer', 'PrequalLogsLink', 'prequalAttachRace');
	arrayFormOptionCheck = new Array();
	arrayFormOptionCheck[0] = new Array('noEmpty', 2, 255);
	arrayFormOptionCheck[1] = new Array('noEmpty', 2, 150);
	arrayFormOptionCheck[2] = new Array('noEmpty', 2, 255);
	arrayFormOptionCheck[3] = new Array('noEmpty');
	
	//Date de départ
	dateArrayStart = new Array(document.getElementById('prequalStartDay').value, document.getElementById('prequalStartMonth').value, document.getElementById('prequalStartYear').value);
	
	//Date de fin
	dateArrayEnd = new Array(document.getElementById('prequalEndDay').value, document.getElementById('prequalEndMonth').value, document.getElementById('prequalEndYear').value);
	
	//Si pas d"erreur
	if (!getCheckForm()) {
		if (!chackDateValid(dateArrayStart)) {
			openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Votre date de lancement de préqualification n'est pas valide !");
			return false;
		}
		
		if (!chackDateValid(dateArrayEnd)) {
			openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Votre date de fin de préqualification n'est pas valide !");
			return false;
		}
		
		form.submit();
		
	} else openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Vous n'avez pas saisie tous les champs nécessaires !");
}

//Init edit partners
function initEditPrequal() {
	//prequalTrack, prequalType, prequalNumInSerie, prequalMaxSeries, prequalLimitTime, prequalAttachRace, prequalServer, prequalLogsLink, prequalGame, prequalStartDate, prequalEndDate
	objFormPrequalType.value = arrayPrequal[1];
	objFormPrequalNumInSerie.value = arrayPrequal[2];
	objFormPrequalMaxSeries.value = arrayPrequal[3];
	objFormPrequalLimitTime.value = arrayPrequal[4];
	objFormPrequalAttachRace.value = arrayPrequal[5];
	objFormPrequalServer.value = arrayPrequal[6];
	objFormPrequalLogsLink.value = arrayPrequal[7];
	objFormPrequalGame.value = arrayPrequal[8];
	objFormPrequalTrack.value = arrayPrequal[0];
	
	//Date start
	document.getElementById('prequalStartDay').value = arrayPrequal[9].substr(8,2);
	document.getElementById('prequalStartMonth').value = arrayPrequal[9].substr(5,2);
	document.getElementById('prequalStartYear').value = arrayPrequal[9].substr(0,4);
	document.getElementById('prequalStartHour').value = arrayPrequal[9].substr(11,2);
	document.getElementById('prequalStartMin').value = arrayPrequal[9].substr(14,2);
	
	//Date end
	document.getElementById('prequalEndDay').value = arrayPrequal[10].substr(8,2);
	document.getElementById('prequalEndMonth').value = arrayPrequal[10].substr(5,2);
	document.getElementById('prequalEndYear').value = arrayPrequal[10].substr(0,4);
	document.getElementById('prequalEndHour').value = arrayPrequal[10].substr(11,2);
	document.getElementById('prequalEndMin').value = arrayPrequal[10].substr(14,2);
	
	//Affichage suppr container
	objPrequalDelContainer.style.display = "block";
}

/***************************************************************************************************************/
/****************************************************MENU*******************************************************/
/***************************************************************************************************************/
var objFormMenuLinkSelect = document.getElementById('menuLinkSelect');
var objFormMenuType = document.getElementById('menuType');
var objMenuTypeContainer = document.getElementById('menuTypeContainer');
var objMenuTitleContainer = document.getElementById('menuTitleContainer');
var objMenuSubContainer = document.getElementById('menuSubContainer');
var objMenuLinkContainer = document.getElementById('menuLinkContainer');
var objMenuSubSelectContainer = document.getElementById('menuSubSelectContainer');
var objMenuDocContainer = document.getElementById('menuDocContainer');
var objMenuLogContainer = document.getElementById('menuLogContainer');
var objMenuChampContainer = document.getElementById('menuChampContainer');
var objMenuChampUniqContainer = document.getElementById('menuChampUniqContainer');
var objMenuMetaContainer = document.getElementById('menuMetaContainer');
var objMenuDisplayContainer = document.getElementById('menuDisplayContainer');
var objmenuOrderContainer = document.getElementById('menuOrderContainer');
var objMenuDelContainer = document.getElementById('menuDelContainer');
var objButtonMenu = document.getElementById('buttonMenu');

function resetFormMenu() {
	//Remet par defaut les radio
	//Sous-menu
	document.getElementById('menuSubNo').className = "formRadioSelect";
	document.getElementById('menuSubYes').className = "formRadio";
	document.getElementById('menuSub').value = 0;
	//Log
	document.getElementById('menuLogNo').className = "formRadioSelect";
	document.getElementById('menuLogYes').className = "formRadio";
	document.getElementById('menuLog').value = 0;
	//Champ
	document.getElementById('menuChampNo').className = "formRadioSelect";
	document.getElementById('menuChampYes').className = "formRadio";
	document.getElementById('menuChamp').value = 0;
	//Display
	document.getElementById('menuDisplayNo').className = "formRadioSelect";
	document.getElementById('menuDisplayYes').className = "formRadio";
	document.getElementById('menuDisplay').value = 1;
	//Delete
	document.getElementById('menuDelNo').className = "formRadioSelect";
	document.getElementById('menuDelYes').className = "formRadio";
	document.getElementById('menuDel').value = 0;
		
	objMenuTitleContainer.style.display = "none";
	objMenuSubContainer.style.display = "none";
	objMenuLinkContainer.style.display = "none";
	objMenuSubSelectContainer.style.display = "none";
	objMenuDocContainer.style.display = "none";
	objMenuLogContainer.style.display = "none";
	objMenuChampContainer.style.display = "none";
	objMenuChampUniqContainer.style.display = "none";
	objMenuMetaContainer.style.display = "none";
	objButtonMenu.style.display = "none";
	objMenuDisplayContainer.style.display = "none";
	objmenuOrderContainer.style.display = "none";
	objMenuDelContainer.style.display = "none";
}

function selectMenuType(e) {
	resetFormMenu();
	
	//Parent
	if (e.value == "_parent") {
		//Affichage des elems
		objMenuTitleContainer.style.display = "block";
		objMenuLinkContainer.style.display = "none";
		objMenuSubContainer.style.display = "block";
		objMenuSubSelectContainer.style.display = "block";
		objMenuDocContainer.style.display = "block";
		objMenuLogContainer.style.display = "block";
		objMenuChampContainer.style.display = "block";
		objButtonMenu.style.display = "block";
		objMenuMetaContainer.style.display = "block";
		objmenuOrderContainer.style.display = "block";
	
	//Blank
	} else if (e.value == "_blank") {
		//Affichage des elems
		objMenuTitleContainer.style.display = "block";
		objMenuLinkContainer.style.display = "block";
		objMenuSubContainer.style.display = "none";
		objMenuSubSelectContainer.style.display = "block";
		objMenuLogContainer.style.display = "block";
		objMenuChampContainer.style.display = "block";
		objButtonMenu.style.display = "block";
		objmenuOrderContainer.style.display = "block";
	}
}

//Init menu form
function initFormMenu() {
	var array, arraySub;
	
	//Select edit menu
	objFormMenuLinkSelect.onchange = function () {
		if (this.value != "") window.open('?p=adminMenu&idLink=' + this.value, '_parent');
	}
	
	//Init les elem ayant un bg perso
	array = new Array('MenuTitle', 'MenuLink', 'MenuMetaTitle', 'MenuMetaDesc', 'MenuMetaKey');
	initInputOver(array);
	
	//Init le select order
	selectMenuOrder(document.getElementById('menuSubSelect'));
	
	//Init select
	array = new Array('menuType', 'menuDoc', 'menuSubSelect', 'menuMetaRobot', 'menuSubSelect');
	arraySub = new Array(); 
	arraySub[0] = new Array('selectMenuType(this)', false); //[onChange, onClick]
	arraySub[1] = new Array(false, false);
	arraySub[2] = new Array(false, false);
	arraySub[3] = new Array(false, false);
	arraySub[4] = new Array('selectMenuOrder(this)', false);
	initSelect(array, arraySub);
	
	//Init les radio
	array = new Array('menuSubYes', 'menuSubNo', 'menuLogYes', 'menuLogNo', 'menuChampYes', 'menuChampNo', 'menuDisplayYes', 'menuDisplayNo', 'menuDelYes', 'menuDelNo');
	arraySub = new Array('menuSub(this)', 'menuSub(this)', 'menuLog(this)', 'menuLog(this)', 'menuChamp(this)', 'menuChamp(this)', 'menuDisplay(this)', 'menuDisplay(this)', 'menuDel(this)', 'menuDel(this)');
	initRadio(array, arraySub);
	
	//Init button form
	array = new Array('MenuSave', 'MenuCancel');
	arraySub = new Array(); 
	arraySub[0] = new Array('initFormCheckMenu();');
	arraySub[1] = new Array("window.open('?p=adminMenu', '_parent');");
	initButton(array, arraySub);
}

//Init le submit du form Xsls
function initFormCheckMenu() {
	var form, i;
	
	form = document.getElementById('formMenu');
	
	//Si champ uniq
	if (objFormMenuType.value == "_parent") {
		arrayFormOptionCheck = new Array();
		
		arrayFormCheck = "'MenuTitle'";
		arrayFormOptionCheck[0] = new Array('noEmpty', 2, 25);
		i = 1;
		
		if (document.getElementById('menuSub').value == 0) {
			if (typeof(arrayLink) == "undefined" || arrayLink[9] == 1) {
				arrayFormCheck += ", 'menuDoc'";
				arrayFormOptionCheck[i] = new Array('noEmpty');
				i++;
			}
			
			arrayFormCheck += ", 'MenuMetaTitle'";
			arrayFormOptionCheck[i] = new Array('noEmpty', 5, 255);
			i++;
			
			arrayFormCheck += ", 'menuMetaRobot'";
			arrayFormOptionCheck[i] = new Array('noEmpty');
			i++;
		}
		
		arrayFormCheck = eval("new Array(" + arrayFormCheck + ")");
		
	//Si champ multi
	} else if (objFormMenuType.value == "_blank") {
		arrayFormOptionCheck = new Array();
		
		arrayFormCheck = "'MenuTitle'";
		arrayFormOptionCheck[0] = new Array('noEmpty', 2, 25);
		i = 1;
		
		arrayFormCheck += ", 'MenuLink'";
		arrayFormOptionCheck[i] = new Array('link');
		i++;
		
		arrayFormCheck = eval("new Array(" + arrayFormCheck + ")");
	
	//Si edit
	} else if (objFormMenuType.value == "" && arrayLink) {
		arrayFormOptionCheck = new Array();
		
		arrayFormCheck = "'MenuTitle'";
		arrayFormOptionCheck[0] = new Array('noEmpty', 2, 25);
		i = 1;
		
		arrayFormCheck = eval("new Array(" + arrayFormCheck + ")");
	
	//Sinon
	} else {
		openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Vous devez sélectionner un type de lien !");
	}
	
	//Si pas d"erreur
	if (!getCheckForm()) form.submit();
	else openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Vous n'avez pas saisie tous les champs nécessaires !");
}

//Affichage de l'edition
function initEditLink() {
	//Parent ou blank
	if (arrayLink[3] == "_parent" || arrayLink[3] == "_blank") {
		objFormMenuType.value = arrayLink[3];
		selectMenuType(objFormMenuType);
			
		//type edit
		if (arrayLink[9] == 0) {
			resetFormMenu();
			objMenuTitleContainer.style.display= "block";
			if (arrayLink[3] == "_parent") objMenuMetaContainer.style.display = "block";
			
		} else {
			objMenuSubContainer.style.display = "none";
			objMenuDisplayContainer.style.display = "block";
			objMenuDelContainer.style.display = "block";
		}
	
	//Submenu
	} else if (arrayLink[3] == "" && arrayLink) {
		resetFormMenu();
		document.getElementById('menuSub').value = 1;
			
		if (arrayLink[9] == 0) {
			objMenuTitleContainer.style.display = "block";
		
		} else {
			objMenuTitleContainer.style.display = "block";
			objMenuLogContainer.style.display = "block";
			objMenuChampContainer.style.display = "block";
			objMenuDisplayContainer.style.display = "block";
			objMenuDelContainer.style.display = "block";
		}
	}
	
	//Gestion d'affichage global
	objMenuTypeContainer.style.display = "none";
	objButtonMenu.style.display = "block";
	objmenuOrderContainer.style.display = "block";
	
	editLinkInsertValue(); //Suivant arrayLink
}

function editLinkInsertValue() {
	var tmp, start, end, e;
	//     0         1         2          3           4               5            6             7             8          9           10        11        12         13           14 		   15     || ID KEY ARRAY
	//menuTitle, menuLink, menuName, menuTarget, menuMetaTitle, menuMetaDesc, menuMetaKey, menuMetaRobots, menuParent, menuEdit, menuDisplay, menuSub, menuLoged, menuChamp, menuUniqChamp, menuOrder || SQL
	
	var start = arrayLink[1].indexOf('&', 0) + 7;
	var end = arrayLink[1].lastIndexOf('&', 50);
	
	//Insertion des données dans les forms
	document.getElementById('MenuTitle').value = arrayLink[0];
	document.getElementById('MenuLink').value = arrayLink[1];
	document.getElementById('menuDoc').value = arrayLink[1].substr(start, end-start);
	document.getElementById('MenuMetaTitle').value = arrayLink[4];
	document.getElementById('MenuMetaDesc').value = arrayLink[5];
	document.getElementById('MenuMetaKey').value = arrayLink[6];
	document.getElementById('menuMetaRobot').value = arrayLink[7];
	document.getElementById('menuChampUniq').value = arrayLink[14];
	
	//Si menu champ
	if (arrayLink[13] == 1) {
		document.getElementById('menuChamp').value = 0;
		menuChamp(document.getElementById('menuChampYes'));
		
		document.getElementById('menuChampUniq').value = arrayLink[14];	
	} else {
		document.getElementById('menuChamp').value = 1;
		menuChamp(document.getElementById('menuChampNo'));
	}
	
	//Si edit 0, on masque le uniq champqui est affiché dans menuChamp()
	if (arrayLink[9] == 0) objMenuChampUniqContainer.style.display = "none";
	
	//Affiche du lien
	if (arrayLink[10] == 1) {
		document.getElementById('menuDisplay').value = 0;
		menuDisplay(document.getElementById('menuDisplayNo'));
	} else {
		document.getElementById('menuDisplay').value = 1;
		menuDisplay(document.getElementById('menuDisplayYes'));
	}
	
	tmp = arrayLink[2].substr(4,10);
	document.getElementById('menuSubSelect').value = arrayLink[8];
	document.getElementById('menuDoc').value = tmp;
	
	//Init le select order & select la pos actu
	e = selectMenuOrder(document.getElementById('menuSubSelect'));
	if (e.length == arrayLink[15]) e.selectedIndex = e.length-1;
	else e.value = parseFloat(arrayLink[15]) + 1;
}

function selectMenuOrder(e) {
	var prefix = "menuOrder";
	
	//Reset all
	document.getElementById(prefix).style.display = "none";
	for (i=0; i<arrayMenu.length; i++) {
		if (arrayMenu[i] != "admin") document.getElementById(prefix + arrayMenu[i]).style.display = "none";
	}
	
	//Affichage
	document.getElementById(prefix + e.value).style.display = "block";
	
	return document.getElementById(prefix + e.value);
}


/***************************************************************************************************************/
/***************************************************NEWS********************************************************/
/***************************************************************************************************************/
objFormNewsSelect = document.getElementById('newsSelect');

//init config form
function initFormNews() {
	var array, arraySub;
	
	//Select edit menu
	objFormNewsSelect.onchange = function () {
		if (this.value != "") window.open('?p=adminNews&idNews=' + this.value, '_parent');
	}
	
	//Init les radio (function obligatoire : function e.id() {})
	array = new Array('newsDelYes', 'newsDelNo');
	arraySub = new Array('newsDel(this)', 'newsDel(this)');
	initRadio(array, arraySub);
	
	//Init les elem ayant un bg perso
	array = new Array('NewsTitle');
	initInputOver(array);
	
	//Init button form
	array = new Array('NewsSave', 'NewsCancel');
	arraySub = new Array(); 
	arraySub[0] = new Array('initFormCheckNews();');
	arraySub[1] = new Array("window.open('?p=adminNews', '_parent');");
	initButton(array, arraySub);
}

//Init le submit du form config
function initFormCheckNews() {
	var form;
	
	form = document.getElementById('formNews');
	
	arrayFormCheck = new Array('NewsTitle', 'newsContent');
		
	arrayFormOptionCheck = new Array();
	arrayFormOptionCheck[0] = new Array('noEmpty', 2, 255);
	arrayFormOptionCheck[1] = new Array('tinyMceNoEmpty');
	
	//Si pas d"erreur
	if (!getCheckForm()) form.submit();
	else openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Vous n'avez pas saisie tous les champs nécessaires !");
}

/***************************************************************************************************************/
/**************************************************CONFIG*******************************************************/
/***************************************************************************************************************/
//init config form
function initFormConfXsls() {
	var array, arraySub;
	
	//Init les elem ayant un bg perso
	array = new Array('NameXsls', 'EmailContact');
	initInputOver(array);
	
	//Init les radio (function obligatoire : function e.id() {})
	array = new Array('displayNameXslsYes', 'displayNameXslsNo', 'champTypeXslsUniq', 'champTypeXslsMulti');
	arraySub = new Array('displayNameXsls(this)', 'displayNameXsls(this)', 'champTypeXsls(this)', 'champTypeXsls(this)');
	initRadio(array, arraySub);
	
	//Init select
	array = new Array('formChampMulti', 'formAddAdmin');
	arraySub = new Array(); 
	arraySub[0] = new Array('formChampMultiAdd(this, this.text)', false); //[onChange, onClick]
	arraySub[1] = new Array('window.open("?p=adminConfig&action=addAdmin&idAdmin=" + this.value, "_parent")', false); //[onChange, onClick]
	initSelect(array, arraySub);
	
	//Init bt multi champ del
	if (arrayMultiChamp) initMultiChampDel();
	
	//Init button form
	array = new Array('ConfigSave', 'ConfigCancel');
	arraySub = new Array(); 
	arraySub[0] = new Array('initFormCheckConfXsls();');
	arraySub[1] = new Array("window.open('?p=adminConfig', '_parent');");
	initButton(array, arraySub);
	
	//Init add admin
	
}

//Init le submit du form config
function initFormCheckConfXsls() {
	var form;
	
	form = document.getElementById('formAdminChamp');
	
	//Si champ uniq
	if (document.getElementById('typeXsls').value == "uniq") {
		arrayFormCheck = new Array('NameXsls', 'EmailContact', 'formChampUniq');
		
		arrayFormOptionCheck = new Array();
		arrayFormOptionCheck[0] = new Array('noEmpty', 2, 255);
		arrayFormOptionCheck[1] = new Array('eMail');
		arrayFormOptionCheck[2] = new Array('noEmpty');
		
	//Si champ multi
	} else {
		arrayFormCheck = new Array('NameXsls', 'EmailContact', 'champMultiId');
		
		arrayFormOptionCheck = new Array();
		arrayFormOptionCheck[0] = new Array('noEmpty', 2, 255);
		arrayFormOptionCheck[1] = new Array('eMail');
		arrayFormOptionCheck[2] = new Array('noEmpty', 3); //3 = 2 champ insérés
	}
	
	//Si pas d"erreur
	if (!getCheckForm()) form.submit();
	else openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Vous n'avez pas saisie tous les champs nécessaires !");
}


//Ajout champ multi
function formChampMultiAdd(e, eText) {
	var valTest, val, eHidden, eChampContainer, eClone;
	
	eChampContainer = document.getElementById('ChampMultiContainer');
	eHidden = document.getElementById('champMultiId');
	
	if (e.value != "") {
		valTest = false;
		
		if (eHidden.value == "") {
			val = e.value;
			
		} else {
				val = "," + e.value;
				arrayChamp = eHidden.value.split(',');
				
				for (i=0; i<arrayChamp.length; i++) {
					if (arrayChamp[i] == e.value) valTest = true;
				}
		}
		
		//Contruction select css
		eClone = document.getElementById('formStyleXsls');
		eClone = eClone.cloneNode(true);
		eClone.id = "formStyleXslsChamp" + e.value;
		
		//Contruction del href
		eAhref = document.createElement('a');
		eAhref.setAttribute('href', '#');
		eAhref.setAttribute('onClick', 'formChampMultiDel(' + e.value + ')');
		eAhref.setAttribute('title', '');
		eAhref.innerHTML = "Supprimer";
		
		//Si valid
		if (!valTest) {
			eHidden.value += val;
			eChampContainer.innerHTML += '<li id="champId' + e.value + '">' + e.options[e.selectedIndex].text + '</li>';
			
			eLi = document.getElementById('champId' + e.value);
			eLi.appendChild(document.createElement('br'));
			eLi.appendChild(eClone);
			eLi.appendChild(document.createElement('br'));
			eLi.appendChild(eAhref);
			
			//Name (ie daube)
			document.getElementById("formStyleXslsChamp" + e.value).name = "formStyleXslsChamp" + e.value;
		}
		
		getChampError();
		
		//Remisa a la 1er option
		e.selectedIndex = 0;
		
	}
}

//Ajout champ multi
function formChampMultiDel(idChamp) {
	var eHidden, eChampContainer;
	
	eChampContainer = document.getElementById('ChampMultiContainer');
	eHidden = document.getElementById('champMultiId');
	
	if (eHidden.value.indexOf(",") != -1) {
		arrayChamp = eHidden.value.split(',');
		
		//Suppr dans le HIDDEN
		eHidden.value = "";
		for (i=0; i<arrayChamp.length; i++) {
			if (arrayChamp[i] != idChamp) {
				if (eHidden.value.length == 1) eHidden.value += ",";
				eHidden.value += arrayChamp[i];
				
			}
		}
	} else {
		eHidden.value = "";
	}
	
	//Suppr dans UL
	var parentli = document.getElementById("champId" + idChamp);
	var parentul = parentli.parentNode;
	parentul.removeChild(parentli);
	
	getChampError();
}

//Affiche l'erreur list multy champ
function getChampError() {
		var eNeed, eHidden, arrayChamp;
		
		eNeed = document.getElementById('champNeed');
		eHidden = document.getElementById('champMultiId'); 
		arrayChamp = eHidden.value.split(',');
		
		
		if (eHidden.value == "" || arrayChamp.length <= 1) {
			eNeed.style.display = 'block';
			return true;
			
		} else {
			eNeed.style.display = 'none';
			return false;
		}
}


/***************************************************************************************************************/
/*************************************************DOCUMENTS*****************************************************/
/***************************************************************************************************************/
//Init selection doc
function initDocSelect(e) {
	e = document.getElementById('docSelect');
	
	e.onchange = function () {
		if (this.value != "") window.open('?p=adminDocs&idDoc=' + this.value, '_parent');
	}
}

function initFormDoc() {
	var array, arraySub;
	
	//Init les elem ayant un bg perso
	array = new Array('NameDoc');
	initInputOver(array);
	
	//Init les radio (function obligatoire : function e.id() {})
	array = new Array('docDelYes', 'docDelNo');
	arraySub = new Array('docDel(this)', 'docDel(this)');
	initRadio(array, arraySub);
	
	
	//Init button form
	array = new Array('DocSave', 'DocCancel');
	arraySub = new Array();
	arraySub[0] = new Array('initFormCheckDoc();');
	arraySub[1] = new Array("window.open('?p=adminDocs', '_parent');");
	initButton(array, arraySub);
}

//Init checking form
function initFormCheckDoc() {
	var form, txt;
	
	form = document.getElementById('formDoc');
	
	arrayFormCheck = new Array('NameDoc', 'docContent');
		
	arrayFormOptionCheck = new Array();
	arrayFormOptionCheck[0] = new Array('noEmpty', 2, 150);
	arrayFormOptionCheck[1] = new Array('tinyMceNoEmpty');
	
	//Si pas d"erreur
	if (!getCheckForm()) form.submit();
	else openAlert('alertContainerError', "SAUVEGARDE IMPOSSIBLE", "Vous n'avez pas saisie tous les champs nécessaires !");
}


/***************************************************************************************************************/
/************************************************RADIO FUNC*****************************************************/
/***************************************************************************************************************/
//Affiche le nam XSLS
function displayNameXsls(e) {
	var eValue = document.getElementById('displayNameXsls');
	
	if (eValue.value == 0) {
		e.className = "formRadioSelect";
		document.getElementById('displayNameXslsNo').className = "formRadio";
		eValue.value = 1;
	} else {
		e.className = "formRadioSelect";
		document.getElementById('displayNameXslsYes').className = "formRadio";
		eValue.value = 0;
	}
}


//Config unique champ
function champTypeXsls(e) {
	var eValue = document.getElementById('typeXsls');
	
	if (eValue.value == "multi" && e.id == 'champTypeXslsUniq') {
		e.className = "formRadioSelect";
		document.getElementById('champTypeXslsMulti').className = "formRadio";
		eValue.value = "uniq";
		
		document.getElementById('adminChampUniq').style.display = "block";
		document.getElementById('adminChampMulti').style.display = "none";
	} else if (eValue.value == "uniq" && e.id == 'champTypeXslsMulti') {
		e.className = "formRadioSelect";
		document.getElementById('champTypeXslsUniq').className = "formRadio";
		eValue.value = "multi";
		
		document.getElementById('adminChampMulti').style.display = "block";
		document.getElementById('adminChampUniq').style.display = "none";
	}
}

//Menu sub
function menuSub(e) {
	var eValue = document.getElementById('menuSub');
	
	if (eValue.value == 0 && e.id == 'menuSubYes') {
		e.className = "formRadioSelect";
		document.getElementById('menuSubNo').className = "formRadio";
		eValue.value = 1;
		
		objMenuSubSelectContainer.style.display = "none";
		objMenuDocContainer.style.display = "none";
		objMenuMetaContainer.style.display = "none";
	} else if (eValue.value == 1 && e.id == 'menuSubNo') {
		e.className = "formRadioSelect";
		document.getElementById('menuSubYes').className = "formRadio";
		eValue.value = 0;
		
		objMenuSubSelectContainer.style.display = "block";
		objMenuDocContainer.style.display = "block";
		objMenuMetaContainer.style.display = "block";
	}
}

//Menu log
function menuLog(e) {
	var eValue = document.getElementById('menuLog');
	
	if (eValue.value == 0 && e.id == 'menuLogYes') {
		e.className = "formRadioSelect";
		document.getElementById('menuLogNo').className = "formRadio";
		eValue.value = 1;
	} else if (eValue.value == 1 && e.id == 'menuLogNo') {
		e.className = "formRadioSelect";
		document.getElementById('menuLogYes').className = "formRadio";
		eValue.value = 0;
	}
}

//Menu champ
function menuChamp(e) {
	var eValue = document.getElementById('menuChamp');
	
	if (eValue.value == 0 && e.id == 'menuChampYes') {
		e.className = "formRadioSelect";
		document.getElementById('menuChampNo').className = "formRadio";
		eValue.value = 1;
		
		objMenuChampUniqContainer.style.display = "block";
	} else if (eValue.value == 1 && e.id == 'menuChampNo') {
		e.className = "formRadioSelect";
		document.getElementById('menuChampYes').className = "formRadio";
		eValue.value = 0;
		
		objMenuChampUniqContainer.style.display = "none";
	}
}

//Menu edit
function menuDisplay(e) {
	var eValue = document.getElementById('menuDisplay');
	
	if (eValue.value == 1 && e.id == "menuDisplayYes") {
		e.className = "formRadioSelect";
		document.getElementById('menuDisplayNo').className = "formRadio";
		eValue.value = 0;
	} else if (eValue.value == 0 && e.id == "menuDisplayNo") {
		e.className = "formRadioSelect";
		document.getElementById('menuDisplayYes').className = "formRadio";
		eValue.value = 1;
	}
}

//Menu del
function menuDel(e) {
	var eValue = document.getElementById('menuDel');
	
	if (eValue.value == 1 && e.id == 'menuDelNo') {
		e.className = "formRadioSelect";
		document.getElementById('menuDelYes').className = "formRadio";
		eValue.value = 0;
	} else if (eValue.value == 0 && e.id == 'menuDelYes') {
		e.className = "formRadioSelect";
		document.getElementById('menuDelNo').className = "formRadio";
		eValue.value = 1;
	}
}

//Partners del
function partnersDel(e) {
	var eValue = document.getElementById('partnersDel');
	
	if (eValue.value == 1 && e.id == 'partnersDelNo') {
		e.className = "formRadioSelect";
		document.getElementById('partnersDelYes').className = "formRadio";
		eValue.value = 0;
	} else if (eValue.value == 0 && e.id == 'partnersDelYes') {
		e.className = "formRadioSelect";
		document.getElementById('partnersDelNo').className = "formRadio";
		eValue.value = 1;
	}
}

//Prequal del
function prequalDel(e) {
	var eValue = document.getElementById('prequalDel');
	
	if (eValue.value == 1 && e.id == 'prequalDelNo') {
		e.className = "formRadioSelect";
		document.getElementById('prequalDelYes').className = "formRadio";
		eValue.value = 0;
	} else if (eValue.value == 0 && e.id == 'prequalDelYes') {
		e.className = "formRadioSelect";
		document.getElementById('prequalDelNo').className = "formRadio";
		eValue.value = 1;
	}
}

//Docs del
function docDel(e) {
	var eValue = document.getElementById('docDel');
	
	if (eValue.value == 1 && e.id == 'docDelNo') {
		e.className = "formRadioSelect";
		document.getElementById('docDelYes').className = "formRadio";
		eValue.value = 0;
	} else if (eValue.value == 0 && e.id == 'docDelYes') {
		e.className = "formRadioSelect";
		document.getElementById('docDelNo').className = "formRadio";
		eValue.value = 1;
	}
}

//News del
function newsDel(e) {
	var eValue = document.getElementById('newsDel');
	
	if (eValue.value == 1 && e.id == 'newsDelNo') {
		e.className = "formRadioSelect";
		document.getElementById('newsDelYes').className = "formRadio";
		eValue.value = 0;
	} else if (eValue.value == 0 && e.id == 'newsDelYes') {
		e.className = "formRadioSelect";
		document.getElementById('newsDelNo').className = "formRadio";
		eValue.value = 1;
	}
}

//autoconnect
function autoConnect(e) {
	var eValue = document.getElementById('autoConnect');
	
	if (eValue.value == 1 && e.id == 'autoConnectNo') {
		e.className = "formRadioSelect";
		document.getElementById('autoConnectYes').className = "formRadio";
		eValue.value = 0;
	} else if (eValue.value == 0 && e.id == 'autoConnectYes') {
		e.className = "formRadioSelect";
		document.getElementById('autoConnectNo').className = "formRadio";
		eValue.value = 1;
	}
}


/***************************************************************************************************************/
/***************************************************FORM********************************************************/
/***************************************************************************************************************/
var fromBg = new Array('images/form_bg.gif', 'images/form_over_bg.gif', 'images/form_error_bg.gif');
var formTextareaBg = new Array('images/form_textarea_bg.gif', 'images/form_textarea_over_bg.gif', 'images/form_textarea_error_bg.gif');
var formButtonBg = new Array('images/button_bg.gif', 'images/button_over_bg.gif');
var formTag = 'formTag';
var formStart = 'formStart';
var formContent = 'formContent';
var formEnd = 'formEnd';
var buttonStart = 'buttonStart';
var buttonContent = 'buttonContent';
var buttonEnd = 'buttonEnd';
var ObjForm = false;

//Change le bg du form
function getNewBgForm(e, bgType) {
	var bgLink;
	
	if (e.type == "textarea") {
		prefixVarDiv = "Textarea";
		var bgLink = formTextareaBg[bgType];
	} else {
		var prefixVarDiv = "";
		bgLink = fromBg[bgType];
	}
		
	document.getElementById(formStart + e.id).style.backgroundImage = "url(" + bgLink + ")";
	document.getElementById(formContent + e.id).style.backgroundImage = "url(" + bgLink + ")";
	document.getElementById(formEnd + e.id).style.backgroundImage = "url(" + bgLink + ")";
}

//Change le bg du form
function getNewBgButton(e, bgType) {	
	document.getElementById(buttonStart + e.id).style.backgroundImage = "url(" + formButtonBg[bgType] + ")";
	document.getElementById(buttonContent + e.id).style.backgroundImage = "url(" + formButtonBg[bgType] + ")";
	document.getElementById(buttonEnd + e.id).style.backgroundImage = "url(" + formButtonBg[bgType] + ")";
}

//Init button
function initButton(array, arraySub) {
	var i, e;
	
	for (i=0; i<array.length; i++) {
		e = document.getElementById(array[i]);
		
		e.onmouseover = function () { getNewBgButton(this, 1); }
		e.onmouseout = function () { getNewBgButton(this, 0); }
		
		if (arraySub[i][0]) eval('e.onclick = function () { ' + arraySub[i][0] + ' }');
	}
}

//Init les elem ayant un bg perso
function initInputOver(array) {
	var i, e;
	
	for (i=0; i<array.length; i++) {
		e = document.getElementById(array[i]);
		
		e.onfocus = function () { getNewBgForm(this, 1); }
		e.onblur = function () { getNewBgForm(this, 0); }
	}
}

//Init les radio
function initRadio(array, arraySub) {
	for (i=0; i<array.length; i++) {
		e = document.getElementById(array[i]);
		
		eval('e.onclick = function () { ' + arraySub[i] + ' }');
	}
}

//Init select
function initSelect(array, arraySub) {
	//arraySub : [onChange, onClick]
	var i;
	
	for (i=0; i<array.length; i++) {
		e = document.getElementById(array[i]);
		
		if (arraySub[i][0]) eval('e.onchange = function () { ' + arraySub[i][0] + ' }');
		if (arraySub[i][1]) eval('e.onclick = function () { ' + arraySub[i][1] + ' }');
	}
}

//Init bt multi champ del
function initMultiChampDel() {
	var i;
	
	for (i=0; i<arrayMultiChamp.length; i++) {
		e = document.getElementById(prefixMultiChampDel + arrayMultiChamp[i]);
		eval ('e.onclick = function () { formChampMultiDel(' + arrayMultiChamp[i] + '); }')
	}
}

//Check le form
function getCheckForm() {
	var i, e, error;
	
	//Verif alert
	if (alertStatus) return false;
	
	arrayFormCheckError = new Array();
	
	if (arrayFormCheck.length) {
		for (i=0; i<arrayFormCheck.length; i++) {
			error = false;
			e = document.getElementById(arrayFormCheck[i]);
			
			if (e.type == "text" || e.type == "textarea" || e.type == "hidden") {
				if (arrayFormOptionCheck[i][0] == "noEmpty" || arrayFormOptionCheck[i][0] == "txtOnly") {
					
					//Verifie si vide
					if (arrayFormOptionCheck[i][0] == "noEmpty" && e.value == "") {
						arrayFormCheckError[i] = "formErrorEmpty";
						error = true;
						
					} else if (arrayFormOptionCheck[i][0] == "txtOnly") {
						var reg1 = new RegExp("[0-9]");
						if (e.value.match(reg1)) {
							arrayFormCheckError[i] = "formErrorRegExp";
							error = true;
						}
					}
					
					//Verifie si longueur est inf au minimun
					if (arrayFormOptionCheck[i][1] && !error) {
						if (e.value.length < arrayFormOptionCheck[i][1]) {
							arrayFormCheckError[i] = "formErrorLengthMin";
							error = true;
						}
					
					//Verifie si longueur est sup au maximun
					} else if (arrayFormOptionCheck[i][2] && !error) {
						if (e.value.length > arrayFormOptionCheck[i][2]) {
							arrayFormCheckError[i] = "formErrorLengthMax";
							error = true;
						}
					}
					
					//Affichage erreur
					if (e.type == "text" || e.type == "textarea") {
						if (error) getNewBgForm(e, 2);
						else getNewBgForm(e, 0);
					}
				
				//EMail
				} else if (arrayFormOptionCheck[i][0] == "eMail") {
					if (e.value.indexOf('@') < 1 || e.value.indexOf('@') == 1 || e.value.indexOf('.') == -1 || e.value.length < (e.value.lastIndexOf('.')+2)) {
						arrayFormCheckError[i] = "formErrorEmail";
						error = true;
						
						if (error) getNewBgForm(e, 2);
						else getNewBgForm(e, 0);
					}
					
				//Link
				} else if (arrayFormOptionCheck[i][0] == "link") {
					if (e.value.substr(0, 7) != 'http://') {
						arrayFormCheckError[i] = "formErrorLink";
						error = true;
						
						if (error) getNewBgForm(e, 2);
						else getNewBgForm(e, 0);
					}
				
				//TinyMce
				} else if (arrayFormOptionCheck[i][0] == "tinyMceNoEmpty") {
					if (tinyMCE.activeEditor.getContent() == "") {
						arrayFormCheckError[i] = "formErrorEmpty";
						error = true;
					}
					
					if (error) document.getElementById(e.id + "_tbl").style.border = "1px solid #880000";
					else {
						document.getElementById(e.id + "_tbl").style.border = "0px";
						document.getElementById(e.id + "_tbl").style.borderRight = "1px solid #ABC6DD";
						document.getElementById(e.id + "_tbl").style.borderLeft = "1px solid #ABC6DD";
					}
				
				//Type float : parseFloat(val)
				
				} else {
					alert('TypeCheck unknow : ' + arrayFormOptionCheck[i][0]);
				}
			
			//SELECT
			} else if (e.type == "select-one") {
				
				//Verifie si vide
				if (arrayFormOptionCheck[i][0] == "noEmpty") {
					//Verifie si vide
					if (e.value == "") {
						arrayFormCheckError[i] = "formErrorEmpty";
						error = true;
					}
					
					//Affichage erreur
					if (error) e.className = "inputSelectError";
					else e.className = "inputSelect";
					
				} else {
					alert('TypeCheck unknow : ' + arrayFormOptionCheck[i][0]);
				}
			
			//UNKNOW TYPE
			} else {
				alert('Type unknow : ' + e.type);
			}
		}
		
		return arrayFormCheckError.length;
	} else {
		return false;
	}
}

//Annule la condif champ
function formAdminChampCancel(e) {
	window.open('?p=adminConfigGlobal', '_parent');
}
