﻿/*
	文件说明：本文件是对jQuery功能的扩展
	创建时间：2014-7-23
	创建者：雍文兵
	修订记录：
		1. 2014-7-23,初始创建
*/
(function($)
{
	$.extend({
		/*
			函数说明：主要是对输入框进行说明，当输入框没有输入任何值时，点击输入框清除说明文字，相反亦然。
			创建时间：2014-7-23
			创建者：雍文兵
			修订记录：
				1. 2014-7-23,初始创建
		*/
		tips:function() {
			$("input[tip]").focus(function(){
				if($(this).val()!=''&&$(this).val()==$(this).attr('tip')){
					$(this).val('').css('color','#3c3c3c');
				}
				if($(this).val()!=''&&$(this).val()!=$(this).attr('tip')){
					$(this).css('color','#3c3c3c');
				}
			});
			$("input[tip]").blur(function(){
				if($(this).val()==''||$(this).val()==$(this).attr('tip')){
					$(this).val($(this).attr('tip')).css('color','#cccccc');
				}
			});
			$('input[tip]').each(function(i){
				if($(this).val()==''||$(this).val()==$(this).attr('tip')){
					$(this).val($(this).attr('tip')).css('color','#cccccc');
				}
			}); 
		},
		/*
			函数说明：在JS文件中导入其他文件。
			创建时间：2014-7-23
			创建者：雍文兵
			修订记录：
				1. 2014-7-23,初始创建
		*/
		ruijie_import:function(path) {
			
			var elem;
			var head=document.head || document.getElementsByTagName("head")[0] || document.documentElement;
				
			if (/.js$/i.test(path)){
				elem = document.createElement("script");
				elem.setAttribute("type", "text/javascript");
				elem.setAttribute("src", path);
				head.appendChild(elem);				
			}
			
			if (/.css$/i.test(path)){
				var elem;
				elem = document.createElement("link");
				elem.setAttribute("rel", "stylesheet");
				elem.setAttribute("type", "text/css");
				elem.setAttribute("href", path);
				head.appendChild(elem);	
			}
		}	
	});
	
	$.fn.extend({
		eleObjsBindEvent:function(type, func){
			var objs = $(this);
			var selector = $(this).selector;
			for(var i=0; i<objs.length; i++)
			{
				(function(index)
				{
					$(selector+':eq('+index+')').bind(type, function()
					{
						var page = 0;
						var idx = 0;
						if (typeof($('#goToPage').val())!='undefined'){
							page=parseInt($('#goToPage').attr('crrVal'))-1;
							maxNum=parseInt($('#goToPage').attr('entry'))
							idx = index + (page*maxNum);
						}
						else{
							idx = index;
						}

						return func(idx);
					});
				})(i);
			}
		},	
		/*
			type: event, 例如: click, dbclick
			func:回调函数
			pgtHtm:页面中第几个翻页，用来获取指定页码数。 
		*/
		eleObjsLiveEvent:function(type, func, pgtHtm){
			var objs = $(this);
			var selector = $(this).selector;
			
			objs.parent().parent().siblings().css('font-weight','normal');

			for(var i=0; i<objs.length; i++)
			{
				(function(index)
				{
					$(selector+':eq('+index+')').live(type, function()
					{
						var page = 0;
						var idx = 0;
						var gpobj=$('input[id="goToPage"]');
						//翻页表单绑定事件
						if (gpobj.length>0){
							if (typeof(pgtHtm)!='undefined'){
								page=parseInt($('#goToPage', pgtHtm).attr('crrVal'))-1;
								maxNum=parseInt($('#goToPage', pgtHtm).attr('entry'));
								idx = index + (page*maxNum);
							}else{
								page=parseInt(gpobj.attr('crrVal'))-1;
								maxNum=parseInt(gpobj.attr('entry'));
								idx = index + (page*maxNum);
							}
						}
						else{//普通呈现表单绑定事件
							idx = index;
						}
						
						$(this).parent().parent().css('font-weight','bold').siblings().css('font-weight','normal');
						return func.call(this, idx);
					});
				})(i);
			}
		},
		eleObjsunLiveEvent:function(type){
			var objs = $(this);
			var selector = $(this).selector;
			
			objs.parent().parent().siblings().css('font-weight','normal');
			
			for(var i=0; i<objs.length; i++)
			{
				(function(index)
				{
					$(selector+':eq('+index+')').die(type);
					
				})(i);
			}
		},
		tip:function(){
			$("input[tip]").focus(function(){
				if($(this).val()!=''&&$(this).val()==$(this).attr('tip')){
					$(this).val('').css('color','#3c3c3c');
				}
				if($(this).val()!=''&&$(this).val()!=$(this).attr('tip')){
					$(this).css('color','#3c3c3c');
				}
			});
			$("input[tip]").blur(function(){
				if($(this).val()==''||$(this).val()==$(this).attr('tip')){
					$(this).val($(this).attr('tip')).css('color','#cccccc');
				}
			});
			$('input[tip]').each(function(i){
				if($(this).val()==''||$(this).val()==$(this).attr('tip')){
					$(this).val($(this).attr('tip')).css('color','#cccccc');
				}
			}); 
		}
	});
	
})(jQuery);/*end hidden function*/

$(document).ready(function(){
	$.tips();						   
});