/*****************************************************************
* 功能：搜索提示字符串
* 参数：
	 elementId:要提示的元素id
	 text:提示文字
******************************************************************/
function initInputText(elementId, text) {
	var obj = $("#" + elementId);
	if($.trim(obj.val()) == "") {
		obj.val(text);
	}
	obj.blur(function() {
		if($.trim(obj.val()) == "") {
			$(this).val(text);
		}
	});
	obj.focus(function() {
		if($.trim(obj.val()) == text) {
			$(this).val("");
		}
	});
}
/*****************************************************************
* 功能：选择所有checkbox
* 参数：
	  elementId:触发全选事件的元素
	  obj:包含checkbox的容器
******************************************************************/
function checkAll(elementId, obj) {
	$("#" + elementId).click(function() {
		if($(this).attr("checked")) {
			$(obj + " input[type=checkbox]").attr("checked", "true");
		} else {
			$(obj + " input[type=checkbox]").removeAttr("checked");
		}
	});
}

/*****************************************************************
* 功能：测试元素的值是否为空
* 参数：
	  elementId:触发全选事件的元素
	  msg:提示信息
******************************************************************/
function isEmpty(elementId, msg) {
	if($.trim($("#" + elementId).val()) == "") {
		$("#" + elementId).focus();
		alert(msg);
		return true;
	} else {
		return false;
	}
}

/*****************************************************************
* 功能：测试元素的值是否为0
* 参数：
	  elementId:触发全选事件的元素
	  msg:提示信息
******************************************************************/
function isZero(elementId, msg) {
	if($.trim($("#" + elementId).val()) == 0) {
		$("#" + elementId).focus();
		alert(msg);
		return true;
	} else {
		return false;
	}
}


/*****************************************************************
* 功能：获取文件的扩展名
* 参数：
	  path:文件路径
******************************************************************/
function getFileExtension(path) {
	return path.substring(path.lastIndexOf("."), path.length).toLowerCase();
}

/*****************************************************************
* 功能：缩放图片
******************************************************************/
jQuery.fn.resizeImg = function(options) {
	options = $.extend({
		src: $(this).attr("src"),
		width: 120,
		height: 90
	}, options);
	var _self = this;
	var img = new Image();
	$(img).attr("src", options.src);
	
	if (img.width > options.width || img.height > options.height) {
		if (img.width / options.width > img.height / options.height) {
			$(this).width(options.width);
			$(this).height(img.height / (img.width / options.width));
		} else {
			$(this).height(options.height);
			$(this).width(img.width / (img.height / options.height));
		}
	}
};

