function processKeywordsString(strkeywords) {

	var unicode_trans_table = {
		"30" : "0"        , "31" : "1"        , "32" : "2"        ,
		"33" : "3"        , "34" : "4"        , "35" : "5"        ,
		"36" : "6"        , "37" : "7"        , "38" : "8"        ,
		"39" : "9"        , "41" : "A"        , "42" : "B"        ,
		"43" : "C"        , "44" : "D"        , "45" : "E"        ,
		"46" : "F"        , "47" : "G"        , "48" : "H"        ,
		"49" : "I"        , "4A" : "J"        , "4B" : "K"        ,
		"4C" : "L"        , "4D" : "M"        , "4E" : "N"        ,
		"4F" : "O"        , "50" : "P"        , "51" : "Q"        ,
		"52" : "R"        , "53" : "S"        , "54" : "T"        ,
		"55" : "U"        , "56" : "V"        , "57" : "W"        ,
		"58" : "X"        , "59" : "Y"        , "5A" : "Z"        ,
		"61" : "a"        , "62" : "b"        , "63" : "c"        ,
		"64" : "d"        , "65" : "e"        , "66" : "f"        ,
		"67" : "g"        , "68" : "h"        , "69" : "i"        ,
		"6A" : "j"        , "6B" : "k"        , "6C" : "l"        ,
		"6D" : "m"        , "6E" : "n"        , "6F" : "o"        ,
		"70" : "p"        , "71" : "q"        , "72" : "r"        ,
		"73" : "s"        , "74" : "t"        , "75" : "u"        ,
		"76" : "v"        , "77" : "w"        , "78" : "x"        ,
		"79" : "y"        , "7A" : "z"        , "20" : " "        ,
		"C0" : "&Agrave;" , "C1" : "&Aacute;" , "C2" : "&Acirc;"  , 
		"C3" : "&Atilde;" , "C4" : "&Auml;"   , "C5" : "&Aring;"  , 
		"C6" : "&AElig;"  , "C7" : "&Ccedil;" , "C8" : "&Egrave;" , 
		"C9" : "&Eacute;" , "CA" : "&Ecirc;"  , "CB" : "&Euml;"   , 
		"CC" : "&Igrave;" , "CD" : "&Iacute;" , "CE" : "&Icirc;"  ,
		"CF" : "&Iuml;"   , "D0" : "&ETH;"    , "D1" : "&Ntilde;" , 
		"D2" : "&Ograve;" , "D3" : "&Oacute;" , "D4" : "&Ocirc;"  , 
		"D5" : "&Otilde;" , "D6" : "&Ouml;"   , "D8" : "&Oslash;" , 
		"D9" : "&Ugrave;" , "DA" : "&Uacute;" , "DB" : "&Ucirc;"  , 
		"DC" : "&Uuml;"   , "DD" : "&Yacute;" , "DE" : "&THORN;"  ,	
		"DF" : "&szlig;"  , "E0" : "&agrave;" , "E1" : "&aacute;" , 
		"E2" : "&acirc;"  , "E3" : "&atilde;" , "E4" : "&auml;"   , 
		"E5" : "&aring;"  , "E6" : "&aelig;"  , "E7" : "&ccedil;" , 
		"E8" : "&egrave;" , "E9" : "&eacute;" , "EA" : "&ecirc;"  , 
		"EB" : "&euml;"   , "EC" : "&igrave;" , "ED" : "&iacute;" ,
		"EE" : "&icirc;"  , "EF" : "&iuml;"   , "F0" : "&eth;"    , 
		"F1" : "&ntilde;" , "F2" : "&ograve;" , "F3" : "&oacute;" , 
		"F4" : "&ocirc;"  , "F5" : "&otilde;" , "F6" : "&ouml;"   , 
		"F8" : "&oslash;" , "F9" : "&ugrave;" , "FA" : "&uacute;" , 
		"FB" : "&ucirc;"  , "FC" : "&uuml;"   , "FD" : "&yacute;" ,
		"FE" : "&thorn;"  , "FF" : "&yuml;" 
	};
	
	var ret = "";
	
	for (var i=0; i<strkeywords.length; i++) {
		var hex = strkeywords.charCodeAt(i).toString(16).toUpperCase();
		ret += (unicode_trans_table[hex]!=undefined)? unicode_trans_table[hex] : " ";
	}
	
	ret = ret.replace(/\u0020+/g, ',');
	
	return ret;
}

function getStartDate() {
	var d = document.getElementById("year-start").value;
	d += "-" + document.getElementById("month-start").value;
	d += "-" + document.getElementById("day-start").value;
	return d;
}

function getEndDate() {
	var d = document.getElementById("year-end").value;
	d += "-" + document.getElementById("month-end").value;
	d += "-" + document.getElementById("day-end").value;
	return d;
}

function disableDateFields(suffix, action) {
	document.getElementById("day-"+suffix).disabled   = action;
	document.getElementById("month-"+suffix).disabled = action;
	document.getElementById("year-"+suffix).disabled  = action;
}

function checkForm(formid) {
	var msg = "";
	var keywords = document.getElementById("keywords-temp-field").value;
	var startdateOn = !document.getElementById("ignore-startdate").checked;
	var enddateOn = !document.getElementById("ignore-enddate").checked;
	
	if (!keywords && !startdateOn && !enddateOn) {
		alert("Recherche invalide !\nAucun mot-clé et aucune date spécifiés");
		return;
	}
	
	if ( (startdateOn && enddateOn) && (getStartDate() > getEndDate()) ) {
		alert("Recherche invalide !\nLa date de fin est plus récente que la date de début");
		return;
	}
	document.getElementById("keywords-field").value = processKeywordsString(keywords);
	document.getElementById(formid).submit();
}

function showMoreOrLess(motherPanel) {
	var childPanelId = motherPanel.id.split("-")[1];
	var childPanel = document.getElementById("event_"+childPanelId+"_more");
	if (motherPanel.firstChild.nodeValue == "en savoir plus") {
		childPanel.style.display = "block";
		motherPanel.firstChild.nodeValue = "masquer";
	} else {
		childPanel.style.display = "none";
		motherPanel.firstChild.nodeValue = "en savoir plus";
	}
}