/*********************YVONNE****************************/
 var arraypanel= new Array();
 var arraypanelbymot= new Array();
 var arraypanelbycat= new Array();
/*********************YVONNE****************************/
/****************************TA/JULIEN************************/


invitorArray = new Array();


function TraitementTemplateReponse(questionid,iduser,profilewebuser,isautorise_reponse,isautorise){

	var thedata="";
	thedata+="iduser="+encodeURIComponent(iduser);
	thedata+="&isautorise_reponse="+encodeURIComponent(isautorise_reponse);	
	thedata+="&profilewebuser="+encodeURIComponent(profilewebuser);	
	thedata+="&isautorise="+encodeURIComponent(isautorise);	
	thedata+="&questionid="+encodeURIComponent(questionid);		
						
	//alert(thedata);
	//getDataValueJSON(nom fichier traitement de thedata,les données ici thedata,fonction qui va traiter le donnée de retour)
	getDataValueJSON("question_answer/traitement_reponse.php", thedata, repTraitementTemplateReponse);
}
function repTraitementTemplateReponse(jsonRep){
	
	var strTuto = "";
	var tplBtnModif = "";
	var tplBtnSignal = "";
	var tplTutoRep = "";
	var tplDateModif = "";
	var res="";
	var array=json(jsonRep);//1ere chose à faire
	var iduser= g1J(array,'iduser');//si tout valeur tout seul
	var questionid = g1J(array,'questionid');
	var alreadyNote = g1J(array,'alreadyNote');
	var isautorise = g1J(array,'isautorise');
	var authorQuestionId = document.getElementById('authorQuestionId').value;	
	var score = g1J(array,'note');
	var responseNoted= g1J(array,'responseNoted');
	var commentaire = g1J(array,'commentaire')
	var ScoreLineComment = "";
	var testarray=array.testarray;//si recupere tableau
	var repFromBank = g1J(array,'repFromBank');
	var TestGlobalArray = new Array();
	var ContainDiv = "";
	var sumimage="";
	var responseid = 0;
	var tutoid = 0;
	var hastuto = 0;
	var statusid = g1J(array,'statusid');
	var star = document.getElementById('templateImageEvaluation').innerHTML;

	var snapshot = "";
	
	var starHaft = document.getElementById('templateImageHaftEvaluation').innerHTML;

	var starFill = document.getElementById('templateImageFillEvaluation').innerHTML;
	var image="";	

	var contain = "";
	var date_modif = "";
	var nb_modif = 0;
	var date_creation = "";	
	var bgaction = "";
	var templateReponseCopie = "";
	var tabVide = "<table style='width:150px;'><tr><td style='width:142px;'>&nbsp;</td></tr></table>";

	
	if (testarray != null) {
		for (var i = 0; i < testarray.length; i++) {
			
			var reponseid= g1J(testarray[i],'reponseid');
			var contain= g1J(testarray[i],'contain');//si tout valeur tout seul
			var date_creation = g1J(testarray[i],'date_creation');//si tout valeur tout seul
			var date_modif = g1J(testarray[i],'date_modif');
			var nbmodif= g1J(testarray[i],'nbmodif');
			var authorid_reponse= g1J(testarray[i],'authorid_reponse');//si tout valeur tout seul
			var nickname= g1J(testarray[i],'nickname');//si tout valeur tout seul
			tutoid = g1J(testarray[i],'tutoid');
			hastuto =  g1J(testarray[i],'hastuto');
			var UrlFotoReponse = g1J(testarray[i],"UrlFotoReponse");

			snapshot = g1J(testarray[i],'snapshot');
		
			TestGlobalArray.push({
				reponseid:reponseid,
				contain:contain,
				date_creation:date_creation,
				date_modif:date_modif,
				nbmodif:nbmodif,
				UrlFotoReponse:UrlFotoReponse,
				authorid_reponse:authorid_reponse,
				tutoid:tutoid,
				hastuto:hastuto,
				nickname:nickname,
				snapshot:snapshot
				});
		}
	}
	var resultdiv = document.getElementById('result');
	if (TestGlobalArray.length != 0) {
		
		for (var i = 0; i < TestGlobalArray.length; i++) {
		
			//recupérer une valeur du tableau=> nomdutableau[position].nomarecuperer
			var divname = "test" + TestGlobalArray[i].authorid_reponse;//nom div
			
			tplBtnModif = tabVide;
			tplBtnSignal = "";
			tplTutoRep = "";
			tplDateModif ="";
			strTuto = "";
			sumimage="";
			ContainDiv = "ContainDiv_"+TestGlobalArray[i].reponseid;
			
			var templateReponse = document.getElementById('templateReponse').innerHTML;//recupere contenu de template

			contain = TestGlobalArray[i].contain;
			date_modif = TestGlobalArray[i].date_modif[0]+" "+MLJS(TestGlobalArray[i].date_modif[1]);
			nb_modif = TestGlobalArray[i].nbmodif;
			
			date_creation = MLJS("txtrepposteele")+" "+ TestGlobalArray[i].date_creation[0]+" "+MLJS(TestGlobalArray[i].date_creation[1]);	
			
			responseid = TestGlobalArray[i].reponseid;
			hastuto = TestGlobalArray[i].hastuto;
			tutoid = TestGlobalArray[i].tutoid;
			bgaction = "bgaction";
			
			templateReponseCopie = "templateReponseCopie_"+responseid;
			templateReponse = repS(templateReponse,"templateReponse",templateReponseCopie);			
			templateReponse = repS(templateReponse,"UrlFotoReponse",TestGlobalArray[i].UrlFotoReponse);
			templateReponse = repS(templateReponse,"UrlRep","ficheuser.php?nickname="+encodeURIComponent(TestGlobalArray[i].nickname));
			templateReponse = repS(templateReponse, "nickname", TestGlobalArray[i].nickname);
			
					
			if (nb_modif != 0 && nb_modif != null ) { //affiche date de modif s'il y en a une
			
				tplDateModif = document.getElementById('templateDateModif').innerHTML;
				tplDateModif = repS(tplDateModif, "modifdate", date_modif);
				tplDateModif = repS(tplDateModif, "nbmodif", nb_modif);				
			}

			
			if (tutoid != 0 && hastuto == 1) { //affiche bouton reponse en video s'il y a un tuto
				if(iduser != 0 && iduser!=""){
					strTuto = "TUTO"+tutoid+"T"+iduser;					
			
				}

				else
					strTuto = "TUTO"+tutoid+"T-2";
					
				tplTutoRep=document.getElementById('templateTutoReponse').innerHTML;
				tplTutoRep = repS(tplTutoRep, "tutoid", strTuto);
	
			}	
		
			if ((TestGlobalArray[i].snapshot == null)||(TestGlobalArray[i].snapshot == "NULL")) {
					snapshot = "images/sp_eclass.jpg";
			} else { 
					snapshot = TestGlobalArray[i].snapshot;
			}
				
			tplTutoRep = repS(tplTutoRep, "snapshotQ", snapshot);			
				
			if(iduser != TestGlobalArray[i].authorid_reponse ){
					var markerflag="responseid="+responseid;
					addflaginfo(responseid,MLJS('txtsignaler'));
					tplBtnSignal = document.getElementById('templateLienAction').innerHTML;		
					tplBtnSignal = repS(tplBtnSignal, "actionname", MLJS("txtsignaler"));
					if(isautorise != 6)
						tplBtnSignal = repS(tplBtnSignal, "urlaction", "flagthis('"+markerflag+"','"+ responseid +"',4);");			
					else
						tplBtnSignal = repS(tplBtnSignal, "urlaction", "window.location='newuser.php'");									
					//alert(tplBtnSignal)
			}

			var tplContainResponse = document.getElementById('templateContainResponse').innerHTML;
			
			tplContainResponse = repS(tplContainResponse,"ContainDiv",ContainDiv);
			tplContainResponse = repS(tplContainResponse, "contain", contain);
			
						
			if( isautorise == 1 || ( iduser != TestGlobalArray[i].authorid_reponse  && ( isautorise == 0 )  )  ){
				
			
				if( TestGlobalArray[i].authorid_reponse != iduser ){
					tplContainResponse = "<img src = 'images/groupe_image.gif' />";
					date_creation = "";
					tplDateModif = "";
					tplBtnSignal = "";
					bgaction = "";
					tplTutoRep = "";
				}
							
			}
			

			
			
			templateRepons = repS(templateReponse, "templateReponse", divname);
//			templateReponse = repS(templateReponse, "ContainDiv", ContainDiv);
			templateReponse = repS(templateReponse, "contain", tplContainResponse);
			templateReponse = repS(templateReponse, "date", date_creation);
			templateReponse = repS(templateReponse, "DateModif", tplDateModif);
			//templateReponse = repS(templateReponse, "Td", bgaction);
			templateReponse = repS(templateReponse, "BtnSignaler", tplBtnSignal);									

			//alert(tplTutoRep)
			templateReponse = repS(templateReponse, "TutoReponse", tplTutoRep);
	


		if (alreadyNote == 0) {


			
				if (authorQuestionId == iduser) { //affiche bouton choisir meilleure reponse si auteur de question est webuser				
					tplBtnModif = document.getElementById('templateBoutonAction').innerHTML;
					//templateReponse = repS(templateReponse, "Td", "bgaction");
					
					tplBtnModif = repS(tplBtnModif, "actionname", MLJS("txtnoterresponse"));
					tplBtnModif = repS(tplBtnModif, "urlaction", "window.location='rate_best_reponse.php?responseid=" + TestGlobalArray[i].reponseid + "'");
					
					
					
				}
				
				else 
					if (TestGlobalArray[i].authorid_reponse == iduser && statusid == 1) { //affiche bouton modifier si auteur de reponse est webuser	
						tplBtnModif = document.getElementById('templateBoutonAction').innerHTML;
						//templateReponse = repS(templateReponse, "Td", "bgaction");
						tplBtnModif = repS(tplBtnModif, "actionname", MLJS("txtmodifier"));
						tplBtnModif = repS(tplBtnModif, "urlaction", "modif_response('FormRepondre'," + responseid + "," + tutoid + "," + hastuto + ");");
						
						
					}
					

				
			
			if(statusid !=1)
				document.getElementById('actionquestion').style.display = "none";			
			templateReponse = repS(templateReponse, "BoutonAction", tplBtnModif);
			templateReponse = repS(templateReponse, "StrCommentLine", "");									
			templateReponse = repS(templateReponse, "CommentScoreLine", "");	
			templateReponse = repS(templateReponse, "Comment", "");							
			
					

		
		}
		else{
			
			if (responseNoted == TestGlobalArray[i].reponseid) {
				sumimage ="<b>"+MLJS('txtbestanswer')+"</b><br />";
				image = "";
				
				for (var str = 0; str < 5; str++) {
					image = star;
					if ((score > str) && (score < (str + 1))) 
						image = starHaft;
					else 
						if (score >= (str + 1)) 
							image = starFill;
					sumimage += image;
					ScoreLineComment +=image;
				}
				
				sumimage = repS(sumimage, "Score", score);
				templateReponse = repS(templateReponse, "StrCommentLine",MLJS("txtcommentaire"));					
				templateReponse = repS(templateReponse, "CommentScoreLine",ScoreLineComment);	
				templateReponse = repS(templateReponse, "Comment",commentaire);										
			}
			else{
				templateReponse = repS(templateReponse, "StrCommentLine", "");					
				templateReponse = repS(templateReponse, "CommentScoreLine", "");	
				templateReponse = repS(templateReponse, "Comment", "");																		
			}

			templateReponse = repS(templateReponse, "BoutonAction", sumimage);

			
	
	
		}
			//alert(templateReponse);
				
			res += templateReponse;
		}
		
	resultdiv.innerHTML = res;
	if(alreadyNote !=0)		
		var hightLightNote = document.getElementById("templateReponseCopie_"+responseNoted).style.backgroundColor = "#DDEBF6";		
	}
	else
		resultdiv.innerHTML = MLJS("txtpasresultat");
		
	if(repFromBank == 2){
		
	}	
	
}

function addResponse(questionid,userid,contain,profilewebuser,isautorise_reponse,isautorise){
	
	var msg = document.getElementById(contain).value;
	var responseid = document.getElementById('responseid').value;
	var tutoid = document.getElementById('TutoIdFromEclass').value;
	var data = "questionid="+questionid+"&userid="+userid+"&contain="+codeUrl(msg)+"&responseid="+responseid+"&tutoid="+tutoid;
//	var isTuto = document.getElementById('CheckBoxForCreateTuto');
	var hastuto = 1;
//	if(isTuto.checked == true){
//		hastuto = 1;
//	}

		
	
	data +="&profilewebuser="+profilewebuser+"&isautorise_reponse="+isautorise_reponse+"&isautorise="+isautorise+"&hastuto="+hastuto;
	//alert(data);
	document.getElementById('ReponseDiv').innerHTML = MLJS('txtdejareponduquestion');
	getDataValueJSON("question_answer/traiter_reponse.php",data,repResponse);
	closeFrm('FormRepondre');
}
function repResponse(jsonRep){
	jsonRep = json(jsonRep);
	var userid = g1J(jsonRep,"userid");
	var profilewebuser = g1J(jsonRep,"profilewebuser");
	var isautorise = g1J(jsonRep,"isautorise");
	var isautorise_reponse = g1J(jsonRep,"isautorise_reponse");	
	var questionid = g1J(jsonRep,"questionid");	
	var repFromBank = g1J(jsonRep,"repFromBank");	
	if(repFromBank == 2){
		
		showalertpanel(MLJS("txtattention"), "error of bank ", '', 3, 1, '');
	}
	else	
		TraitementTemplateReponse(questionid,userid,profilewebuser,isautorise_reponse,isautorise);	
	
}

function modif_response(divName,responseid,tutoid,hastuto){

	closeFrm(divName);
	document.location = "#link_frm_response";
	document.getElementById('responseid').value = responseid;
	document.getElementById('TutoIdFromEclass').value = tutoid;
	
	if(hastuto != 0){
		//document.getElementById('CheckBoxForCreateTuto').checked = true;	
		document.getElementById('ReponseWithTuto').style.display = "block";
	}
	else{
		//document.getElementById('CheckBoxForCreateTuto').checked = false;	
		document.getElementById('ReponseWithTuto').style.display = "none";
	}
			
	var containDOM = document.getElementById('contain');
	
	var value = document.getElementById('ContainDiv_'+responseid).value;

	containDOM.value = value;
	

}



function closeQuestion(btnDivResponse){
	closeFrm_update(btnDivResponse,1);
}

function showFrmResponse(divName){
	closeFrm_update(divName,0);
	document.location = "#link_frm_response";
	
}


function btnAction(mode){
	
	var strListUser = "";
	for(var i=0 ;i< invitorArray.length ;i++){
		strListUser +=invitorArray[i].userid;
		if(i < invitorArray.length )
			strListUser +=";";
		}
		
	switch(mode){

		case 'ok':
		//	alert('ok');
			document.getElementById('isactive').value = 1;	
			
		break;		

		case 'update':
		//	alert('update');
			document.getElementById('listUserPartage').value=strListUser;			
			document.getElementById('isupdate').value = 1;	
			
		break;		
					
		case 'preview':
			//	alert('pre');
			document.getElementById('ispreview').value = 1;
			document.getElementById('listUserPartage').value=strListUser;
			
		break;
		
		case 'cancel':
			//showalertpanel(MLJS("txtattention"), MLJS("txtsursuppquestion"),'',3,1,'');
			//alert('cancel');
			document.getElementById('isactive').value = -1;	
			
		break;
			
		case 'modif':
			//alert('modif');
			document.getElementById('ismodif').value = 1;	
			
		break;		
				
	}
}

function deleteQuestion(questionid){
		

	var array = new Array();
	array.push(questionid);
	array.push(-1);
	showalertpanel(MLJS("txtattention"), MLJS("txtsursuppquestion"),array,3,2,repDeleteQuestion);
			
}
function repDeleteQuestion(array){
	var questionid = array[0];
	var isactive = array[1];
	var data = "isactive="+isactive+"&questionid="+questionid+"&mode=1";
	getDataValueJSON("question_answer/question_answer_op.php",data,okDeleteQuestion);


	
}
function okDeleteQuestion(repJson){
	
		repJson = json(repJson);
		var res = g1J(repJson,"res");
		var query = g1J(repJson,"query");
		var repFromBank = g1J(repJson,"repFromBank");
		if (repFromBank == 0) {
			if (res == 0) 
				window.location = "question_details.php";
			else 
				showalertpanel(MLJS("txtattention"), "error " + res + " & " + query, "", 3, 1, "");
		}
		else if(repFromBank == 2){
				showalertpanel(MLJS("txtattention"), "error bank", "", 3, 1, "");			
		}
}	


function loadViewCode(code,ismodif){
	
	var modeShareDOM = document.getElementById('ContainModeShareDiv');
	var containChoix = document.getElementById('containChoixShareDiv').innerHTML;
	containChoix = repS(containChoix,"listViewCode","listViewCode");
		
	var listViewCode  = "";
	

	if(code == 4 && ismodif == 1){


		modeShareDOM.innerHTML = containChoix;					
	//	displayDestinataire();
		
		
	}


}

function setListChoiceShare(){
	

	var containListChoiceShareDiv = document.getElementById('containListChoiceShareDiv').innerHTML;
	containListChoiceShareDiv = repS(containListChoiceShareDiv,"listDestinataireCopieDiv","listDestinataireCopieDiv");
	containListChoiceShareDiv = repS(containListChoiceShareDiv,"txtChoiceUserDiv","txtChoiceUserDiv");	
	containListChoiceShareDiv = repS(containListChoiceShareDiv,"keyWord","keyWord");	
	containListChoiceShareDiv = repS(containListChoiceShareDiv,"listUserFoundDivCopie","listUserFoundDivCopie");					
	var listViewCode = document.getElementById('listViewCode');
	listViewCode.innerHTML = containListChoiceShareDiv;
	displayDestinataire();
	closeFrm_update('listViewCode',0);
}

function addInvited(id,nickname){
	
    invitorArray.push({
        userid: id,
        nickname: nickname,
        email:''
    });
}





function start_count_down(mode) {
	
	if(mode == 1)
	 	redo();
 		
}

function disPlay(wk,day,hrs,mins,secs) {
	
 	var res = "";
 	
 	if(wk != 0)
	 	res +=wk + " week - ";
 	if(day != 0)
	 	res +=day + " jour - ";
 
 	if(hrs <= 9) {
 		
  		res += " 0";
  		
 	} else {
  		res += " ";
 	} 	
 	
 	res +=hrs + ":";
 	
 	if(mins <= 9) {
  		res += " 0";
 	} else {
  		res += " ";
 	}
 	res += mins + ":";
 	
 	if(secs <= 9) {
  		res += "0" + secs;
 	} else {
  		res += secs;
 	}
 
 	return(res);
 
}

function redo() {
	var divDOM = document.getElementById('compteurDiv');
 	secs--;
 	if(secs == -1) {
  		secs = 59;
  		mins--;
 	}
 	if(mins == -1){
 		mins = 59;
 		hrs --;
 	}
 	if(hrs == -1){
 		
 		hrs = 23;
 		day --;
 		
 	}
 	if(day == - 1){
 		
 		day = 6;
 		wk --;		
 	}
// 	alert(action);
 	divDOM.innerHTML = disPlay(wk,day,hrs,mins,secs); // setup additional displays here.
 	if((mins == 0) && (secs == 0) && ( hrs == 0 ) && ( day == 0 ) && (wk == 0) ) {
		divDOM.style.display = "none";
		closeQuestion('ReponseDiv');
		closeFrm_update('actionquestion',1);
		
		// to do call fct update status

 	} else {
 		start_count_down = setTimeout("redo()",1000);
 	}
	
}





function sendInfo2CreateTuto(questionid,topicid,type){
			
			var questionid = document.getElementById('questionid').value;
			var TutoIdFromEclass = document.getElementById('TutoIdFromEclass').value;
			var data = "idsubject="+questionid+"&idmsgparent="+questionid+"&tutoIdFromEclass="+TutoIdFromEclass+"&topicid="+topicid+"&type="+type;
			//alert(data);
			getDataValueJSON("sscripts/inseclassanswer.php",data,repSendInfo2CreateTuto);
		
}

function repSendInfo2CreateTuto(jsonRep){
	
	jsonRep = json(jsonRep);
	var code = g1J(jsonRep,"code");
	var idtuto = g1J(jsonRep,"idtuto");
	var pid =  g1J(jsonRep,"pid");
	var questionid = g1J(jsonRep,"msgid");
	var scode = "LIVE"+pid;
	var notModif = g1J(jsonRep,"notModif");
	
	if(code && pid && idtuto){
		
		
		if(notModif == 0){
			window.open('launchclass.php?scode='+scode+"&currentqid="+questionid,'','left=0,top=0');			
		}
		else
			window.open('launchclass.php?scode='+scode,'','left=0,top=0');						
		
		document.getElementById('TutoIdFromEclass').value = idtuto;
		
	}
	else
		
		showalertpanel('',"data error",'',2,1,'');	
}


function loadResponse(mode,questionid,userid,profilewebuser,isautorise_reponse,isautorise){

	if(mode == 1)
		TraitementTemplateReponse(questionid,userid,profilewebuser,isautorise_reponse,isautorise);		
}

function closeModeShare(val,modeCallFct){
	//alert("ta");
	var modeShareDOM = document.getElementById('ContainModeShareDiv');
	var currencyDOM = document.getElementById('currencyDiv');
	var containCurrency = document.getElementById('containCurrencyDiv').innerHTML;
	var containFree = document.getElementById('containChoixFreeDiv').innerHTML;
	var containChoix = document.getElementById('containChoixShareDiv').innerHTML;
	containChoix = repS(containChoix,"listViewCode","listViewCode");
		
	var listViewCode  = "";
	
	var containListChoiceShareDiv = document.getElementById('containListChoiceShareDiv').innerHTML;

		
 	if(val == 0){
		if(modeCallFct != 0 ){
			
			showalertpanel(MLJS("txtattention"), MLJS("txtmsgchoixquestiongratuite"),'',3,1,'');		
			closeFrm_update('currencyDiv',1);			
		}
		
		currencyDOM.innerHTML = "";
		modeShareDOM.innerHTML = containFree;
		
		

 		}
 	else{
		
		currencyDOM.innerHTML = containCurrency;
		modeShareDOM.innerHTML = containChoix;		
		if(modeCallFct != 0 ){

			closeFrm_update('currencyDiv',2);

			containListChoiceShareDiv = repS(containListChoiceShareDiv,"listDestinataireCopieDiv","listDestinataireCopieDiv");
			containListChoiceShareDiv = repS(containListChoiceShareDiv,"txtChoiceUserDiv","txtChoiceUserDiv");	
			containListChoiceShareDiv = repS(containListChoiceShareDiv,"keyWord","keyWord");	
			containListChoiceShareDiv = repS(containListChoiceShareDiv,"listUserFoundDivCopie","listUserFoundDivCopie");				
			
			listViewCode  = document.getElementById('listViewCode');
			listViewCode.innerHTML =  containListChoiceShareDiv;


						
		}

	}


 
 }


 
function checkCreateQuestion(){
 
 	var titre = document.getElementById('titre').value;
 	var description = document.getElementById('description').value;

	if ((titre == "") || (description == "")){
		showalertpanel(MLJS("txtattention"), MLJS("txtremplirtouschamps"),'',3,1,'');
		return false;
	}
	return true;
} 	

function displayStartForRating(divName){
	var divDOM = document.getElementById(divName);
	var idtype = 0;
	var body = 
 '<table>'+
  '<tr>'+
  '<td align=left class=\"myratingdiv\">'+
 '<a href=\"javascript:selectRating('+idtype+', 0);\" title=\"0/5\" onmouseout=\"javascript:backToSelectedRating('+idtype+');\" onmouseover=\"javascript:colorStars('+idtype+', 0);\">&nbsp;&nbsp;&nbsp;&nbsp;</a>'+
 '<a href=\"javascript:selectRating('+idtype+', 1);\"><img onmouseout=\"javascript:backToSelectedRating('+idtype+');\" onmouseover=\"javascript:colorStars('+idtype+', 1);\" id=\"altstar1_'+idtype+'\" name=\"altstar1_'+idtype+'\" src=\"images/starfill.gif\" border=\"0\" alt=\"1/5\" title=\"1/5\" />&nbsp;&nbsp;</a>'+
 '<a href=\"javascript:selectRating('+idtype+', 2);\"><img onmouseout=\"javascript:backToSelectedRating('+idtype+');\" onmouseover=\"javascript:colorStars('+idtype+', 2);\" id=\"altstar2_'+idtype+'\" name=\"altstar1_'+idtype+'\" src=\"images/starfill.gif\" border=\"0\" alt=\"2/5\" title=\"2/5\" />&nbsp;&nbsp;</a>'+
'<a href=\"javascript:selectRating('+idtype+', 3);\"><img onmouseout=\"javascript:backToSelectedRating('+idtype+');\" onmouseover=\"javascript:colorStars('+idtype+', 3);\" id=\"altstar3_'+idtype+'\" name=\"altstar1_'+idtype+'\" src=\"images/starfill.gif\" border=\"0\" alt=\"3/5\" title=\"3/5\" />&nbsp;&nbsp;</a>'+
 '<a href=\"javascript:selectRating('+idtype+', 4);\"><img onmouseout=\"javascript:backToSelectedRating('+idtype+');\" onmouseover=\"javascript:colorStars('+idtype+', 4);\" id=\"altstar4_'+idtype+'\" name=\"altstar1_'+idtype+'\" src=\"images/star.gif\" border=\"0\" alt=\"4/5\" title=\"4/5\" />&nbsp;&nbsp;</a>'+
 '<a href=\"javascript:selectRating('+idtype+', 5);\"><img onmouseout=\"javascript:backToSelectedRating('+idtype+');\" onmouseover=\"javascript:colorStars('+idtype+', 5);\" id=\"altstar5_'+idtype+'\" name=\"altstar1_'+idtype+'\" src=\"images/star.gif\" border=\"0\" alt=\"5/5\" title=\"5/5\" />&nbsp;&nbsp;</a>'+
 '<label id=\"selectedrating_'+idtype+'\" name=\"selectedrating_'+idtype+'\">3</label>/5'+
 '</td>'+
 '</tr>'+
 '</table>';	
 
 divDOM.innerHTML = body;	
	
}

function setNoteForResponse(){
	
	
	var contain = document.getElementById('contain').value;
	var note = document.getElementById('selectedrating_0').innerHTML;
	var questionid = document.getElementById('questionid').value;	
	var authorQuestionId = document.getElementById('authorQuestionId').value;
	var responseid = document.getElementById('responseid').value;	
	
	var array = new Array();
	array.push(questionid);
	array.push(authorQuestionId);
	array.push(responseid);
	array.push(contain);
	array.push(note);				

	//document.getElementById('note').value = document.getElementById('selectedrating_0').innerHTML
	showalertpanel(MLJS("txtattention"),MLJS("txtsurchoisirmeilleurereponse"),array,3,2,repChooseBestResponse);
}

function repChooseBestResponse(array){
	
	var contain = array[3];
	var note = array[4];
	var questionid = array[0];	
	var authorQuestionId = array[1];
	var responseid = array[2];
		
	var data = "responseid="+responseid+"&questionid="+questionid+"&authorQuestionId="+authorQuestionId+"&mode=2"+"&contain="+contain+"&note="+note;	
	
	getDataValueJSON("question_answer/traiter_reponse.php",data,repChooseBestResponseForData);


	
}
function repChooseBestResponseForData(repJson){
		repJson = json(repJson);
		var questionid = g1J(repJson,"questionid");
		window.location = "question_details.php?isactive=1&questionid="+questionid;			
}
function voteQuestion(mode,questionid,userid){
	if (userid != '') {
		if (alreadyVote == 0) {
			var data = "questionid=" + questionid + "&userid=" + userid + "&mode=" + mode;
			getDataValueJSON("question_answer/vote_question.php", data, repvoteQuestion);
		}
		else {
			showalertpanel(MLJS("txtattention"), MLJS("txtdejanotequestion"), '', 3, 1, '');
		}
	}
	else
		alert('haha');

	
}

function repvoteQuestion(repJson){
	alreadyVote ++;
	var data = json(repJson);
	var mode = g1J(data,"mode");
	var nbvote = g1J(data,"nbvote");
	
	var div = "";
	if(mode == 1){
		div = document.getElementById('nbVotePositifDiv');

	}
	else{
		div = document.getElementById('nbVoteNegatifDiv');		
	}

	div.innerHTML = "( "+nbvote+" )";	
}


function goBack(url){
	//alert(url)
	window.location = url;
}

/****************************TA/JULIEN************************/

/****************************YVONNNE************************/
function ChoiceMenuQuestionIndex(panel,iduser,critere,sens){
	
	showQuestionReponsePanel(panel);
	var thedata="";
	thedata +="iduser=" + encodeURIComponent(iduser);
	thedata +="&sens=" + encodeURIComponent(sens);
	thedata +="&critere=" + encodeURIComponent(critere);
	
	document.getElementById("resultquestionindex").innerHTML = "<br /><br /><img src='images/load.gif' alt='Chargement...'' title='Chargement...'' /><br /><br />";
	document.getElementById("resultquestionindex").style.visibility = "visible";
	
	if(panel==1)
		getDataValueJSON("sscripts/best_of.php", thedata, repResultBestOf);//critere 5 vote_plus et 6 vote_moins
	
	else if(panel==2)
		getDataValueJSON("sscripts/search_questionactive.php", thedata, repResultQuestion);
	
	else if(panel==3)
		getDataValueJSON("sscripts/search_mesquestions.php", thedata, repResultQuestion);
	
	else
		getDataValueJSON("sscripts/search_mesreponses.php", thedata, repResultQuestion);
	

}

function showDivSearchQuesRep(value){
	if(value==0){
		document.getElementsByName("boutonradio_searchquesrep")[0].checked=true;
 		document.getElementById("divcheck_searchbyword").style.display = "block";
		document.getElementById("divcheck_searchbycat").style.display = "none";
		document.getElementById('resultquestionindex').style.display="none";
		
		}
	if(value==1){
		document.getElementsByName("boutonradio_searchquesrep")[1].checked=true;
 		document.getElementById("divcheck_searchbyword").style.display = "none";
		document.getElementById("divcheck_searchbycat").style.display = "block";
		document.getElementById('resultquestionindex').style.display="none";
		
		}
	
}
function showQuestionReponsePanel(value){
		
	  //var templateRechercheQuestionReponse= document.getElementById('templateRechercheQuestionReponse');
	  var link4="";
	  var link3="";
	  var link1 = document.getElementById("link1");
      var link2 = document.getElementById("link2");
	  if(document.getElementById("link3")!=null)
	  	link3 = document.getElementById("link3");
	   if(document.getElementById("link4")!=null)
	  	link4 = document.getElementById("link4");
      var link5 = document.getElementById("link5");
		document.getElementById('resultquestionindex').style.display="block";
		document.getElementById('templateRechercheQuestionReponse').style.display="none";
	switch(value)
	{
		
		case 1:			
					link1.className = "linkActiveQuesRep";
					link2.className = "linkInactiveQuesRep";
					link3.className = "linkInactiveQuesRep";
					link4.className = "linkInactiveQuesRep";
					link5.className = "linkInactiveQuesRep";
		break;
		
		case 2:
					link1.className = "linkInactiveQuesRep";
					link2.className = "linkActiveQuesRep";
					link3.className = "linkInactiveQuesRep";
					link4.className = "linkInactiveQuesRep";
					link5.className = "linkInactiveQuesRep";
		break;
		
		case 3:
					link1.className = "linkInactiveQuesRep";
					link2.className = "linkInactiveQuesRep";
					link3.className = "linkActiveQuesRep";
					link4.className = "linkInactiveQuesRep";
					link5.className = "linkInactiveQuesRep";
					
		break;
		
		case 4:
					link1.className = "linkInactiveQuesRep";
					link2.className = "linkInactiveQuesRep";
					link3.className = "linkInactiveQuesRep";
					link4.className = "linkActiveQuesRep";
					link5.className = "linkInactiveQuesRep";
					
		break;
		
		case 5:
					link1.className = "linkInactiveQuesRep";
					link2.className = "linkInactiveQuesRep";
					link3.className = "linkInactiveQuesRep";
					link4.className = "linkInactiveQuesRep";
					link5.className = "linkActiveQuesRep";
					document.getElementById('resultquestionindex').style.display="none";
					document.getElementById('templateRechercheQuestionReponse').style.display="block";
		break;	
	}
}

function RechercherQuestion(link,choicesearch){
	showQuestionReponsePanel(link);
	showDivSearchQuesRep(choicesearch);
}
function repResultQuestion(jsonRep){
	var questionarray=json(jsonRep);
	var questioninfo=questionarray.questioninfo;
	var QuestionInfoArray=new Array();
	
	var unArray = new Array();
	 arraypanel= new Array();
	var iduser = g1J(questionarray,'iduser');
	var critere = g1J(questionarray,'critere');
	var sens = g1J(questionarray,'sens');
	var panel = g1J(questionarray,'panel');
	
	unArray.push(iduser);
	unArray.push(critere);
	unArray.push(sens);
	unArray.push(panel);
	
	arraypanel.push({
		critere:critere,
		sens:sens
	});
	
	var nbQuestiontotal = g1J(questionarray,'nbQuestiontotal');
	var nbQuestionbypage = g1J(questionarray,'nbQuestionbypage');
	var page = g1J(questionarray,'page');
	
	QuestionInfoArray=remplirArrayQuestion(questioninfo);

	var resultdiv = document.getElementById('resultquestionindex');
	var res = "";
	res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuiv",unArray,page);
		
	var templateIndexQuetionHautDiv = document.getElementById('templateIndexQuetionHautDiv').innerHTML;
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"nbresultat",nbQuestiontotal);
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebydateasc","javascript:ShowQuestionSuiv('"+iduser+"',1,1,'"+panel+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebydatedesc","javascript:ShowQuestionSuiv('"+iduser+"',1,0,'"+panel+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebynbrepasc","javascript:ShowQuestionSuiv('"+iduser+"',2,1,'"+panel+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebynbrepdesc","javascript:ShowQuestionSuiv('"+iduser+"',2,0,'"+panel+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebystatutasc","javascript:ShowQuestionSuiv('"+iduser+"',3,1,'"+panel+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebystatutdesc","javascript:ShowQuestionSuiv('"+iduser+"',3,0,'"+panel+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebyratingasc","javascript:ShowQuestionSuiv('"+iduser+"',4,1,'"+panel+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebyratingdesc","javascript:ShowQuestionSuiv('"+iduser+"',4,0,'"+panel+"',"+page+")");
	
	res += templateIndexQuetionHautDiv;
	if(QuestionInfoArray.length!=0){
		res +=addResultQuestionInfoToTemplate(QuestionInfoArray,iduser,panel,page);
		res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuiv",unArray,page);
	
		resultdiv.innerHTML ="";
		resultdiv.innerHTML = res;
	}
	else
			resultdiv.innerHTML = MLJS("txtpasresultat");

	
}
function repResultBestOf(jsonRep){
	var questionarray=json(jsonRep);
	var questioninfo=questionarray.questioninfo;
	var QuestionInfoArray=new Array();
	
	var unArray = new Array();
	 arraypanel= new Array();
	var iduser = g1J(questionarray,'iduser');
	var critere = g1J(questionarray,'critere');
	var sens = g1J(questionarray,'sens');
	var panel = g1J(questionarray,'panel');
	
	unArray.push(iduser);
	unArray.push(critere);
	unArray.push(sens);
	unArray.push(panel);
	
	arraypanel.push({
		critere:critere,
		sens:sens
	});
	
	var nbQuestiontotal = g1J(questionarray,'nbQuestiontotal');
	var nbQuestionbypage = g1J(questionarray,'nbQuestionbypage');
	var page = g1J(questionarray,'page');
	
	QuestionInfoArray=remplirArrayQuestion(questioninfo);

	var resultdiv = document.getElementById('resultquestionindex');
	var res = "";
	res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuiv",unArray,page);
		
	var templateBestOfDiv = document.getElementById('templateBestOfDiv').innerHTML;
	templateBestOfDiv = repS(templateBestOfDiv,"nbresultat",nbQuestiontotal);
	templateBestOfDiv = repS(templateBestOfDiv,"triebydateasc","javascript:ShowQuestionSuiv('"+iduser+"',5,1,'"+panel+"',"+page+")");
	templateBestOfDiv = repS(templateBestOfDiv,"triebydatedesc","javascript:ShowQuestionSuiv('"+iduser+"',5,0,'"+panel+"',"+page+")");
	templateBestOfDiv = repS(templateBestOfDiv,"triebynbrepasc","javascript:ShowQuestionSuiv('"+iduser+"',6,1,'"+panel+"',"+page+")");
	templateBestOfDiv = repS(templateBestOfDiv,"triebynbrepdesc","javascript:ShowQuestionSuiv('"+iduser+"',6,0,'"+panel+"',"+page+")");
	
	res += templateBestOfDiv;
	if(QuestionInfoArray.length!=0){
		res +=addResultQuestionInfoToTemplate(QuestionInfoArray,iduser,panel,page);
		res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuiv",unArray,page);
	
		resultdiv.innerHTML ="";
		resultdiv.innerHTML = res;
	}
	else
			resultdiv.innerHTML = MLJS("txtpasresultat");

	
}


function ShowQuestionSuiv(iduser,critere,sens,panel,page){
	//type: 1 best of,2 questions actives,3mes questions,4 mes reponses
	var thedata="";
	thedata = thedata+ "&critere="+encodeURIComponent(critere);
	thedata = thedata+ "&sens="+encodeURIComponent(sens);
	thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
	if(page!=0)
		thedata =thedata+"&page="+encodeURIComponent(page);
	
	if(panel==1)
		getDataValueJSON("sscripts/best_of.php", thedata, repResultBestOf);
	else if(panel==2)
		getDataValueJSON("sscripts/search_questionactive.php", thedata, repResultQuestion);
	else if(panel==3)
		getDataValueJSON("sscripts/search_mesquestions.php", thedata, repResultQuestion);
	else
		getDataValueJSON("sscripts/search_mesreponses.php", thedata, repResultQuestion);

}
function searchQuestionParCat(idtopic,idlanguage,idlevel,idstatut,iduserpropose,iduser,iduserrepondu,check_createdby,check_repondby,critere,sens){
	thedata="";
	thedata = thedata + "&idtopic=" + encodeURIComponent(idtopic);
	thedata = thedata + "&idlanguage=" + encodeURIComponent(idlanguage);
	thedata = thedata + "&idlevel=" + encodeURIComponent(idlevel);
	thedata = thedata + "&idstatut=" + encodeURIComponent(idstatut);
	thedata = thedata + "&iduserpropose=" +encodeURIComponent(iduserpropose);
	thedata = thedata + "&iduser=" +encodeURIComponent(iduser);
	thedata = thedata + "&iduserrepondu=" +encodeURIComponent(iduserrepondu);
	var createdby=1;
	var repondby=1;
	if (check_createdby)
      	thedata = thedata+ "&createdby="+encodeURIComponent(createdby);
	if (check_repondby)
      	thedata = thedata+ "&repondby="+encodeURIComponent(repondby);
	
	thedata = thedata + "&critere=" + encodeURIComponent(critere);
	thedata = thedata + "&sens=" +encodeURIComponent(sens);
	
	document.getElementById("resultquestionindex").innerHTML = "<br /><br /><img src='images/load.gif' alt='Chargement...'' title='Chargement...'' /><br /><br />";
	document.getElementById("resultquestionindex").style.visibility = "visible";
	getDataValueJSON("sscripts/searchquestion_bycat.php", thedata, repSearchQuestionParCat);
}
function repSearchQuestionParCat(jsonRep){
	var questionarray=json(jsonRep);
	var questioninfo=questionarray.questioninfo;
	var QuestionInfoArray=new Array();
	
	var unArray = new Array();
	var iduser = g1J(questionarray,'iduser');
	var critere = g1J(questionarray,'critere');
	var sens = g1J(questionarray,'sens');
	var idtopic = g1J(questionarray,'idtopic');
	var idlanguage = g1J(questionarray,'idlanguage');
	var idlevel = g1J(questionarray,'idlevel');
	var idstatut = g1J(questionarray,'idstatut');
	var iduserpropose = g1J(questionarray,'iduserpropose');
	var iduserrepondu = g1J(questionarray,'iduserrepondu');
	var createdby = g1J(questionarray,'createdby');
	var repondby = g1J(questionarray,'repondby');
	var panel = g1J(questionarray,'panel');
	
	unArray.push(iduser);
	unArray.push(critere);
	unArray.push(sens);
	unArray.push(idtopic);
	unArray.push(idlevel);
	unArray.push(idlanguage);
	unArray.push(idstatut);
	unArray.push(iduserpropose);
	unArray.push(iduserrepondu);
	unArray.push(createdby);
	unArray.push(repondby);
	
	arraypanelbycat= new Array();
	arraypanelbycat.push({
		idtopic:idtopic,
		idlevel:idlevel,
		idlanguage:idlanguage,
		idstatut:idstatut,
		iduserpropose:iduserpropose,
		iduserrepondu:iduserrepondu,
		createdby:createdby,
		repondby:repondby,
		critere:critere,
		sens:sens
		
	});
	  
	
	
	var nbQuestiontotal = g1J(questionarray,'nbQuestiontotal');
	var nbQuestionbypage = g1J(questionarray,'nbQuestionbypage');
	var page = g1J(questionarray,'page');
	QuestionInfoArray=remplirArrayQuestion(questioninfo);

	var resultdiv = document.getElementById('resultquestionindex');
	var res = "";
	res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuivByCat",unArray,page);
		
	var templateIndexQuetionHautDiv = document.getElementById('templateIndexQuetionHautDiv').innerHTML;
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"nbresultat",nbQuestiontotal);
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebydateasc","javascript:ShowQuestionSuivByCat('"+iduser+"',1,1,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebydatedesc","javascript:ShowQuestionSuivByCat('"+iduser+"',1,0,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebynbrepasc","javascript:ShowQuestionSuivByCat('"+iduser+"',2,1,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebynbrepdesc","javascript:ShowQuestionSuivByCat('"+iduser+"',2,0,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebystatutasc","javascript:ShowQuestionSuivByCat('"+iduser+"',3,1,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebystatutdesc","javascript:ShowQuestionSuivByCat('"+iduser+"',3,0,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebyratingasc","javascript:ShowQuestionSuivByCat('"+iduser+"',4,1,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebyratingdesc","javascript:ShowQuestionSuivByCat('"+iduser+"',4,0,'"+idtopic+"','"+idlanguage+"','"+idlevel+"','"+idstatut+"','"+iduserpropose+"','"+iduserrepondu+"','"+createdby+"','"+repondby+"',"+page+")");
	
	res += templateIndexQuetionHautDiv;
	if(QuestionInfoArray.length!=0){
		res +=addResultQuestionInfoToTemplate(QuestionInfoArray,iduser,panel,page);
		res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuivByCat",unArray,page);
	
		resultdiv.innerHTML ="";
		resultdiv.innerHTML = res;
		
			
	}
	else
			resultdiv.innerHTML = MLJS("txtpasresultat");

		document.getElementById('resultquestionindex').style.display="block";
	
}
function ShowQuestionSuivByCat(iduser,critere,sens,idtopic,idlanguage,idlevel,idstatut,iduserpropose,iduserrepondu,createdby,repondby,page){
	var thedata="";
	thedata = thedata + "&idtopic=" + encodeURIComponent(idtopic);
	thedata = thedata + "&idlanguage=" + encodeURIComponent(idlanguage);
	thedata = thedata + "&idlevel=" + encodeURIComponent(idlevel);
	thedata = thedata + "&idstatut=" +encodeURIComponent(idstatut);
	thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
    thedata = thedata+ "&iduserpropose="+encodeURIComponent(iduserpropose);
    thedata = thedata+ "&iduserrepondu="+encodeURIComponent(iduserrepondu);
	 thedata = thedata+ "&createdby="+encodeURIComponent(createdby);
	 thedata = thedata+ "&repondby="+encodeURIComponent(repondby);
	thedata = thedata+ "&critere="+encodeURIComponent(critere);
	thedata = thedata+ "&sens="+encodeURIComponent(sens);
	
	if(page!=0)
		thedata =thedata+"&page="+encodeURIComponent(page);
	getDataValueJSON("sscripts/searchquestion_bycat.php", thedata, repSearchQuestionParCat);

}
function searchQuestionParMot(searchstring,check_title,check_description,critere,sens,iduser){
	thedata="";
	if (searchstring==null) searchstring="";
	lenghtsearchstring=searchstring.length;
	 var strChar="";
	 var nombredespace=0;
    for (i = 0; i < lenghtsearchstring; i++) {
        strChar = searchstring.charAt(i);
        if (strChar ==' ') 
            nombredespace += 1;
    }
	 
	if(lenghtsearchstring==nombredespace)
 	{
		searchstring="";
	}
		if (check_title)
      		thedata += "&title=" + encodeURIComponent(searchstring); 
    	if (check_description)
      		thedata += "&description=" + encodeURIComponent(searchstring); 
		
	  	thedata = thedata + "&critere=" +encodeURIComponent(critere);
		thedata = thedata + "&sens=" + encodeURIComponent(sens);
		thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
		document.getElementById("resultquestionindex").innerHTML = "<br /><br /><img src='images/load.gif' alt='Chargement...'' title='Chargement...'' /><br /><br />";
		document.getElementById("resultquestionindex").style.visibility = "visible";
	
		getDataValueJSON("sscripts/searchquestion_bymot.php", thedata, repSearchQuestionParMot);

}
function repSearchQuestionParMot(jsonRep){
	var questionarray=json(jsonRep);
	var questioninfo=questionarray.questioninfo;
	var QuestionInfoArray=new Array();
	
	var unArray = new Array();
	var iduser = g1J(questionarray,'iduser');
	var critere = g1J(questionarray,'critere');
	var sens = g1J(questionarray,'sens');
	var title = g1J(questionarray,'title');
	var description = g1J(questionarray,'description');
	var panel = g1J(questionarray,'panel');
	unArray.push(iduser);
	unArray.push(critere);
	unArray.push(sens);
	unArray.push(title);
	unArray.push(description);
	arraypanelbymot= new Array();
	
	arraypanelbymot.push({
		title:title,
		description:description,
		critere:critere,
		sens:sens
	})
	
	var nbQuestiontotal = g1J(questionarray,'nbQuestiontotal');
	var nbQuestionbypage = g1J(questionarray,'nbQuestionbypage');
	var page = g1J(questionarray,'page');
	QuestionInfoArray=remplirArrayQuestion(questioninfo);

	var resultdiv = document.getElementById('resultquestionindex');
	var res = "";
	res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuivByMot",unArray,page);
		
	var templateIndexQuetionHautDiv = document.getElementById('templateIndexQuetionHautDiv').innerHTML;
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"nbresultat",nbQuestiontotal);
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebydateasc","javascript:ShowQuestionSuivByMot('"+iduser+"',1,1,'"+title+"','"+description+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebydatedesc","javascript:ShowQuestionSuivByMot('"+iduser+"',1,0,'"+title+"','"+description+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebynbrepasc","javascript:ShowQuestionSuivByMot('"+iduser+"',2,1,'"+title+"','"+description+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebynbrepdesc","javascript:ShowQuestionSuivByMot('"+iduser+"',2,0,'"+title+"','"+description+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebystatutasc","javascript:ShowQuestionSuivByMot('"+iduser+"',3,1,'"+title+"','"+description+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebystatutdesc","javascript:ShowQuestionSuivByMot('"+iduser+"',3,0,'"+title+"','"+description+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebyratingasc","javascript:ShowQuestionSuivByMot('"+iduser+"',4,1,'"+title+"','"+description+"',"+page+")");
	templateIndexQuetionHautDiv = repS(templateIndexQuetionHautDiv,"triebyratingdesc","javascript:ShowQuestionSuivByMot('"+iduser+"',4,0,'"+title+"','"+description+"',"+page+")");
	
	res += templateIndexQuetionHautDiv;
	if(QuestionInfoArray.length!=0){
		res +=addResultQuestionInfoToTemplate(QuestionInfoArray,iduser,panel,page);
		res +=addlinkUrl(nbQuestiontotal,nbQuestionbypage,4,"ShowQuestionSuivByMot",unArray,page);
	
		resultdiv.innerHTML ="";
		resultdiv.innerHTML = res;
	}
	else
			resultdiv.innerHTML = MLJS("txtpasresultat");

		document.getElementById('resultquestionindex').style.display="block";
}
function ShowQuestionSuivByMot(iduser,critere,sens,title,description,page){
	var thedata="";
	thedata = thedata + "&title=" + encodeURIComponent(title);
	thedata = thedata + "&description=" + encodeURIComponent(description);
	thedata = thedata+ "&critere="+encodeURIComponent(critere);
	thedata = thedata+ "&sens="+encodeURIComponent(sens);
	thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
	if(page!=0)
		thedata =thedata+"&page="+encodeURIComponent(page);
		
	getDataValueJSON("sscripts/searchquestion_bymot.php", thedata, repSearchQuestionParMot);

}
function remplirArrayQuestion(questioninfo){
	var QuestionInfoArray=new Array();
	if(questioninfo!=null){
		for(var i=0;i<questioninfo.length;i++){
			var questionid = g1J(questioninfo[i],"questionid");
			var urlfoto = g1J(questioninfo[i],"urlfoto");
			var nameuser = g1J(questioninfo[i],"nameuser");
			var langid = g1J(questioninfo[i],"langid");
			var topiclabel = g1J(questioninfo[i],"topiclabel");
			var levellabel = g1J(questioninfo[i],"levellabel");
			var titre = g1J(questioninfo[i],"titre");
			var nbreponse = g1J(questioninfo[i],"nbreponse");
			var datedebutdebut = g1J(questioninfo[i],"datedebutdebut");
			var dateexpiredebut = g1J(questioninfo[i],"dateexpiredebut");
			var datedebutfin = g1J(questioninfo[i],"datedebutfin");
			var dateexpirefin = g1J(questioninfo[i],"dateexpirefin");
			
			/*if(dateexpirefin!=""){
				dateexpirefin=MLJS(dateexpirefin)
				dateexpirefin=dateexpirefin.substring(0,1);
			
			}*/
				
			var statutlabel = g1J(questioninfo[i],"statutlabel");
			var statutid = g1J(questioninfo[i],"statutid");
			var tarif = g1J(questioninfo[i],"tarif");
			var userquestion = g1J(questioninfo[i],"userquestion");
			var isthebest = g1J(questioninfo[i],"isthebest");
			var nbvote_plus = g1J(questioninfo[i],"nbvote_plus");
			var nbvote_moins = g1J(questioninfo[i],"nbvote_moins");
			var resvote = g1J(questioninfo[i],"resvote");
			var desc = g1J(questioninfo[i],"desc");
			
			
		QuestionInfoArray.push({
				questionid:questionid,
				urlfoto:urlfoto,
				nameuser:nameuser,
				langid:langid,
				topiclabel:topiclabel,
				levellabel:levellabel,
				titre:titre,
				nbreponse:nbreponse,
				datedebutdebut:datedebutdebut,
				dateexpiredebut:dateexpiredebut,
				datedebutfin:datedebutfin,
				dateexpirefin:dateexpirefin,
				statutlabel:statutlabel,
				statutid:statutid,
				tarif:tarif,
				userquestion:userquestion,
				isthebest:isthebest,
				nbvote_plus:nbvote_plus,
				nbvote_moins:nbvote_moins,
				resvote:resvote,
				desc:desc
			});
		}
	}
	return QuestionInfoArray;
}
function addResultQuestionInfoToTemplate(unArray,iduser,panel,page){
	var res="";
	for(var i=0;i<unArray.length;i++){
		
		addrecoinfo(unArray[i].questionid,MLJS("txtrecommandationquestion")+unArray[i].titre);
		addflaginfo(unArray[i].questionid,MLJS("txtcontestationquestion",unArray[i].titre,unArray[i].nameuser));
		var divtuto = "questionDiv"+unArray[i].questionid;
		var templateResultQuestionDiv = document.getElementById('templateResultQuestionDiv').innerHTML;
		
		templateResultQuestionDiv=repS(templateResultQuestionDiv,"templateResultTutoDiv",divtuto);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlfoto",unArray[i].urlfoto);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"nameuser",unArray[i].nameuser);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"reffiche","ficheuser.php?nickname="+unArray[i].nameuser);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"titre",unArray[i].titre);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"datedebutdebut",unArray[i].datedebutdebut);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"datedebutfin",MLJS(unArray[i].datedebutfin));
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"nbreponse",unArray[i].nbreponse);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"statut",unArray[i].statutlabel);
		
		if(unArray[i].statutid==1)
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"classstatutquestion","statutquestion");
		else
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"classstatutquestion","");
			
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"levellabel",unArray[i].levellabel);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"topiclabel",unArray[i].topiclabel);
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"tarif",unArray[i].tarif);
		
		//alert(unArray[i].dateexpirefin)
		//expiration
		if(unArray[i].dateexpiredebut!=""){
			
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"dateexpiredebut","-"+MLJS('txtexpire',unArray[i].dateexpiredebut));
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"dateexpirefin",MLJS(unArray[i].dateexpirefin));
		}
		else{
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"dateexpiredebut","");
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"dateexpirefin","");
		}
		//question resolu
		if(unArray[i].dateexpire==""&&unArray[i].nbreponse!=0)
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"resolu","-"+MLJS('txtresolue'));
		else
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"resolu","");
		
		//action voir
		if(iduser==unArray[i].userquestion){
			//statut active,close,dépassé
			if(unArray[i].statutid==1||unArray[i].statutid==3||unArray[i].statutid==4)
				templateResultQuestionDiv=repS(templateResultQuestionDiv,"actionvoir","question_details.php?isactive=1&questionid="+unArray[i].questionid);
			else
				templateResultQuestionDiv=repS(templateResultQuestionDiv,"actionvoir","question_details.php?ismodif=1&questionid="+unArray[i].questionid);
		
		}
		else{
				templateResultQuestionDiv=repS(templateResultQuestionDiv,"actionvoir","question_details.php?isactive=1&questionid="+unArray[i].questionid);
		
		}
		
		//drapeau des langues
		var tutolangdrapeau="";
		if (unArray[i].langid==1) 
			questionlangdrapeau= "images/flag_fr.png"; 
		else if (unArray[i].langid==2) 
		 	questionlangdrapeau= "images/flag_en.png";
		else
			 questionlangdrapeau= "images/flag_es.png";
		templateResultQuestionDiv=repS(templateResultQuestionDiv,"imglang",questionlangdrapeau);
		
		//best answer
		//templateResultQuestionDiv=repS(templateResultQuestionDiv,"imgbestanswer","images/blanc2.jpg");

		var bestanswer="";
		
		if (unArray[i].isthebest==1){
			bestanswer= "images/crown.png";
			templateResultQuestionDiv=repS(templateResultQuestionDiv,"imgbestanswer",bestanswer);
		} 
		else{
			bestanswer= "images/blanc2.jpg";
			templateResultQuestionDiv=repS(templateResultQuestionDiv,"imgbestanswer",bestanswer);

		}
		
		//commun
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"srcvoteplus","images/pouce_haut.jpg");
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"srcvotemoins","images/pouce_bas.jpg");
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"vote_plus",unArray[i].nbvote_plus);	
		templateResultQuestionDiv = repS(templateResultQuestionDiv,"vote_moins",unArray[i].nbvote_moins);	
		
		
		if(iduser==-2){
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlrecommander","inscrivezvous.php");
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlpartager","inscrivezvous.php");
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"txtsignaler",MLJS('txtsignaler'));
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlsignaler","inscrivezvous.php");
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"idvote","");	
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"altvote","");	
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlvoirplus","");
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlvoirmoins","");
			
			}
		else{
			//recommandation
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlrecommander","javascript:recothis('"+iduser+"','"+unArray[i].questionid+"','4')");
			//signaler
			if(unArray[i].userquestion==iduser){
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlsignaler","");
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"txtsignaler","");
			}
			else{
				var markerflag="idquestion="+unArray[i].questionid;
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"txtsignaler",MLJS('txtsignaler'));
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlsignaler","javascript:flagthis('"+markerflag+"','"+unArray[i].questionid+"','4')");
				
			}
			//partager
			var lien="";
			lien="fr/question_details.php?isactive=1&questionid="+unArray[i].questionid;
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlpartager","javascript:ShowPopupPartage('"+unArray[i].questionid+"','"+iduser+"','"+lien+"',2)");
	
			//vote
			
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlvoirplus","javascript:VoteQuestion(1,"+panel+",'"+unArray[i].questionid+"',"+iduser+","+page+")");
			templateResultQuestionDiv = repS(templateResultQuestionDiv,"urlvoirmoins","javascript:VoteQuestion(0,"+panel+",'"+unArray[i].questionid+"',"+iduser+","+page+")");
			
			if(unArray[i].resvote==1){//peut voter
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"idvote","votecursorpointer");	
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"altvote",MLJS("txtvoter"));	
			
			}else if(unArray[i].resvote==2){//peut plus voter
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"idvote","");	
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"altvote",MLJS("txtdejanotequestion"));	
			
			}else{//proprio
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"idvote","");	
				templateResultQuestionDiv = repS(templateResultQuestionDiv,"altvote",MLJS("txtproprio"));	
			
			}
		
		}
		res += templateResultQuestionDiv;
	}
	return res;	
}
function VoteQuestion(sensicrement,panel,questionid,iduser,page){
	var thedata="";
	thedata = thedata + "&panel=" + encodeURIComponent(panel);
	thedata = thedata + "&sensincrement=" + encodeURIComponent(sensicrement);
	thedata = thedata + "&questionid=" + encodeURIComponent(questionid);
	thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
	thedata = thedata + "&page=" + encodeURIComponent(page);
	getDataValueJSON("sscripts/vote_question.php", thedata, repVoteQuestion);

}
function repVoteQuestion(jsonRep){
	var array=json(jsonRep);
	var iduser = g1J(array,'iduser');
	var panel = g1J(array,'panel');
	var page = g1J(array,'page');
	var res = g1J(array,'res');
	
	if(res==true){
		showalertpanel(MLJS("txtinfo"), MLJS("txtmercivote"),'',2,1,'');
		if(panel!=5&&panel!=6){
			var thedata="";
			thedata = thedata+ "&critere="+encodeURIComponent(arraypanel[0].critere);
			thedata = thedata+ "&sens="+encodeURIComponent(arraypanel[0].sens);
			thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
			if(page!=0)
				thedata =thedata+"&page="+encodeURIComponent(page);
			
			if(panel==1)
				getDataValueJSON("sscripts/best_of.php", thedata, repResultBestOf);
			else if(panel==2)
				getDataValueJSON("sscripts/search_questionactive.php", thedata, repResultQuestion);
			else if(panel==3)
				getDataValueJSON("sscripts/search_mesquestions.php", thedata, repResultQuestion);
			else
				getDataValueJSON("sscripts/search_mesreponses.php", thedata, repResultQuestion);
		}
		else if(panel==5){
			var thedata="";
			thedata = thedata + "&idtopic=" + encodeURIComponent(arraypanelbycat[0].idtopic);
			thedata = thedata + "&idlanguage=" + encodeURIComponent(arraypanelbycat[0].idlanguage);
			thedata = thedata + "&idlevel=" + encodeURIComponent(arraypanelbycat[0].idlevel);
			thedata = thedata + "&idstatut=" +encodeURIComponent(arraypanelbycat[0].idstatut);
			thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
		    thedata = thedata+ "&iduserpropose="+encodeURIComponent(arraypanelbycat[0].iduserpropose);
		    thedata = thedata+ "&iduserrepondu="+encodeURIComponent(arraypanelbycat[0].iduserrepondu);
			thedata = thedata+ "&createdby="+encodeURIComponent(arraypanelbycat[0].createdby);
			thedata = thedata+ "&repondby="+encodeURIComponent(arraypanelbycat[0].repondby);
			thedata = thedata+ "&critere="+encodeURIComponent(arraypanelbycat[0].critere);
			thedata = thedata+ "&sens="+encodeURIComponent(arraypanelbycat[0].sens);
			
			if(page!=0)
				thedata =thedata+"&page="+encodeURIComponent(page);
			getDataValueJSON("sscripts/searchquestion_bycat.php", thedata, repSearchQuestionParCat);
		}
		else{
				var thedata="";
				thedata = thedata + "&title=" + encodeURIComponent(arraypanelbymot[0].title);
				thedata = thedata + "&description=" + encodeURIComponent(arraypanelbymot[0].description);
				thedata = thedata+ "&critere="+encodeURIComponent(arraypanelbymot[0].critere);
				thedata = thedata+ "&sens="+encodeURIComponent(arraypanelbymot[0].sens);
				thedata = thedata + "&iduser=" + encodeURIComponent(iduser);
				if(page!=0)
					thedata =thedata+"&page="+encodeURIComponent(page);
				getDataValueJSON("sscripts/searchquestion_bymot.php", thedata, repSearchQuestionParMot);
		
			}
	}
}
function getPersonQuestion(iduser,motRechercher, _htmlObj,type){
	 var lien = "";
     var data ="iduser="+encodeURIComponent(iduser)+"&search=" + encodeURIComponent(motRechercher)+"&type=" + encodeURIComponent(type);

    lien = "sscripts/listperson_question.php";
    if (motRechercher.length >= 3) {
        document.getElementById(_htmlObj).style.visibility = "visible";
        document.getElementById(_htmlObj).innerHTML = "searching";
        postDataValue(lien, document.getElementById(_htmlObj),data);
    }
    else {
        document.getElementById(_htmlObj).innerHTML = "";
        document.getElementById(_htmlObj).style.visibility = "hidden";
    }
}
function AddPersonQuestion(id, nickname,type){
	var res="";
	res+=nickname;
	res += "<a href = \"javascript:DelPersonQuestion(" +id+","+type+");\"><img src=\"images/delete.gif\" alt=\"Supprimer ce contact de la liste\" title=\"Supprimer ce contact de la liste\" /></a>";
	 
	if(type==1){
		document.getElementById("displaylisteuserposee").innerHTML=res;
		document.getElementById("userposee").value=id;
		document.getElementById("selectposee").style.visibility = "hidden";
	} 
	else{
		document.getElementById("displaylisteuserrepondu").innerHTML=res;
		document.getElementById("userrepondu").value=id;
		document.getElementById("selectrepondu").style.visibility = "hidden";
	}      

}
function DelPersonQuestion(id,type){
	if(type==1){
		document.getElementById("displaylisteuserposee").innerHTML="";
		document.getElementById("userposee").value="";
	}
	else{
		document.getElementById("displaylisteuserrepondu").innerHTML="";
		document.getElementById("userrepondu").value="";
	}
}
/****************************YVONNNE************************/
