/**
 * libarary that contains the news load based on the sarissa library for xml rendering on client side
 * @Author: Nandagopal R
*/
// global function that will store the values of xml, xsl and test
var sXmlFileGlobal, sXslFileGlobal, sDisplayIdGlobal;
// sarissa documents
// create source document
var xmlDoc = Sarissa.getDomDocument();
// create stylesheet
var xslDoc = Sarissa.getDomDocument();
// function that will load the news
function GetNews(sXmlFile, sXslFile, sDisplayId){
	// set the global variables
	sXmlFileGlobal = sXmlFile;
	sXslFileGlobal = sXslFile;
	sDisplayIdGlobal = sDisplayId;
	// load the xml document synchronously
	xmlDoc.async = false;
	// load the xml document
	xmlDoc.load(sXmlFileGlobal);
	// load the xsl document synchronously
	xslDoc.async = false;
	// load stylesheet
	xslDoc.load(sXslFileGlobal);
	// finally load the news
	LoadNews();
}
// function that will load the news
function LoadNews(){
	// set the page number for the news
	var fSetParam = Sarissa.setXslParameter(xslDoc, "sPageNumber", getFormElementValue('frmPageNumber', 'pageNumber'));
	// xslt processor object
	var xsltProcessor = new XSLTProcessor();
	// get the processor loaded with XSLT
	xsltProcessor.importStylesheet(xslDoc);
	// store the transformation result to a new document
	var newDocument = xsltProcessor.transformToDocument(xmlDoc);
	// render the html
	document.getElementById(sDisplayIdGlobal).innerHTML = newDocument.xml;
}

// function that will navigate the news pages
function NavigateNews(sDirection){
	// if clicked on prev then decrease the page number
	if(sDirection == 'prev'){
		// increase the page number by one for the click to the next page
		setFormElementValue('frmPageNumber', 'pageNumber', (parseInt(getFormElementValue('frmPageNumber', 'pageNumber'), 10) - 1));
	} else{
		// increase the page number by one for the click to the next page
		setFormElementValue('frmPageNumber', 'pageNumber', (parseInt(getFormElementValue('frmPageNumber', 'pageNumber'), 10) + 1));
	}
	// call the function to reload the news
	LoadNews();
}
//EOF
