     NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
     NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
   }
-    
+  
+  func disableRegisterButton() {
+    registerButtonOutlet.backgroundColor = UIColor.grayColor()
+    registerButtonOutlet.enabled = false
+  }
+  
+  func enableRegisterButton() {
+    registerButtonOutlet.backgroundColor = studyBoxRedColor
+    registerButtonOutlet.enabled = true
+  }
+  
+  func passwordTooShortAlert() {
+    
+    let alertController = UIAlertController(title: "Za krótkie hasło",
+      message: "Hasło musi mieć co najmniej 8 znaków.",
+      preferredStyle: .Alert)
+    
+    let actionOk = UIAlertAction(title: "OK", style: .Default, handler: nil)
+    alertController.addAction(actionOk)
+    self.presentViewController(alertController, animated: true, completion: nil)
+  }
+  
+  func passwordsDontMatchAlert() {
+    
+    let alertController = UIAlertController(title: "Hasła są różne",
+      message: "Oba hasła muszą być identyczne.",
+      preferredStyle: .Alert)
+    
+    let actionOk = UIAlertAction(title: "OK", style: .Default, handler: nil)
+    alertController.addAction(actionOk)
+    self.presentViewController(alertController, animated: true, completion: nil)
+  }
+  
+  func emailIsTakenAlert() {
+    
+    let alertController = UIAlertController(title: "Adres e-mail zajęty",
+      message: "Już istnieje konto z takim adresem e-mail.",
+      preferredStyle: .Alert)
+    
+    let actionOk = UIAlertAction(title: "OK", style: .Default, handler: nil)
+    alertController.addAction(actionOk)
+    self.presentViewController(alertController, animated: true, completion: nil)
+  }
+  
+  func passwordContainsSpaceAlert() {
+    
+    let alertController = UIAlertController(title: "Spacja w haśle",
+      message: "Hasło hasło nie może zawierać spacji.",
+      preferredStyle: .Alert)
+    
+    let actionOk = UIAlertAction(title: "OK", style: .Default, handler: nil)
+    alertController.addAction(actionOk)
+    self.presentViewController(alertController, animated: true, completion: nil)
+  }
+  
 }

    super.viewWillAppear(animated)
    dataSource = self
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    

    
    if !result {
      textField.textColor = UIColor.redColor()
      disableRegisterButton()
    }
    else {
      //TODO: check if email exists in database, if not then emailIsTakenAlert() and code below
      textField.textColor = studyBoxBlueColor
      enableRegisterButton()
    }
  }
  
  func checkPasswordLengthAndSpaces(password: UITextField) {
    if let characterCount = password.text?.characters.count {
      if characterCount < 8 {
        passwordTooShortAlert()
      }
    }
    
    if (password.text?.containsString(" ") == true) {
      passwordContainsSpaceAlert()
    }
  }
  
  func checkPasswordsMatch(password1 password1:UITextField, password2:UITextField) {
    
    if (password1.text != "" && password2.text != "") {
      if (password1.text != password2.text){
        password1.textColor = UIColor.redColor()
        password2.textColor = UIColor.redColor()
        passwordsDontMatchAlert()
        disableRegisterButton()
      }
      else {
        password1.textColor = studyBoxBlueColor
        password2.textColor = studyBoxBlueColor
        
        enableRegisterButton()
      }
    } else {
      disableRegisterButton()
    }
    
    
