﻿//create by jian 2009 11 04
;(function($){
$.fn.mkValue=function(){
var r={};
this.find("input,select,textarea").each(function(){if(this.name)r[this.name.replace(/^\w+\$/,'')]=$.trim(this.value);});
return r;
};
$.fn.ckValue=function(){
var r=1;
 this.each(function(){
var o=$(this).parent().prev(), e=$(this).attr("require"),v=$.trim(this.value);
if(!o.is("th"))o=o.next();
if(e==undefined){if(v)e=$(this).attr("option");}
 if(e!=undefined){
 switch(e){
 case"price":e=/^-?\d+(?:\.\d{1,2})?$/; break;
 case"email": e=/^(?:[\w-]+\.?)*[\w-]@[\w-]+(?:\.[a-zA-z]{2,4})+$/; break;
 case"num": e=/^\d+/; break;
 default: e=e?new Regex(e):/\S*/;
 }var t=this.type;
 if(t=='checkbox'||t=="radio"){
 $(t+":name="+this.name).each(function(){if(!this.checked)v="";} ); }
 if(v&&e.test(v)){ o.css({color:""}); }else{ o.css({color:"Red"});r=0;this.focus(); } }
});
return !!r;
};
$.ckValues=function(f){
return $('input,select,textarea',f).ckValue();
};
$.ckForm=function(f,v){$(f).submit(function(){
return $.ckValues(v) ;});};
})(jQuery);


