// Enter here the last page number of this report
var LastPageOfReport = 364;

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); 
  if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function CurrentPageNumber() {
	return parseInt(location.pathname.substr(location.pathname.length-7,3),10);
}

function ChapterSelected(lo,hi,idp) {
	if ((CurrentPageNumber() >= lo) && (CurrentPageNumber() <= hi)) {
		return(' selected');
	} else {
		return('');
	}
}

function ShowChapterJumpMenu(idp) {
	document.write ('<select class="field" name="ChapterJumpMenu" onChange="MM_jumpMenu(\'parent\',this,1)">');
	document.write ('<option value="index.htm">Table of contents</option>');
	// Set the values in the call to ChapterSelected as the first and last web page numbers of the chapter.
	// Set the option value to the first web page of the chapter.
	document.write ('<option' + ChapterSelected(500,500,idp) + ' value="index.php?idp=500">Foreword</option>');
	document.write ('<option' + ChapterSelected(501,501,idp) + ' value="index.php?idp=501">Preface</option>');
	document.write ('<option' + ChapterSelected(1,8,idp) + ' value="index.php?idp=1">Summary for Policymakers</option>');
	document.write ('<option' + ChapterSelected(9,22,idp) + ' value="index.php?idp=9">Technical Summary</option>');
	document.write ('<option' + ChapterSelected(23,33,idp) + ' value="index.php?idp=23">Chapter 1. Background and Overview</option>');
	document.write ('<option' + ChapterSelected(34,48,idp) + ' value="index.php?idp=34">Chapter 2. An Overview of the Scenario Literature</option>');
	document.write ('<option' + ChapterSelected(49,88,idp) + ' value="index.php?idp=49">Chapter 3. Scenario Driving Forces</option>');
	document.write ('<option' + ChapterSelected(89,113,idp) + ' value="index.php?idp=89">Chapter 4. An Overview of Scenarios</option>');
	document.write ('<option' + ChapterSelected(114,130,idp) + ' value="index.php?idp=114">Chapter 5. Emission Scenarios</option>');
	document.write ('<option' + ChapterSelected(131,144,idp) + ' value="index.php?idp=131">Chapter 6. Summary Discussions and Recommendations</option>');
	document.write ('<option' + ChapterSelected(145,145,idp) + ' value="index.php?idp=145">Appendices index</option>');
	document.write ('<option' + ChapterSelected(146,146,idp) + ' value="index.php?idp=146">Appendix I</option>');
	document.write ('<option' + ChapterSelected(147,148,idp) + ' value="index.php?idp=147">Appendix II</option>');
	document.write ('<option' + ChapterSelected(149,149,idp) + ' value="index.php?idp=149">Appendix III</option>');
	document.write ('<option' + ChapterSelected(150,155,idp) + ' value="index.php?idp=150">Appendix IV</option>');
	document.write ('<option' + ChapterSelected(156,157,idp) + ' value="index.php?idp=156">Appendix V</option>');
	document.write ('<option' + ChapterSelected(158,163,idp) + ' value="index.php?idp=158">Appendix VI</option>');
	document.write ('<option' + ChapterSelected(164,164,idp) + ' value="index.php?idp=164">Appendix VII</option>');
	document.write ('<option' + ChapterSelected(165,165,idp) + ' value="index.php?idp=165">Appendix VIII</option>');
	document.write ('<option' + ChapterSelected(166,166,idp) + ' value="index.php?idp=166">Appendix IX</option>');
	document.write ('<option' + ChapterSelected(167,167,idp) + ' value="index.php?idp=167">Appendix X</option>');
	document.write ('<option' + ChapterSelected(168,168,idp) + ' value="index.php?idp=168">Appendix XI</option>');
	document.write ('<option' + ChapterSelected(169,169,idp) + ' value="index.php?idp=169">Appendix XII</option>');

	document.write ('</select> ');
	//document.write ('<input type="button" class="field" name="Button1" value="Go" onClick="alert((\'under construction\')">');
	//document.write ('<input type="button" class="field" name="Button1" value="Go" onClick="MM_jumpMenuGo(\'ChapterJumpMenu\',\'parent\',1)">');
}

function PrevNext(p_idp, p_lastpage) {
	var prevPage, nextPage;
	idp=parseInt(p_idp);
	lastpage=parseInt(p_lastpage);
	
	//if (isNaN(CurrentPageNumber())) { 
	if (isNaN(idp)) { 
		document.write('Table of contents | <a href="index.php?idp=1" target="_top">Next page</a>');
		//document.write('Table of contents | <a href="001.htm">Next page</a>');
	} else {
		//if (CurrentPageNumber() == 1) { 
		if (idp == 1) { 
		//if (idp == 0) {
			//prevPage= -1; 
			prevPage= -1; 
			//prevPage='index';
		} else { 
			//prevPage=CurrentPageNumber() - 1; 
			 prevPage=idp - 1; 
			 //prevPage=idp - 2; 
			 if (prevPage > 169 && prevPage < 502) prevPage = prevPage - 330;
		}
		/*
		if (prevPage < 10) { prevPage = '0' + prevPage; }
		if (prevPage < 100) { prevPage = '0' + prevPage; }
		if (prevPage == 002) { prevPage = '530'; }
		if (prevPage == 499){ prevPage = '002' ; }
		*/
		if (prevPage >= 0) {
			document.write('<a href="index.php?idp=0" target="_top">Table of contents</a> | <a href=index.php?idp=' + prevPage + '>Previous page</a>');
		}
		//document.write('<a href="index.htm">Table of contents</a> | <a href=' + prevPage + '.htm>Previous page</a>');
		if (idp != lastpage) {
		//if (CurrentPageNumber() != LastPageOfReport) {
			//nextPage = CurrentPageNumber() + 1;
			nextPage = idp + 1;
			/*
			if (nextPage < 10) { nextPage = '0' + nextPage; }
			if (nextPage < 100){ nextPage = '0' + nextPage; }
			if (nextPage == 003) { nextPage = '500'; }
			if (nextPage == 501) { prevPage = '002'; }
			if (prevPage == 529) { nextPage = '003'; }
			*/
			if (nextPage > 169 && nextPage < 502) nextPage=nextPage+330;
			document.write(' | <a href=index.php?idp=' + nextPage + '>Next page</a>');
			//document.write(' | <a href=' + nextPage + '.htm>Next page</a>');
		} else { 
			//if (CurrentPageNumber() == LastPageOfReport){
			if (idp == lastpage){
			document.write(' | End of report');}
		}
	}
}

function showFootnote (chapter,name) {
	theURL = 'fn' + chapter + '.htm#' + name;
	window.open(theURL,'references_win','width=350,height=200,scrollbars,resizable'); 
}
