
function poll_getResults(params){
    
    var url = '/polls/results.php';
    
    $.ajax({
       type: "POST",
       url: url,
       data: params,
       success: function(html){
          $("#poll-results").html(html);
          $("#view-results").html('<a href="javascript:void(0);" onclick="poll_getOptions(\'' + params + '\')">View Poll</a><img src="/images/arrow-link-inline-r-ko.gif" width="9" height="7" border="0" alt="" />');	       
       },
       error: function(transport, exception) {
		    throw exception;
	   }
    });
}


function poll_getOptions(params){
    
    var url = '/polls/questions.php';
    
    $.ajax({
       type: "POST",
       url: url,
       data: params,
       success: function(html){
          $("#poll-results").html(html);
          $("#view-results").html('<a href="javascript:void(0);" onclick="poll_getResults(\'' + params + '\')">View Results</a><img src="/images/arrow-link-inline-r-ko.gif" width="9" height="7" border="0" alt="" />');	       
       },
       error: function(transport, exception) {
		    throw exception;
	   }
    });
}



$(document).ready(function() { 
    var options = { 
        target: '#poll-results',
       // beforeSubmit:  showRequest,  // pre-submit callback 
        error: function(){
            $("#poll-error").html('<p class="error">Please choose an option</p>');
        },
        success: function(html){ // post-submit callback 
             // Clear errors if any
             $("#poll-error").html('');
             
             // Display results
             $("#poll-results").html(html);
             $("#view-results").html('<a href="javascript:void(0);" onclick="poll_getOptions(\'id=' + $("#params").val() + '\')">View Poll</a><img src="/images/arrow-link-inline-r-ko.gif" width="9" height="7" border="0" alt="" />');	       
        }
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#Poll').ajaxForm(options); 
});

