/**
* A custom combination of Text2Pass & clearField
 */
/*
 *  Text2Pass 0.8
 *	@author	Peter Vahaviolos, http://taledo.com.au
 *	@date 	Mar 20, 2010
 *	@requires	jquery.js
 *
 *	jquery.Text2Pass.js plugin
 *	On load, this script replaces a password field with a temporary text field.
 *  The password field then gets restored once a user focuses that field.
 * 	Can be used on multiple password fields per page, each field is it's own instance.
 *
 *	@example $('.pass').Text2Pass("Enter something");
 *
 */
 /**
 * jQuery-Plugin "clearField"
 * 
 * @version: 1.0, 31.07.2009
 * 
 * @author: Stijn Van Minnebruggen
 *          stijn@donotfold.be
 *          http://www.donotfold.be
 * 
 * @example: $('selector').clearField();
 * @example: $('selector').clearField({ blurClass: 'myBlurredClass', activeClass: 'myActiveClass' });
 * 
 */
 
 
(function($) {

jQuery.fn.clearField = function() {
		
	jQuery(this).each(function() {

		var el = jQuery(this);

		if(el.attr('type') == 'password') {
				
				el.attr('rel', 'pw');
				
				var obj = el;
				
				function getValue() {
					return (obj.val() && obj.val()!="") ? obj.val() : options.text
				}
				
				// Common input attributes to preserve. Add or delete attributes as desired
				var attributes = [
					"id","align","disabled","maxlength","readonly","size","class","accesskey","tabindex","dir","lang","style","value","title","xml:lang","onblur","onchange","onclick","ondblclick","onfocus","onmousedown","onmousemove","onmouseout","onmouseover","onmouseup","onkeydown","onkeypress","onkeyup","onselect" 
				]
										
				var newInput = jQuery("<input />");
				
				//Retrive element attributes and add them to our new input placeholder
				for(attribute in attributes){
					if(jQuery(this).attr(attributes[attribute]) != "undefined"){
						jQuery(newInput).attr(
							attributes[attribute], 
							jQuery(this).attr(attributes[attribute])
						);
					}
				}
				
				newInput.attr({ 
					type: "text",
					value: getValue()
				})

				//Events
				newInput.bind({
					"focusin": function(event) {

						$(this).replaceWith(obj);
						obj.val("").focus().focus() //2nd focus for IE

					}
				})

				jQuery(this).replaceWith(newInput);

		} else {

			if(el.attr('rel') == undefined) {
				el.attr('rel', el.val());
			}
	
			el.focus(function() {
				if(el.val() == el.attr('rel')) {
					el.val('');
				}			
			});
			
			el.blur(function() {			
				if(el.val() == '') {
					el.val(el.attr('rel'));
				} 			
			});		
		
		}
		
	});
	
	return jQuery;
	
};

})(jQuery);



jQuery(document).ready(function(){
	jQuery('.clearField').clearField();	
});