var login = function(){
    return {
        Init: function(){
        },
        opensenha: function(){
            $('span_senha').show();
            $('reenvio_senha').select();
            $('reenvio_senha').value = "";
            $('label_reenvio_erro').hide();
        	$('label_reenvio_ok').hide();  
        },
        reenvia: function(url){
            var el = $('reenvio_senha');
            if(el.value == "")
            {
              $(el).setStyle(
	                    {border:'solid 1px #FF0000'}
	                );
	          $(el).select();   
            }else
            {
               new Ajax.Request(url, {
    	                        asynchronous:true, 
    	                        evalScripts:true, 
    	                        method:'get',
    	                        parameters:{cliente:el.value},
    	                        onComplete : function(req){ 
        	                                    var json = req.responseText.evalJSON();        	                                    
        	                                    if(!json.isAuth){
        	                                        $('label_reenvio_erro').show();
        	                                        $('label_reenvio_ok').hide();        	                                        
        	                                    }else{
        	                                        $('label_reenvio_erro').hide();
        	                                        $('label_reenvio_ok').show();
        	                                        setTimeout("$('span_senha').hide();",1500);
        	                                    }
       		                            }
    	                    });
            }            
        },
        autentica: function(url,form){        
        
            var fields = ['auth_email','auth_senha'];
            var isValid = false;
            
            fields.each(function(item){            
            isValid = $(item).present();            
	        if(!isValid){	            	            
	            $(item).setStyle(
	                    {border:'solid 1px #FF0000'}
	                );
	        } else {
                $(item).setStyle(
                        //{border:'solid 1px #FFFFFF'}
                    );
            }
	        });
	        
	        if(isValid)
	        {
	            new Ajax.Request(url, {
    	                        asynchronous:true, 
    	                        evalScripts:true, 
    	                        method:'get',
    	                        parameters:Form.serialize(form),
    	                        onComplete : function(req){ 
        	                                    var json = req.responseText.evalJSON();        	                                    
        	                                    if(!json.isAuth){
        	                                        alert(json.Message);
        	                                    }else{
        	                                        location.href = json.Url;
        	                                    }
       		                            }
    	                    });
	        }
        }
        
        
    };
}();
login.Init;

