/*** MENU ***/
$(document).ready(function() {
	$(".top-menu > li").hover(
		function() {
			$(this).addClass("active-top-item");
			$(".sub-menu", this).slideDown("fast");
		},
		function() {
			if ($(".sub-menu", this).length) {
				$(".sub-menu", this).slideUp("fast", function() {
					$(this).parent().removeClass("active-top-item");
				});
			} else {
				$(this).removeClass("active-top-item");
			}
		}
	);
});


String.prototype.trim = function() {
    return this.replace(/(?:^\s+|\s+$)/g, "");
};


function clearInput(elem, initValue) {
	if (initValue == undefined 
			|| (initValue != undefined && elem.value == initValue)) {
		elem.value = "";
	}
}

function submitLoginForm(formId) {
	document.getElementById(formId).submit();
}

function showWaitingDialog(text) {
	$("#waiting_dialog").attr("title", text);
	$("#waiting_dialog div").html(text);
	$("#waiting_dialog").show();
}
function hideWaitingDialog() {
	$("#waiting_dialog").hide();
	$("#waiting_dialog").attr("title", "");
	$("#waiting_dialog div").html("");
}


/**
 * @param textAreaId Id du textarea à "enrichir"
 * @param maxHeight 305 pour 20 rows, 178 pour 8 rows
 * Nécessite :
 * - jQuery
 * - jQuery UI droppable
 */
function computeNewEditor(textAreaId, maxHeight) {
	var editor = new nicEditor({
				buttonList: ['fontSize', 'bold', 'italic', 'underline', 'strikethrough', 'left', 'center', 'right', 'justify', 'ol', 'ul', 'hr', 'image', 'upload', 'link', 'unlink', 'forecolor', 'bgcolor', 'cleanpaste'],
				iconsPath: '/sites/js/nicEdit/nicEditorIcons.gif',
				maxHeight: maxHeight ? maxHeight : 200
			}).panelInstance(textAreaId, {hasPanel : true});

	/*** cleanPaste ***/
	var nicEditorDiv = $("#"+textAreaId).prev("div").children(".nicEdit-main");
	nicEditorDiv.droppable("destroy").droppable("disable");
	nicEditorDiv.bind("drop", function(e) {
		e.preventDefault();
		e.stopPropagation();
	});
	nicEditorDiv.bind("paste", function(e) {
		e.preventDefault();
		e.stopPropagation();
		openCleanPaste = function() {
			editor.nicPanel.findButton("cleanpaste").mouseClick();
		};
		setTimeout(openCleanPaste, 500);
	});

	return editor;
}
