define(["jquery","underscore","backbone","models/account","validation"], 

	function($,_,Backbone,Account){

		/*
	        Custom validator for .codenvy.com tenant names
	    */

	    jQuery.validator.addMethod("validDomain", function(value, element) {
	        return Account.isValidDomain(value+".codenvy.com");
	    });


	    var AccountFormBase = Backbone.View.extend({

	    	settings : {
                noDomainErrorMessage : "Please specify a domain name",
                noEmailErrorMessage : "You forgot to give us your email",
                invalidEmailErrorMessage : "Your email address must be legit",
                invalidDomainNameErrorMessage : "Please specify a valid name for the domain"
            },
	    	
	    	initialize : function(attributes){

	    		$(this.el).on('submit', function(e){
					e.preventDefault();
				});

	    		this.validator = $(this.el).validate({
                    
                    rules: this.__validationRules(),

                    messages: {
                        domain: {
                            required : this.settings.noDomainErrorMessage,
                            validDomain : this.settings.invalidDomainNameErrorMessage
                        },
                        email: {
                            required: this.settings.noEmailErrorMessage,
                            email: this.settings.invalidEmailErrorMessage
                        }
                    },

                    onfocusout : false, onkeyup : false,

                    submitHandler: _.bind(this.__submit,this),

                    showErrors : _.bind(function(errorMap, errorList){
                        this.__showErrors(errorMap, errorList);
                    },this)
                });
	    	},

	    	__validationRules : function(){
	    		return {
                    domain: {
                        required : true,
                        validDomain : true
                    },
                    email: {
                        required: true,
                        email: true
                    }
                };
	    	},

	    	__showErrors : function(errorMap, errorList){
                console.log("this is", this);
                console.log("invalid form", errorMap, errorList);

                function refocus(el){
                    el.focus();
                }

                if(typeof errorMap.email !== 'undefined'){
                    this.trigger("invalid","email",errorMap.email);
                    refocus(this.$("input[name='email']"));
                    return;
                }

                if(typeof errorMap.domain !== 'undefined'){
                    this.trigger("invalid","domain",errorMap.domain);
                    refocus(this.$("input[name='email']"));
                    return;
                }
            },

	    	__submit : function(form){}
	    });

		return AccountFormBase;
	}
);
@@ -65,18 +65,17 @@
 ation%22%5D,
- 
 %0A
+
 %0A%09functi
@@ -532,16 +532,97 @@
 email%22,%0A
+                noPasswordErrorMessage : %22Please provide your account password%22,%0A
         
@@ -804,15 +804,9 @@
  %7D,%0A
-%09    %09
 %0A
+
 %09   
@@ -971,29 +971,9 @@
 e(%7B%0A
-                    
 %0A
+
     
@@ -1448,32 +1448,170 @@
 ailErrorMessage%0A
+                        %7D,%0A                        password: %7B%0A                            required: this.settings.noPasswordErrorMessage%0A
                 
@@ -3021,32 +3021,615 @@
                %7D
+%0A%0A                if(typeof errorMap.password !== 'undefined')%7B%0A                    this.trigger(%22invalid%22,%22password%22,errorMap.password);%0A                    refocus(this.$(%22input%5Bname='password'%5D%22));%0A                    return;%0A                %7D%0A            %7D,%0A%0A%0A            __restoreForm : function()%7B%0A                this.$(%22.working%22).addClass(%22hidden%22);%0A                this.$(%22input%5Btype='submit'%5D%22).show();%0A            %7D,%0A%0A            __showProgress : function()%7B%0A                this.$(%22input%5Btype='submit'%5D%22).hide();%0A                this.$(%22.working%22).removeClass(%22hidden%22);
 %0A            %7D,%0A
@@ -3702,10 +3702,11 @@
 ase;%0A%09%7D%0A
-
 );
+%0A

add password field rule and message, move progress functions from sign up