//maked all added functions work onload. at the end of each function you want to work onload add addLoadEvent(function); to the end of the function.
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//**************************************************Replace align attribute with class**************************************************//
function replaceAlign() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementsByTagName('img')) return false;
  var imgList = document.getElementsByTagName('img');
  for (var i=0; i<imgList.length; i++) {
    var align = imgList[i].getAttribute('align');
		if (align) {
			if (align == 'left') {
				imgList[i].className = 'left';
			}
			if (align == 'right') {
				imgList[i].className = 'right';
			}
			if (align == 'middle') {
				imgList[i].className = 'middle';
			}
    	imgList[i].removeAttribute('align')
    }
  }
}


//**************************************************Replace target attribute with class**************************************************//
function replaceTarget() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementsByTagName('a')) return false;
  var aList = document.getElementsByTagName('a');
  for (var i=0; i<aList.length; i++) {
    var target = aList[i].getAttribute('target');
		if (target) {
			aList[i].className = 'newwindow';			
    	aList[i].removeAttribute('target')
    }
  }
}

//**************************************************The following function make it possible to have web standard popups**************************************************//
function strictNewWindow() {
  if (!document.getElementsByTagName) return false;
  var aList = document.getElementsByTagName('a');
  for (var i=0; i<aList.length; i++) {
    if (aList[i].className == 'newwindow') {
      aList[i].onclick = function() {
        window.open(this.getAttribute('href'),'newwindow');
        return false;
      }
    }
  }
}

//**************************************************Load all functions**************************************************//
addLoadEvent(replaceAlign);
addLoadEvent(replaceTarget);
addLoadEvent(strictNewWindow);