﻿$(document).ready(function()
{
    //List sort
    var firstClick = true;
    ListSortCat = function(elm, catId)
    {
        if(catId == "all")
        {
            $(".caseList > li").css("display", "block");
            $(".caseList > li").addClass("on");
            $(".subMenu li").attr("class", "");
            $(".subMenu li:last-child").attr("class", "selected");
            firstClick = true;
            ListCheckPaging();
        }
        else
        {
            //sub menu
            $(".subMenu li:last-child").attr("class", "");
            //$(elm).attr("class", "selected"); //bliver sat her!!!
            
            //list
            if(firstClick)
            {
                $(".caseList > li").css("display", "none");
                $(".caseList > li").removeClass("on");
                $("." + catId).css("display", "block");
                $("." + catId).addClass("on");
                firstClick = false;
            }
            $(elm).toggleClass("selected");
            //elm.className = (elm.className == "selected") ? "" : "selcted";
            
            if(elm.className == "selected")
            {
                $("." + catId).css("display", "block");
                $("." + catId).addClass("on");
                ListCheckPaging();
            }
            else
            {
                $("." + catId).css("display", "none");
                $("." + catId).removeClass("on");
                ListCheckPaging();
            }
        }
    };
    
    var pStart = 0;
    var pEnd = 9;
    ListCheckPaging = function()
    {
        var list = $(".caseList > li.on");
        
        $(".caseList > li.on:lt(" + pStart + ")").css("display", "none");
        $(".caseList > li.on:gt(" + pEnd + ")").css("display", "none");
        
        //create paging
        $("#paging").html("");
        var html = "<ul>";
        for(var i = 0; i < (list.length / 10); i++)
        {
            var next = i * 10;
            html += "<li onclick=\"ListGoTO(this," + (next) + "," + (next + 9) + " );\"><span>" + (i+1) + "</span></li>";
        }
        html += "</ul>";
        $("#paging").html(html);
        
        $("#paging li:eq(0)").attr("class", "selected");
    };
    
    ListGoTO = function(elm, start, end)
    {
        //pStart = start;
        //pEnd = end;
        //console.log($(".caseList li:lt(" + start + ")").length);
        $("#paging li").attr("class", "");
        $(elm).attr("class", "selected");
        $(".caseList > li.on").css("display", "block");
        $(".caseList > li.on:lt(" + start + ")").css("display", "none");
        $(".caseList > li.on:gt(" + end + ")").css("display", "none");
    };
});


function CommentsClear(elm, checkText)
{
    var text = elm.value;
    for(var i = 0; i < checkText.length; i++)
    {
        if(text == checkText[i])
            elm.value = "";
    }
}

function CommentsAdd(elm)
{
    if(elm.id == "ctl00_ContentPlaceHolder1_ctl00_ctl01_txtName" && elm.value == ""){elm.value = "Name:";}
    if(elm.id == "ctl00_ContentPlaceHolder1_ctl00_ctl01_txtEmail" && elm.value == ""){elm.value = "Email:";}
    if(elm.id == "ctl00_ContentPlaceHolder1_ctl00_ctl01_txtContent" && elm.value == ""){elm.value = "Comment:";}
}
