<?php
  /**
   * Copyright 2011 Zazavi - http://www.zazavi.com
   * Zazavi is free software released under the terms of the GNU General Public License.
   * You should have received a copy of the license.  If not, see <http://www.gnu.org/licenses/>.
   */
  if (!defined("_VALID_PHP"))
      die('Direct access to this location is not allowed.');
?>
<!-- Full Layout -->
<div id="main-col">
  <div class="wrap">
    <div class="main-col-inner">
      <?php if(!$core->reg_allowed):?>
      <div class="msgInfo"><?php echo _UA_NOMORE_REG;?></div>
      <?php elseif($core->user_limit !=0 and $core->user_limit == $numusers):?>
      <div class="msgInfo"><?php echo _UA_MAX_LIMIT;?></div>
      <?php else:?>
      <h1><?php echo _UA_TITLE4;?></h1>
      <p class="info"><?php echo _UA_INFO4. _REQ1. required() . _REQ2;?></p>
      <div class="box">
      <div id="response"></div>
      <div id="fullform">
        <form action="" method="post" name="user_form" id="user_form">
          <table width="100%" border="0" cellpadding="3" cellspacing="0">
            <tr>
              <td colspan="2"><h3><?php echo _UA_SUBTITLE4;?></h3></td>
            </tr>
            <tr>
              <td width="250"><strong><?php echo _USERNAME;?>: <?php echo required();?></strong></td>
              <td><span id="getusername">
                <input name="username" type="text" class="inputbox"  id="username" size="45" />
                <img src="<?php echo ADMINURL;?>/images/yes.png" alt="" id="yes" style="display:none" title="<?php echo _UR_USERAVAIL;?>" /> 
                <img src="<?php echo ADMINURL;?>/images/delete.png" alt="" id="no" style="display:none" title="<?php echo _UR_USERNOAVAIL;?>" />
                </span></td>
            </tr>
            <tr>
              <td><strong><?php echo _PASSWORD;?>: <?php echo required();?></strong></td>
              <td><input name="pass" type="password" class="inputbox"  size="45" />
                &nbsp; <?php echo tooltip(_UA_PASSWORD2_T);?></td>
            </tr>
            <tr>
              <td><strong><?php echo _UA_PASSWORD2;?>: <?php echo required();?></strong></td>
              <td><input name="pass2" type="password" class="inputbox"  size="45" /></td>
            </tr>
            <tr>
              <td><strong><?php echo _UR_EMAIL;?>:</strong> <?php echo required();?></td>
              <td><input name="email" type="text" class="inputbox"  value="<?php echo post('email');?>" size="45" /></td>
            </tr>
            <tr>
              <td><strong><?php echo _UR_FNAME;?>:</strong> <?php echo required();?></td>
              <td><input name="fname" type="text" class="inputbox" size="45" value="<?php echo post('fname');?>" /></td>
            </tr>
            <tr>
              <td><strong><?php echo _UR_LNAME;?>:</strong> <?php echo required();?></td>
              <td><input name="lname" type="text" class="inputbox" size="45" value="<?php echo post('lname');?>" /></td>
            </tr>
            <tr>
              <td><strong><?php echo _UA_REG_RTOTAL;?></strong> <?php echo required();?></td>
              <td><input name="captcha" type="text" class="inputbox" size="10" maxlength="2"/></td>
            </tr>
            <tr>
              <td colspan="2"><input class="button" name="submit" value="<?php echo _UA_REG_ACC;?>" type="submit" /></td>
            </tr>
          </table>
          <input name="doRegister" type="hidden" value="1" />
        </form>
        </div>
      </div>
	  <script type="text/javascript">
      // <![CDATA[
      $(document).ready(function() {
          $("#user_form").submit(function () {
              var str = $(this).serialize();
              $.ajax({
                  type: "POST",
                  url: "ajax/user.php",
                  data: str,
                  success: function (msg) {
                      $("#response").ajaxComplete(function(event, request, settings) {
                      if(msg  == 'OK') {
                          result = '<div class="msgOk"><?php echo _UA_REG_OK;?><\/div>';
                      $("#fullform").hide();
                      } else {
                      result = msg;
                      }
                     $(this).html(result);
                          });
                      }
                  });
              return false;
          });
      });
      // ]]>
      </script>
      <?php endif;?>
    </div>
  </div>
</div>
<!-- Full Layout /--> 
<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
	$('#username').keyup(username_check);
});
function username_check() {
	var username = $('#username').val();
	if (username == "" || username.length < 4) {
		$('#yes').hide();
	} else {
		$.ajax({
			type: "POST",
			url: "ajax/user.php",
			data: 'checkUsername=' + username,
			cache: false,
			success: function(response) {
				if (response == 1) {
					$('#yes').hide();
					$('#no').fadeIn();
				} else {
					$('#no').hide();
					$('#yes').fadeIn();
				}

			}
		});
	}
}
// ]]>
</script>