 <script>

//Email Validate
function validateEmail() {
 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
          
			var email = $('#EmailAddress').val();
			if(email != "")
			{
            if (reg.test(email) == false) 
            {
                alert('Please Enter Valid Email Address');
                return (false);
            }
			else
			{
				return true;
			}
			}
}  
   

 
  
 

  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;
				}
			}
			else
			{
				alert('Please Enter PAN Number');
				return (false);
			}
			
}
function validateECCNumber() {
 var reg = /(?=.*[A-Za-z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Za-z]).{1,}(?=.*[A-Za-z]).{2,}(?=.*[0-9]).{3,}$/;
          
			var ECC = $('#Exciseregistration').val();
			
			if(ECC != '')
			{
				if (reg.test(ECC) == false) 
				{
					alert('Please Enter Valid Excise Control Code Number');
					return (false);
				}
				else
				{
					return true;
				}
			}
			
}
function getContactNumberValidation() {
	var contactNumber = $('#ContactNumber').val().length;
	if(contactNumber < 10)
	{
		alert('Please Enter valid Contact Number');
		return false;
	}
	else
	{
		return true;
	}
}
function getValidAlternateNumber() 
{
	var contactNumber = $('#AlternateContactNumber').val().length;
	if(!empty($('#AlternateContactNumber').val()))
	{
		if(contactNumber < 10)
		{
			alert('Please Enter valid Alternate 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 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;
    }
	 
$(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;
	
	 $("#dateofCST").datepicker({
	//minDate : new Date(year-30,1,1),
	maxDate :'now',
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '-100:+0'

});
});
</script>

 <style>
 legend{
 color:#00c0ef ! important;
 } 
 
   .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 -  New Supplier Details</center>
       
      </h1>
	  	  
    </section>
    
    <section class="content">
    <div style="text-align:right;">
    <a href="<?php echo base_url() ?>supplierListing" class="btn btn-primary" value="Back"/>Back</a>
	</div>
	<br/>
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
              <!-- general form elements -->
                               
                
                <div class="box box-primary">
                     
                <!-- form start -->
                    
   
    <div class="row">
    <div class="col-md-10 col-md-offset-1"   style="border:3px solid #3c8dbc;">
      <form class="form-horizontal" role="form" id="addsupplier" action="<?php echo base_url() ?>addNewsupplier" method="post" role="form">
        <fieldset>
		 
          <!-- Form Name -->
          <legend>Supplier Information</legend> 
      		        
            <div class="col-md-3 pad">
			<span for="SupplierName">Supplier Name</span><span class="badge">*</span>
            <input type="text" name="SupplierName" onkeypress="return onlyAlphabets(event);" maxlength="100" id="supplierName"  class="form-control" required>
			
            </div>
             
            <div class="col-md-3 pad">
				<span for="ContactNumber">Contact Number</span><span class="badge">*</span>             
				<input type="text" name="ContactNumber" onchange="return getContactNumberValidation();"  onkeypress="return event.charCode >= 48 && event.charCode <= 57" id="ContactNumber" required pattern="(.){10,10}" maxlength="10"  class="form-control" title="Please Enter 10 digit Number">
            </div>
			
			<div class="col-md-3 pad"> 
				<span for="AlternateContactNumber">Alternate Contact Number</span>
				<input type="text" name="AlternateContactNumber" onchange="return getValidAlternateNumber();"  onkeypress="return event.charCode >= 48 && event.charCode <= 57" id="AlternateContactNumber"  pattern="(.){10,10}" maxlength="10"  class="form-control" title="Please Enter 10 digit Number">
            </div>
			
			<div class="col-md-3 pad">
				<span for="EmailAddress">Email ID</span><span class="badge">*</span>
				<input type="email" name="emailid" id="emailid" required  maxlength="100" class="form-control">
            </div>
             

<!-- Address Section -->
          <!-- Form Name -->
          <legend>Address Details</legend>
          <!-- Text input-->
          
            <div class="col-md-12"><span for="Address2">Address</span><span class="badge">*</span>
                <input type="text" class="form-control required" id="Address" name="Address" maxlength="500" required>
            </div>
      
 
          
  
          
          <legend>Tax Related Data</legend>
          <!-- Text input-->
		           
		    <div class="col-md-3 pad">
			   <span for="PAN">PAN</span> <span class="badge">*</span>
                <input type="text" id="panno"  maxlength="10" pattern="(?=.*[A-Za-z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Za-z]).{1,}" style="text-transform:uppercase;"  name="panno" required  onchange="validatePAN();" class="form-control" title="Please Enter 5 Character and 4 digit numbers and 1 Character format">
		    </div>
			 <div class="col-md-3 pad">
			<span for="TIN">TIN</span><span class="badge">*</span>
                <input type="text"  class="form-control required" pattern="(.){11,11}"  id="TIN" name="TIN" minlength="11" maxlength="11" onkeypress="return event.charCode >= 48 && event.charCode <= 57" required   title="Please Enter 11 digit Number">
            </div>	
			<div class="col-md-3 pad">			
			    <span for="UANumber">UA Number</span>
                <input type="text"  class="form-control" pattern="^\d{12}$" id="UANumber" name="UANumber" maxlength="12" title="Please Enter 12 digit Number" >
            </div>
			
            <div class="col-md-3 pad">			
			<span for="Exciseregistration">Excise Registration</span>
                <input type="text"  class="form-control required"  onchange="validateECCNumber();" id="Exciseregistration" name="Exciseregistration" minlength="15" maxlength="15" pattern="(?=.*[A-Za-z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Za-z]).{1,}(?=.*[A-Za-z]).{2,}(?=.*[0-9]).{3,}" title="Please enter PAN Number and EM/ED option and 3 digit Numbers format" style="text-transform:uppercase;">
            </div>
			
		 
		  <div class="col-md-3 pad">
			<span for="GSTNo">CST Number</span>
                <input type="text"  class="form-control " id="CSTNo"  name="CSTNo" maxlength="15">
            </div>
			 <div class="col-md-3 pad"><span>CST Registration Date</span>
              <input  id="dateofCST" name="dateofCST"   onkeypress="return false;" maxlength="10"   class="form-control">
            </div>
		 
		  
            <div class="col-md-3 pad">
			<span for="GSTNo">GST Number</span>
                <input type="text"  class="form-control " id="GSTNo"  name="GSTNo" maxlength="10">
            </div>
			
			<div class="col-md-3 pad">
			<span for="Range">GST Range</span>
                <input type="text"  class="form-control " id="GSTRange"   name="GSTRange" maxlength="10">
            </div>
			<!-- Text input-->
        
            <div class="col-md-6 pad"><span for="CollectrateAddress">Collectrate Address</span>
            <input type="text"  class="form-control " id="CollectrateAddress"  name="CollectrateAddress" maxlength="500" >
            </div>
        
          <!-- Text input-->
         
		  
		   <legend>Payment Details</legend>
          <!-- Text input-->
		  
       
            <div class="col-md-3">
			    <span for="payablefrom">Payable Terms</span>
				    <select class="form-control required" id="PaymentTerms" name="PaymentTerms">
					    <option value="Date of invoice" >Select Payment method</option>
							<?php
							if(!empty($payment))
							{
								foreach ($payment as $rl)
								{
									?>
									<option value="<?php echo $rl->ConfigValue ?>"><?php echo $rl->ConfigValue ?></option>
									<?php
								}
							}
							?>
					</select>
            </div>
			
            <div class="col-md-3">
			  <span for="PayableAT">Payable AT</span>
              <input type="text"   class="form-control required" id="PayableAT" name="PayableAT">	 
            </div>
			
            <div class="col-md-3"><span>Payment Date</span><br/>
				<label class="radio-inline"><input type="radio" name="Payment"  value="Before">Before</label>
				<label class="radio-inline"><input type="radio" name="Payment" value="After">After</label>
            </div>
			 
  
	   

          <div class="form-group">
            <div class="col-md-3 col-md-offset-9">
              <div class="pull-right">
               <input type="reset" id="reset"  class="btn btn-info" value="Reset" />
                <input type="submit" onclick="return Validate();" class="btn btn-primary">
              </div>
            </div>
          </div>
        </fieldset>
      </form>
    </div><!-- /.col-lg-12 -->
</div><!-- /.row -->
    
                        
                     
                </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>
function Validate()
{
	if(!validatePAN())
	{
		
		$('#panno').focus();
                return false;
	}
if(!validateEmail())
{
  $('#emailid').focus();
   return false;  
}
}

//Call to ajax existing PAN
 $('#panno').change(function() {
    
 var id = $('#panno').val();
		if(id != '')
		{
		 $.ajax({
			data:{id:id},
			
			type:"POST",
			url:"<?php echo base_url();?>supplier/checkPAN",
			success:function(data) {
				if(data)
			{
				
			var answer = confirm(data + " " +" supplier details is already exists in the database.Do you want to change the SUPPLIER details?")
				if (answer) 
{                                      
	                                $('#panno').val('');

					$('#panno').focus();
                                           return false; 
	             	          }
			         else 
				{
					alert('Please edit the supplier details in the Edit screen and change the supplier status to Active');
				        window.location = 'supplier/supplierListing';	
				}					
			
		      }
			}
		
		});	
		}
		else
		{
			alert('Please enter the PAN Number');
			$('#panno').focus();
                        return false;
		}
  
});
</script>
