/* --- JavaScript --- */
/* --- SpamMeNot --- */

// created:	2006-12-16	Sander Aarts	


autoSpamMeNot = function() {
	var spamMeNot = document.getElementById('spamMeNot');
	if (spamMeNot == null) return false;
	
	var sumLabel = document.getElementById('sumLabel');
	var sum = document.getElementById('sum');
	if (sumLabel == null || sum == null) return false;
	
	spamMeNot.removeChild(sumLabel);	// remove <label for="sum"> from DOM
	if (spamMeNot.innerHTML) {	// type attribute can't be set/changed in all browsers (IE), use innerHTML to alter code
		spamMeNot.removeChild(sum);	// remove <input id="sum"> from DOM
		spamMeNot.innerHTML += '<input id="sum" name="sum" type="hidden" value="" />';	// add new <input id="sum"> with type="hidden"
		var sum = document.getElementById('sum');	// make new reference
	}
	else {
		sum.type = "hidden";	// try to change type attribute after all if innerHTML is not supported
	}
	
	var parts = spamMeNot.getElementsByTagName('input');
	var total = 0;
	for (i=0; i<parts.length; i++) {
		var input = parts[i];
		if (input.type == "hidden" && input.id != "sum") {
			total += parseInt(input.value);	// sum of hidden fields
		}
	}
	sum.value = total;
}



/* --- add functions to onload event: addLoadEvent(functionName); --- */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(autoSpamMeNot);
