  var buttonOnEmail = 1; 
  var buttonOnPassword = 1;
  var buttonOnConfirm = 1;

$(function() {
   

   
   $("#CustomerEmail").bind('blur',function() { 
		$.post("/customers/checkEmail/", { email: $("#CustomerEmail").val() }, function(data){
		$('#email_status').html(unescape(data));
		$('#email_status').show("fast");
	
		if(data.charAt(13)=='g')
		{ buttonOnEmail=1; }
		else
		{ buttonOnEmail=0; }
	
		buttonShowHide();
	
		});
    });
    

    $("#CustomerEmailAddress").bind('blur',function() { 
        if ($("#CustomerEmailAddress").val()!="") {
            $.post("/customers/checkEmail/", { email: $("#CustomerEmailAddress").val() }, function(data){
            $('#email_status').html(unescape(data));
            $('#email_status').show("fast");
            $('#errorEmail').hide();
            });
        }
    });
    
    
   $("#CustomerPassword").bind('blur',function() { 
        
        if ($("#CustomerPassword").val().length < 6) {
			$('#password_status').html("<span class=\"badArrow\">&darr;</span> Your password must be at least 6 characters");
			$('#password_status').show("fast");
			$('#errorPassword').hide();
			var buttonOnPassword = 0;
		} else {
			$('#password_status').html("<span class=\"goodArrow\">&darr;</span> OK!");
			$('#password_status').show("fast");
			$('#errorPassword').hide();
			var buttonOnPassword = 1;
			
		}
		
		buttonShowHide();
		
    });
    
    
	$("#CustomerConfirmpassword").bind('blur',function() { 
		
        if ($("#CustomerConfirmpassword").val()!= $("#CustomerPassword").val() && $("#CustomerConfirmpassword").val().length > 1) {
			$('#confirmpassword_status').html("<span class=\"badArrow\">&darr;</span> Your passwords do not match");
			$('#confirmpassword_status').show("fast");
			$('#errorConfirmPassword').hide();
			buttonOnConfirm = 0;
		}
		if ($("#CustomerConfirmpassword").val()== $("#CustomerPassword").val())
		{
			$('#confirmpassword_status').html("<span class=\"goodArrow\">&darr;</span> OK!");
			$('#confirmpassword_status').show("fast");
			$('#errorConfirmPassword').hide();
			buttonOnConfirm = 1;
		}
		
		buttonShowHide();
		
	});
		
});

function buttonShowHide()
{
	if(buttonOnEmail && buttonOnPassword && buttonOnConfirm)
	{
		$('#signup').attr("onclick", " ");
	}
	else
	{
		$('#signup').attr("onclick", "alert('Please correct the errors above.'); return false;");
	}
}