//js工具类
var util = new function(){
	//获得字节长度
	this.getLength = function(str){
		var len = 0; 
		for (var i = 0; i < str.length;) {
			if((str.charCodeAt(i)>=0) && (str.charCodeAt(i)<=255)){
				len += 1;
			}else{
				len += 2;
			}
			i +=1;
		}
		return len; 
	}
	//过滤空格
	this.ignoreSpaces=function(string) {
		var temp = "";
		string = '' + string;
		splitstring = string.split(" ");
		for(i = 0; i < splitstring.length; i++){
			temp += splitstring[i];
		}
		return temp;
	}
	//重定向
	this.forward = function(url){
		location.href = url;
	}
	//验证邮箱
	this.isEmail = function(strEmail) {
		if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
			return true;
		}
		else{
			return false;
		}
	}
	//空判断
	this.isEmpty = function(str){
		if(str == null || str == '' || str == undefined){
			return true;
		}else{
			return false;
		}
	}
	//是否为数字
	this.isNumber = function(str){
		var reg = /^[0-9]*$/;
		if(reg.test(str)){
			return true;
		}else{
			return false;
		}
	}
	//是否为字符
	this.isChar = function(str){
		var reg = /^[a-zA-Z]*$/;
		if(reg.test(str)){
			return true;
		}else{
			return false;
		}
	}
	//局部刷新验证码
	this.getCode = function(url){
		var timestamp = (new Date()).valueOf();
		if((url.indexOf("?") >= 0)){
			url = url + "&t=" + timestamp;
		}else{
			url = url + "?t=" + timestamp;
		}
		$('#code').attr('src',url);
	}
	//ip验证
	this.isIp = function(ip){
		//var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/;
		//内网外网简单校验ip
		var reg =/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
		if(reg.test(ip)) {
			return true;
		}
		else{
			return false;
		}
	}
	
	//图片没有找到默认图片替换
	this.nofind = function (path,obj){ 
		//var img=event.srcElement;
		var img=obj;
		img.src=path+"/images/nophoto.jpg";
		img.onerror=null;//控制不要一直跳动 
	}
}