
var is_decoding;
var DEBUG = 0;

function complaining (s) {
	return new Error(s,s);
}



if(!(document.getElementById && document.getElementsByName)) {}

function check_decoding (idDiv) {
	var d = document.getElementById(idDiv);
	if(!d) {
		return;
	}
	else if(!('textContent' in d)) {

	} else {
		var ampy = d.textContent;
		if(ampy == undefined) throw complaining("'cometestme' element has undefined text content?!");
		if(ampy == '') throw complaining("'cometestme' element has empty text content?!");
		if (ampy == "\x26")
			is_decoding =  true;
		else if (ampy == "\x26amp;" ) {
			is_decoding = false;
		}
		else { throw complaining('Insane value: "' + ampy + '"!'); }
	}
	
	var msg =
	(is_decoding == undefined) ? "I can't tell whether the XSL processor supports disable-content-encoding!D"
	: is_decoding ? "The XSL processor DOES support disable-content-encoding"
	: "The XSL processor does NOT support disable-content-encoding"
	;
	
	return msg;
}


function go_decoding (idDivTest,NameDiv) {	
	check_decoding(idDivTest);
	if(is_decoding) {
		DEBUG && alert("No work needs doing -- already decoded!");
	}
	
	
	if (YAHOO.env.ua.opera)
		var to_decode = YAHOO.util.Dom.getElementsByClassName(NameDiv, 'div');
	else
		var to_decode = document.getElementsByName(NameDiv);
	
		
	//var to_decode = [document.getElementById(NameDiv)];
	
	if(!( to_decode && to_decode.length )) {
		DEBUG && alert("No work needs doing -- no elements to decode!");
		return;
	}
	if(!(  ( "innerHTML"   in to_decode[0]) &&  ( "textContent" in to_decode[0])  )) {
		return;
	}
	
	var s;
	for(var i = to_decode.length - 1; i >= 0; i--) { 
		s = to_decode[i].textContent;
		if(s == undefined || (s.indexOf('&') == -1 && s.indexOf('<') == -1)) {
		  // the null or markupless element needs no reworking
		}
		else {
		  to_decode[i].innerHTML = s;  // that's the magic
		}
	}
	return;
}


