+ echo "</div>";
+}
+
+//-----------------------------------------------------------------------------
+// Tabbed area:
+// $name - prefix for widget internal elements:
+// Nth tab submit name: {$name}_N
+// div id: _{$name}_div
+// sel (hidden) name: _{$name}_sel
+// $tabs - array of tabs; string: tab title or array(tab_title, enabled_status)
+
+function tabbed_content_start($name, $tabs, $dft='') {
+ global $Ajax;
+
+ $selname = '_'.$name.'_sel';
+ $div = '_'.$name.'_div';
+
+ $sel = find_submit($name.'_', false);
+ if($sel==null)
+ $sel = get_post($selname, (string)($dft==='' ? key($tabs) : $dft));
+
+ if ($sel!==@$_POST[$selname])
+ $Ajax->activate($name);
+
+ $_POST[$selname] = $sel;
+
+ div_start($name);
+ $str = "<ul class='ajaxtabs' rel='$div'>\n";
+ foreach($tabs as $tab_no => $tab) {
+
+ $acc = access_string(is_array($tab) ? $tab[0] : $tab);
+ $disabled = (is_array($tab) && !$tab[1]) ? 'disabled ' : '';
+ $str .= ( "<li>"
+ ."<button type='submit' name='{$name}_".$tab_no
+ ."' class='".((string)$tab_no===$sel ? 'current':'ajaxbutton')."' $acc[1] $disabled>"
+ ."<span>$acc[0]</span>"
+ ."</button>\n"
+ ."</li>\n" );
+ }
+
+ $str .= "</ul>\n";
+ $str .= "<div class='spaceBox'></div>\n";
+ $str .= "<input type='hidden' name='$selname' value='$sel'>\n";
+ $str .= "<div class='contentBox' id='$div'>\n";
+ echo $str;
+}
+
+function tabbed_content_end() {
+ output_hidden();
+ echo "</div>"; // content box (don't change to div_end() unless div_start() is used above)
+ div_end(); // tabs widget
+}
+
+function tab_changed($name)
+{
+ $to = find_submit("{$name}_", false);
+ if (!$to) return null;
+
+ return array('from' => $from = get_post("_{$name}_sel"),
+ 'to' => $to);
+}
+/*
+ Check whether tab has been just switched on
+*/
+function tab_opened($name, $tab)
+{
+ return (get_post('_'.$name.'_sel') != $tab) && (find_submit($name.'_', false) == $tab);
+}
+/*
+ Check whether tab has been just switched off
+*/
+function tab_closed($name, $tab)
+{
+ return (get_post('_'.$name.'_sel') == $tab) && (find_submit($name.'_', false) != $tab);
+}
+/*
+ Check whether tab is visible on current page
+*/
+function tab_visible($name, $tab)
+{
+ $new = find_submit($name.'_', false);
+ return (get_post('_'.$name.'_sel') == $tab && !$new) || $new==$tab;
+}
+
+/* Table editor interfaces. Key is editor type
+ 0 => url of editor page
+ 1 => hotkey code
+ 2 => context help
+*/
+$popup_editors = array(
+ 'customer' => array('/sales/manage/customers.php?debtor_no=',
+ 113, _("Customers"), 900, 600),
+ 'branch' => array('/sales/manage/customer_branches.php?SelectedBranch=',
+ 114, _("Branches"), 900, 700),
+ 'supplier' => array('/purchasing/manage/suppliers.php?supplier_id=',
+ 113, _("Suppliers"), 900, 700),
+ 'item' => array('/inventory/manage/items.php?stock_id=',
+ 115, _("Items"), 800, 600),
+ 'fa_item' => array('/inventory/manage/items.php?FixedAsset=1&stock_id=',
+ 115, _("Items"), 800, 600)
+);
+/*
+ Bind editors for various selectors.
+ $type - type of editor
+ $input - name of related input field
+ $caller - optional function key code (available values F1-F12: 112-123,
+ true: default)
+*/
+function set_editor($type, $input, $caller=true)
+{
+ global $path_to_root, $Editors, $popup_editors, $Pagehelp;
+
+ $key = $caller===true ? $popup_editors[$type][1] : $caller;
+
+ $Editors[$key] = array( $path_to_root . $popup_editors[$type][0], $input,
+ $popup_editors[$type][3], $popup_editors[$type][4]);
+
+ $help = 'F' . ($key - 111) . ' - ';
+ $help .= $popup_editors[$type][2];
+ $Pagehelp[] = $help;