//Cache for the loaded pages
HTMLPAGE = new Array();

function loadHtmlPage(page) {

	//Save current content to history and save current action
	saveHistory();
	saveCurrentAction({'action':'htmlpage', 'page':page});

	if (!isDefined(HTMLPAGE[page])) {
	var data;
	//Start session and load page
		$.get(
			SCRIPTURL + 'html.json?xpdato=' + $.cookie("xpdato") + '&xpwlnr=' + $.cookie("xpwlnr") + '&page=' + page + '&callback=?',
			data,
			function(data) {

				//save loaded data on cache
				HTMLPAGE[page] = buildHtmlPageContent(data, page);

				//and show content
				showContent(HTMLPAGE[page]);
			},
			'text/html'
		);
	}
	else {
		//If it is already loaded, build the table and update
		showContent(HTMLPAGE[page]);
	}
}


function buildHtmlPageContent(data, pagename) {
	//build buttonBox
	var buttonBox = buildButtonBox(data, true);

	return buttonBox + '\
		<div id="' + pagename + '" class="box2">\
			' + data + '\
		</div>\
		' + buttonBox;
}

