var caption_indexes      = new Array();

var timecodes = new Array();
timecodes[0] = 0;
timecodes[1] = 89000;
timecodes[2] = 347000;
timecodes[3] = 425000;
timecodes[4] = 472000;
timecodes[5] = 482000;
timecodes[6] = 532000;
timecodes[7] = 909000;
timecodes[8] = 927000;
timecodes[9] = 938000;
timecodes[10] = 971000;
timecodes[11] = 1050000;
timecodes[12] = 1061000;
timecodes[13] = 1092000;
timecodes[14] = 1096000;
timecodes[15] = 1103000;
timecodes[16] = 1121000;
timecodes[17] = 1184000;
timecodes[18] = 1199000;
timecodes[19] = 1236000;
timecodes[20] = 1255000;
timecodes[21] = 1365000;
timecodes[22] = 1518000;
timecodes[23] = 1698000;
timecodes[24] = 1751000;
timecodes[25] = 1764000;
timecodes[26] = 1863000;
timecodes[27] = 1896000;
timecodes[28] = 1978000;
timecodes[29] = 2029000;
timecodes[30] = 2035000;
timecodes[31] = 2041000;
timecodes[32] = 2052000;
timecodes[33] = 2070000;
timecodes[34] = 2075000;
timecodes[35] = 2089000;
timecodes[36] = 2097000;
timecodes[37] = 2111000;
timecodes[38] = 2123000;
timecodes[39] = 2142000;
timecodes[40] = 2157000;
timecodes[41] = 2211000;
timecodes[42] = 2238000;
timecodes[43] = 2294000;
timecodes[44] = 2307000;
timecodes[45] = 2332000;
timecodes[46] = 2345000;
timecodes[47] = 2396000;
timecodes[48] = 2634000;
timecodes[49] = 2650000;
timecodes[50] = 2718000;
timecodes[51] = 2850000;
timecodes[52] = 2943000;
timecodes[53] = 2995000;
timecodes[54] = 3065000;
timecodes[55] = 3134000;
timecodes[56] = 3164000;
timecodes[57] = 3206000;
timecodes[58] = 3253000;
timecodes[59] = 3388000;
timecodes[60] = 3452000;


var captions = new Array();
captions[0] = "Population, Poverty, and Economic Development|";
captions[1] = "Population, poverty and economic development|";
captions[2] = "Debates about the relationship between high fertility/RPG and economic development/poverty|";
captions[3] = "Broad consensus today that rising prosperity yields lower fertility and declining population growth rate|";
captions[4] = "What do we know – macro?|";
captions[5] = "Malthus vs Marx|";
captions[6] = "3 stages of thinking in the modern era|";
captions[7] = "The importance of age structure|";
captions[8] = "What do we know – micro?|";
captions[9] = "Micro studies are fewer because good data are hard and expensive to collect : longitudinal household information But recent research using longitudinal household data (Canning & Schofield, Schultz & Joshi) strongly suggests that high fertility places se|";
captions[10] = "What do we know - micro?|";
captions[11] = "Population growth, high fertility and the MDGs|";
captions[12] = "Figure 1|";
captions[13] = "Trends and prospects|";
captions[14] = "Percentage living on less than $1/day|";
captions[15] = "Poverty decline in Asia|";
captions[16] = "World Bank|";
captions[17] = "Africa|";
captions[18] = "Conclusion|";
captions[19] = "Sola schola et sanitate: Human Capital as the Root Cause and Priority for International Development?Wolfgang LutzWorld Population Program,  IIASA (Int. Institute for Applied Systems Analysis)Vienna Institute of Demography (VID), Austrian Academy o|";
captions[20] = "Why a Latin motto and what does it mean?|";
captions[21] = "International Development Policy is in a State of Confusion|";
captions[22] = "Hypothesis: Human capital is the root cause of international development|";
captions[23] = "Mortality under age 5 by mothers’ education (Source: DHS)|";
captions[24] = "Total Fertility Rates by Level of Education|";
captions[25] = "Population by Age, Sex, and Educational Attainment in Republic of Korea, 2000|";
captions[26] = "Population by Age, Sex, and Educational Attainment in Republic of Korea, 1970|";
captions[27] = "Advantages of this reconstructed data set over other existing ones|";
captions[28] = "Human Capital vs. Process of Education|";
captions[29] = "Principles of Population Projection by age, sex, and education|";
captions[30] = "World Population by Age, Sex and Educational Attainment in 1970|";
captions[31] = "World Population by Age, Sex and Educational Attainment in 2010|";
captions[32] = "World Population by Age, Sex and Educational Attainment in 2050|";
captions[33] = "Alternative Education Scenarios to 2050|";
captions[34] = "Kenya 2000|";
captions[35] = "Kenya 1970|";
captions[36] = "Kenya 2050 – Fast Track Scenario|";
captions[37] = "Kenya 2050 – Global Education Trend|";
captions[38] = "Kenya 2050 – Constant Enrollment Rates|";
captions[39] = "Kenya 2050 – Constant Absolute Enrollment Numbers|";
captions[40] = "Lessons|";
captions[41] = "The changing human capital distribution in the world|";
captions[42] = "Based on the new IIASA-VID Educational Attainment data set for 120 countries for 1970-2000 previous (inconclusive) economic growth regressions could be re-estimated and finally showed consistently significant positive effects of improving educational atta|";
captions[43] = "Education and Democracy|";
captions[44] = "Systems ModelsMulti-sectoral computer models with systems of non-linear equations and feed-backs trying to capture real world interactions as comprehensively as possible are the best way for testing which factors are primary drivers and which are interme|";
captions[45] = "National Success Stories|";
captions[46] = "Alfred Sauvy, 1958 book“ Fertility and Survival: Population Problems from Malthus to Mao Tse-tung”|";
captions[47] = "Conclusions|";
captions[48] = "CommentPopulation and PovertyHuman Capital|";
captions[49] = "Population Crowding|";
captions[50] = "Components of Population Growth|";
captions[51] = "Mortality ReductionsHealth to Wealth: Mechanisms|";
captions[52] = "Health and Saving|";
captions[53] = "The role of fertility|";
captions[54] = "Fertility and steady state working age share (theory)|";
captions[55] = "Total fertility rates and working age shares in 2000|";
captions[56] = "Sub-Saharan Africa’s population|";
captions[57] = "East Asia’s Population|";
captions[58] = "Population and Poverty|";
captions[59] = "Human Capital|";
captions[60] = "Discussion|";


function create_caption_indexes()
{
	var i;
	var running_total=0;
	caption_indexes[0]=running_total;
	for(i=1; i <= captions.length; i++)
	{
		running_total = running_total + captions[i-1].length + 1;
		caption_indexes[i]=running_total;
	}
	return running_total;
}
function find_instances2(search_term) {
  var caption;
  var new_search_term;
  var regular_expression;  
  var s1='';     
  
  s1="<html><head>"; 
  s1=s1+"<link rel=\"stylesheet\" type=\"text/css\" href=\"default.css\">";
  s1=s1+"<script src=\"search.js\"></script></head>";   
  s1=s1+"<body>";
  s1=s1+"<div id=\"search\"><form name=\"form1\" onSubmit=\"find_instances2(document.form1.searchme.value);return false;\">"; 
  s1=s1+"<span style='font-family:Helvetica,Arial;font-size:11px;font-weight:bold;'>Search slide notes and transcript:</span><br/>";
  s1=s1+"<input type=\"text\" size=\"25\" name=\"searchme\" value=\"\">"; 
  s1=s1+"<a href=\"#\" onClick=\"find_instances2(document.form1.searchme.value);return false;\"><img src=\"search.gif\" border=\"0\" alt=\"Search\"></a>"; 
  s1=s1+"</form></div>";   
  s1=s1+"<span style='font-family:Helvetica,Arial;font-size:11px;font-weight:bold;'>";
  s1=s1+'<hr width="100%"/>\n';
  s1=s1+"Search results for: \"" + search_term.toUpperCase() + "\"";

  s1=s1+'<hr width="100%"/>\n';
  //CHECK THE SEARCH TERM TO MAKE SURE IT IS LEGIT--STRIP OUT FINAL *, BAD PUNCTUATION, ETC.
  if (search_term.length > 0) {
    new_search_term = filter_search_term(search_term);
    regular_expression = new RegExp(new_search_term, "gi");

    for(i = 0; i < captions.length; ++i) {
      caption = captions[i];
      if (regular_expression.test(caption)) {
        href = make_href(i, caption);
        s1=s1+href + "<br>\n";
      }
    }
  }
  //s1=s1+"<br><br>End of search results";
  s1=s1+"</span></body></html>";

parent.tabcontent.document.getElementById('search').innerHTML="";  
parent.tabcontent.document.getElementById('search').innerHTML=s1;  
  
}
function find_instances3(search_term) {
  var caption;
  var new_search_term;
  var regular_expression;  
  var s1='';     
  
  s1="<html><head>"; 
  s1=s1+"<link rel=\"stylesheet\" type=\"text/css\" href=\"default.css\">";
  s1=s1+"<script src=\"search.js\"></script></head>";   
  s1=s1+"<body><a href=\"#\" onClick=\"javascript:parent.ChangeTab('keywords','search','keywordsResults','outline');parent.TabSelected(2);return false;\"><< Back to Keywords</a><br/>";
  s1=s1+"<span style='font-family:Helvetica,Arial;font-size:11px;font-weight:bold;'>";
  s1=s1+'<hr width="100%"/>\n';
  s1=s1+"Slides containing keyword: \"" + search_term.toUpperCase() + "\"";

  s1=s1+'<hr width="100%"/>\n';
  if (search_term.length > 0) {
    new_search_term = filter_search_term(search_term);
    regular_expression = new RegExp(new_search_term, "gi");

    for(i = 0; i < captions.length; ++i) {
      caption = captions[i];
      if (regular_expression.test(caption)) {
        href = make_href2(i, caption);
        s1=s1+href + "<br>\n";
      }
    }
  }
  //s1=s1+"<br><br>End of keyword results";
  s1=s1+"</span></body></html>";
  
parent.tabcontent.document.getElementById('keywords').style.display="none";
parent.tabcontent.document.getElementById('keywordsResults').style.display="block";
parent.tabcontent.document.getElementById('keywordsResults').innerHTML="";  
parent.tabcontent.document.getElementById('keywordsResults').innerHTML=s1;  
  
}

function filter_search_term(search_term) {
  new_search_term = filter_out_bad_punctuation(search_term);
  regexp_period = /\./gi;
  regexp_asterisk = /\*/gi;
  regexp_many_asterisks = /[\*][\*]+/gi;
  regexp_final_asterisk = /(\w*)\*$/gi;
  regexp_question = /\?/gi;

  period_replace = 	 "\\\\.";
  many_asterisks_replace = "\*";
  asterisk_replace = "[A-Za-z_&\\-]*";
  question_replace = ".";

  new_search_term1 = new_search_term.replace(regexp_period,period_replace);
  new_search_term2 = new_search_term1.replace(regexp_many_asterisks,many_asterisks_replace);
  new_search_term3 = new_search_term2.replace(regexp_final_asterisk,"$1");
  new_search_term4 = new_search_term3.replace(regexp_asterisk,asterisk_replace);
  new_search_term5 = new_search_term4.replace(regexp_question,question_replace);

  filtered_search_term = new_search_term5;
  return filtered_search_term;
}

function filter_out_bad_punctuation(search_term)
{
		regexp_backslash = 	 /\\/gi;
		regexp_slash = 	         /\//gi;
		regexp_ampersand = 	 /\&/gi;
		regexp_plus = 		 /\+/gi;

		regexp_openparen = 	 /\(/gi;
		regexp_closeparen = 	 /\)/gi;
		regexp_openbracket =	 /\[/gi;
		regexp_closebracket =	 /\]/gi;
		regexp_carrot =		 /\^/gi;
		regexp_dollar = 	 /\$/gi;
		regexp_bar =		 /\|/gi;

		backslash_replace = 	 "\\\\";
		ampersand_replace = 	 "\\&";
		plus_replace =   	 "\\+";
		slash_replace =  	 "\\/";
		openbracket_replace =	 "\\[";
		closebracket_replace =	 "\\]";
		openparen_replace = 	 "\\(";
		closeparen_replace =  	 "\\)";

		carrot_replace =	"\\^";
		dollar_replace =	"\\$";
		bar_replace =		"\\|";

		search_term1  = search_term.replace(regexp_backslash,backslash_replace);
		search_term2  = search_term1.replace(regexp_slash,slash_replace);
		search_term3  = search_term2.replace(regexp_ampersand,ampersand_replace);
		search_term4  = search_term3.replace(regexp_plus,plus_replace);
		search_term5  = search_term4.replace(regexp_openparen,openparen_replace);
		search_term6  = search_term5.replace(regexp_closeparen,closeparen_replace);
		search_term7  = search_term6.replace(regexp_openbracket,openbracket_replace);
		search_term8  = search_term7.replace(regexp_closebracket,closebracket_replace);
		search_term9  = search_term8.replace(regexp_carrot,carrot_replace);
		search_term10 = search_term9.replace(regexp_dollar,dollar_replace);
		search_term11 = search_term10.replace(regexp_bar,bar_replace);

		punctuation_filtered_search_term = search_term11;

		return punctuation_filtered_search_term;
}

function make_href(caption_index, searched_caption)
{
	var caption = captions[caption_index];
	var timecode = timecodes[caption_index];
	var vid_string = get_video_string(timecode);
	var href = "\n <a href='#' OnClick='" + vid_string + ";return false;'>";
	href += searched_caption.substring(0, searched_caption.indexOf('|')) + "</a>";
	bullet_string = "Slide " + (caption_index +1) + ":  ";
	output_string = bullet_string + href;
	return output_string;
	return href;
}
function make_href2(caption_index, searched_caption)
{
	var caption = captions[caption_index];
	var timecode = timecodes[caption_index];
	var vid_string = get_video_string(timecode);
	var href = "\n <a href='#' OnClick='" + vid_string + ";return false;'>";
	href += searched_caption.substring(0, searched_caption.indexOf('|')) + "</a>";
	bullet_string = "Slide " + (caption_index +1) + ":  ";
	output_string = bullet_string + href;
	return output_string;
	return href;
}

function get_video_string(actual_timecode)
{
	var vid_string = "";
	//vid_string += "top.videoFrame.seek(" + actual_timecode + ")";
	vid_string += "parent.BuildPlayer(\"ERROR\"," + actual_timecode + ")";
	return vid_string;
}

/**********************
function search_term_is_a_digit(search_term)
{
	var test = parseInt(search_term);
	if (test >= 0 && test <= 9)
		return true;
	else
		return false;
}
**********************/