$(document).ready(
    function(){
    
       
     $("#install-link").colorbox({transition: 'fade',fixedWidth:"320px", fixedHeight: "440px", inline:true, href:"#signup-container"});
     $("#install-link").click(function(){
        $('#signup-response-status-div').hide();
        install();
     });
     //$(".newUser > a").colorbox({transition: 'fade',fixedWidth:"320px", fixedHeight: "440px", inline:true, href:"#signup-container"});
     //$(".newUser > a").click(function(){
     //   $('#signup-response-status-div').hide();
     //});
     
    $('#new_user').submit(function(e){
              params = {'user[login_name]':$('#user_login_name').val(),
                'user[password]':$('#user_password').val(),
                'user[password_confirmation]':$('#user_password_confirmation').val(),
                'user[first_name]':$('#user_first_name').val()};
              $.post('/users/create_ajax',params, signup_handler);
              toggle_signup_button();
              if (e && e.preventDefault)
                e.preventDefault();
               else
                return false
      });

     

}
);

 eval_json = function(data) {
    return eval("(" + data + ")");
}


toggle_signup_button = function(){
var submitButton = $('#new_user').find("input[type='submit']");

    if ($(submitButton).attr("value") == "Wait.."){
         $(submitButton).attr("value", "Register");
         $(submitButton).attr("disabled", false);
    }
    else{
         $(submitButton).attr("value", "Wait..");
         $(submitButton).attr("disabled", true);

    }
}


var signup_handler = function(data){  
   toggle_signup_button();
   var response = eval_json(data);
   if (response['status'] == 'Success'){
      $('#signup-errors').html('<strong>' +'Signup Complete! ' +'</strong>');
      $('#signup-response-status-div').fadeIn();
      $("#modalClose").click();
      window.location = '/';
   }else{
       errors = response['content'];
       $('#signup-errors').html('<strong>' +'! ' +'</strong>' + errors[0]);
       $('#signup-response-status-div').fadeIn();
   }


 }