/*
Author: 	huangjb.cn@gmail.com
Time:   	2009-12-07
Function:
	Add a mask into the form field
	When the field get focus, remove the mask
	If nothing input, show the mask again
*/
(function($){
	$.fn.extend({ 
		inputMaskText: function( mask ){
			return this.each(function(){
				var obj = $(this);
				var v = obj.attr( "value" );
				if( $.trim( v ) == "" ){
					obj.attr( "value", mask );
				}
				
				obj.focus(function(){
					var o = $(this);
					var v = o.attr( "value" );
					if( $.trim( v ) == mask ){
						o.attr( "value", "" );
					}
				});
				obj.blur(function(){
					var o = $(this);
					var v = o.attr( "value" );
					if( $.trim( v ) == "" ){
						o.attr( "value", mask );
					}
				});
			});
		},
		inputMaskPassword: function( mask ){
			return this.each(function(){
				var obj = $(this);
				var inputText = $("<input type='text' />");
				var id = "id"+parseInt(Math.random()*10000)+parseInt(Math.random()*10000);
				var klass = obj.attr( "class" );
				inputText.attr( "id", id );
				inputText.attr( "name", id );
				inputText.attr( "value", mask );
				inputText.attr( "class", klass );
				
				var v = obj.attr( "value" );
				var v = $.trim( v );
				if( v == "" ){
					obj.hide();
				}
				inputText.insertBefore( obj );
				inputText.focus(function(){
					inputText.hide();
					obj.show();
					obj.focus();
				});
				obj.blur(function(){
					var v = obj.attr( "value" );
					if( $.trim( v ) == "" ){
						obj.hide();
						inputText.show();
						inputText.attr( "value", mask );
					}
				});
				
			});
		},
		inputMask: function( mask ){
			return this.each(function(){
				var obj = $(this);
				if( $.trim( obj.attr( "type" ) ) == "password" ){
					obj.inputMaskPassword( mask );
				}else{
					obj.inputMaskText( mask );
				}
			});
		}
	});	
})(jQuery);


(function($){
	$.fn.extend({ 
		backTips: function( content ,img){
			var obj = $(this);
			xOffset = 40;
			yOffset = 10;
			t=0;
			$(this).hover(function(e){
				$("body").append("<img src='"+img+"' class='tipsview'  id='tipsview2' />");
				$("#tipsview2")
				 .css("top",(e.pageY - xOffset+15) + "px")
				 .css("left",(e.pageX + yOffset) + "px");
				$("body").append("<div style='width:170px;margin-left:0;padding:5px;' class='tipsview1 tipsview' id='tipsview'></div>");
				$("#tipsview")
				 .css("top",(e.pageY - xOffset) + "px")
				 .css("left",(e.pageX + yOffset+27) + "px")
				 .append(content)
				 .fadeIn("slow");
				var h=$("#tipsview").height();
				if( h<50 ){
					$("#tipsview").css("height",50+"px");
				}else{
					t=(h-50)/2;
					$("#tipsview").css("top",(e.pageY - xOffset-t) + "px");
				}
				
			},
			function(){
				t=0;
				$(".tipsview").remove();
			}); 
			$(this).mousemove(function(e){
				$("#tipsview")
				 .css("top",(e.pageY - xOffset-t) + "px")
				 .css("left",(e.pageX + yOffset+27) + "px");
				 $("#tipsview2")
				 .css("top",(e.pageY - xOffset+15) + "px")
				 .css("left",(e.pageX + yOffset) + "px");
			});
		}
	});	
})(jQuery);

