    
    var NewAccountRequest = {
    
        newAccountRequestService:"/webservices/NewAccountRequest.aspx",
        initialize:function()
        {
            //-> DECLARE FORM_FIELDS_DOM_ID
            this.formFieldsDOMId = [
                "SDEZCompany",
                "companyName",
                "clientNumber",
                "contactLastName",
                "contactFirstName",
                "phoneNumber",
                "mail"
            ];
            
            this.missingDOMReference = false
            this.formFields = {}
            //-> CREATE FORM_FIELDS PROPERTIES
            for(var i = 0; i<this.formFieldsDOMId.length; i++)
            {
                if($(this.formFieldsDOMId[i]))
                {
                    this.formFields[this.formFieldsDOMId[i]] = $(this.formFieldsDOMId[i]);
                }
                else
                {
                    this.missingDOMReference = true;
                }
            }
            
            this.messagePanel = $("messagePanel");
            
            
            if(this.missingDOMReference || !$("messagePanel"))
            {
                alert("MISSING NEW_ACCOUNT_REQUEST DOM ELEMENTS !");
                return;
            }
        
            
            this.setupAccountRequestProcess();
            this.formFields.companyName.focus();
            this.messagePanel.update(Application.messages.NEW_ACCOUNT_REQUEST__WELCOME)
            
        },
        
        setupAccountRequestProcess:function()
        {
            if($("send"))
            {
                this.sendButton = new ActionButton("send");
                this.sendButton.addListener("sendNewAccountInformations", "click", function(e){this.sendNewAccountInformations()}.bindAsEventListener(this));
                this.sendButton.enable();
            }
            else
            {
                alert("MISSING SEND DOM BUTTON ELEMENT !");
                return;
            
            }
        },
        
        getFormValues:function()
        {
            //-> CHECK COMPANY_NAME 
            if(this.formFields.SDEZCompany.selectedIndex == 0 ||
               this.formFields.companyName.value == "" ||
               this.formFields.clientNumber.value == "" ||
               this.formFields.contactLastName.value == "" ||
               this.formFields.contactFirstName.value == "" ||
               this.formFields.phoneNumber.value == "" ||
               this.formFields.mail.value == "")
            {
                this.messagePanel.update(Application.errorsManager("MISSING_DATA", true).message);
                return null;
            }
            
            var SDEZAuthorizedInputFormat = Application.regexFormatValidator.SDEZAuthorizedInputFormat;
            
            if(!new RegExp(SDEZAuthorizedInputFormat).test(this.formFields.companyName.value) ||
               !new RegExp(SDEZAuthorizedInputFormat).test(this.formFields.clientNumber.value) ||
               !new RegExp(SDEZAuthorizedInputFormat).test(this.formFields.contactLastName.value) ||
               !new RegExp(SDEZAuthorizedInputFormat).test(this.formFields.contactFirstName.value) ||
               !new RegExp(SDEZAuthorizedInputFormat).test(this.formFields.phoneNumber.value) ||
               !new RegExp(SDEZAuthorizedInputFormat).test(this.formFields.mail.value))
            {
                this.messagePanel.update(Application.errorsManager("SDEZ_INPUT_FORMAT__INVALID_INPUT", true).message);
                return null;
            }
            
            //-> CHECK CONTACT_PHONE_NUMBER FORMAT
            if(!new RegExp(Application.regexFormatValidator.frenchPhoneNumber).test(this.formFields.phoneNumber.value))
            {
                this.messagePanel.update(Application.errorsManager("DATA_FORMAT_INVALID_PHONE_NUMBER", true).message);
                return null;
            }
            
            //-> CHECK MAIL FORMAT
            if(!new RegExp(Application.regexFormatValidator.mail).test(this.formFields.mail.value))
            {
                this.messagePanel.update(Application.errorsManager("DATA_FORMAT_INVALID_MAIL", true).message);
                return null;
            }
            
            //-> COLLECT
            var data = {};
            for(property in this.formFields) data[property] = this.formFields[property].value
                    
            return data;
        
        },
        
        sendNewAccountInformations:function()
        {
        
            var values = this.getFormValues();
            if(values == null) return;
            
            //-> COLLECT
            var postPackage = {};
            postPackage["action"] = "sendNewAccountInformations";
            for(property in values) postPackage[property] = encodeURIComponent(values[property]);
            
            //-> DISABLE TEXTBOXES
            this.toogleTextBoxes(false);
            //-> START LOADING
            this.sendButton.disable();
            this.messagePanel.update(Application.messages.LOADING);
            
            
            Utils.Ajax.webServiceCaller({
                url:this.newAccountRequestService,
                method:"post",
                parameters:postPackage,
                onLoading:Prototype.emptyFunction,
                onComplete:function(transport, json){
                			                                            
                    var response = transport.responseText;
                    
                    //-> SEND SUCCESS
                    if(response == "OK")
                    {
                        this.confirmNewAccountRequest();
                    }
                    else
                    {
                        this.messagePanel.update(Application.errorsManager(response, true).message);
                    
                        //-> ENABLE TEXTBOXES
                        this.toogleTextBoxes(true);
                        this.sendButton.enable();
                    } 

                }.bind(this)
				
            });                
        },
        
        confirmNewAccountRequest:function()
        {
            //-> MODALBOX CONFIRMATION
            Application.modalBox.confirm.open({
                message:Application.messages.NEW_ACCOUNT_REQUEST__CONFIRMATION,
                buttons:[
                    //-> OK BUTTON
                    {codeName:"ok", label:"Ok", action:Prototype.emptyFunction}
                ]
            });

            //-> ENABLE TEXTBOXES
            this.toogleTextBoxes(true);
            //-> ENABLE SEND_BUTTON
            this.sendButton.enable();
            //-> RESTORE DEFAULT MESSAGE PANEL
            this.messagePanel.update(Application.messages.NEW_ACCOUNT_REQUEST__WELCOME)
            //-> EMPTY FIELDS
            for(property in this.formFields)
            {
                if(this.formFields[property].tagName == "SELECT")
                {
                    this.formFields[property].selectedIndex = 0;
                }
                else
                {
                    this.formFields[property].value = "";
                }
            }

        
        },
        
        toogleTextBoxes:function(status)
        {            
            for(property in this.formFields)
            {
                eval("this.formFields[property]." + (!status?"disable":"enable") + "()");
            }
        }
    }
    
	Event.onDOMReady(function(){NewAccountRequest.initialize()});
