var pageValidate=true;
var addValidate=true;
var millisecondnow=0;
(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(){
pageValidate=true;
var theform=$(this).get(0).getAttributeNode("id").value;
$("#"+theform+ " ."+options.css).each(function(){
addValidate=true;
$(this).blur();
});
if(!pageValidate){
if(options.alertmsg){
alert(options.alertmsg);
}else{
alert("对不起，您的输入有误，请重输");
}
}
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){
returnthis.each(function(){
$.ml.showTipState(this.id+"Tip","onShow",options.onshow);
$(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){
returnthis.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(){
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!=""&&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){
returnthis.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;
} 
}
});
});
};
$.ml = {
showTipState:function(id,showclass,msg){
var tip=$("#"+id);
tip.removeClass();
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!=""&&options.oncorrect!=undefined){
alert(options.oncorrect);
}else if(options.oncorrect!=""&&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()}));
});
}
}
})(jQuery);
function clock(){
setTimeout("clock()",1000);
millisecondnow=millisecondnow+1000;
}