// kid, kname, kdesc, kdate,kduration,kbound,kobj
var excelReportingRow = new Entity(excelReportingRow,true, [ 
	[zipAlt1], [zipCount1], 0,0,[zipCount2],1,2,3,6,5]); 
var excelReporting = new Entity(excelReporting,false, ["title.draw(['excel reporting']);","(getSize())[1]/2;",0,1,[excelReportingRow]]);
excelReporting.refresh = function() {
	$.ajax({
		data: {q:"getSchList", d: $("#staffing").val()}, 
		success:function(data,textStatus) {
			if ( ! data ) return;		
			try {
				var dir = $('#direction').val();
				zipCount1.reset();
				zipCount2.reset();
				excelReportingRow.set(data);
				updateFormNumCB = data.length;				
				$('#rightside').html(excelReporting.draw([dir==1 || dir =='1' ? "Duration" : "Value", dir==1 || dir =='1' ? "Lower Bound" : "Upper Bound"]));
				var scr = 	["None", "Number", "CaseInsensitiveString"]; 
				var st1 = new SortableTable($("#excelReportingList").get(0), scr);
			} catch (e) {
				myCatch(e);
			} 
		}
	});
}

excelReportingRow.go = function() {
	var action = $("#action").val(); 
	var ids="";
	var selected=-1;
	try { 
		for (var i=0; i < this.numRows; i++){
			if ($("#checkBox_"+i).attr('checked')){
				if ( ids.length > 0 ) ids +=",";
				ids += $("#checkBox_"+i).val();
				if (selected == -1) selected  = i;
				if ( action == 'gantt' || action == 'ganttv') break;
			}
		}
    
		if ( ids.length == 0 ) {
			throw "You must select something!";
		}
    
		if  (action == 'delete') {
			if ( ! confirm("Do you really want to delete these items?")) {
				return;
			}
			$.ajax({
				data: {q:'deleteSchedule', d: ids},
				success: function(data, textStatus) {
					if ( ! data ) return;
					try {
						rightsideDraw();
					} catch (e) {
						myCatch(e);
					}					
				}
			});
		} else if (action == 'gantt' || action == 'schedule'){ // export
			var fileName =  $("#newName").val();
			var startDate = $('#startDate').val();
			if ( ! fileName ){ 
				fileName = action+'_'+ ids;				
			}
			if ( action == 'gantt' ) {
				if ( ! startDate){
					throw "Please specify the start date";
				}
				var d = Date.parse(startDate);
				if ( isNaN(d)) {
					throw 'Invalide date';					
				} 
			}
			$('#reporttype').val(action);
			$('#filename').val(fileName);
			$('#scheduleIds').val(ids); 
         var tmp = $('#staffing').val();
    		$('#staffingid').val(tmp);
         document.post_form.submit();
		} else { // ganttv
			$('#scheduleIds').val(ids);
			gantt.refresh();
		}
	} catch(e) {
		myCatch(e);
	}
}	
	

