<?php 
echo $this->Html->script('site_js/common');
echo $this->Html->script('jstz.min');
?>


<script type="text/javascript">
var timezone;

var tz = jstz.determine(); // Determines the time zone of the browser client
timezone = tz.name(); //'Asia/Kolhata' for Indian Time.

</script>

<div class="blocktitle"> Discussion</div>
<div class="tar borb">
	<?php echo $this->Html->link('Class Discussions',array('action'=>'discussion'),array('class'=>'btn btn-mini'))?>
	<?php echo $this->Html->link('My Discussions',array('action'=>'discussion','Mydiscussions'),array('class'=>'btn btn-mini'))?>
	<?php echo $this->Html->link('Create',array('action'=>'add','Discussion'),array('class'=>'btn btn-mini'))?>
	<?php echo $this->Html->link('Draft',array('action'=>'draft'),array('class'=>'btn btn-mini'))?>
</div>
<br/>

<div class="w97p pdl10">
	<?php 
	
	$items_per_group = 5;
	$arr_discussionList = sizeof($discussions);
	

	$total_groups= ceil($arr_discussionList/$items_per_group);


	
	?>
	<script type="text/javascript">
    $(document).ready(function() {
    var path='<?php echo $this->webroot?>';

            var track_load = 0; //total loaded record group(s)
            var loading  = false; //to prevents multipal ajax loads
            var total_groups = '<?php echo $total_groups;?>'; //total record group(s)

            $('#results').load(path+"classcontents/draftload", {'group_no':track_load,'timezone':timezone}, function() {track_load++;}); //load first group

                    $('.partA').bind('scroll', function()
                    {
                    	//alert(track_load);
                        
                      if($(this).scrollTop() + $(this).innerHeight()+150>=$(this)[0].scrollHeight)
                      {
                    	  
                              if(track_load <= total_groups && loading==false) //there's more data to load
                                    {
                                            	
                                            loading = true; //prevent further ajax loading
                                            $('.animation_image').show(); //show loading image

                                            //load data from the server using a HTTP POST request
                                            $.post(path+"classcontents/draftload",{'group_no': track_load,'timezone':timezone}, function(data){

                                                    $("#results").append(data); //append received data into the element

                                                    //hide loading image
                                                    $('.animation_image').hide(); //hide loading image once data is received

                                                    track_load++; //loaded group increment
                                                    loading = false; 

                                            }).fail(function(xhr, ajaxOptions, thrownError) { //any errors?

                                                    alert(thrownError); //alert with HTTP error
                                                    $('.animation_image').hide(); //hide loading image
                                                    loading = false;

                                            });

                                    }
                      }
             });
    });
    
</script>
	
<ol id="results">
	</ol>
<div class="animation_image" style="display:none" align="center"><img src="<?php echo $this->webroot;?>img/ajax-loader.gif"></div>
</div>	
<script type="text/javascript">
     var path='<?php echo $this->webroot;?>';
		function blogpublished(id){

			var con=confirm('Are you sure to publish this discussion?');
			if(con==true){
			 $.ajax({
			     	type: 'POST',
			     	url: path +'classcontents/blogpublished',
			     	data: {id:id},
			     	success: function(data){
			     		location.href="<?php echo $this->here?>";
			     		//$("#rf"+id).attr('onclick',"blogunpublish('"+id+"')").html('Unpublish');
			     		//$("#rf"+id).attr('id','df'+id);
			     	}
		     	});
			}
		}
		function blogunpublish(id){

			var con=confirm('Are you sure to unpublish this discussion?');
			if(con==true){
			 $.ajax({
			     	type: 'POST',
			     	url: path +'classcontents/blogunpublish',
			     	data: {id:id},
			     	success: function(data){
			     			$("#df"+id).attr('onclick',"blogpublished('"+id+"')").html('Publish');
			     			$("#df"+id).attr('id','rf'+id);
			     	}
		     	});
			}
		}
	</script>	
	

