<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
<ModulePrefs title="s990we editor">
<Require feature="rpc" /> 
</ModulePrefs>
<Content type="html">
<![CDATA[ 
<div id="content_div" style="height: 50px;"></div>
<div id="curser_position" style="height: 50px;"></div>

<script type="text/javascript" src="http://wave-api.appspot.com/public/wave.js"></script>

    <textarea id="text" style="width: 40%;height: 40%;" onkeyup="keyUp()" onClick="curChange()"></textarea>


    <input type=button value="Click Me!" id="butCount" onClick="buttonClicked()">
    <input type=button value="Reset" id="butReset" onClick="resetCounter()">
    
    <script type="text/javascript">

    var div = document.getElementById('content_div');
    var cur_pos = document.getElementById('curser_position');

    function buttonClicked() {
      var value = parseInt(wave.getState().get('count', '0'));
      wave.getState().submitDelta({'count': value + 1});
    }

    function curChange()
    {
       var ta = document.getElementById('text');
       //cur_pos.innerHTML = "CurPos: " + ta.selectionStart;
    }
    
    function keyUp() {
       var ta = document.getElementById('text');
       curChange();
       wave.getState().submitDelta({'text': ta.value});
    }

    function stateUpdated() {
      if(!wave.getState().get('count')) {
        div.innerHTML = "The count is 0."
      }
      else {
        div.innerHTML = "The count is " + wave.getState().get('count');
	
	var ta = document.getElementById('text');
	ta.value = wave.getState().get('count');
      } 
      if(wave.getState().get('text'))
      {	
	var ta = document.getElementById('text');
	ta.value = wave.getState().get('text');
      }
    }
 
    function curControl()
    {
	var participants = wave.getParticipants();
	var numPeople = participants.length;
	cur_pos.innerHTML = "";
	if (participants) {
		for (var i = 0; i < participants.length; ++i) {
			cur_pos.innerHTML += participants[i].getDisplayName() + " ";
		}
	}

    }
 
    function init() {
      if (wave && wave.isInWaveContainer()) {
        wave.setStateCallback(stateUpdated);
        wave.setParticipantCallback(curControl);
       }
    }

    // Reset value of "count" to 0
    function resetCounter(){
      wave.getState().submitDelta({'count': '0'});
    }

    gadgets.util.registerOnLoadHandler(init);
    
    </script>
  ]]> 
  </Content>
</Module>