function ValidateEmail(emailID){
   var emailReg = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;

   if (!emailReg.test(emailID)) {
        $("#emailErr").removeClass('text-success');   
        $("#emailErr").addClass('text-danger');   
        $("#emailErr").html("Please enter valid email ID.");
        $("#btnAddCompany").attr("disabled", true);
        return false;
    }else{
        $("#emailErr").removeClass('text-danger');   
        $("#emailErr").addClass('text-success');   
        $("#emailErr").html("Valid email ID!");
        $("#btnAddCompany").attr("disabled", false);
        return true;
    }
}

document.getElementById("input").addEventListener('keydown', function (e) {
    if (this.value.length === 0 && e.which === 32) e.preventDefault();
});

function whitspace(input){
    if(/^\s/.test(input.value))
      input.value = '';
}

function myFunction() {
    var x = document.getElementById("password");
    if (x.type === "password") {
      x.type = "text";
    } else {
      x.type = "password";
    }
}

function getBADATA(id){
  $.ajax({
    type: "post",
    url:   base_url+"master/get_ba_data",
    data: {ba_id:id},
    success: function (response) {
        var result = JSON.parse(response);
        $("#order_contact").val(result['ba_mobile']);
    }
  });
}

function scrollBottom(){
  window.scrollTo(0, document.body.scrollHeight);
}

function get_project_name(id)
{
  console.log("sss");
  $.ajax({
    type: "post",
    url:   base_url+"master/get_project_name",
    data: {id:id},
    success: function (response) {
        var result = JSON.parse(response);
        console.log(result);
        $("#gst_no").val(result['customer']['gst_no']);

        $('#project_name').html('<option value="">Select Project Name</option>'); 
        if(result['project'] !=''){
          $(result['project']).each(function(){
              var option = $('<option />');
              option.attr('value', this.id).text(this.project_name);           
              $('#project_name').append(option);
          });

      }else{
          $('#project_name').html('<option value="">Project Not Available</option>');
      }
    }
  });
}


function CustomerName(cust_name){
    var field_name = 'customer_name';
    $.ajax({
      type: "post",
      url:   base_url+"customermanage/get_cust_name",
      data: {field_name:field_name,field_value:cust_name},
      success: function (res) {
        
        if (res == 1) {
              swal({
                title:'Customer is already added !',
                width: 600,
                type: 'error',
                confirmButtonColor: '#57a94f'
            });
        }else{
            console.log('new customer');
        }
      }
    });
}

function CustomerGstCheck(gst_no){
  var field_name = 'gst_no';
  $.ajax({
    type: "post",
    url:   base_url+"customermanage/get_cust_name",
    data: {field_name:field_name,field_value:gst_no},
    success: function (res) {
      if (res == 1) {
            swal({
              title:'Customer Gst No. is already added !',
              width: 600,
              type: 'error',
              confirmButtonColor: '#57a94f'
          });
      }else{
          console.log('new customer');
      }
    }
  });
}

