var ie4 = (document.all && !document.getElementById);

function getDocumentObject(id) {
	if (ie4) {
		return(document.all(id));
	} else {
		return(document.getElementById(id));
	}
}

function getElementsByClassName(obj, className) {
	var elements = obj.childNodes;
	var elmLength = elements.length;
	
	var elmList = [];

	for (var i = 0; i < elmLength; ++i) {
		if (elements[i].className == className) {
			elmList.push(elements[i]);
		}

		var children = getElementsByClassName(elements[i], className);

		for (var j = 0; j < children.length; ++j) {
			elmList.push(children[j]);
		}
	}

	return(elmList);
}

var currentAction = null;

function submitFrm(frm, init) {
	var submitForm = getDocumentObject(frm);

	if (init) {
		init.disabled = true;
	}

	submitForm.target = 'actionFrame';

	for(var i = 0; i < submitForm.elements.length; ++i) {
		submitForm.elements[i].readOnly = true;
	}

	currentAction = {
		SubmitForm: submitForm,
		Initiator: init
	};
	
	submitForm.submit();
}

function response(msg) {
	var init = currentAction.Initiator;

	if (init) {
		init.disabled = false;
	}
		
	var submitForm = currentAction.SubmitForm;

	for(var i = 0; i < submitForm.elements.length; ++i) {
		submitForm.elements[i].readOnly = false;
	}

	if (WhispDialog.Current != null) {
		WhispDialog.Close();
	}

	alert(msg);
}

function C(type, children, attrs) {
	var node = document.createElement(type);

	if (children) {
		if (children instanceof Array) {
			for (var i = 0; i < children.length; ++i) {
				node.appendChild(children[i]);
			}
		} else {
			node.appendChild(children);
		}
	}

	if (attrs) {
		for(var attr in attrs) {
			if (attr == "className") {
			  node.className = attrs[attr];
			} else if (attr == "style") {
			  node.style.cssText = attrs[attr];
			} else {
			  node.setAttribute(attr, attrs[attr]);
			}
		}
	}

	return node;
}

function T(value) {
	var node = document.createTextNode(value);
	return node;
}

