<?php
	require_once('common.php');

	if (isset($_POST['submitBtn'])){
		// Get user input
		$username  = isset($_POST['username']) ? $_POST['username'] : '';
		$password1 = isset($_POST['password1']) ? $_POST['password1'] : '';
		$password2 = isset($_POST['password2']) ? $_POST['password2'] : '';
        $secretpassword = isset($_POST['secretpassword']) ? $_POST['secretpassword'] : '';
		// Try to register the user
		$error = registerUser($username,$password1,$password2,$secretpassword);
	}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Jimmy Cleans Administration Registration</title>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
		<!-- stylesheets -->
		<link rel="stylesheet" type="text/css" href="css/reset.css" />
		<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
		<link id="color" rel="stylesheet" type="text/css" href="css/greyblue.css" />
		<!-- js (jquery) -->
		<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
		<script src="js/jquery-ui-1.8.custom.min.js" type="text/javascript"></script>
		<script src="js/smooth.js" type="text/javascript"></script>
		<script type="text/javascript">
			$(document).ready(function () {
				style_path = "css/colors";

				$("input.focus").focus(function () {
					if (this.value == this.defaultValue) {
						this.value = "";
					}
					else {
						this.select();
					}
				});

				$("input.focus").blur(function () {
					if ($.trim(this.value) == "") {
						this.value = (this.defaultValue ? this.defaultValue : "");
					}
				});

				$("input:submit, input:reset").button();
			});
		</script>
	</head>
	<body>
		<div id="login">
			<!-- login -->
			<div class="title">
				<h5>Jimmy Cleans - Register A User</h5>
				<div class="corner tl"></div>
				<div class="corner tr"></div>
			</div>
			<?php
			 if (isset($_POST['submitBtn'])){

	if ($error == '') {
		
		echo'
			<div class="messages">
			<div id="message-success" class="message message-success">
							<div class="image">
								<img src="images/icons/success.png" alt="Success" height="32" />
							</div>
							<div class="text">
								<h6>Success</h6>
								<span>Username was registered successfully!</span>
								<br/>
						<span><a href="login.php">You can login here</a></span>
							</div>
							<div class="dismiss">
								<a href="#message-success"></a>
							</div>
			</div>
			</div>
		';
		
		
	}
	else echo $error;

?>
	
	
<?php            
    }

 if ((!isset($_POST['submitBtn'])) || ($error != '')) {?>

			<div class="inner">
      <form id="registration" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="registerform">
				<div class="form">
					<!-- fields -->
					<div class="fields">
						<div class="field">
							<div class="label">
								<label for="username">Username:</label>
							</div>
							<div class="input">
								<input type="text" id="username" name="username" size="40" class="focus" />
							</div>
						</div>
						<div class="field">
							<div class="label">
								<label for="password">Password:</label>
							</div>
							<div class="input">
								<input class="focus" name="password1" type="password" id="password" size="40"/>
							</div>
						</div>
						<div class="field">
							<div class="label">
								<label for="password">Confirm password:</label>
							</div>
							<div class="input">
								<input class="focus" name="password2" type="password" size="40"/>
							</div>
						</div>
						<div class="field">
							<div class="label">
								<label for="password">Super Secret Password:</label>
							</div>
							<div class="input">
								<input class="focus" name="secretpassword" type="password" size="40"/>
							</div>
						</div>

						<div class="field">
							<div class="checkbox">
							
							</div>
						</div>
						<div class="buttons">
							<input type="submit" name="submitBtn" value="Sign In" />
						</div>
					</div>
					<!-- end fields -->
					<!-- links -->
					<div class="links">
						<a href="index.php">Go Back</a>
					</div>
					<!-- end links -->
				</div>
				</form>
			</div>
			<?php 
}  
?>
		</div>
	</body>
</html>
</html>