function Report_Init() {
	report = {};

	report.styles = {};
	report.tables = {};
	report.data = [];
	report.head = [];
	report.lastTable={};
	report.ajaxs=[];
	report.orientation=0;
	
	report.AddTable = function(name,values) {
		report.tables[name] = new ReportTable(name,values);
	}
	report.Add = function(table_name, values, styles){
		var table = report.tables[table_name];
		report.lastTable=table_name;
		var row = {};
		
		if(table!=null) {
			var row = new ReportRow(table,values,styles);
			switch(report.currentSection){
				case 'head':
					report.head.push(row);
					break;
				default:
					report.data.push(row);
					break;
			}
		}
		return row;
	}
	report.AddStyle= function(name,style) {
		report.styles[name] = style;
	}
	report.SetSection=function(value) {
		report.currentSection=value;
	}
	report.AddSpace=function(height,table){
		var table_name='@space';
		if(typeof(table)=="undefined") { table=false; }
		if(table==true) { table_name=report.lastTable; }
		else if(table==false ) { table_name='@space'; }
		else { table_name=table; }
		var row = report.Add(table_name);
		row.properties.height=height;
		for(var i in row.cells){
			row.cells[i].height=height;
			row.cells[i].value='';
		}
		return row;
	}
	
	report.AddTable('@space',{padding:0,className:'space_break'});
	report.tables['@space'].Add();
	report.AddTable('@break',{padding:0,className:'space_break'});
	report.tables['@break'].Add();
}
function ReportTable(name,values) {
	var table = {};
//Properties
	table.name = name;
	table.columns = [];
	table.properties = {};
	if(typeof(values)=="undefined") { values=[]; }
//Sets
	if(typeof(values)!="undefined")	{
		for(var i in ReportColumnProperties){
			if(typeof(values[i])!="undefined") { table.properties[i] = values[i]; }
			else{table.properties[i]=ReportColumnProperties[i]}
		}
	}
//Functions
	table.Add = function(values){
		var column={};
		column.properties={};
		if(typeof(values)=="undefined") { values=[]; }
		for(var i in this.properties) {
			if(typeof(values[i])!="undefined") { column.properties[i] = values[i]; }
			else{ column.properties[i]=this.properties[i]; }
		}
		this.columns.push(column);
	}
	return table;
}

function ReportRow(table,values,styles) {
	var row={};
	row.table=table.name;
	row.properties={};
	row.cells=[];
	for(var i in table.properties) {
		row.properties[i]=table.properties[i];
	}
	if(typeof(values)=="undefined") { values=[]; }
	if(typeof(styles)=="undefined") { styles=[]; } 
	for(var i in table.columns){
		var cell={};
		if(typeof(values[i])!="undefined") { cell.value=values[i].toString(); }
		else { cell.value='&nbsp'; }
		if(cell.value=='') { cell.value='&nbsp;'; } 
		//
		var column = table.columns[i];
		cell.width = column.properties.width;
		cell.height = row.properties.height;
		cell.visible = column.properties.width;
		cell.border_top = row.properties.border_top;
		cell.border_bottom = row.properties.border_bottom;
		cell.border_left = column.properties.border_left;
		cell.border_right = column.properties.border_right;
		cell.border_color = column.properties.border_color;
		cell.border_bottom_color = column.properties.border_bottom_color;
		cell.border_style = column.properties.border_style;
		cell.style = column.properties.className;
		cell.padding = column.properties.padding;
		cell.align = column.properties.align;
		
		if(typeof(styles[i])!="undefined") { cell.style=styles[i]; }
		cell.width-=cell.padding;	
		if(cell.border_left){ cell.width--; }
		if(cell.border_right){ cell.width--; }
		if(cell.border_top){ cell.height--; }
		if(cell.border_bottom){ cell.height--; }
		
		
		row.cells.push(cell);
	}
	return row;
}

var ReportColumnProperties={ width: 150, height: 22, visible: true, padding: 10, className: '', align: 'left',
						border_top: false, border_left: false, border_bottom: false, border_right: false, border_color: '#000', border_bottom_color: '#000', border_style: 'solid'};
include('control.draw.js');