/**
  * create by huofei 2008-11-10
  * desc: 用来显示提示用户输入信息
  */
//function initPrompt(obj) {
//	//$("div.prompt").remove();
//	for(var i = 0; i < obj.length; i ++) {
//		var o = obj.eq(i);
//		if ($.trim(o.val()) == "") {
//			createPromptDiv(o);
//		}
//	}
//}
//
//function createPromptDiv(obj) {
//	var div=$("<div class='prompt'>提示</div>");
//	//div.css("border", "1px solid #548F0E");
//	//div.css("background", "#e6ffe6");
//	div.css("position", "absolute");
//	div.css("color", "gray");
//	var pos=obj.offset();
//	div.width(obj.width());
//	div.height(obj.height());
//	div.css("top", pos.top + 1);
//	div.css("left", pos.left + 3);
//	div.text(obj.attr("prompt"));
//	obj.after(div);
//	div.bind("click",function() {
//		div.hide();
//		obj.click();
//		obj.focus();
//	});
//	obj.bind("blur",function() {
//		if ($.trim($(this).val()) == "") {
//			div.show();
//		}
//	});
//	obj.bind("focus", function() {
//		div.hide();
//	});	
//}
$(document).ready(function() {
	initPrompt($(":text[@prompt]"));
	$(document).bind("click", function() {
		$(":text[@prompt]").each(function () {
			if ($(this).val() != "" && $(this).val() != $(this).attr("prompt")) {
				$(this).css("color", "");
			}
		});
	});
	$(document).bind("keyup", function() {
		$(":text[@prompt]").each(function () {
			if ($(this).val() != "" && $(this).val() != $(this).attr("prompt")) {
				$(this).css("color", "");
			}
		});
	});
});

function initPrompt(obj) {
	obj.each(function() {
		if ($(this).val() == "" || $(this).val() == $(this).attr("prompt")) {
			$(this).css("color","gray"); 
			$(this).val($(this).attr("prompt"));
		} else {
			$(this).css("color", "");
		}
		
		$(this).bind("focus", function() {
			if ($(this).val() == $(this).attr("prompt")) {
				$(this).val("");
			}
			$(this).css("color",""); 
		});
		
		$(this).bind("click", function() {
			if ($(this).val() == $(this).attr("prompt")) {
				$(this).val("");
			}
			$(this).css("color",""); 
		});
		
		$(this).bind("blur", function() {
			if ($(this).val() == "" || $(this).val() == $(this).attr("prompt")) {
				$(this).css("color","gray"); 
				$(this).val($(this).attr("prompt"));
			} else {
				$(this).css("color", "");
			}
		});
		if($.browser.msie) {
			this.onpropertychange = function() {
				//alert("change1");
				if ($(this).val() == $(this).attr("prompt")) {
					$(this).css("color","gray"); 
				} else {
					$(this).css("color", "");
				}
			};
		} else {
			this.addEventListener("input", function() {
				//alert("change2");
				//$("#test001").html($("#test001").html() + $(this).val() + "<br/>");
				if ($(this).val() == $(this).attr("prompt")) {
					$(this).css("color","gray"); 
				} else {
					$(this).css("color", "");
				}
			}, false);
		}
	});
}

function checkPromptText(form) {
	var promptTexts;
	if (form) {
		promptTexts = $("input[@prompt]", form);
	} else {
		promptTexts = $("input[@prompt]");
	}
	for(var i = 0; i < promptTexts.length; i ++) {
		var promptText = promptTexts.eq(i);
		if (promptText.val() == promptText.attr("prompt")) {
			promptText.val("");
		}
	}
}

/*
    功能：修改 window.setTimeout，使之可以传递参数和对象参数
    使用方法： setTimeout(回调函数,时间,参数1,,参数n)
*/
//var __sto = setTimeout;
//window.setTimeout = function(callback,timeout,param)
//{
//    var args = Array.prototype.slice.call(arguments,2);
//    var _cb = function()
//    {
//        callback.apply(null,args);
//    }
//    
//    __sto(_cb,timeout);
//}

