// Ready to Learn JavaScript Code
var data;
// Functions
Array.prototype.unique = function () {
	var o = new Object();
	var i, e;
	for (i = 0; e = this[i]; i++) {
		o[e] = 1
	};
	var a = new Array();
	for (e in o) {
		a.push (e)
	};
	return a;
}

String.prototype.splitCSV = function(sep) {
	for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
		if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
			if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
				foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
			} else if (x) {
				foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
			} else 
				foo = foo.shift().split(sep).concat(foo);
		} else 
			foo[x].replace(/""/g, '"');
	} 

	return foo;
}

var temp = new Array();
temp[0] = " ";
temp[1] = "Finger Pupptet Show,Animals,Art Activity/Fine Motor,PHD,Develops fine motor skills,http://pbskids.org/superwhy/parentsteachers/activities/123.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[2] = "Animal Fun Facts,Animals,Game,SED,Develops positive social relationships,http://pbs.org/parents/lions/educators/activities-animal_fun.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[3] = "Animal Friends,Animals,Cutting Activity,C and L,Demonstrates emergent writing skills,http://pbskids.org/lions/parentsteachers/educators/activities-animal_friends.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[4] = "Color Collection,Colors,Matching,C and L,Demonstrates early reading skills,http://pbskids.org/lions/parentsteachers/educators/activities-color_collection.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[5] = "Pen Pal Postcard,Communication,Writing Experience,SED,Exhibits sense of self,http://www.pbs.org/parents/sesame/activity_4164.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[6] = "Finger Puppet Show,Communication,Arts and Crafts,SED,Develops self-control and personal responsibility,http://www.pbs.org/parents/superwhy/activities/123.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[7] = "Matching Shoes,Cooperation,Game,SED,Develops positive social relationships,http://pbskids.org/sesame/parentsTeachers/activity_4162.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[8] = "Its Unanimous,Cooperation,Game,SED,Develops positive social relationships,http://www.pbs.org/parents/sesame/activity_4169.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[9] = "A Surprise Party,Cooperation,Activity,SED,Develops positive social relationships,http://www.pbs.org/parents/superwhy/activities/121.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[10] = "Matching Shoes,Cooperation,Game,CD,Demonstrates understanding of number concepts,http://www.pbs.org/parents/sesame/activity_4162.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[11] = "Laundry Sorting Game,Cooperation,Game,CD,Demonstrates understanding of number concepts,http://pbskids.org/sesame/parentsTeachers/activity_4163.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[12] = "Nature Buddies,Cooperation,Game,CD,Demonstrates an understanding of the process of scientific inquiry,http://www.pbs.org/parents/lions/educators/activities-nature_buddies.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[13] = "Matching Shoes,Cooperation,Game,C and L,Demonstrates early reading skills,http://www.pbs.org/parents/sesame/activity_4162.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[14] = "It's Unanimous,Cooperation,Game,C and L,Observes and responds to communication,http://www.pbs.org/parents/sesame/activity_4169.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[15] = "Competition,Cooperation,Game,C and L,Uses language many ways,http://pbskids.org/martha/parentsteachers/activities/competition.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[16] = "Good or Bad,Cooperation,Game,C and L,Demonstrates early reading skills,http://pbskids.org/martha/parentsteachers/activities/goodorbad.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[17] = "Dream Dinner,Food,Cooking Experience,SED,Develops positive social relationships,http://pbs.org/parents/lions/educators/activities-dream_dinner.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[18] = "Charades,Imagination,Gross Motor Game,PHD,Moves body with control and balance,http://www.pbs.org/parents/wordworld/activities/105b.html,Word World,WordWorldDATA.jpg,3-6";
temp[19] = "A Surprise Party,Imagination,Gross Motor Game,PHD,Develops gross motor skills,http://www.pbs.org/parents/superwhy/activities/121.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[20] = "Scavenger Hunt,Imagination,Active Actiity,SED,Develops self-control and personal responsibility,http://www.pbs.org/parents/sesame/activity_4161.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[21] = "Dreams and Wishes,Imagination,Game,SED,Demonstrates imagination and creativity in play,http://pbs.org/parents/lions/educators/activities-dreams_and_wishes.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[22] = "Car Trips,Imagination,Pretending Game,SED,Develops positive social relationships,http://pbskids.org/martha/parentsteachers/activities/cartrip.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[23] = "Dress Up,Imagination,Make Believe Game,SED,Demonstrates imagination and creativity in play,http://pbskids.org/martha/parentsteachers/activities/dressup.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[24] = "Who Stole the Cookie,Imagination,Pretending Game,SED,Demonstrates understanding of simple rules,http://pbskids.org/martha/parentsteachers/activities/whostolethecookie.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[25] = "Charades,Imagination,Active Game,SED,Responds appropriately during group activities,http://www.pbs.org/parents/wordworld/activities/105b.htmlWord World,WordWorldDATA.jpg,3-6";
temp[26] = "Scavenger Hunt,Imagination,Active Actiity,CD,Demonstrates positive approaches to learning,http://www.pbs.org/parents/sesame/activity_4161.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[27] = "Dreams and Wishes,Imagination,Make believe game,CD,Demonstrated creativity throught the arts,http://www.pbs.org/parents/lions/educators/activities-dreams-_and_wishes.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[28] = "Scavenger Hunt,Imagination,Game,C and L,Uses language many ways,http://pbs.org/parentsTeachers/sesame/activity_4161.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[29] = "Pen Pal Postcard,Imagination,Writing Activity,C and L,Demonstartes emergent writing,http://pbs.org/parentsTeachers/sesame/activity_4164.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[30] = "Car Trip,Imagination,Game,C and L,Observes and responds to communication,http://pbskids.org/martha/parentsteachers/activities/cartrip.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[31] = "Dress Up,Imagination,Game,C and L,Uses language many ways,http://pbskids.org/martha/parentsteachers/activities/dressup.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[32] = "Guess that Stink,Imagination,Game,C and L,Demonstrates early reading skills,http://pbskids.org/martha/parentsteachers/activities/guessthatstink.html,Martha Speaks,MarthaSpeaksDATA.jpg,4-7";
temp[33] = "Gingerbread Cookie Letter,Imagination,Cooking activity,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/102.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[34] = "Race Day,Imagination,Game,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/105.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[35] = "The Magic S Game,Imagination,Letter Game,C and L,Demonstrates emergent writing skills,http://pbskids.org/wordworld/activities/106a.html,Word World,WordWorldDATA.jpg,3-6";
temp[36] = "Big and Little,Imagination,Size Exploring,C and L,Demonstrates emergent writing skills,http://www.pbs.org/parents/lions/educators/activities-big_and_little.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[37] = "Bugs all Around,Insects,Gross Motor Game,PHD,Develops gross motor skills,http://pbskids.org/sesame/parentsTeachers/activity_4165.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[38] = "Bugs all Around,Insects,Gross Motor Game,PHD,Develops gross motor skills,http://pbskids.org/sesame/parentsTeachers/activity_4165.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[39] = "Bugs all Around,Insects,Outside Game,CD,Demonstrates knowledge of the fundamental concepts of space science,http://pbskids.org/sesame/parentsTeachers/activity_4165.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[40] = "Bug Museum,Insects,Activity,CD,Demonstrates knowledge of the fundamental concepts,http://wwwlpbs.org/parents/lions/educators/activities-bug_museum.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[41] = "Bugging Out in the 'Hood,Insects,Game,CD,Demonstrates an understanding of  the process of scientific inquiry,http://www-tc.pbskids.org/electriccompany/pdfs/Bugging%20Out%20In%20The%20Hood.pdf,The Electric Company,ElecCompanyDATA.jpg,6-9";
temp[42] = "Going on an \"O\" Hunt,Letter Rec,Fine Motor Game,PHD,Moves body with control and balance,http://www.pbskids.org/wordworld/activities/101a.html,Word World,WordWorldDATA.jpg,3-6";
temp[43] = "\"V\" Freeze Tag,Letter Rec,Gross Motor Game,PHD,Moves body with control,http://www.pbskids.org/wordworld/activities/107b.html,Word World,WordWorldDATA.jpg,3-6";
temp[44] = "Alphabet Corn Maze,Letter Rec,Fine Motor Cutting,PHD,Moves small muscles with purpose,http://pbskids.org/superwhy/parentsteachers/activities/114.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[45] = "Have a Letter Party,Letters,Cooking Experience/Game,SED,Participates In large and small group activities,http://pbskids.org/superwhy/parentsteachers/activities/107.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[46] = "Going on an \"O\" hunt,Letters,Active Game,SED,Demonstrates understanding of simple rules,http://www.pbs.org/parents/wordworld/activities/101a.html,Word World,WordWorldDATA.jpg,3-6";
temp[47] = "Build a Sign,Letters,Game,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/101.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[48] = "Egg-cellent alphabet Hunt,Letters,Game,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/103.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[49] = "Musical Alphabet Chairs,Letters,Active Game,C and L,Demonstrates emergent writing skills,http://pbskids.org/superwhy/parentsteachers/activities/106.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[50] = "Have a Letter Party,Letters,Cooking activity,C and L,Demonstrates emergent writing skills,http://pbskids.org/superwhy/parentsteachers/activities/107.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[51] = "Make an Invitation,Letters,Writing Activity,C and L,Demonstrates emergent writing skills,http://pbskids.org/superwhy/parentsteachers/activities/110.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[52] = "Alphabet Corn Maze,Letters,Cutting Activity,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/114.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[53] = "Rhyming Hopscotch,Letters,Active Game,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/115.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[54] = "Alphabet Clues,Letters,Puzzle,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/119.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[55] = "Missing Letters Mystery,Letters,Game,C and L,Demonstrates early reading skills,http://pbskids.org/superwhy/parentsteachers/activities/124.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[56] = "Going on an \"O\" Hunt,Letters,Active Game,C and L,Demonstrates emergent writing skills,http://pbskids.org/wordworld/activities/101a.html,Word World,WordWorldDATA.jpg,3-6";
temp[57] = "Uppercase-lowercase Matching,Letters,Matching Game,C and L,Demonstrates emergent writing skills,http://pbskids.org/wordworld/activities/103a.html,Word World,WordWorldDATA.jpg,3-6";
temp[58] = "Build a Word Thing,Letters,Arts and Crafts,C and L,Demonstrates emergent writing skills,http://pbskids.org/wordworld/activities/103b.html,Word World,WordWorldDATA.jpg,3-6";
temp[59] = "Fish-sh-ing,Letters,Matching Game,C and L,Demonstrates emergent writing skills,http://pbskids.org/wordworld/activities/105a.html,Word World,WordWorldDATA.jpg,3-6";
temp[60] = "Big and Little-exploring size,Matching,Matching Game,CD,Demonstrateds an understanding of patterns and relationships,http://pbskids.org/parents/lions/educators/activities-big_and_little.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[61] = "Super Why Guitar,Music,Fine Motor Art Activity,PHD,Moves small muscles with purpose,http://www.pbs.org/parents/superwhy/activities/121.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[62] = "Super Why Guitar,Music,Art and Craft,CD,Demonstrated creativity throught the arts,http://www.pbs.org/parents/superwhy/activities/104.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[63] = "Music and Dance,Music,Game,CD,Demonstrated creativity throught the arts,http://www.pbs.org/parents/lions/educators/activities-music_and_dance.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[64] = "Rhyming Hopscotch,Numbers,Gross Motor Game,PHD,Develops gross motor skills,http://pbskids.org/superwhy/parentsteachers/activities/115.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[65] = "Counting in different ways,Numbers,Counting Game,CD,Demonstrates understanding of number concepts andnumerical operations,http://pbskids.org/sesame/parentsTeachers/activity_4168.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[66] = "Big Bad Wolves,Nursery Ryhmes Game,Matching Game,SED,Demonstrates imagination and creativity in play,http://pbs.org/parents/lions/educators/activities-big_and_little.html,Between the Lions,BtwnLionsDATA.jpg,4-6";
temp[67] = "Mixed Up Magnets,Science,Letter Game,C and L,Demonstrates emergent writing skills,http://pbskids.org/wordworld/activities/106b.html,Word World,WordWorldDATA.jpg,3-6";
temp[68] = "Looking for pieces of Pie,Shapes,Gross Motor game,PHD,Coordinates movements in spacein group activity,http://www.pbskids.org/wordworld/activities/104a.html,Word World,WordWorldDATA.jpg,3-6";
temp[69] = "Gingerbread Cookie Cutter,Shapes,Fine Motor Game,PHD,Moves small muscles with purpose,http://pbskids.org/superwhy/parentsteachers/activities/102.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[70] = "Gingerbread Cookie Cutter,Shapes,Cooking Experience/Game,SED,Participates In large and small group activities,http://pbskids.org/superwhy/parentsteachers/activities/102.html,Super Why,SuperWhyDATA.jpg,3-5";
temp[71] = "Shape Collage,Shapes,Art Activity,CD,Demonstrated creativity throught the arts,http://www.pbs.org/parents/sesame/activity_4167.html,Sesame Street,SstreetDATA.jpg,3-6";
temp[72] = "Werid Science,Space,Arts and Crafts,CD,Demonstrates logical thinking,http://www-tc.pbskids.org/electriccompany/bdfs/Weird%20Science.pdf,The Electric Company,ElecCompanyDATA.jpg,6-9";

var tempdata = new Array(temp.length);

for(var c=0;c<temp.length;c++){
	tempdata[c] = new Array();
	tempdata[c] = temp[c].splitCSV(",");
}
data = tempdata;
data = data.sort();

function loadrtl(){
	// Build Select Box Array
	var sel = new Array();
	for (var i=1;i<data.length;i++){
		sel.push(data[i][1]);
	}
	sel = sel.unique();
	sel = sel.sort();
	// Populate form with unique key words
	// Load form
	var formoutput = "<form name=\"readytolearn\" id=\"readytolearn\"><select name=\"rtlsel\" id=\"rtlsel\" size=\"1\" onchange=\"updatertl(this)\"></select></form><br />";
	document.getElementById("rtlform").innerHTML = formoutput;
	
	
	document.getElementById("rtlsel").length = 0;
	document.getElementById("rtlsel").options[0] = new Option("","",false,false);
	for (j=0;j<sel.length;j++){
		document.getElementById("rtlsel").options[j+1] = new Option(sel[j],sel[j],false,false);
	}
	
	var output = "<p class=\"rtlp\">Select a keyword above to find activities.</p>";
	document.getElementById("rtlbox").innerHTML = output;
}

function updatertl(keyword){
	document.getElementById("rtlbox").innerHTML = "";
	keyword = keyword.value;
	if(keyword!=""){
		var output = "<table id=\"rtltable\" width=\"90%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\">\n";
		output += "<tr class=\"rtlheader\"><td></td><td><strong>What is it?</strong></td><td><strong>Activity Category</strong></td><td><strong>KSDE Standard</strong></td><td><strong>PBS Program</strong></td><td><strong>Age Range</strong></td></tr>\n";
		var e = 0;
		for (k=0;k<data.length;k++){
			if(keyword==data[k][1]){
				if(e%2==0){output += "<tr class=\"rtlrow1 drow\" onclick=\"launch("+k+");\">";}else{output += "<tr class=\"rtlrow2 drow\" onclick=\"launch("+k+");\">";}e++;
				output += "<td><img src=\"http://www.ktwu.org/wp-content/themes/ktwu/js/readytolearn/images/"+data[k][7]+"\" /></td>"; // Program Image				
				output += "<td>"+data[k][0]+"</td>"; // Activity Name
				output += "<td>"+data[k][2]+"</td>"; // Activity Category
				output += "<td>"+data[k][4]+"</td>"; // Activity KDSE Standard
				output += "<td>"+data[k][6]+"</td>"; // PBS Program Title
				output += "<td>ages "+data[k][8]+"</td>"; // Age Range
				output += "</tr>\n";
			}
		}
		output += "</table>";
	}else{
		var output = "<p class=\"rtlp\">Select a keyword above to find activities.</p>";
	}
	document.getElementById("rtlbox").innerHTML = output;
}

function launch(id){
	window.open(data[id][5],"ReadytoLearn");	
}

