﻿$().ready(function () {
    setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
var ClassLink = "";
var Landing = true;
function checkAnchor() {
    if (currentAnchor != document.location.hash) {
        currentAnchor = document.location.hash;

        if (!currentAnchor) {
            if (!Landing) {                
                window.location = document.location.href;
            }
            query = "";
        }
        else {
            Landing = false;
            var splits = currentAnchor.substring(1).split('&');

            var section = splits[0];
            delete splits[0];

            var params = splits.join('&');
            var query = "section=" + section + params;

            var PageID = getParamValue(splits[1]);

            if (section == "Pages") {
                if (PageID == 4) {
                    window.location = "Laws.aspx";
                    return;
                }
                if (PageID == 11) {
                    window.location = "News.aspx";
                    return;
                }
                if (PageID == 12) {
                    window.location = "Vacancies.aspx";
                    return;
                }
                if (PageID == 13) {
                    window.location = "Tenders.aspx";
                    return;
                }
                if (PageID == 16) {
                    window.location = "NewsPaper.aspx";
                    return;
                }
                if (PageID == 18) {
                    window.location = "Complain.aspx";
                    return;
                }
            }


            if (splits.length == 3) {
                var Menu = getParamValue(splits[2]);

                if (document.getElementById(Menu).style.display == "none") {
                    SlideMenu(Menu);
                }
            }
            

            $.ajaxSetup({ cache: false });

            $("#Content").empty().html('<div style="text-align:center;height:600px;background-color:#FFF;margin-top:20px;"><br /><br /><br /><br /><br /><img src="images/ajax-loader.gif" algin="center" /></div>');

            $.post(section + ".aspx", query, function (data) {
                $("#Content").html(data);
            });


            if (section == "Pages") {
                if (ClassLink != "") {
                    $("#" + ClassLink + "_Link").removeClass("link-selected");
                    $("#" + ClassLink + "_Link").css("line-height", "30px");
                    $("#" + PageID + "_Link").addClass("link-selected");
                    $("#" + PageID + "_Link").css("line-height", "25px");
                    ClassLink = PageID;
                }
                else {
                    $("#" + PageID + "_Link").addClass("link-selected");
                    $("#" + PageID + "_Link").css("line-height", "25px");
                    ClassLink = PageID;
                }
            }

            NewsHeader();           
        }
    }
}

function NewsHeader() {
    document.getElementById("Menu_BG").style.backgroundImage = "url(Images/right-menu-bottom-news.png)";
    document.getElementById("Menu_BG").style.height = "119px";

    GetLatestNews();
}

function getParamValue(str) {
    var sp = str.split('=');
    return sp[1];
}

function SlideDiv(id, GroupID) {
    if (document.getElementById(id).style.display == "none") {
        $("#" + id).slideDown(500);
        $("#" + GroupID).css("border-bottom", "0");
    }
    else {
        $("#" + id).slideUp(500);
        $("#" + GroupID).css("border-bottom", "1px dotted #CCCCCC");
    }
}

function GetEvent(id) {
    $.ajaxSetup({ cache: false });
    $("#Event-Content").empty().html('<img src="images/ajax-loader.gif" algin="center" />');

    var query = "EID=" + id;
    $.post("Event.aspx", query, function (data) {
        $("#Event-Content").html(data);
    });
}

function SlideMenu(id) {
    if (document.getElementById(id).style.display == "none") {
        $("#" + id).slideDown(500);        
    }
    else {
        $("#" + id).slideUp(500);
    }
}

function GetLatestNews() {
    $.ajaxSetup({ cache: false });
    $("#Event-Content").empty().html('<img src="images/ajax-loader.gif" algin="center" />');
    
    $.post("LatestNews.aspx", "", function (data) {
        $("#Right_1").html(data);
    });
}
