function checkEnter(e) { //e is event object passed from function invocation
	var characterCode; // literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return true
	}
	else {
		return false
	}

}

function navigationAjax(page, args, target, callback) {
	
	if (target==undefined)
		target="leftpart"
			
	displayThis('leftpart');
	hideThis('subcontent_container');
	window.scrollTo(0,0);
	
	/************ Gestion Sous Menu *************/
	var h=getMenuHighlight(page);
	if(h == 0) {
		// Menu Home ou Jukebox
		// Masquage des sous-menus
		
		hideThis("bloc_submenu");
		highlightMenu(page);
	}
	else if(h == 1) { 
		// Menu Account
		// Affichage & Highlight des sous-menus
		
		highlightSubMenu(page);
		displayThis("bloc_submenu");
		
	}	
	
	
	/************ Gestion Sous Menu *************/
	
	
	
	
	
	
	if (page == 'voir-profil' && pageEnCours == 'profil') {
		updateProfil();
	}

	var xhr = createXHR();
	
	var script = '/'+ page +'.html';
	
	pageEnCours = page;
	
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	chainePost = '';
	
	if (args) {
		chainePost = '&'+ args;
	}
	
	xhr.send("navigation=voir" + chainePost);
	
	if (target) {
		ajaxLoading(target);
	}
	
	xhr.onreadystatechange = function() {
		// On ne fait quelque chose que si on a tout recu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			if (callback != undefined)
				eval(callback)
			setInnerHTML($(target), xhr.responseText);
		}
	}
}

function naviguerProjet(id) {
	navigationAjax('voir-projet-gratuit', 'idProjet='+ id);
}

function verifierNavigation() {
	var ancre = location.hash.substr(1);
	var parts = ancre.split("?");
	
	if (parts[0] != '' && parts[0] != pageEnCours) {
		if (parts[1]) {
			args = parts[1];
		}
		else {
			args = '';
		}
		
		//navigationAjax(parts[0], args);
	}
	
	//setTimeout('verifierNavigation()', 2000);
}


function getMenuHighlight(page)
{
	switch(page) {
		case "accueil":
		case "jukebox":
			return 0;
		case "voir-profil":
		case "profil":
		case "gerer-playlist":
		case "projet":
		case "messagerie-reception":
		case "beta":
			return 1;
		default:
			return 2;
	}
}

function highlightMenu(id)
{
	var a=$("bloc_menu_container").getElementsByTagName("a");
	$("profile_main").removeAttribute("style");
	for (var i=0;i<a.length;i++)	{a[i].className="menu_inactive";}
	$(id+"_main").className="menu_active";	
}

function highlightSubMenu(id)
{	
	highlightMenu("profile");
	$("profile_main").removeAttribute("style");
	var a=$("bloc_submenu").getElementsByTagName("a");
	for (var i=0;i<a.length;i++)	{a[i].className="menu_inactive";}
	$(id+"_sub").className="menu_active";
	$("account_list").className="hidden";
	setColor('profile_main','#00899B');
	ct(c);	
}