////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 12/3/2014	ELL
// Revised: 3/10/2015	ELL
// Converted deprecated font stretch to letter spacing.
// Revised: 4/5/2015	ELL
// Added font size units.

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 SelectMenu(menu)
{
	var url = "edit_css_menu_styles.php?menu=" + menu;
	window.location.href = url;
}

function popupcolorpicker(form_name, field_name)
{
	var start_color = document.getElementById(field_name).value;
	if (start_color == "")
		start_color = "-not set-";
	else
		start_color = start_color.replace("#", "");
	
	var URL = "colorpicker.php?form_name=" + form_name + "&field_name=" + field_name + "&source_page=edit_css_menu_styles.php&start_color=" + start_color;
	
	window.open (URL, "colorpicker", "alwaysRaised=0,dependent=1,menubar=0,resizable=0,width=450,height=350,scrollbars=0,location=0");
}

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

function CheckLetterSpacing(element, letter_spacing_el_id)
{
	if (((element.value == 0) || (element.value > 14)) && (document.getElementById(letter_spacing_el_id).value != -1000000) && (document.getElementById(letter_spacing_el_id).value != '-not set-') && (document.getElementById(letter_spacing_el_id).value != ''))
	{
		popup_msg.popup_msg_type = 2;
		popup_msg.status_msg = EDIT_CSS_MENU_STYLES_LETTER_SPACING_MSG;
		popup_msg.popup_timeout = -1;
		popup_msg.top_offset = 0;
		popup_msg.left_offset = 250;
		popup_msg.msg_width = 600;
		popup_msg.popup_timeout = 10000;
		popup_msg.ShowPopupMsg();
	}
	
	if ((element.value > 0) && (element.value < 15))
		document.getElementById(letter_spacing_el_id).disabled = false;
	else
		document.getElementById(letter_spacing_el_id).disabled = true;
}

function enable_disable_letter_spacing()
{
	if ((document.getElementById("top_level_letter_spacing_units").value > 0) && (document.getElementById("top_level_letter_spacing_units").value < 15))
		document.getElementById("top_level_letter_spacing").disabled = false;
	else
		document.getElementById("top_level_letter_spacing").disabled = true;
		
	if ((document.getElementById("sub_level_1_letter_spacing_units").value > 0) && (document.getElementById("sub_level_1_letter_spacing_units").value < 15))
		document.getElementById("sub_level_1_letter_spacing").disabled = false;
	else
		document.getElementById("sub_level_1_letter_spacing").disabled = true;
		
	if ((document.getElementById("sub_level_2_letter_spacing_units").value > 0) && (document.getElementById("sub_level_2_letter_spacing_units").value < 15))
		document.getElementById("sub_level_2_letter_spacing").disabled = false;
	else
		document.getElementById("sub_level_2_letter_spacing").disabled = true;
}

function enable_disable_controls()
{
	enable_disable_letter_spacing();
	enable_disable_font_size('top_level_font_size', 'top_level_font_size_units');
	enable_disable_font_size('sub_level_1_font_size', 'sub_level_1_font_size_units');
	enable_disable_font_size('sub_level_2_font_size', 'sub_level_2_font_size_units');
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
function enable_disable_font_size(font_size_el_id, font_size_units_el_id)
{
	var units = document.getElementById(font_size_units_el_id).value;
	var font_size = "";
	
	var no_length_arr = new Array("xx-small","x-small","small","medium","large","x-large","xx-large","smaller","larger","initial","inherit");
	var integer_length_arr = new Array("px","%");
	
	if (no_length_arr.indexOf(units) > -1)
		document.getElementById(font_size_el_id).disabled = true;
	else
		document.getElementById(font_size_el_id).disabled = false;
		
	if (integer_length_arr.indexOf(units) > -1)	{
		font_size = document.getElementById(font_size_el_id).value;
		var font_size_arr = font_size.split(".");
		document.getElementById(font_size_el_id).value = font_size_arr[0];
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
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();
}