﻿    var id = 0;
    
    var InitialSearchColour = "#999999";
    
    
    
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;    
  } else if( document.body && ( document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;    
  } else if( document.documentElement && (document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;    
  }
  return  scrOfY ;
}    

$(document).ready(function() { 


    $("table.Category p a").attr("target","_blank"); 

    var _docHeight = document.height || document.body.offsetHeight;
    var _windowHeight = document.documentElement.clientHeight
    var theHeight = 0;
    if (_docHeight>_windowHeight)
    {
        theHeight = _docHeight;
    }
    else
    {
        theHeight = _windowHeight;
    }
    
    $("#PopUpBackground").css("height",(theHeight+15) + "px");
    $("#PopUpControls").css("margin-left","-370px");
    $("#PopUpControls").css("margin-top","-200px");    
    

    $("#Header #SearchBox input").val(InitialSearchText);
    $("#Header #SearchBox input").css("color",InitialSearchColour);
    
    $("#Header #SearchBox input").focus(function(){
        if ($(this).val()==InitialSearchText)
        {
            $(this).val("");        
        }
        $(this).css("color","#404040");
    });

    $("#Header #SearchBox input").blur(function(){
        if ($(this).val()=="")
        {
            $(this).val(InitialSearchText);            
        }        
        $(this).css("color",InitialSearchColour);
    });

    $("#Content .BreadCrumbs li a:not(:last)").append(" >>");
    $("#Footer #FooterLinks ul li:not(:last)").append("|");

    $("span.UserPosts[Posts='Pink']").css("background-image","url(img/UserIconPink.gif)");

    if ($("#PopUpEnabled")!=null)
    {
        if ($("#PopUpEnabled").val()=="true")
        {
            $("#PopUpControls").css("visibility","visible");
            $("#PopUpBackground").css("visibility","visible");
        }
    }

    $("a.Add").click(function(e){
        e.preventDefault();
        $("#PopUpControls").css("visibility","visible");
        $("#PopUpBackground").css("visibility","visible");        
        id = $(this).attr("id");
        
        $("#PopUpControls").css("margin-top", (getScrollY()-200) + "px");    
        
    });

    $("a.Close").click(function(e){
        e.preventDefault();
        $("#PopUpControls").css("visibility","hidden");
        $("#PopUpBackground").css("visibility","hidden");
        $(".ErrorMessage").remove();
        $("#PopUpEnabled").remove();
    });


        
    // add a topic    
    $("#btnAddTopic").click(function(e){
        e.preventDefault();
        // check that something has been added to the text boxes
        var elt = $(this);        
        var subj = _CleanHTML($("#tbxTopicSubject").val());
        var topc = _CleanHTML($("#tbxTopicComment").val());
        
        if ((id>0) & (subj!="") & (topc!=""))
        {
            $.post("__adm/__pt.aspx", {id : id, subj : subj, topc : topc}, function(txt){
                if (txt=="###NOTSIGNEDIN###")                
                { 
                    alert("You are no longer signed in, please sign in and try again");
                }
                else if (txt=="##ERROR##")
                {}
                else
                {
                    // add to the page
                    $("#tbxTopicSubject").val("");
                    $("#tbxTopicComment").val("");
                    // or postback
                    window.location.reload();
                }
            });
        }
    });
    
    
    $("#btnAddComment").click(function(e){
        e.preventDefault();
        // check that something has been added to the text boxes
        var elt = $(this);        
        var cmt = _CleanHTML($("#tbxComment").val());
  
        if ((id>0) & (cmt!=""))
        {
            $.post("__adm/__pc.aspx", {id : id, cmt : cmt}, function(txt){
                if (txt=="###NOTSIGNEDIN###")                
                { 
                    alert("You are no longer signed in, please sign in and try again");
                }
                else if (txt=="##ERROR##")
                {}
                else
                {
                    // add to the page                    
                    $("#tbxComment").val("");
                    // or postback
                    window.location.reload();
                }
                
            });
        }
    });
    
    $(".ShowComment").click(function(e){
        e.preventDefault();
        // check that something has been added to the text boxes
        var elt = $(this);        
        var commentID = elt.attr("commentID");
  
        if (commentID>0)
        {
            $.post("__adm/__show.aspx", {id : commentID}, function(txt){
                if (txt=="###NOTSIGNEDIN###")                
                { 
                    alert("You are no longer signed in, please sign in and try again");
                }
                else if (txt=="##ERROR##")
                {}
                else
                {
                    // or postback
                    window.location.reload();
                }
                
            });
        }
    });
    
    
    
    $(".DeleteComment").click(function(e){
        e.preventDefault();
        // check that something has been added to the text boxes
        var elt = $(this);        
        var commentID = elt.attr("commentID");
  
        if (commentID>0)
        {
            $.post("__adm/__del.aspx", {id : commentID}, function(txt){
                if (txt=="###NOTSIGNEDIN###")                
                { 
                    alert("You are no longer signed in, please sign in and try again");
                }
                else if (txt=="##ERROR##")
                {}
                else
                {
                    // or postback
                    window.location.reload();
                }
                
            });
        }
    });    
    
});

function _CleanHTML(sent)
{
    if (sent!="")
    {
        sent = sent.replace(/&/g,"&amp;");
        sent = sent.replace(/</g,"&lt;");
        sent = sent.replace(/>/g,"&gt;");
        
    }

    return sent;
}