// JavaScript Document
// Examples of general Javascript code with proper syntax so I can 'look up' examples and syntax and copy/paste rather than memorize of find the text book.
// Created: 2009 Jan 25
// Steven Grindle
// Last Update: 

function array_loop_alert_write(){
	//Create an array; manually fill the array; loop through all array items; display each array item and the loop counter using alert and document.write
	var array_object = new Array(); //Create an empty array object to hold a list of items.
	array_object = ["zero","one","two",3,4]; //Fill array manually.
	loop_end = array_object.length;
	for(i=0;i<loop_end;i++){ //Loop through all items in the array
		alert("i= "+i+" : array_object.length="+array_object.length+" : array_object["+i+"]= "+array_object[i]);
		document.write("i= "+i+" : array_object.length="+array_object.length+" : array_object["+i+"]= "+array_object[i]+"<br />");
	}
}

function prompt_if_else(){
	//Define a variable which equals the text input by the user
	var user_input = prompt("Enter a, b or c","lower case, please"); //prompt displays a dialog box
	confirm("You entered "+user_input); //confirm with no option if user presses 'Cancel'
	if(user_input == "a"){ //Beginning of the conditional. Did the user input 'a'?
		document.write(user_input+":a<br />"); //Yes the user input 'a'. Now skip to end of conditional.
	}else if(user_input == "b"){ //No the user did NOT input 'a'. Did the user input 'b'?
		document.write(user_input+":b<br />"); //Yes the user input 'b'. Now skip to end of conditional.
	}else if(user_input == "c"){ //No the user did NOT input 'b'. Did the user input 'c'?
		document.write(user_input+":c<br />"); //Yes the user input 'c'. Now skip to end of conditional.
	}else{ //No the user did NOT input 'c'.
		document.write(user_input+": is invalid"); //this happens when no previous condition is met.
	} //end of conditional
}

var htm_file = new Array("zero.htm","first.htm","second.htm","third.htm")
//Purpose: Recieve a whole number called which_htm from a navigation area and replace the current .htm with the new one identified by which_htm
//Manually assign the htm file names a position in the array. 
function see_htm(which_htm){//which_htm is assigned in the calling object and identifies the position in the array for the htm file.
	for (i=0;i<=htm_file.length;i++){
		//document.write("i= "+i+"<br />");
		if (i==which_htm){
		window.location=htm_file[i]
		}
	}
}


function string_bean(){
	//Example of slicing characters from the end of strings
	whole_string1= "/images/picture001.jpg";
	whole_string2= "/images/pic002.gif";
	whole_string3= "/images/pic_of_elephant.png";
	document.write(whole_string1+"= 'whole_string1'<br />");
	document.write(whole_string2+"= 'whole_string2'<br />");
	document.write(whole_string3+"= 'whole_string3'<br /><br />");
	alert("Each string is listed.");
	document.write(whole_string1.length+"  =   the number of characters in 'whole_string1'<br />");
	document.write(whole_string2.length+"  =   the number of characters in 'whole_string2'<br />");
	document.write(whole_string3.length+"  =   the number of characters in 'whole_string3'<br />");
	alert("The number of characters in each string is listed.");
	document.write("<br />Slice and keep the last 4 charaters from the first string");
	document.write("<br />Slice and keep the first 7 characters from the second string");
	document.write("<br />Slice OFF the first 7+1 and the last 4 characters from the third string and keep the remaining characters in the middle.<br /><br />");
	document.write(whole_string1.slice(whole_string1.length-4)+"  =   the last 4 characters of 'whole_string1'<br />");
	document.write(whole_string2.slice(0,7)+"  =   the first 7 characters of 'whole_string2'<br />");
	document.write(whole_string3.slice(7+1,whole_string3.length-4)+"  =   the middle characters of 'whole_string3'<br />");
	alert("The .slice method and (some basic arithmetic) allows the user to capture the end, beginning or middle of a string.");
}
