/**
 * Copy the value of an input field's title attribute to its value attribute.
 * Clear the input field on focus if its value is the same as its title.
 * Repopulate the input field on blur if it is empty.
 * Hide the input field's associated label if it has one.
 */
var autoPopulate = {
	sInputClass:'populate', // Class name for input elements to autopopulate
	sHiddenClass:'structural', // Class name that gets assigned to hidden label elements
	bHideLabels:true, // If true, labels are hidden
	/**
	 * Main function
	 */
	init:function() {
		// Check for DOM support
		if (!document.getElementById || !document.createTextNode) {return;}
		
		var oInput = $('input#q');
		console.log(oInput);
		console.log(oInput.value);
		console.log(oInput.title);
		// If value is empty and title is not, assign title to value
		if ((oInput[0].value == '') && (oInput[0].title != '')) { oInput[0].value = oInput[0].title; }

		// Add event handlers for focus and blur
		oInput.focus(function() {
			// If value and title are equal on focus, clear value
			if (this.value == this.title) {
				this.value = '';
				this.select(); // Make input caret visible in IE
			}
		});
		oInput.blur(function() {
				// If the field is empty on blur, assign title to value
				if (!this.value.length) { this.value = this.title; }
		});		
	
	}
};

/**
 * Init on DOM load.
 */

$(document).ready(function(){
	autoPopulate.init();
});

