////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 7/2/2010 ELL
// Revised: 3/23/2021	ELL
// Added highlighting of last row selected.

var param_array = {'popup_msg_type' : 1, 'status_msg' : '', 'popup_timeout' : -1};
var popup_msg = new PopupMsg(param_array);

window.parent.document.title = document.title;

function OpenHelpWindow()
{
	window.open(http + "breezewebsitebuilder.com/docs/cms/help.html#restore_page_select", "Help", "scrollbars=1,resizable=1,status=0,toolbar=0,menubar=0,location=0,height=700,width=800");
}

//////////////////////////////////////////////////////////////
function DeleteConfirm(page_name, ID)
{
	popup_msg.top_offset = 0;
	popup_msg.left_offset = 300;
	popup_msg.popup_msg_type = 3;
	popup_msg.popup_btn_cnt = 2;
	popup_msg.msg_width = 450;
	popup_msg.popup_msg_cell = RESTORE_PAGE_DELETE_BACKUP_CONFIRM_1_MSG + " <b>" + page_name + "</b> " + RESTORE_PAGE_DELETE_BACKUP_CONFIRM_2_MSG;
	popup_msg.popup_button_2_span = YES_WORD;
	popup_msg.popup_button_1_span = NO_WORD;
	popup_msg.popup_timeout = -1;
	popup_msg.ShowPopupMsg();
	document.getElementById("popup_button_2_span").onclick = function () { DeletePageFromHistory(page_name, ID); };
	document.getElementById("popup_button_1_span").onclick = function () { popup_msg.HidePopupMsg(); };
}

function DeletePageFromHistory(page_name, ID)
{
	popup_msg.HidePopupMsg();
	var url = "delete_from_history.php?ID=" + ID + "&page_name=" + page_name;
	window.location = url;
}

////////////////////////////////////////////////////////////////////
function RestoreConfirm(page_name, ID)
{
	popup_msg.top_offset = 0;
	popup_msg.left_offset = 300;
	popup_msg.popup_msg_type = 3;
	popup_msg.popup_btn_cnt = 2;
	popup_msg.msg_width = 450;
	popup_msg.popup_msg_cell = RESTORE_PAGE_RESTORE_PAGE_CONFIRM_1_MSG + " <b>" + page_name + "</b> " + RESTORE_PAGE_RESTORE_PAGE_CONFIRM_2_MSG;
	popup_msg.popup_button_2_span = YES_WORD;
	popup_msg.popup_button_1_span = NO_WORD;
	popup_msg.popup_timeout = -1;
	popup_msg.ShowPopupMsg();
	document.getElementById("popup_button_2_span").onclick = function () { RestorePage(page_name, ID); };
	document.getElementById("popup_button_1_span").onclick = function () { popup_msg.HidePopupMsg(); };
}

function RestorePage(page_name, ID)
{
	popup_msg.HidePopupMsg();
	var url = "restore_page.php?ID=" + ID + "&page_name=" + page_name;
	window.location = url;
}

/////////////////////////////////////////////////////////////////////////////////
function SelectPage(page_name)
{
	var url = "restore_page_select.php?page_name=" + page_name;
	window.location = url;
}

/////////////////////////////////////////////////////////////////////////////////
function DisplayArchivedContent(ID)
{
	popup_msg.popup_msg_type = 1;
	popup_msg.status_msg = EDITOR_PREPARING_PREVIEW_MSG;
	popup_msg.popup_timeout = 2000;
	popup_msg.top_offset = 0;
	popup_msg.left_offset = 500;
	popup_msg.ShowPopupMsg();
	$.post( "preview_archive_init.php", { ID: ID } ).done(function( data ) { CompleteDisplayArchivedContent(data, ID); } ) ;
}
function CompleteDisplayArchivedContent(data, ID)
{
	var JSON_row = JSON.parse(data);
	var page_name = JSON_row.page_name;
	var special = JSON_row.source;
	
	HighlightCurRow(ID);

	var preview_page_string = "preview_page.php?page_name=" + page_name + "&special=" + special + "&mode=restore&blog_id=0&restore_id=" + ID;
	window.open(preview_page_string, "Preview", "scrollbars=1,resizable=1,status=0,toolbar=0,menubar=0,location=0,height=900,width=1000");
}

function HighlightCurRow(ID)
{
	var page_rows = document.getElementsByClassName('cur_row');
	for (var i = 0; i < page_rows.length; i++)
	{
		page_rows[i].className = '';
	}
	var row_id = 'row_' + ID;
	document.getElementById(row_id).className = 'cur_row';
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
function ResizeWorkspace(mainWidth, mainHeight, menuWidth, headerHeight) {

}

function DisplayNotSavedMessage(btn)	{
	// Needed to complete call when deleting unsaved page.
	window.parent.SetWorkSavedNotSaved(true);
	window.parent.next_btn = btn;
	window.parent.DoNextClick();
}