/**
 * Cette classe javascript gère les processus des pages
 * utilisateurs, comme le login, l'inscription, l'édition
 * du profile, etc...
**/

var ProcessLogin = {
	
    formSubmit : function(form) {
        
        getById('img_process_login').style.visibility = 'visible' ;
        getById('process_message_login').style.visibility = 'hidden' ;
        getById('process_error_login').style.visibility = 'hidden' ;

        getById('img_process_login').style.display = 'block' ;
        getById('process_message_login').style.display = 'none' ;
        getById('process_error_login').style.display = 'none' ;
                
        getById('submit').style.visibility = 'hidden' ;
        getById('submit').style.display = 'none' ;
        
        vAjax.form_submit(form, ProcessLogin.refresh) ;
        
        return false ;
    },
	
	refresh : function()	{
		
        if (vAjax.xhReq.readyState == 4 && vAjax.xhReq.status == 200)	{
		
            // gestion du retour xml différent pour Explorer ou FF
			if (window.ActiveXObject)	{
				//vLogs.addLine(vAjax.xhReq.responseText) ;

				xmldoc = new ActiveXObject("Microsoft.XMLDOM");
				textXML = vAjax.xhReq.responseText;
				xmldoc.async="false";
				if (!xmldoc.loadXML(textXML) )	{
					alert("Une erreur inconnue s'est produite durant le processus.") ;
				}
			} else	{
				//vLogs.addLine(vAjax.xhReq.responseText) ;
				xmldoc = vAjax.xhReq.responseXML ;
			}
			
			response = xmldoc.getElementsByTagName('response').item(0) ;
			response = response.firstChild.data ;
            
			// on test tout d'abord s'il faut faire une redirection
			redirect = xmldoc.getElementsByTagName('redirect').item(0) ;
			if (redirect && redirect.firstChild && redirect.firstChild.data)	{
                location.href = redirect.firstChild.data ;
                return ;
			}
			
			/*
			if (response == 'true')	{
			}
			*/

			message = xmldoc.getElementsByTagName('message').item(0) ;
			if (message && message.firstChild)	{

                message = message.firstChild.data ;
				obj = getById('process_message_login') ;
				obj.innerHTML = message ;

				getById('process_message_login').style.visibility = 'visible' ;
				getById('process_message_login').style.display = 'block' ;

			} else	{
				
                error = xmldoc.getElementsByTagName('error').item(0) ;
				if (error && error.firstChild)	{
					
                    error = error.firstChild.data ;

					obj = getById('process_error_login') ;
					obj.innerHTML = error ;

					getById('process_error_login').style.visibility = 'visible' ;
					getById('process_error_login').style.display = 'block' ;
				}
			}
			
			getById('img_process_login').style.visibility = 'hidden' ;
			getById('img_process_login').style.display = 'none' ;
			
			getById('submit').style.visibility = 'visible' ;
			getById('submit').style.display = 'block' ;
			
			// on réactive la classe Ajax
			vAjax.busy = false ;
		}
	}	
} ;
