/*
* Registration event click
*/
function leftMenuEventClick()
{
    $(".leftMenuButton").click(function()
    {
        $(".leftMenuButtonActive").toggleClass("leftMenuButtonActive");
        $(this).toggleClass("leftMenuButtonActive");
    });
}

function leftMenuAction( leftMenuButton, src )
{
    $(".leftMenuButtonActive").toggleClass("leftMenuButtonActive");
    $(leftMenuButton).toggleClass("leftMenuButtonActive");
    ajaxAction(src);
}

function openAction( src )
{
    location.href = src;
}

function ajaxAction( src )
{
    _ajaxAction(src, "#basicContent", false, "", "");
}

/*
function _ajaxAction( src, destination, pop )
{
    _ajaxAction( src, destination, pop,  "", "");
}

function _ajaxAction( src, destination, pop, formName )
{
    _ajaxAction( src, destination, pop,  formName, "");
}
*/
function _ajaxAction( src, destination, pop, formName, nameFunction )
{
    /*
    * note: simple variant AJAX request;
    $(".basicContent").load(src);
    */
    $.ajax({
        url: src,
        cache: false,
        dataType: 'html',
        async: true,
        data: formName == ""?"":$('#' + formName).serialize(),
        type: 'POST',
        timeout: 120000,
        beforeSend: function( req )
        {
            showWin("#splash");
        },
        success: function( html )
        {
            try
            {
                hideWin("#splash");
                if( html == null || html == "" )
                {
                    $(destination).html("_ajaxAction : 1");
                }
                else
                {
                    $(destination).html("");
                    $(destination).html(html);
                }
            }
            catch( e )
            {
                $(destination).html("_ajaxAction : 2");
            }
        },
        error: function( html, textStatus )
        { 
            hideWin("#splash");
            $(destination).html("Server status : " + textStatus);
            afterAjaxActionErr();
        },
        complete: function (html, type )
        {  
            try
            {
                if (pop){
                    if (nameFunction != "" && nameFunction != null){
                        setTimeout(nameFunction+"()", 0);
                    }
                    else
                    {
                        afterAjaxAction();
                    }
                }
            }catch(e)
            {
                $(destination).html("_ajaxAction : 3");
            }
        }
    });
}
//ajax request without splash
function ajaxhHddenAction( src, destination, pop, nameFunction )
{
    $.ajax({
        url: src,
        cache: false,
        dataType: 'html',
        async: true,
        type: 'POST',
        timeout: 120000,
        success: function( html )
        {
            if( destination != "" && destination != null )
            {
                try
                {
                    $(destination).html("");
                    if( html != null && html != "" )
                    {
                        $(destination).html(html);
                    }
                }
                catch( e )
                {
                    afterAjaxActionErr();
                }
            }
        },
        error: function( html, textStatus )
        {
            afterAjaxActionErr();
        },
        complete: function (html, type )
        {
            try
            {
                if (pop){
                    if (nameFunction != "" && nameFunction != null){
                        setTimeout(nameFunction+"()", 0);
                    }
                    else
                    {
                        afterAjaxAction();
                    }
                }
            }catch(e)
            {
                afterAjaxActionErr();
            }
        }
    });
}

/*override this method in page*/
function afterAjaxAction(){}
/*override this method in page*/
function afterAjaxActionErr(){}

function showWin(winID){ $(winID).show();}
function hideWin(winID){ $(winID).hide();}
function hideWinSlideUp(winID){ $(winID).slideUp(300);}
function hideWinFadeOut(winID){ $(winID).fadeOut(300);}
function showWinWithShadow(winID){$("#shadow").show();$(winID).show();}
function hideWinWithShadow(winID){$("#shadow").hide();$(winID).hide();}

function ajaxActionWithForm( src, formName )
{
    $.ajax({
        url: src,        
        dataType: 'html',
        async: true,
        data: $('#' + formName).serialize(),
        type: 'POST',
        beforeSend: function( req )
        {
            showWin("#splash");
        },
        success: function( html )
        {
            hideWin('#shadow');
            $(".basicContent").html(html);
        },
        error: function( html, textStatus )
        {
            hideWin('#shadow');
            $(".basicContent").html("Server status : " + textStatus);
            afterAjaxActionErr();
        },
        complete: function ( html, type )
        {
            try
            {
                hideWin("#splash");
            }
            catch( e )
            {
                $(basic).html("ajaxActionWithForm : 1");
            }
        }
    });
}

//* functions movie cursor to end string    */
function moveCaretToEnd( inputObject )
{
    if( $.browser.msie )
    {
        if( inputObject.createTextRange )
        {
            var r = inputObject.createTextRange();
            r.collapse(false);
            r.select();
        }
    }
    else
    {
        if( inputObject.selection )
        {
            var end = inputObject.value.length;
            inputObject.setSelectionRange(end, end);
            inputObject.focus();
        }
    }
}
//count down session timer
var startTimerKillSession = false;
var closeSessionAfterMin = 40;
var countSecInMinute = 60;
var intervalSessionID = 0;
var divMinID = "countdownMin";
var divSecID = "countdownSec";
function _killSessionAfterTime()
{
    var _divMin = document.getElementById(divMinID);
    var _divSec = document.getElementById(divSecID);

    if( !startTimerKillSession )
    {
        startTimerKillSession = true;
        if( closeSessionAfterMin - 1 < 10 )
            _divMin.innerHTML = "0" + new String(-- closeSessionAfterMin);
        else
            _divMin.innerHTML = new String(-- closeSessionAfterMin);
    }

    if( countSecInMinute - 1 < 10 )
        _divSec.innerHTML = "0" + new String(-- countSecInMinute);
    else
        _divSec.innerHTML = new String(-- countSecInMinute);

    if( closeSessionAfterMin == 0 && countSecInMinute == 0)
    {
        clearInterval(intervalSessionID);
        return;
    }
    if( countSecInMinute == 0 )
    {
        countSecInMinute = 60;
        if( closeSessionAfterMin - 1 < 10 )
            _divMin.innerHTML = "0" + new String(closeSessionAfterMin--);
        else
            _divMin.innerHTML = new String(closeSessionAfterMin--);
    }
    if( countSecInMinute == 59)
    {
        if( closeSessionAfterMin  < 10 )
            _divMin.innerHTML = "0" + new String(closeSessionAfterMin);
        else
            _divMin.innerHTML = new String(closeSessionAfterMin);
    }

}
function killSessionAfterTime()
{
    var _divMin = document.getElementById(divMinID);
    var _divSec = document.getElementById(divSecID);
    if( closeSessionAfterMin - 1 < 10 )
        _divMin.innerHTML = "0" + new String(closeSessionAfterMin);
    else
        _divMin.innerHTML = new String(closeSessionAfterMin);
    _divSec.innerHTML = new String("00");
    intervalSessionID = setInterval(_killSessionAfterTime, 1000);
}


