Variable UI_STD_INIT <<EOV
[perl]
	# call only once per page
	return if $Config->{ImageDirOriginal};

	# determine catalog URL before mangling config URLs
	$Scratch->{ui_catalog_url} = $Tag->area('index');

	# replace ImageDir variables with UI equivalents to take advantage
	# of Interchange's automatic image path rewriting
	$Config->{ImageDirOriginal} = $Config->{ImageDir};
	$Config->{ImageDirSecureOriginal} = $Config->{ImageDirSecure};
	$Config->{ImageDir} =
		$Tag->image( { ui => 1, secure => 0, dir_only => 1 } );
	$Config->{ImageDirSecure} =
		$Tag->image( { ui => 1, secure => 1, dir_only => 1 } );

	# force using secure URL for this page?
	$Config->{VendURLOriginal} = $Config->{VendURL};
	if ($Variable->{UI_SECURE} or $Tag->var('UI_SECURE', 1)) {
		$Config->{VendURL} = $Config->{SecureURL};
	}

	# allow CGI setting to override locale for this page
	my $c = delete $CGI->{mv_charset};
	if ($c) {
		$Scratch->{mv_charset_save} = $Scratch->{mv_charset}
			if $Scratch->{mv_charset};
		$Scratch->{mv_charset} = $c;
	}
	else {
		# default charset encoding should normally match current locale
		$Scratch->{mv_charset} = $Config->{Locale}{MV_CHARSET} || 'iso-8859-1'
			unless $Scratch->{mv_charset_keep};
	}

	''
[/perl]
EOV

Variable UI_STD_HEAD <<EOV
[tag pragma strip_white][/tag]
[tag pragma no_image_rewrite 0][/tag]
@_UI_STD_INIT_@
[if-mm !logged_in]
	[set ui_checklist][/set]
	[if !scratch no_login_required]
		[bounce href=|
			[area href="__UI_BASE__/login" form="destination=[var MV_PAGE 1]"]
		|]
	[/if]
[/if-mm]
[calc]
	delete $Scratch->{no_login_required};
	@parms = grep /^ui_class_/, keys %$Scratch;
	my $last;
	for(@parms) {
		delete $Scratch->{$_};
		$last = $_;
		$last =~ s/ui_class_//;
	} 
	$ui_tag = (delete $Scratch->{ui_class} || $last || 'None');
	my $sparams = <<EOF;
		fi=@_UI_MENU_TABLE_@
		st=db
		rf=*
		co=yes
		tf=msort

		sf=mgroup
		se=$ui_tag
		op=rm
EOF
	$Scratch->{"ui_class_$ui_tag"} = 1;
	$Scratch->{ui_menu_sparams} = $sparams;
	return $out;
[/calc]
[if scratch table_perm]
	[calc]
		my $table = $CGI->{mv_data_table} || $Values->{mv_data_table};
		if($Scratch->{table_perm} =~ /^\s*=(\w+)/) {
			$Scratch->{table_perm} = "$CGI->{mv_data_table}=$1";
		}
		elsif ( $Scratch->{table_perm} =~ /\w+=/) {
			# do nothing
		}
		else {
			$Scratch->{table_perm} = $CGI->{mv_data_table};
		}
		return;
	[/calc]
	[if-mm function="!tables" table="[scratch table_perm]"]
	[seti ui_error][msg arg.0="[scratch table_perm]" arg.1="[cgi mv_data_table]" arg.2="[var MV_PAGE 1]"]Sorry, no permission '%s' for table '%s' in '%s'.[/msg][/seti]
	[set table_perm][/set]
	[bounce page="__UI_BASE__/error"]
	[/if-mm]
[/if]
[if scratch page_perm]
	[if-mm function="!advanced" name="[scratch page_perm]"]
	[seti ui_error][msg arg.0="[scratch page_perm]"]Sorry, no permission for page '%s'.[/msg][/seti]
	[set page_perm][/set]
	[bounce page="__UI_BASE__/error"]
	[/if-mm]
[/if]
<html[scratch ui_language_direction]>
<head>
[if scratch mv_charset]
	<meta http-equiv="content-type" content="text/html; charset=[scratch mv_charset]">
[/if]
<title>[scratch page_title]</title>
<script language="JavaScript">
<!--

function open_help(url) {
	opts="top=0,left=0,scrollbars,status=no,menubar=no,location=yes,toolbar=no,resizable=yes,fullsize=no,width=__UI_HELP_WIDTH__,height=__UI_HELP_HEIGHT__";
	window.open(url, 'Help', opts);
}

function MM_swapImgRestore() {
	var i,x,a=document.MM_sr;
	for (i=0; a&&i < a.length && (x=a[i]) && x.oSrc; i++) x.src=x.oSrc;
}

function checkAll(form,what,uncheck) {
	var i, n, check;
	n = form.elements[what].length;
	if (!n) {
		if (uncheck == 1) {
			form.elements[what].checked=false;
		} else {
			form.elements[what].checked=true;
		}
	} else {
		if (what != "deleteid" || sure()) {
			var checkval;
			if (uncheck == 1) { checkval=false; } else { checkval=true; }
			for (i=0; i < n; i++) {
				check = form.elements[what][i];
				check.checked = checkval;
			}
		}
	}
}

function addItem(selector, receptor, joiner) {
	if (joiner == null) { joiner = " "; } else { joiner = "\n"; }
	if (receptor.value != '') receptor.value = receptor.value + joiner;
	if (selector[selector.selectedIndex].value != null) {
		receptor.value = receptor.value + selector[selector.selectedIndex].value;
	} else {
		if (selector[selector.selectedIndex].text != null) {
			receptor.value = receptor.value + selector[selector.selectedIndex].text;
		}
	}
	return true;
}

function MM_preloadImages() {
	var d=document;
	if (d.images) {
		if (!d.MM_p) d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for (i=0; i<a.length; i++)
			if (a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = "[image dir_only=1]" + a[i];
			}
	}
}

function MM_findObj(n, d) {
	var p,i,x;
	if (!d) d=document;
	if ((p=n.indexOf("?")) > 0 && parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if (!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	return x;
}

function MM_swapImage() {
	var i, j=0, x, a=MM_swapImage.arguments;
	document.MM_sr = new Array;
	for (i=0; i < (a.length-2); i+=3)
		if ((x=MM_findObj(a[i])) != null) {
			document.MM_sr[j++]=x;
			if (!x.oSrc) x.oSrc=x.src;
			x.src = "[image dir_only=1]" + a[i+2];
		}
}
//-->
</SCRIPT>
<STYLE TYPE="text/css">
<!--
@_UI_STYLE_@
-->
</STYLE>
[scratch meta_header][set meta_header][/set]
</head>

<body [scratch ui_body_extra] bgcolor="__UI_C_BG__" onLoad="MM_preloadImages('B3_b.gif','B4_b.gif','B5_b.gif','B6_b.gif','B7_b.gif','B2_b.gif','B8_b.gif','B9_b.gif','A1_b.gif','A3_b.gif')" leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<!-- ----- BEGIN TITLEBAR ----- -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="__UI_TOP_BG__">
  <tr>
    <td bgcolor="__UI_TOP_BG__"><A HREF="http://www.redhat.com/"><img src="redhat_logo.gif" width="189" height="53" border=0 alt="Interchange logo"></A></td><td align="right" valign="bottom" nowrap><a href="[if session logged_in]@_UI_ABOUT_NORMAL_URL_@[else]@_UI_ABOUT_LOGIN_URL_@[/else][/if]" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('About','','A1_b.gif',1)"><img name="About" border="0" src="A1.gif" width="102" height="38" alt=About></a><a href="[area __UI_BASE__/index]"><img name="Index" border="0" src="A2.gif" width="294" height="38" alt=Menu></a><a href="javascript:open_help('[area href="[either][var UI_HELP_URL 2][or][var UI_BASE]/help[/either]" form="topic=[scratch help_name]"]')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Help','','A3_b.gif',1)"><img name="Help" border="0" src="A3.gif" width="125" height="38" alt=Help></a></td>
  </tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr bgcolor="#000000"> 
    <td><img src="spacer1.gif" width="1" height="1" alt=line></td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td><img src="spacer2.gif" width="1" height="1" alt=line></td>
  </tr>
  <tr bgcolor="__UI_C_INTBLOCKBAR__"> 
    <td nowrap> 
      <div align="left"><img src="B1.gif" width="9" height="19" alt=line>[loop
	  prefix=am
	  search="
	  	fi=@_UI_MENU_TABLE_@
		st=db
		co=yes

		sf=mgroup
		se=Top
		op=eq

		tf=msort
		rf=*
	  "
	  lr=1]
	  [if-am-param !inactive]
	  [if-mm advanced [am-param depends_on]]
	  [if-am-param img_dn]
	  	<!-- class=[am-param name]=[scratch ui_class_[am-param name]] -->
	  <a href="[area href='[am-param page]' form='[am-param form]']" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('[am-param name]','','[am-param img_up]',1)"><img name="[am-param name]" alt="[am-param alt]" border="0" src="[if scratch ui_class_[am-param name]][am-param img_up][else][am-param img_dn][/else][/if]"></a>
	  [/if-am-param]
	  [if-am-param !img_dn]
		  <a href="[area href='[am-param page]' form='[am-param form]']" class=ctitle>[msg][am-param name][/msg]</a>
	  [/if-am-param]
	  [/if-mm]
	  [/if-am-param]
	  [/loop]
	  <img src="B10.gif" width="17" height="19" alt=line></div>
    </td>
  </tr>
</table>

[loop
	prefix=sm
	search="[scratch ui_menu_sparams]"
	safe_data=1
][sm-calc]
	my $pre  = '';
	my $post = '';
	my $out  = '';
	$out .= <<'EOF' if ! $sm_once++;
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td bgcolor="__UI_C_TOPBLOCKBAR__"><img src="spacer3.gif" width=1 height=1 alt=line></td>
  </tr>
  <tr bgcolor="000000"> 
    <td><img src="spacer4.gif" width=1 height=1 alt=line></td>
  </tr>
  <tr bgcolor="__UI_C_TITLEBARBG__"> 
    <td valign=center nowrap><font face="Verdana, Arial, Helvetica, sans-serif" size="-1"><img src="bg.gif" height=19 width=3 align=middle alt=x>&nbsp;&nbsp;&nbsp;&nbsp;
EOF
	return if q{[sm-param inactive]};
	return if q{[sm-param super]} and $Tag->if_mm('!super');
	my $indicator = q{[sm-param indicator]};
	my $exclude = q{[sm-param exclude_on]};
#Log("indicator=$indicator");
	my $depend = q{[sm-param depends_on]};
	return '' if $exclude and $CGI->{$exclude};
	return '' if $depend and ! $CGI->{$depend};
	my $name = errmsg(q{[sm-param name]});
	my $page = q{[sm-param page]};
	my $form = q{[sm-param form]};
	for(\$name, \$page, \$form) {
		$$_ =~ s/\[cgi\s+([^\[]+)\]/$CGI->{$1}/g;
		$$_ =~ s/\[var\s+([^\[]+)\]/$Variable->{$1}/g;
		$$_ =~ s/\[value\s+([^\[]+)\]/$Values->{$1}/g;
	}
#Log("Form is: $form");
	$form =~ tr/&/\n/;
	my $next = q{[sm-param next_line]};
	if($name =~ s/^((&nbsp;)+)//i) {
		$pre = $1;
	}
	if($name =~ s/((&nbsp;)+)$//i) {
		$post = $1;
	}
	$name =~ s/ /&nbsp;/g;
#Log("Form is: $form");
	$out .= $pre;
	$out .= q{</td></tr><tr bgcolor="__UI_C_INTBLOCKBAR__"><td nowrap valign=center><img src="bg.gif" height=19 width=3 align=middle alt=x>&nbsp;&nbsp;&nbsp;&nbsp;
}
		if $next;
	$out .= qq{<A HREF="} if $page;
	$out .= $Tag->area( { href => $page, form => $form } )
		if $page;
	$out .= qq{">} if $page;
	my $fc = q{__UI_C_TITLEBARCONT__};
	my $rev = $indicator =~ s/^!//;

#Log("indicator=$indicator rev=$rev CGI=$CGI->{$indicator} VALUES=$Values->{$indicator}");

	if($indicator) {
		if($rev) {
			$fc = q{__UI_C_TITLEBARTXT__}
				if !  (defined $CGI->{$indicator} ? $CGI->{$indicator} : $Values->{$indicator});
		}
		else {
			$fc = q{__UI_C_TITLEBARTXT__}
				if (defined $CGI->{$indicator} ? $CGI->{$indicator} : $Values->{$indicator});
		}
	}
	elsif($Tag->var('MV_PAGE', 1) eq $page) {
#Log("page presence select");
		$fc = q{__UI_C_TITLEBARTXT__};
	}

	$out .= qq{<FONT COLOR="$fc" SIZE="-1">$name</FONT>};
	$out .= '</A>' if $page;
	$out .= $post;
	$out .= '&nbsp;&nbsp;&nbsp;';
[/sm-calc] [/loop]
	[calc]
	return unless $sm_once;
	$out = qq!</td></TR>!;
	$out .= q!<tr bgcolor="#000000"><td>!;
	$out .= q!<IMG SRC="bg.gif" WIDTH="1" HEIGHT="1" alt=x>!;
	$out .= q!</td></tr></table>!;
	[/calc]
<!-- ----- END MENUBAR ----- -->
[if scratch ui_checklist]
	[include file=include/wizard_checklist locale="[scratch mv_locale]"]
[/if]

[if !scratch ui_no_title]
<table width="100%">
<TR>
<TD WIDTH="20">&nbsp;</td><TD>
          <br>
		[if scratch icon_name]<img src="[scratch icon_name]" width=16 height=16 border=0 valign=top alt=icon> &nbsp; [/if]
	   <font size="+1" face="Verdana,arial,helvetica,sans-serif" color="__UI_C_HEADERTXT__">[either][scratch page_banner][or][scratch page_title][/either]&nbsp;</font><p>
    [if type=explicit compare="[error all=1 show_var=1 keep=1]"]
	<P>
	<B>Error:</B>
	<BLOCKQUOTE class=cerror>
		[error all=1 show_error=1 joiner="<br>"]
	</BLOCKQUOTE>
	</P>
	[/if]
	[if scratch ui_failure]
	<P>
	<BLOCKQUOTE>
	<FONT COLOR="__CONTRAST__">[scratchd ui_failure]</FONT>
	</BLOCKQUOTE>
	</P>
	[/if]
	[if scratch ui_message]
	<P>
	<BLOCKQUOTE>
	<FONT COLOR="__UI_C_SUCCESS__">[scratchd ui_message]</FONT>
	</BLOCKQUOTE>
	</P>
	[/if]
[/if]
[comment] Clear these puppies [/comment]
[calc]
	for (qw/
				page_title
				page_banner
				icon_name
				help_name
				page_perm
				table_perm
				ui_body_extra
		/) { delete $Scratch->{$_} }
	return;
[/calc]
EOV
