function changeOngletMenu(id, actualMode, newMode) {
	document.getElementById("menuOngletGauche_" + id).className = document.getElementById("menuOngletGauche_" + id).className.replace(actualMode, newMode);
	document.getElementById("menuOngletContent_" + id).className = document.getElementById("menuOngletContent_" + id).className.replace(actualMode, newMode);
	document.getElementById("menuOngletDroite_" + id).className = document.getElementById("menuOngletDroite_" + id).className.replace(actualMode, newMode);
}

function changeBtnPagination(id, mode) {
	if(mode == "on") {
		id.className = "btn_pagination_hover";
	}
	else {
		id.className = "btn_pagination";
	}
}

function trim(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

function emailValid(email)
{
	var place = email.indexOf("@",1);
	var point = email.indexOf(".",place+1);
	
	if ((place > -1)&&(email.length >2)&&(point > 1)) {
		return true;
	}
	else {
		return false;
	}
}

function ajaxLoader() {
	this.actualActuBloc = 1;
	this.actualInterlocuteur = -1;
}

ajaxLoader.prototype.displayActu = function(pageBloc, lang) {
	var actualBloc = this.actualActuBloc;
	document.getElementById("btn_pagination" + this.actualActuBloc).className = "btn_pagination";
	document.getElementById("btn_pagination" + this.actualActuBloc).onmouseover = function(){changeBtnPagination(document.getElementById("btn_pagination" + actualBloc),'on')};
	document.getElementById("btn_pagination" + this.actualActuBloc).onmouseout = function(){changeBtnPagination(document.getElementById("btn_pagination" + actualBloc),'off')};
	document.getElementById("btn_pagination" + this.actualActuBloc).onclick = function(){theAjaxLoader.displayActu(actualBloc,lang)};
	this.actualActuBloc = pageBloc;
	document.getElementById("btn_pagination" + pageBloc).className = "btn_pagination_hover";
	document.getElementById("btn_pagination" + pageBloc).onmouseover = function(){};
	document.getElementById("btn_pagination" + pageBloc).onmouseout = function(){};
	this.callAjax("getBlocArticle",lang);
}

ajaxLoader.prototype.filterInterlocuteur = function(lang) {
	this.actualInterlocuteur = document.getElementById("scar_secteur_filtre").value;
	this.callAjax("getInterlocuteur",lang);
}

ajaxLoader.prototype.callAjax = function(mode,lang) { 
	var httpObject = getXMLHTTP();
	
	if(httpObject)
	{
		switch(mode) {
			case "getInterlocuteur":
				httpObject.open("POST","include/ajaxModules/" + mode + ".php?secteur=" + this.actualInterlocuteur + "&lang=" + lang, true);	
				break;
			case "getBlocArticle":
				httpObject.open("POST","include/ajaxModules/" + mode + ".php?page=" + this.actualActuBloc + "&lang=" + lang, true);	
				break;
		}
	}

	httpObject.onreadystatechange = function()
	{
		/*  When call is finished */
		if (httpObject.readyState==4 && httpObject.responseText)
		{	
			parent.theAjaxLoader.generateJson(httpObject, mode);		
		}
	};
	
	httpObject.send(null)
}

ajaxLoader.prototype.generateJson = function(httpObject, mode) { 
	var toDisplay = "";
	var JSON = eval('(' + httpObject.responseText + ')'); 

	switch(mode) {
		case "getInterlocuteur":
			toDisplay += '<table>';
			for(var aInterlocuteur in JSON.interlocuteurs) {
				toDisplay += '<td style="width:318px;vertical-align:top">';
					toDisplay += '<table>';
						toDisplay += '<tr>';
							toDisplay += '<td rowspan="5" style="padding-right:5px;vertical-align:top">';
								toDisplay += '<img style="border:1px solid #7a7a7a;" src="' + JSON.interlocuteurs[aInterlocuteur].visuel + '" alt="" />';
							toDisplay += '</td>';
							toDisplay += '<td style="vertical-align:top;">' + JSON.interlocuteurs[aInterlocuteur].nom + '</td>';
						toDisplay += '</tr>';
						toDisplay += '<tr>';
							toDisplay += '<td style="vertical-align:top">' + JSON.interlocuteurs[aInterlocuteur].prenom + '</td>';
						toDisplay += '</tr>';
						toDisplay += '<tr>';
							toDisplay += '<td style="vertical-align:top">' + JSON.interlocuteurs[aInterlocuteur].fonction + '</td>';
						toDisplay += '</tr>';
						toDisplay += '<tr>';
							toDisplay += '<td style="vertical-align:top">' + JSON.interlocuteurs[aInterlocuteur].specialite + '</td>';
						toDisplay += '</tr>';
						toDisplay += '<tr>';
							toDisplay += '<td style="vertical-align:top"><a target="_blank" class="lien_gris" style="font-weight:normal" href="mailto://' + JSON.interlocuteurs[aInterlocuteur].email + '">' + JSON.interlocuteurs[aInterlocuteur].email + '</a></td>';
						toDisplay += '</tr>';
					toDisplay += '</table>';
				toDisplay += '</td>';
				
				if(aInterlocuteur%3 == 2) {
					toDisplay += "</tr><tr><td colspan='3' style='height:15px'></td></tr><tr>";
				}
			}
			toDisplay += '</table>';
			document.getElementById("entreprise_interlocuteurs").innerHTML = toDisplay;
			break;
		case "getBlocArticle":
			toDisplay += '<table>';
			for(var aActu in JSON.actus) {
				toDisplay += "<tr>";
					toDisplay += "<td class='bloc_actu'>";
						toDisplay += '<div class="date_bloc_actu">' + JSON.actus[aActu].date_actualite + '</div>';
						toDisplay += '<div class="titre_bloc_actu"><a class="titre_bloc_actu" href="' + JSON.actus[aActu].link + '">' + JSON.actus[aActu].titre + '</a></div>';
						toDisplay += '<div style="text-align:justify;padding-right:15px;" class="texte_bloc_actu">' + JSON.actus[aActu].contenu + '</div>';
						
						if(aActu < JSON.actus.length-1) {
							toDisplay += '<div class="barre_actu"></div>';
						}
						
					toDisplay += "</td>";
				toDisplay += "</tr>";
			}
			toDisplay += "</table></td></tr>";
			document.getElementById("actus").innerHTML = toDisplay;
			
			for(var j=0; j<JSON.nbPages; j++) {
				if(j>=JSON.debDisplay && j<(JSON.debDisplay+8)) {
					document.getElementById("btn_pagination" + (j+1)).style.display = "block";
				}
				else {
					document.getElementById("btn_pagination" + (j+1)).style.display = "none";
				}
			}

			if(JSON.debDisplay > 0) {
				document.getElementById("previousPage").style.display = "block";
			}
			else {
				document.getElementById("previousPage").style.display = "none";
			}
			
			if(JSON.debDisplay == JSON.maxDebDisplay) {
				document.getElementById("nextPage").style.display = "none";
			}
			else {
				document.getElementById("nextPage").style.display = "block";
			}
		break;
	}
}
