<script type="text/javascript">

 var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;

// $(document).ready(function(){
//  //    $("#addnew").click(function(){
//  //        $("#clinic_mphoto").clone().appendTo("#clinic_p_append");
//  //    });
//  //    $("#clinic_primary_speciality").change(function(){
//  //        var val = $("#clinic_primary_speciality").val();
//  //        $.ajax({
//  //        url: "clinicadd.php",
//  //        data: 'act=feature&speciality='+val,
//  //        method: 'POST',
//  //        success: function(res){
//  //             $("#spe_feature").html(res);
//  //            }
//  //        });
//  //    });
//  //        $("#frm-clinic").submit(function(e){
//  //            if(!validate_clinic()){
//  //                e.preventDefault();
//  //            }
// 	// });
//  //        $("#clinic_email").blur(function(){
//  //            var email = $("#clinic_email");
//  //            var emailmsg = $("#msg_clinic_email");
//  //            if(email.val()==""){
//  //                email.addClass('error');email.focus();emailmsg.html('Please enter email address').show();
//  //                return false;
//  //            }
//  //            if($("#clinic_id").length > 0){var clinic_id = $("#clinic_id").val();
//  //            }else{var clinic_id = '';}
//  //            $("#submit").prop('disabled', true);
//  //            $.ajax({
//  //                url: "clinicadd.php",
//  //                data: 'act=validate_email&email='+email.val()+'&clinic_id='+clinic_id,
//  //                method: 'POST',
//  //                success: function(msg){
//  //                    if(msg!=''){
//  //                        email.addClass('error');email.focus();emailmsg.html(msg).show();
//  //                        return false;
//  //                    }else{
//  //                        $("#submit").prop('disabled', false);
//  //                        email.removeClass('error');emailmsg.hide();
//  //                    }
//  //                }
//  //            });
// 	// });
//         // $("#clinic_phone").blur(function(){
//         //     var phone = $("#clinic_phone");
//         //     var phonemsg = $("#msg_clinic_phone");
//         //     if(phone.val()==""){
//         //         phone.addClass('error');phone.focus();phonemsg.html('Please enter phone').show();
//         //         return false;
//         //     }
//         //     if($("#clinic_id").length > 0){var clinic_id = $("#clinic_id").val();
//         //     }else{var clinic_id = '';}
//         //     $("#submit").prop('disabled', true);
//         //     $.ajax({
//         //         url: "clinicadd.php",
//         //         data: 'act=validate_phone&phone='+phone.val()+'&clinic_id='+clinic_id,
//         //         method: 'POST',
//         //         success: function(msg){
//         //             if(msg!=''){
//         //                 phone.addClass('error');phone.focus();phonemsg.html(msg).show();
//         //                 return false;
//         //             }else{
//         //                 $("#submit").prop('disabled', false);
//         //                 phone.removeClass('error');phonemsg.hide();
//         //             }
//         //         }
//         //     });
// 	});
// });

function deletePhotos(id){
     $.ajax({
            url: "clinicadd.php",
            data: 'act=deletephoto&photoid='+id,
            method: 'POST',
            success: function(msg){
               $("#photo_"+id).remove();
            }
        });
}
// function validate_clinic(){

//    // if($("#clinic_user_id").val()==''){
//    //      $("#clinic_user_id").addClass('error');
//    //      $("#clinic_user_id").focus();
//    //      $("#msg_clinic_user_id").html('Please select user').show();
//    //      return false;
//    //  }else{
//    //      $("#clinic_user_id").removeClass('error');
//    //      $("#msg_clinic_user_id").hide();
//    //  }
//    // if($("#clinic_primary_speciality").val()==''){
//    //      $("#clinic_primary_speciality").addClass('error');
//    //      $("#clinic_primary_speciality").focus();
//    //      $("#msg_clinic_primary_speciality").html('Please select speciality').show();
//    //      return false;
//    //  }else{
//    //      $("#clinic_primary_speciality").removeClass('error');
//    //      $("#msg_clinic_primary_speciality").hide();
//    //  }
//    // if($("#clinic_name").val()==''){
//    //      $("#clinic_name").addClass('error');
//    //      $("#clinic_name").focus();
//    //      $("#msg_clinic_name").html('Please enter name').show();
//    //      return false;
//    //  }else{
//    //      $("#clinic_name").removeClass('error');
//    //      $("#msg_clinic_name").hide();
//    //  }
//    //  if($("#clinic_email").val()==''){
//    //      $("#clinic_email").addClass('error');
//    //      $("#clinic_email").focus();
//    //      $("#msg_clinic_email").html('Please enter email address').show();
//    //      return false;
//    //  }else if($("#clinic_email").val()!='' && !(emailFilter.test($("#clinic_email").val())) ){
//    //      $("#clinic_email").addClass('error');
//    //      $("#clinic_email").focus();
//    //      $("#msg_clinic_email").html('Please enter valid email address').show();
//    //      return false;
//    //  }else{
//    //      $("#clinic_email").removeClass('error');
//    //      $("#msg_clinic_email").hide();
//    //  }

//    // if($("#clinic_phone").val()==''){
//    //      $("#clinic_phone").addClass('error');
//    //      $("#clinic_phone").focus();
//    //      $("#msg_clinic_phone").html('Please enter phone number').show();
//    //      return false;
//    //  }else{
//    //      $("#clinic_phone").removeClass('error');
//    //      $("#msg_clinic_phone").hide();
//    //  }

//    //  if($("#clinic_logo").val()=='' && $("#hidden_logo").val()==''){
//    //      $("#clinic_logo").addClass('error');
//    //      $("#clinic_logo").focus();
//    //      $("#msg_clinic_logo").html('Upload Logo').show();
//    //      return false;
//    //  }else{
//    //      $("#clinic_logo").removeClass('error');
//    //      $("#msg_clinic_logo").hide();
//    //  }
//    //  return true;
// }

</script>
<div class="breadcrumb">
    <h1>Clinic</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Add New Clinic</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
    <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>
<form action="" id='frm-clinic' method="post" enctype="multipart/form-data">
<div class="row">
    <div class="col-md-6">
        <!-- <div class="card mb-4">
            <div class="card-body">
                -->
                <?php if(isset($clinicDetail->clinic_id) && $clinicDetail->clinic_id!=0) { ?>
                    <input type="hidden" id="clinic_id" name="clinic_id" value="<?php echo $clinicDetail->clinic_id ?>" />
                 <?php } ?>
                   <!-- <div class="card-title mb-3">Clinic Information</div>
                    <div class="row">
                        <div class="col-md-4 form-group mb-3">
                            <label for="clinic_user_id">Select user <span class="asterisk">*</span></label>
                            <select id="clinic_user_id" name="clinic_user_id" class="form-control">
                                <option value="">Select User</option>
                                <?php if($alluser && count($alluser)){foreach($alluser as $key =>$user){?>
                                <option value="<?php echo $user->user_id ?>" <?php echo (isset($clinicDetail)&& $clinicDetail->clinic_user_id==$user->user_id)?"selected='selected'":""  ?>><?php echo $user->user_fname." ".$user->user_lname ?></option>
                                <?php }} ?>
                            </select>    
                            <div class="invalid-tooltip" id="msg_clinic_user_id"></div>
                        </div>    
                        <div class="col-md-4 form-group mb-3">
                            <label for="clinic_primary_speciality">Primary Speciality <span class="asterisk">*</span></label>
                            <select id="clinic_primary_speciality" name="clinic_primary_speciality" class="form-control">
                                <option value="">Select Speciality</option>
                                <?php if($allspecialities && count($allspecialities)){foreach($allspecialities as $key =>$speciality){?>
                                <option value="<?php echo $speciality->speciality_id ?>" <?php echo (isset($clinicDetail)&& $clinicDetail->clinic_primary_speciality==$speciality->speciality_id)?"selected='selected'":""  ?>><?php echo $speciality->speciality_name ?></option>
                                <?php }} ?>
                            </select>    
                            <div class="invalid-tooltip" id="msg_clinic_primary_speciality"></div>
                        </div>    
                        <div class="col-md-4 form-group mb-3">
                            <label for="clinic_name">Clinic Name <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="clinic_name" name="clinic_name" value="<?php echo $clinicDetail->clinic_name; ?>" placeholder="Enter first name">
                            <div class="invalid-tooltip" id="msg_clinic_name"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="clinic_email">Email <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="clinic_email" name="clinic_email" value="<?php echo $clinicDetail->clinic_email; ?>" placeholder="Enter your email address">
                            <div class="invalid-tooltip" id="msg_clinic_email"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="clinic_phone">Phone<span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="clinic_phone" name="clinic_phone" value="<?php echo $clinicDetail->clinic_phone; ?>" placeholder="Enter your phone number">
                            <div class="invalid-tooltip" id="msg_clinic_phone"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="clinic_website">Website</label>
                            <input type="text" class="form-control" id="clinic_website" name="clinic_website" value="<?php echo $clinicDetail->clinic_website; ?>" placeholder="website URL">
                            <div class="invalid-tooltip" id="msg_clinic_website"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="clinic_logo">Logo <span class="asterisk">*</span></label>
                            <input type="file" class="form-control" id="clinic_logo" name="clinic_logo">
                            <?php 
                            $logo = json_decode($clinicDetail->clinic_logo,1);
                            if($logo['name']!='' && file_exists(DIR_UPLOAD_CLINIC.$logo['name']."-200x200.".$logo['type'])){ ?>
                                </br>
                                <input type="hidden" name="hidden_logo" id="hidden_logo" value="<?php echo $logo['name'] ?>">
                                <input type="hidden" name="hidden_logo_ext" id="hhidden_logo_ext" value="<?php echo $logo['type'] ?>">
                                <img src="<?php echo DIR_UPLOAD_CLINIC_SHOW.$logo['name']."-200x200.".$logo['type'] ?>" width="100px" />
                            <?php } ?>
                            <div class="invalid-tooltip" id="msg_clinic_logo"></div>
                        </div>
                        
                    </div>
            </div>
        </div> -->
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Clinic Address</div>
                    <div class="row">
                        <div class="col-md-12 form-group mb-3" id="map" style="height: 170px;">
                         </div>
                        <div class="col-md-12 form-group mb-3">
                            <label for="autocomplete_search">Search Here <span class="asterisk">*</span></label>
                            <input type="text" class="form-control" id="autocomplete_search" name="autocomplete_search" value="<?php echo $addressformat ?>">
                            <input type="hidden" id="address_id" name="address_id" value="<?php echo $addressDetail->address_id; ?>">
                            <input type="hidden" id="street_number" name="street_number" value="<?php echo $addressDetail->address_street; ?>">
                            <input type="hidden"  id="route" name="route" value="<?php echo $addressDetail->address_route; ?>">
                            <input type="hidden"  id="locality" name="locality" value="<?php echo $addressDetail->address_locality; ?>">
                            <input type="hidden"  id="sublocality_level_1" name="sublocality_level_1" value="<?php echo $addressDetail->address_sublocality; ?>">

                            <input type="hidden"  id="neighborhood" name="neighborhood" value="<?php echo $addressDetail->address_neighborhood; ?>">

                            <input type="hidden"  id="postal_code" name="postal_code" value="<?php echo $addressDetail->address_postal; ?>">
                            <input type="hidden"  id="administrative_area_level_1" name="administrative_area_level_1" value="<?php echo $addressDetail->address_level_1; ?>">
                            <input type="hidden"  id="address_level_1_short" name="address_level_1_short" value="<?php echo $addressDetail->address_level_1_short; ?>">
                            <input type="hidden"  id="country" name="country" value="<?php echo $addressDetail->address_country; ?>">
                            <input type="hidden"  id="subpremise" name="subpremise" value="<?php echo $addressDetail->address_suite; ?>">
                            <input type="hidden"  id="lng" name="lng" value="<?php echo $addressDetail->address_longitude; ?>">
                            <input type="hidden"  id="lat" name="lat" value="<?php echo $addressDetail->address_latitude; ?>">
                            
                         </div>
                    </div>
                </div>
            </div>
            <!-- <div class="card mb-4">
                <div class="card-body">
                    <div class="card-title mb-3">Clinic Hours</div>
                        <div class="row">
                             <div class="col-md-4 form-group mb-3">
                                <label for="">Day</label>
                             </div>
                             <div class="col-md-4 form-group mb-3">
                                <label for="">Start</label>
                             </div>
                             <div class="col-md-4 form-group mb-3">
                                <label for="">End</label>
                             </div>
                        </div>
                        <div class="row">
                            <?php foreach($days as $dkey => $day){?>
                            <div class="col-md-4 form-group mb-3">
                                <span><?php echo $day ?></span>
                                 <input type="hidden" id="clinic_day" name="clinic_day[]" value="<?php echo $dkey ?>"/>
                            </div>
                            <div class="col-md-4 form-group mb-3">
                                <select id="clinic_hour" name="clinic_hour[<?php echo $dkey ?>][]" class="form-control">
                                    <?php foreach ($hours as $hkey =>$h){ ?>
                                        <option value="<?php echo $hkey ?>" <?php echo $clinichours[$dkey][0]==$hkey?'selected="selected"':"" ?> ><?php echo $h ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="col-md-4 form-group mb-3">
                                <select id="clinic_hour" name="clinic_hour[<?php echo $dkey ?>][]" class="form-control">
                                    <?php foreach ($hours as $hkey =>$h){ ?>
                                        <option value="<?php echo $hkey ?>" <?php echo $clinichours[$dkey][1]==$hkey?'selected="selected"':"" ?>><?php echo $h ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <?php } ?>
                            
                        </div>
                    </div>
                </div> -->
    </div>


    <!-- <div class="col-md-6">
        <div class="card mb-4">
            <!-- <div class="card-body">
                <div class="card-title mb-3">Clinic Photos <a style="float: right;font-size: 12px;" href="javascript:void(0);" id="addnew">Add New</a></div>
                <div class="row" id="clinic_p_append">
                        <?php if($allclinicphotos && count($allclinicphotos)>0){ foreach ($allclinicphotos as $clinicphoto){ 
                            if($clinicphoto->clinic_photo_image!='' && file_exists(DIR_UPLOAD_CLINIC.$clinicphoto->clinic_photo_image)){ ?>
                            <div class="col-md-4" id="photo_<?php echo $clinicphoto->clinic_photo_id ?>">
                                <div class="card text-white o-hidden mb-3">
                                    <img class="card-img" src="<?php echo DIR_UPLOAD_CLINIC_SHOW.$clinicphoto->clinic_photo_image ?>" alt="">
                                    <div class="card-img-overlay">
                                        <div class="p-1 text-left card-footer font-weight-light d-flex">
                                            <span class="mr-3 d-flex align-items-center">
                                                <a href="javascript:void(0)" style="color: #fff;" onclick="deletePhotos('<?php echo $clinicphoto->clinic_photo_id ?>')"><i class="i-Close-Window mr-1"></i> Delete </a>
                                            </span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php }}}  ?>
                        <div class="col-md-8 form-group mb-3" id="clinic_mphoto">
                            <input type="file" class="form-control" id="clinic_photos" name="clinic_photos[]">
                        </div>
                    </div>
                </div>
            </div> 
            <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Profile Description</div>
                    <div class="row">
                        <div class="col-md-12 form-group mb-3">
                            <textarea class="form-control" id="clinic_desc" rows="10" name="clinic_desc"  placeholder="Enter profile description."><?php echo $clinicDetail->clinic_desc; ?></textarea>
                            <div class="invalid-tooltip" id="msg_clinic_desc"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Profile Questions</div>
                    <div class="row">
                        <?php if($allquestions && count($allquestions)>0){foreach($allquestions as $qkey =>$question){ ?>
                        <div class="col-md-12 form-group mb-3">
                            <label for="question_answer_<?php echo $qkey ?>"><?php echo $question->question_title ?></label>
                            <input type="hidden" id="hdn_que_<?php echo $qkey ?>" name="question_id[]" value="<?php echo $question->question_id ?>" />
                            <textarea class="form-control" id="question_answer_<?php echo $qkey ?>" rows="5" name="question_answer[<?php echo $qkey ?>]"  placeholder="Enter answer."><?php echo $clinicDetail->clinic_desc; ?></textarea>
                            <div class="invalid-tooltip" id="msg_question_answer_<?php echo $qkey ?>"></div>
                        </div>
                       <?php }}?> 
                    </div>
                </div>
            </div>
            <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Clinic Features</div>
                    <div class="row"  id="spe_feature">
                    <?php if($allfeature && count($allfeature) > 0){ foreach ($allfeature as $key => $value){ ?>
                        <div class="col-md-6 form-group mb-3">
                            <label class="checkbox checkbox-outline-primary inline-checkbox">
                                <input type="checkbox" name="clinic_feature[]" id="clinic_feature_<?php echo $key ?>" <?php echo (in_array($value->feature_id, explode(",",$clinicDetail->clinic_feature)))?"checked='checked'":"" ?>  value="<?php echo $value->feature_id ?>" >
                                <span><?php echo $value->feature_name; ?></span>
                                <span class="checkmark"></span>
                            </label>
                            </div>
                        <?php } } ?>	
                    </div>
                </div>
            </div>
        </div> -->
    <div class="col-md-12">
        <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
    </div>
    </div>
</form>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDIDMklRxHmFYWU8Vvo1P-dVkB_nbHARj8&libraries=places"></script>
<script>
    var componentForm = {
        street_number: 'long_name',
        subpremise: 'short_name',
        route: 'long_name',
        locality: 'long_name',
        sublocality_level_1: 'long_name',
        administrative_area_level_1: 'long_name',
        country: 'long_name',
        postal_code: 'short_name',
        neighborhood:'long_name'
    };
    
     
  google.maps.event.addDomListener(window, 'load', initialize);
    function initialize() {
        var map = new google.maps.Map(document.getElementById('map')
      <?php if(isset($addressDetail) && $addressDetail->adddress_latitude!=""){ ?>
          , {
          center: {lat: <?php echo $addressDetail->address_latitude ?>, lng: <?php echo $addressDetail->address_longitude ?>},
          zoom: 15,
          scrollwheel: !1,
          disableDoubleClickZoom: !0,
          mapTypeControlOptions: {
             mapTypeIds: []
          },
          disableDefaultUI: !0,
          draggable: !1,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
      <?php } ?>    
    );
        <?php if(isset($addressDetail) && $addressDetail->adddress_latitude!=""){ ?>
            var marker = new google.maps.Marker({
            position: {lat: <?php echo $addressDetail->address_latitude ?>, lng: <?php echo $addressDetail->address_longitude ?>},
            map: map
            });
       <?php } ?>     
        
      var input = document.getElementById('autocomplete_search');
      var autocomplete = new google.maps.places.Autocomplete(input);
       autocomplete.bindTo('bounds', map);
        // Set the data fields to return when the user selects a place.
        var marker = new google.maps.Marker({
          map: map,
          anchorPoint: new google.maps.Point(0, -29)
        });
      
//      autocomplete.setFields(['address_component']);
        autocomplete.addListener('place_changed', function () {
        marker.setVisible(false);
     
      var place = autocomplete.getPlace();
      input.value=place.formatted_address;
//      console.log(place.geometry['location']);
      document.getElementById('lat').value = place.geometry['location'].lat();
      document.getElementById('lng').value = place.geometry['location'].lng();
       for (var key in componentForm) {
         document.getElementById(key).value = "";
       }
       for (var i = 0; i < place.address_components.length; i++) {
        var addressType = place.address_components[i].types[0];
            if (componentForm[addressType]) {
                if(addressType=='administrative_area_level_1'){
                    var val = place.address_components[i]['short_name'];
                    document.getElementById('address_level_1_short').value = val;
                }
                var val = place.address_components[i][componentForm[addressType]];
                document.getElementById(addressType).value = val;
            }
        }
        
        map.setCenter(place.geometry.location);
        map.setZoom(15);  // Why 17? Because it looks good.
        marker.setPosition(place.geometry.location);
        marker.setVisible(true);
    });
  }
</script>
<style>
    .gm-fullscreen-control {
  display: none;
}
</style>