/*
Hypercombofinish.com
Comment Engine

Chris Maguire 2009
*/

$(document).ready(function() {
  
  $("#comment_viewer").click(function(e) {
    $(".comment_display").css("display","block");
  });
  
  $("#comment_submit_button").click(function(e) {
    var old_button_value=$("#comment_submit_button").attr('value');
  	$("#comment_submit_button").attr('value', "Please Wait...");
  	$("#comment_submit_button").attr('disabled', true);
  	$.post("forms/login_register.php",
    { 
      ret_email:$("#ret_email").val(),
      ret_password:$("#ret_password").val(),
      new_username:$("#new_username").val(),
      new_email:$("#new_email").val(),
      new_password1:$("#new_password1").val(),
      new_password2:$("#new_password2").val(),
      logged_in:$("#logged_in").val(),
      entry_id:$("#entry_id").val(),
      from_url:$("#from_url").val()
    },
    function(json){
      var error_message=json['error_message'];
      var happy_message=json['happy_message'];
      var user_id=json['user_id'];
      if(error_message)
      {
      	//$("#message_cell").css("display","block");
      	$("#message_cell").css("color","#ae1d1d");
        $("#message_cell").html(error_message);
        $("#comment_submit_button").attr('value', old_button_value);
        $("#comment_submit_button").attr('disabled', false);
      }
      else
      {
      	//$("#message_cell").css("display","block");
      	$("#message_cell").css("color","#27d715");
        $("#message_cell").html(happy_message);
        //if we got a happy message, i guess can close off the form?
        $("#ret_email").attr("disabled","disabled");
        $("#ret_password").attr("disabled","disabled");
        $("#new_username").attr("disabled","disabled");
        $("#new_email").attr("disabled","disabled");
        $("#new_password1").attr("disabled","disabled");
        $("#new_password2").attr("disabled","disabled");
        
        //redirect attempt
        if(happy_message=="&bull; You have been logged in! You are being redirected to the last page you were browsing.")
        {
        	if(!$("#from_url").val())
        	{
        		document.location.href="http://www.hypercombofinish.com/index.php";
        	}
        	else
        	{
        		document.location.href=$("#from_url").val();
        	}
        }
        
      	$("#comment_submit_button").attr('value', old_button_value);
        //$("#comment_submit_button").attr('disabled', false);
      }
    }, 'json');
  });
  
});
