﻿// espace de nom  realisée par lazaar sami pour la gestion des appel asynchrones utilisant la bib yahoo
if (typeof LAZAAR.UTILS.AsynchDBOp == "undefined") {
    /**
     * The LAZAAR.UTILS.AsynchDBOp global namespace object.  If LAZAAR.UTILS.AsynchDBOp is already defined, the
     * existing LAZAAR.UTILS.AsynchDBOp object will not be overwritten so that defined
     * namespaces are preserved.
     * @class AsynchDBOp
     * @static
     */
   LAZAAR.UTILS.AsynchDBOp={};
}


			
//classe static pour la gestion des oeuvres du space name LAZAAR.UTILS.AsynchDBOp
LAZAAR.UTILS.AsynchDBOp.KANVASLogin=
{
		PROXY:function() 
		{ 
			//pour eliminer que ie mettre la page en cache
			var rand=parseInt(777*Math.random(0,1));
			return "../../handlers/handlerLogin.php?Random="+rand;
		}
		,
		OP:LAZAAR.UTILS.NatureOperation.Login
		,
		Sections:
		{
			espace_client		:'client.php',
			rubrique_page		:'rubrique.php',
			accueil				:'accueil.php'
			
		}
		,
		Forms:
		{
			auth				:9,
			reg_fact			:15,
			decl_chiff_aff		:4,
			dec_chiff_aff_sais	:14,
			reg_fact_sais		:16,
			reg_fact_epay		:17
			
		}
		,
		WAITDLG:new YAHOO.widget.Panel("wait",  
			{ width:"65px", 
			  fixedcenter:true, 
			  close:false, 
			  draggable:false, 
			  zindex:4,
			  modal:true,
			  visible:false,
			 constraintoviewport: true 
			} 
		),
		MENU : new YAHOO.widget.Panel('widget_menu', { 
	            visible:false, 
	            width: '420px',
	            zIndex: 9999, 
	            close: false, 
	            fixedcenter: true, 
	            modal: true, 
	            draggable: true, 
	            constraintoviewport: true 
	          
	        })
		,
		
		Init:function()
		{
			this.WAITDLG.setHeader("");
			this.WAITDLG.setBody('<img src="../../images/wait_login.gif" />');
			this.WAITDLG.render(document.body);
			this.MENU.setHeader("Bienvenue dans l'espace client"); 
			//this.MENU.setBody('Veuillez séléctionner une tache<br>'+document.getElementById("mm").innerHTML); 
	   // this.MENU.setFooter('<span id="buttonSpan" class="button-group"></span>'); 
	   		this.MENU.render(document.body);
			
		}
		,
		callback : 
		{
			cache:false ,
			customevents:
			{
				onStart:function(eventType, args)
				{
					LAZAAR.UTILS.AsynchDBOp.KANVASLogin.WAITDLG.show();
				// eventType has a string value of "startEvent". 
          		// args[0].tId is the integer transaction ID. 
	          	// args[1] contains the value of <code>callback.argument</code>, if callback.argument is defined.
				//alert('ghjgjhg');
				}//fin onstart,
				,
				onComplete:function(eventType, args)
				{
					
					LAZAAR.UTILS.AsynchDBOp.KANVASLogin.WAITDLG.hide();
				
					// eventType has a string value of "completeEvent". 
	          // args[0].tId is the integer transaction ID. 
	          // args[1] contains the value of <code>callback.argument</code>, if callback.argument is defined.
				}//fin onComplete
				,
				onSuccess:function(eventType, args)
				{
					/*
					* eventType has a string value of "successEvent".
					* args[0] is the response object, which has the
					* following properties:
					*
					* args[0].tId
					* args[0].status
					* args[0].statusText
					* args[0].getResponseHeader[ ]
					 * args[0].getAllResponseHeaders
					* args[0].responseText
					* args[0].responseXML
					* args[0].argument
					 */
				
					 if((args[0].responseXML !== undefined)&&(args[0].responseXML !== null))
					 {
						
						var REPXML=args[0].responseXML;
						var response=REPXML.documentElement;
						
						//alert();
						//var statue=response.selectSingleNode("@statue").value;
						var statue=response.attributes[0].value;
						
						switch (statue)
						{
						
						case 'CONNECT-NOTOK':
						   // alert("la reponse est:"+args[0].responseText);
						   var error=response.firstChild.firstChild.nodeValue;
							try
							{
								var div_tag=document.getElementById("currentState");
								div_tag.style.display="block";
								var msg_tag=document.getElementById("alert_message");
								msg_tag.innerHTML=error.replace('\\n','<br>');
							}
							catch(erreur1){}
							alert(error.replace('\\n','\n'));
							break;	
						case 'CONNECT-OK':
						    // alert("la reponse est:"+args[0].responseText);
							
							try
							{
								/*						
								var Formdst;
								Formdst = document.getElementById("formdest");
								Formdst.frm.value=KANVASLogin.Forms.reg_fact;
								Formdst.frm_param.value=response.firstChild.firstChild.nodeValue;
								Formdst.action=KANVASLogin.Sections.espace_client;
								Formdst.submit();
								*/
								var htmlmenu=response.firstChild.firstChild.nodeValue;
								LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.setBody('<span class=\'menu_head\'>Veuillez s\u00E9lectionner une t\u00E2che:</span><br>'+htmlmenu); 
								LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.render(document.body); 
								 if (LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.bringToTop)
								 { 
									LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.bringToTop(); 
								 }
								LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.show();
								
							}
							catch(erreur1){}
							
							
							break;
							
							//KANVASLogin.LoadSection(KANVASLogin.Sections.espace_client);
							break;
						case 'CONNECT-2-OK':
						   // alert("la reponse est:"+args[0].responseText);
							
							try
							{
								/*						
								var Formdst;
								Formdst = document.getElementById("formdest");
								Formdst.frm.value=KANVASLogin.Forms.reg_fact;
								Formdst.frm_param.value=response.firstChild.firstChild.nodeValue;
								Formdst.action=KANVASLogin.Sections.espace_client;
								Formdst.submit();
								*/
								var htmlmenu=response.firstChild.firstChild.nodeValue;
								LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.setBody('<span class=\'menu_head\'>Veuillez s\u00E9lectionner une t\u00E2che:</span><br>'+htmlmenu); 
								LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.render(document.body); 
								 if (LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.bringToTop)
								 { 
									LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.bringToTop(); 
								 }
								LAZAAR.UTILS.AsynchDBOp.KANVASLogin.MENU.show();
								
							}
							catch(erreur1){}
							
							
							break;
						case 'CONNECT-2-NOTOK':
						   // alert("la reponse est:"+args[0].responseText);
						   var error=response.firstChild.firstChild.nodeValue;
							try
							{
								
								
								var div_tag=document.getElementById("currentState");
								div_tag.style.display="block";
								var msg_tag=document.getElementById("alert_message");
								msg_tag.innerHTML=error.replace('\\n','<br>');
								
								
								
							}
							catch(erreur2){}
							alert(error.replace('\\n','\n'));
							
							break;	
						
						case 'DECONNECT':
												
							try
							{
								var Formdst;
								Formdst = document.getElementById("formdest");
								Formdst.frm.value=KANVASLogin.Forms.auth;
								Formdst.frm_param.value=-2;
								Formdst.action=KANVASLogin.Sections.accueil;
								Formdst.submit();
							}
							catch(error){}
						
						/*KANVASLogin.LoadSection(KANVASLogin.Sections.espace_client);*/
						break;
						case 'REDIRECT-ACCUEIL':
												
							try
							{
								var Formdst;
								Formdst = document.getElementById("formdest");
								Formdst.frm.value=KANVASLogin.Forms.auth;
								Formdst.frm_param.value=-2;
								Formdst.action=KANVASLogin.Sections.accueil;
								Formdst.submit();
							}
							catch(error){}
						
						/*KANVASLogin.LoadSection(KANVASLogin.Sections.espace_client);*/
						break;
							
						default:
							alert ('Cotunace Clients Management\n\nErreur serveur! ');			
							break;
							
						}
					}
					else
					alert ('Cotunace clients Management \n\nune erreur est survenue,impossible de recevoir une reponse depuis le serveur');
				
				}//fin onSuccess
				,
				
				onFailure:function(eventType, args)
				{
					// eventType has a string value of "failureEvent". 
	          		// args[0] is the response object.
			 		 alert('Cotunace Contents Management System\n\nImpossible de communiquer avec le serveur!');
				}//fin onFailure
				,
				// Define this event handler for file upload transactions *only*. 
        		// This handler will not be used for any other transaction cases. 
	       	 	onUpload:function(eventType, args)
				{ 
          			// eventType has a string value of "uploadEvent". 
	          		// args[0] is the response object. 
        		}//fin onUpload
				, 
				onAbort:function(eventType, args)
				{
					 // eventType has a string value of "abortEvent". 
		 			 // args[0].tId is the integer transaction ID. 
			  		// args[1] contains the value of <code>callback.argument</code>, if callback.argument is defined. 
				}//fin onAbort
		}//fincustomevents
	}//fin callback
	,
	LoadSection:function(oSec)
	{
		window.location=oSec;
	}
	,
	LoadForm:function(oForm,idSess)
	{
		var Formdst;

		try{
		Formdst = document.getElementById("formdest");
		Formdst.frm.value=oForm;;
		Formdst.frm_param.value=idSess;
		
		Formdst.action=KANVASLogin.Sections.espace_client;
		Formdst.submit();
		}
		catch(e)
		{
			alert("impossible de transefer");
		}
	}
	,
	Deconnect:function()//deconnexion du client
	{
		var postData='OP=DECONNECT'; 
		var rand=parseInt(777*Math.random(0,1));//pour eliminer que ie mettre la page en cache
		postData+="&R="+ rand;
		KANVASLogin.MENU.hide();
		/*KANVASLogin.WAITDLG.setHeader("D\u00E9connection en cours, veuillez patientez...");*/
		YAHOO.util.Connect.asyncRequest("post", this.PROXY(), this.callback,postData);
		
	}
	,
	VerifUser:function() //verifier utilisateur
	{
		//alert("cher utilisateur, cette espace est en cours de développement maintenant, bientot sera disponible"); return;
		
		var oForm = document.getElementById("formlogin");
		if (oForm!='undefined')
		{
			
			YAHOO.util.Connect.setForm(oForm,false,true);
			YAHOO.util.Connect.asyncRequest("post", this.PROXY(), this.callback);
		}
		else
		{ 
			alert('Cotunace Contents Management System\n\nErreur interne');
		}
		
		
		return;
	}
	,
	VerifUser2:function() //verdifer  utilisateur
	{
		//alert("1cher utilisateur, cette espace est en cours de développement maintenant, bientot sera disponible"); return;
		
		var oForm = document.getElementById("form_19");
		if (oForm!='undefined')
		{
			YAHOO.util.Connect.setForm(oForm,false,true);
			YAHOO.util.Connect.asyncRequest("post", this.PROXY(), this.callback);
		}
		else
		{ 
			alert('Cotunace Contents Management System\n\nErreur interne');
		}
		return;
	}
	, 
	DecclareChiffreAffaire:function() //declaration chiffre affaire
	{
		
		var Formdst;
		try
		{
			Formdst = document.getElementById("formdest");
			if (Formdst!='undefined')
			{
				Formdst.frm.value=KANVASLogin.Forms.decl_chiff_aff;
				Formdst.action=KANVASLogin.Sections.espace_client;
				Formdst.submit();
			}
			
		}
		catch(error){alert('Formulaire non definie!');}
		
	}
	, 
	ReglerFacture:function() //regler facture
	{
		var Formdst;
		try
		{
			Formdst = document.getElementById("formdest");
			
		}
		catch(error){}
		
		if (Formdst!='undefined')
		{
			Formdst.frm.value=KANVASLogin.Forms.reg_fact;
			Formdst.action=KANVASLogin.Sections.espace_client;
			Formdst.submit();
		}
		else
		{ 
			alert('Formulaire non definie!');
		}
	}
};
var KANVASLogin;
YAHOO.util.Event.onDOMReady(function(p_sType) 
									 {
										LAZAAR.UTILS.XML.ENLEVEBUGS_pour_F_FOX();
										LAZAAR.UTILS.AsynchDBOp.KANVASLogin.Init();
										KANVASLogin=LAZAAR.UTILS.AsynchDBOp.KANVASLogin;
									}
							);	
	

