/**************************************************************************
 * 所有的数据在预加载的时候，搭建全部结构
 * 显示的时候只负责定位
 *
 * opt 
 * {
 *  flag   : str //标识
 *	width  : xxx
 *	height : xxx
 *	ull / el / word : ?
 *  title : xxx
 *
 *
 *
 *
 *******************************************************************
*/ 

$.extend({
	popup : {
		method : {
			rand : function() {
				var num = Math.random();
				num = num.toString().substr(2,num.toString().length);
				return num;
			},
			gWH : function (stri) {//判断字符的长度和宽度；
				var flag = stri.constructor == String ? true : false;
				if (!flag) {
					return {w : 20, h : 15};
				} else {
					var re = new RegExp('<[/]?[a-zA-Z0-9"\'= :/.()%\d;]+[/]?>','ig');
					stri = stri.replace(/<br>|<br \/>|<br\/>/ig,'+++');		
					stri = stri.replace(re,'');
					var strArr = stri.split('+++');
					var l = 0;
					for (var i = 0; i < strArr.length; i++ ) {
						l = strArr[i].length > l ? strArr[i].length : l;
					}
					return {w:l,h:strArr.length};
				}
			}

		},
		
		//创建结构
		create : function(){
			var html = '<div id="pop_box">';
				html +=		'<iframe id="pop_shadow1" src="about:blank"></iframe>';
				html +=		'<div id="pop_shadow2"><q class="a_1"></q><q class="a_2"></q><q class="a_3"></q><q class="a_4"></q></div>';
				html +=		'<div id="pop_dBox">';
				html +=			'<a id="pop_dclose" href="javascript:void(0)" title="关闭" onclick=$.popup.close()>X</a>';
				html +=			'<h3 id="pop_dTitle"></h3>';
				html +=		'</div>';
				html += '</div>';
			$('body').append(html);

			//存放所有对象
			this.el = {
				box  : $('#pop_box'),
				bg1  : $('#pop_shadow1'),
				bg2  : $('#pop_shadow2'),
				dbox : $('#pop_dBox'),
				dtit : $('#pop_dTitle'),
				close : $('#pop_dclose')
			}
		},
		
		//存放参数
		d : {},

		//调整弹出层结构
		resize : function() {
			var winH = $(window).height();
			var winW = $(window).width();
			this.d.opt.height = this.d.opt.height > winH ? winH : this.d.opt.height;//弹出最大高度不能大于窗口高度
			this.d.opt.width  = this.d.opt.width > winW ? winW : this.d.opt.width;//弹出最大高度不能大于窗口高度
			this.el.box.css({
				width  : this.d.opt.width,
				height : this.d.opt.height
			});
			this.el.bg1.css({
				width  : this.d.opt.width,
				height : this.d.opt.height
			});
			this.el.bg2.css({
				width  : this.d.opt.width,
				height : this.d.opt.height
			});
			this.el.dbox.css({
				width  : this.d.opt.width - 16,
				height : this.d.opt.height - 16,
				overflow : 'hidden',
				border : '1px solid #ccc'
			});
			$('#' + this.d.opt.flag + '_d').css({
				border : 0,
				width  : this.d.opt.width - 16,
				height : this.d.opt.height - 46
			});
		},

		//设置弹出层位置
		setpos : function () {
			var winH = $(window).height();
			var winW = $(window).width();
			var scrollTop  = $('html').scrollTop();
			var scrollLeft = $(window.body).scrollLeft();
			var top  = (winH - this.d.opt.height) / 2 + scrollTop;
			var left = (winW - this.d.opt.width) / 2 + scrollLeft;
			var mid  = (winH-this.d.opt.height) / 2;
			var cent = (winW - this.d.opt.width) / 2;
			if(window.navigator.userAgent.indexOf("MSIE 6.0") > -1) {
				//alert(top);
				this.el.box.css({
					top  : top,
					left : left
				})
			} else {
				this.el.box.css({
					position : 'fixed',
					top  : mid,
					left : cent
				})
			}
		},

		//预载数据 data { url?word?el? : xxx , width : xxx, height : xxx, flag : xxx }
		init : function(opt){
			if (!document.getElementById('pop_box')) {
				this.create();
			};
			if (opt.url) {//链接形式
                this.el.dbox.append('<div id="' + opt.flag + '" style="display:none"><iframe id="' + opt.flag + '_d" src="' + opt.url + '" style="display:none" frameborder="no"></iframe></div>');
				$('#' + opt.flag).prepend('<p id="' + opt.flag + '_loading" style="background:#f0f0f0; padding:1em; text-align:center; color:#888; font-size:14px;"><img src="/image/ico/loading.gif" width="20" class="middle" />&nbsp;您请求的页面正在加载,请稍候...</p>');
                var pop_iframe = document.getElementById(opt.flag + '_d');
                var doc = document.all ? pop_iframe: pop_iframe.contentWindow;
				pop_iframe[document.all ? "onreadystatechange" : "onload"] = function() {
					$(pop_iframe).show();
					$('#' + opt.flag + '_loading').hide();					
				}
            };
			if (opt.word) {//字符串形式
				this.el.dbox.append('<div id="' + opt.flag + '" style="display:none"><div id="' + opt.flag + '_d">' + opt.word + '</div></div>');
			};
			if (opt.el) {//直接传对象参数
				this.el.dbox.append('<div id="' + opt.flag + '" style="display:none"></div>');
				$('#' + opt.flag).append(opt.el);
				opt.el.attr('id',opt.flag + '_d');
			};
			
		},

		//弹出 {flag}
		show : function(opt) {
			this.d.opt = opt;
			this.d.opt.flag = this.d.opt.flag == undefined ? 'flag_' + this.method.rand() : this.d.opt.flag;
			document.getElementById(opt.flag) ? null : this.init(this.d.opt);
			this.resize();//调整每层的样式
			this.setpos();//定位
			$('#' + this.d.opt.flag).show();
			this.el.box.hide().show();
			$('#' + this.d.opt.flag).siblings('div').hide();
			var title = opt.title == undefined ? '' : opt.title;
			this.el.dtit.html(title);//写入弹出标题			
			window.onscroll = function(){$.popup.setpos()};
//			window.onresize = function(){$.popup.setpos()};
//			drag.run($('#pop_dTitle')[0],$('#pop_box')[0])//拖动
//			this.el.box.drag();
		},

		//弹出 {flag}
		alert : function(opt) {
			var str = opt.word;
			var src = opt.src == undefined ? '/image/ico/alert2.jpg' : opt.src;
			var auto = opt.time == undefined ? false : true;
			var func = opt.func == undefined ? null : opt.func;
			var title = opt.title == undefined ? '友情提示：' : opt.title;
			func = func == 'reload' ? 'top.location.reload()' : func;//添加默认reload
			var backurl = $.cookie('backurl') == null ? 'index.php?do=control_home_index' : $.cookie('backurl');
			func = func == 'back' ? ('top.location.href = ' + backurl + '') : func;//默认返回
						
			var s = this.method.gWH(str);//通过字符的多少判断宽度
			var flag = 'flag_' + this.method.rand().toString();
			this.d.opt = { width : s.w*14 + 20 + 80, height : s.h*28 + 50 + 60, flag : flag, title : title, word : str } ;
			this.d.opt.width = this.d.opt.width > 300 ? this.d.opt.width : 300;
			this.d.opt.height = this.d.opt.height > 200 ? this.d.opt.height : 200;
			this.init(this.d.opt);			
			this.resize();//调整每层的样式						
			this.setpos();//定位
			this.el.dtit.html(this.d.opt.title);//写入弹出标题
			this.el.close.hide();//隐藏关闭按钮
			this.el.box.hide().fadeIn(100);
			$('#' + this.d.opt.flag).show();
			$('#' + this.d.opt.flag + '_d').css({
				width : this.d.opt.width - 100,
				height : this.d.opt.height - 90,
				background : 'url(' + src + ') no-repeat 13px 18px',
				padding: '20px 20px 60px 60px',
				lineHeight : '1.8',
				fontSize : '14px'
			});
			//返回函数
			this.method.callBack = function (){
				$.popup.close();
				eval(func);
				if (auto) (clearTimeout($.popup.d.timer));
			};

			$('#' + this.d.opt.flag + '_d').append('<div class="clear c" style="margin:0 0 0 -25px;"><input type="button" class="commBtn" value=" 关闭 " onclick="$.popup.method.callBack ()" /></div>');
			$('#' + this.d.opt.flag).siblings('div').hide();
			window.onscroll = function(){$.popup.setpos()};
			window.onresize = function(){$.popup.setpos()};	
			if (auto) {this.d.timer = setTimeout('$.popup.method.callBack ()',opt.time)}

			//drag.run(this.el.dtit[0],this.el.box[0])
		},

		//关闭
		close : function() {
			if (parent.document.getElementById('pop_box')){
				parent.document.getElementById('pop_box').style.display = 'none';
			} else {
				this.el.box.hide();
			}
		}	
	}
});



/****************************************************************
 * 弹出提示框
 *
 * 默认设置 { pos : 0, align : 'left', delay : 0, html : xxx }
 *
 *  1 如果设置html，则不理会info属性内容
 *  2 样式在模板文件中定义
 *****************************************************************
*/
$.fn.show_info = function(opt) {
	opt = opt || {};
	/* 默认设置为左侧，不随鼠标移动，延迟为0 */
	opt.pos = opt.pos == undefined ? 0 : opt.pos;
	opt.align = opt.align == undefined ? 'left' : opt.align;
	opt.delay = opt.delay == undefined ? 0 : opt.delay;
	opt.offsetX = opt.offsetX == undefined ? 5 : opt.offsetX;
	opt.offsetY = opt.offsetY == undefined ? 5 : opt.offsetY;

	if (typeof $('#show_info').get(0) == 'undefined') {
		$('body').append('<div id="show_info"><b id="lt"></b><b id="lb"></b><b id="rt"></b><b id="rb"></b><div id="show_info_box"></div></div>')
	};
	var m_pos = function(e) {
		e = e || window.event;
		var x = e.clientX ? (document.documentElement.scrollLeft + e.clientX - document.body.clientLeft) : e.pageX;
		var y = e.clientY ? (document.documentElement.scrollTop + e.clientY - document.body.clientTop) : e.pageY;
		return { 'x' : x, 'y' : y };
	};
	
	/* 通过参数判断弹出的位置 */
	var g_pos = function() {
			var l = 0;
			if (opt.align === 'center') {
				l = $('#show_info').width()/2;
			}
			return l;
	};	
	$(this).each(function(){
		var _this = $(this);
		if (opt.html == undefined && _this.attr('info') == undefined) {
			opt.html = '<span class="red">暂无帮助信息。</span>';
		} else {
			opt.html = opt.html == undefined ? _this.attr('info') : opt.html
		}
		
		this.onmouseover = function(e) {
			/* 延迟提示 */
//			opt.timer = setTimeout(function(){
				$('#show_info').css({
					left : m_pos(e).x + opt.offsetX - g_pos(),
					top : m_pos(e).y - $('#show_info').outerHeight() - opt.offsetY
				}).fadeIn(50);
				$('#show_info_box').html(opt.html);
				/* 如果传参，则弹出位置随鼠标改动 */
				if (opt.pos) {
					_this.get(0).onmousemove = function(e){
						$('#show_info').css({
							left : m_pos(e).x + opt.offsetX - g_pos(),
							top : m_pos(e).y - $('#show_info').outerHeight() - opt.offsetY
						})	
					}	
				}
//			},opt.delay)					
		};
		/* 隐藏 */
		function s_hide(){clearTimeout(opt.timer);$('#show_info').hide(0);}
		var ev = ['onmouseout','onclick','onfocus'];
		for (var k = 0; k < ev.length ; k++ ) {
			_this.get(0)[ev[k]] = s_hide;
		}
	});
};


$.fn.cutstr = function(l,eStr){
	var eStr = eStr || '';
	var l = l || text.length;
	$(this).each(function(){
		var text = $(this).text();		
		$(this).text($(this).text().substr(0,l) + eStr);
	})	
}
$.fn.clearPrompt = function(){
	$(this).each(function(){
		var text,prompt = $(this).val();
		$(this).focus(function(){
			text = $(this).val() === prompt ? '' : $(this).val();
			$(this).val(text);
		}).blur(function(){
			text = $(this).val() === '' ? prompt : $(this).val();
			$(this).val(text);
		})
	})
}


/* old plug */
$.extend({
	pop : {

		isOk : false,
		refresh : false,

		onOk : function() {},

		create : function() {
			$(document.body).prepend('<div id="shadowDiv" style="display:none;width:100%;height:100%;position:absolute;top:0px;left:0px;background-color:#000;filter:alpha(opacity=40);opacity:0.4;z-index:65534"><iframe style="width:100%;height:100%;border:0;position:absolute;filter:alpha(opacity=0);opacity:0;z-index:65533" frameborder="0" scrolling="no" id="shadowIframe"></iframe></div>');
			$(document.body).prepend('<div id="popDiv" style="display:none;position:absolute;width:500px;height:300px;background-color:#fff;border:4px solid #e4e4e4;z-index:65535"><div style="text-align:left;background-color:#efefef;height:25px;font-size:14px;cursor:_move_"><span style="display:block;float:left;line-height:25px;padding-left:10px;font-weight:bold" id="popDivTitle"></span><input type="button" id="dialogBoxClose" onclick="$.pop.hide();return false" title="关闭" style="display:block;float:right;width:3.5em; font-size:12px;height:16px;float:right;background:#efefef;0background:url(image/ico/popclose.gif) no-repeat 0 0;border:0;margin:3px 1em 0 0;*margin:5px 0.3em 0 0;padding:0;" onmouseover="this.style.color=\'#ff6600\'" onmouseout="this.style.color=\'#000\'" value=\"X 关闭\" /></div><div id="popBody" style="display:none;text-align:center;padding:5px 10px 10px 10px;font-size:14px;height:auto;overflow:hidden;"></div><div id="popIframeDiv" style="margin:auto;"><iframe id="popIframe" name="popIframe" frameborder="0" scrolling="auto" src="about:blank" width="100%" style=""></div></div>');
		},

		resize : function(width,height) {
			var winH = $(window).height();
			var scrollTop = $(window.body).scrollTop();
			var  top = winH > height ? ((winH-height)/2 + scrollTop) : 50;
			var left = ($(window).width() - width ) / 2 + $(window.body).scrollLeft();
			$('#popDiv').css({'top': top, 'left': left});
			var w = document.documentElement.clientWidth; 
			$('#shadowDiv').css({'height': height, 'width': w});
			$('#shadowIframe').css({'width' : width, 'height' :  height});
			$('#popIframeDiv').css({'width' : width, 'height' : height-25, margin : 'auto', marginTop : '5px'});
			$('#popIframe').css({'width' :  width, 'height' :  (height-25) });
			$('#popBody').css({'width' : width-10, 'height' : height-25, overflow : 'hidden'});
			$('#popDiv').css({'width' : width+10, 'height' : height+10});
		},

		show : function(str, json) { 
			this.create();
			if (str) {
				$('#popDivTitle').html(str);
			}
			if (json) {
				this.resize(json.width,json.height);
				if (json.url) {
					$('#popIframe').attr('src', json.url);

					if (json.refresh) {//给每个form插入input，父页面是否刷新。
						this.refresh = json.refresh;
					}			
					
					$('#popBody').hide();
					$('#popIframeDiv').show();
					window.isForbidGo = 'yes';//forbidGo表示运行php端的alertGo函数，还是exit函数
				}
				if (json.info) {
					$('#popBody').html(json.info);
					$('#popBody').show();
					$('#popIframeDiv').hide();
				}
			}
			$('#shadowDiv').show();
			$('#popDiv').show();
			$('#shadowIframe').css({
				width : '100%',
				height: '100%'
			})
			/* 屏蔽移动
			$(window).resize(function(){
			  $.pop.resize(json.width, json.height);
			});
			$(window).scroll(function(){
			  $.pop.resize(json.width, json.height);
			});
			*/
			if (json.drag) {
				$('#popDivTitle').parents('div').eq(0).css('cursor','move')
				$("#popDiv").draggable();
			}
			
		},

		hide : function() { 
			if (document.getElementById('popDiv_del')) {
				$('#popDiv_del').remove();
			}
			if (document.getElementById('shadowDiv_del')) {
				$('#shadowDiv_del').remove();
			}
			$('#shadowDiv').css('display','none');
			$('#popDiv').css('display','none');
			$('#shadowIframe').css('display','none');
			$('#shadowDiv').attr('id','shadowDiv_del');
			$('#popDiv').attr('id','popDiv_del');
			if (this.refresh) {
				window.parent.location.reload();
			}
		},

		confirm : function(i) {
			if (typeof i == 'undefined') {
				i = '此操作';
			}
			var arr = i.split('<br>');
			var max = 0;
			for (var k in arr) {
				max = arr[k].byteLength() > max ? arr[k].byteLength() : max; 
			}
			var width  = max * 7 + 70;
			width = width > 400 ? width : 400;
			var height = arr.length * 20 + 100;
			var info = '<p style="width:100%;padding:10px;padding-left:40px;text-align:left;font-size:14px;line-height:1.4;">'+ i +'</p>';
			info += '<p style="text-align:center;padding:10px;"><input type="button" value="确定" class="btnOk" onclick="$.pop.onOk();$.pop.hide()">&nbsp;&nbsp;';
			info += '<input type="button" value="取消" class="btnCancel" onclick="$.pop.hide()">';
			info += '</p>';
			info += '<img src="image/helper/confirm.gif" style="float:left;position:absolute; top:50px; left:5px; width:40px;height:40px;" />';
			this.show('提示：',{info: info,width:width,height:height});
		},

		alert : function(i) {
			if (typeof i == 'undefined') {
				i = '';
			}			
			var arr = i.split('<br>');
			var max = 0;
			for (var k in arr) {
				max = arr[k].byteLength() > max ? arr[k].byteLength() : max; 
			}
			var width  = max * 7 + 70;
			width = width > 300 ? width : 300;
			var height = arr.length * 20 + 100;
			var info = '<p id="info" style="width:100%;padding:15px 10px 10px 0;text-align:left;font-size:14px;line-height:2em;"><img src="image/helper/alert.gif" style="float:left;margin-left:10px;margin-right:10px;" />'+ i +'</p>';
			info += '<p style="width:100%;text-align:center;padding:10px;*padding-top:0;"><input type="button" value="确定" class="btnOk" onclick="$.pop.hide()"></p>';
			
			this.show('提示：',{info: info,width:300,height:130});
			this.resize(width, height);
		}
	}
});

$.extend({
	win : {
		create : function() {
			$(document.body).prepend('<div id="shadowDivWin" style="display:none;width:100%;height:100%;position:absolute;top:0px;left:0px;background-color:#000;filter:alpha(opacity=30);opacity:.3;z-index:65534"><iframe style="width:100%;height:100%;border:0;position:absolute;filter:alpha(opacity=0);opacity:0;z-index:65533" frameborder="0" scrolling="no" id="shadowIframeWin"></iframe></div>');
			$(document.body).prepend('<div id="popDivWin" style="display:none;position:absolute;background-color:#fff;border:4px solid #e4e4e4;z-index:65535;text-align:center"></div>');
		},
		resize : function(width,height) {
			var top = ($(window).height() -  height ) / 2 + $(window.body).scrollTop();
			var left = ($(window).width() - width ) / 2 + $(window.body).scrollLeft();
			$('#popDivWin').css({'top': top, 'left': left});	
			var w = document.documentElement.clientWidth;
			$('#shadowDivWin').css({'height': height, 'width': w});
			$('#popDivWin').css({'width' : width, 'height' : height});
		},
		loading : function() { 
			this.create();
			this.resize(250,32);
			$('#popDivWin').html('<p class="f14 pt10 gray">正在处理中，请稍候... ...</p>');			
			$('#shadowDivWin').hide();
			$('#popDivWin').show();
			setTimeout(function(){
				$('#popDivWin').html('<p class="f14 pt10 gray">处理超时，请重新操作。</p>')
				setTimeout(function(){$.win.hide()},3000)
			},30000)
		},
		alert : function(msg, url) {
			this.hide();
			this.create();


			var arr = msg.split('<br>');
			var max = 0;
			for (var k in arr) {
				max = arr[k].byteLength() > max ? arr[k].byteLength() : max; 
			};
			var width  = max * 7 + 70;
			width = width > 300 ? width : 300;
			var height = arr.length * 20 + 100;
			this.resize(width, height);

			var html = "";
			html += '<img src="image/helper/alert.gif" align="absmiddle" />' + msg;
			html += "<br>";
			html += "<center><input type=\"button\" class=\"tplbtn btnOk\" value='确定' id='popDivBtnWin'></center>";
			$('#popDivWin').html(html).css({'line-height':'50px','font-size':'14px','padding-top':'30px','font-family':'verdana'});
			setTimeout("$('#popDivBtnWin').focus()",0);
			$('#popDivBtnWin').click(function(){
//				$('#shadowDivWin').css('display','none');
				$('#popDivWin').css('display','none');
				$('#shadowIframeWin').css('display','none');
			});
			if (url) {
				$('#popDivBtnWin').click(function(){
					if (url.indexOf('(') > -1 && url.indexOf(')') > -1) {
						eval('window.' + url);
					} else {
						if (url == 'reload') {
							window.parent.location.reload();
						} else {
							window.parent.location.href = url;
						}
					}
				});
			}
			$('#shadowDivWin').hide();
			$('#popDivWin').show();			
		},
		confirm : function(msg, func) {
			this.hide();
			this.create();
			this.resize(300,120);
			var html = "";
			html += msg;
			html += "<br>";
			html += "<center><input type=button class=\"btnOk\" value='确定' id='popDivBtnWin'>&nbsp;&nbsp;&nbsp;&nbsp;<input type=button class=\"btnCancel\" value='取消' id='popDivBtnCanncelWin'></center>";
			$('#popDivWin').html(html).css({'line-height':'50px','font-size':'14px','padding-top':'30px'});
			$('#popDivBtnWin').click(function(){
				$('#shadowDivWin').remove()
				$('#popDivWin').remove();
				$('#shadowIframeWin').remove()
				if (func) {
					eval('window.parent.' + func);
				} else {
					window.parent.location.href = url;
				}
			});
			$('#popDivBtnCanncelWin').click(function(){
				$('#shadowDivWin').remove();
				$('#popDivWin').remove();
				$('#shadowIframeWin').remove();
			});
			$('#shadowDivWin').show();
			$('#popDivWin').show();			
		},
		hide : function() { 
			$('#shadowDivWin').remove();
			$('#popDivWin').remove();
			$('#shadowIframeWin').remove();
		}
	}
});

$.extend({
	validRule : function(rule,jqForm) {
			if(rule == '') return true;
			for (var i in rule) {
				/* 检查必填项 */
				if (rule[i].must != 0) {
					if ( rule[i].must == 1) { 
						if(jqForm.find(":input[id="+i+"]").attr('disabled') == true || document.getElementById(i) == null) { // disabled或此id的表单不存在将不验证	
							continue;//以上两个情况不满足，就continue
						}
					};
					if(jqForm.find(":input[name='"+i+"']").size() < 1) {
						$.win.alert('对不起,' + rule[i].msg + '不能为空！');
						jqForm.find(":input[name="+i+"]")[0].focus();
						return false;
					} else {
						var type = jqForm.find(":input[name='"+i+"']").attr('type');
						var isOk = true;
						switch(type){
							case 'hidden' : if(jqForm.find(":input[name="+i+"]").val() == '') isOk = false;break;
							case 'checkbox' : if(jqForm.find(":input[name='"+i+"'][checked]").val() == undefined) isOk = false;break;
							case 'radio' : if(jqForm.find(":input[name='"+i+"'][checked]").val() == undefined) isOk = false;break;
							default : if(jqForm.find(":input[name="+i+"]").val() == '') isOk = false;break;
						}
					};
					if(!isOk){						
						$.win.alert('对不起,' + rule[i].msg + '不能为空！');
						jqForm.find(":input[name="+i+"]")[0].focus();
						return false;
					}					
				};
				
				if(jqForm.find(":input[name="+i+"]").val() == '') { //非必填写项，不为空才需要进行下面的检测。
					continue;
				};
				

				/* 检查正则 */
				if (rule[i].reg) {					
					var reg = rule[i].reg.replace(/\/u$/,'/').replace(/\\x\{(.{4})\}/g,"\\u$1");//后一个是子模式匹配，php中文正则和替换成js的
					reg = eval(reg);
					if (!(reg.test($("#"+i).val()))) {
						$.win.alert('对不起,' + rule[i].msg + '不符合验证规则，请按要求的正确格式填写');
						jqForm.find("#"+i).focus();
						return false;
					}
				};
				
				if (rule[i].type) {
					var reg;
					switch (rule[i].type) {
						case 'email' : 
							reg = /^([a-zA-Z0-9_\-\.])+@([a-zA-Z0-9\-])+\.[a-zA-Z0-9\-\.]+$/; 
							if (!(reg.test($("#"+i).val()))) {
								$.win.alert('对不起，email不合法！');
								jqForm.find("#"+i).focus();
								return false;
							}
							break;
						case 'tel'   :
							reg = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/; 
							if (!(reg.test($("#"+i).val()))) {
								$.win.alert('对不起，电话号码不符合要求！');
								jqForm.find("#"+i).focus();
								return false;
							}
							break;
						case 'cn'   :
							reg = /^[\u4e00-\u9fa5]+$/; 
							if (!(reg.test($("#"+i).val()))) {
								$.win.alert('对不起，' + rule[i].msg + '要求是纯中文字符');
								jqForm.find("#"+i).focus();
								return false;
							}
							break;
					};
					/*
					reg = eval(reg);
					if (!(reg.test(jqForm.find("#"+i).val()))) {
						$.win.alert('对不起' + rule[i].msg + '不符合要求！');
						jqForm.find("#"+i).focus();
						return false;
					}
					*/
				};

				if (rule[i].min) {
					if ( jqForm.find("#"+i).val().byteLength() < rule[i].min) {
						$.win.alert('对不起,' + rule[i].msg + '太短！');
						jqForm.find("#"+i).focus(); 
						return false;
					}
				};

				if (rule[i].max) {
					if (jqForm.find("#"+i).val().byteLength() > rule[i].max) {
						$.win.alert('对不起,' + rule[i].msg + '太长！');
						jqForm.find("#"+i).focus();
						return false;
					}
				}				
			};
			return true;
		}
})


$.extend({
	checkRule : function(rule,jqForm) {
			for (var i in rule) {
				/* 上传表单 */
				if (document.getElementById(i) == null || $("#"+i).attr('disabled') == true) { // 可以对动态添加的表单和表单属性为disabled的进行验证，没有时不验证
					continue;
				};
				if (i == 'path[]') {
					if (rule[i].must == 1) {
						if (jqForm.find("input[name='path[]']").size() == 0) {
							$.win.alert('对不起，' + rule[i].msg + '！');
							return false;
						}
					}
					continue; // 检测下一个。
				};
				/* 检查必填项 */
				if (rule[i].must == 1) {
					if($.trim($("#"+i).val()) == ''){//要求每个表单元素的id必须和name一样的才能被这里顺利验证
						$.win.alert('对不起，' + rule[i].msg + '！');
						$("#"+i).focus();
						return false;
					}
				};

				if($("#"+i).val() == '') { //非必填写项，不为空才需要进行下面的检测。
					continue;
				};

				/* 检查正则 */
				if (rule[i].reg) {					
					var reg = rule[i].reg.replace(/\/u$/,'/').replace(/\\x\{(.{4})\}/g,"\\u$1");//后一个是子模式匹配，php中文正则和替换成js的
					reg = eval(reg);
					if (!(reg.test($("#"+i).val()))) {
						alert('对不起' + rule[i].msg + '不符合要求！');
						$("#"+i).focus();
						return false;
					}
				};

				if (rule[i].type) {
					var reg;
					switch (rule[i].type) {
						case 'email' : 
							reg = /^([a-zA-Z0-9_\-\.])+@([a-zA-Z0-9\-])+\.[a-zA-Z0-9\-\.]+$/; 
							if (!(reg.test($("#"+i).val()))) {
								alert('对不起，email不合法！');
								$("#"+i).focus();
								return false;
							}
							break;
						case 'tel'   :
							reg = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/; 
							if (!(reg.test($("#"+i).val()))) {
								alert('对不起，电话号码不符合要求！');
								$("#"+i).focus();
								return false;
							}
							break;
						case 'cn'   :
							reg = /^[\u4e00-\u9fa5]+$/; 
							if (!(reg.test($("#"+i).val()))) {
								alert('对不起，' + rule[i].msg + '要求是纯中文字符');
								$("#"+i).focus();
								return false;
							}
							break;
					};
					reg = eval(reg);
					if (!(reg.test($("#"+i).val()))) {
						alert('对不起' + rule[i].msg + '不符合要求！');
						$("#"+i).focus();
						return false;
					}
				};

				if (rule[i].min) {
					if ( $("#"+i).val().byteLength() < rule[i].min) {
						alert('对不起' + rule[i].msg + '太短！');
						$("#"+i).focus(); 
						return false;
					}
				};

				if (rule[i].max) {
					if ($("#"+i).val().byteLength() > rule[i].max) {
						alert('对不起' + rule[i].msg + '太长！');
						$("#"+i).focus();
						return false;
					}
				}				
			};
			return true;
		}
})

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            };
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

jQuery.btnCancelClick = function() {
	if (top.document.getElementById('popDiv')) {
		top.$.pop.hide();
	} else {
		top.history.go(-1);
	}
}
$.fn.slide = function(data) {
	//var _this = this;
	this.css('position','relative');

	//alert($(this).parent().width());

	var pid = this.attr('id');
	var $body = $('<div id="' + pid + 'body"></div>');
	var $foot = $('<div id="' + pid + 'foot"></div>');
	var $num  = $('<ul id="' + pid + 'num" style="position:absolute;bottom:21px;right:0;z-index:10;margin:0"></ul>');
	var $height = this.innerHeight();
	var $width = this.innerWidth();
	$body.css({width: $width, height: $height - 21,position: 'relative'});
	$foot.css({width: $width, height: 21,background: '#f7f7f7',filter: 'alpha(opacity=80)',opacity: '0.8',textAlign: 'center',lineHeight: '21px',position:'absolute',bottom:0,whiteSpace:'nowrap',overflow:'hidden'});
	this.append($body).append($foot).append($num);
	slide = (typeof slide == 'undefined') ? {} : slide;
	slide[pid] = {};
	slide[pid].point  = 0;
	slide[pid].timer  = '';
	slide[pid].data   = data;
	slide[pid].total  = data.length,
	slide[pid].change = function() {
		this.point = this.point % this.total;
		var h  = '<a href="'  + this.data[this.point].url  + '" target="_blank" onmouseover="slide[\'' + pid + '\'].stop()" onmouseout="slide[\'' + pid + '\'].start()" ';
		
			var traffic_url = 'index.php?do=sys_traffic_click&id='+this.data[this.point].traffic_id;

			if(traffic_url != ''){ //有流量统计时，添加onclick事件
				h += "onclick=traffic('" + traffic_url + "')";
			};

		    h += '><img src="' + this.data[this.point].path + '" width="' + ($width) + '" height="' + ($height-21) + '" style="border:0"></a>';
		$body.html(h).show()//hide().fadeIn(500);
		    h  = '<a href="'  + this.data[this.point].url  + '" target="_blank" onmouseover="slide[\'' + pid + '\'].stop()" onmouseout="slide[\'' + pid + '\'].start()" style="font-size:12px;font-weight:700;color:#000;text-decoration:none;font-family:verdana,tahoma,arial;line-height:21px;"';
			
			if(traffic_url != ''){ //有流量统计时，添加onclick事件
				h += "onclick=traffic('" + traffic_url + "')";
			};			
			
			h += '>'+this.data[this.point].title + '</a>';
		$foot.html(h);

		/* 数字导航 */
		var v  = '';
		for (var i = 0; i < slide[pid].data.length ; i++ ) {			
		    v += '<li style="float:left;background:#ffddee;margin-left:2px;padding:0px 10px;line-height:14px;cursor:pointer;list-style:none">'+(i+1)+'</li>';
		}
		$('#'+pid + 'num').html(v);
		$('#'+pid + 'num li').eq(this.point).attr('style','float:left;margin-left:2px;color:#fff;background:#66aaff;font-weight:bold;cursor:pointer;list-style:none;filter:alpha(opacity=90);opacity:.9;font-size:12px;width:20px;height:20px;line-height:20px;text-align:center;')
		.siblings('li').attr('style','float:left;background:#ffccaa;margin-left:2px;cursor:pointer;list-style:none;filter:alpha(opacity=50);opacity:.5;font-size:12px;width:20px;height:20px;line-height:20px;text-align:center;')

		/* 点击数字导航 */
		$('#'+pid+' li').each(function(){
			$(this).mousedown(function(){
				slide[pid].point = parseInt($(this).html())-1;
				slide[pid].change();
				slide[pid].stop();
			}).mouseup(function(){
				slide[pid].start();
			})
		})

		this.point ++;
	},
	slide[pid].start  = function() {
		this.timer = setInterval("slide['" + pid + "'].change()",3000); 
	},
	slide[pid].stop   = function() {
		clearInterval(this.timer);
	}
	slide[pid].change();
	slide[pid].start();
};

var drag = {
	m : {
		mpos : function(e) { //获取鼠标位置
			e = e || window.event;
			var x = e.clientX ? (document.documentElement.scrollLeft + e.clientX - document.body.clientLeft) : e.pageX;
			var y = e.clientY ? (document.documentElement.scrollTop  + e.clientY - document.body.clientTop ) : e.pageY;
			return { x : x, y : y }
		},

		opos : function(el) {
			if (el.getBoundingClientRect) {
				return {
					x : el.getBoundingClientRect().left,
					y : el.getBoundingClientRect().top
				}
			} else {
				var pos = {
					x : el.offsetLeft,
					y : el.offsetTop
				}
				do {
					pos.x += el.offsetLeft;
					pos.y += el.offsetTop;
				} 
				while (el = el.parentOffset);
				return pos;
			}
		}	
	},
	
	run : function(dragEl,el) {
		var ox,oy,xl,yl,isDrag;
		el = el || dragEl;
		el.style.position = 'absolute';
		dragEl.style.cursor = 'move';
		dragEl.onmousedown = function(e){
			e = e || window.event;
			isDrag = true;
			ox = drag.m.opos(el).x;
			oy = drag.m.opos(el).y;
			xl = drag.m.mpos(e).x - drag.m.opos(el).x;
			yl = drag.m.mpos(e).y - drag.m.opos(el).y;
			this.onmousemove = function(e){
				e = e || window.event;
				if (isDrag){
					el.style.left = (drag.m.mpos(e).x - xl) + 'px';
					el.style.top  = (drag.m.mpos(e).y - yl) + 'px';	
				}
			}
		}
		el.onmouseup = function(){
			isDrag = false;		
		}
	}

}

/**************************************************************** 
 *           滚动轮播 
 *
 * 参数：data 和 opt
 * opt { derict : 'top/left'; time : 3000/?? }
 *
*/
$.fn.slideScroll = function(data,opt){
	//参数设置
	var option  = { driect : 'left', time : 3000 };
	opt = opt || option ;
	var argSet  = {};
	argSet.top  = opt.driect == 'top' ? true : false;
	argSet.left = opt.driect == 'left' ? true : false;

	var _this   = this;
	var temRnd  = Math.random().toString();
	var rnd     = temRnd.substr(2,temRnd.length-2);
	var frame   = '<div id="box_' + rnd + '"><ul id="ul_' + rnd + '"></ul><span id="num_' + rnd + '"></span><div id="title_' + rnd + '"></div><div id="title_bg' + rnd + '"></div></div>'; //组织html基础结构
	var frame_inner = frame_serial = frame_title = '';
	var w = _this.width(),h = _this.height();	

	//初始化结构
	_this.append(frame);
	var _box     = $('#box_' + rnd);
	var _ul      = $('#ul_' + rnd);
	var _num     = $('#num_' + rnd);
	var _title   = $('#title_' + rnd);
	var _titleBg = $('#title_bg' + rnd);
	_box.css({
		width     : w,
		height    : h,
		position  : 'relative',
		overflow  : 'hidden'
	});
	_ul.css({
		width     : argSet.top ? w : data.length * w,
		height    : argSet.top ? data.length * h : h,
		position  : 'absolute'
	});
	_num.css({
		position  : 'absolute',
		right     : '0',
		bottom    : '20px'
	});
	_title.css({
		position  : 'absolute',
		bottom    : '0',
		color     : '#fff',
		width     : '100%',
		zIndex    : 5,
		textAlign : 'center'
	});
	_titleBg.css({
		position  : 'absolute',
		bottom    : '0',
		background : '#000',
		opacity   : '.3',
		filter    : 'alpha(opacity=30)',
		color     : '#fff',
		width     : '100%',
		height    : 20,
		zIndex    : 4
	});

	var styleLi = argSet.left ? 'float:left' : ''; //如果设置
	for (var i = 0; i < data.length ; i++ ) {
		//图片结构
		frame_inner  += '<li style="width:' + w + 'px; height:' + h + 'px;' + styleLi + ';display:inline">';
		frame_inner  +=	'<a href="' + data[i].url + '" title="' + data[i].title + '" target="_blank">';
		frame_inner  +=		'<img src="' + data[i].src + '" alt="' + data[i].title + '" width="' + w + '" height="' + h + '" />';
		frame_inner  +=	'</a>';
		frame_inner  += '</li>';
		
		//序号结构
		frame_serial += '<span style="display:inline-block; zoom:1; width:12px; height:12px; line-height:14px; text-align:center; border:1px solid #ff6600; background:#ffcda4; color:#333; margin:0 10px 0 0; font-size:12px; opacity:.6; filter:alpha(opacity=60);vertiacl-align:bottom; cursor:pointer">';
		frame_serial +=		i + 1;
		frame_serial += '</span>';

		//标题结构
		frame_title += '<a style="color:#fff;text-decoration:none;' + (i === 0 ? 'display:none;"' : 'display:block;') + '" href="' + data[i].url + '" title="' + data[i].title + '" target="_blank">' + data[i].title + '</a>';
	};

	_ul.append(frame_inner);
	_num.append(frame_serial);
	_title.append(frame_title);
	
	function scroll(tPos) {
		if (argSet.left) {
			_ul.animate({
				left : tPos
			},500)	
		} else {
			_ul.animate({
				top : tPos
			},500)
		}
	}

	function signCurr (num) {
		_num.find('span').eq(num).css({
			background : '#f7994d',
			padding    : '4px',
			color      : '#fff',
			opacity    : '1',
			filter     : 'alpha(opacity=100)',
			fontWeight : '800'
		}).siblings().css({
			background : '#ffcda4',
			padding    : '2px',
			color      : '#333',
			opacity    : '.5',
			filter     : 'alpha(opacity=50)',
			fontWeight : '200'
		});
		_title.find('a').eq(num).show().siblings().hide();
	};

	var timer,c_num = 0;
	function start() { //current position || target position		
		signCurr(c_num);
		if (argSet.top) { //上下滚动
			timer = setInterval(function(){				
				if (Math.abs(parseInt(_ul.css('top'))) < h*(data.length-1)) {
					signCurr(c_num+1);
					scroll(-h*(c_num+1));
					c_num += 1;
				} else {
					c_num = 0;
					signCurr(c_num);
					scroll(0);
				}
			},opt.time)
		};
		if (argSet.left) { //左右滚动
			signCurr(c_num);
			timer = setInterval(function(){
				if (Math.abs(parseInt(_ul.css('left'))) < w*(data.length-1)) {
					signCurr(c_num+1);
					scroll(-w*(c_num+1));
					c_num += 1;
				} else {
					c_num = 0;
					signCurr(0);
					scroll(0);					
				}
			},opt.time)
		}
	}

	function stp() { clearTimeout(timer); }
	
	(function() { //run
			start();
			//鼠标滚动
			_num.find('span').each(function(){
				$(this).mouseover(function(){					
					_ul.stop();
					stp();
					var curN = parseInt($(this).text());
					c_num = curN-1;					
					signCurr(c_num);
					var o = argSet.left ? w : h;
					scroll(-o*(c_num));
				}).mouseout(function(){
					start();
				})
			});

			_ul.find('li').each(function(){
				$(this).mouseover(function(){
					stp();
				}).mouseout(function(){
					start();
				})
			});
			_title.find('a').each(function(){
				$(this).mouseover(function(){
					stp();
				}).mouseout(function(){
					start();
				})
			});
	})()

};

$.fn.scroll = function(data,opt){ // by Even[ websev Team ]
	var $t = $(this),
		opt = opt || {};

	var main = (function(){
		return {
			// 对象空间
			el : {},

			// 默认配置
			opt : {
				time : 3000,                        // 时间
				act : 'fade',                       // 切换效果
				event : ['mouseover','mouseout']    // 触发事件
			},

			// 结构
			frame : function() {
				var html = '';
				html += '<div id="plug_scroll">';
				html += '	<div id="p_s_img1"><ul></ul></div>';
				html += '	<div id="p_s_tit"><ul></ul></div>';
				html += '	<div id="p_s_img2"><ul></ul></div>';
				html += '	<div id="p_s_num"></div>';
				html += '</div>';
				$t.html(html);
				
				this.el.B   = $('#plug_scroll');
				this.el.I1  = $('#p_s_img1');
				this.el.T   = $('#p_s_tit');
				this.el.I2  = $('#p_s_img2');
				this.el.N   = $('#p_s_num');
				this.el._I1 = $('#p_s_img1 ul');
				this.el._T  = $('#p_s_tit ul');
				this.el._I2 = $('#p_s_img2 ul');
			},

			// 函数集
			fn : {
				random : function(){return new Date().getTime()}
			},

			// 切换动作
			go : function(){
					var curr = this.curr;
					this.el.Is2.eq(curr).addClass('curr').siblings().removeClass('curr');
					this.el.Ns.eq(curr).addClass('curr').siblings().removeClass('curr');
					this.el.Ts.eq(curr).addClass('curr').show().siblings().removeClass('curr').hide();
					switch (this.opt.act){
						case 'scrollLeft': // 左右滚动
							this.el._I1.stop().animate({
								left : -curr * this.opt.oneW
							},500);
							break;
						case 'scrollTop': // 上下滚动
							this.el._I1.stop().animate({
								top : -curr * this.opt.oneH
							},500);
							break;
						default :
							this.el.Is1.eq(curr).fadeIn(1000).siblings().hide();
							break;
					};
					
			},			

			// 装载数据
			load : function(){
				var d = this.D,
					h_img = '',
					h_tit = ''
					h_num = '';					
				for (var i = 0; i < d.length ; i++ ){
					d[i].cont = d[i].cont == undefined ? '' : d[i].cont; // 不传cont，则为空
					h_img += '<li><a href="' + d[i].url + '" title="' + d[i].title + '" target="_blank"><img src="' + d[i].src + '" alt="' + d[i].title + '" /></a></li>';
					h_tit += '<li><a href="' + d[i].url + '" title="' + d[i].title + '" target="_blank">' + d[i].title + '</a><p>' + d[i].cont + '</p></li>';
					h_num += '<em>' + (i + 1) + '</em>';
				};
				this.el._I1.html(h_img);
				this.el._I2.html(h_img);
				this.el.N.html(h_num);
				this.el._T.html(h_tit);

				this.el.Is1 = this.el._I1.find('li');
				this.el.Is2 = this.el._I2.find('li');
				this.el.Ns  = this.el.N.find('em');
				this.el.Ts  = this.el._T.find('li');

				this.opt.oneW = this.el.Is1.eq(0).outerWidth();
				this.opt.oneH = this.el.Is1.eq(0).outerHeight();

				this.el._I1.css({
					width : this.opt.oneW * d.length,
					height : this.opt.oneH * d.length
				});

				this.el.Is2.css({
					width : this.opt.oneW / d.length
				});


				if(this.opt.act == 'scrollLeft'){
					this.el.Is1.css({
						float : 'left'
					});
				}
			},

			// 初始化
			init : function(){
				this.D = data;
				this.curr = 0;
				for (var i in this.opt){ // 加载配置
					this.opt[i] = opt[i] === undefined ? this.opt[i] : opt[i];
				}
				this.frame();
				this.load();				
				this.go();
			},

			// 自动播放
			start : function(){
				var _this = this;
				this.timer = setInterval(function(){
					_this.curr += 1;
					_this.curr = _this.curr%(_this.D.length);
					_this.go();
				},this.opt.time)
			},

			// 暂停
			stop  : function(){
				clearInterval(this.timer);
			},

			// 运行
			run : function(){
				var _this = this;
				this.init();
				this.start();
				this.el.Is2.each(function(i){  // 缩略图
					$(this).bind(_this.opt.event[0],function(){
						_this.curr = i;
						_this.go(i);
						_this.stop();
					}).bind(_this.opt.event[1],function(){
						_this.start();
					});
				});

				this.el.Ns.each(function(i){ // 当前项数字
					$(this).bind(_this.opt.event[0],function(){
						_this.curr = i;
						_this.go(i);
						_this.stop();
					}).bind(_this.opt.event[1],function(){
						_this.start();
					});
				});
			}
		}
	})();
	main.run();
}

// 拖动
$.fn.drag=function(s){
	  if(this.size()>1) return this.each(function(i,o){$(o).drag(s)});
	  var t=this,h=s?t.find(s):t,m={},to=false,
	      d=function(v){
			  v.stopPropagation();
			  m={ex:v.clientX,ey:v.clientY,x:t.css("position")=="relative"?parseInt(t.css("left")):t.position().left,y:t.css("position")=="relative"?parseInt(t.css("top")):t.position().top,fw:t.get(0).style.width,w:t.width()};
			  if(t.css("position")=="static") to={"left":m.x,"top":m.y};
			  $(document).mousemove(b).mouseup(e);
		      if(document.body.setCapture) document.body.setCapture(); 
			  },
		  b=function(v){t.css({"left":v.clientX-m.ex+m.x,"top":v.clientY-m.ey+m.y});},
		  e=function(v){
		      if(document.body.releaseCapture) document.body.releaseCapture();
			  $(document).unbind("mousemove").unbind("mouseup");
			  };
		  h.mousedown(d);
		  return t;
	  };


// form验证
function FORM(id){
	return new function () {
		var that = this;
		this.fn = {
			o : function(){var arg = arguments[0] ? arguments[0] : id; return document.getElementById(arg)}, // id
			os : function(el,tag,filterOpt){ // tagName
				filterOpt = filterOpt || {nodeName : tag};
				var os = el.getElementsByTagName(tag);
					arr = [];
				for (var i = 0,j; i < os.length; i ++) {
					for (var j in filterOpt){
						os[i][j].toLowerCase() == filterOpt[j].toLowerCase() ? arr.push(os[i]) : null
					}
				}
				return arr;
			}
		}
		this.focusblur = function(){
			inps = that.fn.os(that.fn.o(),'input',{type : 'text'});
			for (var i = 0; i < inps.length; i++){
				(function(i){
					
				})(i)
			}
		}
		this.valide = function(rule){
			var rule = rule || [],				
				error = function(el,str){
					el.style.backgroundColor = '#fef1e0';
					alert(str);
					/*
					if(!that.fn.o(el.id + '_msg')){
						var info = document.createElement('span');
						info.id = el.id + '_msg';
						el.parentNode.appendChild(info);
						info.innerHTML = str;
					} else {
						that.fn.o(el.id + '_msg').innerHTML = str;
					}
					*/
						
				},
				curret = function(el,str){
					str = str || '';
					el.style.backgroundColor = '#fff';
					/*
					if(!that.fn.o(el.id + '_msg')){
						var info = document.createElement('span');
						info.id = el.id + '_msg';
						el.parentNode.appendChild(info);
						info.innerHTML = str;
					} else {
						that.fn.o(el.id + '_msg').innerHTML = str;
					}
					*/

				};
			for (var i = 0; i < rule.length; i++){ // 开始验证
				var cel = this.fn.o(rule[i].id),
					msg = rule[i].msg ? rule[i].msg : '填写有误！',
					cont = rule[i].cont ? rule[i].cont : '此项';
				if (rule[i].must && cel.value == ''){					            // 必填项
					cel.focus();
					error(cel,cont + '不能为空！');
					return false;
				}
				if (rule[i].min){              // 最小
					if(cel.value.length < rule[i].min){
						cel.focus();
						error(cel,cont + '长度应大于' + rule[i].min + '个字！');
						return false;
					}
				}
				if (rule[i].max){              // 最大
					if(cel.value.length > rule[i].max){
						cel.focus();
						error(cel,cont + '长度应小于' + rule[i].max + '个字！');
						return false;
					}					
				}
				if (rule[i].reg){
					if (!rule[i].reg.test(cel.value)){              // 正则验证
						cel.focus();
						error(cel,msg);;
						return false;
					}
				}
				if (rule[i].same){
					if(cel.value != this.fn.o(rule[i].same).value){
						cel.focus();
						error(cel,'两次输入不一致！');
						return false;
					}
				}
				curret(cel);
			}
			return true;
		}
	}
}
