function alertFctn(msg, elmtId) {
	var sticky = new Element('div', {'id': 'Sticky', 'class': 'closeSticky', 'html' : msg});
	sticky.inject($(elmtId+'Input'), 'after');
	highlightField(elmtId);
	(function(){ sticky.set('fade', {onComplete: function() {this.dispose();}}).fade('out');}).delay(2500);
}
function alertFctnHighlight(msg, elmtId, highlightId) {
	var sticky = new Element('div', {'id': 'Sticky', 'class': 'closeSticky', 'html' : msg});
	sticky.inject($(elmtId), 'after');
	//highlightField(elmtId);
	(function(){ sticky.set('fade', {onComplete: function() {this.dispose();}}).fade('out');}).delay(2500);
	highlightField(highlightId);
}
function highlightField(fieldName) {
	$(fieldName).set('morph', {duration: 500}).morph({
		color: ['#ffffff', '#000000'],
		backgroundColor: ['#d50926', '#ffffff']
	});

	return $(fieldName);
}
function popupHelp() {
	SqueezeBox.open(BasePath + '/contact/popup_help.php', {handler: 'ajax',size: {x: 600, y: 200}});
	return ;
}
function menuItemOver(id) {
	$(id).getElements('div').each(function(item) {
		item.set('class', item.className+'On');
	});
}

function menuItemOut(id) {
	$(id).getElements('div').each(function(item) {
		item.set('class', item.className.substring(0, item.className.length-2));
	});
}

function morphElements(elements, zone) {
	var Bgs = ['#ffffff', '#fbff98', '#f2b574', '#ff6464'];
	newZone = ((zone+1)%(parseInt($('nbZonesHidden').value)+1));

	elements.set('class', 't' + newZone).set('morph', {duration: 250}).morph({
		backgroundColor: [Bgs[zone], Bgs[newZone]]
	});
}

function setZoneMonth(year, month) {
	zone = parseInt($('CB_' + year + '_' + month).getElement('.dayinmonth').getElement('input').get('class').substr(1, 2));
	morphElements($('CB_' + year + '_' + month).getElements('.dayinmonth').getElement('input'), zone);
}
function setZoneDayInWeek(year, month, dayinweek) {
	zone = parseInt($('CB_' + year + '_' + month).getElement('.dayinmonth[id^=DIW' + dayinweek + ']').getElement('input').get('class').substr(1, 2));
	morphElements($('CB_' + year + '_' + month).getElements('.dayinmonth[id^=DIW' + dayinweek + ']').getElement('input'), zone);
}
function setZoneDay(year, month, day) {
	zone = parseInt($('BTN_' + year + '_' + month + '_' + day).get('class').substr(1, 2));
	morphElements($('BTN_' + year + '_' + month + '_' + day), zone);
}
function adTypeTranslationForURL(ad_type, language) {
	if (ad_type == "ALL" && language == "en") return("rent");
	else if (ad_type == "ALL" && language == "es") return("alquiler");
	else if (ad_type == "ALL") return("location");
	else if (ad_type == "LOCALS" && language == "fr") return("chambre-a-louer");
	else if (ad_type == "LOCALS" && language == "en") return("homestay");
	else if (ad_type == "LOCALS" && language == "es") return("casa-particular");
	else if (ad_type == "COLOC" && language == "fr") return("colocation");
	else if (ad_type == "COLOC" && language == "en") return("flateshare-houseshare");
	else if (ad_type == "COLOC" && language == "es") return("compartir-piso");
	else if (ad_type == "BEDNBREAKFAST" && language == "fr") return("chambre-d-hotes");
	else if (ad_type == "BEDNBREAKFAST" && language == "en") return("bed-and-breakfast");
	else if (ad_type == "BEDNBREAKFAST" && language == "es") return("casa-rural");
	else if (ad_type == "SEASONAL" && language == "fr") return("location-vacance");
	else if (ad_type == "SEASONAL" && language == "en") return("holidays-rentals");
	else if (ad_type == "SEASONAL" && language == "es") return("alquiler-de-vacaciones");
	else if (ad_type == "SERVICE" && language == "fr") return("logement-contre-service");
	else if (ad_type == "SERVICE" && language == "en") return("accommodation-in-exchange-for-services");
	else if (ad_type == "SERVICE" && language == "es") return("alojamiento-a-cambio-de-servicios");
	else return(ad_type);
}
function nicePopup() {
	SqueezeBox.open('message', {handler: 'adopt',size: {x: 400, y: 160}});
}


var swf = new Array();
function initUploadLink(name, code, fieldName, className, extensions, postTreatmentMsg, currentFieldValue, txts, buttonStyle) {
	window.addEvent('domready', function() {
		var link = $('UploadButton' + fieldName);
		var uploadInstance;
		var progressBar;

		function linkUpdate() {
			if (!swf[fieldName].uploading) return;

			uploadInProgress = true;
			if (swf[fieldName].percentLoaded == 100)
				$('ProgressBar' + fieldName).set('html', postTreatmentMsg);
			else progressBar.setPercentage(swf[fieldName].percentLoaded);
		}
		if (DetectFlashVer(8, 0, 0)) {
			swf[fieldName] = new Swiff.Uploader({
				path: ComPath + '/thirdparty/mootools/fancyupload/Swiff.Uploader.swf',
				url: BasePath + '/include/php/rt_uploadfile.php?code=' + code + '&name=' + name + '&className=' + className + '&fieldName=' + fieldName + '&currentFieldValue=' + currentFieldValue + '&buttonStyle=' + buttonStyle + '&language=' + Language,
				verbose: true,
				queued: false,
				multiple: false,
				target: link,
				instantStart: true,
				typeFilter: { "Fichiers acceptés": extensions },
				fileSizeMax: 1024 * 1024 * 1024,
				onSelectSuccess: function(files) {
					$('progress' + fieldName).innerHTML = txts[0] + '&nbsp;<div id="ProgressBar' + fieldName + '"></div><div align="center" id="Percent' + fieldName + '"></div><br /><br />';
					progressBar = new MoogressBar('ProgressBar' + fieldName, {
						bgImage: BasePath + '/picture/progressbar/yellow_animated.gif',
						percentage: 0,
						fx: false,
						hide: true,
						onChange: function(per) { }
					});
					this.setEnabled(false);
				},
				onSelectFail: function(files) {
					notifyError('<b>' + files[0].name + '</b> pas ajoutée !<br />(Erreur : #' + files[0].validationError + ')');
				},
				appendCookieData: true,
				onQueue: linkUpdate,
				onFileComplete: function(file) {
					uploadInProgress = false;
					if (!JSON.decode(file.response.text).status) {
						notifyError("Le fichier <b>" + this.fileList[0].name + "</b> n'a pas été upload&eacute;e.<br /><div>Erreur : " + JSON.decode(file.response.text).error + ')</div>');
					} else {
						JSON.decode(file.response.text).AfterUploadHTML;
						$('FieldDetail' + fieldName).innerHTML = JSON.decode(file.response.text).AfterUploadHTML;
						$('Buttons' + fieldName).innerHTML = JSON.decode(file.response.text).ButtonsHTML;
						eval(JSON.decode(file.response.text).AfterUploadJS);
						eval(JSON.decode(file.response.text).ButtonsJS);
						$(fieldName.toLowerCase()).value = JSON.decode(file.response.text).fileName;
					}
					file.remove();
					this.setEnabled(true);
				},
				onComplete: function() {
				}
			});

			link.addEvents({
				click: function() { return false; },
				mouseenter: function() {
					swf[fieldName].reposition();
				}/*,
				/*mouseleave: function() {
					this.blur();
				},
				mousedown: function() {
					this.focus();
				}*/
			});
		} else {
			link.addEvents({
				click: function() { $('progress' + fieldName).innerHTML = '<input type="file" name="' + fieldName.toLowerCase() + 'file">'; }
			});
		}
	});
}

function deleteFile(name, code, fieldName, className, buttonStyle) {
	var jsonRequest = new Request.JSON({url: BasePath + '/include/php/rt_deletefile.php?name=' + name + '&fieldName=' + fieldName + '&code=' + code + '&buttonStyle=' + buttonStyle , onComplete: function(jsonObj) {
	    $('Buttons' + fieldName).set('html', jsonObj.ButtonsHTML);
		eval(jsonObj.ButtonsJS);
		$('FieldDetail' + fieldName).set('html', '');
		$(fieldName.toLowerCase()).value = "";
	}}).send();
}

function removeAccentUTF8 (str) {
	str = str.replace(/[èéêë]/g,"e"); str = str.replace(/[ÈÉÊË]/g,"E");
	str = str.replace(/[àâä]/g,"a"); str = str.replace(/[ÀÂÄ]/g,"A");
	str = str.replace(/[îï]/g,"i"); str = str.replace(/[ÎÏ]/g,"I");
	str = str.replace(/[ûü]/g,"u"); str = str.replace(/[ÛÜ]/g,"U");
	str = str.replace(/[ôö]/g,"o"); str = str.replace(/[ÔÖ]/g,"O");
	return str;
}

