function MultiPageContent(instanceName,HTMLcontent,TAGseparator) {

	// properties
	this.totPages		= 0;			// totale pages
	this.page			= 0;			// displayed page
	this.content		= ""; 			// HTML content
	this.separator		= "";			// string that is used to split the pages
	this.instanceName	= "";			// instance name of the DIV that will be created
	this.loop			= true;			// Loop when at the end of the totalpages and click NEXT or at first page and click BACK

	// ******* setting methods *******************
	this.setPage = function(pageNum) {
		var reg = new RegExp ("^[0-9]+$")
		if (reg.test(pageNum)) this.page = parseInt(pageNum);
	}
	
	this.setContent = function(content){
		if (content != "" && content != undefined && content != null) this.content = content;
	}
	
	this.setSeparator = function(separator){
		if (separator != "" && separator != undefined && separator != null) this.separator = separator;
	}
	
	this.setInstanceName = function(name){
		// if no instance name is passed, it is generated random
		this.instanceName = (name != "" && name != undefined && name != null) ? name : "_MPC_" + Math.random();
	}
	
	// ******************** getting methods *****************************
	
	this.getInstanceName = function(){
		return this.instanceName;
	}
		
	this.getContent = function(){
		return this.content;
	}

	this.getTotalPages = function(){
		return this.totPages;
	}
	
	this.getPage = function(){
		return this.page;
	}
	
	// ************ DOM Methods	********************************
	this.getAllChildren = function(){
		obj = document.getElementById(this.getInstanceName() )
		children = new Array();
		for (var i = 0;i<obj.childNodes.length;i++)
		if(obj.childNodes[i].nodeType == 1) children.push(obj.childNodes[i]) 
		
		return children;
	}
			
	this.getPageNode = function (pageNum){
		children = this.getAllChildren();
		return (children.length >= pageNum) ? children[pageNum-1] : null;
	}
	
	this.appendPages = function(toElement){
		contenuto 		= this.getContent();
		splittedContent = contenuto.split(this.separator);
		
		if (toElement.nodeType == 1) {
			// foreach "page" I create a new DIV
			for(var i=0;i<splittedContent.length; i++) {
				pageDiv = document.createElement("DIV");
				pageDiv.style.display = "none";
				pageDiv.innerHTML = splittedContent[i];
				
				toElement.appendChild(pageDiv)
			}
		}
	}
	
	// ************** application methods ****************************
	
	this.splitContent = function(){

		splittedContent = this.content.split(this.separator);
		this.totPages = splittedContent.length;
	}
	
	// ************** Drawing methods ****************************
	
	this.hidePage = function(pageNum){
		var success = true;
		var reg = new RegExp ("^[0-9]+$")
		
		if (reg.test(pageNum) && pageNum <= this.getTotalPages()) {
			pageNode = this.getPageNode(pageNum);
			
			if (pageNode != null) pageNode.style.display = "none";
			else success = false;
			
		}
		else success = false;
		
		return success;
	}	
	
	this.showPage = function(pageNum){
		var success = true;
		var reg = new RegExp ("^[1-9]{1}[0-9]*$")

		if (reg.test(pageNum) && pageNum <= this.getTotalPages()) {
			pageNode = this.getPageNode(pageNum);
			if (pageNode != null) {
				this.setPage(pageNum);
				pageNode.style.display = "block";
				// if an "onchange" event has been defined, I call it
				if(this.onChange) this.onChange();
			} else success = false;
			
		}
		else success = false;
		
		return success;
	}
	
	this.debug = function(){
		parentElement = document.getElementById(this.getInstanceName());
		if (parentElement != null) {
			debgugArea = document.createElement("TEXTAREA");
			parentElement.appendChild(debgugArea);
			this.appendPages(debgugArea);
		}
	}

	this.draw = function(showFirstPage){
		// append element to the instance name Object
		this.appendPages(document.getElementById(this.getInstanceName()));
		if (showFirstPage != false) this.showPage(1);
	}

	this.innerDraw = function(element,html){
		if (element.nodeType == 1) element.innerHTML = html;
	}

	this.drawCurrentPage = function(elementID){
		this.innerDraw(document.getElementById(elementID),this.getPage());
	}
	
	this.drawTotalPages = function(elementID){
		this.innerDraw(document.getElementById(elementID),this.getTotalPages());
	}
	
	// ***************** controller methods ******************************
	this.back = function() {
		page = this.getPage();
		
		if (page > 1) {
			this.hidePage(page);
			this.showPage(page-1);
		}
		else if(this.loop) {
			this.hidePage(page);
			this.showPage(this.getTotalPages());
		}
	}
	
	this.next = function() {
		page = this.getPage();
		
		if (page < this.getTotalPages()) {
			this.hidePage(page);
			this.showPage(page+1);
		}
		else if(this.loop) {
			this.hidePage(page);
			this.showPage(1);
		}
	}
	
	this.jumpTo = function(pageNum) {
		if (pageNum > 0 && pageNum <= this.getTotalPages()) {
			this.hidePage(this.getPage());
			this.showPage(pageNum)
		}
	}
	
	// ***************** INIT METHOD (constructor) ***********************
	
	this.init = function(instanceName,HTMLcontent,TAGseparator){
		this.setInstanceName(instanceName);
		this.setContent(HTMLcontent);
		this.setSeparator(TAGseparator);
		this.splitContent();
	}
	
	// init 
	this.init(instanceName,HTMLcontent,TAGseparator);
}
