function Report_Load_Draw() {
	report.pages=[];
	report.codePages=[];
	report.totalPages=0;

	report.draw={};
	report.draw.currentHeight=0;
	report.draw.currentWidth=0;
	report.draw.currentPage={};
	report.draw.styles='';
	report.draw.stylepair=false;
	
	report.ChangeOrientation=function(value) {
		report.orientation=value;
		if(value==0){
			report.draw.maxWidth=749;
			report.draw.maxHeight=1091;
			paper.style.width='827px';
			paper.style.height='1169px';
		}
		else{
			report.draw.maxWidth=1091;
			report.draw.maxHeight=749;
			paper.style.width='1169px';
			paper.style.height='827px';
		}
	}
	report.ChangeOrientation(report.orientation);
	
	report.draw.styles += 'td {vertical-align: middle; font-size: 9pt; }'+"\n";
	//report.draw.styles += 'td.values {white-space: nowrap; overflow: hidden; }'+"\n";
	report.draw.styles += 'div.arrow {width: 5px; height: 9px; margin: 2px 8px 0px 0px; background: url(design.images.png) no-repeat 0px -238px; float: left;}'+"\n";
	report.draw.styles += '*.space_break { }'+"\n";
	
	for(var i in report.styles){
		report.draw.styles += "*."+i+" { "+report.styles[i]+" }\n";
	}
	
	NewReportPage();
	for(var i in report.data) {
		ReportDraw_Row(report.data[i]);
	}
	ReportDraw_Foot();
	
	for(var i in report.pages) {
		ReportDraw_Page(i);
	}
	menu.reset();
	SetLoading(false);
}

function NewReportPage() {
	var page =new Array;
	report.pages.push(page);
	report.totalPages++;
	report.draw.currentHeight=0;
	ReportDraw_Header();
	return page;
}
function ReportDraw_Header() {
	for(var i in report.head) {
		ReportDraw_Row(report.head[i]);
	}
}
function ReportDraw_Row(row) {
	if(row.table!='@break') {
		var height = row.properties.height;
		
		//if(row.properties.border_top) { height++; }
		//if(row.properties.border_bottom) {
		//height++; }
	
		if((report.draw.currentHeight+height)>=report.draw.maxHeight) {
			ReportDraw_Foot();
			NewReportPage();
		}
	
		report.draw.currentWidth=0;
		for(var i in row.cells) {
			var cell=row.cells[i];

			if(row.table=="head_double" || row.table=="headers" || row.table=="values" || row.table=="checks"){
				var measure = MeasureRow(cell.value,cell.width);
				if(measure>row.properties.height){
					height=measure; 
				}
			}
			if(i==row.cells.length-1) {
				cell.width=report.draw.maxWidth-report.draw.currentWidth-cell.padding
				if(cell.border_left){ cell.width--; }
				if(cell.border_right){ cell.width--; }
			}
			else{
				report.draw.currentWidth+=cell.width+cell.padding;
				if(cell.border_left){ report.draw.currentWidth.width++; }
				if(cell.border_right){ report.draw.currentWidth++; }
			}
		}
	
		report.pages[report.pages.length-1].push(row);
		
		
		
		report.draw.currentHeight += height;
		report.lastTable=row.table;
	}
	else {
		ReportDraw_Foot();
	}
}
function ReportDraw_Foot() {
	if(report.lastTable!='@break') {
		var space = new ReportRow(report.tables['@space'],[],[]);
		space.cells[0].value='';
		space.cells[0].height=report.draw.maxHeight-report.draw.currentHeight;
		space.cells[0].width=report.draw.maxWidth;
	
		report.pages[report.pages.length-1].push(space);
	
		report.draw.currentHeight = report.draw.maxHeight;
		report.lastTable='@break';
	}
}

function ReportDraw_Page(number){
	var table_name=null;
	var table={};
	
	report.codePages[number]='';
	for(var i in report.pages[number]){
		var row = report.pages[number][i];
		if(row.table!=table_name) { ReportDraw_Table(number); table_name=row.table; }
		ReportDraw_Tr(number,row);
	}
}
function ReportDraw_Table(number){
	var code = report.codePages[number];
	if(code!='') { code += "</tbody>\n</table>\n"; }
	code += '<table style="width: '+report.draw.maxWidth+'px; border-width: 0;" border="0" cellpadding="0" cellspacing="0">';
	code += "<tbody>\n";
	report.codePages[number]=code;
	report.draw.stylepair=false;
}
function ReportDraw_Tr(number,row){
	report.draw.currentWidth=0;
	report.codePages[number] += "<tr>\n";
	for(var i in row.cells){
		ReportDraw_Td(number,row.cells[i]);
	}
	report.codePages[number] += "</tr>\n";
	report.draw.stylepair=!report.draw.stylepair;
}
function ReportDraw_Td(number,cell){
	var code = '';
	var style = '';
	
	code += '<td';
	code += ' class="'+cell.style;

	if(report.draw.stylepair) { code += ' pair'; }
	code += '"';
	style += 'width: '+cell.width+'px;';
	style += 'height: '+cell.height+'px;';
	style += 'padding-left: '+cell.padding+'px;';
	style += 'text-align: '+cell.align+';';
	if(cell.border_top) { style += 'border-top: 1px '+cell.border_style+' '+cell.border_color+';'; }
	if(cell.border_bottom) {
		style += 'border-bottom: 1px '+cell.border_style+' '
		if(cell.border_bottom_color=='#000'){ style += cell.border_color+';'; }
		else{ style += cell.border_bottom_color+';'; }
		
		}
	if(cell.border_left) { style += 'border-left: 1px '+cell.border_style+' '+cell.border_color+';'; }
	if(cell.border_right) { style += 'border-right: 1px '+cell.border_style+' '+cell.border_color+';'; }
	style 
	code += ' style="'+style+'"';
	code +=	">\n";
	code += cell.value+"\n";
	code += "</td>\n";
	
	report.codePages[number] += code;
}
include('control.load.js');