<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="PAGED-LIST">
<script language="javascript">
function pagedListDoSort(tab, orderBy, orderType) {
	var formName = '<xsl:value-of select="@FORM-NAME"/>';
	var form = document.forms[formName];
	form.action = '<xsl:value-of select="@URL"/>';
	form.tab.value = tab;
	form.pageNum.value = 1;
	form.orderBy.value = orderBy;
	form.orderType.value = orderType;
	form.submit();
}
</script>
	<fieldset class="sb-toolbar-fieldset">
		<legend class="sb-label-toolbar-title"><xsl:value-of select="TOOLBAR/@TITLE"/></legend>
		<xsl:apply-templates select="TOOLBAR"/>
		<xsl:choose>
			<xsl:when test="count(LIST/ITEM) &gt; 0">
				<xsl:apply-templates select="PAGER"/>
				<xsl:apply-templates select="LIST"/>
				<xsl:apply-templates select="PAGER"/>
			</xsl:when>
			<xsl:otherwise>
			<!--	<xsl:value-of select="/SITEBUILDER-PAGE/LOCALE/MSG-NO-RECORDS"/> -->
				<table width="100%" class="sb-gridview-emptydatarow" >
					<tr><td><xsl:value-of select="/SITEBUILDER-PAGE/LOCALE/MSG-NO-RECORDS"/></td></tr>
				</table>
			</xsl:otherwise>
		</xsl:choose>
	</fieldset>
</xsl:template>

<xsl:template match="PAGED-LIST/LIST">
<table cellspacing="1" border="0" style="width:100%;">
	<xsl:apply-templates select="HEADER" />
	<xsl:apply-templates select="ITEM" />
</table>
</xsl:template>

<xsl:template name="LIST-HEADER-ITEM">
<xsl:param name="align"/>
<xsl:param name="field"/>
<xsl:param name="title"/>
<xsl:param name="width"/>
<xsl:param name="currentSortField" value=''/>
<xsl:param name="currentSortType"/>
<xsl:param name="tab"/>

<xsl:variable name="orderType">
<xsl:choose>
	<xsl:when test="$field = $currentSortField">
		<xsl:choose>
			<xsl:when test="$currentSortType = 'ASC'">DESC</xsl:when>
			<xsl:otherwise>ASC</xsl:otherwise>
		</xsl:choose>
	</xsl:when>
	<xsl:otherwise>ASC</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<th class="sb-gridview-header"  scope="col" style="width:{$width};text-align:{$align};">
	<xsl:if test="$field = $currentSortField">
		<xsl:attribute name="class">sb-gridview-header-sorted</xsl:attribute>
	</xsl:if>

	<xsl:choose>
		<xsl:when test="$field">
			<a href="javascript:pagedListDoSort('{$tab}','{$field}','{$orderType}');">
				<xsl:value-of select="$title"/>
			</a>
			<xsl:if test="$field = $currentSortField">
				<xsl:choose>
					<xsl:when test="$currentSortType = 'ASC'">
						<img style="border-width:0px;vertical-align: middle; ">
							<xsl:attribute name="src"><xsl:value-of select="/SITEBUILDER-PAGE/PROPERTIES/SKIN-PATH/."/>/images/dlg_sort_up.gif</xsl:attribute>
						</img>
					</xsl:when>
					<xsl:otherwise>
						<img style="border-width:0px;vertical-align: middle; ">
							<xsl:attribute name="src"><xsl:value-of select="/SITEBUILDER-PAGE/PROPERTIES/SKIN-PATH/."/>/images/dlg_sort_down.gif</xsl:attribute>
						</img>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:if>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$title"/>
		</xsl:otherwise>
	</xsl:choose>

	
</th>
</xsl:template>

<xsl:template name="LIST-ROW-CLASS">
<xsl:param name="position"/>
<xsl:choose>
	<xsl:when test="$position mod 2">sb-gridtext</xsl:when>
	<xsl:otherwise>sb-gridtext-alter</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="LIST-ROW-ITEM">
<xsl:param name="align"/>
<xsl:param name="title"/>
<xsl:param name="action"/>
<xsl:param name="icon"/>
<td style="text-align:{$align};padding-left:4px;padding-right:4px;">
	<xsl:choose>
		<xsl:when test="$action">
			<a href="{$action}">
				<xsl:if test="$icon">
				<img style="border-width:0px;width:16px;height:16px">
					<xsl:attribute name="src"><xsl:value-of select="/SITEBUILDER-PAGE/PROPERTIES/SKIN-PATH/."/>/icons/<xsl:value-of select="$icon"/></xsl:attribute>
				</img>
				</xsl:if>
				<xsl:value-of select="$title"/>
			</a>
		</xsl:when>
		<xsl:otherwise>
			<xsl:if test="$icon">
				<img style="border-width:0px;width:16px;height:16px">
					<xsl:attribute name="src"><xsl:value-of select="/SITEBUILDER-PAGE/PROPERTIES/SKIN-PATH/."/>/icons/<xsl:value-of select="$icon"/></xsl:attribute>
				</img>
			</xsl:if>
			<xsl:value-of select="$title"/>
		</xsl:otherwise>
	</xsl:choose>
</td>
</xsl:template>

<xsl:template match="PAGED-LIST/TOOLBAR">
	<xsl:choose>
		<xsl:when test="@TITLE">
			<xsl:call-template name="TOOLBAR-CONTENT"/>
<!--			</fieldset> -->
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="TOOLBAR-CONTENT"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="TOOLBAR-CONTENT">
	<table cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;" width="100%">
		<tr>
			<td colspan="3" style="padding-top:10px;">
				<xsl:apply-templates select="OPERATIONS"/>
			</td>
		</tr>
		
		<tr>
			<td style="padding-top:10px;" width="10"><xsl:apply-templates select="LIST-VIEW-STATES"/></td>
			<td style="padding-top:10px;" width="10"><xsl:apply-templates select="SEARCH-PANEL"/></td>
			<td align="right" width="90%"><div style="width: 1px; height: 10px;"><span></span></div></td>
		</tr>
	</table>
</xsl:template>

<xsl:template match="PAGED-LIST/TOOLBAR/OPERATIONS">
<xsl:if test="count(../../LIST/ITEM) &gt; 0">
	<table cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;" >
	<tr>
	<xsl:for-each select="OPERATION">
		<td style="padding-right: 4px;">
				<a href="#">
					<xsl:attribute name="onclick"><xsl:value-of select="@ACTION"/></xsl:attribute>
					<img border="0" alt="" width="16" height="16">
						<xsl:attribute name="src"><xsl:value-of select="$skinPath"/>/icons/<xsl:value-of select="@ICON"/></xsl:attribute>
					</img>
				</a>
		</td>
		<td style="padding-right: 8px;">
			<a href="#" style="color: Black;">
				<xsl:attribute name="onclick"><xsl:value-of select="@ACTION"/></xsl:attribute>
				<xsl:value-of select="@TITLE"/>
			</a>
		</td>
	</xsl:for-each>
	</tr>
	</table>
</xsl:if>
</xsl:template>

<xsl:template match="PAGED-LIST/TOOLBAR/SEARCH-PANEL">
<xsl:variable name="tab"><xsl:value-of select="ancestor::TAB-PANEL-CARD/@ID"/></xsl:variable>
<script language="javascript">
function pagedListShowAll(tab) {
	var formName = '<xsl:value-of select="../../@FORM-NAME"/>';
	var form = document.forms[formName];
	form.tab.value = tab;
	form.action = '<xsl:value-of select="../../@URL"/>';

	if (form.filterValue) {
		form.filterValue.selectedIndex = 0;
	}
	form.elements[tab+'searchString'].value='';
	form.submit();
}
function pagedListSearchItems(tab) {
	var formName = '<xsl:value-of select="../../@FORM-NAME"/>';
	var form = document.forms[formName];
	form.tab.value = tab;
	form.action = '<xsl:value-of select="../../@URL"/>';

	form.submit();
}
function pagedListChangeFilter(tab) {
	var formName = '<xsl:value-of select="../../@FORM-NAME"/>';
	var form = document.forms[formName];
	form.tab.value = tab;	
	form.action = '<xsl:value-of select="../../@URL"/>';

	form.submit();
}
</script>
<table border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td style="width: 150px; white-space: nowrap;padding-right: 10px;">
		<input type="text" value="{.}" class="sb-text" style="border-color:#999EA1;border-width:1px;border-style:Solid;width:145px;">
			<xsl:attribute name="name"><xsl:value-of select="$tab"/>searchString</xsl:attribute>
		</input>
	</td>
	<td align="center" style="width: 10; padding-right: 10px">
		<table cellpadding="0" cellspacing="0" border="0" type="button" style="cursor:pointer;">
		<xsl:attribute name="onclick">pagedListSearchItems('<xsl:value-of select="$tab"/>');</xsl:attribute>
		<tr>
			<td align="center">
				<img src="{$skinPath}/icons/search.png" alt="" width="16" height="16"/>
			</td>
			<td align="center" class="sb-text" style="text-decoration:underline;padding-left:5px;white-space:nowrap;"><xsl:value-of select="@SEARCH-TITLE"/></td>
		</tr>
		</table>
	</td>
	<td align="left" style="width: 10;">
		<table cellpadding="0" cellspacing="0" border="0" type="button" name="ImageButtonShowAll" style="cursor:pointer;">
			<xsl:attribute name="onclick">pagedListShowAll('<xsl:value-of select="$tab"/>');</xsl:attribute>
			<tr>
				<td align="center">
					<img src="{$skinPath}/icons/showall.png" alt="" width="16" height="16"/>
				</td>
					<td align="center" class="sb-text" style="text-decoration:underline;padding-left:5px;white-space:nowrap;"><xsl:value-of select="@SHOW-ALL-TITLE"/></td>
			</tr>
		</table>
	</td>
	</tr>
</table>
</xsl:template>

<xsl:template match="PAGED-LIST/TOOLBAR/LIST-VIEW-STATES">
<xsl:variable name="tab"><xsl:value-of select="ancestor::TAB-PANEL-CARD/@ID"/></xsl:variable>
<script language="javascript">
function pagedListChangeFilter(tab) {
	var formName = '<xsl:value-of select="../../@FORM-NAME"/>';
	var form = document.forms[formName];
	form.tab.value = tab;
	form.action = '<xsl:value-of select="../../@URL"/>';

	form.submit();
}
</script>
<table cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;" >
	<tr>
		<td valign="middle" class="sb-text" style="padding-right: 5px;"><xsl:value-of select="@TITLE"/></td>
		<td valign="middle" style="padding-right: 5px;">
			<select class="sb-text">
			<xsl:attribute name="name"><xsl:value-of select="$tab"/>filterValue</xsl:attribute>
			<xsl:attribute name="onchange">pagedListChangeFilter('<xsl:value-of select="$tab"/>');</xsl:attribute>
				<xsl:for-each select="STATE">
					<option>
						<xsl:if test="../@SELECTED = @VALUE"><xsl:attribute name="selected">true</xsl:attribute></xsl:if>
						<xsl:attribute name="value"><xsl:value-of select="@VALUE"/></xsl:attribute>
						<xsl:value-of select="@TITLE"/>
					</option>
				</xsl:for-each>
			</select>
		</td>
	</tr>
</table>
</xsl:template>

</xsl:stylesheet>
