// JavaScript Document

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}



//PHOTO BOX 
function createPhotoBox() {
  if (!document.getElementById) return false;
  if (!document.getElementById("ed-art-content")) return false;
  
	// Finding the image and its width and removing the alignment
  	var bodyContent = document.getElementById("ed-art-content");
  	var insertedImage = bodyContent.getElementsByTagName("img");
	for(i=0; i<insertedImage.length; i++) 
	{
		var theImage = insertedImage[i];
  		if (theImage.className == "captionedimage") 
		{
				theImage.getAttributeNode("vspace").nodeValue = "0";
				theImage.getAttributeNode("hspace").nodeValue = "0";
				
				//Building the DIV around the IMG 
				var imageBox = document.createElement("div");
				theImage.parentNode.insertBefore(imageBox,theImage);
				imageBox.className = "insertimg";
				
				//Setting the alignment (if valid) 
				if (theImage.getAttributeNode("align")) {
					var imageAlign = theImage.getAttributeNode("align").nodeValue;
					theImage.getAttributeNode("align").nodeValue = "center";
					imageBox.style.cssFloat = imageAlign;
					imageBox.style.styleFloat = imageAlign;
					}
					
				//Setting the width (if valid)
				var newWidth = theImage.getAttribute("width");
				var newWidth = theImage.width;
				imageBox.style.width = newWidth + "px";
				
				
				imageBox.appendChild(theImage);
				
				//Adding the text (if valid)
				if (theImage.getAttribute("alt")) {
					var imageAlt = theImage.getAttribute("alt");
					var imageAlt = theImage.alt;
					var imageCaption = document.createElement("p");
					var captionText = document.createTextNode(imageAlt);
					imageCaption.appendChild(captionText);
					imageBox.appendChild(imageCaption);
					}
			}
		else {}
	}
		
}

		

//DISPLAY THANKS BOX
function displayThxBox() {
  if (!document.getElementById) return false;
  if (!document.getElementById("ContactForm")) return false;
  if (!document.getElementById("showTheThx")) return false;
	
	//description text
  var thxBox = document.createElement("h4");
  thxBox.id = "calltoaction";
  var thxText = document.createTextNode("Thank you for fighting the good fight! Let the money fall like rain from the evil hands of the oppressors.");
  thxBox.appendChild(thxText);
	
	// Finding the image and its width and removing the alignment
  var contactForm = document.getElementById("ContactForm");
  var parent = contactForm.parentNode;
  parent.insertBefore(thxBox,ContactForm);
	
	contactForm.style.display = "none"; 
	}
		

addLoadEvent(createPhotoBox);
addLoadEvent(displayThxBox);