<?php
$this->load->view('project_footer');
//echo '<pre>'; print_r($this->uri->segments);print_r($this->uri->rsegments);
?>
<!--SCRIPT FILES-->
<script src="<?php echo theme_url(); ?>js/bootstrap.js" type="text/javascript"></script>
<?php //if($_SERVER['REQUEST_URI']!='/'){ ?>
<!--<script src="<?php echo theme_url(); ?>js/materialize.min.js" type="text/javascript"></script>-->
<?php // } ?>
<script src="<?php echo theme_url(); ?>js/custom.js"></script>
<script type="text/javascript">

  function validateEmail($email) {
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    return emailReg.test($email);
  }

  //check if user is from india
  jQuery('#register_country').change(function () {
    if (jQuery(this).val() == 'India') {
      jQuery('.registerMobileDiv').show();
      jQuery('.registerEmailDiv').hide();
    } else {
      jQuery('.registerMobileDiv').hide();
      jQuery('.registerEmailDiv').show();
    }
  });

  //Form Validation for mobile no
  jQuery('#registerMobileNo').keyup(function () {
    if (jQuery(this).val().length < 10)
      jQuery('#otpInputBox').hide(0);
    jQuery("#regis-ter .createAccountbutton").show();
    jQuery(".verifyOtpButton").hide();
    jQuery('.otpVerifyText').hide();
    jQuery('.otpSMSText').show();
  });
  jQuery('.pop-btn-rgstr').click(function (e) {
    var fname = jQuery('#regFirstName').val();
    var lname = jQuery('#regLastName').val();
    var compIdVerification = jQuery('.viewCompContact').val();
    var error = '';
    if (fname == '') {
      error += 'Please Enter your First Name.';
    }
    if (lname == '') {
      error += '<br />Please Enter your Last Name.';
    }

    if (error == '') {
      if (jQuery('#register_country').val() == 'India') {
        var alMessage = 'Mobile No. must be of 10 digit.';
        if (jQuery('#registerMobileNo').val().length === 10) {
          var str = jQuery('#registerMobileNo').val();
          var strnew = str.split('');
          jQuery.post(site_url + 'home/send_otp', {mobile: jQuery('#registerMobileNo').val()}, function (response) {
            if (response === 'T') {
              $('.ermgs').html('');
              jQuery('#otpInputBox').show(0);
              jQuery('.otpSMSText').show(0);
              jQuery("#regis-ter .createAccountbutton").hide();
              jQuery(".verifyOtpButton").show();
              jQuery(".pop-btn-rgstr").hide();
            } else {
              $('.ermgs').html(response);
              $('#login_mobile').val(jQuery('#registerMobileNo').val());
              setTimeout(function () {
                $('.registerCloseButton').trigger('click');
              }, 300);
              setTimeout(function () {
                $('#LoginButtonBottomPop').trigger('click');
              }, 900);
            }
          });
        } else
          alert(alMessage);
        jQuery('#otpInputBox').hide(0);
        jQuery("#regis-ter .createAccountbutton").show();
        jQuery(".verifyOtpButton").hide();
        jQuery('.otpVerifyText').hide();
        jQuery('.otpSMSText').show();
      } else {
        if (jQuery('#registerEmailId').val() == '' || !validateEmail(jQuery('#registerEmailId').val())) {
          jQuery('.ermgs').html("Please enter a valid Email ID");
          return false;
        } else {
          jQuery('.ermgs').html('');
          jQuery.post(site_url + 'users/create_user', {email: jQuery('#registerEmailId').val(), firstname: fname, lastname: lname, country : jQuery('#register_country').val(), compIdVerification: compIdVerification}, function (msg) {
            if (msg > 0) {
              jQuery('.sucmgs').html('');
              window.location.href = '<?php echo site_url(); ?>members';
            } else {
              //alert('Hi');
              var myKey = /-/;
              var myStringVar = msg;
              var myMatch = myStringVar.search(myKey);
              if (myMatch != -1) {
                var name = msg.substring(3, 200);
                jQuery('.ermgs').html('Dear ' + name + ', You are already Registered, Please enter Password and Login');
                $('#login_mobile').val(jQuery('#registerEmailId').val());
                setTimeout(function () {
                  $('.registerCloseButton').trigger('click');
                  $('.loginLink').eq(0).trigger('click');
                }, 300);

              } else if (msg == 'V') {
                window.location.reload();
              } else if (msg == 'E') {
                jQuery('.sucmgs').html('Verification Email Sent! Please Verify your Email ID to Login.');
              } else {
                jQuery('.sucmgs').html('');
                alert('Something went wrong, please try again.');
              }
            }
          });
        }
      }
    } else {
      jQuery('.ermgs').html(error);
    }
  }
  );

  //OTP form validation
  jQuery('.pop-btn-otp').click(function () {
    var alMessage = 'Please enter a valid 4 digit OTP sent to your Mobile No.';
    var fname1 = jQuery('#regFirstName').val();
    var lname1 = jQuery('#regLastName').val();
    var compIdVerification = jQuery('.viewCompContact').val();
    if (jQuery('#registerMobileCode').val().length === 4) {
      jQuery.post(site_url + 'home/verify_otp', {mobile: jQuery('#registerMobileNo').val(), otp: jQuery('#registerMobileCode').val()}, function (response) {
        if (response === '1') {
          jQuery.post(site_url + 'users/create_user', {mobile: jQuery('#registerMobileNo').val(), otp: jQuery('#registerMobileCode').val(), firstname: fname1, lastname: lname1, country : jQuery('#register_country').val(), compIdVerification: compIdVerification}, function (msg) {
            if (msg > 0) {
              window.location.href = site_url + 'members';
            } else {
              if (msg == 'V') {
                window.location.reload();
              } else if (msg == 'E') {
                jQuery('.sucmgs').html('Verification Email Sent! Please Verify your Email ID to Login.');
              } else {
                jQuery('.sucmgs').html('');
                alert('Something went wrong, please try again.');
              }
            }
          });
        } else {
          jQuery('.otpVerifyText').show();
          jQuery('.otpSMSText').hide();
        }
      });
    } else {
      alert(alMessage);
    }
  });

  //forget password
  jQuery('.forget-btn').click(function (e) {
    jQuery.post('<?php echo site_url(); ?>home/send_password', {mobile: jQuery('#forgetMobileNo').val()}, function (response) {
      if (response === '1') {
        alert('Your Account Password has been sent to your regstered Mobile No. / Email ID Please Login Now!');
        window.location.href = '<?php echo site_url(); ?>users/login';
      } else {
        alert('This Mobile No. / Email ID is not Registered with us. Kindly check the Mobile No. / Email ID.');
      }
    });
  });

  //post enquiry
  $('#getQuoteForm').submit(function (e) {
    e.preventDefault();
    var fullName = $('#fullName').val();
    var mobileNumber = $('#mobileNumber').val();
    var emailAddress = $('#emailAddress').val();
    var productQuantity = $('#productQuantity').val();
    var enquiryMessage = $('#enquiryMessage').val();
    var productID = $('#productQuoteID').val();
    var companyID = $('#productCompID').val();
    var location = $('.productLocation').val();
    var post_url = $('#post_url').val();
    var type = '4';

    $.post(site_url + 'products/postEnquiry', {fullName: fullName, mobileNumber: mobileNumber, emailAddress: emailAddress, productQuantity: productQuantity, enquiryMessage: enquiryMessage, productID: productID, companyID: companyID, post_url: post_url, location: location,type:type}, function (response) {
      //alert(response);
      obj = JSON.parse(response);
      if (obj.success == 'true') {
        $('.SmessageBox').show(0);
        $('.EmessageBox').hide(0);
        $('.Emessage').html('');
        $('.Smessage').html('');
        $('.Smessage').html(obj.message);
        $('#getQuoteForm')[0].reset();
      } else {
        $('.EmessageBox').show();
        $('.SmessageBox').hide();
        $('.Smessage').html('');
        $('.Emessage').html('');
        $('.Emessage').html(obj.error);
      }
    });
  });
  
  //post enquiry from home page floating button
  $('.get_quote_home_foot').submit(function (e) {
    e.preventDefault();
    var productname = $("#productnameHomeFoot").val();
    var productQuantity = $("#qtyHomeFoot").val();
    var fullName = $('#fullNameHomeFoot').val();
    var mobileNumber = $('#mobileNumberHomeFoot').val();
    var emailAddress = $('#emailAddressHomeFoot').val();
    var enquiryMessage = $('#enquiryMessageHomeFoot').val();
    var location = $('#locationHomeFoot').val();
    //var post_url = $('#post_url_home_foot').val();
    var post_url = 'NULL';
    var type = '1';

    $.post(site_url + 'products/postEnquiry', {fullName: fullName, mobileNumber: mobileNumber, emailAddress: emailAddress, productQuantity: productQuantity, enquiryMessage: enquiryMessage, post_url: post_url, location: location, productname:productname,type:type}, function (response) {
      //alert(response);
      obj = JSON.parse(response);
      if (obj.success == 'true') {
        $('.SmessageBoxHomeFoot').show(0);
        $('.EmessageBoxHomeFoot').hide(0);
        $('.EmessageHomeFoot').html('');
        $('.SmessageHomeFoot').html('');
        $('.SmessageHomeFoot').html(obj.message);
        $('.get_quote_home_foot')[0].reset();
      } else {
        $('.EmessageBoxHomeFoot').show();
        $('.SmessageBoxHomeFoot').hide();
        $('.SmessageHomeFoot').html('');
        $('.EmessageHomeFoot').html('');
        $('.EmessageHomeFoot').html(obj.error);
      }
    });
  });

  //Open Modal
  jQuery('body').on('click', '.addComments', function () {
    var clintID = jQuery(this).attr('data-enqId');
    var userID = jQuery(this).attr('data-vendId');
    jQuery('#enqId').val(clintID);
    jQuery('#vendId').val(userID);
  });

  //Add SUPPORT Comment
  jQuery('#add_cv_btnFooter').click(function (event) {
    event.preventDefault();
    var btn = jQuery(this);
    //btn.button('loading');
    //Form validation
    var inputs = ['commentsFooter', 'stageFooter', 'follow_up_dateFooter', 'follow_up_timeFooter'];
    var messages = ['Comment', 'Stage', 'Follow up date', 'Follow up Time'];
    var status = false;
    for (var i = 0; i < inputs.length; ++i) {
      if (jQuery("#" + inputs[i]).val() == '') {
        alert(messages[i] + ' is required.');
        status = false;
        return;
      } else {
        status = true;
      }
    }
    if (status) {
      btn.button('loading');
      var enqId = jQuery("#enqId").val();
      var vendId = jQuery("#vendId").val();
      var cv_comment = jQuery("#commentsFooter").val();
      var commentType = jQuery('input[name=conversation_typeFooter]:checked').val();
      var follow_up_date = jQuery("#follow_up_dateFooter").val();
      var stage = jQuery("#stageFooter").val();
      var follow_up_time = jQuery("#follow_up_timeFooter").val();
      jQuery.post(site_url + 'members/add_vendor_comment', {enqId: enqId, vendId: vendId, conversation_ty: commentType, comment: cv_comment, follow_up_date: follow_up_date, follow_up_time: follow_up_time, stage: stage}, function (data) {
        //alert(msg);
        obj = jQuery.parseJSON(data);
        alert(obj.msg);
        btn.button('reset');
        jQuery("#add_cv_formFooter")[0].reset();
        location.reload();
      });
    }
  });
  //END HERE

  //View Shared/Added Comment List
  var reqID = '';
  function view_shared_comments(id) {
    reqID = id;
    $.post(site_url + 'members/view_addedcomments', {enqId: reqID}, function (data) {
     $("#commentListTable tbody").html(data);
    });
  }

  //search Suggestions
  $('.search_keyword').keyup(function () {
    keyword = $(this).val();
    if (keyword.length != "") {
      $.post(site_url + 'home/search_services', {keyword: keyword}, function (data) {
        $('.serach_listt').slideDown();
        $('.serach_listt').html(data);
      });
    }
  });
  $('.search_keyword').blur(function () {
    $('.serach_listt').slideUp();
  });

  //Factory Video
  $('.youtube_btn').click(function () {
    var youtubeId = 'https://www.youtube.com/embed/' + $(this).attr('data-youtubeId');
    var companyName = $(this).attr('data-companyFacName');
    $('.factoryVideoFrame').attr('src', youtubeId);
    $('#factCompanyName').html(companyName);
  });
  //End Here

  //Removig source fine to close voice
  $('body, .closeFacVideo').click(function () {
    setTimeout(function () {
      if ($('#facVideo').is(':visible')) {
      } else {
        $('.factoryVideoFrame').attr('src', '')
      }
      if ($('#regis-ter').is(':visible')) {
      } else {
        $('.pop-btn-rgstr').val('Create Your Account');
      }
    }, 300);
  });
  //End here

  //get contact no of companyID when not logged in
<?php
if ($this->session->userdata('compIdVerification') > 0) {
  ?>
    $.post(site_url + 'home/getCompanyContactNo', {compId: '<?php echo $this->session->userdata('compIdVerification'); ?>'}, function (data) {
      $('.contactNumberSupplier').html(data);
      $('#contactNumberSupplierPop').modal({
        dismissible: true
      });
      $('#contactNumberSupplierPop').modal('open');
    });
  <?php
}
?>
  //When Login
  $('.viewContactNo').click(function () {
    $.post(site_url + 'home/getCompanyContactNo', {compId: $(this).attr('data-companyID')}, function (data) {
      console.log(data);
      $('.contactNumberSupplier').html(data);
      $('#contactNumberSupplierPop').modal({
        dismissible: true
      });
      $('#contactNumberSupplierPop').modal('open');
    });
  });
  //Close View Contact Infor Pop Up
  $('.closeontactInfo').click(function () {
    $('#contactNumberSupplierPop').modal({
      dismissible: true
    });
    $('#contactNumberSupplierPop').modal('close');
  });


  //forgot password
  $('.forgotPassword').click(function () {
    var userName = $('#login_mobile').val();
    if (userName) {
      jQuery.post('<?php echo site_url(); ?>home/send_password', {mobile: userName}, function (response) {
        if (response === '1') {
          alert('Your Account Password has been sent to your regstered Mobile No. / Email ID Please Login Now!');
        } else {
          alert('This Mobile No. / Email ID is not Registered with us. Kindly check the Mobile No. / Email ID.');
        }
      });
    } else {
      alert('Please Enter Valid Mobile No. / Email ID.');
    }
  });
  
  
  //Activate Website URL
  jQuery('.website_activation').click(function(){
    var chkVal = jQuery("input[name='website_activation']:checked").val();
    if(chkVal == '1'){
      jQuery('.websiteUrl').show();
    }else{
      jQuery('.websiteUrl').hide();
    }
  });

</script>


<script>
  // This example displays an address form, using the autocomplete feature
  // of the Google Places API to help users fill in the information.

  // This example requires the Places library. Include the libraries=places
  // parameter when you first load the API. For example:
  // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

  var placeSearch, autocomplete, autocomplete1;
  var componentForm = {
    street_number: 'short_name',
    route: 'long_name',
    locality: 'long_name',
    administrative_area_level_1: 'short_name',
    country: 'long_name',
    postal_code: 'short_name'
  };

  function initAutocomplete() {
    // Create the autocomplete object, restricting the search to geographical
    // location types.
    autocomplete = new google.maps.places.Autocomplete(
            /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
            {types: ['geocode']});

    autocomplete1 = new google.maps.places.Autocomplete(
            /** @type {!HTMLInputElement} */(document.getElementById('autocomplete1')),
            {types: ['geocode']});

    // When the user selects an address from the dropdown, populate the address
    // fields in the form.
    autocomplete.addListener('place_changed', fillInAddress);
  }

  function fillInAddress() {
    // Get the place details from the autocomplete object.
    var place = autocomplete.getPlace();

    for (var component in componentForm) {
      document.getElementById(component).value = '';
      document.getElementById(component).disabled = false;
    }

    // Get each component of the address from the place details
    // and fill the corresponding field on the form.
    for (var i = 0; i < place.address_components.length; i++) {
      var addressType = place.address_components[i].types[0];
      if (componentForm[addressType]) {
        var val = place.address_components[i][componentForm[addressType]];
        document.getElementById(addressType).value = val;
      }
    }
  }

  // Bias the autocomplete object to the user's geographical location,
  // as supplied by the browser's 'navigator.geolocation' object.
  function geolocate() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function (position) {
        var geolocation = {
          lat: position.coords.latitude,
          lng: position.coords.longitude
        };
        var circle = new google.maps.Circle({
          center: geolocation,
          radius: position.coords.accuracy
        });
        autocomplete.setBounds(circle.getBounds());
      });
    }
  }
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCYyhHAHS-58SXSyMw66_MulbmH-xHruxI&libraries=places&callback=initAutocomplete"
async defer></script>
<script src="<?php echo theme_url(); ?>js/owl.carousel.js"></script>
<script src="<?php echo theme_url(); ?>js/typed.js"></script>
</body>
</html>