<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="CustomText._Default" %>
<%@ Register Assembly="RadSpell.Net2" Namespace="Telerik.WebControls" TagPrefix="radS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Untitled Page</title>
</head>
<body>

    <script type="text/javascript">
    //<!--
   
      /* Setting a simple text source */
      function MyTextSource()
      {
          this.GetText = function()
          {
              return document.getElementById('TextArea1').value;
          }
          
          this.SetText = function(newValue)
          {
              document.getElementById('TextArea2').value = newValue;
          }
      }
            
      function spellCheck()
      {			
	      var RadSpell1 = GetRadSpell('<%= RadSpell1.ClientID %>');

	      var source = new MyTextSource();		
	      RadSpell1.SetTextSource(source);
	      RadSpell1.StartSpellCheck();
      }      
      
      function MultipleTextSource(sources)
      {
        this.sources = sources;

        this.GetText = function()
        {
          var texts = [];
          for (var i = 0; i < this.sources.length; i++)
          {
	          texts[texts.length] = this.sources[i].innerHTML;
          }
          return texts.join("<someUniqueTag></someUniqueTag>");
        }

        this.SetText = function(text)
        {
          var texts = text.split("<someUniqueTag></someUniqueTag>");
          for (var i = 0; i < this.sources.length; i++)
          {
	          this.sources[i].innerHTML = texts[i];
          }
        }
      }

      function multipleCheck()
      {	

        var sources = 
        [
          document.getElementById('textarea1'),
          document.getElementById('textarea2'),
          document.getElementById('textarea3')
        ];

        var spell = GetRadSpell('<%= RadSpell1.ClientID %>');
        spell.SetTextSource(new MultipleTextSource(sources));
        spell.StartSpellCheck();
      }
      
      function SelectedTextSource(source)
      {
        this.GetText = function()
        {        
          source.setActive();
          var range = document.selection.createRange();
          return range.text;
        }

        this.SetText = function(text)
        {    
          source.setActive();
          var range = document.selection.createRange();
          range.text = text;
        }
      }

      function selectionCheck()
      {			
        var RadSpell1 = GetRadSpell('<%= RadSpell1.ClientID %>');
          var source = document.getElementById('TextArea1'); 
        RadSpell1.SetTextSource(new SelectedTextSource(source));
        RadSpell1.StartSpellCheck();
      }
                             
    //-->
    </script>

  <form id="form1" runat="server">
  
    <div>
      <radS:RadSpell ID="RadSpell1" runat="server" ButtonType="None">
      </radS:RadSpell>
      <textarea id="TextArea1" cols="40" rows="5">Thiis iis mispeld in TextArea1.</textarea>
      <textarea id="TextArea2" cols="40" rows="5">Thiis iis mispeld in TextArea2.</textarea>
      <textarea id="TextArea3" cols="40" rows="5">Thiis iis mispeld in TextArea3.</textarea>
      <br/>
      <button onclick="spellCheck();" class="Button">Spellcheck One</button>
      <button onclick="multipleCheck();" class="Button">Spellcheck Multiple</button>
      <button onclick="selectionCheck();" class="Button">Spellcheck Selection</button>
  </form>
</body>
</html>
