I4Portal.Report = function(contentDiv,langId) {
	
	this.contentDiv=contentDiv;
	this.jContentDiv = "#"+contentDiv;
	this.langId=langId;

	this.getDistrictsUrl = "CMSPortal/reports/get_districts.php";
	this.getDistrictDetailUrl = "CMSPortal/reports/district_detail.php";
	this.getBlocksUrl = "CMSPortal/reports/get_block_control.php";
	this.getPeriodsUrl = "CMSPortal/reports/get_report_periods.php";
	this.getBlockReportsUrl = "CMSPortal/reports/get_block_reports.php";
	
	this.selDistrictId=0;
	this.selBlockReportTypeId = 0;
	this.selBlockId = 0;
	this.selPeriodId=0;
	
};


I4Portal.Report.prototype = {
		
	initialize:function(){

		var t=this;
		$(this.jContentDiv).load(t.getDistrictsUrl,
								function(){ t.onLoadDistricts();   }
		);
	
	
    },
    
    onLoadDistricts:function(){
    	
    		var t=this;
    		 t.selDistrictId=0;
    		$('#formi_district').change(function() {
    			  t.selDistrictId=$(this).val();
    			
    			  if(t.selDistrictId >0){
    				  t.getDistrictDetails(t.selDistrictId);
    			  }
    		});
    	
    },
    
    getDistrictDetails:function(districtId){
    	  var t=this;
    	  $('#report_dist_result').load(t.getDistrictDetailUrl, { 'district_id' : districtId },
					function(){ t.onLoadDistrictDetail(districtId);   }
    	  );
    	  
    	 

    
    },
    
    onLoadDistrictDetail:function(districtId){
    	// alert('district reports displayed');
    	 var t=this;
    	 $('#report_block_select').load(t.getBlocksUrl, { 'district_id' : districtId },
					function(){ t.onLoadBlockControlDetail();   }
 	  );
    	
    },
    
    
    onLoadBlockControlDetail:function(){
    	var t = this;
    	this.selBlockReportTypeId = 0;
    	this.selBlockId = 0;
    	this.selPeriodId=0;
    	
    	$('#formi_block').change(function() {
    		t.selBlockId =$(this).val();
		});
	
    	
    	$('#formi_rtype').change(function() {
    		t.selBlockReportTypeId =$(this).val();
			
			  if(t.selBlockReportTypeId >0){
				  $('#periodcontrol').load(t.getPeriodsUrl, { 'report_type_id' : t.selBlockReportTypeId },
							function(){ t.onLoadPeriods();   }
				  );
			  }
		});
	
    	
    	
    },
    
    
    onLoadPeriods:function(){
    	var t=this;
    	
    	$('#formi_rperiod').change(function() {
    		t.selPeriodId =$(this).val();
		});
	
    	
    	$('#report_submit_btn').click(function(){
    		
    		$('#report_block_detail').load(t.getBlockReportsUrl , 
    				{ 'report_type_id' : t.selBlockReportTypeId,
    				  'block_id': t.selBlockId ,
    				  'period_id' : t.selPeriodId,
    				  'district_id' : t.selDistrictId},
					function(){ t.onLoadBlockReports();   }
			  );
    		
    		//html('<p> No Reports Found </p>');
    		
    	});
    	
    	
    },
    
    onLoadBlockReports:function(){
    	
    	
    }
    
    
    
    
		
		
		
		
}
