﻿function placeholderSetup(id) {
	var el = $("#" + id);
	if(!el) return;
	var ph = el.attr("placeholder");
	if( ph && ph != "" ) {
		el.val(ph);
		el.css("color","#555");
		el.is_focused = 0;
		el.focus(placeholderFocus);
		el.blur(placeholderBlur);
    }
}
function placeholderFocus() {
    if(!this.is_focused) {
        this.is_focused = 1;
        this.value = '';
        this.style.color = '#000';
    }
}
function placeholderBlur() {
    var ph = this.getAttribute("placeholder")
    if( this.is_focused && ph && this.value == "" ) {
		this.is_focused = 0;
        this.value = ph;
        this.style.color = '#777';
    }
}
jQuery.preloadImages = function()
{
    var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
    for(var i = a.length -1; i > 0; i--) 
    {
        jQuery("<img>").attr("src", a[i]);
    }
}
function DiaryTab(ID, MaxTab, Act)
{
    $('#DiaryPrevious').unbind("click").click(function(){
        DiaryTab(ID, 3, 0);
    });
    $('#DiaryNext').unbind("click").click(function(){
        DiaryTab(ID, 3, 1);
    });
    var LastID = 0;
    if(document.getElementById('DiaryLastID'))
        LastID = document.getElementById('DiaryLastID').value;
    if(arguments.length == 2)
        LastID = 0;
    $.ajax({
        url: "Handlers/DiaryBox.ashx",
        data: "Tab=" + ID + "&Act=" + Act + "&LID=" + LastID,
        cache: false,
        success: function(html){
            $("#DiaryContent").html(html);
        },
        error: function () {
            $("#DiaryContent").html();
        },
        beforeSend: function(){
            LoadingBar('DiaryContent');
        },
        complete: function()
        {
            for(i = 0; i <= MaxTab; i++)
            {
                $("#Tab" + i + " > a").removeClass();
            }
            $("#Tab" + ID + " > a").attr('class', 'Act');
        }
    });
}
function AgendaTab(ID, MaxTab, ContentID)
{
    $.ajax({
        url: "Handlers/AgendaBox.ashx",
        data: "Tab=" + ID + "&ID=" + ContentID,
        cache: false,
        success: function(html){
            $("#AgendaBox").html(html);
        },
        error: function () {
            $("#AgendaBox").html("");
        },
        beforeSend: function(){
            LoadingBar('AgendaBox');
        },
        complete: function()
        {
            for(i = 0; i <= MaxTab; i++)
            {
                $("#AgendaTab" + i).removeClass();
                $("#AgendaTab" + i).addClass("AgendaTabOff");
            }
            $("#AgendaTab" + ID).attr('class', 'AgendaTab');
        }
    });
}
function LoadingBar(ID)
{
    $("#" + ID).html("<div class=\"Loading\"><img src=\"Image/ajax-loader.gif\" /></div>");
}
function OpenSubmenu(Sub, Disp)
{
    document.getElementById(Sub).style.display = Disp ? 'block' : 'none';
}
