/**
* This file is part of the easy-CMS project.
* easy-CMS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* 
* easy-CMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with easy-CMS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/**
* This file contains scripts used by the easy-CMS user-interface.
*
*/

/*
function openWindow(url, width, height, options) {
  var top  = (screen.height-height)/2;
  var left = (screen.width-width)/2;
  window.open(url,'','top='+top+',left='+left+',width='+width+',height='+height+','+options);
}
*/


var selectedContentId;
var selectedContentTypeName;
var selectedContentContainerId;
var selectedContainerId;
var selectedContainerCloneId;
var selectedContainerTypeName;
var selectedContainerContainersListId;
var selectedMenuId;
var selectedContainersListId;
var selectedPageId;
var selectedNodeId;
var selectedNodeParentId;
var selectedNodeMenuId;
var selectedNodePageId;


function selectContent(contentId, typeName, containerId) {
	selectedContentId = contentId;
	selectedContentTypeName = typeName;
	selectedContentContainerId = containerId;
}

function selectContainer(containerId, cloneId, typeName, containersListId) {
	selectedContainerId = containerId;
	selectedContainerCloneId = cloneId;
	selectedContainerTypeName = typeName;
	selectedContainerContainersListId = containersListId;
}

function selectContainersList(containersListId) {
	selectedContainersListId = containersListId;
}

function selectPage(pageId) {
	selectedPageId = pageId;
}

function selectNode(menuId, menuNodeId, parentNodeId, pageId) {
	selectedNodeId = menuNodeId;
	selectedNodeParentId = parentNodeId;
	selectedNodeMenuId = menuId;
	selectedNodePageId = pageId;
}


function contentMenuMoveBottomOption() {
	window.location.href = '/index.php?display=edit_container&action=move_content_bottom&container_id='+selectedContentContainerId+'&content_id='+selectedContentId;
}

function contentMenuMoveTopOption() {
	window.location.href = '/index.php?display=edit_container&action=move_content_top&container_id='+selectedContentContainerId+'&content_id='+selectedContentId;
}

function contentMenuMoveDownOption() {
	window.location.href = '/index.php?display=edit_container&action=move_content_down&container_id='+selectedContentContainerId+'&content_id='+selectedContentId;
}

function contentMenuMoveUpOption() {
	window.location.href = '/index.php?display=edit_container&action=move_content_up&container_id='+selectedContentContainerId+'&content_id='+selectedContentId;
}

function contentMenuRemoveOption() {
	launchContentDeletionWindow('container_id='+selectedContentContainerId+'&content_id='+selectedContentId+'&type_name='+selectedContentTypeName);
}

function contentMenuEditOption() {
	launchContentEditionWindow('container_id='+selectedContentContainerId+'&content_id='+selectedContentId+'&type_name='+selectedContentTypeName);
}


function containerMenuAddOption() {
	launchContentEditionWindow('container_id='+selectedContainerCloneId+'&content_id=0&type_name='+selectedContainerTypeName);
}

function containerMenuMoveDownOption() {
	window.location.href = '/index.php?display=edit_containers_list&action=move_container_down&container_id='+selectedContainerId+'&containers_list_id='+selectedContainerContainersListId;
}

function containerMenuMoveUpOption() {
	window.location.href = '/index.php?display=edit_containers_list&action=move_container_up&container_id='+selectedContainerId+'&containers_list_id='+selectedContainerContainersListId;
}

function containerMenuRemoveOption() {
	launchContainerDeletionWindow('container_id='+selectedContainerId);
}

function containerMenuEditOption() {
	launchContainerEditionWindow('container_id='+selectedContainerId);
}


function containersListMenuAddGalleryOption() {
	launchContainerEditionWindow('containers_list_id='+selectedContainersListId+'&container_id=0&container_type=1');
}

function containersListMenuAddOption() {
	launchContainerEditionWindow('containers_list_id='+selectedContainersListId+'&container_id=0');
}

function containersListMenuEditOption() {
	launchContainersListEditionWindow('containers_list_id='+selectedContainersListId);
}


function pageMenuAddOption() {
	launchPageEditionWindow('parent_id='+selectedPageId);
}

function pageMenuRemoveOption() {
	launchPageDeletionWindow('page_id='+selectedPageId);
}

function pageMenuEditOption() {
	launchPageEditionWindow('page_id='+selectedPageId);
}


function nodeMenuAddOption() {
	launchPageEditionWindow('parent_id='+selectedNodePageId);
}

function nodeMenuMoveBottomOption() {
	window.location.href = '/index.php?display=edit_menu&action=move_page_bottom&menu_id='+selectedNodeMenuId+'&parent_id='+selectedNodeParentId+'&node_id='+selectedNodeId;
}

function nodeMenuMoveTopOption() {
	window.location.href = '/index.php?display=edit_menu&action=move_page_top&menu_id='+selectedNodeMenuId+'&parent_id='+selectedNodeParentId+'&node_id='+selectedNodeId;
}

function nodeMenuMoveDownOption() {
	window.location.href = '/index.php?display=edit_menu&action=move_page_down&menu_id='+selectedNodeMenuId+'&parent_id='+selectedNodeParentId+'&node_id='+selectedNodeId;
}

function nodeMenuMoveUpOption() {
	window.location.href = '/index.php?display=edit_menu&action=move_page_up&menu_id='+selectedNodeMenuId+'&parent_id='+selectedNodeParentId+'&node_id='+selectedNodeId;
}

function nodeMenuRemoveOption() {
	launchPageDeletionWindow('page_id='+selectedNodePageId);
}

function nodeMenuEditOption() {
	launchPageEditionWindow('page_id='+selectedNodePageId);
}



function launchUserEditionWindow(vars) {
  openWindow('/index.php?'+'display=edit_user&mode=ask_modif_user&'+vars,540, 600, 0, 0);
}

function launchPageEditionWindow(vars) {
  openWindow('/index.php?'+'display=edit_page&mode=ask_modif_page&'+vars,540, 600, 0, 0);
}

function launchPageDeletionWindow(vars) {
  openWindow('/index.php?'+'display=edit_page&mode=ask_delete_page&'+vars,380, 280, 0, 0);
}

function launchContainersListEditionWindow(vars) {
  openWindow('/index.php?'+'display=edit_containers_list&mode=ask_modif_containers_list&'+vars,540, 600, 0, 0);
}

function launchMenuEditionWindow(vars) {
  openWindow('/index.php?'+'display=edit_menu&mode=ask_modif_menu&'+vars,540, 600, 0, 0);
}

function launchContainerEditionWindow(vars) {
  openWindow('/index.php?'+'display=edit_container&mode=ask_modif_container&'+vars,540, 600, 0, 0);
}

function launchContainerDeletionWindow(vars) {
  openWindow('/index.php?'+'display=edit_container&mode=ask_delete_container&'+vars,380, 280, 0, 0);
}

function launchVersionEditionWindow(vars) {
  openWindow('/index.php?'+'display=edit_version&mode=ask_modif_content&'+vars,540, 600, 0, 0);
}

function launchContentEditionWindow(vars) {
  openWindow('/index.php?'+'display=edit_content&mode=ask_modif_content&'+vars,540, 600, 0, 0);
}

function launchContentDeletionWindow(vars) {
  openWindow('/index.php?'+'display=edit_content&mode=ask_delete_content&'+vars,380, 280, 0, 0);
}

function launchLogonWindow() {
  openWindow('/login.php?'+'mode=ask_logon',250, 200, 0, 0);
}

function launchChooseFileWindow(vars) {
  openWindow('/admin/choose_file.php?'+'mode=ask_choose_file&'+vars,400, 420, 0, 0);
}

function launchRenameFileWindow(vars) {
  openWindow('/admin/rename_file.php?'+'mode=ask_rename_file&'+vars,300, 200, 0, 0);
}

function launchDeleteFileWindow(vars) {
  openWindow('/admin/delete_node.php?'+'mode=ask_delete_file&'+vars,300, 150, 0, 0);
}

function launchChoosePageWindow(vars) {
  openWindow('/admin/choose_page.php?'+'mode=ask_choose_page&'+vars,250, 300, 0, 0);
}

function launchCreateNodeWindow(vars) {
  openWindow('/admin/create_node.php?'+'mode=ask_create&'+vars,300, 150, 0, 0);
}