// 自定义全局通用函数
//
// Version 1.0
(function($) {
	//是否为数字
	isNum = function(N){
		if(typeof(N)!='string'){
			N = N+"";
		}
	    numtype="0123456789";
	    for(i=0;i<N.length;i++){
		    if(numtype.indexOf(N.substring(i,i+1))<0)
		    	return false; 
	  	}
	    return true;
	}
	//是否为定长的浮点数
	isUnsigned = function (strNum,strLen){
		if(typeof(strNum)!='string'){
			strNum = strNum+"";
		}
		if(strNum.search(/^\d+(\.\d+)?$/)!=-1){
			var s = strNum.split(".");
			if(s.length<2) return true;
			if(s[1].length>strLen) return false;
			else return true;
		}else{
			return false;
		}
	}
	//email校验
	isEmail = function (mail) {
	 	return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
	}
	
	$.send = function(url, data, callback, errCallback, type){
		if ( jQuery.isFunction( data ) ) {
			if( !jQuery.isFunction( callback ) ){
				type = callback;
				errCallback = function(){ };
			}else{
				type = errCallback;
				errCallback = callback;
			}
			callback = data;
			data = {};
		}else if( !jQuery.isFunction( errCallback ) ) {
			type = errCallback;
			errCallback = function(){ };
		}
		
		return jQuery.ajax({
			type: "GET",
			url: url,
			data: data,
			success: callback,
			error: errCallback,
			dataType: type
		});
	}

	systemMsg = function () {
		return '<table class="content"><tr><td class="textleft">网络繁忙，请重试</td></tr></table>';
	}
	
	$.obj2str = function (o){
	   var r = [];
	   if(typeof o == "string" || o == null) {
	     return o;
	   }
	   if(typeof o == "object"){
	     if(!o.sort){
	       r[0]="{"
	       for(var i in o){
	         r[r.length]=i;
	         r[r.length]=":";
	         r[r.length]= $.obj2str(o[i]);
	         r[r.length]=",";
	       }
	       r[r.length-1]="}"
	     }else{
	       r[0]="["
	       for(var i =0;i<o.length;i++){
	         r[r.length]= $.obj2str(o[i]);
	         r[r.length]=",";
	       }
	       r[r.length-1]="]"
	     }
	     return r.join("");
	   }
	   return o.toString();
	}

	$.str2obj = function (json){ 
		return eval("("+json+")"); 
	}

})(jQuery);