
var editorWindow = null;



function changeLanguage(languageID)
{
    
}


/**
* loginForm()
*
* Function to open login form.
*/
function loginForm()
{
    $.ajax({
        type: "POST",
        url: "index.php",
        data: ({
                page        : 'login_controller',
                Action      : 'get_login_form'
              }),
        success: function(data)
        {
            $.facebox(data);
        }
    });
}


function logout()
{
    $.ajax({
        type: "POST",
        url: "index.php",
        data: ({
                page        : 'login_controller',
                Action      : 'logout'
              }),
        success: function(data)
        {
            location.href = document.location;
        }
    });
}


/**
* openSystemManagement()
*
* Function to open system management page
* to the browser.
*
* @author   Mika Hakkarainen
*
* @date     2010.07.xx
* @version  0.1
*/
function openSystemManagement()
{
    location.href = "?page=settings&Action=edit";
}


/**
* editOwnProfile()
*
* Function to show a dialog to edit user's own profile.
*
*/
function editOwnProfile()
{
    $.ajax({
        type: "POST",
        url: "index.php",
        data: ({
                page        : 'user_management',
                Action      : 'get_profile_form'
              }),
        success: function(data)
        {
            $.facebox(data);
        }
    });
}



function profileFormSaved(data)
{
    editOwnProfile();
}



/**
* openTinyMCE()
*
*
* Function to open the content of the page to the TinyMCE editor.
* Set also url of the page to the session variable so it is
* available on the editor page to header the user back to the page
* under edit.
*
* @author   Mika Hakkarainen
*
* @date     2010.05.22
* @version  0.1
*
* @param    string  contentName
*           Name of the content to edit
*
* @param    integer language
*           Id of the selected language
*/
function openTinyMCE(contentName, language, editorType, height, width)
{
    /* TÄMÄ EI TOIMI NIIN KUIN PITÄISI - SIKSI LAITETTU TRUE, JOTTA IKKUNA AUKEAA: */
    if (!editorWindow || true)
    {        
        /*
        * Open the content manager:
        */
        editorWindow = window.open("?page=contentmanager&contentName=" + contentName + "&language=" + language + "&type=" + editorType + "&height=" + height + "&width=" + width, "TinyMCE",
                    config="location=0,status=0,scrollbars=0,width=790,height=690");
    }
    /*
    * If editor window is already opened, show message to the user:
    */
    else
    {
        $.facebox("<strong>Editori-ikkuna vaikuttaisi olevan jo auki</strong> - tarkista onko se esimerkiksi jollain v&auml;lilehdell&auml; tai piilossa toisten ikkunoiden alla.");
    }
}


/**
* refreshContent()
*
*
*/
function refreshContent(contentID, data)
{
    $(contentID).html(data);
}


function initEditContentMenu()
{
    /*
    * Show edit content menu when mouse is over editable content:
    */
    $('.pageContentDiv').mouseover(function() {
        $('.editIcon_' + this.id).css('display', 'block');
    });
    
    $('.editContentIconDiv').mouseover(function() {
        $(this).css('display', 'block');
    });
    
    /*
    * Hide edit content menu when mouse is out of the editable content:
    */
    $('.pageContentDiv').mouseout(function() {
        $('.editIcon_' + this.id).css('display', 'none');
    });
}


$(document).ready(function() {
        
    initEditContentMenu();
            
});
