function on(id){
	id = document.getElementById(id);
	id.src = (""+id.src).split(".gif")[0] + "1.gif";
}
function off(id){
	id = document.getElementById(id);
	id.src = (""+id.src).split("1.gif")[0] + ".gif";
}

function pageload(){
	//Dynamic image replacement function call a.k. DIIP. put 'diip-' infront of file name to work
	if( document.images && (""+document.location).indexOf("as_contrib_edit")==-1) {
		for( var i=0; i<document.images.length; i++) {
			var temp = (document.images[i].src).split("/");
			temp = (temp[temp.length-1]).substr(0, 5);
			if( temp == "diip-") {
				replaceImageModel(document.images[i]);
			}
		}
	}	
}

//******************** For Image Replacement
function makeNewImage(i){
	
	//get HTML and store it in code
	var temp = document.createElement("DIV");
	temp.appendChild(i);
	var code = temp.innerHTML
	delete temp;
	
	//add block-style declration
	code = code.split(">");
	code = code[0] + " style=\"display: block; margin: 0px; padding: 0px\">";
	return code;
}

function replaceImageModel(old) {
	
	//set image attributes
	old.hspace = "0";
	old.vspace = "0";
	
	//get variables
	var imageTxt = old.getAttribute("alt");
	var imageWidth = old.width;
	var imageAlign = old.getAttribute("align");
	var imageParent = old.parentNode;
	
	if( imageAlign == "" || imageAlign == null ) imageAlign = "";
	else imageAlign = "style='float: " + imageAlign + ";'";
	
	//make new image clone (returns code from DOM)
	var imageCode = makeNewImage(old.cloneNode(true));
	
	//generate table code
	var code = "<table width='"+(imageWidth+2)+"' class='imageTable' cellspacing='0' cellpadding='0' border='0' "+imageAlign+ ">";
	code += "<tfoot><tr><td>"+imageTxt+"</td></tr></tfoot>";
	code += "<tbody><tr><td>"+imageCode+"</td></tr></tbody>";
	code += "</table>";
	
	//wrap code in a div element to replace old image
	var div = document.createElement("DIV");
	div.innerHTML = code;
	
	//replace old image with new image (image inside a table wrapper)
	imageParent.replaceChild(div, old);
}
//End Image Replacement