<?xml version="1.0" encoding="UTF-8"?>
<bindings 	xmlns="http://www.mozilla.org/xbl" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xbl="http://www.mozilla.org/xbl"	xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <binding id="xml-radiobox">
		<content>
      <xul:radiogroup datasources="" ref="*" querytype="xml" xbl:inherits="onselect,orient">
        <xul:template>
          <xul:query/>
          <xul:action>
            <xul:radio/>
          </xul:action>
        </xul:template>
      </xul:radiogroup>
		</content>
		<implementation>
			<field name="datasources">this.getAttribute("datasources") ? this.getAttribute("datasources") : ""</field>
			<field name="expr">this.getAttribute("expr") ? this.getAttribute("expr") : ""</field>
			<field name="label">this.getAttribute("label") ? this.getAttribute("label") : ""</field>
			<field name="value">this.getAttribute("value") ? this.getAttribute("value") : ""</field>
      <field name="default">this.getAttribute("default") ? this.getAttribute("default") : ""</field>
			<field name="radiogroup">document.getAnonymousNodes(this)[0];</field>
			<field name="query">this.radiogroup.firstChild.firstChild;</field>
			<field name="radio">this.query.nextSibling.firstChild;</field>
			<constructor><![CDATA[
        this.radiogroup.setAttribute("datasources", this.datasources);
        this.query.setAttribute("expr", this.expr);
        
        if(this.value[0] == "!") {
          var arg1 = this.value.substring(1,this.value.length);
          var assign = document.createElement("assign");
          assign.setAttribute("var","?var1");
          assign.setAttribute("expr",arg1);
          
          this.query.appendChild(assign);
        }
        
        if(this.label[0] == "!") {
          var arg2 = this.label.substring(1,this.label.length);
          var assign = document.createElement("assign");
          assign.setAttribute("var","?var2");
          assign.setAttribute("expr",arg2);
          
          this.query.appendChild(assign);
        }
        
        this.radio.setAttribute("uri", "?");
        
        if(this.label[0] == "!")
          this.radio.setAttribute("label", "?var2");
        else
          this.radio.setAttribute("label", this.label);
        
        if(this.value[0] == "!")
          this.radio.setAttribute("value", "?var1");
        else
          this.radio.setAttribute("value", this.value);
         
        
        
			]]></constructor>
      <method name="getSelectedValue">
				<parameter name="aValue"/>
				<body><![CDATA[
          if(this.radiogroup.selectedItem)
            return this.radiogroup.selectedItem.value;
          else
            return "";
				]]></body>
			</method>
      <method name="selectValue">
				<parameter name="aValue"/>
				<body><![CDATA[
          if(aValue == null) {
            this.radiogroup.selectedIndex = 0;
            return;
          }
          
          for(var i = 0; i<this.radiogroup.itemCount ; i++) 
          {
            if(this.radiogroup.getItemAtIndex(i).value == aValue) {
              this.radiogroup.selectedIndex = i;
              return;
            }
          }
          this.radiogroup.selectedIndex = 0;
				]]></body>
			</method>
      <method name="hideAllItems">
				<body><![CDATA[
          for(i = 0; i<this.radiogroup.itemCount ; i++) 
          {
            this.radiogroup.getItemAtIndex(i).setAttribute("hidden", "true");
          }
				]]></body>
			</method>
      <method name="unHide">
        <parameter name="aValue"/>
				<body><![CDATA[
          for(i = 0; i<this.radiogroup.itemCount ; i++) 
          {
            if(this.radiogroup.getItemAtIndex(i).value == aValue) {
              this.radiogroup.getItemAtIndex(i).setAttribute("hidden", "false");
              return;
            }
          }
				]]></body>
			</method>
      <method name="unHideAll">
				<body><![CDATA[
          for(i = 0; i<this.radiogroup.itemCount ; i++) 
          {
            this.radiogroup.getItemAtIndex(i).setAttribute("hidden", "false");
          }
				]]></body>
			</method>
		</implementation>
		<handlers>
      <handler event="mousedown">
        <![CDATA[

        ]]>
      </handler>
		</handlers>
	</binding>
</bindings>