﻿/**
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;
	};
/*
	自动移动多个元素
	function goLeftRight(left,right,items,i){
	items.parent().css({position:'relative',overflow:'hidden'});
	items.parent().wrapInner('<div></div>');
	items.parent().css('position','absolute');
	var offw=items.eq(0).outerWidth();
	var allw=items.outerWidth()*(items.length);
	items.parent().width(allw+'px');
	$(left).click(function(){
		if(items.parent().queue('fx').length!=0)return;
		if(items.parent().position().left+allw-offw*i<10)return;
		items.parent().animate({left:'-='+offw+'px'},500);
	});
	$(right).click(function(){
		if(items.parent().queue('fx').length!=0)return;
		if(items.parent().position().left>-10)return;
		items.parent().animate({left:'+='+offw+'px'},500);
	});
}
	$('.theimg').moveBlock({off:4,movespeed:1000,stoptime:1000});
*/
	$.fn.moveBlock=function(options){
		var opt=options.opt?options.opt:'left';
		var off=options.off?options.off:1;
		var movespeed=options.movespeed?options.movespeed:400;
		var stoptime=options.stoptime?options.stoptime:1000;
		var seewidth=$(this).parent().width();
		$(this).parent().css({position:'relative',overflow:'hidden'});
		$(this).parent().wrapInner('<div></div>');
		$(this).parent().css('position','absolute');
		var offw=$(this).eq(0).outerWidth()*off;
		var allw=$(this).outerWidth()*($(this).length);
		$(this).parent().width(allw+'px');
		
		var marquee=jqmoveBlock($(this),movespeed,offw,allw,off,seewidth);
		var MyMar=setInterval(marquee,stoptime)
		$(this).parent().mouseover(function() {clearInterval(MyMar)});
		$(this).parent().mouseout(function() {MyMar=setInterval(marquee,stoptime)}); 
	};
/*
	局部放大
*/
$.fn.showPartImg=function(options){
  if(!options)options={};
  var src=$(this).attr('bigsrc');
  src=src?src:$(this).attr('src');
  var imgW=$(this).width();
  var imgH=$(this).height();
  var width=options.width?options.width:(imgW+'px');
  var height=options.height?options.height:(imgH+'px');
  var x=options.x?options.x:($(this).width()+10+'px');
  var y=options.y?options.y:0;
  var imgoff=$(this).offset();
  var img=$(this);
  
  img.wrap('<div style="position:relative;"></div>');
  img.parent().append('<div class="bigimgdiv" style="visibility:hidden;position:absolute;left:'+x+';top:'+y+';width:'+width+';height:'+height+';overflow:hidden;background:url('+src+') no-repeat;"><img style="display:none;width:auto;height:auto;" src="'+src+'"/></div>');
  
  img.parent().find('.bigimgdiv img').load(function(){
   
   var bigimgW=img.parent().find('.bigimgdiv img').width();
   var bigimgH=img.parent().find('.bigimgdiv img').height();
   var moveW=((parseInt)(width))*imgW/bigimgW;
   var moveH=((parseInt)(height))*imgH/bigimgH;
   img.parent().append('<div class="bigimgmove" style="left:0;top:0;border:1px solid #ccc;background-color:#eee;position:absolute;width:'+moveW+'px;height:'+moveH+'px;display:none;">&nbsp;</div>');
   img.parent().find('.bigimgmove').css({'opacity':'0.6','cursor':'pointer'});
   /* 构造原图完毕*/
   
   img.parent().mouseover(function(){
    $(this).find('.bigimgmove').css('display','block');
    $(this).find('.bigimgdiv').css('visibility','visible');
    
   });
   img.parent().mouseout(function(){
    $(this).find('.bigimgmove').css('display','none');
    $(this).find('.bigimgdiv').css('visibility','hidden');
   });
   
   img.parent().mousemove(function(e){
    var bigimgmove=$(this).find('.bigimgmove');
    bigimgmove.css('display','block');
    var offX=bigimgmove.width()/2;
    var offY=bigimgmove.height()/2;
    var left=(window.event||e).clientX+document.documentElement.scrollLeft;
    var top=(window.event||e).clientY+document.documentElement.scrollTop;
    var imgleft=imgoff.left;
    var imgtop=imgoff.top;
    var truex=((left-offX)-imgleft)>0&&left<((imgleft-offX)+imgW);
    var truey=((top-offY)-imgtop)>0&&top<((imgtop-offY)+imgH);
    var bigimgpos=bigimgmove.position();
    if(truex){
     bigimgmove.css('left',left-offX-imgleft+'px');
    }
    if(truey){
     bigimgmove.css('top',top-offY-imgtop+'px');
    }
    if(((left)-imgleft)<0||left>((imgleft)+imgW)||((top)-imgtop)<0||top>((imgtop)+imgH)){
     bigimgmove.css('display','none');
    }
    $(this).find('.bigimgdiv').css('background-position','-'+bigimgW*bigimgpos.left/imgW+'px -'+bigimgH*bigimgpos.top/imgH+'px');
   });
   img.parent().find('.bigimgdiv').mousemove(function(){
    $(this).css('visibility','hidden'); 
   });
  });
  
 }
/*
	类似GOOGLE的提示搜索
	$('theinput').searchRemind({left:'2px',top:'25px',width:'200px',url:'index2.php?options=com_user'});
	　　　　　　　　　　　　　　　　　相对对自身输入框父亲左边,相对对自身输入框父亲上部,提示的宽度,取数据的路径(用#@!分开)
*/
	$.fn.searchRemind=function(options){
		var left = options.left?options.left:'0';
		var top = options.top?options.top:'25px';
		var width = options.width?options.width:'200px';
		var url = options.url;
		var theinput = $(this);
		var index=0;
		var getstr='';
		var inputstr='';
		$(this).parent().css('position','relative');
		$(this).attr('autocomplete','off');
		var outdiv = $('<div class="searchoutdiv" style="z-index:999999;left:'+left+';top:'+top+';width:'+width+';position:absolute;background-color:#fff;border:1px solid #888;display:none;"></div>');
		$(this).parent().append(outdiv);
		
		$(this).keyup(function(event){
			if(inputstr==$(this).val()){
				return;
			}else{
				inputstr=$(this).val();
				getstr='';
			}
			if(event.keyCode==38||event.keyCode==40)return;
			$.ajax({
			url:url,
			data:'keyword='+theinput.val(),
			type:'post',
			dataType:'text',
			timeout:15000,
			error: function(){
				alert('通信失败，请重试');
			},
			success:function(text){
				if(getstr==$.trim(text)){
					return;
				}else{
					getstr=text;
					index=0;
				}
				if($.trim(text)==''){
					outdiv.html('');
					return;
				}
				index=0;
				var items = $.trim(text).split('#@!');
				outdiv.css('display','block');
				index=0;
				outdiv.html('');
				for (i in items){
					if($.trim(items[i])=='')continue;
					outdiv.append('<div>'+items[i]+'</div>');
				}
				outdiv.find('div').each(function(i){
					$(this).mouseover(function(){
						index=i+1;
						outdiv.find('div').css('background-color','#fff');
						$(this).css('background-color','#888');
					}).mouseout(function(){
						index=0;
						outdiv.find('div').css('background-color','#fff');
						$(this).css('background-color','#fff');
					}).click(function(){
						theinput.attr('value',$(this).text());
					}).css('cursor','default');
				});
			}	 
			});
		});
		$('body').click(function(){
			outdiv.css('display','none');
		});
		$('body').keydown(function(event){
			if(event.keyCode==38){
				if(index==1)index=outdiv.find('div').length+1;
				index--;
				outdiv.find('div').css('background-color','#fff');
				outdiv.find('div').eq(index-1).css('background-color','#888');
				theinput.attr('value',outdiv.find('div').eq(index-1).text());
			}
			if(event.keyCode==40){
				if(index==outdiv.find('div').length)index=0;
				index++;
				outdiv.find('div').css('background-color','#fff');
				outdiv.find('div').eq(index-1).css('background-color','#888');
				theinput.attr('value',outdiv.find('div').eq(index-1).text());
			}
		});
	};

/*
	弹出层效果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:absolute;width:100%;height:100%;z-index:9998;left:0;top:0;display:none;"></div>');
			alertdiv=$('<div class="alertdiv" style="overflow:auto;position:fixed !important;poposition: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($('html').width());
		layerdiv.height($('html').height())
		alertdiv.css('background',alertdivBg);
		alertdiv.css({'width':alertdivWidth,'height':alertdivHeight}).html('').append($(this));
		
		if(!options.multil){
			layerdiv.css('opacity','0').css('display','block').fadeTo(500,layoverOpa);
		}
		alertdiv.fadeIn();
		
		if(!options.canNotDrag){
			if(alertdiv.find('img').length!=0){
				alertdiv.drag({dragbody: alertdiv,opacity: '0.8',preventEvent:true});
			}else{
				alertdiv.drag({dragbody: alertdiv,opacity: '0.8'});
			}
		}
		//if(alertdiv.css('position')!='fixed'){
			alertdiv.css({'margin-left':'-'+(alertdiv.outerWidth()/2+'px'),'margin-top':'-'+(alertdiv.outerHeight()/2)+'px'}); 
			$(this).add($(this).find('img')).load(function(){
				alertdiv.css({'margin-left':'-'+(alertdiv.outerWidth()/2+'px'),'margin-top':'-'+(alertdiv.outerHeight()/2)+'px'});
			});
		//}
		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,startfn,speend);
*/
	},butShowTab:function(buts,tabs,num,targe,backfn,startfn,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(){'+
				'startfn?startfn(i):";";'+
				'$(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);
                  }
         }
} 
/**
	点击后左右移动
	item为要移动的元素<div><a>20/a><a>fds</a></div>,item=div
	$(document).ready(function(){
	goLeftRight('#pre','#next','img',3);	
	});
*/
function goLeftRight(right,left,items,i){
items.parent().css({position:'relative',overflow:'hidden'});
items.parent().wrapInner('<div></div>');
items.parent().css('position','absolute');
var offw=items.eq(0).outerWidth();
var allw=items.outerWidth()*(items.length);
items.parent().width(allw+'px');
$(left).click(function(){
if(items.parent().queue('fx').length!=0)return;
if(items.parent().position().left+allw-offw*i<10)return;
items.parent().animate({left:'-='+offw+'px'},500);
});
$(right).click(function(){
if(items.parent().queue('fx').length!=0)return;
if(items.parent().position().left>-10)return;
items.parent().animate({left:'+='+offw+'px'},500);
});
}
/*
	循环移动方法
	jqmoveBlock($(this),movespeed,offw,allw,off,seewidth);
*/
function jqmoveBlock(items,speed,offw,allw,off,seewidth){
	var items=items;var speed=speed;var offw=offw;var allw=allw;var off=off;var seewidth=seewidth;
	return (function(){
		if(items.parent().queue('fx').length!=0)return;
		if(items.parent().position().left+allw-seewidth<10){
			items.parent().append(items.slice(0,off));
			items.parent().css('left','0');
		}
		if(allw-(seewidth-items.parent().position().left)<=offw){
			offw2=allw-(seewidth-items.parent().position().left);
			items.parent().animate({left:'-='+offw2+'px'},speed);
		}else{
			items.parent().animate({left:'-='+offw+'px'},speed);
		}
	});	
}
/*
	图片切换
	imagesSwitch('#pre','#next',$('.item'),400,3);
*/
function imagesSwitch(left,right,items,switchtime,num){
	switchtime=(parseInt(switchtime))?switchtime:400;
	items.parent().css({position:'relative',overflow:'hidden'});
	items.parent().wrapInner('<div></div>');
	items.parent().css('position','absolute');
	var offw=items.eq(0).outerWidth();
	var allw=items.outerWidth()*(items.length);
	items.parent().width(allw+'px');
	var len=items.length;
	$(left).click(function(){
		items.parent().animate({opacity:'0.2'},switchtime,function(){
			items.parent().append(items.parent().find('>').slice(0,num));
			items.parent().animate({opacity:'1'},switchtime);
		});
	});
	$(right).click(function(){
		items.parent().animate({opacity:'0.2'},switchtime,function(){
			items.parent().prepend(items.parent().find('>').slice(len-num,len));
			items.parent().animate({opacity:'1'},switchtime);
		});
	});
}
/*
	图片切换3
	imagesSwitch3('#pre','#next',$('.item'),400,3,500,'left');
*/
function imagesSwitch3(left,right,items,movetime,num,stoptime,pos){
	movetime=(parseInt(movetime))?movetime:400;
	items.parent().parent().css({position:'relative',overflow:'hidden'});
	//items.parent().wrapInner('<div></div>');
	items.parent().css('position','absolute');
	var offw=items.eq(0).outerWidth();
	var allw=items.outerWidth()*(items.length);
	var movew=offw*num;
	var pos=pos?pos:'left';
	var stoptime=stoptime?(stoptime+movetime):1000;
	//items.parent().width(allw+'px');
	items.parent().width('530px');
	var len=items.length;
	var isclick=false;
	
	var marquee=imagesAutoSwitch3(items,movetime,pos,movew,num,len);
	var MyMar=setInterval(marquee,stoptime);
	//items.parent().mouseover(function() {clearInterval(MyMar)});
	//items.parent().mouseout(function() {MyMar=setInterval(marquee,stoptime)});
	 items.parent().hover(
     function() {clearInterval(MyMar)},
     function() {
			marquee=imagesAutoSwitch3(items,movetime,pos,movew,num,len);
			if(items.parent().queue('fx').length==0)marquee();
			MyMar=setInterval(marquee,stoptime);
		}
	);
	$(left+','+right).mouseout(function(){
		if(!isclick)return;
		isclick=false;
		marquee=imagesAutoSwitch3(items,movetime,pos,movew,num,len);
		MyMar=setInterval(marquee,stoptime);
	});
	
	$(left).click(function(){
		clearInterval(MyMar);
		if(items.parent().queue('fx').length!=0)return;
		isclick=true;
		items.parent().prepend(items.parent().find('>').slice(len-num,len));
		items.parent().css('left','-'+movew+'px');
		items.parent().animate({left:'+='+movew+'px'},movetime,function(){
			//items.parent().append(items.parent().find('>').slice(0,num));
			items.parent().css('left',0);
		});
		pos='right';
	});
	$(right).click(function(){
		clearInterval(MyMar);
		if(items.parent().queue('fx').length!=0)return;
		isclick=true;
		items.parent().animate({left:'-='+movew+'px'},movetime,function(){
			//items.parent().prepend(items.parent().find('>').slice(len-num,len));
			items.parent().append(items.parent().find('>').slice(0,num));
			items.parent().css('left',0);
		});
		pos='left';
	});
	
}
function imagesAutoSwitch3(items,movetime,pos,movew,num,len){
	return (function(){
			if(pos=='left'){
				items.parent().animate({left:'-='+movew+'px'},movetime,function(){
					items.parent().append(items.parent().find('>').slice(0,num));
					items.parent().css('left',0);
				});
			}else{
				items.parent().prepend(items.parent().find('>').slice(len-num,len));
				items.parent().css('left','-'+movew+'px');
				items.parent().animate({left:'+='+movew+'px'},movetime,function(){
					items.parent().css('left',0);
				});
			}
		});
}

/*
	图片切换2
	imagesSwitch2('#pre','#next',imgarray,hrefarray,titlearray,400,$('.item'),$('.content'));
*/
function imagesSwitch2(left,right,imgarray,hrefarray,titlearray,switchtime,items,theparent){
	switchtime=(parseInt(switchtime))?switchtime:400;
	var imgi=0;
	var imglen=imgarray.length;
	var len=items.length;
	$(left).click(function(){
		theparent.animate({opacity:'0.2'},switchtime,function(){
			items.each(function(i){
				items.eq(i).find('img').attr('src',imgarray[(imgi+i+len)%imglen]);
				items.eq(i).find('a').attr('href',hrefarray[(imgi+i+len)%imglen]);
				items.eq(i).find('span').text(titlearray[(imgi+i+len)%imglen]);
			});
			imgi=(imgi+len)%imglen;
			theparent.animate({opacity:'1'},switchtime);
		});
	});
	$(right).click(function(){
		theparent.animate({opacity:'0.2'},switchtime,function(){
			items.each(function(i){
				items.eq(i).find('img').attr('src',imgarray[(imgi-len+i+imglen)%imglen]);
				items.eq(i).find('a').attr('href',hrefarray[(imgi-len+i+imglen)%imglen]);
				items.eq(i).find('span').text(titlearray[(imgi-len+i+imglen)%imglen]);
			});
			imgi=(imgi-len+imglen)%imglen;
			theparent.animate({opacity:'1'},switchtime);
		});
	});
}