/*
FUNCTION TO CENTER NeXTensio FORMS
Best with javascript toolbox position.js available.
*/
function setTngWidth() {
	var thedivs = document.getElementsByTagName('div');
	for (i=0;i<thedivs.length;i++) {
		if (thedivs[i].className.indexOf("KT_tng") != -1) {
			var theWrapper = thedivs[i].parentNode;
			theWrapper.style.width = "auto";
		}
		if ((thedivs[i].className.indexOf("KT_tnglist") != -1) || (thedivs[i].className.indexOf("KT_tngform") != -1)) {
			var tngBox = thedivs[i];
			tngBox.style.width = "auto";
		}
		if (thedivs[i].className.indexOf("KT_bottombuttons") != -1) {
			var btmBtns = thedivs[i];
			btmBtns.style.width = "auto";
		}
		if (thedivs[i].className.indexOf("KT_topbuttons") != -1) {
			var topBtns = thedivs[i];
			topBtns.style.width = "auto";
		}
	}
	var theTables = document.getElementsByTagName('table');
	for (i=0;i<theTables.length;i++) {
		if (theTables[i].className.indexOf("KT_tngtable") != -1) {
			var tngTable = theTables[i];
			tngTable.style.width = "auto";
		}
	}
	if (typeof Position != "undefined") {
		var theWrapperWidth = Position.get(theWrapper).width;
		var tngBoxWidth = Position.get(tngBox).width;
		var tngTableWidth = Position.get(tngTable).width;
	} else {
		var theWrapperWidth = theWrapper.offsetWidth;
		var tngBoxWidth = tngBox.offsetWidth;
		var tngTableWidth = tngTable.offsetWidth;
	}
	//alert(theWrapperWidth+", "+tngBoxWidth+", "+tngTableWidth);
	if (theWrapperWidth && tngBoxWidth && tngTableWidth) {
		var padL = Math.round((theWrapperWidth - tngTableWidth)/2);
		theWrapper.style.paddingLeft = padL + "px";
		btmBtns.style.width = tngBoxWidth + "px";
		if (typeof topBtns != "undefined") {
			// Sometimes we don't use top buttons
			topBtns.style.width = tngBoxWidth + "px";
		}
		tngTable.align="center";
	}
}
/* 
FUNCTIONS TO TOGGLE THE SUBMIT FORMS OF NeXTensio FORMS 
*/
function tngSubmitOff() {
	if (document.getElementById('KT_Insert1')) {
		document.getElementById('KT_Insert1').disabled='disabled';
	} else if (document.getElementById('KT_Edit1')) {
		document.getElementById('KT_Edit1').disabled='disabled';
	}
}
function tngSubmitOn() {
	if (document.getElementById('KT_Insert1')) {
		if (document.getElementById('KT_Insert1').disabled=='disabled') {
			document.getElementById('KT_Insert1').disabled='';
		} else {
			document.getElementById('KT_Insert1').disabled='disabled';
		}
	} else if (document.getElementById('KT_Edit1')) {
		document.getElementById('KT_Edit1').disabled='';
	}
}
function tngSubmitToggle() {
	if (document.getElementById('KT_Insert1')) {
		document.getElementById('KT_Insert1').disabled='';
	} else if (document.getElementById('KT_Edit1')) {
		if (document.getElementById('KT_Edit1').disabled='disabled') {
			document.getElementById('KT_Edit1').disabled='';
		} else {
			document.getElementById('KT_Edit1').disabled='disabled'
		}
	}
}