document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
	var classes = elem[i].className;
	if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}; 

function resizeBlocks(){
	if(!document.getElementById('cright')){
		var marginBlock = 10;
		var widthBlockMin = 330;
		var middiv = document.getElementById('cmid');
		var blocks = document.getElementsByClassName('datablock');
		var blocksInner = document.getElementsByClassName('datablockinner');
		var blocksTitle = document.getElementsByClassName('bmmodtitle');
		
		
	
		availablewidth = middiv.offsetWidth;
		widthBlock = widthBlockMin;
		restSpace = availablewidth / (widthBlock + marginBlock);
		colamount = Math.floor(restSpace);
		percRestSpace = restSpace - colamount;
		
		newWidth = Math.floor((availablewidth - (colamount*marginBlock)) / colamount);
		if(newWidth < widthBlockMin) newWidth = widthBlockMin;
		for(i=0; i < blocks.length; i++){
			blocks[i].style.width = newWidth + 'px';
			blocksInner[i].style.width = (newWidth-20) + 'px';
			blocksTitle[i].style.width = (newWidth-10) + 'px';
		}
	}
}

function decodeEmail(href){
	return href.replace(/.*contact\/([a-z0-9._%-]+)\+([a-z0-9._%-]+)\+([a-z.]+)/i, '$1' + '@' + '$2' + '.' + '$3');
}

function emailObfusc_decode(anchor) { // function to recompose the orginal address
	var href = anchor.getAttribute('href');
	var address = decodeEmail(href);
	var linktext = anchor.innerHTML; // IE Fix
	if (href != address) {
		anchor.setAttribute('href','mailto:' + address);
		anchor.innerHTML = linktext; // IE Fix
	}
}

function emailObfusc_decode2(anchor) { // function to recompose the orginal address
	//var href = anchor.getAttribute('href');
	var href = 'contact/' + anchor.innerHTML;
	var address = decodeEmail(href);
	if (href != address) {
		return address;
	}
	return false;
}

function gracefulEmailObfuscation() {
	if (!document.getElementsByTagName) // Check for browser support
			return false;
	var links = document.getElementsByTagName('a'); // Get all anchors
	for (var l = 0 ; l < links.length ; l++) { // Loop through the anchors
		//alert(links[l].getAttribute('href'));
		if(typeof links[l].onclick == 'undefined' || links[l].onclick == undefined || links[l].onclick == ''){
			links[l].onclick = function() { // Encode links when clicked
				emailObfusc_decode(this);
			}
			if(links[l].getAttribute('rel') == 'nofollow'){
				decoded = emailObfusc_decode2(links[l]);
				
				if(decoded) links[l].innerHTML = decoded;
			}
		}
	}
}
