var submited = false;

var AMsubmit = 'submit';
var AMxml = 'xml';
var AMstream = 'stream';

//function fnAction (name, validation, pparam, method, target, atile) {
function fnAction (name, validation, atile, pparam, target, method) {
	if (submited) return false;
	prefix = name.substring (0, name.lastIndexOf ('__') + 2);

	if (validation && !eval (validation)) return false;

	var tile = fnGetTileFor (name);
	atile = atile !== undefined ? atile : tile;
	
	document.forms['form'].caction.value = name;
	document.forms['form'].param.value = pparam;
	document.forms['form'].abase.value = atile;

	if (0 && method != AMstream && method != AMsubmit) {
		try {
			fnLoadTile (tile, atile, target);
			return false;
		} catch (error) { /*alert (error); alert (atile);*/ }
	}
	document.forms['form'].abase.value = '';
	//document.forms['form'].action = target;
	if (method != AMstream) submited = true;
	document.forms['form'].submit();
	return false;
}

function fnSAction (name, validation, param) {
	return fnAction (name, validation, undefined, param, undefined, AMsubmit);
}

function fnGetTileFor (name) {
	var index = name.lastIndexOf ('__');
	if (index == -1) return '';
	name = name.substr (0, index);
	index = name.lastIndexOf ('__');
	if (index == -1) return '';
	return name.substr (0, index);
}

function fnShowHint (parent, text, closeText) {
	var hint = document.getElementById ('hint');
	document.getElementById ('ihidden').appendChild (hint);

	hint.innerHTML = '<button onclick="document.getElementById (\'ihidden\').appendChild (this.parentNode); this.parentNode.style.display = \'none\';">' + closeText + '</button><br/>' + text;
	parent.appendChild (hint);
	hint.style.display = 'block';
	return false;
}

function fnSetVisibleAll (state, tag, prop, value) {
	var els = document.getElementsByTagName (tag);
	var dbg = 0;
	//alert (els.length);
	for (var el in els) {
		//if (els[el].title.length && !!dbg < 5) alert (els[el].title + "=" + els[el][prop]);
		if (els[el][prop] == value) els[el].style.display = state ? '' : 'none';
	}
}