<script type="text/javascript">
function validate_user(){

	var emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	if($("#user_username").val()==''){
		$("#msg_user_error_message").html('Please enter Username');
		$("#user_username").addClass('jquery_err');
		$("#user_username").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#user_username").removeClass('jquery_err');
	}
	
	
	
	if($("#user_password").val()==''){
		$("#msg_user_error_message").html('Please enter Password');
		$("#user_password").addClass('jquery_err');
		$("#user_password").focus();
		return false;
	}else if($("#user_password").val()!='' && $("#user_password").val()!=$("#user_repassword").val()){
		$("#msg_user_error_message").html('Password and Again password do not matched');
		$("#user_password").addClass('jquery_err');
		$("#user_password").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#user_password").removeClass('jquery_err');
	}
	
	if($("#user_name").val()==''){
		$("#msg_user_error_message").html('Please enter name');
		$("#user_name").addClass('jquery_err');
		$("#user_name").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#user_name").removeClass('jquery_err');
	}
	if($("#father_name").val()==''){
		$("#msg_user_error_message").html('Please enter Father Name');
		$("#father_name").addClass('jquery_err');
		$("#father_name").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#father_name").removeClass('jquery_err');
	}
	
	if($("#father_occupation").val()==''){
		$("#msg_user_error_message").html('Please enter Father Occupation');
		$("#father_occupation").addClass('jquery_err');
		$("#father_occupation").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#father_occupation").removeClass('jquery_err');
	}
	
	if($("#mother_name").val()==''){
		$("#msg_user_error_message").html('Please enter Mother Name');
		$("#mother_name").addClass('jquery_err');
		$("#mother_name").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#mother_name").removeClass('jquery_err');
	}
	
	if($("#mother_name").val()==''){
		$("#msg_user_error_message").html('Please enter Mother Name');
		$("#mother_name").addClass('jquery_err');
		$("#mother_name").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#mother_name").removeClass('jquery_err');
	}
	
	if($("#date_of_birth").val()==''){
		$("#msg_user_error_message").html('Please select Date of Birth');
		$("#date_of_birth").addClass('jquery_err');
		$("#date_of_birth").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#date_of_birth").removeClass('jquery_err');
	}
	
	if($("#last_degree").val()==''){
		$("#msg_user_error_message").html('Please select last Education Qualification');
		$("#last_degree").addClass('jquery_err');
		$("#last_degree").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#last_degree").removeClass('jquery_err');
	}
	
	if($("#annual_incom").val()==''){
		$("#msg_user_error_message").html('Please select Annual income');
		$("#annual_incom").addClass('jquery_err');
		$("#annual_incom").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#annual_incom").removeClass('jquery_err');
	}
	
	if($("#address").val()==''){
		$("#msg_user_error_message").html('Please enter address');
		$("#address").addClass('jquery_err');
		$("#address").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#address").removeClass('jquery_err');
	}
	
	if($("#mobile_no").val()==''){
		$("#msg_user_error_message").html('Please enter contact number');
		$("#mobile_no").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#mobile_no").removeClass('jquery_err');
	}

	if($("#mobile_no").val().length > 16){
		$("#msg_user_error_message").html('Please enter proper digit mobile number');
		$("#mobile_no").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#mobile_no").removeClass('jquery_err');
	}

	if(isNaN($("#mobile_no").val())== true){
		$("#msg_user_error_message").html('Please enter valid mobile number');
		$("#mobile_no").focus();
		return false;
	}else{
		$("#msg_user_error_message").html('');
		$("#mobile_no").removeClass('jquery_err');
	}
		
	
}


function validate_username(username,user_id){
	
	$("#loading_username").show();

	$.ajax({
		  url: "adduser.php",
		  data: 'act=validate_username&username='+username.value+'&user_id='+user_id,
		  method: 'POST',
		  success: function(msg){
				$("#loading_username").hide();
		  		if(msg!=''){
					$("#user_username").addClass('jquery_err');
					$("#msg_user_username").html(msg);
		  		}else{
					$("#user_username").removeClass('jquery_err');
					$("#msg_user_username").html('');
		  		}
		  }
		});
}
$(document).ready(function(){
	
	$("#user_password").blur(function (){
		$("#loading_pass").show();

		
		
		if($("#user_password").val()==''){
			$("#msg_user_password").html('Please enter Password');
			$("#user_password").addClass('jquery_err');
			$("#loading_pass").hide();
			$("#user_password").focus();
			return false;
		}else{
			$("#user_password").removeClass('jquery_err');
			$("#loading_pass").hide();
			$("#msg_user_password").html('');
  		}
  		
 	});

	$("#user_repassword").blur(function (){
		$("#loading_repass").show();

		if($("#user_repassword").val()!==$("#user_password").val()){
			$("#user_repassword").addClass('jquery_err');
			$("#msg_user_repassword").html('Password and Again password do not matched');
	  		$("#loading_repass").hide();
	  	}else{
			$("#user_repassword").removeClass('jquery_err');
			$("#msg_user_repassword").html('');
	  		$("#loading_repass").hide();
  		}

	});
});

</script>
<!-- Content (Right Column) -->

<div id="content" class="box">
  <h1> User &raquo; Add User</h1>
  <?php if(isset($successMsg) && $successMsg!=''){ ?>
  <p class="msg done"><?php echo $successMsg; ?></p>
  <?php } ?>
  <?php if(isset($failedMsg) && $failedMsg!=''){ ?>
  <p class="msg error"><?php echo $failedMsg; ?></p>
  <?php } ?>
  <form action="" method="post" id="userFrm" name="userFrm" onsubmit="return validate_user();" enctype="multipart/form-data">
    <?php if(isset($_REQUEST['user_id']) && $_REQUEST['user_id']!=''){ ?>
    <input type="hidden" id="user_id" name="user_id" value="<?php echo $userDetail->user_id ?>" >
    <?php } ?>
    <!-- Login -->
    
    <p class="nomt"> <span class="smaller low message" id="msg_user_error_message" style="font-weight:bold;">&nbsp;</span> </p>
    <div id="tab01" class="eng_tab">
      <fieldset>
        <legend>Basic Details</legend>
        <p class="nomt">
          <label for="inp-01" class="req">Email Address / Username:</label>
          <br />
          <input type="text" size="50" name="email_address" id="email_address" value="<?php echo $userDetail->email_address ?>" class="input-text-02" />
          <span id="loading_email" class="aloader" style="display:none"><img src="images/ajaxLoader.gif"></span><br/>
          <span class="smaller low message" id="msg_email_address">&nbsp;</span> </p>
        <?php if(!isset($userDetail->user_password) || $userDetail->user_password ==''){ ?>
        <p>
          <label for="inp-02" class="req">Password*:</label>
          <br />
          <input type="password" size="50" name="user_password" id="user_password" value="" class="input-text-02"/>
          <span id="loading_pass" class="aloader" style="display:none"><img src="images/ajaxLoader.gif"></span><br/>
          <span class="smaller low message" id="msg_user_password">&nbsp;</span> </p>
        <p class="nomb">
          <label for="inp-03" class="req">Password again:</label>
          <br />
          <input type="password" size="50" name="user_repassword" id="user_repassword" value="" class="input-text-02"  />
          <span id="loading_repass" class="aloader" style="display:none"><img src="images/ajaxLoader.gif"></span><br/>
          <span class="smaller low message" id="msg_user_repassword">&nbsp;</span> </p>
        <?php } ?>
        <p class="nomt">
          <label for="inp-01" class="req">Full Name*:</label>
          <br />
          <input type="text" size="50" name="user_name" id="user_name" value="<?php echo $userDetail->user_name; ?>" class="input-text-02" />
          <br/>
          <span class="smaller low message" id="msg_user_name">&nbsp;</span> </p>
        <p class="nomt">
      <label for="inp-01" class="req">Profile Image :</label>
      <br />
      <input type="file" name="profile_image" id="profile_image" class="input-text-02"   />
      <?php if($userDetail->profile_image!='' && file_exists(DIR_UPLOAD_BANNER.$userDetail->profile_image)) {?>
      <img src="<?php echo DIR_UPLOAD_BANNER_SHOW.$userDetail->profile_image ?>"/>
      <input type="hidden" id="uploaded_file" name="uploaded_file" value="<?php echo $userDetail->profile_image;  ?>" />
      <?php } ?>
      <br/>
      <span class="smaller low message" id="msg_gallery_banner">&nbsp;</span> </p>
        <p class="nomt">
          <label for="inp-01" class="req">Cell / Mobile No*:</label>
          <br />
          <input type="text" name="mobile_no" id="mobile_no" class="input-text-02" value="<?php echo $userDetail->mobile_no; ?>" size="50" />
          <br/>
          <span class="smaller low message" id="msg_mobile_no">&nbsp;</span> </p>
        
        <p class="nomb">
          <label for="inp-03" class="req">Status :</label>
          <br />
          <select id="user_status" name="user_status" class="input-text-02">
            <option value="0" <?php echo ($userDetail->user_status==0) ? "selected='selected'" : "" ?>>Inactive</option>
            <option value="1" <?php echo (!isset($userDetail->user_status) || $userDetail->user_status==1) ? "selected='selected'" : "" ?>>Active</option>
          </select>
          <br/>
          <span class="smaller low message" id="msg_user_status">&nbsp;</span> </p>
      </fieldset>
    </div>
    <?php if(isset($userDetail->user_id) && $userDetail->user_id!=''){ ?>
    <p>
      <input type="submit" value="Edit User" id="submit" name="submit" class="input-submit" />
    </p>
    <?php }else{ ?>
    <p>
      <input type="submit" value="Add User" id="submit" name="submit" class="input-submit" />
    </p>
    <?php } ?>
    <input type="button" value="Cancel" id="cancel" name="cancel" class="input-submit" onclick="javascript:window.location='userlist.php'" />
  </form>
</div>
<!-- /content --> 
