<?xml version="1.0"?> 
<!--
   The contents of this file are subject to the Netscape Public
   License Version 1.1 (the "License"); you may not use this file
   except in compliance with the License. You may obtain a copy of
   the License at http://www.mozilla.org/NPL/
    
   Software distributed under the License is distributed on an "AS
   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
   implied. See the License for the specific language governing
   rights and limitations under the License.
    
   The Original Code is Mozilla Communicator client code, released
   March 31, 1998.
   
   The Initial Developer of the Original Code is Netscape
   Communications Corporation. Portions created by Netscape are
   Copyright (C) 1998-1999 Netscape Communications Corporation. All
   Rights Reserved.
   
   Contributor(s): 
  -->

<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>

<!DOCTYPE window [
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
%brandDTD;
<!ENTITY % prefSmartBrowsingDTD SYSTEM "chrome://communicator/locale/pref/pref-smart_browsing.dtd" >
%prefSmartBrowsingDTD;
]>

<window xmlns:html="http://www.w3.org/TR/REC-html40"
        class="color-dialog"
		    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="&title.label;" 
        orient="vertical"
  		  onload="parent.initPanel('chrome://communicator/content/pref/pref-smart_browsing.xul');">

  <script language="JavaScript">
  <![CDATA[
  
  _elementIDs = ["browserRelatedDisabledForDomains", "addDomain", "browserGoBrowsingEnabled"];
  
  
  function Startup()
  {
    // populate tree
    var domainPrefField = document.getElementById( "browserRelatedDisabledForDomains" );
    var domains = domainPrefField.getAttribute("value").split(",");
    if( domains[0] != "" )
      {
        for( var i = 0; i < domains.length; i++ )
          createCell( domains[i] );
      }
      
    // select the first item    
    selectFirstCell();
    
    // enable buttons
    doButtonEnabling();
  }

  function selectFirstCell()
  {
    var domainKids = document.getElementById( "disabledKids" );
    if( domainKids.childNodes.length >= 1 ) {
      var domainTree = document.getElementById( "disabledDomains" );
      domainTree.selectItem( domainKids.firstChild );
    }
  }
  
  function addDomain()
  {
    var domainField = document.getElementById( "addDomain" );
    if( domainField.value != "" ) {
      var domainTree = document.getElementById( "disabledDomains" );
      domainTree.selectItem( createCell( domainField.value ) );
      rebuildPrefValue();
      domainField.value = "";
      doButtonEnabling();
    }
  }
  
    
  function removeDomain()
  {
    var domainTree = document.getElementById( "disabledDomains" );
    var treeKids = document.getElementById( "disabledKids" );
    var selectedItems = domainTree.selectedItems;
    if( selectedItems.length >= 1 )
    {
      for( var i = 0; i < selectedItems.length; i++ )
      {
        treeKids.removeChild( selectedItems[i] );
      }
    }
    selectFirstCell();
    rebuildPrefValue();
  }
    
  function rebuildPrefValue()
  {
    var treeKids = document.getElementById( "disabledKids" );
    var string = "";
    if( treeKids.hasChildNodes() )
    {
      for( var i = 0; i < treeKids.childNodes.length; i++ )
      {
        var domain = treeKids.childNodes[i].firstChild.firstChild.getAttribute("value");
        string += ( domain + "," );
      }
    }
    var domainPrefField = document.getElementById( "browserRelatedDisabledForDomains" );
    domainPrefField.setAttribute("value",string);
  }
  
  function createCell( aValue )
  {
    var treeKids  = document.getElementById( "disabledKids" );
    var item      = document.createElement( "treeitem" );
    var row       = document.createElement( "treerow" );
    var cell      = document.createElement( "treecell" );
    cell.setAttribute( "value", aValue );
    row.appendChild( cell );
    item.appendChild( row );
    treeKids.appendChild( item );
    return item;
  }

  function treeHandleEvent( aEvent )
  {
    if( aEvent.which == 46 )
      removeDomain();
  }

  function doButtonEnabling()
  {
    var addDomain = document.getElementById("addDomain");
    var prefstring = document.getElementById("browserRelatedDisabledForDomains").getAttribute("value");
    if( addDomain.value == "" || prefstring.indexOf( addDomain.value + "," ) != -1 )
      document.getElementById("addDomainButton").setAttribute("disabled","true");
    else
      document.getElementById("addDomainButton").removeAttribute("disabled");
  }  

  ]]>
  </script>
        
  <box class="box-smallheader" title="&lHeader;"/>

  <titledbox orient="vertical">
	  <title><text value="&lHeader;"/></title>
		
    <html>&whatsRelatedDescription.label;</html>
    
    <html id="doNotAcceptText">&doNotDecp.label;</html>
    
    <grid flex="1">
      <columns>
        <column flex="1"/>
        <column/>
      </columns>
      <rows>
        <row>
          <tree class="inset" id="disabledDomains" multiple="true" onkeyup="treeHandleEvent(event)">
            <treecol/>   
            <treechildren id="disabledKids"/>
          </tree>
          <box autostretch="never" valign="top">
            <button class="dialog" id="removeDomain" value="&removeDomain.label;" accesskey="&removeDomain.accesskey;"
                    oncommand="removeDomain();"/>
          </box>
        </row>
        <row>
          <box autostretch="never">
            <text class="label" id="domainText" value="&domain.label;" accesskey="&domain.accesskey;" for="addDomain"/>
            <textfield id="addDomain" flex="1" onkeyup="doButtonEnabling();"/>
          </box>
          <button disabled="true" class="dialog" id="addDomainButton" value="&addDomain.label;" accesskey="&addDomain.accesskey;"
                  oncommand="addDomain();"/>
        </row>
      </rows>
    </grid>

    <data id="browserRelatedDisabledForDomains" pref="true" preftype="string" 
                 prefstring="browser.related.disabledForDomains" prefattribute="value" wsm_attributes="value"/>

  </titledbox>

  <titledbox orient="vertical">
	  <title><text value="&internetKeywordsHeader.label;"/></title>

    <html>&internetKeywordsDescription.label;</html>
    
    <box autostretch="never">
      <checkbox id="browserGoBrowsingEnabled" value="&keywordsEnabled.label;" accesskey="&keywordsEnabled.accesskey;"
                pref="true" preftype="bool" prefstring="keyword.enabled"
                prefattribute="checked"/>
      <spring flex="1"/>
      <button class="dialog" value="&moreInformation.label;" accesskey="&moreInformation.accesskey;"/>
    </box>
    
  </titledbox>
		
</window>
