var occurence=0;
var textvalue;
//var finalvalue;
function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {	
		if (x[i].getAttribute('maxlength')) {		
			x[i].onkeyup = checkMaxLength;			
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;		
	if (currentLength >= maxLength){
		occurence = occurence+1;
		/*if(occurence == 1){			
			textvalue = (this.value).substring(0,maxLength);
			finalvalue=textvalue;
		}else if((occurence!=0)&&(occurence>1)){
			finalvalue = textvalue;
		}else{*/
			finalvalue = (this.value).substring(0,maxLength);
		//}
		this.value=finalvalue;
	}
	/*else{
		this.relatedElement.className = '';
	}
	this.relatedElement.firstChild.nodeValue = currentLength;*/
	// not innerHTML
}