// JavaScript Document
  var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
  var ie = (typeof window.ActiveXObject != 'undefined'); 
   var xmlDoc;



function displaySustainResult(startIndex)
{
// code for IE
if (window.ActiveXObject)
  {
  	 xmlDoc = new ActiveXObject( "MSXML2.DOMDocument.3.0" );
     xslDoc = new ActiveXObject( "MSXML2.FreeThreadedDOMDocument.3.0" );
     var xslTemplate = new ActiveXObject( "MSXML2.XSLTemplate.3.0" );

    //1. Load in the raw XML data:
    xmlDoc.async = "false";
    xmlDoc.load('/utc/xml/sustaining.xml' );

    //2. Load in the XSLT transform script:
    xslDoc.async = "false";
    xslDoc.load('/utc/xml/sustaining.xsl' );

    xslTemplate.stylesheet = xslDoc;
    xslProcessor = xslTemplate.createProcessor( );
    xslProcessor.input = xmlDoc;


    //3. Overwrite the xsl:params with runtime selected values:
    xslProcessor.addParameter( "startIndex", startIndex );

    //4. Output the XML (as processed by the XSLT) to the div target
    xslProcessor.transform();
    document.getElementById("sustainingExample").innerHTML= xslProcessor.output;
  }

// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
sourceXML = "/utc/xml/sustaining.xml";
sourceXSL = "/utc/xml/sustaining.xsl";
container = "sustainingExample";
  
//Load the XML
xmlhttpXSL = new XMLHttpRequest();
xmlhttpXSL.open("GET", sourceXSL, false);
xmlhttpXSL.setRequestHeader("Content-Type", "text/css")
xmlhttpXSL.send(null);
loadedStyle = xmlhttpXSL.responseXML;
xsl = xmlhttpXSL.responseXML;


//Load the XSL
xmlhttpXML = new XMLHttpRequest();
xmlhttpXML.open("GET", sourceXML, false);
xmlhttpXML.setRequestHeader("Content-Type", "text/xml")
xmlhttpXML.send(null);
var xmlDoc = xmlhttpXML.responseXML;
xml = xmlhttpXML.responseXML;
//Transform
var writeObj = document.getElementById(container);
var xsltProcessor = new XSLTProcessor();
//var xmls = new XMLSerializer();
xsltProcessor.importStylesheet(xsl);
xsltProcessor.setParameter(null, "startIndex",startIndex); // pass the parameter
 resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("sustainingExample").innerHTML="";
document.getElementById("sustainingExample").appendChild(resultDocument);


  
  }
}



function sustainingPagination()
{ 


//Load the XSL
sourceXML = "/utc/xml/sustaining.xml";
var xmlDoc = loadXMLDoc(sourceXML); //function loadXMLDoc exists in leadership.js file
var xml = loadXMLDoc(sourceXML); //function loadXMLDoc exists in leadership.js file


  var nodes;
  var pages;
  var remainder;
  // code for IE
  if (window.ActiveXObject)
  {
  	xmlObj=xmlDoc.documentElement;
	nodes = xmlObj.childNodes.length ;
  }
  
  else if (document.implementation && document.implementation.createDocument)
  {
   		nodes = xmlDoc.getElementsByTagName('root')[0].getElementsByTagName('item').length;
  }	
   if(nodes>5)
  {
    pages = nodes/5; 
	remainder = nodes % 5;
	pages = ( nodes - remainder ) / 5;
  }
  else
    pages = nodes;
        
//alert(pages);
  var innerhtml;
  if(pages>=1)
  {
	  gotosustainpage(1,nodes,pages);
  }
}

function gotosustainpage(page,nodes,pages)
{
	 var innerhtml="";
	
	  var pagesno = pages;
	 
	  if ((nodes % 5)>0)
	  {
		 pagesno+=1; 
	  }
	  
	  if(page>1)
	  	  innerhtml += '<input type="button" title="previous page" class="btn_moveup" value=" " onmouseover="this.className=\'btn_moveupHover\'" onmouseout="this.className=\'btn_moveup\';" onclick="javascript:gotosustainpage('+(page-1)+','+nodes+','+pages+')" />';
      else
	  	  innerhtml += "<img src='/utc/images/buttons/move_up_dimmed.gif' title='previous page' alt='previous page' />";
		
	  

	  
	  if(page<pagesno)
	  	  innerhtml += '<input type="button" title="next page" class="btn_movedn" value=" " onmouseover="this.className=\'btn_movednHover\'" onmouseout="this.className=\'btn_movedn\';" onclick="javascript:gotosustainpage('+(page+1)+','+nodes+','+pages+')" />';
		  
      else
	      innerhtml += "<img src='/utc/images/buttons/move_dn_dimmed.gif' title='next page' alt='next page' />";
		  
	    
	  document.getElementById('sustainingPagination').innerHTML =innerhtml;
		  
	  displaySustainResult(((page-1)*5)+1);	  
}




//////////////////////////////////////function loadXMLDoc exists in leadership.js file//////////////////////////
/*
function loadXMLDoc(fname)
{

// code for IE
if (window.ActiveXObject)
  {
	  
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load(fname)
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  
xmlhttpXML = new XMLHttpRequest();
xmlhttpXML.open("GET", fname, false);
xmlhttpXML.setRequestHeader("Content-Type", "text/xml")
xmlhttpXML.send(null);
xmlDoc = xmlhttpXML.responseXML; 
  }
else
  {
  alert('Your browser cannot handle this script');
  }
;
return(xmlDoc);
}
*/