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

function confirmations() {
	if (!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	var all_links = document.getElementsByTagName("a");
	for (var i=0; i < all_links.length; i++) {	
		if (all_links[i].className == "confirmationLink") {
			all_links[i].onclick = function(event) {
				var posx = getPosition('x', event);
				var posy = getPosition('y', event);
				//alert(posx);
				//alert(posy);
				var modalBackground = document.getElementById('modalBackground');
				modalBackground.style.display = 'inline';
				
				confirmID = this.getAttribute("id");	
				blockConfirm = document.getElementById('block'+confirmID);
				blockConfirm.style.display = 'block';
				blockConfirm.style.top = (posy-100)+'px';
				blockConfirm.style.lefy = posx+'px';
				return false;
			} 	
		}
		if (all_links[i].className == "cancel") {
			all_links[i].onclick = function() {	
				confirmID = this.getAttribute("id");	
				blockConfirm = document.getElementById('bloc'+confirmID);
				blockConfirm.style.display = 'none';
				var modalBackground = document.getElementById('modalBackground');
				modalBackground.style.display = 'none';
				return false;
			} 	
		}
		if (all_links[i].className == "delete") {
			all_links[i].onclick = function() {	
				var deleteConfirm = confirm('Are you sure you want to remove?');
				if(deleteConfirm) return true;
				else return false;
			}
		}
	} 
} 

function getPosition(type, e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = this.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	if (type = 'x') pos = posx;
	if (type = 'y') pos = posy;
	return(pos);
}

function dashMessages(){
	if(!document.getElementById) return false;
	if(!document.getElementById('dashMessages'))return false;
	var dashMessages = document.getElementById('dashMessages');
	var modalBackground = document.getElementById('modalBackground');
	modalBackground.style.display = 'inline';
	if(!document.getElementById('dashWindow'))return false;
	var closeWindow = document.getElementById('dashWindow');
	closeWindow.onclick = function() {	
		modalBackground.style.display = 'none';
		dashMessages.style.display = 'none';
		return false;
	}
//	var messages = document.getElementById('dashMessages');
//	messages.style.position = 'absolute';
//	messages.style.top = '100';
//	alert('test');
}

addLoadEvent(dashMessages);
addLoadEvent(confirmations);