﻿
function RegisterkeywordService(keyword, tolerance, dymCount, total, literal, path) {
    var parameters = "{'phrase':'" + keyword + "','count':'" + dymCount + "'}";
    
    if (parseInt(total) <= parseInt(tolerance)) {
        
        $.ajax(
                    {
                        url: "KeywordDictionary.asmx/GetPotentialKeywords",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: parameters,
                        success: function(displayKeywords) {
                            str = displayKeywords.d.toString().split('|');
                            for (i = 0; i < str.length; i++) {
                                literal.innerHTML += "<li> <a href='" + path + "?Keyword=" + str[i] + "'>" + str[i] + "</a> </li>   ";
                                literal.innerHTML.trimEnd();
                                if (str.length > 0) {
                                    if (str[0] != '') {
                                        document.getElementById('divh').innerHTML = "Did you mean?";
                                    }
                                }
                                else {
                                    document.getElementById('divh').innerHTML = "";
                                }
                            }
                            $('.didyoumean').show();
                        },
                        error: function(xhr, desc, exceptionobj) { errorCallback(xhr, desc, exceptionobj); }
                    });
    }
}

function errorCallback(xhr,desc,exceptionobj){
    alert(xhr.ResponseText);
}

