/*
 * 
	bm_ui
	place to centralize UI tasks, like formating and enabling and disabling input control
 */

;(function($){

var $$;


$$ = $.fn.bm_ui = function($options) {
	// set default options
	var $defaults = {
		productid   : 0
	};
	
	// extend the options
	var $opts = $.extend($defaults, $options);
	
	// bring the options to the jquery object
	for (var i in $opts) {
		$.bm_ui[i]  = $opts[i];
	}
};


$.extend({bm_ui : {
	//Capitalized items act as constants
	//the goal is to have as few element names as possible imbedded in the code.
	colorscheme : "WHITE",
	BOX_COLOR_DARK : "#306141", //-20 rgb
	BOX_COLOR_LIGHT : "#708161", //+20 rgb
	BOX_COLOR : "#506141", //sync with tab box-color
	DEFAULT_USERNAME : "enter your username or email",
	DEFAULT_PASSWORD : "enter your password",
	DEFAULT_EMAIL : "enter your email",
	DEFAULT_CITY : "enter your city",
	DEFAULT_MEASUREMENT_SCALE : "inches",
	DEFAULT_WEIGHT_SCALE : "pounds",
	ERROR_COLOR : "#DAA520", //GoldenRod
	EDITING_NOTHING : 0,
	EDITING_USERNAME : 1,
	EDITING_PASSWORD : 2,
	EDITING_EMAIL : 3,
	EDITING_CITY : 4,
	EDITING_COMMENTS : 5,
	EDITING_EXISTING_PASSWORD : 6,
	EDITING_NEW_PASSWORD : 7,
	EDITING_CONFIRM_NEW_PASSWORD : 8,
	EDITING_FIRST_NAME : 9,
	EDITING_LAST_NAME : 10,
	EDITING_PREFERENCES_UPDATE_PASSWORD_BUTTON : 11,
	EDITING_LOGIN_REMEMBER_ME : 12,
	HIGHLIGHT:"red", /* used in the utility highlight */
	INPUT_COLOR : "#FFFFFF", //default background color for input control
	KEY_TAB : 9,
	KEY_ENTER : 13,
	KEY_SPACE : 32,
	KEY_PAGE_UP : 33,
	KEY_PAGE_DOWN : 34,
	KEY_LEFT_ARROW : 37,
	KEY_UP_ARROW : 38,
	KEY_RIGHT_ARROW : 39,
	KEY_DOWN_ARROW : 40,
	SUCCESS : 0,
	TEMPLATE_COLOR : "#FAFAD2", //default background color
	color_scheme : "WHITE",
	current_focus : null,
	current_edit_mode : 0,
	cancel_event : false,
	template : "HOME_PAGE",
	title : "",
	toggleInput : function(eCheck,eChange)
	{
		//This function allows a change in eCheck (checkbox input control) 
		//to change the disabled state of an eChange
		//Echange can be an input element or a class. 
		if ($(eCheck).attr("checked"))
		{
			$.bm_ui.formatInputEnabled(eChange);
		} else
		{
			$.bm_ui.formatInputDisabled(eChange);
		}
	},
	checkboxReverse : function(event,e,pbMouseClick)
	{
		if ($.bm_ui.cancel_event){$.bm_ui.cancel_event=false;return}
		//Reverse a checkbox value based on a checkbox container click or space bar event
		var iKey = getKeystroke(event);
		//Put the div parents of checkboxs in the tab order in tab.html and toggle checked value on space bar keypress. 
		//Necessary because check boxes weren't entering the tab order in firefox 
		if (iKey == $.bm_ui.KEY_SPACE || pbMouseClick)
		{
			if (!$(e).children("input").attr("checked")) {$(e).children("input").attr("checked",true);} else
			{$(e).children("input").attr("checked",false)}
		}
	},
	formatInputEnabled : function(e)
	{
		$(e).attr("disabled","");
		return;
		$(e).css("backgroundColor",$.bm_ui.INPUT_COLOR);
		$(e).css({"border-style":'inset'});
		//alert("border-style "+$(e).css("border-style"));
		$(e).css({"border-right-width":"2px"});
		$(e).css({"border-right-color":"#306141"});
		$(e).css({"border-bottom-width":"2px"});
		$(e).css({"border-bottom-color":"#306141"});

		$(e).css({"border-top-width":"2px"});
		$(e).css({"border-top-color":$.bm_ui.BOX_COLOR_DARK});
		$(e).css({"border-left-width":"2px"});

		$(e).css({"border-left-color":$.bm_ui.BOX_COLOR_DARK});

		//$(e).css({"border-color":"red"});
	},
	formatInputDisabled : function(e)
	{
		//NB Move to interface class //
		$(e).attr("disabled","disabled");
		return;
		$(e).css("background-color","transparent");
		$(e).css({"border": "1px solid grey"});
	},
	setCursor : function(psState)
	{
		document.body.style.cursor = psState;
	},
	highlight : function(psElementId)
	{ //used to highlight screen elements as part of the help
		try{
			var e = document.getElementById(psElementId);
			e.style.zIndex = "500";
			e.style.borderColor=$.bm_ui.HIGHLIGHT;
		} catch(err)
		{errorHandler("highlight "+psElementId,err)}
	},
	unhighlight : function(psElementId,piZindex)
	{
		try{
			var e; 
			if (piZindex == "" || piZindex == null)
			{
				piZindex == "100";
			}	
			e = document.getElementById(psElementId);
			e.style.borderColor="transparent";
			if (!ie)
			{
				e.style.zIndex = piZindex;
			}
		} catch(err)
			{errorHandler("unhighlight "+psElementId,err)}
	}
}
})

})(jQuery);


