<script>
    $.noConflict(); // Code that uses other library's $ can follow here.
</script>
<script src="<?php echo base_url(); ?>resource_library/jquery/jquery-2.1.1.min"></script>

<div class="col-sm-8">
    <div class="row gray_ttc">
        <div class="col-sm-12 padding-zero">
            <div class="col-sm-12">
                <h3>Update Teacher Information</h3>  
                <hr>
            </div>
            <div class="col-sm-12"><br><br></div>
            <div class="col-sm-12">
                <?php
//                echo validation_errors();
                $teacher_url = $this->session->userdata('teacher_url');
                $url = 'edit-teacher-information';
                echo form_open_multipart($url, 'class="" id="formID2" name="userForm" onsubmit=""');
                ?>
                <input type="hidden" name="teacher_url" value="<?php echo $teacher_url; ?>">
                <div class="col-sm-12">
                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <input type="email"
                                   data-errormessage-value-missing="Person Email is required!" 
                                   class="form-control"
                                   placeholder="Please enter your  Email .." 
                                   value="<?php
                                   if (set_value('person_email')) {
                                       echo set_value('person_email');
                                   } else {
                                       echo $resource_person_info->person_email;
                                   }
                                   ?>" 
                                   oninput="checkUserEmail(this.value,'<?php echo base_url(); ?>check-org-teacher-email');"
                                   autofocus name="person_email" id="person_email" 
                                   maxlength="256">
                            <input type="hidden" name="person_previous_email" id="person_previous_email" value="<?php echo $resource_person_info->person_email; ?>">
                            <input type="hidden" name="email_status_value" id="email_status_value" value="1"/>
                            <span class="input-group-addon"  title="Please enter your  Email"><i class="fa fa-envelope"></i></span>
                        </div>
                        <span id="person_email_message" style="color:red;"><?php echo form_error('person_email'); ?></span>
                    </div>
                    <div class="col-sm-12"><br></div>

                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <input type="text"
                                   data-errormessage-value-missing="Person First Name is required!"
                                   class="form-control" 
                                   id="person_first_name" 
                                   name="person_first_name" 
                                   value="<?php
                                   if (set_value('person_first_name')) {
                                       echo set_value('person_first_name');
                                   } else {
                                       echo $resource_person_info->person_first_name;
                                   }
                                   ?>" 
                                   oninput="getUrlValue(this.value, person_last_name.value, profile_url.value, '<?php echo base_url(); ?>user/check-add-teacher-forbidden', '<?php echo base_url(); ?>user/edit-teacher-url-exist', '<?php echo base_url(); ?>profile_url_existance');"
                                   placeholder="Please enter your First Name .."  maxlength="100">
                            <span class="input-group-addon"  title="Please enter your First Name"><i class="fa fa-user"></i></span>
                        </div>
                        <span id="person_first_name_message" style="color:red;"><?php echo form_error('person_first_name'); ?></span>
                    </div>

                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <input type="text"
                                   data-errormessage-value-missing=" "
                                   class="form-control"  
                                   id="person_last_name"
                                   name="person_last_name"
                                   oninput="getUrlValue(person_first_name.value, this.value, profile_url.value, '<?php echo base_url(); ?>user/check-add-teacher-forbidden','<?php echo base_url(); ?>user/edit-teacher-url-exist', '<?php echo base_url(); ?>profile_url_existance');"
                                   value="<?php
                                   if (set_value('person_last_name')) {
                                       echo set_value('person_last_name');
                                   } else {
                                       echo $resource_person_info->person_last_name;
                                   }
                                   ?>" 
                                   placeholder="Please enter your Last Name .."   maxlength="100" >
                            <span class="input-group-addon"  title="Please enter your Last Name"><i class="fa fa-user"></i></span>
                            <input type="hidden" id="add_teacher_org_forbidden_exists" value="">
                        </div>
                        <span id="person_last_name_message" style="color:red;"><?php echo form_error('person_last_name'); ?></span>
                    </div>
                    <div class="col-sm-12"><br></div>

                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <input type="hidden" name="old_url" id="old_url" value="<?php echo $resource_person_info->url; ?>">
                            <input type="hidden" name="url_id" id="url_id" value="<?php echo $resource_person_info->url_id; ?>">
                            <input type="text" 
                                   data-errormessage-value-missing="Profile URl is required!" type="text" 
                                   class="form-control" 
                                   id="profile_url" name="profile_url"
                                   oninput="getUrlValue(person_first_name.value, person_last_name.value, this.value, '<?php echo base_url(); ?>user/check-add-teacher-forbidden', '<?php echo base_url(); ?>user/edit-teacher-url-exist', '<?php echo base_url(); ?>profile_url_existance');" 
                                   value="<?php
                                   if (set_value('profile_url')) {
                                       echo set_value('profile_url');
                                   } else {
                                       echo $resource_person_info->url;
                                   }
                                   ?>"
                                   <?php
                                   if ($resource_person_info->person_last_change_url_date) {
                                       if ($url_change_different < 1) {
                                           echo 'readonly="readonly"';
                                       }
                                   }
                                   ?>
                                   placeholder="Please enter your Profile URL .."  
                                   maxlength="100"
                                   readonly="readonly">
                            <input type="hidden" name="url_exist" id="url_exist" value="">
                            <span class="input-group-addon"  title="Please enter your Profile URL"><i class="fa fa-user"></i></span>
                        </div>

                        <?php
                        if ($resource_person_info->person_last_change_url_date) {
                            if ($url_change_different < 1) {
                                ?>
                                <span id="profile_url_message" style="color:red">You can not change your url within 1 days</span>
                            <?php } else {
                                ?>
                                <span id="profile_url_message" style="color:red;"><?php echo form_error('profile_url'); ?></span>
                                <?php
                            }
                        }
                        ?>
                    </div>
                    <div class="col-sm-12"><br></div>
                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <input type="password" 
                                   data-errormessage-value-missing="* Password field is required!"
                                   class="form-control" 
                                   id="person_password" 
                                   name="person_password"  
                                   placeholder="Please enter your Password ..">
                            <span class="input-group-addon"  title="Please enter your Password"><i class="fa fa-th"></i></span>
                            <input type="hidden" name="pass_stat" id="pass_stat" value="3">

                        </div>
                        <span id="person_password_message" style="color:red;"><?php echo form_error('person_password'); ?></span>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group input-group">
                            <input type="password" 
                                   data-errormessage-value-missing="* Person Confirm Password is required!"
                                   class="form-control"
                                   id="confirm_password" 
                                   name="confirm_password"
                                   minlength="6" 
                                   placeholder="Please enter  Confirm Password ..">
                            <span class="input-group-addon"  title="Please enter  Confirm Password"><i class="fa fa-th"></i></span>
                            <input type="hidden" name="pass_match_stat" id="pass_match_stat" value="0">
                        </div>
                        <span id="confirm_password_message" style="color:red;"><?php echo form_error('confirm_password'); ?></span>
                    </div>

                    <div class="col-sm-12 ">
                        <div class="text-left" id="password_status"></div>
                        <div class="text-left" id="password_score"></div>
                        <br>
                    </div>

                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <select data-errormessage-value-missing="Person Country is required!"
                                    class="form-control" 
                                    id="person_country"
                                    name ="person_country">
                            </select>
                            <span class="input-group-addon"  title="Please select Country"><i class="fa fa-flag-checkered"></i></span>
                        </div>
                        <span id="person_country_message" style="color:red;"><?php echo form_error('person_country'); ?></span>
                    </div>
                    <script>
    populateCountries("person_country", "person_city");  // ....for Country with State
    $("#person_country").on("keypress keyup keydown blur change mouseup input", function () {
        document.getElementById('hidden_country_code').value = getCountryCode('person_country');
    });
    $(document).ready(function () {
        document.getElementById('hidden_country_code').value = getCountryCode('person_country');
    });
                    </script>

                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <select  data-errormessage-value-missing="Person City is required!"
                                     class="form-control"
                                     name ="person_city"
                                     id ="person_city" >
                            </select>
                            <span class="input-group-addon"  title="Please Select City"><i class="fa fa-flag"></i></span>
                        </div>
                        <span id="person_city_message" style="color:red;"><?php echo form_error('person_city'); ?></span>
                    </div>

                    <div class="col-sm-12"><br></div>
                    <div class="form-group col-sm-12">
                        <div class="input-group">
                            <textarea rows="3" cols="100"
                                      id="person_address" name="person_address"
                                      data-errormessage-value-missing="Person Address is required!"
                                      class="form-control"
                                      placeholder="Please Type Your Address" style="max-width: 620px;max-height: 300px;"><?php
                                          if (set_value('person_address')) {
                                              echo set_value('person_address');
                                          } else {
                                              echo $resource_person_info->person_address;
                                          }
                                          ?></textarea>
                        </div>
                    </div>

                    <div class="form-group col-sm-6">
                        <div class="input-group">
                            <input type="text"
                                   data-errormessage-value-missing="Person Zip/Postal Code is required!"
                                   class="form-control" 
                                   name="person_zip" class="form-control" value="<?php
                                   if (set_value('person_zip')) {
                                       echo set_value('person_zip');
                                   } else {
                                       echo $resource_person_info->person_zip;
                                   }
                                   ?>"
                                   placeholder="Zip/Postal Code"
                                   minlength="3" maxlength="5"
                                   oninput="setCountryCode()">
                            <span class="input-group-addon"  title="Please type Zip/Postal Code"><i class="fa fa-trello"></i></span>
                        </div>
                        <span id="person_zip_message" style="color:red;"><?php echo form_error('person_zip'); ?></span>
                    </div>

                    <div class="form-group col-sm-6">
                        <?php
                        if (set_value('person_contact_number')) {
                            $mobile_number = set_value('person_contact_number');
                        } else {
                            $mobile_number = $resource_person_info->person_contact_number;
                        }
                        ?>
                        <div class="form-group">
                            <input  data-errormessage-value-missing="Person country Code is required!"
                                    class="form-control col-sm-2"
                                    name="country_code" 
                                    id ="country_code" 
                                    style="width:70px;" 
                                    minlength="3" 
                                    maxlength="4" 
                                    value="<?php
                                    if (set_value('country_code')) {
                                        echo set_value('country_code');
                                    } else {
                                        $country_code = strstr($mobile_number, ' ', TRUE);
                                        echo $country_code;
                                    }
                                    ?>"
                                    disabled="1">
                            <input type="hidden" name="hidden_country_code" id="hidden_country_code" value="<?php
                            if (set_value('hidden_country_code')) {
                                echo set_value('hidden_country_code');
                            } else {
                                echo $country_code;
                            }
                            ?>">

                            <?php
                            $country_code = strstr($mobile_number, ' ', FALSE);
                            ?>
                            <div class="col-sm-1" style="padding: 5px;">-</div>
                            <input data-errormessage-value-missing="Person Mobile Number is required!"
                                   class="form-control col-sm-4"
                                   name="person_contact_number" 
                                   id ="person_contact_number"
                                   style="width:200px;"                                 
                                   minlength="8" maxlength="16"
                                   value="<?php
                                   if (set_value('person_contact_number')) {
                                       echo set_value('person_contact_number');
                                   } else {
                                       echo trim($country_code);
                                   }
                                   ?>">
                        </div>
                        <div class="col-sm-12 padding-zero">
                            <span id="country_code_message" style="color:red;"><?php echo form_error('country_code'); ?></span>
                            <span id="person_contact_number_message" style="color:red;"><?php echo form_error('person_contact_number'); ?></span>
                        </div>
                    </div>
                    <div class="col-sm-12"><br></div>

                    <input type="hidden" id="user_image" name="person_image" value="<?php echo $resource_person_info->person_image; ?>">
                    <input type="hidden" id="user_image_thumb" name="person_image_thumb" value="<?php echo $resource_person_info->person_image_thumb; ?>">

                    <script>
                        $(":file").filestyle({icon: false});
                    </script>

                    <div class="form-group col-sm-6 ">
                        <div id="image_field">
                            <input type="file" class="filestyle" data-icon="false" name="person_new_image" onchange="personImageUpload(this, 'photo_0');" >
                        </div>
                    </div>
                    <div class="form-group col-sm-6 ">
                        <div id="image" style="float:left; width: 50px; height: 50px;" >
                            <?php if ($resource_person_info->person_image_thumb) { ?>
                                <img class="img-responsive" src="<?php echo base_url() . 'content-library/' . $resource_person_info->url . '/' . $resource_person_info->person_image_thumb; ?>" id="image_source" style="float:left;" alt="Course image"/>
                            <?php } else { ?>
                                <img class="img-responsive" src="<?php echo base_url() ?>image/no_profile_picture.png" id="image_source" style="float:left;" alt="Course image">
                            <?php } ?>
                            <span id="person_image_message" style="color:red;"><?php echo form_error('person_image'); ?></span>
                        </div>
                        <div id="message"></div>
                    </div>

                    <input style="float:left;" type='hidden' name="image_path" id="image_path" value="<?php echo set_value('image_path'); ?>"/>
                    <div class="col-sm-12"><br></div>

                    <div class="form-group col-sm-6 text-left">
                        <label class="col-sm-4">Gender :  &nbsp;&nbsp;</label>
                        <div class="col-sm-8">
                            <div class="radio radio-success margin-zero">
                                <input type="radio"
                                       data-errormessage-value-missing="Person Gender is required!"
                                       class="" 
                                       id="male" 
                                       name="person_gender" 
                                       value="1" 
                                       onchange="checkGenderStatus()">
                                <label for="male">Male</label>
                                <span style="margin-right: 30px"></span>
                                <input type="radio"
                                       data-errormessage-value-missing="Person Gender is required!"
                                       class="" 
                                       id="female" 
                                       name="person_gender" 
                                       value="2"  onchange="checkGenderStatus()">
                                <label for="female">Female</label>
                            </div>
                            <script>
                                document.forms['userForm'].elements['person_gender'].value = '<?php
                            if (set_value('person_gender')) {
                                echo set_value('person_gender');
                            } else {
                                echo $resource_person_info->person_gender;
                            }
                            ?>';

                            </script>
                            <span id="person_gender_message" style="color:red;"><?php echo form_error('person_gender'); ?></span>
                        </div>
                    </div>

                    <div class="form-group col-sm-6 text-left">
                        <?php if ($resource_person_info->person_id != $this->session->userdata('user_id')) { ?>
                            <label class="col-sm-4">Status : &nbsp;&nbsp; </label>
                            <div class="col-sm-8">
                                <div class="radio radio-success margin-zero">
                                    <input type="radio"
                                           data-errormessage-value-missing="Person Status is required!"
                                           class=""
                                           name="person_status" 
                                           id="person_status1" 
                                           value="1"  />
                                    <label for="active">Active</label>
                                    <span style="margin-right: 30px"></span>
                                    <input type="radio" 
                                           data-errormessage-value-missing="Person Status is required!"
                                           class=""
                                           name="person_status" 
                                           id="person_status2" 
                                           value="4" />
                                    <label for="inactive">Inactive</label>
                                </div>

                                <script>
                                document.forms['userForm'].elements['person_status'].value = '<?php
                                    if (set_value('person_status')) {
                                        echo set_value('person_status');
                                    } else {
                                        echo $resource_person_info->person_status;
                                    }?>';
                                </script>
                            </div>
                            <span id="person_status_message" style="color:red;"><?php echo form_error('person_status'); ?></span>
                        <?php } ?>
                    </div>
                    <div class="col-sm-12"><br></div>
                    <div class="col-sm-4"></div>
                    <div class="col-sm-2">
                        <a href="<?php echo base_url() ?>manage-teacher"> <span class="green-btn btn btn-default">Cancel </span></a><br/><br/>
                    </div>                    
                    <div class="form-group col-sm-2">
                        <input type="submit" class="green-btn btn btn-default" value=" Update"><br/><br/>
                    </div>
                    <div class="col-sm-4"></div>
                </div>
                <?php echo form_close(); ?>
            </div>
        </div><!-- /.row gray -->
    </div>
</div>
<script>
    document.forms['userForm'].elements['person_country'].value = '<?php
                if (set_value('person_country')) {
                    echo set_value('person_country');
                } else {
                    echo $resource_person_info->person_country;
                }
                ?>';

    populateStates('person_country', 'person_city');

    document.forms['userForm'].elements['person_city'].value = '<?php
                if (set_value('person_city')) {
                    echo set_value('person_city');
                } else {
                    echo $resource_person_info->person_city;
                }
                ?>';

    function checkGenderStatus() {
        document.getElementById('person_gender_message').innerHTML = '';
    }

    function checkPersonStatus() {
        document.getElementById('person_status_message').innerHTML = '';
    }
    setCountryCode();
</script>
<script type="text/javascript" src="<?php echo base_url() ?>front_end_resource/organization/add_teacher_organization.js"></script>
