var gb_urlCurrDiv = '';
var gb_onceMls = false;
var gb_lock = false;
var newSoftware = false;


function openFeedback() {
	var params = 'todo=open_feedback';
	new Ajax.Updater('lightbox_content', 'ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onSuccess: function(t) {
			openLightBox();
		}
	});
}

function isEnter(keyCode) {
	return keyCode==13;
}

function getKeyPressed(ev) {
	return ev.keyCode;
}

// 300px -> 300
function sizeToInt(strSize) {
	return parseInt(strSize.replace(/px$/, ''), 10);
}

function isGuid(guid, strictMode) {
	if(strictMode) return guid.match(/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i);
	else		   return guid.match(/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/i);
}

function displayAjaxSWF(container) {
	var tabObjects = $$('#'+container+' object');
	if(tabObjects.length > 0) {
		// Opera bug
		tabObjects[0].show();
		tabObjects[0].focus();
	}
}

function reloadPage() {
	window.location.reload();
}

function hideLightBox() {
	var lb = $('div_full_black');
	lb.hide();
}

function showPrevLightbox() {
	var lb = $('div_full_black');
	lb.setStyle({
		opacity: '0.5'
	});
	lb.show();
}

function confirmSendFeedback() {
	var params = 'todo=send_feedback&txt='+encodeURIComponent($F('txt_feedback'));
	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onSuccess: function(t) {
			if(t.responseText == 'true') {
				updateNotification({
					divID: 'feedback_notification',
					typeMess: 'success',
					mess: 'Thank you for your feedback',
					delayVisible: 2000,
					callback: reloadPage
				});
			} else {
				updateNotification({
					divID: 'feedback_notification',
					typeMess: 'warning',
					mess: 'Please enter a real message to help us improving our product',
					delayVisible: 2000
				});
			}
		}
	});
	return false;
}

function jsPrintr(obj) {
	var mess = obj+" {\n";
	for(var i in obj) {
		mess += "  "+i+" : "+obj[i]+"\n";
	}
	mess += "}";
	alert(mess);
}

function jsTrim(str) {
	return str.replace(/(^\s+)|(\s+$)/g, '');
}

function returnFalse() {
	return false;
}

function clearNode(node) {
	while(node.hasChildNodes()) {
		node.removeChild(node.firstChild);
	}
}

function startProcessing() {
	var obj = $('table_header');
	if(obj != null) {
		obj.addClassName('content_header_wait');
	}
}

function endProcessing() {
	var obj = $('table_header');
	if(obj != null) {
		obj.removeClassName('content_header');
		obj.removeClassName('content_header_wait');
		obj.addClassName('content_header');
	}
}

function initPage() {
	initDimensions();
	initBlanks();
}

function initBlanks() {
	$$('a._blank').each(function(link) {
		link.onclick = function() {
			window.open(this.href);		
			return false;
		}
	});
}

function initDimensions() {
	if (window.innerWidth) gb_posX = window.innerWidth;
	else if (document.body && document.body.offsetWidth) gb_posX = document.body.offsetWidth;
	else gb_posX = screen.width;

	if (window.innerHeight) gb_posY = window.innerHeight;
	else if (document.body && document.body.offsetHeight) gb_posY = document.body.offsetHeight;
	else gb_posY = screen.height;
}

function showElement(idElement, typeElement) {
	if(document.getElementById(idElement) != null) {
		document.getElementById(idElement).style.display = typeElement;
	}
	return false;
}

function hideElement(idElement, delay) {
	if(document.getElementById(idElement) != null) {
		if(delay > 0) {
			setTimeout("document.getElementById('"+idElement+"').style.display = 'none';", delay);
		} else {
			document.getElementById(idElement).style.display = 'none';
		}
	}
	return false;
}

function displayCenter(div, w, h){
	var posX = (gb_posX-w)/2;
	var posY = (gb_posY-h)/5;
	
	if(newSoftware) {
		var scrollTop = 0;
		if(document.body.scrollTop>0)				  scrollTop = document.body.scrollTop;
		else if (document.documentElement.scrollTop>0) scrollTop = document.documentElement.scrollTop;
		else if(window.pageYOffset>0)				  scrollTop = window.pageYOffset;
		posY += scrollTop;
	}

	document.getElementById(div).style.left = posX+'px';
	document.getElementById(div).style.top  = posY+'px';
}

function affichprix(val,virgule,thousand,dec) {
	val = val.toString();
	place_virgule = val.indexOf(virgule);
	if(place_virgule>-1){
		valeur_dec = val.substr(place_virgule,3);
		valeur = Math.round(suppr_espace(val.substr(0,place_virgule)));
	}else{
		valeur = Math.round(suppr_espace(val));
		valeur_dec = '';
	}
	new_valeur = '';
	if(!isNaN(valeur) && valeur > 0){
		valeur = valeur.toString();
		if(valeur.length > 3){
			for(i = valeur.length-3; i>0; i = i-3){
				valeur = valeur.substr(0,i)+thousand+valeur.substr(i);
			}
		}
		if(dec && valeur_dec.length<3){
			valeur_dec = valeur_dec.substr(1,2)+'00';
			valeur_dec = virgule+valeur_dec.substr(0,2);
		}
		return valeur+valeur_dec;
	}else{
		return val.substr(0,val.length-1);
	}
	return '';
}

function suppr_espace(old_str) {
	return old_str.replace(/ |,/g, '');
}

/********************/
/*** New Lightbox ***/
/********************/
function openLightBox() {
	if(arguments.length>0) {
		// Custom lightbox size
		if(arguments[0].addClass != null) {
			$('lightbox').addClassName( arguments[0].addClass );
		}
	}
	displayCenter('lightbox', $('lightbox').getWidth(), 300);
	showPrevLightbox();
	showElement('lightbox', 'block');
	return false;
}

function openAlertBox() {
	var aBox = $('alertbox');
	if(arguments.length>0 && arguments[0].addClass != null) {
		aBox.addClassName( arguments[0].addClass );
	}
	
	var width = aBox.getWidth();
	if( isNaN(width) ) width = 600;
	displayCenter('alertbox', width, 100);
	aBox.show();
//	$('div_full_black').addClassName('div_full_black_hidden').show();
}

function closeAlertBox() {
	var div = $('alertbox');
	if(div != null) {
		// remove all class names with =/= width to get standard alertbox
		div.className = 'alertbox';
		div.hide();
	}
	$('div_full_black').removeClassName('div_full_black_hidden').hide();
	return false;
}

function closeLightBox() {
	$('lightbox').removeClassName('lightbox_video');
	$('lightbox').removeClassName('lightbox_images');
	$('lightbox_content').update('');
	hideElement('lightbox', 0);
	hideLightBox();
	return false;
}

/*
 *  @obj {
 *	divID: id of the <div> to update
 *	typeMess: type of message for correct style (warning|success)
 *	mess: message to display
 *	delayVisible: time in ms after the <div> disappears. values <= 0 if not.
 *	callback: Launch a fonction on end
 *  }
 */
function updateNotification(obj) {
	var div = $(obj.divID);

	// remove all styles
	div.removeClassName('messwarn');
	div.removeClassName('messgood');
	div.removeClassName('messinfo');

	hideElement(obj.divID, 0);

	// add correct style
	if(obj.typeMess.toLowerCase()=='warning') {
		div.addClassName('messwarn');
	} else if(obj.typeMess.toLowerCase()=='success') {
		div.addClassName('messgood');
	} else if(obj.typeMess.toLowerCase()=='info') {
		div.addClassName('messinfo');
	}

	// update message
	if(obj.mess.length > 0) {
		div.update(obj.mess);
	}

	// timer if <div> needs to be hidden
	if(obj.delayVisible > 0) {
		hideElement(obj.divID, obj.delayVisible);
	}

	// callback function on end
	if(obj.callback != null && typeof(obj.callback)=='function') {
		setTimeout(obj.callback, obj.delayVisible);
	}

	// display <div>
	showElement(obj.divID, 'block');
}


/***************/
/**** Login ****/
/***************/
function getMail() {
	var mail = document.getElementById('email').value;
	if(mail.match(/^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)$/)) {
		var params = 'todo=get_mail&mail='+mail;
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onComplete: function(t) {
				var node = document.getElementById('send_result');
				var mess = '';
				clearNode(node);

				if(t.responseText == 'true') {
					mess = mailSendOK;
					hideElement('lost_password', 1500);
				} else {
					mess = mailSendKO.replace(/#MAIL#/, document.getElementById('email').value);
				}
				node.appendChild(document.createTextNode(mess));
			}
		});
	}
	return false;
}


function check_form(ereg){
	var fields = ['todo','nom_utilisateur','prenom_utilisateur','adresse','ville','etat','code_postal','id_pays','telephone_utilisateur','email_utilisateur','id_adresse_facturation'];
	var params = '';
	var tab_fields=['nom_utilisateur','prenom_utilisateur','adresse','ville','code_postal','email_utilisateur'];
	var valid_mail = false;
	var empty_fields=[];

	//resettings
	$('message_box').update('');

	for(var i=0;i<tab_fields.length;i++){
		f_name = tab_fields[i];
		f_value = $(f_name).value;

		if(f_value==""){
			$(f_name).addClassName('input_warn');
			empty_fields.push(f_name);
		}
		else{
			if(f_name=='email_utilisateur'){
				//test email address validity
				var pattern = new RegExp(ereg);
				var valid_mail = pattern.test(f_value);

				if(!valid_mail) $(f_name).addClassName('input_warn');
				else $(f_name).removeClassName('input_warn');
			}
			else{
				$(f_name).removeClassName('input_warn');
			}
		}
	}

	if(empty_fields.length==0 && valid_mail){
		//do ajax post
		for(var i=0;i<fields.length;i++){
			f_name = fields[i];
			if($(f_name)!=null) {
				f_value = $(f_name).value;
				if(i==0) params+=f_name+"="+f_value;
				else  params+="&"+f_name+"="+f_value;
			}
		}

		startProcessing();

		new Ajax.Request('ajax.php',{
			asynchronous: true,
			evalScripts: false,
			postBody: params,
			onSuccess: function(data){
				$('add_facturation').update(data.responseText);
				endProcessing();
			}
		});

		return false;
	}
	else return false;
}


/***************************************/
/****  Formulaire recherche visites ****/
/***************************************/
function setTri(idTri){
	for(var i=1; i<=7; i++){
		var imgTri = document.getElementById('img_tri_'+i);
		if(imgTri != null) {
			if(i == idTri){
				if(imgTri.src.match(/arrow_asc/)){
					imgTri.src = 'images/arrow_desc.gif';
					gb_tri = i;
				}else{
					imgTri.src = 'images/arrow_asc.gif';
					gb_tri = -i;
				}
				imgTri.style.display = 'inline';
			}else{
				imgTri.style.display = 'none';
			}
		}
	}
	gb_currentPage = 1;
	return getListTours();
}

function getListTours(){
	if(gb_currentMode=='normal') {
		var ref   = document.getElementById('fs_ref') != null   ? document.getElementById('fs_ref').value   : '';
		var city  = document.getElementById('fs_city') != null  ? document.getElementById('fs_city').value  : '';
		var price = document.getElementById('fs_price') != null ? document.getElementById('fs_price').value : '';
		var zip   = document.getElementById('fs_zip') != null   ? document.getElementById('fs_zip').value   : '';
		var divToUpdate = 'div_list_tour';
	} else {
		var divToUpdate = 'div_list_tour_bundle';
	}
	var nbResPage = gb_resPage;
	var zoneRes   = document.getElementById(divToUpdate);

	if(gb_fullList){
		if(gb_currentMode=='normal') {
			ref   = document.getElementById('fs_ref').value   = '';
			city  = document.getElementById('fs_city').value  = '';
			price = document.getElementById('fs_price').value = '';
			zip   = document.getElementById('fs_zip').value   = '';
			if(document.getElementById('fs_mls')!=null) {
				document.getElementById('fs_mls').value = '';
			}
		}
		gb_currentPage = 1;
		nbResPage = -1;
	}else{
		if(gb_changement){
			gb_currentPage = 1;
		}
	}

	var params = 'todo=list_tour&tri='+gb_tri+'&num_page='+gb_currentPage+'&res_page='+nbResPage+'&mode='+gb_currentMode;
	if(gb_currentMode=='normal') {
		params += '&ref='+ref+'&city='+city+'&price='+price+'&zip='+zip;
	}
	if(document.getElementById('fs_mls')!=null) {
		params += '&mls='+document.getElementById('fs_mls').value
	}

	clearNode(zoneRes);

	new Ajax.Updater(divToUpdate, 'ajax.php', {
		asynchronous: true,
		evalScripts: false,
		postBody: params,
		onSuccess: function(t) {
			var comm = t.responseText.match(/<!--[0-9]*-->/);
			var nbTours = parseInt(comm[0].replace(/[^0-9]*/g, ''));

			var span = document.getElementById('nb_tours');
			if(span != null) {
				clearNode(span);
				span.appendChild(document.createTextNode(nbTours));
			}

			if(nbTours%gb_resPage == 0) gb_maxPage = nbTours/gb_resPage;
			else gb_maxPage = Math.floor(nbTours/gb_resPage) + 1;

			clearNode(document.getElementById('p_navigation_top'));
			clearNode(document.getElementById('p_navigation_bottom'));

			if(gb_maxPage > 1) {
				if(nbTours > 0 && !gb_fullList) {
					updateLinkNav('p_navigation_top', '-');
					updateLinkNav('p_navigation_bottom', '-');
				}
			}
		}
	});
	gb_changement = false;

	return false;
}

function switchMode(link) {
	var textLink  = '';
	var linkNode  = document.getElementById('switch_mode');
	clearNode(linkNode);
	if(gb_fullList){
		textLink  = gb_messDisplayPage;
		linkNode.onclick = function (){
			gb_fullList = false;
			switchMode(this);
			return getListTours();
		}
	}else{
		textLink = gb_messDisplayAll;
		linkNode.onclick = function (){
			gb_fullList = true;
			switchMode(this);
			return getListTours();
		}
	}
	linkNode.appendChild(document.createTextNode(textLink));
}


function highlightRowTour(tr, originalClassName) {
	tr.originalClass = originalClassName;
	tr.className = 'highlight';
	if(tr.style.cursor != null) {
		tr.style.cursor = 'pointer';
	}
}

function updateLinkNav(container, separator){
	var limit = gb_limitLinks;

	var params = 'todo=update_link_nav&max_page='+gb_maxPage+'&current='+gb_currentPage+'&limit='+gb_limitLinks+'&mode='+gb_currentMode;
	new Ajax.Updater(container, 'ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params
	});

}
/**** Fin *****/



/********************************/
/****   Suppression visite   ****/
/********************************/
function openDeleteTour(tour) {
	var params = 'todo=open_delete_tour&tour='+tour;
	new Ajax.Updater('alertbox_content', 'ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			if(t.responseText.length>0) {
				openAlertBox();
			} else {
				closeAlertBox();
			}
		}
	});
}


function confirmDeleteTour(tour) {
	var params = 'todo=delete_tour&tour='+tour;
	var toRedirect = document.location.href.indexOf('list_tour.php') == -1;

	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onSuccess: function(t) {
			if(t.responseText=='true'){
				if(toRedirect) {
					window.location.href = 'list_tour.php';
				}else{
					closeAlertBox();
					getListTours();
				}
			}
		}
	});
}

function deleteTour(idTour) {
	if(confirm(gb_messConfirmDelete)) {
		var params = 'todo=delete_tour&tour='+idTour;
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onSuccess: function(t) {
				if(t.responseText=='true'){
					if(!gb_redirect) {
						getListTours();
					}else{
						window.location.href = 'list_tour.php';
					}
				}
			}
		});
	}
	return false;
}

function deleteTourBundle(idTour) {
	window.location.href = 'delete_tour.php?tour='+idTour;
	return false;
}


/***************************/
/****   Apercu visite   ****/
/***************************/
function viewTour(idTour) {
	var popView = window.open(gb_urlViewer.replace(/#ID#/, idTour), 'popView', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1024,height=768');
	popView.focus();
	return false;
}

function getUrlTour(idTour) {
	var params = 'todo=get_url_tour&tour='+idTour;
	var toUpdate = newSoftware ? 'alertbox_content' : 'lightbox_content';
	new Ajax.Updater(toUpdate, 'ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onSuccess: function(t) {
			if(newSoftware) openAlertBox({
				addClass: 'alertbox_geturl'
			});
			else openLightBox();
		}
	});
	return false;
}

function openGeneric(w, h) {
	var div = $('div_float_generic');
	gb_urlCurrDiv = 'div_float_generic';
	if(isNaN(h)) {
		displayCenter('div_float_generic', w, Math.ceil(w*3.0/4.0));
	} else {
		displayCenter('div_float_generic', w, h);
	}

	if(isNaN(w)) finalW = '400px';
	else finalW = w+'px';
	if(isNaN(h)) finalH = 'auto';
	else finalH = h+'px';

	div.update('');

	if(!document.all) {
		div.setStyle({
			width: finalW,
			height: finalH
		});
	} else {
		div.setAttribute('width', finalW);
		div.setAttribute('height', finalH);
	}

	if(document.all) {
		updateSelectDisplay('', 'none');
	}
	showPrevLightbox();
	showElement('div_float_generic', 'block');
}


function setOpacity(id, level) {
	var obj = null;

	if(typeof(id)=='string') {
		obj = document.getElementById(id);
	} else if(typeof(id)=='object') {
		obj = id;
	}

	if(obj != null) {
		if(obj.style.opacity != null) {
			obj.style.opacity = level/100;
		} else if(obj.style.filter != null) {
			obj.style.filter = 'alpha(opacity='+level+')';
		}
	}
}

function displayHelp(page) {
	if(parent.length==0) {
		gb_urlCurrDiv = 'help';
		if(document.all) {
			updateSelectDisplay('', 'none');
		}
		displayCenter('help_window', 720, 540);
		showPrevLightbox();
		showElement('help_window', 'block');
		new Ajax.Updater('help_window', 'help.php?page='+page, {asynchronous: true, evalScripts: false});
	} else {
		var popHelp = window.open('help.php?mode=page&page='+page, 'popHelp', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=720,height=540');
		popHelp.focus();
	}
	return false;
}

function closeCurrentDiv(){
	switch(gb_urlCurrDiv){
		case 'help':
			closeHelp();
			break;
		case 'reprocess':
			if(gb_levelBrightness != parseInt(document.getElementById('brightness_value').value, 10)){
				if(confirm(gb_messChangeBrightness)) {
					postBrightness(parseInt(document.getElementById('brightness_value').value, 10));
				}
			}
			closeReprocess();
			break;
		case 'sendmobile':
			closeSendMobile();
			break;
		case 'documents':
			closeHelpLinks();
			break;
		case 'details':
			closeDetails();
			break;
		case 'degraded':
			closeDegraded();
			break;
		case 'mail_integration':
			closeMailIntegration();
			break;

		case 'div_floorplanner':
			closeFloorplanner();
			break;
		case 'div_float_generic':
			if(document.all) {
				updateSelectDisplay('', 'block');
			}
			hideLightBox();
			hideElement('div_float_generic', 0);
			break;
	}
	closeLightBox();
	return false;
}


function closeDetails() {
	if(document.all) {
		updateSelectDisplay('', 'inline');
	}
	hideElement('details', 0);
	hideLightBox();
}

function closeHelp() {
	if(document.all) {
		updateSelectDisplay('', 'inline');
	}
	hideLightBox();
	hideElement('help_window', 0);
	return false;
}

function displayHelpLinks(){
	gb_urlCurrDiv = 'documents';
	if(document.all) {
		updateSelectDisplay('', 'none');
	}
	displayCenter('help_documents', 300, 60);
	showPrevLightbox();
	showElement('help_documents', 'block');
	return false;
}

function closeHelpLinks(){
	if(document.all) {
		updateSelectDisplay('', 'inline');
	}
	hideLightBox();
	hideElement('help_documents', 0);
	return false;
}

function displayDegraded() {
	gb_urlCurrDiv = 'degraded';
	if(document.all) {
		updateSelectDisplay('', 'none');
	}
	displayCenter('degraded', 400, 100);
	showPrevLightbox();
	showElement('degraded', 'block');
	return false;
}

function closeDegraded() {
	if(document.all) {
		updateSelectDisplay('', 'inline');
	}
	hideLightBox();
	hideElement('degraded', 0);
	return false;
}

/*************************************************/
/****   Controle formulaire creation visite   ****/
/*************************************************/
function hideSuggest(id){
	hideElement(id, 0);
	if(document.all && !gb_isOpen_f_zip && !gb_isOpen_f_city){
		updateSelectDisplay('', 'inline');
	}
}

function suggest(val, type){
	if(val.length > 0){
		gb_typeSearch = type;
		var params = 'todo=suggest&value='+val+'&type='+type;
		new Ajax.Updater('suggest_'+type, 'ajax.php', {asynchronous: true, evalScripts: false, method: 'post', postBody: params, onComplete: suggestSuccess});
	}else{
		eval("gb_isOpen_"+gb_typeSearch+" = false;");
		hideSuggest('suggest_'+gb_typeSearch);
	}
}

function suggestSuccess(t){
	if(t.responseText.length>0){
		showElement('suggest_'+gb_typeSearch, 'inline');
		eval("gb_isOpen_"+gb_typeSearch+" = true;");
		if(document.all) {
		}
	}else{
		eval("gb_isOpen_"+gb_typeSearch+" = false;");
		hideSuggest('suggest_'+gb_typeSearch);
	}
}
/*************************************/
/*** Formulaire upload images http ***/
/*************************************/
function uploadWait() {
	$('upload_btn').value = msgUploadWait;
	startProcessing();
	return true;
}



/*******************/
/*** Modif image ***/
/*******************/
function updateOrderImage(idimg, oldPos, newPos) {
	if(gb_nbToDelete == 0 || confirm(gb_warnUpdateDelete)) {
		var params = 'todo=update_tour_order_image&tour='+gb_tour+'&image='+idimg+'&old_pos='+oldPos+'&new_pos='+newPos+'&to_del='+gb_listToDelete;
		startProcessing();
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onSuccess: function(t) {
				refreshImages();
			}
		});
	}
	return false;
}

function updateOrderFloorplan(idimg, oldPos, newPos) {
	if(gb_nbToDelete == 0 || confirm(gb_warnUpdateDelete)) {
		var params = 'todo=update_tour_order_plan&tour='+gb_tour+'&floorplan='+idimg+'&old_pos='+oldPos+'&new_pos='+newPos+'&to_del='+gb_listToDelete;
		startProcessing();
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onSuccess: function(t) {
				refreshPlan();
			}
		});
	}
	return false;
}


function updateImageName(ident, name){
	var params = 'todo=update_image_name&id='+ident+'&name='+encodeURIComponent(name)+'&lang='+gb_refLangue+'&tour='+gb_tour;
	startProcessing();
	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onSuccess: function(t) {
			endProcessing();
		}
	});
}


function checkToRefresh(pe) {
	if(gb_imagesToCheck.length > 0) {
		var params = 'todo=check_images&images='+gb_imagesToCheck+'&tour='+gb_tour;
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			postBody: params,
			method: 'post',
			onComplete: checkToRefreshSuccess
		});
	}else{
		gb_updater.stop();
	}
}

function checkToRefreshSuccess(t) {
	var listBads = t.responseText;
	var listImgs = gb_imagesToCheck.split('#');
	var newListToCheck = '';
	for(var i=0; i<listImgs.length; i++){
		if(document.getElementById('th-'+listImgs[i]) != null) {
			eval("var finished = listBads.match(/"+listImgs[i]+"/) ? false : true;");
			if(finished) {
				var newUrl = gb_urlThumbs.replace(/%ID%/, listImgs[i]);
				document.getElementById('th-'+listImgs[i]).src = newUrl;
			}else{
				if(newListToCheck.length==0) newListToCheck = listImgs[i];
				else newListToCheck += '#'.listImgs[i];
			}
		}
	}
	gb_imagesToCheck = newListToCheck;
	if(gb_imagesToCheck.length<36) {
		gb_updater.stop();
	}
}

function refreshImages() {
	var params = 'todo=list_images&tour='+gb_tour+'&thumbs_w='+gb_thumbsW+'&thumbs_h='+gb_thumbsH;
	if(gb_imagesToCheck.length > 0){
		params += '&to_check='+gb_imagesToCheck;
	}

	new Ajax.Updater('content_image_list', 'ajax.php', {
		asynchronous: true,
		evalScripts: false,
		method: 'post',
		postBody: params,
		onFailure: function(t) {
			endProcessing();
		},
		onComplete: function(t) {
			gb_listToDelete = '';
			gb_nbToDelete   = 0;

			document.getElementById('trash').style.display = 'none';
			document.getElementById('mess_nb_selected').style.display = 'none';

			endProcessing();
			if(t.responseText.length == 0) {
				setTimeout("window.location.href = 'upload_tour.php?tour="+gb_tour+"';", 1000);
			}

			gb_nbImagesLeft = document.getElementById('content_image_list').getElementsByTagName('select').length;

			var node = document.getElementById('nb_images_left');
			var nodeText = document.createTextNode(gb_nbImagesTour.replace(/#NB#/, gb_nbImagesLeft));
			clearNode(node);
			node.appendChild(nodeText);
		}
	});
}


function deleteImage(path, img){
	var statut = document.getElementById(path+'-statut-'+img);
	statut.value *= -1;
	if(statut.value==-1) {
		setOpacity('th-'+img, 25);
		document.getElementById('picto-delete-'+img).src = 'images/trash_out_10.gif';
		document.getElementById('picto-delete-'+img).setAttribute('title', gb_labelRestore);
		gb_listToDelete += img+'#';
	}else{
		setOpacity('th-'+img, 100);
		document.getElementById('picto-delete-'+img).src = 'images/trash_in_10.gif';
		document.getElementById('picto-delete-'+img).setAttribute('title', gb_labelDelete);
		gb_listToDelete = gb_listToDelete.replace(img+'#', '');
	}
	checkAllStatus();
	return false;
}

function selectImageToDelete(img) {
	if(gb_listToDelete.match(img)) {
		gb_listToDelete = gb_listToDelete.replace(img+'#', '');
		gb_nbToDelete--;
		setOpacity('th-'+img, 100);
		document.getElementById('picto-delete-'+img).src = 'images/trash_in_10.gif';
		document.getElementById('picto-delete-'+img).setAttribute('title', gb_labelDelete);
	} else {
		gb_listToDelete += img+'#';
		gb_nbToDelete++;
		setOpacity('th-'+img, 25);
		document.getElementById('picto-delete-'+img).src = 'images/trash_out_10.gif';
		document.getElementById('picto-delete-'+img).setAttribute('title', gb_labelRestore);
	}

	if(gb_listToDelete.length > 0){
		var ratio	= Math.ceil(100*gb_nbToDelete/(gb_nbImagesLeft));
		var node	 = document.getElementById('mess_nb_selected');
		var nodeText = document.createTextNode(gb_nbToDelete);

		clearNode(node);
		node.appendChild(nodeText);

		if(ratio <= 20){
			document.getElementById('trash').src = 'images/trash_low_32.jpg';
		}else if(ratio <= 80){
			document.getElementById('trash').src = 'images/trash_avg_32.jpg';
		}else{
			document.getElementById('trash').src = 'images/trash_hi_32.jpg';
		}
		document.getElementById('trash').style.display = 'inline';
		document.getElementById('mess_nb_selected').style.display = 'inline';
	}else{
		document.getElementById('trash').style.display = 'none';
		document.getElementById('mess_nb_selected').style.display = 'none';
	}
	return false;
}

function checkAllStatus() {
	var listHidden = document.getElementsByTagName('input');
	gb_nbToDelete   = 0;
	gb_nbImagesLeft = 0;
	for(var i=0; i<listHidden.length; i++){
		if(listHidden[i].type == 'hidden'){
			if(listHidden[i].id.match(/^(img|plan)-statut-/)){
				if(listHidden[i].value=='-1'){
					gb_nbToDelete++;
				}else{
					gb_nbImagesLeft++;
				}
			}
		}
	}
	if(gb_nbToDelete>0){
		var ratio = Math.ceil(100*gb_nbToDelete/(gb_nbToDelete+gb_nbImagesLeft));
		var node = document.getElementById('mess_nb_selected');
		var nodeText = document.createTextNode(gb_nbToDelete);
		clearNode(node);
		node.appendChild(nodeText);
		if(ratio <= 20){
			document.getElementById('trash').src = 'images/trash_low_32.jpg';
		}else if(ratio <= 80){
			document.getElementById('trash').src = 'images/trash_avg_32.jpg';
		}else{
			document.getElementById('trash').src = 'images/trash_hi_32.jpg';
		}
		document.getElementById('trash').style.display = 'inline';
		document.getElementById('mess_nb_selected').style.display = 'inline';
	}else{
		document.getElementById('trash').style.display = 'none';
		document.getElementById('mess_nb_selected').style.display = 'none';
	}
}



function deleteSelectedImagesNew() {
	if(confirm(gb_messDeleteImages)) {
		startProcessing();
		var params = 'todo=delete_selected_images&tour='+gb_tour+'&to_delete='+gb_listToDelete
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onSuccess: function(t) {
				refreshImages();
			}
		});
	}
	return false;
}

function deleteSelectedFloorplan() {
	if(confirm(gb_messDeletePlans)) {
		var params = 'todo=delete_selected_plan&tour='+gb_tour+'&to_delete='+gb_listToDelete
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onSuccess: function(t) {
				refreshPlan();
			}
		});
	}
	return false;
}


function checkFloorplan() {
	if(gb_planToCheck.length>36) {
		var params = 'todo=check_floorplan&tocheck='+encodeURIComponent(gb_planToCheck);
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onComplete: function(t) {
				var tabGood = t.responseText.split('#');
				for(var i=0; tabGood.length; i++) {
					var tpl  = tabGood[i]+'#';
					var floorplan  = tabGood[i].split('_');
					gb_planToCheck = gb_planToCheck.replace(tpl, '');

					if(document.getElementById('th-'+floorplan[0]) != null) {
						document.getElementById('th-'+floorplan[0]).src = gb_urlFloorplan.replace(/#ID#/, floorplan[0]).replace(/#EXT#/, floorplan[1]);
					}
				}
			}
		});
	} else {
		gb_updater.stop();
	}
}


function updateSelectDisplay(container, newDisplay){
	if(container.length>0) {
		var listSelect = document.getElementById(container).getElementsByTagName('select');
	}else{
		var listSelect = document.getElementsByTagName('select');
	}
	for(var i=0; i<listSelect.length; i++){
		listSelect[i].style.display = newDisplay;
	}
	return false;
}

function closeImage(div){
	div.style.display = 'none';

	// Workaround IE6
	if(document.all){
		updateSelectDisplay('content_image_list', 'inline');
	}
}


function showReprocessMenu(div){
	document.getElementById('infocamera').style.display = 'none';
	document.getElementById('infobrightness').style.display = 'none';
	document.getElementById('inforestitch').style.display = 'none';
	document.getElementById('infodownload').style.display = 'none';
	document.getElementById('infohotline').style.display = 'none';
	document.getElementById('inforotate').style.display = 'none';
	document.getElementById('quality_comment').value = gb_messYourMessage;
	if(document.getElementById('rotate_angle')!=null) {
		document.getElementById('rotate_angle').value = '0';
	}

	var idImage   = document.getElementById('idimg').value.replace(/-/g, '_');
	var nameImage = encodeURIComponent(document.getElementById('imgname'+idImage).value);

	document.getElementById('download_link_img').href = gb_urlDownload.replace(/#TOUR#/, idImage).replace(/#NAME#/, encodeURIComponent(nameImage)+'.jpg');
	document.getElementById('download_link_img_hq').href = gb_urlDownloadHQ.replace(/#TOUR#/, idImage).replace(/#NAME#/, encodeURIComponent(nameImage)+'hq.jpg');
	if(document.getElementById('download_flat_img') != null) {
		document.getElementById('download_flat_img').href = gb_urlDownloadFlat.replace(/#TOUR#/, idImage).replace(/#NAME#/, encodeURIComponent(nameImage)+'hq.jpg');
	}

	resetBrightness();
	document.getElementById(div).style.display = '';
}
function viewReprocess(img, ti, w, h){
	gb_urlCurrDiv = 'reprocess';
	gb_levelBrightness = 100;
	document.getElementById('div_reprocess').style.display = 'none';
	/* Black background */
	showPrevLightbox();
	/* Workaround IE6 */
	if(document.all) updateSelectDisplay('content_image_list', 'none');
	document.getElementById('idimg').value = img;
	displayCenter('div_reprocess', w, h);
	showElement('div_reprocess', 'block');
	showReprocessMenu('infocamera');

	if(ti==1) {
		showElement('row_reprocess', 'block');

	} else {
		hideElement('row_reprocess', 0);
	}

	document.getElementById('img_reprocess').src = gb_urlImages.replace(/%ID%/, img);
	getCameraInfo();
	return false;
}
function closeReprocess() {
	document.getElementById('div_reprocess').style.display = 'none';
	/* Black background */
	hideLightBox();
	/* Workaround IE6 */
	if(document.all) updateSelectDisplay('content_image_list', 'inline');
	document.getElementById('img_reprocess').src = 'images/ajax_big.gif';
	return false;
}
function getCameraInfo() {
	document.getElementById('camera_brand').innerHTML = '-';
	document.getElementById('camera_model').innerHTML = '-';
	document.getElementById('camera_size').innerHTML = '-';
	document.getElementById('camera_date').innerHTML = '-';
	document.getElementById('title_info').innerHTML = '-';
	var params = 'todo=camera_info&image='+document.getElementById('idimg').value;
	new Ajax.Request('ajax.php', {asynchronous: true, method: 'post', postBody: params, onComplete: getCameraInfoSuccess});
}
function getCameraInfoSuccess(t) {
	var infos = t.responseText.split('|');
	document.getElementById('camera_brand').innerHTML = infos[0];
	document.getElementById('camera_model').innerHTML = infos[1];
	document.getElementById('camera_size').innerHTML  = infos[2];
	document.getElementById('camera_date').innerHTML  = infos[3];
	document.getElementById('title_info').innerHTML = infos[4];
}
function postRestitch() {
	document.getElementById('img_reprocess').src = 'images/ajax_big.gif';
	var params = 'todo=restitch_image&type=hemisphere&tour='+gb_tour+'&image='+document.getElementById('idimg').value;
	if(gb_account!=null) params += '&account='+gb_account;
	new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onComplete: function(t) {
				if(t.responseText.match(/^OK : [0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12}/i)){
					var img = t.responseText.replace(/^.*([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}).*$/i, '$1');
					document.getElementById('idimg').value = img;
					document.getElementById('img_reprocess').src = gb_urlImages.replace(/%ID%/, img)+'&random='+Math.floor(Math.random()*100000);
					window.location.href = window.location.href;
				}else{
					document.getElementById('img_reprocess').src = 'images/warning_32.gif';
				}
			}
		});
}

function postPreviewBrightness(percent) {
	document.getElementById('brightness_value').value = percent;
	document.getElementById('img_reprocess').src = 'images/ajax_big.gif';

	var params = 'todo=preview_brightness_image&percent='+percent+'&tour='+gb_tour+'&image='+document.getElementById('idimg').value;
	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			if(t.responseText.match(/^OK : [0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12}/i)) {
				var img = t.responseText.replace(/^.*([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}).*$/i, '$1');
				document.getElementById('img_reprocess').src = 'getimage.php?todo=get_bright&img='+img+'&random='+Math.floor(Math.random()*1000);

			} else {
				document.getElementById('img_reprocess').src = 'images/warning_32.gif';
			}
		}
	});
	var slider1 = new Control.Slider('handle1','track1',{ sliderValue:(percent), range:$R(50,200) });
	return false;
}

function postBrightness(percent) {
	var idImage = document.getElementById('idimg').value;
	document.getElementById('img_reprocess').src = 'images/ajax_big.gif';
	document.getElementById('th-'+idImage).src = 'images/ajax_big.gif';
	var params = 'todo=brightness_image&percent='+percent+'&tour='+gb_tour+'&image='+idImage;
	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			if(t.responseText.match(/^OK : [0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12}/i)) {
				closeReprocess();
				window.location = window.location+'&todo=check';
			} else {
				document.getElementById('img_reprocess').src = 'images/warning_32.gif';
			}
			gb_levelBrightness = percent;
		}
	});
	return false;
}

function resetBrightness() {
	document.getElementById('img_reprocess').src = gb_urlImages.replace(/%ID%/, document.getElementById('idimg').value);

	document.getElementById('brightness_value').value = "100";
	var slider1 = new Control.Slider('handle1','track1',{ sliderValue:(100), range:$R(50,200) });
	return false;
}
function changeOpacity(percent) {
	document.getElementById('img_mask').style.filter = 'alpha(opacity'+percent+')';
	document.getElementById('img_reprocess').style.filter = 'alpha(opacity'+percent+')';
	document.getElementById('img_reprocess').style.MozOpacity = percent / 100;
	document.getElementById('img_reprocess').style.opacity = percent / 100;
	document.getElementById('img_reprocess').style.bgColor = '#000';
}
function sendQualityReport(emailfrom, comment) {
	if(comment.length > 20) {
		document.getElementById('quality_comment').className = 'text_mini';
		var params = 'todo=report_quality&from='+ emailfrom + '&comment='+comment+'&tour='+gb_tour+'&image='+document.getElementById('idimg').value;
		new Ajax.Request('ajax.php', {asynchronous: false, method: 'post', postBody: params, onComplete:sendQualityReportSuccess});
	}else{
		document.getElementById('quality_comment').className = 'text_mini_warn';
	}
	return false;
}
function sendQualityReportSuccess(t) {
	alert(gb_messThankReporting);
	showReprocessMenu('infocamera');
	closeReprocess();
}

/*****************/
/*** Floorplan ***/
/*****************/
function refreshPlan(){
	var params = 'todo=list_plan&tour='+gb_tour+'&thumbs_w='+gb_thumbsW+'&thumbs_h='+gb_thumbsH;
	startProcessing();
	new Ajax.Updater('content_plan_list', 'ajax.php', {
		asynchronous: true,
		evalScripts: false,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			if(t.responseText.length == 0){
				hideElement('table_nav', 0);
				hideElement('content_plan_list', 0);
			}

			gb_nbToDelete = 0;
			gb_listToDelete = '';

			endProcessing();
			hideElement('trash', 0);
			hideElement('mess_nb_selected', 0);
		}
	});
}

function retraiteImage(img){
	if(confirm(gb_messRetraiteImage)){
		document.getElementById('th-'+img).src = 'images/ajax_big.gif';
		var params = 'todo=retraite_image&tour='+gb_tour+'&image='+img;
		new Ajax.Request('ajax.php', {asynchronous: true, method: 'post', postBody: params, onComplete: retraiteImageSuccess});
	}
	return false;
}

function retraiteImageSuccess(t){
	if(t.responseText.match(/^OK : [0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12}/i)){
		var img = t.responseText.replace(/^.*([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}).*$/i, '$1');
		document.getElementById('th-'+img).src = gb_urlThumbs.replace(/%ID%/, img);
	}else{
		document.getElementById('th-'+img).src = 'images/warning.gif';
	}
}

function updatePlanName(ident, name){
	var params = 'todo=update_plan_name&plan='+ident+'&name='+encodeURIComponent(name)+'&lang='+gb_refLang+'&tour='+gb_tour;
	startProcessing();
	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			refreshPlan();
		}
	});
}


/* Rotate de l'image */
function addAngle(increment) {
	if(!gb_lock) {
		document.getElementById('img_reprocess').src = 'images/ajax_big.gif';
		gb_lock	  = true;
		var oldAngle = parseInt(document.getElementById('rotate_angle').value);
		var newAngle = oldAngle += increment;
		document.getElementById('rotate_angle').value = newAngle.toString();
		var params = '&todo=preview_rotate_image&tour='+gb_tour+'&image='+document.getElementById('idimg').value+'&angle='+newAngle;
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onComplete: function(t) {
				if(t.responseText.match(/OK : .{36}/)) {
					document.getElementById('img_reprocess').src = gb_urlImgReprocess+document.getElementById('idimg').value+'&rand='+Math.round(100000*Math.random());
				} else {
					document.getElementById('img_reprocess').src = 'images/warning_32.gif';
				}
				gb_lock = false;
			}
		});
	}
	return false;
}

function postRotate() {
	if(!gb_lock) {
		document.getElementById('img_reprocess').src = 'images/ajax_big.gif';
		gb_lock	  = true;
		var newAngle = parseInt(document.getElementById('rotate_angle').value);
		var idImg	= document.getElementById('idimg').value;

		document.getElementById('rotate_angle').value = newAngle.toString();

		var params = '&todo=rotate_image&tour='+gb_tour+'&image='+idImg+'&angle='+newAngle;

		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onComplete: function(t) {
				if(t.responseText.match(/OK : .{36}/)) {
					document.getElementById('img_reprocess').src = gb_urlImages.replace(/%ID%/, idImg)+'&rand='+Math.round(100000*Math.random());
					document.getElementById('th-'+idImg).src	 = gb_urlThumbs.replace(/%ID%/, idImg)+'&rand='+Math.round(100000*Math.random());
				} else {
					document.getElementById('img_reprocess').src = 'images/warning_32.gif';
				}
				gb_lock = false;
			}
		});

	}
}


/************************/
/******** Video *********/
/************************/
function closeMailIntegration() {
	if(document.all) {
		updateSelectDisplay('create_reference', 'inline');
	}
	hideElement('mail_integration', 0);
	hideLightBox();
	return false;
}


function sendMailIntegration(ref, mail, urlTour, wTour, hTour) {
	var params = 'todo=mail_integration&ref='+encodeURIComponent(ref)+'&urlTour='+encodeURIComponent(urlTour)+'&mail='+encodeURIComponent(mail)+'&width='+wTour+'&height='+hTour;
	gb_urlCurrDiv = 'mail_integration';
	new Ajax.Updater('mail_integration', 'ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			displayCenter('mail_integration', 500, 300);
			showElement('mail_integration', 'block');

			if(document.all) {
				updateSelectDisplay('create_reference', 'none');
			}

			showPrevLightbox();
			showElement('mail_integration', 'block');
		}
	});
}

function updateChoice(ref, val) {
	var params = 'todo=update_viewer_option&element='+gb_element+'&id_element='+gb_idElement+'&ref='+ref+'&val='+val;
	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params
	});
}

function openFloorplanner() {
	gb_urlCurrDiv = 'div_floorplanner';
	if(document.all) {
		updateSelectDisplay('', 'none');
	}
	displayCenter('div_floorplanner', 360, 240);
	var params = 'todo=auth_floorplanner&tour='+gb_tour;
	new Ajax.Updater('div_floorplanner', 'ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			showElement('div_floorplanner', 'block');
			showPrevLightbox();
		}
	});
	return false;
}

function openDiakrit(email, uID, tID) {
	var urlPop = 'http://shop.diakrit.com/php/previsite.php?emailID='+encodeURIComponent(email)+'&userID='+encodeURIComponent(uID)+'&tourID='+encodeURIComponent(tID);
	var popDiakrit  = window.open(urlPop, 'popDiakrit', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=750');
}

function closeFloorplanner() {
	if(document.all) {
		updateSelectDisplay('', 'inline');
	}
	hideLightBox();
	hideElement('div_floorplanner', 0);
	return false;
}

function addFloorplanner() {
	var login  = encodeURIComponent($F('fp_login'));
	var pwd	= encodeURIComponent($F('fp_password'));
	var params = 'ajax.php?todo=add_floorplanner&tour='+gb_tour+'&lang='+gb_refLang+'&fp_login='+login+'&fp_password='+pwd+'&name='+encodeURIComponent($F('title2'));
	var popFP  = window.open(params, 'popFP', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=800,height=600');
	popFP.focus();
}

function checkImageTourForm() {
	var update = false;

	var tabImage = document.getElementById('list_all_images').value.split(';');

	checkAllStatus();

	if(gb_nbToDelete>0){
		if(confirm(gb_warnUpdateDelete)){
			update = true;
		}
	}else{
		update = true;
	}

	if(update){
		startProcessing();

		var toDel  = '';

		var params = 'todo=update_images&tour='+gb_tour+'&lang='+gb_refLangue;
		for(var i=0; i<tabImage.length; i++) {
			if(document.getElementById('img-poids-'+tabImage[i]) != null) {
				var statusObj = document.getElementById('img-statut-'+tabImage[i]);
				if(statusObj != null) var status = document.getElementById('img-statut-'+tabImage[i]).value;
				else				  var status = 1;
				params += '&img-poids-'+tabImage[i]+'='+document.getElementById('img-poids-'+tabImage[i]).value;
				params += '&img-name-'+tabImage[i]+'='+document.getElementById('imgname'+tabImage[i].replace(/-/g, '_')).value;
				params += '&img-statut-'+tabImage[i]+'='+status;
				if(parseInt(status) < 0) {
					if(toDel.length>0) {
						toDel += '#'+tabImage[i];
					} else {
						toDel  = '&delete='+tabImage[i];
					}
				}
			}
		}
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onSuccess: function(t) {
				var toRefresh = t.responseText;
				if(toRefresh == 'true'){
					refreshImages();
				}else{
					endProcessing();
				}
				hideElement('trash', 0);
				hideElement('mess_nb_selected', 0);

				var node = document.getElementById('nb_images_left');
				var nodeText = document.createTextNode(gb_nbImagesTour.replace(/#NB#/, gb_nbImagesLeft));
				clearNode(node);
				node.appendChild(nodeText);
			}
		});

	}
	return false;
}



function checkPlanForm() {
	var update = false;

	checkAllStatus();

	if(gb_nbToDelete>0){
		if(confirm(gb_warnUpdateDelete)){
			update = true;
		}
	}else{
		update = true;
	}

	if(update){
		var params  = 'todo=update_plan&tour='+gb_tour;
		var params2 = '';

		for(var i=0; i<tabPlan.length; i++) {
			if(document.getElementById('plan-poids-'+tabPlan[i]) != null) {
				params += '&plan-poids-'+tabPlan[i]+'='+document.getElementById('plan-poids-'+tabPlan[i]).value;
				params += '&plan-desc-'+tabPlan[i]+'='+document.getElementById('plan-desc-'+tabPlan[i]).value;
				params += '&plan-statut-'+tabPlan[i]+'='+document.getElementById('plan-statut-'+tabPlan[i]).value;
				if(params2.length==0) params2 += '&liste_plan='+tabPlan[i];
				else params2 += '#'+tabPlan[i];
			}
		}
		params += params2;
		startProcessing();
		new Ajax.Request('ajax.php', {
			asynchronous: true,
			method: 'post',
			postBody: params,
			onComplete: refreshPlan
		});
	}
	return false;
}

function updateOrderPlan(obj){
	var listSelect = document.getElementsByTagName('select');
	var oldPos = obj.title;
	var newPos = obj.value;
	for(var i=0; i<listSelect.length; i++){
		if(listSelect[i].id.match(/^plan-poids-.{36}$/)){
			if(listSelect[i].id != obj.id && listSelect[i].value <= newPos && listSelect[i].value > oldPos && oldPos<newPos){
				listSelect[i].selectedIndex--;
			}else if(listSelect[i].id != obj.id && listSelect[i].value >= newPos && listSelect[i].value < oldPos && oldPos>newPos){
				listSelect[i].selectedIndex++;
			}
		}
	}
	return checkPlanForm();
}


function openMobileAddv() {
	var params = 'todo=open_mobile_add&tour='+gb_tour;
	new Ajax.Updater('lightbox_content', 'ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			if(t.responseText.length > 0) {
				openLightBox();
			} else {
				closeLightBox();
			}
		}
	});
	return false;
}

function updateStatesList(selectToUpdate, country) {
	var params = 'todo=update_states_list&country='+country;

	new Ajax.Request('ajax.php', {
		asynchronous: true,
		method: 'post',
		postBody: params,
		onComplete: function(t) {
			var listStates = t.responseXML.getElementsByTagName('state');
			var selectNode = $(selectToUpdate);
			clearNode(selectNode);
			if(listStates.length>0) {
				selectNode.removeClassName('disabled_element');
				for(var i=0; i<listStates.length; i++) {
					var optionNode = document.createElement('option');
					optionNode.value = listStates[i].getAttribute('id');
					optionNode.appendChild(document.createTextNode(listStates[i].getAttribute('name')));
					selectNode.appendChild(optionNode);
				}
			} else {
				selectNode.addClassName('disabled_element');
			}
		}
	});
}
