/**
Copyright (c) 2009 MULAN-lsw
验证例子：1.html要求
			<input type="text" name="name" id="name" size="40"/>//要被验证的组件
			<div id=textTip"></div> //显示信息的DIV id为组件(id+Tip)
		
		2.导入JS CSS　如下是PHP动态导入
			$document =& JFactory::getDocument();
	    	$document->addStyleSheet('../media/mulan/css/admin.validate.css');//验证时显示的样式
	    	$document->addScript('../media/mulan/js/jquery.js');//jquery
	    	$document->addScript('../media/mulan/js/regexs.js');//关于一些通用的正则表达式
	   		$document->addScript('../media/mulan/js/jquery.mlvalidate.js');//验证插件
	    
	    3.在对应的HTML script中配置各个组件的验证方法　onerror是错误时的显示,onshow,是初始时的显示,onfocus是得到焦点时的显示,oncorrect是验证通过的显示
	    	一般都写在jQuery(document).ready(function(){
	    	});中
			1)email1要求非空，且要满足email的正则格式，
			$("#email1").required({onerror:"主联系人邮箱非空"})
	    				.regexValidator({regexp:regexEnum.email,onshow:"更改主联系人邮箱",onfocus:"输入正确主联系人邮箱",oncorrect:"验证通过",onerror:"主联系人邮箱格式错误"});
			2)name 要满足一定正则格式，但可以空
			$("#name").regexValidator({regexp:regexEnum.notblank,onshow:"更改名称",onfocus:"输入正确名称",oncorrect:"验证通过",onerror:"不能为空"});
			3)address 非空，但内容任意 jQuery是为了不和其它插件冲突
			jQuery("#address").required({onerror:"小区内地址非空",oncorrect:"验证通过"})
 					 .regexValidator({onshow:"填写小区内地址",onfocus:"请输入您小区内的地址"});
		 	4)deliverAddr可空，也可任意
		 	jQuery("#deliverAddr").regexValidator({onshow:"填写收货地址",onfocus:"请输入收货地址",oncorrect:"验证通过"});
			5)id 为optiontable 下的全部input中要求有至少２个input填写。alloption find all input ,showwhere是在什么地方显示信息
			$("#optiontable input").controlOption({least:"2",alloption:"#optiontable input",showwhere:"polloptionTip",onshow:"更改选项",onfocus:"输入投票选项",onerror:"最少二项要填写",oncorrect:"验证通过"});
		    6)memberPrice中的值不能比marketPrice中的值大，非空，值为浮点数 sign 比较方式可< <= ==... type是比较类型number和string
		    $("#memberPrice").required({onerror:"社员价未填"})
							.regexValidator({regexp:regexEnum.price,onshow:"更改社员价",onfocus:"设置正确社员价",oncorrect:"验证通过",onerror:"社员价格式不正确"})
							.compareWith({sign:"<=",id:"marketPrice",type:"number",onerror:"社员价不应高于市场价"});
			7)hobbies爱好　可自定义正则式，0-40个字符
			$("#hobbies").regexValidator({regexp:"^(.){0,40}$",onshow:"填写爱好",onfocus:"此项可空",onerror:"最多40个字符",oncorrect:"验证通过"});
			8)issue输入不能为空。且出错时用alert的形式告知
			$("#issue").regexValidator({regexp:regexEnum.notblank,onerror:"投诉内容不能为空",alertit:true})
			9)第二次密码输入验证
			$("#password2").compareWith({sign:"==",id:"password",onshow:"重新输入",onfocus:"再一次输入密码",onerror:"二次输入不一致",oncorrect:"验证通过"});
			
		4.为了提交时再验证时能匹配到全部组件，为每个要验证的组件配上相同的CSS样式
			$("form select").each(function(){
				this.addClass("text_area");
			});
 		5.adminForm为form的id，指定提交时验证，1)只有验证的功能，但改变了pageValidate全局变量的真假,true为验证通过2)中submit指定submitValidator有提交表单的功能，
 			1)$("#adminForm").submitValidator({css:"text_area"});
 			2)jQuery("#mulanform").submitValidator({css:"aaa",submit:true});
 		6.当5中用1时,手动触发提交
 		 $("#adminForm").submit();
        	if (pageValidate){
        		//验证通过，做你想做的事，最后记得提交
        	}else{
        		//验证失败，做你想做的事。
        	}
        	
        	
例：
$("#username").required({onerror:"用户名必填"})
.regexValidator({regexp:regexEnum.username,onshow:"填写用户名",onfocus:"输入用户名",oncorrect:"格式正确",onerror:"5-16位，字母或数字"});
$("#realname").required({onerror:"真实姓名必填"})
.regexValidator({regexp:regexEnum.username,onshow:"填写真实姓名",onfocus:"输入真实姓名",oncorrect:"格式正确",onerror:"2-6个汉字或2-16个字母"});
$("#mobilephone").required({onerror:"手机号码必填"})
.regexValidator({regexp:regexEnum.mobile,onshow:"填写号码",onfocus:"输入您的手机号码",oncorrect:"格式正确",onerror:"格式不正确"});
$("#phone").regexValidator({regexp:regexEnum.telblank,onshow:"填写固定电话",blankshownone:true,onfocus:"输入固定电话",oncorrect:"格式正确",onerror:"格式不正确"});
$("#emailaddress").required({onerror:"邮箱必填"})
.regexValidator({regexp:regexEnum.email,onshow:"填写邮箱",onfocus:"输入您的邮箱",oncorrect:"格式正确",onerror:"格式不正确"});
$("#password").regexValidator({regexp:regexEnum.password,onshow:"填写密码",onfocus:"8-18位字符",onerror:"长度为8-18,字母数字和_",oncorrect:"验证通过"});
$("#repassword").equalWith({id:"password",onshow:"重新输入",onfocus:"再一次输入密码",onerror:"二次输入不一致",oncorrect:"输入一致"});
$("#newpw").regexValidator({regexp:regexEnum.password,onshow:"输入新密码",onfocus:"输入新密码8-18位",oncorrect:"验证通过",onerror:"长度为8-18"});
$("#renewpw").compareWith({sign:"==",id:"newpw",onshow:"重新输入",onfocus:"再一次输入密码",onerror:"二次输入不一致",oncorrect:"验证通过"});
$("#createForm").submitValidator({selector:"#createForm input"});	

	$("#username").required({onerror:"Email is required"})
				.regexValidator({regexp:regexEnum.email,onshow:"",onfocus:"",oncorrect:"",onerror:"Email format is incorrect"});
	$("#name").required({onerror:"Name is required"});
	$("#password").required({onerror:"Password is required"})
				.regexValidator({regexp:regexEnum.password,onshow:"",onfocus:"",oncorrect:"",onerror:"Password contains 6-18 letters or numbers"});
	$("#repassword").compareWith({sign:"==",id:"password",onshow:"",onfocus:"",onerror:"Confirm password does not match the previous one",oncorrect:""});
	$("#register-form").submitValidator({selector:"#register-form input",submit:true,alertit:true,alertmsg:'Sorry! Your input contains error. Please try again.'});
	
*/


var pageValidate = true;
var addValidate = true;
var errormsgs='';	
var millisecondnow = 0;
var startsubmit=false;
(function ($) {
	$.fn.regexValidator = function (options) {
		return this.each(function () {
			if (options.alertit != true) {
				if (options.onshow != "" && options.onshow != undefined) {
					$.ml.showTipState(this.id + "Tip", "onShow", options.onshow);
				}
				$(this).bind("focus", function () {
					addValidate = true;
					if (options.onfocus != "" && options.onfocus != undefined) {
						$.ml.showTipState(this.id + "Tip", "onFocus", options.onfocus);
					}
				});
				$(this).bind("blur", function () {
					if (addValidate) {
						$.ml.regexValidate(this.id, options);
					}
				});
			} else {
				$(this).bind("focus", function () {
					addValidate = true;
				});
				$(this).bind("blur", function () {
					if (addValidate) {
						$.ml.regexValidate(this.id, options);
					}
				});
			}
		});
	};
	$.fn.submitValidator = function (options) {
		return $(this).submit(function () {
			startsubmit=true;
			pageValidate = true;
			errormsgs='';
			var theform = $(this).get(0).getAttributeNode("id").value;
			var selector = options.selector ? options.selector : ("#" + theform + " ." + options.css);
			$(selector).each(function () {
				addValidate = true;
				$(this).blur();
			});
			if (!pageValidate) {
				if (options.alertmsg) {
					alert(options.alertmsg+errormsgs);
				} else {
					alert("\u5bf9\u4e0d\u8d77\uff0c\u60a8\u7684\u8f93\u5165\u6709\u8bef\uff0c\u8bf7\u91cd\u8f93"+errormsgs);
				}
			}
			if (options.submit) {
				return pageValidate;
			} else {
				return false;
			}
		});
	};
	$.fn.required = function (options) {
		return $(this).bind("blur", function () {
			if (addValidate && $.trim($("#" + this.id).val()) == "") {
				$.ml.showTipState(this.id + "Tip", "onError", options.onerror);
				addValidate = false;
				pageValidate = false;
			}
			if ($.trim($("#" + this.id).val()) != "" && options.oncorrect) {
				$.ml.showTipState(this.id + "Tip", "onSuccess", options.oncorrect);
				addValidate = false;
			}
		});
	};
	$.fn.equalWith = function (options) {
		return this.each(function () {
			var the=this;
			$.ml.showTipState(this.id + "Tip", "onShow", options.onshow);
			$('#'+options.id).bind("blur",function(){
				$(the).focus().blur();
			});
			$(this).bind("focus", function () {
				addValidate = true;
				$.ml.showTipState(this.id + "Tip", "onFocus", options.onfocus);
			});
			$(this).bind("blur", function () {
				if (addValidate && ($.trim($("#" + this.id).val())) == ($.trim($("#" + options.id).val()))) {
					$.ml.showTipState(this.id + "Tip", "onSuccess", options.oncorrect);
				} else {
					$.ml.showTipState(this.id + "Tip", "onError", options.onerror);
					pageValidate = false;
					addValidate = false;
				}
			});
		});
	};
	$.fn.clickTree = function (options) {
		if (typeof (tree) == "undefined") {
			return;
		}
		return this.each(function () {
			$.ml.showTipState(options.onwhere, "onShow", options.onshow);
			$(this).bind("click", function () {
				if (tree.getAllChecked()) {
					$.ml.showTipState(options.onwhere, "onSuccess", options.oncorrect);
				} else {
					$.ml.showTipState(options.onwhere, "onError", options.onerror);
				}
			});
		});
	};
	$.fn.controlOption = function (options) {
		return this.each(function () {
			$.ml.showTipState(options.showwhere, "onShow", options.onshow);
			$(this).bind("focus", function () {
				$.ml.showTipState(options.showwhere, "onFocus", options.onfocus);
			});
			$(this).bind("blur", function () {
				var num = 0;
				$(options.alloption).each(function () {
					if ("" != $.trim($(this).val())) {
						num++;
					}
				});
				if (num < options.least) {
					$.ml.showTipState(options.showwhere, "onError", options.onerror);
					pageValidate = false;
				} else {
					$.ml.showTipState(options.showwhere, "onSuccess", options.oncorrect);
				}
			});
		});
	};
	$.fn.compareWith = function (options) {
		return this.each(function () {
			var the=$(this);
			$('#'+options.id).bind("blur",function(){
				$(the).focus().blur();
			});
			if (options.onshow != "" && options.onshow != undefined) {
				$.ml.showTipState(this.id + "Tip", "onShow", options.onshow);
			}
			if (options.onfocus != "" && options.onfocus != undefined) {
				$(this).bind("focus", function () {
					addValidate = true;
					$.ml.showTipState(this.id + "Tip", "onFocus", options.onfocus);
				});
			}
			$(this).bind("blur", function () {
				var right = false;
				var first = $.trim($("#" + this.id).val());
				var second = $.trim($("#" + options.id).val());
				var regex = new RegExp(regexEnum.price);
				if (addValidate && options.type == "number" && (regex.test(second))) {
					right = eval(first + options.sign + second);
				} else {
					right = eval("\"" + first + "\"" + options.sign + "\"" + second + "\"");
				}
				if (addValidate && right) {
					if (options.oncorrect != undefined) {
						$.ml.showTipState(this.id + "Tip", "onSuccess", options.oncorrect);
					}
				} else {
					if (addValidate && options.onerror != "" && options.onerror != undefined) {
						$.ml.showTipState(this.id + "Tip", "onError", options.onerror);
					}
					pageValidate = false;
					addValidate = false;
				}
			});
		});
	};
	$.fn.between = function (options) {
		return this.each(function () {
			if (options.onshow != "" && options.onshow != undefined) {
				$.ml.showTipState(this.id + "Tip", "onShow", options.onshow);
			}
			if (options.onfocus != "" && options.onfocus != undefined) {
				$(this).bind("focus", function () {
					addValidate = true;
					$.ml.showTipState(this.id + "Tip", "onFocus", options.onfocus);
				});
			}
			$(this).bind("blur", function () {
				if (addValidate) {
					var inputvalue = $.trim($("#" + this.id).val());
					rightmin = eval(inputvalue + options.operators1 + options.min);
					rightmax = eval(inputvalue + options.operators2 + options.max);
					if (rightmin && rightmax) {
						if (options.oncorrect != "" && options.oncorrect != undefined) {
							$.ml.showTipState(this.id + "Tip", "onSuccess", options.oncorrect);
						}
					}
					if (!rightmin || !rightmax) {
						$.ml.showTipState(this.id + "Tip", "onError", options.onerror);
						addValidate = false;
						pageValidate = false;
					}
				}
			});
		});
	};
	/*$.fn.getCenterPosition=function(){
	$('#abc').get(0).clientHeight 为可视部分
	$('#abc').get(0).scrollTop		为上下的滚动距离
	$('#abc').get(0).scrollHeight	是内容的高度
	$('#abc').get(0).offsetHeight   加个边框和滚动条的内容高度
	//}*/
/*
    判断#a是否存在
	$('#a').isExist() 
*/
	$.fn.isExist=function(){
		if($(this).length==0)return false;
		else return true;
	};
/*
	弹出层效果layerdivClick:点击layerdiv层是否关闭alertdiv true为不关
jquerydiv.setLightBox({layoverBg:'#154',layoverOpa:'0.5',alertdivBg:'#fff',alertdivWidth:'540px',alertdivHeight:'310px',waitload:true,sureBut:'#suersub',sureFn:saveAlbumToSearve,suerPara:xml,closeSelfBut:'#colseself',closeBut:'#closeit,#closebut',layerdivClick:true      ,canNotDrag:true              ,multil:true})
	对应参数	mask层的背景色      mask层的透明度        弹出层的背景色       弹出层的宽               弹出层的高                   确定按钮，可多个     确定后执行的回调函数  确定的回调函数的参数      关闭弹出层的按钮，可多个  	关闭全部层的按钮，可多个		点击mask层是否关闭全部，true为不关闭  不能被拖动，true为不能被拖动  	此弹出层是否与先前的层共存，即是否能有多个弹出层存在																																只关闭弹出的层 				全部关闭																								
*/	
	$.fn.setLightBox=function(options){
		var layoverBg=options.layoverBg?options.layoverBg:'#fff';
		var layoverOpa=options.layoverOpa?options.layoverOpa:'0.5';
		var alertdivWidth=options.alertdivWidth?options.alertdivWidth:'auto';
		var alertdivHeight=options.alertdivHeight?options.alertdivHeight:'auto';
		var alertdivBg=options.alertdivBg?options.alertdivBg:'#fff';
		var closebut=options.closeBut;
		var layerdiv,alertdiv;
		if($('.layoverdiv').length==0){
			layerdiv=$('<div class="layoverdiv" style="position:fixed !important;position:absolute;width:100%;height:100%;z-index:9998;left:0;top:0;display:none;"></div>');
			alertdiv=$('<div class="alertdiv" style="overflow:auto;position:absolute;top:50%;left:50%;display:none;z-index:9999;"></div>');
			$('body').append(alertdiv).append(layerdiv);
		}else{
			layerdiv=$('.layoverdiv');
			if(options.multil){
				off=$('.alertdiv').length*3+50+'%';
				alertdiv=$('<div class="alertdiv alertmultil" style="overflow:auto;position:absolute;top:'+off+';left:'+off+';display:none;z-index:9999;"></div>');
				$('body').append(alertdiv);
			}else{
				$('.alertmultil').remove();
				alertdiv=$('.alertdiv');
			}
		}
		layerdiv.css('background',layoverBg);
		layerdiv.width($('body').width());
		layerdiv.height($('body').height())
		alertdiv.css('background',alertdivBg);
		alertdiv.css({'width':alertdivWidth,'height':alertdivHeight}).html('').append($(this));
		if(options.waitload){
			$(this).load(function(){
				alertdiv.css({'margin-left':'-'+(alertdiv.outerWidth()/2+'px'),'margin-top':'-'+(alertdiv.outerHeight()/2)+'px'});
			});
		}else{
			alertdiv.css({'margin-left':'-'+(alertdiv.outerWidth()/2+'px'),'margin-top':'-'+(alertdiv.outerHeight()/2)+'px'});
		}
		
		if(!options.multil){
		layerdiv.css('opacity','0').css('display','block').fadeTo(500,layoverOpa);
		}
		alertdiv.fadeIn();
		
		if(!options.canNotDrag){
			if(options.waitload){
				alertdiv.drag({dragbody: alertdiv,opacity: '0.8',preventEvent:true});
			}else{
				alertdiv.drag({dragbody: alertdiv,opacity: '0.8'});
			}
		}
		if(!options.layerdivClick&&!options.multil){
			layerdiv.click(function(){
				$.ml.closeLightBox();
			});
		}
		if(closebut!=undefined){
			$(closebut).click(function(){
				$.ml.closeLightBox();
			});
		}
		if(options.sureBut!=undefined){
			//,sureFn:saveAlbumToSearve,suerPara:xml
			$(options.sureBut).click(function(){
				if(!options.sureFn(options.suerPara))return;
				$.ml.closeLightBox();
			});
		}
		if(options.closeSelfBut!=undefined){
			alertdiv.find(options.closeSelfBut).click(function(){
				alertdiv.remove();
			});
		}
		/*http://www.cnblogs.com/cloudgamer/archive/2008/09/15/1290954.html*/
		/*$(window).resize(function(){
		 	if($('.layoverdiv').length!=0){
		 		$('.layoverdiv').get(0).style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
    			$('.layoverdiv').get(0).style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
    			alertdiv.css({'margin-left':'-'+(alertdiv.outerWidth()/2+'px'),'margin-top':'-'+(alertdiv.outerHeight()/2)+'px'});
		 	}
		});
		$(window).scroll(function(){
			if($('.layoverdiv').length!=0){
		 		$('.layoverdiv').get(0).style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
    			$('.layoverdiv').get(0).style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
    			alertdiv.css({'margin-left':'-'+(alertdiv.outerWidth()/2+'px'),'margin-top':'-'+(alertdiv.outerHeight()/2)+'px'});
		 	}
		});*/
	};
	$.ml = {showTipState:function (id, showclass, msg) {
		if(showclass=='onError')errormsgs+=(msg?('\r\n'+msg):'');
		var tip = $("#" + id);
		tip.removeClass('onShow onFocus onError onSuccess');
		tip.addClass(showclass);
		tip.html(msg);
	}, regexValidate:function (id, options) {
		if (options.regexp == undefined || options.regexp == "") {
			$.ml.showTipState(id + "Tip", "onSuccess", options.oncorrect);
			return false;
		}
		var regex = new RegExp(options.regexp);
		if (regex.test($.trim($("#" + id).val()))) {
			if (options.alertit == true && options.oncorrect != undefined) {
				alert(options.oncorrect);
			} else {
				if (options.oncorrect != undefined) {
					if (options.blankshownone && $.trim($("#" + id).val()) == "") {//
						$.ml.showTipState(id + "Tip", "blankshownone", "");
					} else {
						$.ml.showTipState(id + "Tip", "onSuccess", options.oncorrect);
					}
				}
			}
			if ($.trim($("#" + id).val()) == "") {
				addValidate = false;
			}
			return true;
		} else {
			if (options.alertit == true) {
				alert(options.onerror);
			} else {
				$.ml.showTipState(id + "Tip", "onError", options.onerror);
			}
			pageValidate = false;
			addValidate = false;
			return false;
		}
	}, submitTree:function (options) {
		if (typeof (tree) == "undefined") {
			return;
		}
		if (tree.getAllChecked()) {
			$.ml.showTipState(options.onwhere, "onSuccess", options.oncorrect);
			return true;
		} else {
			$.ml.showTipState(options.onwhere, "onError", options.onerror);
			pageValidate = false;
			return false;
		}
	}, moneyFormat:function (options) {
		var money = options.moneyvalue ? options.moneyvalue + "" : ($("#" + options.moneyidval).val() ? $("#" + options.moneyidval).val() : $("#" + options.moneyidval).html());
		if (money == null || money == undefined) {
			return "noexist";
		}
		money = $.trim(money);
		if (money == "") {
			return 0;
		}
		money = money.toUpperCase();
		if (!money.match(/^(￥|＄|\$|¥|€|£|₩|RMB|USD|JPY|EUR|GBP|KRW)?-?0*((([1-9][0-9]+)|[0-9]{1})(\.[0-9]+)?)$/)) {
			return "notmoney";
		}
		var moneyhead = money.match(/^((￥|＄|\$|¥|€|£|₩|RMB|USD|JPY|EUR|GBP|KRW)?-?)0*((([1-9][0-9]+)|[0-9])(\.[0-9]+)?)$/)[1];
		if (moneyhead == undefined) {
			moneyhead = "";
		}
		var moneytail = money.match(/^((￥|＄|\$|¥|€|£|₩|RMB|USD|JPY|EUR|GBP|KRW)?-?)0*((([1-9][0-9]+)|[0-9])(\.[0-9]{1,3})?[0-9]*)$/)[6];
		if (moneytail == undefined) {
			moneytail = "";
		} else {
			if (moneytail.length == 4) {
				var tail1 = moneytail.match(/^\.([0-9])[0-9][0-9]$/)[1];
				var tail2 = moneytail.match(/^\.[0-9]([0-9])[0-9]$/)[1];
				var tail3 = moneytail.match(/^\.[0-9][0-9]([0-9])$/)[1];
				if (parseInt(tail3) >= 5) {
					moneytail = "." + tail1 + (parseInt(tail2) + 1);
				} else {
					moneytail = "." + tail1 + tail2;
				}
			}
		}
		var moneymid = money.match(/^((￥|＄|\$|¥|€|£|₩|RMB|USD|JPY|EUR|GBP|KRW)?-?)0*((([1-9][0-9]+)|[0-9])(\.[0-9]+)?)$/)[4];
		if (moneymid == undefined) {
			moneymid = "";
		}
		moneymid = moneymid.match(/./g).reverse();
		moneymid = moneymid.join("").match(/(\d{3})*?\d{1,3}/g).toString();
		moneymid = moneymid.match(/./g).reverse().join("");
		money = moneyhead + moneymid + moneytail;
		return money;
	}, moneyFormatInner:function (para) {
		$(para).each(function () {
			$(this).html($.ml.moneyFormat({moneyvalue:$(this).html()}));
		});
/*
参数 按钮数组 内容数组 开始显示那个组 怎么触发 回调函数
例子
var buts1=['.tag-user-1','.tag-user-2'];
var tabs1=['.user-type-1','.user-type-2'];
$.ml.butShowTab(buts1,tabs1,0,'click');

var buts1=['.but'];but 和tab有多个，且都是一一对应
var tabs1=['.tab'];
$.ml.butShowTab(buts1,tabs1,0,'click',backfn);
*/
	},butShowTab:function(buts,tabs,num,targe,backfn,speed){
		$(tabs.join()).css('display','none');
		$(tabs.join()).eq(num).css('display','block');
		$(buts.join()).each(function(i){
			if(num!=i){
				$(this).addClass('imagenone');
			}
			eval('$(this).'+targe+'(function(){'+
				'$(buts.join()).addClass("imagenone");'+
				'$(tabs.join()).stop(null,true).fadeTo(speed,0.1,function(){$(tabs.join()).css("display","none");$(tabs.join()).eq(i).css("display","block");});'+
				//$(tabs.join()).css("display","none");
				//'$(buts.join()).eq(i).removeClass("imagenone");'+
				//'$(tabs.join()).eq(i).css("display","block");'+
				'$(tabs.join()).eq(i).stop(null,true).fadeTo(speed,1,function(){backfn?backfn(i):";"});'+
				//'backfn?backfn(i):";"'+
			'});');			
		});		
	},closeLightBox:function(options){
		alertdiv=$('.alertdiv,.layoverdiv').fadeOut();
	}
	};
})(jQuery);
String.prototype.replaceAll = stringReplaceAll;
function stringReplaceAll(AFindText,ARepText){
	raRegExp = new RegExp(AFindText,"g");
	return this.replace(raRegExp,ARepText)
}
//改变URL，使得其能够正常发送到服务(特殊字符)
function modifURL(url){
	url=url.replace(/\%/g,'%25');
	url=url.replace(/\+/g,'%2B');
	url=url.replace(/ /g,'%20');
	url=url.replace(/[\/]/g,'%2F');
	url=url.replace(/\?/g,'%3F');
	url=url.replace(/#/g,'%23');
	url=url.replace(/&/g,'%26');
	url=url.replace(/=/g,'%3D');
	return url;
}
function str2html(str){
	str=str.replaceAll(' ','&nbsp;');
	str=str.replaceAll('\n','<br/>');
	str=str.replaceAll('>','&gt;');
	str=str.replaceAll('<','&lt;');
	str=str.replaceAll('"','&quot;');
	str=str.replaceAll('\'','&#39;');
	return str;
}
//得到指定字节数的字符串
function cutText(str,len,append){
var a = 0;
var i = 0;
var temp = '';
for (i=0;i<str.length;i++) {
	if (str.charCodeAt(i)>255) a+=2;
	else a++;
	if(a > len) return temp+(append?append:'');
	temp += str.charAt(i);
}
return str;
}
//返回字符串的字节长度
function getByteCounts(str){
	var a=0;
for (i=0;i<str.length;i++) {
	if (str.charCodeAt(i)>255) a+=2;
	else a++;
}
return a;
}
//添加为收藏<a href="#" onclick="AddFavorite(window.location,document.title)"></a> 
function AddFavorite(sURL, sTitle)
{
    try
    {
         window.external.addFavorite(sURL, sTitle);
     }
    catch (e)
    {
        try
        {
             window.sidebar.addPanel(sTitle, sURL, "");
         }
        catch (e)
        {
             alert("加入收藏失败，请使用Ctrl+D进行添加");
         }
     }
}
//设为首页<a href="#" onclick="SetHome(this,window.location)">设为首页</a> 
function SetHome(obj,vrl){
        try{
                 obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
         }
        catch(e){
                if(window.netscape) {
                        try {
                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                         }
                        catch (e) {
                                 alert("此操作被浏览器拒绝！请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
                         }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService

(Components.interfaces.nsIPrefBranch);
                         prefs.setCharPref('browser.startup.homepage',vrl);
                  }
         }
} 
