addLoadEvent(function() {
	
	// Retrieve an array of all divs that have their class set to 'edit'
	var editingDivs = getElementsByClass('edit');
	
	// Loop around the editing divs and register onclick event to launch editing window
	for(var i=0; i<editingDivs.length; i++) {
		editingDivs[i].onclick = launchEdit;
	}
	
});

function launchEdit(e) {
	if (!e) var e = window.event
	
	var tmp = this.id.split('_');
	var edit_id = tmp[1];
	
	editWin = window.open("/cms/edit?id="+edit_id,"editWin","left=30px,top=40px,height=500px,width=800px");
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
