
(function($, undefined) {
	
	function LF() {
		
		// private 
		var _config = {};
		
		// public
		this.setConfig = function(key, val) {
			if(typeof key == "string") {
				key = key.replace(/[^a-zA-Z 0-9]+/g,'');
				lf.log("setting key to " + key);
				_config[key] = val;
			}
		};
		this.getConfig = function(key) {
			return(_config[key]);
		};
		
		this.log = function(msg) {
			if (window.console && console.log) {
				console.log(msg);
			}
		};
		
		this.init = function() {
			// event bindings
			$(document).bind('validationError.adEdit', function() {
			  lf.ad.displayAppropriatePriceInput();
			});
		};


		// general form functions
		this.form = {
			setLabelError: function(elementId) {
				var label = $("label[for="+elementId+"]");
				if(label.html()) {
					label.addClass("label_error");
				}
			},

			updateInputCounter: function(elementId, maxLen, countDownElementId) {
				var el = $("#"+elementId);
				if(el && $("#"+countDownElementId)) {
					if(el.val().length > maxLen) {
						$("#"+countDownElementId).css( { "color": "red" } );
					} else {
						$("#"+countDownElementId).css( { "color": "" } );
					}
					$("#"+countDownElementId).text(maxLen - el.val().length);
				}
			},

			/**
			 * Prevents the user from typing too many characters in an 
			 * input element (specifically for textarea elements since
			 * there is no maxlength attribute for them)
			 */
			limitInputLength: function(element, maxLen, countDownElementId) {
				if (element.value.length > maxLen) {
					$(element).val(element.value.substring(0, maxLen));
				} 
	
				this.updateInputCounter(element, maxLen, countDownElementId);
			}
		};
		// end form object
		
		
		this.feedback =  {
			init: function() {
				$("#submitButtonContainer").click(
					function() {
						$("#buttonSubmit").hide();
						$("#lightBlueSpinny").show();
						$('#feedbackForm').submit();
					}
				);
			}
		};
		// end feedback object
	}

	window.lf = new LF();

})(jQuery);


//catch all document.write() calls
//(function(doc){
//  var write = doc.write;
//  doc.write = function(q){ 
//    lf.log('document.write(): ');
//    lf.log(arguments);
//    if (/docwriteregexwhitelist/.test(q)) {
//    	write.apply(doc,arguments);  
//    }
//  };
//})(document);




