/*   
 * @Author              : Kazol 
 * @CreatedDate         : 22-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : 
 * @Description         : The function is used for getting the child topic of the parent topic
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : topic_type, url
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function getChildTopic(parent_topic_id, url, id) {
    if(id == 'parent_topic_id'){
        if(parent_topic_id != ''){
            $('#parent_topic_id_error').hide();
        }else{
            $('#parent_topic_id_error').show();
            $('#parent_topic_id_error').html('This field is required');
        }
    }
    if (parent_topic_id !== '') {
        $.ajax({
            url: url,
            type: 'post',
            data: {parent_topic_id: parent_topic_id},
            success: function (responseData) {
                //console.log(responseData);
                $("#video_course_child_topic").show();
                $("#video_course_child_topic").html(responseData);
            }
        });
    }
}

/*   
 * @Author              : Kazol 
 * @CreatedDate         : 22-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : 
 * @Description         : The function is used for other topic from child topic
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : topic
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function getOtherTopic(topic) {
    if (topic === 'other') {
        $('.other_topic').show();
    } else {
        $('.other_topic').hide();
    }
}
/*   
 * @Author              : Kazol 
 * @CreatedDate         : 22-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : 
 * @Description         : The function is used for open the price input box if clicked paid
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : coursePaymentType
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function getVideoCoursePaymentType(coursePaymentType, id) {
    if(id == 'video_course_payment_type'){
        if(coursePaymentType != ''){
            $('#video_course_payment_validation').hide();
        }else{
            $('#video_course_payment_validation').show();
            $('#video_course_payment_validation').html('This field is required');
        }
    }
    if (coursePaymentType === '2') {
        console.log(coursePaymentType);
        $('#video_course_price_view').show();
        
    } else if (coursePaymentType === '1') {
        $('#video_course_price_view').hide();
        
    }
}

/*   
 * @Author              : Kazol 
 * @CreatedDate         : 22-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : search-admin-video-course
 * @Description         : The function is used for search language by ajax in video course add
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : 
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
$(document).ready(function () {
    $(document).on('keyup', "#search_language_id", function () {
        viewLanguage();
    });   
});

/*   
 * @Author              : Kazol 
 * @CreatedDate         : 22-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : search-admin-video-course-language
 * @Description         : The function is used for search video course language
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : 
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function viewLanguage() {
    var languageName = $("#search_language_id").val().trim();
    var baseUrl = $("#baseUrl").val();
    $.post(baseUrl + 'search-admin-video-course-language',
            {
                language_name: languageName

            },
            function (data) {
                if (data === 'no_data') {
                    $("#searchResult").html('No Result Found');
                } else {
                    //console.log(data);
//                var jsonData = JSON.parse(data);
//                
                    //var languageDetails = $.parseJSON('{ "name": "John" }');
                    //console.log(languageDetails.name);
//                var tt = json_decode(data);
//                console.log(tt);
                    $('#searchResult').show();
                    $("#searchResult").html(data);
//               var languageDetails = JSON.parse(data);
//                console.log(languageDetails);
                    //var languageName = data.language_name;
//                $("#language_ID").val(languageDetails.language_id);
                    //$("#search_language_id").autocomplete({ source: languageName });
                }
            });

}
/*   
 * @Author              : Kazol 
 * @CreatedDate         : 01-08-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : check-admin-video-course-url
 * @Description         : The function is used for checking the the Url existence
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : 
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
$("#video_course_title").keyup(function(){
    var baseUrl = $("#baseUrl").val();
    var val = $(this).val();
    var result = val.toLowerCase();
    var url_value = result.replace(/[^\w]+/g, "-");
    $("#video_course_url").val(url_value);
    console.log(url_value);
    $.post(baseUrl + 'check-admin-video-course-url',
            {
                video_course_url: url_value
            },
            function (data) {
                //console.log(data);
                if(data === 'found'){
                    $("#url_error").show();
                    $("#url_error").html('Url Alrady Exist');
                }else{
                    $("#url_error").hide();
                }
                
            });    
});
/*   
 * @Author              : Kazol 
 * @CreatedDate         : 23-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : 
 * @Description         : The jquery function is used for get the value of video course title and make the video course url
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : 
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
$("#video_course_url").keyup(function(){
    //var val = $(this).val();
    //var result = val.toLowerCase();
    var url_value = $(this).val();
    var video_url_value = url_value.replace(/[^\w]+/g, "-");
    $("#video_course_url").val(video_url_value);
    var baseUrl = $("#baseUrl").val();
    //console.log(url_value);
    $.post(baseUrl + 'check-admin-video-course-url',
            {
                video_course_url: video_url_value
            },
            function (data) {
                //console.log(data);
                if(data === 'found'){
                    $("#url_error").show();
                    $("#url_error").html('Url Alrady Exist');
                }else{
                    $("#url_error").hide();
                }
                
            });       
});

//function validate_video_course(){
//    var video_course = $('#search_language_id').val();
//    if(video_course === ''){
//        $('#video_course_language_validation_id').html('This field is required');
//    }else{
//        $('#video_course_language_validation_id').html('');
//    }
//}
/*   
 * @Author              : Kazol 
 * @CreatedDate         : 03-08-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : 
 * @Description         : This function is used for hide and show language error message
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : language, id
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function language_validation(language, id){
    if(id == 'search_language_id'){
        if(language != ''){
            $('#video_course_language_validation_id').hide();
        }else{
            $('#video_course_language_validation_id').show();
            $('#video_course_language_validation_id').html('This field is required');
        }
    }
    
}
/*   
 * @Author              : Kazol 
 * @CreatedDate         : 03-08-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : 
 * @Description         : This function is used for hide and show price error message
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : price_value, id
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function check_price_validation(price_value, id){
    if(id == 'video_course_price'){
        if(price_value != ''){
            if(price_value < 0 ){
                $('#video_course_price_error').show();
                $('#video_course_price_error').html('Input positive number');
            }else{
                if (price_value.match(/[a-z!@#$%^&*()_+-]/i)) {
                    $('#video_course_price_error').show();
                    $('#video_course_price_error').html('Input valid number');
                }else{
                    $('#video_course_price_error').hide();
                }
            }
            //$('#video_course_price_error').hide();
        }else{
            $('#video_course_price_error').show();
            $('#video_course_price_error').html('This field is required');
        }
    }
    
}
/*   
 * @Author              : Kazol 
 * @CreatedDate         : 03-08-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : 
 * @Description         : This function is used for hide and show  error message
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : value, id
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function add_edit_admin_video_course_validation(value, id){
    if(id == 'video_course_title'){
        if(value != ''){
            $('#video_course_title_error').hide();
        }else{
            $('#video_course_title_error').show();
            $('#video_course_title_error').html('This field is required');
        }
    }
    if(id == 'video_course_upload_video_type'){
        if(value != ''){
            $('#video_course_upload_video_type_error').hide();
        }else{
            $('#video_course_upload_video_type_error').show();
            $('#video_course_upload_video_type_error').html('This field is required');
        }
    }
    if(id == 'other_topic_id'){
        if(value != ''){
            $('#other_topic_id_error').hide();
        }else{
            $('#other_topic_id_error').show();
            $('#other_topic_id_error').html('This field is required');
        }
    }
    if(id == 'resource_person_id'){
        if(value != ''){
            $('#resource_person_id_error').hide();
        }else{
            $('#resource_person_id_error').show();
            $('#resource_person_id_error').html('This field is required');
        }
    }
    if(id == 'video_course_skill_level'){
        if(value != ''){
            $('#video_course_skill_level_error').hide();
        }else{
            $('#video_course_skill_level_error').show();
            $('#video_course_skill_level_error').html('This field is required');
        }
    }
    if(id == 'video_course_access_level'){
        if(value != ''){
            $('#video_course_access_level_error').hide();
        }else{
            $('#video_course_access_level_error').show();
            $('#video_course_access_level_error').html('This field is required');
        }
    }
    if(id == 'video_course_publication_status'){
        if(value != ''){
            $('#video_course_publication_status_validation').hide();
        }else{
            $('#video_course_publication_status_validation').show();
            $('#video_course_publication_status_validation').html('This field is required');
        }
    }
    
}
  