////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 12/16/2013	ELL

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_params.php?menu=" + menu;
	window.location.href = url;
}

function  LoadOrientationDefaults(orientation)
{
	if (orientation == "vertical")
	{
		if (load_defaults == 1)	{
			document.getElementById("menu_width").value = -1;
			document.getElementById("sub_level_offset_top").value = -5;
			document.getElementById("sub_level_offset_left").value = 80;	
		}
		document.getElementById("menu_width").disabled = true;
		document.getElementById("menu_width_units").disabled = true;
	}
	else if (orientation == "horizontal_fixed_width")
	{
		if (load_defaults == 1)	{
			document.getElementById("menu_width").value = 100;
			document.getElementById("menu_width_units").value = 1;
			document.getElementById("sub_level_offset_top").value = 0;
			document.getElementById("sub_level_offset_left").value = 20;
		}
		document.getElementById("menu_width").disabled = false;
		document.getElementById("menu_width_units").disabled = false;
	}
	else if (orientation == "horizontal_variable_width")
	{
		if (load_defaults == 1)	{
			document.getElementById("menu_width").value = -1;
			document.getElementById("sub_level_offset_top").value = 0;
			document.getElementById("sub_level_offset_left").value = 20;
		}
		document.getElementById("menu_width").disabled = true;
		document.getElementById("menu_width_units").disabled = true;
	}
}

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

function PreloadLocationDefaults(location)
{
	if (location == "header")
	{
		document.getElementById("vertical").style.border = "none";
		document.getElementById("horizontal_fixed").style.border = "solid";
		document.getElementById("horizontal_fixed").style.borderWidth = "3px";
		document.getElementById("horizontal_fixed").style.borderColor = "#FFFF00";
		document.getElementById("horizontal_variable").style.border = "none";
		document.getElementById("offset_top").style.border = "solid";
		document.getElementById("offset_top").style.borderWidth = "3px";
		document.getElementById("offset_top").style.borderColor = "#FFFF00";
		document.getElementById("offset_left").style.border = "solid";
		document.getElementById("offset_left").style.borderWidth = "3px";
		document.getElementById("offset_left").style.borderColor = "#FFFF00";
		document.getElementById("offset_bottom").style.border = "none";
		document.getElementById("offset_right").style.border = "none";
		document.getElementById("absolute").style.border = "solid";
		document.getElementById("absolute").style.borderWidth = "3px";
		document.getElementById("absolute").style.borderColor = "#FFFF00";
		document.getElementById("relative").style.border = "none";
	}
	else if (location == "top")
	{
		document.getElementById("vertical").style.border = "none";
		document.getElementById("horizontal_fixed").style.border = "solid";
		document.getElementById("horizontal_fixed").style.borderWidth = "3px";
		document.getElementById("horizontal_fixed").style.borderColor = "#FFFF00";
		document.getElementById("horizontal_variable").style.border = "none";
		document.getElementById("offset_top").style.border = "solid";
		document.getElementById("offset_top").style.borderWidth = "3px";
		document.getElementById("offset_top").style.borderColor = "#FFFF00";
		document.getElementById("offset_left").style.border = "solid";
		document.getElementById("offset_left").style.borderWidth = "3px";
		document.getElementById("offset_left").style.borderColor = "#FFFF00";
		document.getElementById("offset_bottom").style.border = "none";
		document.getElementById("offset_right").style.border = "none";
		document.getElementById("absolute").style.border = "none";
		document.getElementById("relative").style.border = "solid";
		document.getElementById("relative").style.borderWidth = "3px";
		document.getElementById("relative").style.borderColor = "#FFFF00";
	}
	else if (location == "left")
	{
		document.getElementById("vertical").style.border = "solid";
		document.getElementById("vertical").style.borderWidth = "3px";
		document.getElementById("vertical").style.borderColor = "#FFFF00";
		document.getElementById("horizontal_fixed").style.border = "none";
		document.getElementById("horizontal_variable").style.border = "none";
		document.getElementById("offset_top").style.border = "solid";
		document.getElementById("offset_top").style.borderWidth = "3px";
		document.getElementById("offset_top").style.borderColor = "#FFFF00";
		document.getElementById("offset_left").style.border = "solid";
		document.getElementById("offset_left").style.borderWidth = "3px";
		document.getElementById("offset_left").style.borderColor = "#FFFF00";
		document.getElementById("offset_bottom").style.border = "none";
		document.getElementById("offset_right").style.border = "none";
		document.getElementById("absolute").style.border = "none";
		document.getElementById("relative").style.border = "solid";
		document.getElementById("relative").style.borderWidth = "3px";
		document.getElementById("relative").style.borderColor = "#FFFF00";
	}
	else if (location == "right")
	{
		document.getElementById("vertical").style.border = "solid";
		document.getElementById("vertical").style.borderWidth = "3px";
		document.getElementById("vertical").style.borderColor = "#FFFF00";
		document.getElementById("horizontal_fixed").style.border = "none";
		document.getElementById("horizontal_variable").style.border = "none";
		document.getElementById("offset_top").style.border = "solid";
		document.getElementById("offset_top").style.borderWidth = "3px";
		document.getElementById("offset_top").style.borderColor = "#FFFF00";
		document.getElementById("offset_left").style.border = "none";
		document.getElementById("offset_bottom").style.border = "none";
		document.getElementById("offset_right").style.border = "solid";
		document.getElementById("offset_right").style.borderWidth = "3px";
		document.getElementById("offset_right").style.borderColor = "#FFFF00";
		document.getElementById("absolute").style.border = "none";
		document.getElementById("relative").style.border = "solid";
		document.getElementById("relative").style.borderWidth = "3px";
		document.getElementById("relative").style.borderColor = "#FFFF00";
	}
	else if (location == "bottom")
	{
		document.getElementById("vertical").style.border = "none";
		document.getElementById("horizontal_fixed").style.border = "none";
		document.getElementById("horizontal_variable").style.border = "solid";
		document.getElementById("horizontal_variable").style.borderWidth = "3px";
		document.getElementById("horizontal_variable").style.borderColor = "#FFFF00";
		document.getElementById("offset_top").style.border = "none";
		document.getElementById("offset_left").style.border = "solid";
		document.getElementById("offset_left").style.borderWidth = "3px";
		document.getElementById("offset_left").style.borderColor = "#FFFF00";
		document.getElementById("offset_bottom").style.border = "solid";
		document.getElementById("offset_bottom").style.borderWidth = "3px";
		document.getElementById("offset_bottom").style.borderColor = "#FFFF00";
		document.getElementById("offset_right").style.border = "none";
		document.getElementById("absolute").style.border = "none";
		document.getElementById("relative").style.border = "solid";
		document.getElementById("relative").style.borderWidth = "3px";
		document.getElementById("relative").style.borderColor = "#FFFF00";
	}
	else if (location == "footer")
	{
		document.getElementById("vertical").style.border = "none";
		document.getElementById("horizontal_fixed").style.border = "none";
		document.getElementById("horizontal_variable").style.border = "solid";
		document.getElementById("horizontal_variable").style.borderWidth = "3px";
		document.getElementById("horizontal_variable").style.borderColor = "#FFFF00";
		document.getElementById("offset_top").style.border = "none";
		document.getElementById("offset_left").style.border = "solid";
		document.getElementById("offset_left").style.borderWidth = "3px";
		document.getElementById("offset_left").style.borderColor = "#FFFF00";
		document.getElementById("offset_bottom").style.border = "solid";
		document.getElementById("offset_bottom").style.borderWidth = "3px";
		document.getElementById("offset_bottom").style.borderColor = "#FFFF00";
		document.getElementById("offset_right").style.border = "none";
		document.getElementById("absolute").style.border = "solid";
		document.getElementById("absolute").style.borderWidth = "3px";
		document.getElementById("absolute").style.borderColor = "#FFFF00";
		document.getElementById("relative").style.border = "none";
	}
}

function CheckFormatOnUnitSelect(unit_el_id, length_el_id, offset)
{
	var units = document.getElementById(unit_el_id).value;
	var length = "";		
	if (units < (2 + offset))	{
		length = document.getElementById(length_el_id).value;
		var length_arr = length.split(".");
		document.getElementById(length_el_id).value = length_arr[0];
	}
}

function InitializeForm()
{
	CheckFormatOnUnitSelect("menu_top_units", "menu_top", 0);
	CheckFormatOnUnitSelect("menu_left_units", "menu_left", 0);
	CheckFormatOnUnitSelect("menu_bottom_units", "menu_bottom", 0);
	CheckFormatOnUnitSelect("menu_right_units", "menu_right", 0);
	CheckFormatOnUnitSelect("menu_width_units", "menu_width", 0);
	CheckFormatOnUnitSelect("top_level_item_width_units", "top_level_item_width", 0);
	CheckFormatOnUnitSelect("top_level_item_height_units", "top_level_item_height", 2);
	CheckFormatOnUnitSelect("top_level_padding_top_units", "top_level_padding_top", 0);
	CheckFormatOnUnitSelect("top_level_padding_right_units", "top_level_padding_right", 0);
	CheckFormatOnUnitSelect("top_level_padding_bottom_units", "top_level_padding_bottom", 0);
	CheckFormatOnUnitSelect("top_level_padding_left_units", "top_level_padding_left", 0);
	CheckFormatOnUnitSelect("sub_level_1_item_width_units", "sub_level_1_item_width", 0);
	CheckFormatOnUnitSelect("sub_level_1_item_height_units", "sub_level_1_item_height", 2);
	CheckFormatOnUnitSelect("sub_level_1_padding_top_units", "sub_level_1_padding_top", 0);
	CheckFormatOnUnitSelect("sub_level_1_padding_right_units", "sub_level_1_padding_right", 0);
	CheckFormatOnUnitSelect("sub_level_1_padding_bottom_units", "sub_level_1_padding_bottom", 0);
	CheckFormatOnUnitSelect("sub_level_1_padding_left_units", "sub_level_1_padding_left", 0);
	CheckFormatOnUnitSelect("sub_level_1_offset_top_units", "sub_level_1_offset_top", 0);
	CheckFormatOnUnitSelect("sub_level_1_offset_left_units", "sub_level_1_offset_left", 0);
	CheckFormatOnUnitSelect("sub_level_2_offset_top_units", "sub_level_2_offset_top", 0);
	CheckFormatOnUnitSelect("sub_level_2_offset_left_units", "sub_level_2_offset_left", 0);
	CheckFormatOnUnitSelect("sub_level_2_item_width_units", "sub_level_2_item_width", 0);
	CheckFormatOnUnitSelect("sub_level_2_item_height_units", "sub_level_2_item_height", 2);
	CheckFormatOnUnitSelect("sub_level_2_padding_top_units", "sub_level_2_padding_top", 0);
	CheckFormatOnUnitSelect("sub_level_2_padding_right_units", "sub_level_2_padding_right", 0);
	CheckFormatOnUnitSelect("sub_level_2_padding_bottom_units", "sub_level_2_padding_bottom", 0);
	CheckFormatOnUnitSelect("sub_level_2_padding_left_units", "sub_level_2_padding_left", 0);
	
	CheckFormatOnUnitSelect("top_level_item_spacing_units", "top_level_item_spacing", 0);
	CheckFormatOnUnitSelect("sub_level_1_item_spacing_units", "sub_level_1_item_spacing", 0);
	CheckFormatOnUnitSelect("sub_level_2_item_spacing_units", "sub_level_2_item_spacing", 0);
	
	if (document.getElementById("top_level_item_width").value == _NOT_SET_)
		document.getElementById("top_level_item_width").className = "not_set";
	else
		document.getElementById("top_level_item_width").className = "";
	if (document.getElementById("sub_level_1_item_width").value == _NOT_SET_)
		document.getElementById("sub_level_1_item_width").className = "not_set";
	else
		document.getElementById("sub_level_1_item_width").className = "";
		
	if (document.getElementById("sub_level_2_item_width").value == _NOT_SET_)
		document.getElementById("sub_level_2_item_width").className = "not_set";
	else
		document.getElementById("sub_level_2_item_width").className = "";
		
	if (document.getElementById("top_level_item_height").value == _NOT_SET_)
		document.getElementById("top_level_item_height").className = "not_set";
	else
		document.getElementById("top_level_item_height").className = "";
	if (document.getElementById("sub_level_1_item_height").value == _NOT_SET_)
		document.getElementById("sub_level_1_item_height").className = "not_set";
	else
		document.getElementById("sub_level_1_item_height").className = "";
	if (document.getElementById("sub_level_2_item_height").value == _NOT_SET_)
		document.getElementById("sub_level_2_item_height").className = "not_set";
	else
		document.getElementById("sub_level_2_item_height").className = "";
	if (document.getElementById("menu_top").value == _NOT_SET_)
		document.getElementById("menu_top").className = "not_set";
	else
		document.getElementById("menu_top").className = "";
	if (document.getElementById("menu_left").value == _NOT_SET_)
		document.getElementById("menu_left").className = "not_set";
	else
		document.getElementById("menu_left").className = "";
	if (document.getElementById("menu_bottom").value == _NOT_SET_)
		document.getElementById("menu_bottom").className = "not_set";
	else
		document.getElementById("menu_bottom").className = "";
	if (document.getElementById("menu_right").value == _NOT_SET_)
		document.getElementById("menu_right").className = "not_set";
	else
		document.getElementById("menu_right").className = "";
	if (document.getElementById("sub_level_1_offset_top").value == _NOT_SET_)
		document.getElementById("sub_level_1_offset_top").className = "not_set";
	else
		document.getElementById("sub_level_1_offset_top").className = "";
	if (document.getElementById("sub_level_2_offset_top").value == _NOT_SET_)
		document.getElementById("sub_level_2_offset_top").className = "not_set";
	else
		document.getElementById("sub_level_2_offset_top").className = "";
	if (document.getElementById("sub_level_1_offset_left").value == _NOT_SET_)
		document.getElementById("sub_level_1_offset_left").className = "not_set";
	else
		document.getElementById("sub_level_1_offset_left").className = "";
	if (document.getElementById("sub_level_2_offset_left").value == _NOT_SET_)
		document.getElementById("sub_level_2_offset_left").className = "not_set";
	else
		document.getElementById("sub_level_2_offset_left").className = "";
		
	if (document.getElementById("top_level_item_spacing").value == _NOT_SET_)
		document.getElementById("top_level_item_spacing").className = "not_set";
	else
		document.getElementById("top_level_item_spacing").className = "";
	if (document.getElementById("sub_level_1_item_spacing").value == _NOT_SET_)
		document.getElementById("sub_level_1_item_spacing").className = "not_set";
	else
		document.getElementById("sub_level_1_item_spacing").className = "";
	if (document.getElementById("sub_level_2_item_spacing").value == _NOT_SET_)
		document.getElementById("sub_level_2_item_spacing").className = "not_set";
	else
		document.getElementById("sub_level_2_item_spacing").className = "";
		
	if (document.getElementById("top_level_padding_top").value == _NOT_SET_)
		document.getElementById("top_level_padding_top").className = "not_set";
	else
		document.getElementById("top_level_padding_top").className = "";
	if (document.getElementById("top_level_padding_right").value == _NOT_SET_)
		document.getElementById("top_level_padding_right").className = "not_set";
	else
		document.getElementById("top_level_padding_right").className = "";
	if (document.getElementById("top_level_padding_bottom").value == _NOT_SET_)
		document.getElementById("top_level_padding_bottom").className = "not_set";
	else
		document.getElementById("top_level_padding_bottom").className = "";
	if (document.getElementById("top_level_padding_left").value == _NOT_SET_)
		document.getElementById("top_level_padding_left").className = "not_set";
	else
		document.getElementById("top_level_padding_left").className = "";
		
	if (document.getElementById("sub_level_1_padding_top").value == _NOT_SET_)
		document.getElementById("sub_level_1_padding_top").className = "not_set";
	else
		document.getElementById("sub_level_1_padding_top").className = "";
	if (document.getElementById("sub_level_1_padding_right").value == _NOT_SET_)
		document.getElementById("sub_level_1_padding_right").className = "not_set";
	else
		document.getElementById("sub_level_1_padding_right").className = "";
	if (document.getElementById("sub_level_1_padding_bottom").value == _NOT_SET_)
		document.getElementById("sub_level_1_padding_bottom").className = "not_set";
	else
		document.getElementById("sub_level_1_padding_bottom").className = "";
	if (document.getElementById("sub_level_1_padding_left").value == _NOT_SET_)
		document.getElementById("sub_level_1_padding_left").className = "not_set";
	else
		document.getElementById("sub_level_1_padding_left").className = "";
		
	if (document.getElementById("sub_level_2_padding_top").value == _NOT_SET_)
		document.getElementById("sub_level_2_padding_top").className = "not_set";
	else
		document.getElementById("sub_level_2_padding_top").className = "";
	if (document.getElementById("sub_level_2_padding_right").value == _NOT_SET_)
		document.getElementById("sub_level_2_padding_right").className = "not_set";
	else
		document.getElementById("sub_level_2_padding_right").className = "";
	if (document.getElementById("sub_level_2_padding_bottom").value == _NOT_SET_)
		document.getElementById("sub_level_2_padding_bottom").className = "not_set";
	else
		document.getElementById("sub_level_2_padding_bottom").className = "";
	if (document.getElementById("sub_level_2_padding_left").value == _NOT_SET_)
		document.getElementById("sub_level_2_padding_left").className = "not_set";
	else
		document.getElementById("sub_level_2_padding_left").className = "";
		
	if (document.getElementById("OrientationGroup_0").checked)
		LoadOrientationDefaults('vertical');
	else if (document.getElementById("OrientationGroup_1").checked)
		LoadOrientationDefaults('horizontal_fixed_width');
	else if (document.getElementById("OrientationGroup_2").checked)
		LoadOrientationDefaults('horizontal_variable_width');
}

function SaveMenuParams()
{	
	$.ajax({type:'POST', url: 'save_css_menu_params.php', data:$('#frm_menu_params').serialize(), success: function(response) {
		CompleteSaveMenuParams(response);
	}});
}
function CompleteSaveMenuParams(response)
{
//alert(response);
	if (response == 1)
		popup_msg.status_msg = EDIT_JS_MENU_PARAMETERS_SAVE_SUCCESS_MSG;
	else
		popup_msg.status_msg = EDIT_JS_MENU_PARAMETERS_SAVE_FAIL_ERR;
	popup_msg.popup_msg_type = 1;
	popup_msg.top_offset = 0;
	popup_msg.left_offset = 250;
	popup_msg.popup_timeout = 2000;
	popup_msg.ShowPopupMsg();
}

function TextFieldClick(el)
{
	if (el.value == _NOT_SET_)	{
		el.value = "";
		el.className = "";
	}
}
function TextFieldChange(el)
{
	el.value = el.value.replace(/[a-z]/gi, '');
}
function TextFieldBlur(el)
{
	if (el.value == "")	{
		el.value = _NOT_SET_;
		el.className = "not_set";
	}
}

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