
function showResultTextauthorize(saisiecomment,tabarray){//pour accepter invitation pour mineur

			var thedata = "";
			thedata=thedata+"&saisiecomment="+encodeURIComponent(saisiecomment);
			thedata=thedata+"&webuserid="+encodeURIComponent(tabarray[0]);
			thedata=thedata+"&lessonid="+encodeURIComponent(tabarray[1]);
			getDataValueJSON("sscripts/verifycodeparental.php", thedata, ResultVerifyCodeParental);	
    }
    
function ResultVerifyCodeParental (jsonRep){
	var codearray=json(jsonRep);
	var permission = g1J(codearray,"permission");
    var lessonid = g1J(codearray,"lessonid");
  
	if(permission==1){
		thedata="lessonid="+encodeURIComponent(lessonid);
	
			postDataValue("sscripts/insparticipant.php", document.getElementById(''), thedata);
 			document.location='active_lessons.php';
			
	}
	else
		 showalertpanel(MLJS("txtattention"),MLJS("txtcodeincorrect"),'',3,1,'')

		
    
}


//pour permettre à un mineur de voir ou non l'onglet parent
function verifyStatus(ismineur,webuserid){
if(ismineur==1){
 
 			var tabarray=new Array();
			tabarray.push(webuserid);
			showprompt(tabarray,showOngletParent,MLJS("txtaccesparent"));
	}
else
	document.location.href="parent.php?iduser="+webuserid; 
  
}

function showOngletParent(saisiecomment,tabarray){
			var thedata = "";
			thedata = thedata + "saisiecode=" + encodeURIComponent(saisiecomment);
			thedata = thedata + "&webuserid=" + encodeURIComponent(tabarray[0]);
			getDataValueJSON("sscripts/showongletparent.php", thedata, getShowOngletParent);
   		
    }
function getShowOngletParent(jsonRep){
	var codearray=json(jsonRep);
	var permission = g1J(codearray,"permission");
	var webuserid = g1J(codearray,"webuserid");
	 
	if(permission=="1")
		document.location.href="parent.php?iduser="+webuserid; 

	else
		showalertpanel(MLJS("txtattention"),MLJS("txtcodeincorrect"),webuserid,3,1,reshowOngletParent)
}
function reshowOngletParent(webuserid){
		verifyStatus(1,webuserid);
    }
	
function verifyStatusForInvite(iduser,webuserid,idcodemessage){
	
		var thedata = "";
  		thedata=thedata+"iduser="+encodeURIComponent(iduser);
		thedata=thedata+"&webuserid="+encodeURIComponent(webuserid);
		thedata=thedata+"&idcodemessage="+encodeURIComponent(idcodemessage);
		 getDataValueJSON("sscripts/verifystatusforinvite.php", thedata, getverifyStatusForInvite);
   		
}
function getverifyStatusForInvite (jsonRep){
	var codearray=json(jsonRep);
 	var idcodemessage="";
    var idcontact ="";
	var permissioninvite ="";
	var webuserid ="";

   	var idcodemessage = g1J(codearray,'idcodemessage');
	var idcontact =  g1J(codearray,'idcontact');
    var permissioninvite = g1J(codearray,'permissioninvite');
	var webuserid =  g1J(codearray,'webuserid');

		if(permissioninvite==0)
			msgattention();
		else if(permissioninvite==1)
				document.location.href='invitation.php?user='+idcontact+'&idcodemessage=2';

		else if(permissioninvite==2){
			msgattention3(idcontact,1);
		}
		
}

 function showResultTextauthorizeinvite(tabarray){
			
			var pass="";
			var pass=document.getElementById("passformulaire").value;
			mywindow.destroy();
			mywindow = null;
			delete formulaire;
			formulaire = null;
			var thedata = "";
			thedata=thedata+"&saisiecomment="+encodeURIComponent(pass);
			thedata=thedata+"&webuserid="+encodeURIComponent(tabarray[0]);
			thedata=thedata+"&idcontact="+encodeURIComponent(tabarray[1]);
			thedata=thedata+"&idcodemessage="+encodeURIComponent(tabarray[2]);
			getDataValueJSON("sscripts/verifycodeparental.php", thedata, ResultVerifyCodeParentalinvite);	
    }

function ResultVerifyCodeParentalinvite (jsonRep){
	var codearray=json(jsonRep);
	var permission = g1J(codearray,'permission');
	var idcontact = g1J(codearray,'idcontact');
	
	if(permission==1){
		 document.location.href='invitation.php?user='+idcontact+'&idcodemessage=0';
	
			
	}
	else
		 showalertpanel(MLJS("txtattention"),MLJS("txtcodeincorrect"),'',3,1,'');

}

function connectToChild(idmineur,type,activation){
	
	var thedata="";
	thedata=thedata+"idmineur="+encodeURIComponent(idmineur);
	thedata=thedata+"&type="+encodeURIComponent(type);
	if(activation==0){
		
		showalertpanel(MLJS("txtattention"),MLJS("txtnotconnectchild"),'',3,1,'');
	}
	else
	getDataValueJSON("sscripts/idparent.php", thedata,Connexion);
}

function Connexion(jsonRep){
	var codearray=json(jsonRep);
	var type = g1J(codearray,"type");
	if(type==1)
	document.location.href='index.php';
    else if(type==2)
	document.location.href='past_lessons.php?type=revoir';
    else if(type==3)
	document.location.href='contacts.php';
    else if(type==4)
	document.location.href='finance.php';
}

function addContact(iduser,webuserid,mustberefresh){
    var thedata = "";
    thedata =thedata+ "idcontact=" + encodeURIComponent(iduser);
	 thedata =thedata+ "&webuserid=" +encodeURIComponent(webuserid);
	 thedata =thedata+ "&mustberefresh=" +encodeURIComponent(mustberefresh);
	
	 var dataSource = "sscripts/inscontact.php";
    getDataValueJSON(dataSource, thedata, VerifeAjoutContact);
}


function VerifeAjoutContact (jsonRep){
	var codearray=json(jsonRep);
   
	var permission = g1J(codearray,"permission");
	var webuserid = g1J(codearray,"webuserid");
	var idcontact = g1J(codearray,"idcontact");
	var mustberefresh = g1J(codearray,"mustberefresh");

	if(permission==0){
		msgattention();
	}		

	if(permission==1){
			showalertpanel(MLJS("txtinfo"),MLJS("txtcontactajoutliste"),mustberefresh,2,1,RefreshAddContact);
	}
	if(permission==2){
		tabarray=new Array();
			tabarray.push(webuserid);
			tabarray.push(idcontact);
			tabarray.push(mustberefresh);
			showprompt(tabarray,showResultTextauthorizeaddcontact,MLJS("txtsaisircode"));
	}
    
}
function RefreshAddContact(mustberefresh){
	if(mustberefresh==1)
		document.location.href=document.location.href;
}
function getAddContact(btn){
	if(btn=='ok')
		document.location.href=document.location.href;
	
}
 function showResultTextauthorizeaddcontact(saisiecomment,tabarray){
			var thedata = "";
			thedata=thedata+"&saisiecomment="+encodeURIComponent(saisiecomment);
			thedata=thedata+"&webuserid="+encodeURIComponent(tabarray[0]);
			thedata=thedata+"&idcontact="+encodeURIComponent(tabarray[1]);
			thedata=thedata+"&mustberefresh="+encodeURIComponent(tabarray[2]);
			thedata=thedata+"&addcontact=1";
			getDataValueJSON("sscripts/verifycodeparental.php", thedata, ResultVerifyCodeParentaladdcontact);	

    }

function ResultVerifyCodeParentaladdcontact (jsonRep){
	var codearray=json(jsonRep);
	var permission = g1J(codearray,'permission');
	var mustberefresh = g1J(codearray,'mustberefresh');
	
	if(permission==1)
		showalertpanel(MLJS("txtinfo"),MLJS("txtcontactajoutliste"),mustberefresh,2,1,RefreshAddContact);
	else
		showalertpanel(MLJS("txtattention"),MLJS("txtcodeincorrect"),'',3,1,'');

}

function delContact(iduser,webuserid){
	tabarray=new Array();
	tabarray.push(iduser);
    tabarray.push(webuserid);
	showalertpanel(MLJS("txtconfirmation"),MLJS("txtsursuppcontact"),tabarray,3,2,confirmDeletecontact);
}
function confirmDeletecontact(tabarray){
	var data = "idcontact=" + encodeURIComponent(tabarray[0]) + "&webuserid=" +encodeURIComponent(tabarray[1]);
    postDataValueAndRefresh("sscripts/delcontact.php", "", data);

 }
 
 
function showResultTextauthorizeaddcontact2(saisiecomment,tabarray){

			var thedata = "";
			thedata=thedata+"&saisiecomment="+encodeURIComponent(saisiecomment);
			thedata=thedata+"&userid="+encodeURIComponent(tabarray[0]);
			thedata=thedata+"&motRechercher="+encodeURIComponent(tabarray[1]);
			thedata=thedata+"&typeUser="+encodeURIComponent(tabarray[2]);
			thedata=thedata+"&page="+encodeURIComponent(tabarray[3]);
			thedata=thedata+"&webuserid="+encodeURIComponent(tabarray[4]);
			getDataValueJSON("sscripts/verifycodeparental2.php", thedata, ResultVerifyCodeParentaladdcontact2);	

    }

function ResultVerifyCodeParentaladdcontact2(jsonRep){
			var codearray=json(jsonRep);
			var userid = g1J(codearray,"userid");
			 var permission = g1J(codearray,"permission");
			var motRechercher = g1J(codearray,"motRechercher");
			var typeUser = g1J(codearray,"typeUser");
			var page = g1J(codearray,"page");

	if(permission==1){
		 var data = "userid=" + encodeURIComponent(userid) +"&addContact=1&motRechercher="+ encodeURIComponent(motRechercher) +"&typeUser=" + encodeURIComponent(typeUser)+"&page="+encodeURIComponent(page);
		getDataValueJSON("sscripts/rechercheruser.php",data,repAddContactFromSearchUser);	
	}
	else
		showalertpanel(MLJS("txtattention"),MLJS("txtcodeincorrect"),'',3,1,'');
		
    
}

function repAddContactFromSearchUser(jsonRep){
	var codearray=json(jsonRep);
	var page = 0;
	var motRechercher = 0;
	var typeUser=3;
	
	page = g1J(codearray,"page");
	motRechercher = g1J(codearray,"motrechercher");
	if(motRechercher==null){
		motRechercher=0;
	}
	typeUser = g1J(codearray,"typeuser");
	
	searchUser(motRechercher,typeUser,page);	
}
function ShowChampPaypalAdress(){
		if(document.getElementById("optionpaypal1")!=null){
			if(document.getElementById("optionpaypal1").checked==true)
				document.getElementById("champmailpaypal").style.display = "block";
			else
				document.getElementById("champmailpaypal").style.display = "none";
		}
	}
function ShowChampTeacheroInfo(){
		if(document.getElementById("optionpaypal2")!=null){
			if(document.getElementById("optionpaypal2").checked==true)
				document.getElementById("champteachero").style.display = "block";
			else
				document.getElementById("champteachero").style.display = "none";
		}
	}
function GenerateCoupon(webuserid,ip,montant){
	var thedata="";
	thedata+="webuserid="+webuserid+"&ip="+ip+"&montant="+montant;
	getDataValueJSON("sscripts/generate_coupon.php", thedata, getGenerateCoupon);
}
function getGenerateCoupon(jsonRep){
	var array=json(jsonRep);
	var res = g1J(array,'res');
	var numerocoupon  = g1J(array,'numerocoupon ');
	var webuserid = g1J(array,'webuserid');
	if(res!=1){
		if(res==5){
			showalertpanel(MLJS("txtattention"),MLJS("txtpbapi"),'',3,1,'');
		}
		else if (res==4)
			showalertpanel(MLJS("txtattention"),MLJS("txtmaxatteint"),'',3,1,'');
		else
			showalertpanel(MLJS("txtattention"),MLJS("txtdejacoupon"),'',3,1,'');
	}
	else{
		 var resultdiv = document.getElementById('resultcoupon');
	 	 var res = "";
		if(webuserid==-2){
			var templateResultCoupon= document.getElementById('coupongenerenonlogge').innerHTML;
			templateResultCoupon=repS(templateResultCoupon,"coupongenerenonlogge","coupon");
		}
		else{
			var templateResultCoupon= document.getElementById('coupongenerelogge').innerHTML;
			templateResultCoupon=repS(templateResultCoupon,"coupongenerelogge","coupon");
		}
		templateResultCoupon = repS(templateResultCoupon,"numerocoupon",numerocoupon);
		resultdiv.innerHTML ="";
		resultdiv.innerHTML = templateResultCoupon;
		
	}
}
