function getLen(str) {
     var len = 0;
     for (var i=0; i<str.length; i++) {
      if (str.charCodeAt(i) > 127)
       len += 2; //utf8格式下中文占3位，gb2312请修改位2位
      else 
       len++;
     }
     return len;
}

//function for roundedRectClass
function hex2num(hex){
	if(hex.charAt(0) == "#") hex = hex.slice(1);
	hex = hex.toUpperCase();
	var value = new Array(3);
	var k = 0;
	for(var i=0;i<6;i+=2){
		value[k]=parseInt("0x"+hex.substr(i,2),16);
		k++;
	};
	return value;
}
//function for roundedRectClass
function num2hex(triplet){
	var hex="#";
	var hR=triplet[0].toString(16);
	var hG=triplet[1].toString(16);
	var hB=triplet[2].toString(16);
	var value="#"+(triplet[0]<16?("0"+hR):hR)+(triplet[1]<16?("0"+hG):hG)+(triplet[2]<16?("0"+hB):hB)
	return value.toUpperCase();  
}
//class for rounded rectangle background
var roundedRectClass = new Class({
	Implements: Options,
	options:{
		canvas: 'cav',
		fillStyle: "#f4ffef",
		strokeStyle: "#43dd00",
		lineWidth: 4,
		radius: 5,
		useShadow: true,
		shadowColor: "#43dd00",
		shadowBlur: 5,
		zIndex: 10,
		contentPadding: 20
	},
	initialize: function(target, content, options){
		this.options = $extend(this.options, options);
		var offset = 2;
		target.setStyles({"z-index":this.options.zIndex, "position":"relative"});
		content.setStyles({"padding":this.options.contentPadding+"px"});
		var w = target.getStyle("width").toInt()-offset;
		var h = target.getStyle("height").toInt()-offset;
		var canvas = new Element("canvas", {
			"id" : "csv-" + canvas,
			"width": w,
			"height": h
		}).setStyles({"position":"absolute","top":"0px", "left":"0px", "z-index":-1}).inject(content, "before");
		if(Browser.Engine.trident)
			G_vmlCanvasManager.initElement(canvas);
		var ctx = canvas.getContext("2d");
		if(this.options.useShadow == true){
			for (var x = 0; x <= this.options.shadowBlur; x++){
				this.roundedRect(
					ctx,
					offset + x,
					offset + x,
					w - (x * 2) - offset,
					h - (x * 2) - offset,
					this.options.radius + (this.options.shadowBlur - x),
					hex2num(this.options.shadowColor),
					x == this.options.shadowBlur ? 1 : 0.06 + (x * 0.01)
				);
			}
		}else this.roundedRect(ctx, offset+this.options.lineWidth, offset+this.options.lineWidth, w-offset-this.options.lineWidth*2, h-offset-this.options.lineWidth*2, this.options.radius, hex2num(this.options.strokeStyle), 1000);
	},
	roundedRect: function(ctx, x, y, width, height, radius, rgb, a){
		if(a<1)ctx.fillStyle = 'rgba(' + rgb.join(',') + ',' + a + ')';
		else{
			ctx.fillStyle = this.options.fillStyle; 
			ctx.strokeStyle = this.options.strokeStyle;
			ctx.lineWidth = this.options.lineWidth;
			if(a==1000)ctx.strokeStyle = num2hex(rgb);
		}
		ctx.beginPath();
		ctx.moveTo(x, y + radius);
		ctx.lineTo(x, y + height - radius);
		ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
		ctx.lineTo(x + width - radius, y + height);
		ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius);
		ctx.lineTo(x + width, y + radius);
		ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
		ctx.lineTo(x + radius, y);
		ctx.quadraticCurveTo(x, y, x, y + radius);
		ctx.fill(); 
		if(a==1||a==1000)ctx.stroke();
	}
});

function verifyMobile(mobile){
	var reg=/(^0{0,1}1[3|5|8][0-9]{9}$)/; 
	return reg.test(mobile);
}