<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>
<!--
*******************************************************************
* MediaCoder extension XSLT template version 0.6.0.1
* Distributed under GPL license
* Copyright (c) 2007 Stanley Huang <stanleyhuangyc@gmail.com>
* All rights reserved.
*******************************************************************
-->
<xsl:template match="/extension">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<xsl:call-template name="InitExtension"/>
<script language="javascript">
var entry = null;
<xsl:if test="entry">
entry='<xsl:value-of select="entry"/>';
</xsl:if>
if (entry)
	window.location.href = entry;
else
	alert("No entry defined.");
</script>
</head>
<body style="font-family:Verdana;font-size:large">
Loading Extension...
</body>
</html>
</xsl:template>

  <xsl:template name="InitExtension">
  	<script language="javascript" src="../_include/extension.js"></script>
    <script>
	<xsl:if test="defaults">SetDefaultPrefs();</xsl:if>
	function SetDefaultPrefs()
	{
		var docExtensionPrefs = document.implementation.createDocument("", "MediaCoderPrefs", null);
		<xsl:for-each select="defaults/node">
		AddPrefNode(docExtensionPrefs,'<xsl:value-of select="@key" />','<xsl:value-of select="@value" />');
		</xsl:for-each>
		PostPrefXML(docExtensionPrefs);
		delete docExtensionPrefs;
	}
	</script>
  </xsl:template>

  <xsl:template name="AddElement">
	<xsl:param name="element"/>
	<xsl:param name="option"/>
	<xsl:choose>
	<xsl:when test="$element/@type='checkbox'">
		<label><input type="checkbox">
		<xsl:attribute name="id"><xsl:value-of select="$element/@id"/></xsl:attribute>
		<xsl:if test="$element/@selected or $element/option[2]/@selected">
			<xsl:attribute name="checked">true</xsl:attribute>
		</xsl:if>
		<xsl:attribute name="onclick">onElementChange(id,checked);</xsl:attribute>
		<xsl:choose>
		<xsl:when test="$element/option">
			<xsl:attribute name="onchange">
			if(checked){
			<xsl:for-each select="$element/option[2]/node">SetPrefValue('<xsl:value-of select="@key" />','<xsl:value-of select="@value" />');</xsl:for-each>}else{
			<xsl:for-each select="$element/option[1]/node">SetPrefValue('<xsl:value-of select="@key" />','<xsl:value-of select="@value" />');</xsl:for-each>}
			</xsl:attribute>
		</xsl:when>
		<xsl:otherwise>
			<xsl:attribute name="onchange">SetPrefValue('<xsl:value-of select="$element/@key" />',checked);</xsl:attribute>
			<xsl:if test="$element/@value='true' or $element/@value='1'">
				<xsl:attribute name="checked">true</xsl:attribute>
			</xsl:if>
		</xsl:otherwise>
		</xsl:choose>
		</input><xsl:value-of select="$element/@text"/></label>
	</xsl:when>
	
	<xsl:when test="$element/@type='radiobox'">
		<label><input type="radio">
		<xsl:attribute name="name"><xsl:value-of select="$element/@id"/></xsl:attribute>
		<xsl:if test="$option/@selected">
			<xsl:attribute name="checked">true</xsl:attribute>
		</xsl:if>
		<xsl:attribute name="onclick">onElementChange(name,'<xsl:value-of select="$option/@text"/>');</xsl:attribute>
		<xsl:attribute name="onchange">
		<xsl:choose>
		<xsl:when test="$element/option"><xsl:for-each select="$option/node">SetPrefValue('<xsl:value-of select="@key" />','<xsl:value-of select="@value" />');</xsl:for-each></xsl:when>
		<xsl:otherwise>SetPrefValue('<xsl:value-of select="$element/@key" />','<xsl:value-of select="$element/@value" />');</xsl:otherwise>
		</xsl:choose>
		</xsl:attribute>
		</input><xsl:value-of select="$option/@text"/></label>
	</xsl:when>
	
	<xsl:when test="$element/@type='editbox'">
		<input type="text">
		<xsl:attribute name="id"><xsl:value-of select="$element/@id"/></xsl:attribute>
		<xsl:attribute name="size"><xsl:value-of select="$element/@size"/></xsl:attribute>
		<xsl:attribute name="value"><xsl:value-of select="$element/@value"/></xsl:attribute>
		<xsl:attribute name="onchange">
		  <xsl:choose>
		  <xsl:when test="node">
		  <xsl:for-each select="$element/node">SetPrefValue('<xsl:value-of select="@key" />',value);</xsl:for-each>onElementChange(id,value);
		  </xsl:when>
		  <xsl:otherwise>
		  SetPrefValue('<xsl:value-of select="$element/@key" />',value);onElementChange(id,value);
		  </xsl:otherwise>
		  </xsl:choose>
		</xsl:attribute>
		</input>
	</xsl:when>
	
	<xsl:when test="$element/@type='combobox' or $element/@type='listbox'">
		<select>
		<xsl:attribute name="id"><xsl:value-of select="$element/@id"/></xsl:attribute>
		<xsl:attribute name="onclick">onElementChange(id,value);</xsl:attribute>
		<xsl:if test="$element/@size">
		<xsl:attribute name="size"><xsl:value-of select="$element/@size"/></xsl:attribute>
		</xsl:if>
		<xsl:for-each select="$element/option">
		  <option>
		  <xsl:if test="@selected">
			  <xsl:attribute name="selected"/>
		  </xsl:if>
		  <xsl:if test="@value">
			<xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute>
		  </xsl:if>
		  <xsl:attribute name="onclick">
		    <xsl:choose>
		    <xsl:when test="node">
			  <xsl:for-each select="node">SetPrefValue('<xsl:choose><xsl:when test="@key"><xsl:value-of select="@key" /></xsl:when><xsl:otherwise><xsl:value-of select="../../@key"/></xsl:otherwise></xsl:choose>','<xsl:value-of select="@value" />');</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
			  <!--no node-->
			  SetPrefValue('<xsl:value-of select="../@key"/>','<xsl:value-of select="@value"/>')
			</xsl:otherwise>
			</xsl:choose>
		  </xsl:attribute>
		  <xsl:choose>
		  <xsl:when test="@text">
		    <xsl:value-of select="@text" />
		  </xsl:when>
		  <xsl:otherwise>
		    <xsl:value-of select="@value" />
		  </xsl:otherwise>
		  </xsl:choose>
		  </option>
		</xsl:for-each>
		</select>
	</xsl:when>
	</xsl:choose>

  </xsl:template>
</xsl:stylesheet>