$(document).ready(function(){
 
  
/*CREATE MODEL COMPANY NAME*/
  
  $('.cname').on('keyup',function(){

   var error_name = '';

   var company_name = $('.cname').val();

   

    if(company_name==""){

      $('#cnameblock').removeClass("hide");     

      $('#cnameblock').css("color","red");

      $('#cnameblock').text('Enter Company Name !!!!');

      $('.submit').attr('disabled', 'disabled');

    }
    
   else{

    $.ajaxSetup({

      headers: {
 
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
 
      }
 
      });
 
     
 
      $.ajax({ 
         url:url_companyvalidation,
 
         method:"POST",
 
         data:{company_name:company_name},
 
         success:function(result)
 
         {
 
            if(result == 'not_unique')
 
            {
 
              $('#cnameblock').removeClass("hide");     

              $('#cnameblock').css("color","red");
        
              $('#cnameblock').text('Company Name is not available !!!!');

              $('.submit').attr('disabled', 'disabled');  
 
            }
 
            else
 
            {
 
              $('#cnameblock').addClass("hide");      
 
              $('.submit').attr('disabled', false);

            }
 
          }
 
         })
 
     }

   
  });

/*CREATE MODEL COMPANY EMAIL*/
  
  $('.cemail').on('keyup',function(){
  
    var company_emailid = $('.cemail').val();

    var filter = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
    if(company_emailid==""){
       
      $('#cemailblock').removeClass("hide");
      
      $('#cemailblock').css("color","red");    
      
      $('#cemailblock').text('Enter Email Address !!!');

      $('.submit').attr('disabled', 'disabled');

    }
    
    else if(!filter.test(company_emailid))
    
    {
       $('#cemailblock').removeClass("hide");

       $('#cemailblock').css("color","red");     
  
       $('#cemailblock').text('Invalid Email Address !!!');

       $('.submit').attr('disabled', 'disabled');

    }

    else{

      $.ajaxSetup({

        headers: {
   
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
   
        }
   
        });
   
       
   
        $.ajax({ 
           url:url_companyvalidation,
   
           method:"POST",
   
           data:{company_emailid:company_emailid},
   
           success:function(result)
   
           {
   
              if(result == 'not_unique')
   
              {
   
                $('#cemailblock').removeClass("hide");
               
                $('#cemailblock').css("color","red");     
           
                $('#cemailblock').text('Email id is already used !!!');

                $('.submit').attr('disabled', 'disabled');
   
              }
   
              else
   
              {
                $('#cemailblock').addClass("hide");
                
                $('.submit').attr('disabled', false);
              
              }
   
            }
   
           })
   
       
   
    }

  
  });

/*CREATE MODEL COMPANY GST NUMBER*/
  
  $('.cgstin').on('keyup',function(){

    var company_gstin = $('.cgstin').val();

    var filter = /^([0-9]){2}([A-Z]){5}([0-9]){4}([A-Z]){1}([A-Z0-9]){1}([Z]){1}([A-Z0-9]){1}?$/;

    if(company_gstin==""){
      
      $('#cgstinblock').removeClass("hide");
      
      $('#cgstinblock').css("color","red");
      
      $('#cgstinblock').text('Enter GST Number !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else if(!filter.test(company_gstin)&&company_gstin!="URP")

    {
      
      $('#cgstinblock').removeClass("hide");
      
      $('#cgstinblock').css("color","red");
      
      $('#cgstinblock').text('Invalid GST Number !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else{

      console.log("here!!!!");

      $.ajaxSetup({

        headers: {
   
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
   
        }
   
        });
   
       
   
        $.ajax({ 
           url:url_companyvalidation,
   
           method:"POST",
   
           data:{company_gstin:company_gstin},
   
           success:function(result)
   
           {
             
   
              if(result == 'not_unique')
   
              {
   
                $('#cgstinblock').removeClass("hide");
      
                $('#cgstinblock').css("color","red");
                
                $('#cgstinblock').text('GST Number is already used !!!');

                $('.submit').attr('disabled', 'disabled');
   
              }
   
              else
   
              {

                $('#cgstinblock').addClass("hide");

                $('.submit').attr('disabled', false);
    
              }
   
            }
   
           })

    }

  
  });

/*CREATE MODEL COMPANY CODE*/

  $('.ccode').on('keyup',function(){

    var company_code = $('.ccode').val();

    if(company_code==""){
      
      $('#ccodeblock').removeClass("hide");
      
      $('#ccodeblock').css("color","red");
      
      $('#ccodeblock').text('Enter Company Code !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else{

      $.ajaxSetup({

        headers: {
   
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
   
        }
   
        });
   
       
   
        $.ajax({ 
           url:url_companyvalidation,
   
           method:"POST",
   
           data:{company_code:company_code},
   
           success:function(result)
   
           {
   
              if(result == 'not_unique')
   
              {
   
                $('#ccodeblock').removeClass("hide");
      
                $('#ccodeblock').css("color","red");
                
                $('#ccodeblock').text('Company Code is already used !!!');

                $('.submit').attr('disabled', 'disabled');
   
              }
   
              else
   
              {

                $('#ccodeblock').addClass("hide");

                $('.submit').attr('disabled', false);
    
              }
   
            }
   
           })

    }

  
  });

/*CREATE MODEL COMPANY ALTERNATE EMAIL*/
 
  $('#alternate_cemail').on('keyup',function(){

    var Alter_Email=$('#alternate_cemail').val();
    var Email=$('#cemail').val();

    
    var filter = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
    
    if(!filter.test(Alter_Email))      
    {
      $('#alternate_cemailblock').removeClass("hide");
    
      $('#alternate_cemailblock').css("color","red");
    
      $('#alternate_cemailblock').text('Enter valid alternate email id !!!');

      $('.submit').attr('disabled', 'disabled');
      
    }
    else if(Alter_Email==Email)
    {
      $('#alternate_cemailblock').removeClass("hide");
    
      $('#alternate_cemailblock').css("color","red");
    
      $('#alternate_cemailblock').text('Both email id and alternate Email is equal !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else
    {
      
      $.ajaxSetup({

        headers: {
 
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
 
        }
 
      });
    
      $.ajax({ 
         url:url_companyvalidation,
 
         method:"POST",
 
         data:{Alter_Email:Alter_Email},
         
        success:function(result)
        {
          
          console.log(result);
          if(result == 'not_unique')
          {

            $('#alternate_cemailblock').removeClass("hide");
  
            $('#alternate_cemailblock').css("color","red");
            
            $('#alternate_cemailblock').text('Email ID is already used !!!');

            $('.submit').attr('disabled', 'disabled');

          }

          else

          {

            $('#alternate_cemailblock').addClass("hide");

            $('.submit').attr('disabled', false);

          }

        }
      
      });

    }

  });

/*CREATE MODEL COMPANY BILLING ADDRESS*/
  
    /*CREATE MODEL COMPANY BILLING ADDRESS LINE 1*/

    $('#billaddline1').on('keyup',function(){

    var bill_street1 = $('#billaddline1').val();

    if(bill_street1==""){
      
      $('#bill_aadline1block').removeClass("hide");
      
      $('#bill_aadline1block').css("color","red");
      
      $('#bill_aadline1block').text('Enter address !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else{

      $('#bill_aadline1block').addClass("hide");

      $('.submit').attr('disabled', false);

    }

  
    });

    /*CREATE MODEL COMPANY BILLING ADDRESS LINE 2*/

    $('#billaddline2').on('keyup',function(){

    var bill_street2 = $('#billaddline2').val();

    if(bill_street2==""){
      
      $('#bill_aadline2block').removeClass("hide");
      
      $('#bill_aadline2block').css("color","red");
      
      $('#bill_aadline2block').text('Enter address !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else{

      $('#bill_aadline2block').addClass("hide");

      $('.submit').attr('disabled', false);

    }

  
    });

    /*CREATE MODEL COMPANY BILLING PINCODE*/
   
    $('#Pincode').on('keyup',function(){

      var bill_pincode = $('#Pincode').val();

      var filter = /^[1-9][0-9]{5}$/;

      if(bill_pincode==""){
        
        $('#bill_pincodeblock').removeClass("hide");
        
        $('#bill_pincodeblock').css("color","red");
        
        $('#bill_pincodeblock').text('Enter Pincode!!!');

        $('.submit').attr('disabled', 'disabled');

      }

      else if(!filter.test(bill_pincode))

      {
        
        $('#bill_pincodeblock').removeClass("hide");
        
        $('#bill_pincodeblock').css("color","red");
        
        $('#bill_pincodeblock').text('Invalid Pincode !!!');

        $('.submit').attr('disabled', 'disabled');

      }

      else{

        $('#bill_pincodeblock').addClass("hide");

        $('.submit').attr('disabled', false);

      }

    
    });

    /*CREATE MODEL COMPANY BILLING PINCODE*/
    
    $('#billmobile').on('keyup',function(){

      var company_mobile = $('#billmobile').val();

      var filter = /^([0-9]){1}([0-9]){15}?$/;

      if(company_mobile==""){
        
        $('.billmobileblock').removeClass("hide");
        
        $('.billmobileblock').css("color","red");
        
        $('.billmobileblock').text('Enter Mobile Number !!!');

        $('.submit').attr('disabled', 'disabled');

      }

      /*else if(!filter.test(company_mobile))

      {
        
        $('.billmobileblock').removeClass("hide");
        
        $('.billmobileblock').css("color","red");
        
        $('.billmobileblock').text('Invalid Mobile Number !!!');

        $('.submit').attr('disabled', 'disabled');

      }*/


      else{

        $('.billmobileblock').addClass("hide");

        $('.submit').attr('disabled', false);

      }

    
    });

/*CREATE MODEL COMPANY SHIPPING ADDRESS*/


  /*CREATE MODEL COMPANY SHIPPING ADDRESS LINE 1*/  

    $('#shipaddline1').on('keyup',function(){

      var ship_street1 = $('#shipaddline1').val();
      

      if(ship_street1==""){
          
        $('#ship_add1block').removeClass("hide");
        
        $('#ship_add1block').css("color","red");
        
        $('#ship_add1block').text('Enter address !!!');

        $('.submit').attr('disabled', 'disabled');

      }

      else{

        $('#ship_add1block').addClass("hide");

        $('.submit').attr('disabled', false);

      }

    });
  
  /*CREATE MODEL COMPANY SHIPPING ADDRESS LINE 2*/

    $('#shipaddline2').on('keyup',function(){

      var ship_street2 = $('#shipaddline2').val();
      

      if(ship_street2==""){
          
        $('#ship_add2block').removeClass("hide");
        
        $('#ship_add2block').css("color","red");
        
        $('#ship_add2block').text('Enter address !!!');

        $('.submit').attr('disabled', 'disabled');

      }

      else{

        $('#ship_add2block').addClass("hide");

        $('.submit').attr('disabled', false);

      }

    });

  /*CREATE MODEL COMPANY SHIPPING ADDRESS PINCODE*/

    $('#ShipToPincode').on('keyup',function(){
    
      var bill_pincode = $('#ShipToPincode').val();

      var filter = /^[1-9][0-9]{5}$/;

      if(bill_pincode==""){
          
        $('#ShipToPincodeblock').removeClass("hide");
          
        $('#ShipToPincodeblock').css("color","red");
          
        $('#ShipToPincodeblock').text('Enter Pincode!!!');

        $('.submit').attr('disabled', 'disabled');

      }

      else if(!filter.test(bill_pincode))

      {
          
        $('#ShipToPincodeblock').removeClass("hide");
          
        $('#ShipToPincodeblock').css("color","red");
          
        $('#ShipToPincodeblock').text('Invalid Pincode !!!');

        $('.submit').attr('disabled', 'disabled');

      }

      else{

        $('#ShipToPincodeblock').addClass("hide");

        $('.submit').attr('disabled', false);

      }


    });

  /*CREATE MODEL COMPANY SHIPPING ADDRESS MOBILE*/

  $('#ShipToMobile').on('keyup',function(){

    var company_mobile = $('#ShipToMobile').val();

    var filter = /^([6-9]){1}([0-9]){9}?$/;

    if(company_mobile==""){
      
      $('#ShipToMobileblock').removeClass("hide");
      
      $('#ShipToMobileblock').css("color","red");
      
      $('#ShipToMobileblock').text('Enter Mobile Number !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    // else if(!filter.test(company_mobile))

    // {
      
    //   $('#ShipToMobileblock').removeClass("hide");
      
    //   $('#ShipToMobileblock').css("color","red");
      
    //   $('#ShipToMobileblock').text('Invalid Mobile Number !!!');

    //   $('.submit').attr('disabled', 'disabled');

    // }


    else{

      $('#ShipToMobileblock').addClass("hide");

      $('.submit').attr('disabled', false);

    }

  
  });

  /*CREATE MODEL COMPANY SHIPPING ADDRESS RECEIVER NAME*/

    $('#receiver_name').on('keyup',function(){

      var receiver_name = $('#receiver_name').val();

      if(receiver_name==""){
        
        $('#receiver_nameblock').removeClass("hide");
        
        $('#receiver_nameblock').css("color","red");
        
        $('#receiver_nameblock').text('Enter Receiver Name !!!');

        $('.submit').attr('disabled', 'disabled');

      }

      else{

        $('#receiver_nameblock').addClass("hide");

        $('.submit').attr('disabled', false);

      }

    
    });


 



    
  
    $('#editbilladdline1').on('keyup',function(){

      var bill_street1 = $('#editbilladdline1').val();
  
      if(bill_street1==""){
        
        $('#Editbill_streetblock1').removeClass("hide");
        
        $('#Editbill_streetblock1').css("color","red");
        
        $('#Editbill_streetblock1').text('Enter address !!!');
  
        $('.submit').attr('disabled', 'disabled');
  
      }
  
      else{
  
        $('#Editbill_streetblock1').addClass("hide");
  
        $('.submit').attr('disabled', false);
  
      }
  
    
    });
  
  /*CREATE MODEL COMPANY SHIPPING ADDRESS LINE 1*/
    
    $('#editbilladdline2').on('keyup',function(){

      var bill_street1 = $('#editbilladdline2').val();
  
      if(bill_street1==""){
        
        $('#Editbill_streetblock2').removeClass("hide");
        
        $('#Editbill_streetblock2').css("color","red");
        
        $('#Editbill_streetblock2').text('Enter address !!!');
  
        $('.submit').attr('disabled', 'disabled');
  
      }
  
      else{
  
        $('#Editbill_streetblock2').addClass("hide");
  
        $('.submit').attr('disabled', false);
  
      }
  
    
    });

  /*CREATE MODEL COMPANY SHIPPING ADDRESS LINE 1*/

    $('.editbillpincode').on('keyup',function(){

    var bill_pincode = $('.editbillpincode').val();

    var filter = /^[1-9][0-9]{5}$/;

    if(bill_pincode==""){
      
      $('#Editbill_pincodeblock').removeClass("hide");
      
      $('#Editbill_pincodeblock').css("color","red");
      
      $('#Editbill_pincodeblock').text('Enter Pincode!!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else if(!filter.test(bill_pincode))

    {
      
      $('#Editbill_pincodeblock').removeClass("hide");
      
      $('#Editbill_pincodeblock').css("color","red");
      
      $('#Editbill_pincodeblock').text('Invalid Pincode !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else{

      $('#Editbill_pincodeblock').addClass("hide");

      $('.submit').attr('disabled', false);

    }

  
    });

  /*CREATE MODEL COMPANY SHIPPING ADDRESS LINE 1*/
  
    $('.editshipmobile').on('keyup',function(){

    var company_mobile = $('.editbillmobile').val();

    var filter = /^([6-9]){1}([0-9]){9}?$/;

    if(company_mobile==""){
      
      $('#editmobileblock').removeClass("hide");
      
      $('#editmobileblock').css("color","red");
      
      $('#editmobileblock').text('Enter Mobile Number !!!');

      $('.submit').attr('disabled', 'disabled');

    }

    else if(!filter.test(company_mobile))

    {
      
      $('#editmobileblock').removeClass("hide");
      
      $('#editmobileblock').css("color","red");
      
      $('#editmobileblock').text('Invalid Mobile Number !!!');

      $('.submit').attr('disabled', 'disabled');

    }


    else{

      $('#editmobileblock').addClass("hide");

      $('.submit').attr('disabled', false);

    }

  
    });

  /*CREATE MODEL COMPANY SHIPPING ADDRESS LINE 1*/

    $('#receiver_name').on('keyup',function(){

      var receiver_name = $('#receiver_name').val();
  
      if(receiver_name==""){
        
        $('#receiver_nameblock').removeClass("hide");
        
        $('#receiver_nameblock').css("color","red");
        
        $('#receiver_nameblock').text('Enter Receiver Name !!!');
  
        $('.submit').attr('disabled', 'disabled');
  
      }
  
      else{
  
        $('#receiver_nameblock').addClass("hide");
  
        $('.submit').attr('disabled', false);
  
      }
  
    
    });


});




