var Bha = Bha || {}; 
var Form = {error:true}; 
 
Bha.Login = function()
{
     Bha.ToggleForms();
 
     //Bha.ToggleError();
     //$("#error").html('');
     //$("#error").hide();
                        
     var A = $.cookie('agree') || false; 
     var B = $.cookie('login') || false;
       
     if(parseInt(A))
     $('#agree').attr('checked',true);
     
     if(parseInt(B.length))
     $('#idEmail').attr('value',B);
     
     
     $("#LoginButton").click(function()
     {
         var E = '';
         var L = new Array('idEmail','idPassword','tmp');
         var I = {idEmail:"",idPassword:"",tmp:""}
         for(i=0;i<L.length;i++)
         {
            if(E=$("#"+L[i]+"").attr('value'))
            {
                I[L[i]]=E;
            }
         }
        if(I.idEmail.length<2)
        return Bha.LoginError('Invalid Email');
        if(I.idPassword.length<2)
        return Bha.LoginError('Invalid Password');
        
        var i = $('#agree').attr('checked');
        if(i!=true)
        return Bha.LoginError('You must accept Terms and Conditions'); 
         $.cookie('agree','1',{expires:7});
         $.cookie('login',I.idEmail,{expires:7});
     //if(!$('#agree').attr('checked'));
        //return Bha.LoginError('You must accept Terms and Conditions');
       
       
        
        $("#pass").attr('value',hex_md5(I.tmp+hex_sha1(I.idPassword)));
        $("#name").attr('value',I.idEmail);  
        Form.error = ''; 
     }); 
}
Bha.ToggleError = function()
{
    $(".error").each(function()
    {
        if('display:none'==$(this).attr('style'))
        return;
         
        var t = $(this).html();if(!parseInt(t.length))return;
        $(this).schedule('3s',function(){$(this).hide('fast');$(this).html('');$(this).unbind();});
    });  

}
Bha.ToggleForms = function()
{
    $(".js_fail").toggle();  
    $(".js_enabled").toggle(); 
}
Bha.LoginError = function(i)
{
    $("#error").show();
    $("#error").html(' Error: '+i+' ');   
    //Bha.ToggleError();
}
Bha.CheckForm = function()
{
        return (Form.error)?false:true;  
}

 
