// Version: "4.0.0"
// Copyright (c) Kore Technologies LLC .  All rights reserved.
var collectPostBacks = false;

function ksPostBacksCollecting() {
	return collectPostBacks;
}

function ksCollectPostBacks(mode) {
	collectPostBacks = mode;
}

function ksSetFocus(column) {
	try {
		var el = document.getElementById(column);
		if (el!=null) {
			el.focus();
			el.select();
		}
	} catch (e) {
	}
}

function ksViewFilter(viewName, filterName) {
	try {
		var frm = ksGetDataForm();
		var tbCtl = frm.toolbar_action;
		if (tbCtl==null) {  // callback should have registered
			alert("Form postback cannot find the action control registered on the parent window.");
		} else {
			// stuff search value into control
			//alert("Setting tbact value");
			tbCtl.value = "ksfrmdatafilter."+viewName+"."+filterName;
		}
		//alert("Submit");
		frm.submit();
	} catch(e) {
		alert("Client Filter Failed: " + e.message);
	}
	
}

function ksPageClick(page, view, item, val)
{
	ksSetClientViewSetting(page, view, item, val);
	ksGetDataForm().submit();
}
function ksExpandClick(page, view, expand_obj)
{
	var val = !ksGetClientViewSetting(page, view, 'expand');
	ksSetClientViewSetting(page, view, 'expand', val);
	expand_obj.style.display = (val ? '' : 'none');
	ksUpdateIcon(page, view, 'expand', val);
	var alt = (val ? "collapse" : "expand") + " this view";
	ksGetDataForm()[view + '.tbi_expand'].alt = alt;
}
function ksUpdateIcon(page, view, tb_name, val)
{
	ksGetDataForm()[view + '.tbi_' + tb_name].src = "images/skins/cur/tbi_" + tb_name + "_" + String(val) + ".gif";
}
function ksGetClientViewSetting(page, view, name)
{
	var val = ksGetDataForm()[view + '.' + name].value;
	if(val == 'true')
	{
		val = true;
	}
	else if(val = 'false')
	{
		val = false
	}
	return(val);
}
function ksSetClientViewSetting(page, view, name, val)
{
	ksGetDataForm()[view + '.' + name].value = val.toString();
}

function changeActiveTab(i) {
	changeActiveTab(i, false);
}

function changeActiveTab(i, refresh) {
	document.getElementById(".selectTab").value = i;
	for( j=0; j < tabCount; ++j ) {
		if( i==j ) { activateTab(j); }
		else { deactivateTab(j); }
	}
	if (refresh && editor==null)
		editorHtmlInit();
}

function activateTab(i) {
	document.getElementById( "tab-left:"+i ).src="images/tabs/tab-left_active.gif";
	document.getElementById( "tab-bg:"+i ).style.background="url(images/tabs/tab-bg_active.gif)";
	document.getElementById( "tab-right:"+i ).src="images/tabs/tab-right_active.gif";
	document.getElementById( "tab-body:"+i ).style.display='block';
}

function deactivateTab(i) {
	// check for tabs that may not be visible due to application installation
	var tabLeft = document.getElementById( "tab-left:"+i );
	var tabBg = document.getElementById( "tab-bg:"+i );
	var tabRight = document.getElementById( "tab-right:"+i );
	var tabBody = document.getElementById( "tab-body:"+i );
	
	if (tabLeft) 
		tabLeft.src="images/tabs/tab-left_inactive.gif";
	if (tabBg) 
		tabBg.style.background="url(images/tabs/tab-bg_inactive.gif)";
	if (tabRight) 
		tabRight.src="images/tabs/tab-right_inactive.gif";
	if (tabBody) 
		tabBody.style.display='none';
}

