
function loadAlertPanel(){
	
	getDataValueJSON("sscripts/alertspanel.php","",repLoadAlertPanel);

}
function addPartAlert(id,alertType,alertTitle,israting){
	
	var templatePartAlertDiv = document.getElementById('templatePartAlertDiv').innerHTML;
	var templatePartAlertCopieDiv = "templatePartAlertCopieDiv";
	templatePartAlertDiv = repS(templatePartAlertDiv,"templatePartAlertDiv",templatePartAlertCopieDiv);	
	// si alert rating	
	if(israting == 1){
		templatePartAlertDiv = repS(templatePartAlertDiv,"PartAlertUrl","javascript:ratingthis('"+id+"','"+alertType+"');");		
	}
	// si non alert finance prof
	else if(israting == 2){
		templatePartAlertDiv = repS(templatePartAlertDiv,"PartAlertUrl","finance.php?type=credit");				
	}
	// si non alert finance eleve
	else if(israting == 3){
		
		templatePartAlertDiv = repS(templatePartAlertDiv,"PartAlertUrl","finance.php?type=debit");				
		
	}
	
	else if(israting == 4){
		
		templatePartAlertDiv = repS(templatePartAlertDiv,"pid",alertType);	
		templatePartAlertDiv = repS(templatePartAlertDiv,"tooltip",alertTitle);							
		
	}
		
	//templatePartAlertDiv = repS(templatePartAlertDiv,"PartAlertName",alertTitle);					
	
	
	return templatePartAlertDiv;
}
function addAlertPanel(res){
	
	var templateAlertPanelDiv = document.getElementById('templateAlertPanelDiv').innerHTML;
	templateAlertPanelDiv = repS(templateAlertPanelDiv,"templateAlertPanelDiv","templateAlertPanelCopieDiv");
	templateAlertPanelDiv = repS(templateAlertPanelDiv,"ContainAlertDiv",res);	
	
	return templateAlertPanelDiv;
}

function repLoadAlertPanel(jsonRep){
	if(document.getElementById("lastusersdiv")!=null){
		jsonRep = json(jsonRep);
		var show = g1J(jsonRep,'show');
		
		//var fixme = document.getElementById('fixme');
		var lastusersdiv = document.getElementById('lastusersdiv');
		
		var i = 0 ;
		var res = "";
		var resPanel = "";
		//if(alertpanel.length !=0){
			
		var lessonToBeRated = g1J(jsonRep,'lessonToBeRated'); 
		
		var tutoToBeRated = g1J(jsonRep,'tutoToBeRated'); 
		var financeProf = g1J(jsonRep,'financeProf'); 
		var financeEleve = g1J(jsonRep,'financeEleve'); 
		var paymentToBeRated = g1J(jsonRep,'paymentToBeRated'); 
		var coursimminent = g1J(jsonRep,'coursimminent'); 
	    
		var strLessonRate = document.getElementById('templateStringLessonRatingDiv').innerHTML;
		var strTutoRate = document.getElementById('templateStringTutoRatingDiv').innerHTML;
		var strPaymentRate = document.getElementById('templateStringPaymentRatingDiv').innerHTML;						
		var strFinanceProf = document.getElementById('templateStringFinanceProfDiv').innerHTML;
		var strFinanceEleve = document.getElementById('templateStringFinanceEleveDiv').innerHTML;						
		//var strCoursImminent = document.getElementById('templateStringCoursImminentDiv').innerHTML;						
	
		if(lessonToBeRated){
			
			for(i = 0;i<lessonToBeRated.length;i++){
				if(i==0)
					res +=strLessonRate;
				var lessonid = g1J(lessonToBeRated[i],"lessonid");
				var lessontitle = g1J(lessonToBeRated[i],"lessontitle");
				addratinginfo(lessonid,lessontitle,"lesson");
				res += addPartAlert(lessonid,"lesson",lessontitle,1);
	
			}
		}
		if(tutoToBeRated){
			for(i = 0;i<tutoToBeRated.length;i++){
				if(i==0)
					res +=strTutoRate;
				var tutoid = g1J(tutoToBeRated[i],"tutoid");
				var tutotitle = g1J(tutoToBeRated[i],"tutotitle");
				addratinginfo(tutoid,tutotitle,"tuto");
				res += addPartAlert(tutoid,"tuto",tutotitle,1);
	
			}		
		}
		if(paymentToBeRated){		
			for(i = 0;i<paymentToBeRated.length;i++){
				if(i==0)
					res +=strPaymentRate;	
				var paymentid = g1J(paymentToBeRated[i],"paymentid");
				var financeRatingTitle = g1J(paymentToBeRated[i],"financeRatingTitle");
				addratinginfo(paymentid,financeRatingTitle,"payment");		
				res += addPartAlert(paymentid,"payment",financeRatingTitle,1);
	
			}
		}
		if(financeProf){
			for(i = 0;i<financeProf.length;i++){
				if(i==0)
					res +=strFinanceProf;			
				var financeProfTitle = g1J(financeProf[i],"financeProfTitle");
				res += addPartAlert(0,"",financeProfTitle,2);
	
			}		
		}		
		
		if(financeEleve){		
			for(i = 0;i<financeEleve.length;i++){
				if(i==0)
					res +=strFinanceEleve;			
				var financeELeveTitle = g1J(financeEleve[i],"financeELeveTitle");
				res += addPartAlert(0,"",financeELeveTitle,3);
	
			}
		}
		
		if(coursimminent){
			for(i = 0;i<coursimminent.length;i++){
				//if(i==0)
					//res +=strCoursImminent;

				var coursimminentTitle = g1J(coursimminent[i],"coursimminentTitle");
				var pid = g1J(coursimminent[i],"pid");
				res += addPartAlert(0,pid,coursimminentTitle,4);
	
			}
			if(coursimminent.length!=0)
				document.getElementById('lastusersdiv').style.border='solid 1px #CCCCCC';
			
		}
		if(res!="")
			resPanel = addAlertPanel(res);					
		//}
		lastusersdiv.innerHTML = resPanel;
		/*fixme.innerHTML = resPanel;
		if(fixme.innerHTML!=""){
			if(show==0){
			document.getElementById("fixmemiddle").style.display="none";
			document.getElementById("fixmebas").style.display="none";
			HideFixme();
			}
			else{
				ShowFixme();
			}
		}*/
	}
}
function ShowFixme(){
	YUI({timeout: 10000}).use("node", "anim", function(Y) {
    var module = Y.get('#fixme');
	var content = module.query('.fixmemiddle').plug(Y.plugin.NodeFX, {
        from: { height: 0},
        to: {
            height: function(node) {
                return node.get('scrollHeight');
            }
        },
        easing: Y.Easing.easeOut,
        duration: 0.5
    });
	var onClick = function(e) {
		module.toggleClass('bouton_ouvrir');
    	content.fx.set('reverse', !content.fx.get('reverse'));
    	content.fx.run();
	};
	var control = Y.Node.create(
	    '<a title="'+MLJS('txtshowhide')+'" class="bouton_fermer">' +
	        '<em>'+MLJS('txtshowhide')+'</em>' +
	    '</a>'
	);
	module.query('.fixmehaut').appendChild(control);
	control.on('click', onClick);

});
}

function HideFixme(){
	YUI({timeout: 10000}).use("node", "anim", function(Y) {
    var module = Y.get('#fixme');
	var content = module.query('.fixmemiddle').plug(Y.plugin.NodeFX, {
        to: { height: 0},
        from: {
            height: function(node) {
                return node.get('scrollHeight');
            }
        },
        easing: Y.Easing.easeOut,
        duration: 0.5
    });
	var onClick = function(e) {
		document.getElementById("fixmemiddle").style.display="block";
		document.getElementById("fixmebas").style.display="block";
		module.toggleClass('bouton_fermer');
    	content.fx.set('reverse', !content.fx.get('reverse'));
    	content.fx.run();
	};
	var control = Y.Node.create(
	    '<a title="'+MLJS('txtshowhide')+'" class="bouton_ouvrir">' +
	        '<em>'+MLJS('txtshowhide')+'</em>' +
	    '</a>'
	);
	module.query('.fixmehaut').appendChild(control);
	control.on('click', onClick);

});
}


function showalertpanel(titre,contenu,data,icone,nbbouton,fnretour) {
	var alertPanel="";
	
	var handleYes = function() {
		this.destroy();
		if(fnretour!='')
			fnretour(data);
	};
	var handleNo = function() {
		this.destroy();
	};
	if(nbbouton==2){
		var bouton=[ { text:MLJS('txtyes'), handler:handleYes},
				  { text:MLJS('txtno'),  handler:handleNo } ];
	}
	else{
		var bouton=[ { text:"ok", handler:handleYes}];
	}
	// Instantiate the Dialog
	alertPanel = new YAHOO.widget.Dialog(
	"alertPanel", 
	 {
	 	width:"300px",
	   effect:{effect:YAHOO.widget.ContainerEffect.FADE, 
	         duration:0.1},  
	   fixedcenter: true,
	   visible: true,
	   draggable: true,
	   close: true,
	   zindex:150000,
	   constraintoviewport: true,
	   modal:true,
	   buttons:bouton
	 
	 } );
	 //1 ICON_HELP
	if(icone==1)
		alertPanel.setHeader("<div class='tl'><img src=\"images/fond_ccm.jpg\"/></div>"+titre+"<div class='tr'></div>");
	//2 ICON_INFO
	else if(icone==2)
		alertPanel.setHeader("<div class='tl'><img src=\"images/fond_info.jpg\"/></div>"+titre+"<div class='tr'></div>");
	//3 ICON_WARN
	else if(icone==3)
		alertPanel.setHeader("<div class='tl'><img src=\"images/fond_attention.jpg\"/></div>"+titre+"<div class='tr'></div>");
	
	alertPanel.setBody(contenu);
	
	// permet de montrer la boite de dialogue
	alertPanel.render("containerdiv");
}

function showalertpanelhome(titre,contenu,data,icone,nbbouton,fnretour) {
	var alertPanel="";
	
	var handleYes = function() {
		this.destroy();
		if(fnretour!='')
			fnretour(data);
	};
	var handleNo = function() {
		this.destroy();
	};
	if(nbbouton==2){
		var bouton=[ { text:MLJS('txtyes'), handler:handleYes},
				  { text:MLJS('txtno'),  handler:handleNo } ];
	}
	else{
		var bouton=[ { text:"ok", handler:handleYes}];
	}
	// Instantiate the Dialog
	alertPanel = new YAHOO.widget.Dialog(
	"alertPanelhome", 
	 {
	 	width:"300px",
	   effect:{effect:YAHOO.widget.ContainerEffect.FADE, 
	         duration:0.1},  
	   fixedcenter: true,
	   visible: true,
	   draggable: true,
	   close: true,
	   zindex:150000,
	   constraintoviewport: true,
	   modal:true,
	   buttons:bouton
	 
	 } );
	 //1 ICON_HELP
	if(icone==1)
		alertPanel.setHeader("<div class='tl'><img src=\"images/fond_ccm.jpg\"/></div>"+titre+"<div class='tr'></div>");
	//2 ICON_INFO
	else if(icone==2)
		alertPanel.setHeader("<div class='tl'><img src=\"images/fond_info.jpg\"/></div>"+titre+"<div class='tr'></div>");
	//3 ICON_WARN
	else if(icone==3)
		alertPanel.setHeader("<div class='tl'><img src=\"images/fond_attention.jpg\"/></div>"+titre+"<div class='tr'></div>");
	
	alertPanel.setBody(contenu);
	
	// permet de montrer la boite de dialogue
	alertPanel.render("containerdiv");
}

function showpromtpanel(type,titre,contenu,data,icone,fnretour){
	
	var promptPanel="";
	var handleYes = function() {
		saisiecomment=document.getElementById('inputprompt').value;
		this.destroy();
		fnretour(saisiecomment,data);
		
	};
	var handleCancel = function() {
		this.destroy();
	};
	// Instantiate the Dialog
	promptPanel = new YAHOO.widget.Dialog(
	"promptPanel", 
	 {
	   width:"350px",
	   effect:{effect:YAHOO.widget.ContainerEffect.FADE, 
	         duration:0.1},  
	   fixedcenter: true,
	   visible: true,
	   draggable: true,
	   close: true,
	   constraintoviewport: true,
	   modal:true,
	   buttons: [ { text:MLJS('txtyes'),handler:handleYes},
				  { text:MLJS('btannuler'),  handler:handleCancel } ]
	 } );
	 //proposer arrangement
	 if(icone==1)
		promptPanel.setHeader("<div class='tl'><img src=\"images/fond_reco.jpg\"/></div>"+titre+"<div class='tr'></div>");
	//2 mot de passe
	else if (icone==2)
		promptPanel.setHeader("<div class='tl'><img src=\"images/fond_pass.jpg\"/></div>"+titre+"<div class='tr'></div>");
	else
		promptPanel.setHeader("<div class='tl'><img src=\"images/fond_reco.jpg\"/></div>"+titre+"<div class='tr'></div>");


	if(type==1)//normal
		promptPanel.setBody("<div class='titrepromt'>"+contenu+"</div><input type=\"text\" id=\"inputprompt\"/><br />");
	else //mot de passe
		promptPanel.setBody("<div class='titrepromt'>"+contenu+"</div><input type=\"password\" id=\"inputprompt\"/><br />");
	
	// permet de montrer la boite de dialogue
	promptPanel.render("containerdiv");
}
function Alert(saisiecomment){
	alert(saisiecomment);
}
function TestAlert(){
	showpromtpanel(MLJS('txtrecommandertuto'),MLJS('txtpartagertuto'),"",2,Alert);
//showalertpanel(MLJS('txtrecommandertuto'),MLJS('txtpartagertuto'),2,2,Alert);
	//rating(1,'lesson');
	//showalertpanel(MLJS('txterreur'),MLJS('txtpartagertuto'),2,Alert);
	//showrecopanel(MLJS('txterreur'),MLJS('txtpartagertuto'),2,Alert);
	//testsimple();
	showalertpanel(MLJS("txtattention"),MLJS("txtcodeincorrect"),webuserid,3,1,reshowOngletParent)

}
function testsimple(){
	YAHOO.namespace("example.container");
	// Define various event handlers for Dialog
	var handleYes = function() {
		alert("You clicked yes!");
		this.hide();
	};
	var handleNo = function() {
		this.hide();
	};

	// Instantiate the Dialog
	YAHOO.example.container.simpledialog1 = new YAHOO.widget.Dialog("alertPanel", 
	 { width:"300px",
	   
	   fixedcenter: true,
	   visible: true,
	   draggable: true,
	   close: true,
	   zindex:150000,
	   constraintoviewport: true,
	   modal:true,
	   buttons: [ { text:"Yes", handler:handleYes, isDefault:true },
				  { text:"No",  handler:handleNo } ]
	 } );
	YAHOO.example.container.simpledialog1.setHeader("Are you sure?");
	
	// Render the Dialog
	YAHOO.example.container.simpledialog1.render("containerdiv");
}
function ShowPopupPartage(idpartage,iduser,lien,type){

	if(type==1){
		var txtreco=MLJS("txtjerecotuto");
		var titre=MLJS("txtrecommandationtuto");
	}
	else{
		var txtreco=MLJS("txtjerecoquestion");
		var titre=MLJS("txtrecommandationquestion");
	}
		
		
	var handleCancel = function() {
		this.destroy();
	};
	// Instantiate the Dialog
	partagePanel = new YAHOO.widget.Dialog(
	"partagePanel", 
	 {
	   width:"500px",
	   effect:{effect:YAHOO.widget.ContainerEffect.FADE, 
	         duration:0.1},  
	   fixedcenter: true,
	   visible: true,
	   draggable: true,
	   close: true,
	   constraintoviewport: true,
	   modal:true,
	   buttons: [ { text:MLJS("btenvoyer"),handler:function (){getPopupPartage(idpartage,iduser,lien,type);}},
				  { text:MLJS('btannuler'),  handler:handleCancel } ]
	 } );
	 
		partagePanel.setHeader("<div class='tl'><img src=\"images/fond_reco.jpg\"/></div>"+titre+"<div class='tr'></div>");


		partagePanel.setBody(
		'<table>'+
			'<tr>'+
				'<td class=\"textalert\">E-mail:</td>'+
				'<td align=left><input type=\"text\" id=\"email\" size=40/></td>'+
			'</tr>'+
			'<tr>'+
				'<td class=\"textalert\">'+MLJS("txtcommentaire")+':</td>'+
				'<td>'+
					'<textarea class=\"textareapanel\" id=\"commentaire\">'+txtreco+'</textarea>'+
				'</td>'+
			'</tr>'+
		'</table>');
	// permet de montrer la boite de dialogue
	partagePanel.render("containerdiv");
}

function getPopupPartage(idpartage,iduser,lien,type){
	
	if (partagePanel.validate()) {
		var commentaire = document.getElementById("commentaire").value;
		var email=document.getElementById("email").value;
		//var maReg = new RegExp ("^([a-zA-Z0-9]+(([\.\-\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[\.\-\_])+[a-zA-Z]{2,4})$");
		//if ( (email).search( maReg ) == -1 )
		var rep=isValidEmail(email);
		if(rep==false)
			email=false;
		var thedata = "";
		thedata=thedata+"&commentaire="+encodeURIComponent(commentaire);
		thedata=thedata+"&email="+encodeURIComponent(email);
		thedata=thedata+"&idpartage="+encodeURIComponent(idpartage);
		thedata=thedata+"&iduser="+encodeURIComponent(iduser);
		thedata=thedata+"&lien="+encodeURIComponent(lien);
		thedata=thedata+"&type="+encodeURIComponent(type);
		if( isValidEmail(email) )
		getDataValueJSON("sscripts/getpartage.php", thedata,ResultPopupPatage);
	}
}
function ResultPopupPatage(jsonRep){

	 var infoerr=json(jsonRep);
	 var err = g1J(infoerr,'err');
	if(err!='null')
		   		showalertpanel(MLJS("txtattention"),MLJS("txtsaisirmailvalide"),'',3,1,'');
   
	else{
			partagePanel.destroy();
		   showalertpanel(MLJS("txtattention"),MLJS("txtdemandeenvoyee"),'',2,1,'');
		}
}
function showPopupEclass(){
getDataValueJSON("sscripts/popupeclass.php","",getshowPopupEclass);
}
function getshowPopupEclass(jsonRep){
	
	
	jsonRep = json(jsonRep);
		var priceArray = g1J(jsonRep,'priceArray');
		var matiereArray = g1J(jsonRep,'matiereArray');
		var niveauArray = g1J(jsonRep,'niveauArray');
	
	// Instantiate the Dialog
	eclassPanel = new YAHOO.widget.Dialog(
	"eclassPanel", 
	 {
	   width:"220px",
	   effect:{effect:YAHOO.widget.ContainerEffect.FADE, 
	         duration:0.1},  
	   fixedcenter: true,
	   visible: true,
	   draggable: true,
	   close: true,
	   constraintoviewport: true,
	   modal:true,
	   buttons: [ { text:MLJS("btdemarrer"),handler:function (){getPopupEclass();}}]
	 } );
	 
		eclassPanel.setHeader("<div class='tl'><img src=\"images/fond_cours.jpg\"/></div>Eclass<div class='tr'></div>");

	
	var bodyeclass='<table>'+
			'<tr>'+
				'<td align=\"left\" class=\"txtlibelle\">'+MLJS('txttarif')+':</td>'+
				'<td align=\"left\"><input size=\"1\" type=\"text\" name=\"horlyrate\" id=\"horlyrate\" value=\"0\" maxlength=\"7\"/>'+
					'<select id=\"idcurrency\" name=\"idcurrency\" style=\"width : 60px;font-size:14px;\">';
					for(var i=0;i<priceArray.length;i++){
						bodyeclass+='<option value=\"'+g1J(priceArray[i],'id')+'\">'+g1J(priceArray[i],"label")+'</option>';
					}
					bodyeclass+='</select>'+
				'</td>'+
			'</tr>'+
			'<tr>'+
				'<td align=\"left\" class=\"txtlibelle\">'+MLJS('txtmatiere')+':</td>'+
				'<td align=\"left\">'+
					'<select id=\"topic\" name=\"topic\" style=\"width : 130px;font-size:12px;\">';
					for(var i=0;i<matiereArray.length;i++){
						bodyeclass+='<option value=\"'+g1J(matiereArray[i],'id')+'\">'+g1J(matiereArray[i],"label")+'</option>';
					}
					bodyeclass+='</select>'+
				'</td>'+
			'</tr>'+
			'<tr>'+
				'<td align=\"left\" class=\"txtlibelle\">'+MLJS('txtniveau')+':</td>'+
				'<td align=\"left\">'+
					'<select id=\"level\" name=\"level\" style=\"width : 130px;font-size:12px;\">';
					for(var i=0;i<niveauArray.length;i++){
						bodyeclass+='<option value=\"'+g1J(niveauArray[i],'id')+'\">'+g1J(niveauArray[i],"label")+'</option>';
					}
					bodyeclass+='</select>'+
				'</td>'+
			'</tr>'+
		"</table>";
		eclassPanel.setBody(bodyeclass);
	
	eclassPanel.render("containerdiv");
}
function getPopupEclass(){
if (eclassPanel.validate()) {
	var idtopic= document.getElementById("topic").value;
	var idlevel= document.getElementById("level").value;
	var horlyrate= document.getElementById("horlyrate").value;
	var idcurrency= document.getElementById("idcurrency").value;
	var thedata = "";
	thedata=thedata+"&idtopic="+idtopic;
	thedata=thedata+"&idlevel="+idlevel;
	thedata=thedata+"&horlyrate="+horlyrate;
	thedata=thedata+"&idcurrency="+idcurrency;
	if(checkHourlyRate(document.getElementById('horlyrate')))
	{
	//alert(thedata);
	window.open('directToEclass.php?idtopic='+idtopic+'&idlevel='+idlevel+'&horlyrate='+horlyrate+'&idcurrency='+idcurrency,'','left=0,top=0');
	eclassPanel.destroy();
	}
	
	}
}
