<script>
     function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#profilepicture')
                        .attr('src', e.target.result)
                        .width(166)
                        .height(166);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
		
$(function(){
    $('#checksame').click(function(){
		if ($('#checksame').prop('checked'))
		 
		 {
		
			$('#permanentaddress').val($('#currentaddress').val());
	  
		 }
		 else
		 {
			 $('#permanentaddress').val('');
		 }
	  
    });
});



  function blockKeyPress(evt)
{
	 var charCode = (evt.which) ? evt.which : evt.keyCode;
	 alert(charCode);
			if(charCode == 8 || charCode == 46 )
       
			{
				return false;
			}
			else
			{
				return false;
			}
}

 function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
	   
//PAN Validate 
function validatePAN() {
 var reg = /(?=.*[A-Za-z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Za-z]).{1,}$/;
          
			var PAN = $('#panno').val();
			
			if(PAN != '')
			{
				if (reg.test(PAN) == false) 
				{
					alert('Please Enter Valid PAN Number');
					return (false);
				}
				else
				{
					return true;
				}
			}
			
}

function getMobileValidation() {
	var contactNumber = $('#ContactNumber').val().length;
	if(contactNumber < 10)
	{
		alert('Please Enter valid Contact Number');
		return false;
	}
	else
	{
		return true;
	}
}
function getValidEmergencyNumber() {
	var contactNumber = $('#emergencycontactnumber').val().length;
	if(contactNumber < 10)
	{
		alert('Please Enter valid Emergency Contact Number');
		return false;
	}
	else
	{
		return true;
	}
}
function getValidReferNumber() {
	var contactNumber = $('#referrercontno').val().length;
	if(contactNumber > 0 &&  contactNumber < 10)
	{
		alert('Please Enter valid Refernce Contact Number');
		return false;
	}
	else
	{
		return true;
	}
}
function validateEmail() {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
          
			var email = $('#emailid').val();
			
			if(email != '')
			{
            if (reg.test(email) == false) 
            {
                alert('Please Enter Valid Email Address');
                return (false);
            }
			else
			{
				return true;
			}
			}
			else
			{
				alert('Please Enter email id');
			}
			
}  
function getAge() {
	
	var  dateString =  $("#DateofBirth").val();
	
    var today = new Date();
    var birthDate = new Date(dateString);
	
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
    }
	 $("#age").val(age);
   
}

$(function() {
	var d = new Date();

	var month = d.getMonth();
	var day = d.getDate();
	var year = d.getFullYear()  ;
	var SIAStartYear = year - 2015;
	var mindt = year-70;
	var maxdt =  year-15;
	
    $("#DateofBirth").datepicker({
	minDate : new Date(mindt,1,1),
	maxDate : new Date(maxdt,1,1),
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '-100:+0'


});
	  $("#dateofjoining").datepicker({
	minDate : new Date(year-SIAStartYear,1,1),
	maxDate :'now',
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,



});
	  $("#ValidTill").datepicker({dateFormat: 'mm/dd/yy',minDate :'now',changeMonth: true, changeYear: true,yearRange: '-0:+100'
});
	 
});

function resetphoto()
{  
    $("#photo").src("");
}

function ValidatePassport()
{
        var regsaid = /^[A-PR-WY][1-9]\d\s?\d{4}[1-9]$/ig;
		var passport = $("#passportno").val();
		//alert(passport);
        if(regsaid.test(passport) == false)
        {
            alert('You have entered invalid Passport.');
			return;
        }
        
}

function onlyAlphabets(evt) {
        var charCode;
        if (window.event)
            charCode = window.event.keyCode;  //for IE
        else
            charCode = evt.which;  //for firefox
        if (charCode == 32) //for &lt;space&gt; symbol
            return true;
        if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
            return false;
        if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
            return false;
        if (charCode > 122) //for characters beyond 'z' in ASCII Table
            return false;
        return true;
    }
</script>
 <style>
 legend{
 color:#00c0ef ! important;
 } 
 .form-group
 {
	 padding-bottom:4%;
   }
   .pad{
	   padding-bottom:1%;
   }
    .badge
   {
	   color:red; background-color:#fff;
   }
 </style>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
          <CENTER>Siddharth Industries Employee Profile</CENTER>
         
      </h1>
	  
    </section>
    
    <section class="content">
	<div style="text-align:right;">
    <a href="<?php echo base_url() ?>employeeListing" class="btn btn-info" value="Back">Back</a>
	</div>
	<br/>
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
              <!-- general form elements -->
                 
 <div class="box box-primary">
		<!-- /.box-header -->
                    <!-- form start -->
					 
               	 
<form role="form" id="addemployee" action="<?php echo base_url() ?>employeedetails/AddNewEmployee" method="post"  enctype="multipart/form-data"> 
 
  <div class="row">
    <div class="col-md-10 col-md-offset-1"   style="border:3px solid #3c8dbc;">
      <form class="form-horizontal" role="form" >
        <fieldset>
		 
          <!-- Form Name -->
          <legend>Personal Information</legend>
           
		   <div class="col-md-12">
		   <div class="col-md-3">
		   <div class="box-header">                                              
                <img id="profilepicture" src="<?php echo base_url(); ?>assets/dist/img/avatar.png" alt="your image"  style="width: 139px;"/><br/>
                <input type='file' onchange="readURL(this);" id="photo" name="photo"/>  
                <label for="photo">Select profile picture<br/><small>(only .jpg or .png)</small></label>
               
        </div>
		   </div>
		   <div class="col-md-9">
           
            <div class="col-md-6 pad">
			<span>First Name</span><span class="badge">*</span>
              <input type="text" name="FirstName" onkeypress="return onlyAlphabets(event);" maxlength="100" id="FirstName"  class="form-control" required>
            </div>
             
            <div class="col-md-6 pad"><span>Last Name</span><span class="badge">*</span>
              <input type="text" name="LastName" onkeypress="return onlyAlphabets(event);"  maxlength="100" id="LastName"  class="form-control" required>
            </div>
			 <div class="col-md-6 pad"><span>Father / Husband  Name</span><span class="badge">*</span>
              <input type="text" name="FatherName" onkeypress="return onlyAlphabets(event);" id="FatherName" maxlength="200" 
			  class="form-control" required>
            </div>
			<div class="col-md-6 pad"><span>Date Of Birth</span><span class="badge">*</span>
              <input  id="DateofBirth" required name="DateofBirth"  onkeypress="return false;"  maxlength="10"  onchange="getAge();" class="form-control">
            </div>
 			 
			<div class="col-md-6 pad"><span>Age</span>
              <input type="text"  name="age"  id="age" class="form-control" readonly>
            </div>
            <div class="col-md-6 pad"><span>Contact Number</span><span class="badge">*</span>
              <input type="text" name="ContactNumber" onchange="return getMobileValidation();"  onkeypress="return event.charCode >= 48 && event.charCode <= 57" id="ContactNumber" required  pattern="(.){10,10}" maxlength="10"  class="form-control">
            </div>
            <div class="col-md-6 pad"><span>Email ID</span><span class="badge">*</span>
              <input type="email" name="emailid" id="emailid" required    maxlength="100" class="form-control">
            </div>
            
            <div class="col-md-6 pad"><span>Gender</span><span class="badge">*</span>
              <select id="gender" name="gender" type="text" required class="form-control">
                <option value="-1">Select Gender</option>
			  <?php
                                            if(!empty($Gender))
                                            {
                                                foreach ($Gender as $rl)
                                                {
                                                    ?>
                                                    <option value="<?php echo $rl->ConfigValue ?>"><?php echo $rl->ConfigValue ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
              </select>
            </div>
			
            <div class="col-md-6 pad"><span>Marital Status</span><span class="badge">*</span>
              <select  id="MartialStatus" name="MartialStatus" type="text" required placeholder="Marital status" class="form-control">
                <option value="-1">Select Marital Status</option>
			   <?php
								if(!empty($Martial))
                                            {
                                                foreach ($Martial as $rl)
                                                {
                                                    ?>
                                                    <option value="<?php echo $rl->ConfigValue ?>"><?php echo $rl->ConfigValue ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
              </select>
            </div>
           
  
		  <div class="col-md-6 pad"><span>Blood group</span><span class="badge">*</span>
			<select id="bloodgroup" name="bloodgroup"  required class="form-control">
			  <option value="-1">Select Blood group</option>
      <?php
								if(!empty($BloodGroup))
                                            {
                                                foreach ($BloodGroup as $rl)
                                                {
                                                    ?>
                                                    <option value="<?php echo $rl->ConfigValue ?>"><?php echo $rl->ConfigValue ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
			 </select>
		  </div>
  </div>
</div>
		  
         

<!-- Address Section -->
          <!-- Form Name -->
          <legend>Address Details</legend>
          <!-- Text input-->
          <div class="form-group">
            <div class="col-md-12"><span>Current Address</span><span class="badge">*</span>
              <input type="text" id="currentaddress" required name="currentaddress" maxlength="500"    class="form-control">
            </div>
          </div>
		   <div class="form-group">
                <div class="col-md-10">
                  <input type="checkbox" id="checksame" name="sameaddress" onclick="CheckClick">   Current address same as permanent address
                </div>                
          </div>
          <!-- Text input-->
          <div class="form-group">
            <div class="col-md-12"><span>Permanent Address</span><span class="badge">*</span>
              <input type="text" id="permanentaddress" required name="permanentaddress"  maxlength="500"   class="form-control">
            </div>
          </div>
          <!-- Text input-->
          


<!-- Emergency Contact Section -->
          <!-- Form Name -->
          <legend>Emergency Contact Information</legend>
          <!-- Text input-->
          <div class="form-group">
            <div class="col-md-6"><span>Emergency Contact Name</span><span class="badge">*</span>
              <input type="text" id="emergencycontactname" onkeypress="return onlyAlphabets(event);" maxlength="100" required name="emergencycontactname"  class="form-control">
            </div>
            <div class="col-md-6"><span>Emergency Contact Number</span><span class="badge">*</span>
              <input type="text" id="emergencycontactnumber" min_length="5" required name="emergencycontactnumber" onchange="return getValidEmergencyNumber();" onkeypress="return event.charCode >= 48 && event.charCode <= 57" maxlength="10"  class="form-control">
            </div>
             
          </div>
          
		   
<!-- profile Section -->
          <!-- Form Name -->
          <legend>Work Profile</legend>
          <!-- Text input-->
		  
          <div class="form-group">
            <div class="col-md-3"><span>Designation</span>
			 <select type="text" id="desigination" name="desigination"  required class="form-control">
               <option value="-1">Select Designation</option>
      <?php
								if(!empty($Designation))
                                            {
                                                foreach ($Designation as $rl)
                                                {
                                                    ?>
                                                    <option value="<?php echo $rl->ConfigValue ?>"><?php echo $rl->ConfigValue ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
              </select>
             
            </div>
            <div class="col-md-3"><span>Department</span><span class="badge">*</span>
               <select type="text" id="departmentname" name="departmentname" required  class="form-control">               
				 <option value="-1">Select Department</option>
      <?php
								if(!empty($Department))
                                            {
                                                foreach ($Department as $rl)
                                                {
                                                    ?>
                                                    <option value="<?php echo $rl->DEPCode ?>"><?php echo $rl->DEPCode." - " .$rl->DepartmentName ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>				
              </select>
			  
            </div>
            <div class="col-md-3"><span>Date Of Joining</span><span class="badge">*</span>
              <input  id="dateofjoining" name="dateofjoining"   onkeypress="return false;" maxlength="10" required  class="form-control">
            </div>
			<div class="col-md-3"><span>Previous Years of Experience</span>
              <input type="text" id="Previousexperience" name="Previousexperience" maxlength="4" onkeypress="return isNumberKey(event)"  class="form-control">
            </div>
          </div>
		  
		  <div class="form-group">
            <div class="col-md-3"><span>Qualification</span><span class="badge">*</span>
              <select type="text"  id="eduqualifaction" name="eduqualifaction" required class="form-control">
               <option value="-1">Select Qualification</option>
      <?php
								if(!empty($Qualification))
                                            {
                                                foreach ($Qualification as $rl)
                                                {
                                                    ?>
                                                    <option value="<?php echo $rl->ConfigValue ?>"><?php echo $rl->ConfigValue ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
              </select>
			  
            </div>
            <div class="col-md-3"><span>Additional Qualification</span>
              <input type="text" id="addqualification" name="addqualification" maxlength="100"  class="form-control">
            </div>
            <div class="col-md-3"><span>Referred By</span>
              <input type="text" id="referredby" onkeypress="return onlyAlphabets(event);" name="referredby" maxlength="100" class="form-control">
            </div>
			<div class="col-md-3"><span>Referrer Contact Number</span>
              <input type="text" id="referrercontno" name="referrercontno" onchange=" return getValidReferNumber();"
		 maxlength="10" onkeypress="return event.charCode >= 48 && event.charCode <= 57"  class="form-control">
            </div>
          </div>
          
          <legend>Bank Details</legend>
          <!-- Text input-->
		  
          <div class="form-group">
            <div class="col-md-3"><span>Account Number</span>
              <input type="text" id="accountno" onkeypress="return event.charCode >= 48 && event.charCode <= 57" maxlength="20"  name="accountno" class="form-control">
            </div>
            <div class="col-md-3"><span>IFSC Code</span> 
              <input type="text" id="ifsccode" name="ifsccode" maxlength="12" class="form-control">
            </div>
            <div class="col-md-3"><span>Bank Branch Name</span> 
              <input type="text" id="bankbranchname" maxlength="200" name="bankbranchname"  class="form-control">
            </div>
			<div class="col-md-3"><span>Bank Address</span> 
              <input type="text" id="bankaddress" maxlength="200" name="bankaddress"  class="form-control">
            </div>
          </div>
		  
		   <legend>ID Proof</legend>
          <!-- Text input-->
		  
          <div class="form-group">
            <div class="col-md-3"><span>Aadhar Number</span> 
              <input type="text" id="aadharno" name="aadharno" maxlength="12"   class="form-control">
            </div>
            <div class="col-md-3"><span>PAN Number</span> 
              <input type="text" id="panno"  maxlength="10"  name="panno"  onchange="validatePAN();" class="form-control">
            </div>
            <div class="col-md-3"><span>Passport Number</span>
               <input type="text" id="passportno"  maxlength="8" onchange="ValidatePassport();" name="passportno" class="form-control">
            </div>
			<div class="col-md-3"><span>Valid Till</span>
               <input  id="ValidTill" name="ValidTill"  onkeypress="return false;"  maxlength="10"  class="form-control">
            </div>
          </div>
		  
		  		  
		  <!-- Command -->

          <div class="form-group">
            <div class="col-md-3 col-md-offset-9">
              <div class="pull-right">
               <input type="reset" id="reset" onclick="resetphoto();"  class="btn btn-info" value="Reset" />
                <input type="submit" onclick="validate();"   class="btn btn-primary">
              </div>
            </div>
          </div>
        </fieldset>
      </form>
    </div><!-- /.col-lg-12 -->
</div><!-- /.row -->
 				 
                    </form>
                </div>
            </div>
            <div class="col-md-4">
                <?php
                    $this->load->helper('form');
                    $error = $this->session->flashdata('error');
                    if($error)
                    {
                ?>
                <div class="alert alert-danger alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('error'); ?>                    
                </div>
                <?php } ?>
                <?php  
                    $success = $this->session->flashdata('success');
                    if($success)
                    {
                ?>
                <div class="alert alert-success alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('success'); ?>
                </div>
                <?php } ?>
                
                <div class="row">
                    <div class="col-md-12">
                        <?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
                    </div>
                </div>
            </div>
        </div>    
    </section>
    
</div>

<script src="<?php echo base_url(); ?>assets/js/addUser.js" type="text/javascript"></script>
<script>
function Validate()
{
     if($("#FirstName").val().length < 1)
	 {
		 alert('Please Enter  FirstName');
		return false;
	 }
	 if($("#LastName").val().length < 1)
	 {
		 alert('Please Enter  LastName');
		return false;
	 }
	 if($("#FatherName").val().length < 1)
	 {
		 alert('Please Enter  FatherName');
		return false;
	 }
	 if($("#DateofBirth").val().length < 1)
	 {
		 alert('Please Enter  Date of Birth');
		return false;
	 }
	 if ( $('#ContactNumber').val().length < 1 )
	 {
		 alert('Please Enter  Contact Number');
		return false;
	 }
	 else if(!getMobileValidation())
	 { return false; }
		 
	 
	
	
	 if($("#emailid").val().length < 1)
	 {
		 alert('Please Enter  Email ID');
		return false;
	 }
	 else if(!validateEmail()) 
	 {
		 return false;
	 }
	 
	
	if($("option:selected", $("#gender")).val() == '-1')
	{
		alert('Please Select Gender');
		return false;
	}
	
	if($("option:selected", $("#MartialStatus")).val() == "-1")
	{
		alert('Please Select Martial Status');
		return false;
	}
	
	if($("option:selected", $("#bloodgroup")).val() == "-1")
	{
		alert('Please Select Blood group ');
		return false;
	}
	 if($("#currentaddress").val().length < 1)
	 {
		 alert('Please Enter  Current Address');
		return false;
	 }
	 if($("#permanentaddress").val().length < 1)
	 {
		 alert('Please Enter  Permanent Address');
		return false;
	 }
	 if($("#emergencycontactname").val().length < 1)
	 {
		 alert('Please Enter  Emergency Contact Name');
		return false;
	 }
	 if($("#emergencycontactnumber").val().length < 1)
	 {
		 alert('Please Enter  Emergency Contact Number');
		return false;
	 }
	 else if(!getValidEmergencyNumber())
	 { return false;}
	
	
	if($("option:selected", $("#desigination")).val() == "-1")
	{
		alert('Please Select Desigination ');
		return false;
	}
	if($("option:selected", $("#departmentname")).val() == "-1")
	{
		alert('Please Select Department name');
		return false;
	}
	if($("option:selected", $("#eduqualifaction")).val() == "-1")
	{
		alert('Please Select Qualification');
		return false;
	}
		
	if($("#referrercontno").val().length > 0)
	 {	
		getValidReferNumber();
	 }	
	
	if($("#passportno").val().length > 1)
	 {
		 ValidatePassport();	
		
	 }
	
}
 $("#emailid").change(function () {
   
    var id = $('#emailid').val();
		if(validateEmail())
		{
		 $.ajax({
			data:{id:id},
			
			type:"POST",
			url:"<?php echo base_url();?>employeedetails/CheckEmail",
			success:function(data) {
				if(data)
			{
								
				var answer = confirm(data+""+" Employee already exists in the database.Do you want to change the Email id ?")
				if (answer) {        
	                $('#emailid').val('');
					$('#emailid').focus();
	             	}
			else 
				{
				    window.location = 'employeedetails/employeeListing';	
				}
				     
			}						
			
		}
		
		});	
		}
  
});
</script>