start=0;end=count-1;NodesLen=0;
function GetContent(CONTENT_DIV,API_TOTAL_RECS){
	if(!API_TOTAL_RECS){API_TOTAL_RECS='50'}
	jsonReq = new ecnext.JsonService({uri:API_URI});
	var dResult = jsonReq.sendMessage({msg:{action:API_ACTION,maxRows:API_TOTAL_RECS}});
	obj=GetObj(CONTENT_DIV+'ALL');
	dResult.addCallback(function(result) {
		obj.innerHTML=result.html;
		CopyContent(); // Copy records A->B 
		return result;
	});
	dResult.addErrback(function(error) {
		//alert("There was an error retrieving the Company Q&A data.");
		return error;
	});
}
function CopyContent(start,end){
	if(!start){start=0;end=count-1}
	NodesLen=0;
	Content=GetObj(CONTENT_DIV); // Only START - END records
	ContentALL=GetObj(CONTENT_DIV+'ALL'); // All records from API request
	Container=GetObj(CONTENT_DIV+'Container');
	if(ContentALL.innerHTML!=""){
		Content.innerHTML=""; // clear target
		if(ContentALL.childNodes){ // content exists
			NodesLen=ContentALL.childNodes.length;
			for (x=start; x <= end; x++){
				if (x < ContentALL.childNodes.length) {
					var node = ContentALL.childNodes[x];
					if (node && "nodeType" in node && node.nodeType == 1) {
						c = node.innerHTML
						newNode=document.createElement('div');
						if (x==end){d=c.replace(/Line/gi,"hide");c=d;} //last line
						newNode.innerHTML=c
						Content.appendChild(newNode)
					}
				}
			}
			if(Container){show(CONTENT_DIV+'Container')}
		}
	}
}
function PageContent(PrevNext){
	if (PrevNext=='prev'){show('NEXT');
		start=start-count; end=start+count-1;
		if (start <= 0){start=0;end=count-1;hide('PREV')}
	}	else if (PrevNext=='next'){show('PREV');
		start=start+count; end=end+count
		if (end >= NodesLen-1){end=NodesLen-1;hide('NEXT')}
	}
	CopyContent(start,end)
}
dojo.addOnLoad( function(){GetContent(CONTENT_DIV,API_TOTAL_RECS)} );
