function ForNumerOnly(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}
$('.PageAlias').bind('keyup blur', function () {
    $(this).val(function (i, val) {
        return val.toLowerCase().replace(/ /g, '-').replace(/--/g, '-').replace(/[^a-z0-9-]+/g, '');
    });
});

$('.PageAliasTitle').bind('keyup blur', function () {

    var value = $(this).val();
    value = value.toLowerCase().replace(/[^[a-z][0-9][०-९][\u0900-\u097F]\s]/gi, '').replace(/[_\s]/g, '-').replace(/[&*+\\/;"'?/~`#%,]/g, '');
    $("#PageAlias").val(value);
});
function Alias() {
    $('.PageAlias').bind('keyup blur', function () {
        $(this).val(function (i, val) {
            return val.toLowerCase().replace(/ /g, '-').replace(/--/g, '-').replace(/[^a-z0-9-]+/g, '');
        });
    });

    $('.PageAliasTitle').bind('keyup blur', function () {

        var value = $(this).val();
        value = value.toLowerCase().replace(/[^[a-z][0-9][०-९][\u0900-\u097F]\s]/gi, '').replace(/[_\s]/g, '-').replace(/[&*+\\/;"'?/~`#%,]/g, '');
        $("#PageAlias").val(value);
    });
}

$('.textboxrestriction').bind('keyup blur', function () {
    $(this).val(function (i, val) {
        return val.replace(/[^a-zA-Z0-9- ()=+*#$]+/, '');
    });
});
//function Attributesuggestion() {
//    $("#txtAttributeValue").autocomplete({
//        source: function (request, response) {
//            $.ajax({
//                type: "POST",
//                contentType: "application/json; charset=utf-8",
//                url: "/admins/action",
//                data: "{'jsondata':'" + JSON.stringify({ action: $("#hdattributevalue").val(), values: $('#txtAttributeValue').val() }) + "'}",
//                dataType: "json",
//                success: function (Data) {
//                    var dat = JSON.parse(Data.data);
//                    var a = dat['category'];
//                    data = $.parseJSON(Data.data)
//                    console.log(data.Value);
//                    response($.map(data, function (item) {
//                        return {
//                            url: item.URL,
//                            value: item.Value,
//                            category: item.category,
//                            pcategory:item.primarycategory
//                        }
//                    }))
//                },
//                error: function (result) {
//                    alert("Error");
//                }
//            });
//        },
//        select: function (e, ui) {
//            $('#txtblogsearchs').val(ui.item.value);

//        },
//        minLength: 1
//    });
//}
function mySearchFunction(id, postion) {
    // Declare variables 
    var input, filter, table, tr, td, i;
    input = document.getElementById(id);
    filter = input.value.toUpperCase();
    table = document.getElementById("example1");
    tr = table.getElementsByTagName("tr");

    // Loop through all table rows, and hide those who don't match the search query
    for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td")[postion];
        if (td) {
            if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                tr[i].style.display = "";
            } else {
                tr[i].style.display = "none";
            }
        }
    }
}
$("#btnSearchView").click(function () {
    var s1 = $("#txtsearch1").val();
    var s2 = $("#txtsearch2").val();
    var s3 = $("#txtsearch3").val();
    var url = window.location;
    var search = "";
    if (s1 != undefined && s1 != "") {
        search += "&s1=" + s1;
    }
    if (s2 != undefined && s2 != "") {
        search += "&s2=" + s2;
    }
    if (s3 != undefined && s3 != "") {
        search += "&s3=" + s3;
    }
    if (search != "") {
        search = search.substring(1, search.length);
        var url = mergeQueryString(search);
        window.location.href = url;
    }

});
function mergeQueryString(newquerystring) {
    var NQSArray = newquerystring.split('&');
    var url = window.location.href;
    for (i = 0; i < NQSArray.length; i++) {
        var QSArray = NQSArray[i].split('=');
        url = mergeUrlParameter(url, QSArray[0], QSArray[1]);
    }
    return url;
}
function mergeUrlParameter(mainurl, parameter, paravalue) {
    var url = "";

    var vars = [], hash;
    var len = mainurl.indexOf('?');
    var hashes = mainurl;
    var query = "";
    var newQS = "";
    if (len > 1) {
        //len = len - 1;
        hashes = hashes.substring(0, len);
        query = mainurl.substring(len + 1, mainurl.length);


        var hashesparameter = query.split('&');
        var update = 0;
        for (var j = 0; j < hashesparameter.length; j++) {
            hash = hashesparameter[j].split('=');
            if (hash[0] == parameter) {
                update = 1;
                //hash[1] = paravalue;
                newQS += "&" + parameter + "=" + paravalue;
            }
            else {
                newQS += "&" + hash[0] + "=" + hash[1];
            }

        }
        if (update == 0) {
            url = hashes + "?" + newQS.substring(1, newQS.length) + "&" + parameter + "=" + paravalue;
        }
        else {
            url = hashes + "?" + newQS.substring(1, newQS.length);
        }
    }
    else {
        url = mainurl + "?" + parameter + "=" + paravalue;
    }

    return url;

}
$(document).ready(function () {
    if ($("#MessageType").val() == "success") {
        $("#btninfo2").click();
    }
    else if ($("#MessageType").val() == "error") {
        $("#btninfo1").click();
    }
});
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
function updateQueryStringParameter(uri, key, value) {
    var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
    var separator = uri.indexOf('?') !== -1 ? "&" : "?";
    if (uri.match(re)) {
        return uri.replace(re, '$1' + key + "=" + value + '$2');
    }
    else {
        return uri + separator + key + "=" + value;
    }
}

function removeURLParameter(url, parameter) {
    //prefer to use l.search if you have a location/link object
    var urlparts = url.split('?');
    if (urlparts.length >= 2) {

        var prefix = encodeURIComponent(parameter) + '=';
        var pars = urlparts[1].split(/[&;]/g);

        //reverse iteration as may be destructive
        for (var i = pars.length; i-- > 0;) {
            //idiom for string.startsWith
            if (pars[i].lastIndexOf(prefix, 0) !== -1) {
                pars.splice(i, 1);
            }
        }

        url = urlparts[0] + '?' + pars.join('&');
        return url;
    } else {
        return url;
    }
}
