function form($instance)
    {
        $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
        $id = isset($instance['id']) ? esc_attr($instance['id']) : '';
        $type = isset($instance['type']) ? esc_attr($instance['type']) : 'poll';
        ?>
				<p><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', OPINIONSTAGE_WIDGET_UNIQUE_ID);
        ?>
</label>
				<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
" /></p>
				
				<p>
					<label for="<?php 
        echo $this->get_field_id('type');
        ?>
"><?php 
        _e('Content type:', OPINIONSTAGE_WIDGET_UNIQUE_ID);
        ?>
</label>
					<select class="widefat" name="<?php 
        echo $this->get_field_name('type');
        ?>
" id="<?php 
        echo $this->get_field_id('type');
        ?>
">
						<option value="poll" <?php 
        selected($type, 'poll');
        ?>
>Poll</option>
						<option value="set" <?php 
        selected($type, 'set');
        ?>
>Set</option>
						<option value="0" <?php 
        selected($type, 0);
        ?>
>Disable</option>
					</select>
				</p>
				
				<p>
					<label for="<?php 
        echo $this->get_field_id('id');
        ?>
">
						<span class="pollWrp" style="display: none;">
							<?php 
        _e('Poll ID:', OPINIONSTAGE_WIDGET_UNIQUE_ID);
        ?>
						</span>
						<span class="setWrp" style="display: none;">
							<?php 
        _e('Set ID:', OPINIONSTAGE_WIDGET_UNIQUE_ID);
        ?>
						</span>
					</label>
					<input class="widefat" id="<?php 
        echo $this->get_field_id('id');
        ?>
" name="<?php 
        echo $this->get_field_name('id');
        ?>
" type="text" value="<?php 
        echo $id;
        ?>
" />
				</p>
				
				<div class="pollWrp" style="display: none;">
					<p><?php 
        echo opinionstage_create_link('Locate the Poll ID', 'dashboard', '');
        ?>
</p>
				</div>
				<div class="setWrp" style="display: none;">
					<p><?php 
        echo opinionstage_create_link('Locate the Set ID', 'dashboard', 'tab=sets');
        ?>
</p>
				</div>
								
				<script type="text/javascript">
					jQuery(function ($)
					{
						var $pollWrp = $(".pollWrp");
						var $setWrp = $(".setWrp");
						$("#<?php 
        echo $this->get_field_id('type');
        ?>
").change(function (e)
						{
							var $this = $(this);
							var val = $this.val();
							if (val == "poll")
							{
								$setWrp.stop(false, true).fadeOut(0, function ()
								{
									$pollWrp.stop(false, true).fadeIn(e.isTrigger ? 0 : "fast");
								});
							}
							else if (val == "set")
							{
								$pollWrp.stop(false, true).fadeOut(0, function ()
								{
									$setWrp.stop(false, true).fadeIn(e.isTrigger ? 0 : "fast");
								});					
							}							
						}).trigger("change");
						$(window).load(function ()
						{
							$("#<?php 
        echo $this->get_field_id('type');
        ?>
").trigger("change");
						});
					});
				</script>				
			<?php 
    }
/**
 * The popup window in the post/page edit/new page
 */
function opinionstage_add_poll_popup()
{
    ?>
	<div id="opinionstage-insert-poll-form" style="display:none;">
      <div id="content">
		<h3><strong>Type:</strong></h3>
		<p>
			<select style="width: 100%; max-width: 300px; font-size: 20px; height: 40px; line-height: 40px;" id="opinionstage-type">
				<option value="poll">Insert a Poll</option>
				<option value="set">Insert a Set</option>
			</select>
		</p>
		<style type="text/css">
			.pollWrp p, .setWrp p { padding: 1px 0 !important; }
		</style>
		<script type="text/javascript">
			jQuery(function ($)
			{
				var $pollWrp = $(".pollWrp");
				var $setWrp = $(".setWrp");
				$("#opinionstage-type").change(function ()
				{
					var $this = $(this);
					var val = $this.val();
					if (val == "poll")
					{
						$setWrp.fadeOut(0, function ()
						{
							$pollWrp.fadeIn("fast");
						});
					}
					else if (val == "set")
					{
						$pollWrp.fadeOut(0, function ()
						{
							$setWrp.fadeIn("fast");
						});					
					}
				}).trigger("change");
			});
		</script>
		<div class="pollWrp" style="display: none;">
			<h3><strong>Enter Poll ID (e.g. 2195036):</strong></h3>
			<p><input type="text" name="poll-id" id="opinionstage-poll-id" value="" /></p>
			<p class="submit">
			  <input type="button" class="opinionstage-submit button-primary" value="Insert Poll" name="submit" />
			</p>
			<p><strong>Haven't created a poll yet?</strong></br></br>
				<?php 
    echo opinionstage_create_link('Create a new poll', 'new_poll', '');
    ?>
			</p>
			<p><strong>Don't know the poll ID?</strong></br></br>
				<?php 
    echo opinionstage_create_link('Locate ID of an existing poll', 'dashboard', '');
    ?>
			</p>
		</div>
		<div class="setWrp" style="display: none;">
			<h3><strong>Enter Set ID (e.g. 2152089):</strong></h3>
			<p><input type="text" name="set-id" id="opinionstage-set-id" value="" /></p>
			<p class="submit">
			  <input type="button" class="opinionstage-submit button-primary" value="Insert Set" name="submit" />
			</p>
			<p><strong>Haven't created a set yet?</strong></br></br>
				<?php 
    echo opinionstage_create_link('Create a new set', 'sets/new', '');
    ?>
			</p>
			<p><strong>Don't know the set ID?</strong></br></br>
				<?php 
    echo opinionstage_create_link('Locate ID of an existing set', 'dashboard', 'tab=sets', array());
    ?>
			</p>
		</div>
	  </div>
	</div>  
	<?php 
}