////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 12/30/2018
//
function CheckForBATLoginTable()
{
	$.post( "check_for_bat_login_table.php", {   } ).done(function( data ) { CompleteCheckForBATLoginTable(data); } ) ;
}
function CompleteCheckForBATLoginTable(data)
{
	if (data > 0)
		document.getElementById("save_to_bat_btn").style.display = "block";
	else
		document.getElementById("save_to_bat_btn").style.display = "none";
}

function EditBatLogin()
{
	var form_bottom = 850 - document.body.scrollHeight;
	document.getElementById("edit_bat_login_frm_div").style.bottom = form_bottom + "px";
	document.getElementById("edit_bat_login_frm_div").style.display = "block";
	$.post( "get_bat_login.php", { } ).done(function( data ) { CompleteGetBATLogin(data); } ) ;
}
function CompleteGetBATLogin(data)
{
	if (data == -1)
		return;
	
	login_creds = data.split("@@@@@");
	document.getElementById("user_name").value = login_creds[0];
	document.getElementById("password").value = login_creds[1];
}

function SaveBATLogin()
{
	var user_name = document.getElementById("user_name").value;
	var password = document.getElementById("password").value;
	$.post( "save_bat_login.php", { user_name: user_name, password: password  } ).done(function( data ) { CompleteSaveBATLogin(data); } ) ;
	document.getElementById('edit_bat_login_frm_div').style.display = 'none';
}
function CompleteSaveBATLogin(data)
{
	if (data == 1)
		popup_msg.status_msg = EDIT_CSS_UPDATE_COMPLETE_MSG;
	else if (data == 0)
		popup_msg.status_msg = EDIT_PAGE_NO_CHANGE;
	else
		popup_msg.status_msg = EDIT_PAGE_UPDATE_FAILED;
	popup_msg.top_offset = 100;
	popup_msg.left_offset = 320;
	popup_msg.popup_msg_type = 2;
	popup_msg.popup_timeout = 500;
	popup_msg.ShowPopupMsg();
	
	setTimeout("CheckForBATLoginTable();", 1000);
}

function SaveEventToBat()
{
	var event_id = document.getElementById("event_id").value;
	var location_id = document.getElementById("location_id").value;
	if ((event_id != -1) && (event_id != ""))
		$.post( "save_event_to_bat.php", { event_id: event_id  } ).done(function( data ) { CompleteSaveEventToBat(data, event_id, location_id); } ) ;
}
function CompleteSaveEventToBat(data, event_id, location_id)
{
	if ((data != "") && (data.indexOf("@@@@@") > 0))	{
		var data_arr = data.split("@@@@@");
		popup_msg.status_msg = CALENDAR_EVENTS_SAVE_TO_BAT_RESULT_MSG_1 + " <b>" + event_id + "</b> " + CALENDAR_EVENTS_SAVE_TO_BAT_RESULT_MSG_2 + " <b>" + location_id + "</b> " + CALENDAR_EVENTS_SAVE_TO_BAT_RESULT_MSG_3 + " <b>" + data_arr[0] + "</b> " + CALENDAR_EVENTS_SAVE_TO_BAT_RESULT_MSG_4 + " <b>" + data_arr[1] + "</b>.";
		popup_msg.popup_timeout = 8000;
	}
	else	{
		popup_msg.status_msg = EDIT_PAGE_UPDATE_FAILED;
		popup_msg.popup_timeout = 4000;
	}
	popup_msg.top_offset = 100;
	popup_msg.left_offset = 320;
	popup_msg.popup_msg_type = 2;
	popup_msg.ShowPopupMsg();
}