<?php if ($_SESSION['priv'] == 'Superadmin') { ?>
<style>
		body { font-size: 62.5%; }
		label, input, select { display:block; margin:5px 0px 0px 0px; }
		/*input.text { margin-bottom:12px; width:95%; padding: .4em; }*/
		fieldset { padding:0; border:0; margin-top:20px; }
		h1 { font-size: 1.2em; margin: .6em 0; }
		div#users-contain { width: 350px; margin: 20px 0; }
		div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
		div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
		.ui-dialog .ui-state-error { padding: 0px 0px 0px 5px; }
		.validateTips { border: 1px solid transparent; padding: 0.3em; }
	</style>
	<script>

	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var username = $( "#username" ),
			password = $( "#password" ),
			fullname = $( "#fullname" ),
			email = $( "#email" ),
			priv = $( "#priv" ),
			allFields = $( [] ).add( username ).add( password ).add( fullname ).add( email ).add( priv ),
			tips = $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o1, o2, o3, o4, min) {
			if ( o1.val().length < min || o2.val().length < min  || o3.val().length < min || o4.val().length < min ) {
				//o1.addClass( "ui-state-error" );
				updateTips( "Please enter all user details." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 450,
			width: 350,
			modal: true,
			resizable: false,
			buttons: {
				"Submit user": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

					bValid = checkLength( username, password, fullname, email, 4 );

					bValid = bValid && checkRegexp( email, /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/, "Email address is not valid." );
					
					bValid = bValid && checkRegexp( username, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
						// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					
					
					if ( bValid ) {
						// INSERT PAGE
						// CREATE NOTE
						
						xmlhttp = new XMLHttpRequest();
						xmlhttp.open("POST","ajax/submit_user.php",true);
						xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
						xmlhttp.send("username="+username.val()+"&password="+password.val()+"&email="+email.val()+"&fullname="+fullname.val()+"&priv="+priv.val());
						
						xmlhttp.onreadystatechange=function() {
  							if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    							if (xmlhttp.responseText == "success") {
									//updateTips (xmlhttp.responseText);
									$( "#dialog-form" ).dialog( "close" );					
									$( "#dialog-message" ).dialog( "open" );
								}
							}
						}
						
						// title.val()
						// pagelink.val() 
						// pid.val() 
						//$( this ).dialog( "close" );
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#dialog-message" ).dialog({
			autoOpen: false,
			height: 450,
			width: 350,
			modal: true,
			resizable: false,
			buttons: {
				Ok: function() {
					$( "#dialog-form" ).dialog( "close" );
					$( this ).dialog( "close" );
				}
			}
		});

		$( "#create_page" )
			.button()
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
	});
	
	</script>


<div id="dialog-form" title="Create new account">
	<p class="validateTips">Please enter user details.</p>

	<form>
	<fieldset>
		<label for="username">Username</label>
		<input type="text" name="username" id="username" value="" class="text ui-widget-content ui-corner-all" />
		<label for="password">Password</label>
		<input type="text" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
        <label for="fullname">Full Name</label>
        <input type="text" name="fullname" id="fullname" class="text ui-widget-content ui-corner-all" />		
        <label for="email">E-mail</label>
        <input type="text" name="email" id="email" class="text ui-widget-content ui-corner-all" />		
        <label for="priv">Privilegy</label>
        <select name="priv" id="priv" class="text ui-widget-content ui-corner-all">
        <option value="Starter">Starter</option>
        <option value="Advanced">Advanced</option>
        <option value="Master">Master</option>
        <option value="Admin">Admin</option>
        </select>
    </fieldset>
	</form>
</div>


<div id="dialog-message" title="Account sucessfully created">
	<p>New user successfully created. <br /><br />
Thank You!</p>
</div>



<div class="content_box">
<div class="content_box_custom">
<?php /*?><form action="#" method="post">
<input name="newpage" value="Page name" id="newpage" onfocus="eraseText('Page name', this.id);" onblur="retrieveText('Page name', this.id);" />
<button id="create_page">Create Page</button>
</form>
<?php */?>

<button id="create_page">Submit User</button>

</div>

</div>

<?php } ?>