﻿$(document).ready(function() {
    var tmpURL = window.location.href;
    var regexS = "[\\?&]err=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(tmpURL);
    if (results != null) {
        $("div#" + results[1]).addClass("highlight");
    }

    if (tmpURL.charAt(tmpURL.length - 1) == "/") {
        tmpURL = tmpURL.substring(0, tmpURL.length - 1);
    }

    var lastSlash = tmpURL.lastIndexOf("/");
    if (lastSlash != -1 && (lastSlash + 1) < tmpURL.length) {
        var searchS = tmpURL.substring(lastSlash + 1);
        var questionMarkPos = searchS.indexOf("?");
        if (questionMarkPos != -1) {
            searchS = searchS.substring(0, questionMarkPos);
        }

        if (searchS.charAt(searchS.length - 1) == "/") {
            searchS = searchS.substring(0, searchS.length - 1);
        }

        var checkFirstLink = $("li.CategoryItem a.selected");
        var t1 = checkFirstLink.text();
        if (t1.indexOf(searchS) == -1) {
            $("a[href*='" + searchS + "'][name^='SubCategoryLink']").addClass("selected");
            $("a[href*='" + searchS + "'][name^='SubCategoryLink']").parent().find("div").removeClass("hide");
            $("a[href*='" + searchS + "'][name^='SubCategoryLink']").parent().find("div").addClass("show");
        }
    }
});