var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))

var myDialog;
var callbackFunc;
function myOpenDialog(frameURL, width, height, callbackFuncLocal) {

	var dialog = myDialog;

	if (dialog && typeof (dialog) != "undefined" && !dialog.closed) {
		dialog.focus();
	} else {

		var openleft = 10;
		var opentop = 10;
		var attr = "resizable=yes,scrollbars=yes,modal=yes,width=" + width
				+ ",height=" + height;
		if (Nav4) {
			// center on the main window
			openleft = parseInt(window.screenX
					+ ((window.outerWidth - width) - 50), 10);
			opentop = parseInt(window.screenY
					+ ((window.outerHeight - height) - 50), 10);
			attr += ",screenX=" + openleft + ",screenY=" + opentop;
		} else {
			// best we can do is center in screen
			openleft = parseInt(
					((screen.width - width) - ((screen.width - width) / 2)), 10);
			opentop = parseInt(
					((screen.height - height) - ((screen.height - height) / 2)),
					10);

			attr += ",left=" + openleft + ",top=" + opentop;
		}

		dialog = window.open(frameURL, 'myPopupWindow', attr);
		if (dialog == null) {
			alert('Всплывающие окна заблокированы вашим браузером!');
		}

		myDialog = dialog;
		callbackFunc = callbackFuncLocal;

		if (dialog.opener == null) {
			dialog.opener = self;
		}

	}
}

var actionQueryBackUp;

var tabQParam = '&startTab=';
/**
 * Переключение между вкладками на форме
 * 
 * @param selNumber -
 *            номер вкладки (с единицы)
 * @param docName -
 *            имя документа для формы
 */
function switchTab(selNumber, docName) {

	var node;

	// пробежимся по вкладкам
	var i = 1;
	var tabName = docName + '_tab';
	while ((node = document.getElementById(tabName + i))) {
		if (i == selNumber) {
			node.style['display'] = '';
		} else {
			node.style['display'] = 'none';
		}
		i++;
	}

	// пробежимся по переключателям вкладок
	i = 1;
	tabName = docName + '_head';
	while ((node = document.getElementById(tabName + i))) {
		if (i == selNumber) {
			node.className = 'HeadCellSel';
		} else {
			node.className = 'HeadCell';
		}
		i++;
	}
	var actionQ = document.forms[docName].action;
	if(!actionQueryBackUp){
		actionQueryBackUp = actionQ;
	}
	document.forms[docName].action = actionQueryBackUp + tabQParam + selNumber;
}

function prepareTabs(docName,number) {
	var actionQ = document.forms[docName].action;
	if (!actionQueryBackUp) {
		actionQueryBackUp = actionQ;
	}
	document.forms[docName].action += tabQParam + number;
}
