<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Wave Poll" >
  <Require feature="wave" />
  <Require feature="dynamic-height" heigth="500" />
  </ModulePrefs>
  <Content type="html">
    <![CDATA[

      <style type="text/css">

        * {
          font-size: 8pt;
        }

        #alert {
          color: #32CD32;
          font-weight: bold;
        }


        .btn_x {
          border: none;
         -moz-border-radius: 15px;
         max-height: 15px;
         max-width: 15px;
         background-color: #dd0000;
         color: #ffffff;
         display: -moz-inline-box;
         display: inline-block;
         font-size: 6pt;
        }

        .btn_x:hover {
          cursor: pointer;
          background-color: #bb0000;
        }

        .tab {
          display: block;
          border: 1px solid #D3D3D3;
          -moz-border-radius: 5px;
          padding: 10px;
          margin: 0 2px 2px;
          width: 400px;
        }

        .tab_btn {
           border-left: 1px solid #D3D3D3;
           display: -moz-inline-box;
           display: inline-block;
           border-top: 1px solid #D3D3D3;
           border-right: 1px solid #D3D3D3;
          -moz-border-radius-topleft: 10px;
          -moz-border-radius-topright: 10px;
          margin-left: 10px;
          width: 70px;
          text-align:center;
          cursor: pointer;
        }

        .tab_btn:hover {
          text-decoration: underline;
          cursor: pointer;
        }


        .clear {
          clear: both;
        }


        .fills {
         display: -moz-inline-box;
         display: inline-block;
         margin-top: 3px;
         width: 100px;
         height: 16px;
         font-size: 7pt;
         color: #ffffff;
         -moz-border-radius: 10px;
         background-color: #4887ee;
        }

        .desc {
          top: 1px;
          left: 10px;
          display: -moz-inline-box;
         display: inline-block;
         position: relative;
         float: left;
        }


        .btn_r, .btn_l {
         float:right;
         width: 19px;
         text-align: center;
         height: 16px;
         font-size: 8pt;
         background-color: #ffffff;
         color: #4887ee;
        }

        .btn_r {
         border: 1px solid #4887ee;
         -moz-border-radius-topright: 10px;
         -moz-border-radius-bottomright: 10px;
        }

        .btn_l {
         border-left: 1px solid #4887ee;
         border-top: 1px solid #4887ee;
         border-bottom: 1px solid #4887ee;
         -moz-border-radius-topleft: 10px;
         -moz-border-radius-bottomleft: 10px;
         border-right: none;
        }

        .btn_l:hover, .btn_r:hover {
         background-color: #4887ee;
         cursor: pointer;
         color: #ffffff;
        }

        .row {
          position: relative;
          display: block;
        }
        </style>
        <script type="text/javascript">

        function getGesValue(){var b=getVotes(),a=0;if(b!==null)a=b.length;return a}function getOptions(){var b=wave.getState().get("options","");return b?b.split("|"):null}function getVotespp(){var b=wave.getState().get("votespp","");return b?parseInt(b):null}function getVoter(){var b=wave.getState().get("voter","");return b?b.split("|"):null}function getVotes(){var b=wave.getState().get("votes","");return b?b.split("|"):null} function setOptions(b){var a=null;if(b!==null)a=b.join("|");wave.getState().submitDelta({options:a})}function deleteOption(b){var a=getOptions();if(a!==null){a.splice(b,1);setOptions(a);a=getVotes();var c=getVoter();if(a!==null&&c!==null){for(var d=c.length-1;d>=0;d--)if(a[d]==b){a.splice(d,1);c.splice(d,1)}for(d=c.length-1;d>=0;d--)a[d]>b&&a.splice(d,1,parseInt(a[d])-1);setVote(a,c)}}} function setVote(b,a){var c=null,d=null;if(b!==null&&a!==null){d=b.join("|");c=a.join("|")}wave.getState().submitDelta({votes:d,voter:c})}function AddOption(b){var a=getOptions();if(a!==null)a[a.length]=b.value;else{a=[];a[0]=b.value}document.getElementById("alert").innerHTML='You added "'+b.value+'"';setOptions(a);b.value=""} function ChangeVotespp(b){if(b.value==parseInt(b.value)){reset();wave.getState().submitDelta({votespp:b.value});document.getElementById("alert").innerHTML='You changed the votes per participant to "'+b.value+'".'}}function getAnzVotes(){var b;b=1;var a=getVoter();if(a!==null)for(var c=0;c<a.length;c++)a[c]==wave.getViewer().getId()&&b++;return b} function vote(b){var a=getVotes(),c=getVoter();if(getAnzVotes()<=getVotespp()){if(a!==null&&c!==null){a[a.length]=b;c[c.length]=wave.getViewer().getId()}else{a=[];a[0]=b;c=[];c[0]=wave.getViewer().getId()}setVote(a,c)}}function getValue(b){var a=getVotes(),c=0;if(a!==null)for(var d=0;d<a.length;d++)a[d]==b&&c++;return c} function deleteOpt(){wave.getState().submitDelta({votes:""});wave.getState().submitDelta({voter:""});setOptions(null);document.getElementById("alert").innerHTML="You have deleten the whole poll"}function reset(){wave.getState().submitDelta({votes:""});wave.getState().submitDelta({voter:""});document.getElementById("alert").innerHTML="You have resetted the votes"}function init(){wave&&wave.isInWaveContainer()&&wave.setStateCallback(stateUpdate)} function hatGevotet(b){var a=getVotes(),c=getVoter();if(a!==null&&c!==null)for(var d=0;d<c.length;d++)if(a[d]==b&&c[d]==wave.getViewer().getId())return true;return false}function deleteVote(b){var a=getVotes(),c=getVoter(),d=true;if(a!==null&&c!==null)for(var e=0;e<c.length;e++)if(a[e]==b&&c[e]==wave.getViewer().getId()&&d){a.splice(e,1);c.splice(e,1);setVote(a,c);d=false}} function writeLog(){var b=document.getElementById("tab_3");b.innerHTML="";var a=getVotes(),c=getVoter(),d=getOptions();if(a!==null&&c!==null)for(var e=0;e<c.length;e++)b.innerHTML+="<div><b>"+wave.getParticipantById(c[e]).getDisplayName()+'</b> voted for "'+d[a[e]]+'"</div>'}function countVotes(b){var a=getVotes(),c=0;if(a!==null)for(var d=0;d<a.length;d++)a[d]==b&&c++;return c} function getPercent(b){b=getOptions();for(var a=[],c=0;c<b.length;c++){var d=50;d=getValue(c);a[c]=parseInt(d/getGesValue()*100)}return a}var show_tab=1;function TabClick(b){for(var a=1;a<=4;a++)if(b==a)document.getElementById("tab_"+a).style.display="block";else document.getElementById("tab_"+a).style.display="none";show_tab=b;document.getElementById("chart").innerHTML="<i>Click on a Chart to show it</i>";document.getElementById("btn_embed").style.display="none";stateUpdate()} function embed(){var b=document.getElementById("chart").innerHTML;wave.getState().submitDelta({embed:b})} function showChart(b){var a=document.getElementById("chart"),c="",d=getVotes(),e=getOptions();if(d!==null&&e!==null){percent=getPercent(d);a.innerHTML="";for(var f=d=0;f<e.length;f++){d=b==2?e.length-f-1:f;a.innerHTML+="<div style='border-bottom: 1px solid #dddddd; pading: 1px; margin: 1px; max-width: 400px;'>"+(d+1)+". "+e[f]+" <span style='float: right; color: #aaaaaa;'>"+countVotes(f)+"/"+getGesValue()+" = "+percent[f]+" %</span></div>";e[f]=""+(f+1)+""}switch(b){case 1:c="http://chart.apis.google.com/chart?cht=bvs&chd=t:"+ percent.join(",")+"&chxt=x,y&chxl=0:|"+e.join("|")+"&chs=300x150&chco=0000ff";break;case 2:c="http://chart.apis.google.com/chart?cht=bhs&chd=t:"+percent.join(",")+"&chxt=x,y&chxl=1:|"+e.join("|")+"&chs=300x150&chco=0000ff";break;case 3:c="http://chart.apis.google.com/chart?cht=p&chd=t:"+percent.join(",")+"&chs=300x150&chl="+e.join("|")+"&chco=0000ff";break;case 4:c="http://chart.apis.google.com/chart?cht=p3&chd=t:"+percent.join(",")+"&chs=300x150&chl="+e.join("|")+"&chco=0000ff";break}a.innerHTML+= "<div style='text-align: center;'><img src='"+c+"' width='300' height='150' alt='Bar Chart'></div>";if(wave.getViewer()==wave.getHost())document.getElementById("btn_embed").style.display="block"}gadgets.window.adjustHeight()} function stateUpdate(){var b=wave.getState().get("embed","");if(b)document.getElementById("gadget").innerHTML=b;else{b=document.getElementById("tab_1");var a=getVotespp();if(a==parseInt(a))document.getElementById("votespp").value=a;else{wave.getState().submitDelta({votespp:1});document.getElementById("votespp").value=1}a=getOptions();if(a!==null&&show_tab==1){output="";if(getAnzVotes()<=getVotespp())output+="<span id='votes_left'><b>"+(getVotespp()-getAnzVotes()+1)+"</b> votes left</span>";else output= "<i>you have no votes left</i>";output+="<table>";for(var c=0;c<a.length;c++){var d=50,e=getValue(c),f=0;if(e!=0){f=e/getGesValue();d=f*200+50}output+="<tr>";if(wave.getViewer()==wave.getHost())output+="<td><input type='button' class='btn_x' onClick='deleteOption("+c+")' value='x'></td>";output+="<td>"+a[c]+"</td>";output+="<td style='width: 250px;'>";output+="<div class='fills' style='width: "+d+"px'><div class='desc'> "+Math.round(f*100)+"% </div>";if(getAnzVotes()<=getVotespp()&&hatGevotet(c)){output+= "<input type='button' id='tbn_"+c+"' class='btn_r' value='+' onClick='vote("+c+")'>";output+="<input type='button' id='tbn_"+c+"' class='btn_l' value='-' onClick='deleteVote("+c+")'>"}else if(hatGevotet(c))output+="<input type='button' id='tbn_"+c+"' class='btn_r' value='-' onClick='deleteVote("+c+")'>";else if(getAnzVotes()<=getVotespp())output+="<input type='button' id='tbn_"+c+"' class='btn_r' value='+' onClick='vote("+c+")'>";output+="</td></tr>"}b.innerHTML=output}if(wave.getViewer()==wave.getHost())document.getElementById("admin_btn").style.display= "inline-block";writeLog()}gadgets.window.adjustHeight()}gadgets.util.registerOnLoadHandler(init);

        </script>
  <div id="gadget" style="max-width: 500px;">
    <div class="tab_btn" onClick="TabClick(1)">poll</div>
    <div class="tab_btn" onClick="TabClick(2)">diagram</div>
    <div class="tab_btn" onClick="TabClick(3)">logs</div>
    <div id="admin_btn" style="display: none" class="tab_btn" onClick="TabClick(4)">settings</div>



    <div id="tab_1" class="tab" style="display: block">

The owner of the Gadget have to add options in the settings

<script type="text/javascript"><!--
google_ad_client = "pub-7710919379530435";
/* 468x60, Erstellt 30.01.10 */
google_ad_slot = "6058800307";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

</div>
    <div id="tab_2" class="tab" style="display: none">
       <div style="margin-bottom: 5px;">
              <span style="cursor: pointer; padding: 0 10px; border-right: 1px solid #d3d3d3;" onClick="showChart(1)">Bar Chart 1</span>
              <span style="cursor: pointer; padding: 0 10px; border-right: 1px solid #d3d3d3;" onClick="showChart(2)">Bar Chart 2</span>
              <span style="cursor: pointer; padding: 0 10px;" onClick="showChart(3)">Pie Chart 2D</span>
              <span style="cursor: pointer; padding: 0 10px; border-left: 1px solid #d3d3d3;" onClick="showChart(4)">Pie Chart 3D</span>
         </div>
        <div style="border-top: 1px solid #d3d3d3;" id="chart"><i>Click on a Chart to show it</i></div>
        <input style='float: right; display: none;' type='button' value='embed the result' id='btn_embed' onClick='embed()'><div class='clear'></div>
    </div>

     <div id="tab_3" class="tab" style="display: none; max-height: 200px; overflow: scroll;"></div>

    <div id="tab_4" style="display: none" class="tab">
     <div id="alert"></div>
      <table>
          <tr><td style="text-align: right;"><input type="text" id="option"></td><td style="text-align: left"><input type="button" value="add" onClick="AddOption(document.getElementById('option'))"> new Option</td></tr>
          <tr><td style="text-align: right"><input type="text" id="votespp" size="2" value="1" onkeyup="ChangeVotespp(document.getElementById('votespp'))"></td><td style="text-align: left"> votes per participant (this will reset the votes)</td></tr>
          <tr><td style="text-align: right"><input type="button" value="reset" onClick="reset()"></td><td style="text-align: left"> the votes</td></tr>
          <tr><td style="text-align: right"><input type="button" value="delete" onClick="deleteOpt()"></td><td style="text-align: left"> all options and reset the votes</td></tr>
      </table>
    </div>
  </div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12746084-1");
pageTracker._setDomainName(".samuirai.de");
pageTracker._trackPageview();
} catch(err) {}</script>

  ]]>
  </Content>
</Module>
