| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | var itemsToShow = new Array();	//list of indexes to all dives to view
 | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | var items = new Array(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | var start;			//index of first element viewed in itemsToShow
 | 
					
						
							|  |  |  | var sizeofpage;			//size of viewed page
 | 
					
						
							|  |  |  | var numberofwords = 0;		//just for stats
 | 
					
						
							|  |  |  | var olditemstoshow;		//to reference the indexes to all dives if changed
 | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | //////////////////////////////////
 | 
					
						
							|  |  |  | //				//
 | 
					
						
							|  |  |  | //		View Model	//
 | 
					
						
							|  |  |  | //				//
 | 
					
						
							|  |  |  | //////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *This Method view all items | 
					
						
							|  |  |  | *View N pages each of sizeofpage size items. | 
					
						
							|  |  |  | *starting from zero | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function showAllDives() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (var i = 0; i < items.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		itemsToShow.push(i); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	olditemstoshow = itemsToShow; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	start = 0; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	viewInPage(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *This function view the 'itemstoshow' in pages. | 
					
						
							|  |  |  | *It start from 'start' variable. | 
					
						
							|  |  |  | *It showes N pages each of sizeofpage size. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function viewInPage() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var end = start + sizeofpage - 1; | 
					
						
							|  |  |  | 	if (end >= itemsToShow.length) | 
					
						
							|  |  |  | 		end = itemsToShow.length - 1; | 
					
						
							|  |  |  | 	updateView(start, end); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *addHTML this Method puts the HTML of items of given indexes | 
					
						
							|  |  |  | *@param {array} indexes array of indexes to put in HTML | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function updateView(start, end) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var divelist = document.getElementById('diveslist'); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	divelist.innerHTML = ""; | 
					
						
							|  |  |  | 	for (var i = start; i <= end; i++) { | 
					
						
							|  |  |  | 		divelist.innerHTML += '<ul id="' + itemsToShow[i] + '" onclick="toggleExpantion(this)"</ul>'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		expand(document.getElementById(itemsToShow[i])); | 
					
						
							|  |  |  | 		items[itemsToShow[i]].expanded = true; | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	view_pagging(start, end); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *addHTML this Method puts the HTML of items of given indexes | 
					
						
							|  |  |  | *@param {array} indexes array of indexes to put in HTML | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function addHTML(indexes) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var divelist = document.getElementById('diveslist'); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	divelist.innerHTML = ""; | 
					
						
							|  |  |  | 	for (var i = 0; i < indexes.length; i++) { | 
					
						
							|  |  |  | 		divelist.innerHTML += '<ul id="' + indexes[i] + '" onclick="toggleExpantion(this)"</ul>'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		expand(document.getElementById(indexes[i])); | 
					
						
							|  |  |  | 		itemsToShow[indexes[i]].expanded = true; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *This Method shows items in a range [start,end] | 
					
						
							|  |  |  | *@param {integer} start start from this index | 
					
						
							|  |  |  | *@param {integer} finish at this index. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function view_in_range(start, end) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var ind = new Array(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (end >= itemsToShow.length) | 
					
						
							|  |  |  | 		end = itemsToShow.length - 1; | 
					
						
							|  |  |  | 	for (var i = start; i <= end; i++) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		ind.push(i); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	addHTML(ind); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	view_pagging(start, end); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function prev_page() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var end = start + sizeofpage - 1; | 
					
						
							|  |  |  | 	if (start - sizeofpage > 0) { | 
					
						
							|  |  |  | 		start -= sizeofpage; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		start = 0; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (end - sizeofpage > 0) { | 
					
						
							|  |  |  | 		end -= sizeofpage; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (end >= itemsToShow.length) { | 
					
						
							|  |  |  | 		end = itemsToShow.length - 1; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	updateView(start, end) | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function next_page() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var end = start + sizeofpage - 1; | 
					
						
							|  |  |  | 	if (end + sizeofpage < itemsToShow.length) { | 
					
						
							|  |  |  | 		end += sizeofpage; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		end = itemsToShow.length - 1; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (start + sizeofpage < itemsToShow.length) { | 
					
						
							|  |  |  | 		start += sizeofpage; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	updateView(start, end) | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function view_pagging(start, end) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var page = document.getElementById("pagging"); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	page.innerHTML = (start + 1) + ' to ' + (end + 1) + ' of ' + (itemsToShow.length) + ' dives'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function expandAll() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (var i = start; i < start + sizeofpage; i++) { | 
					
						
							|  |  |  | 		if (i >= itemsToShow.length) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		unexpand(document.getElementById(itemsToShow[i])); | 
					
						
							|  |  |  | 		items[itemsToShow[i]].expanded = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function collapseAll() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (var i = start; i < start + sizeofpage; i++) { | 
					
						
							|  |  |  | 		if (i >= itemsToShow.length) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		expand(document.getElementById(itemsToShow[i])); | 
					
						
							|  |  |  | 		items[itemsToShow[i]].expanded = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function setNumberOfDives(e) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var value = e.options[e.selectedIndex].value; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	sizeofpage = parseInt(value, 10); | 
					
						
							|  |  |  | 	var end = start + sizeofpage - 1; | 
					
						
							|  |  |  | 	view_in_range(start, end); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function toggleExpantion(ul) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!items[ul.id].expanded) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		expand(ul); | 
					
						
							|  |  |  | 		items[ul.id].expanded = true; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		unexpand(ul); | 
					
						
							|  |  |  | 		items[ul.id].expanded = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function expand(ul) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	ul.innerHTML = getlimited(items[ul.id]); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	ul.style.padding = '2px 10px 2px 10px'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function unexpand(ul) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	ul.innerHTML = getExpanded(items[ul.id]); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	ul.style.padding = '3px 10px 3px 10px'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //			Dive Model
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function getlimited(dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return '<div style="height:20px"><div class="item">' + (settings.subsurfaceNumbers === '0' ? dive.number : dive.subsurface_number) + '</div>' + | 
					
						
							|  |  |  | 	       '<div class="item">' + dive.date + '</div>' + | 
					
						
							|  |  |  | 	       '<div class="item">' + dive.time + '</div>' + | 
					
						
							|  |  |  | 	       '<div class="item_large">' + dive.location + '</div>' + | 
					
						
							|  |  |  | 	       '<div class="item">' + dive.temperature.air + '</div>' + | 
					
						
							|  |  |  | 	       '<div class="item">' + dive.temperature.water + '</div></div>'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function getExpanded(dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var res = '<table><tr><td class="words">Date: </td><td>' + dive.date + | 
					
						
							|  |  |  | 		  '</td><td class="words">     Time: </td><td>' + dive.time + | 
					
						
							|  |  |  | 		  '</td><td class="words">     Location: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' + | 
					
						
							|  |  |  | 		  dive.location + '</a>' + | 
					
						
							|  |  |  | 		  '</td></tr></table><table><tr><td class="words">Rating:</td><td>' + putRating(dive.rating) + | 
					
						
							|  |  |  | 		  '</td><td class="words">   Visibilty:</td><td>' + putRating(dive.visibility) + | 
					
						
							|  |  |  | 		  '</td></tr></table>' + | 
					
						
							|  |  |  | 		  '<table><tr><td class="words">Air temp: </td><td>' + dive.temperature.air + | 
					
						
							|  |  |  | 		  '</td><td class="words">    Water temp: </td><td>' + dive.temperature.water + | 
					
						
							|  |  |  | 		  '</td></tr></table><table><tr><td class="words">DiveMaster: </td><td>' + dive.divemaster + | 
					
						
							|  |  |  | 		  '</td></tr><tr><td class="words"><p>Buddy: </p></td><td>' + dive.buddy + | 
					
						
							|  |  |  | 		  '</td></tr><tr><td class="words">Suit: </td><td>' + dive.suit + | 
					
						
							|  |  |  | 		  '</td></tr><tr><td class="words">Tags: </td><td>' + putTags(dive.tags) + | 
					
						
							|  |  |  | 		  '</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes + '</div>'; | 
					
						
							|  |  |  | 	if (settings.listOnly === '0') { | 
					
						
							|  |  |  | 		res += '<center><a onclick="showDiveDetails(' + dive.number + ')">show more details</a></center>'; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:49 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function putTags(tags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var result = ""; | 
					
						
							|  |  |  | 	for (var i in tags) { | 
					
						
							|  |  |  | 		result += '<a onclick=\"Search_list_Modules(\'' + tags[i] + '\')\">' + tags[i] + '</a>'; | 
					
						
							|  |  |  | 		if (i < tags.length - 1) | 
					
						
							|  |  |  | 			result += ', '; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function putRating(rating) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var result; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	result = '<div>'; | 
					
						
							|  |  |  | 	for (var i = 0; i < rating; i++) | 
					
						
							|  |  |  | 		result += ' ★ '; | 
					
						
							|  |  |  | 	for (var i = rating; i < 5; i++) | 
					
						
							|  |  |  | 		result += ' ☆ '; | 
					
						
							|  |  |  | 	result += '</div>'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //		Sorting
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | /////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | this variables keep the state of | 
					
						
							|  |  |  | each col. sorted asc or des | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-14 19:20:37 +03:00
										 |  |  | var number = false; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | var time = true; | 
					
						
							|  |  |  | var date = true; | 
					
						
							|  |  |  | var air = true; | 
					
						
							|  |  |  | var water = true; | 
					
						
							|  |  |  | var locat = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function list_sort(sortOn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (sortOn) { | 
					
						
							|  |  |  | 	case '1': //number
 | 
					
						
							|  |  |  | 		if (number) { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpNumAsc); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			number = 1 - number; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpNumDes); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			number = 1 - number; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	case '2': //date
 | 
					
						
							|  |  |  | 		if (date) { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpDateAsc); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			date = 1 - date; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpDateDes); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			date = 1 - date; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	case '3': //time
 | 
					
						
							|  |  |  | 		if (time) { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpTimeDes); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			time = 1 - time; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpTimeAsc); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			time = 1 - time; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	case '4': //Air temp
 | 
					
						
							|  |  |  | 		if (air) { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpAtempDes); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			air = 1 - air; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpAtempAsc); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			air = 1 - air; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	case '5': //Water temp
 | 
					
						
							|  |  |  | 		if (water) { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpWtempDes); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			water = 1 - water; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpWtempAsc); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			water = 1 - water; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	case '6': //Water temp
 | 
					
						
							|  |  |  | 		if (locat) { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpLocationDes); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			locat = 1 - locat; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			sort_it(sortOn, cmpLocationAsc); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 			locat = 1 - locat; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function cmpLocationAsc(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].location < items[iSmaller].location; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function cmpLocationDes(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].location > items[iSmaller].location; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function cmpNumAsc(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].subsurface_number < items[iSmaller].subsurface_number; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpNumDes(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].subsurface_number > items[iSmaller].subsurface_number; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpTimeAsc(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].time < items[iSmaller].time; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpTimeDes(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].time > items[iSmaller].time; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpDateAsc(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].date < items[iSmaller].date; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpDateDes(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return items[j].date > items[iSmaller].date; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpAtempAsc(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return parseInt(items[j].temperature.air, 10) < parseInt(items[iSmaller].temperature.air, 10); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpAtempDes(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return parseInt(items[j].temperature.air, 10) > parseInt(items[iSmaller].temperature.air, 10); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpWtempAsc(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return parseInt(items[j].temperature.water, 10) < parseInt(items[iSmaller].temperature.water, 10); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | function cmpWtempDes(j, iSmaller) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return parseInt(items[j].temperature.water, 10) > parseInt(items[iSmaller].temperature.water, 10); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function sort_it(sortOn, function_) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var res = new Array(); | 
					
						
							|  |  |  | 	var visited = new Array(itemsToShow.length); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	for (var j = 0; j < itemsToShow.length; j++) { | 
					
						
							|  |  |  | 		visited[j] = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for (var i = 0; i < itemsToShow.length; i++) { | 
					
						
							|  |  |  | 		for (var j = 0; j < itemsToShow.length; j++) | 
					
						
							|  |  |  | 			if (visited[j] === false) | 
					
						
							|  |  |  | 				var iSmaller = j; | 
					
						
							|  |  |  | 		for (var j = 0; j < itemsToShow.length; j++) { | 
					
						
							|  |  |  | 			if (function_(itemsToShow[j], itemsToShow[iSmaller])) { | 
					
						
							|  |  |  | 				if (visited[j] === false) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 					iSmaller = j; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		visited[iSmaller] = true; | 
					
						
							|  |  |  | 		res.push(itemsToShow[iSmaller]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	itemsToShow = res; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	start = 0; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	viewInPage(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //		Searching
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function Set() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	this.keys = new Array(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | Set.prototype.contains = function(key) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	return (this.keys.indexOf(key) >= 0) ? true : false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | Set.prototype.push = function(key) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!this.contains(key)) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		this.keys.push(key); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | Set.prototype.isEmpty = function() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return this.keys.length <= 0 ? true : false; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | Set.prototype.forEach = function(do_) { | 
					
						
							|  |  |  | 	this.keys.forEach (do_); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | Set.prototype.Union = function(another_set) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-06 19:48:39 +03:00
										 |  |  | 	if (another_set === null) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	for (var i = 0; i < another_set.keys.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		this.push(another_set.keys[i]); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function Node(value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	this.children = new Array(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	this.value = value; | 
					
						
							|  |  |  | 	this.key = new Set(); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | ///////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function Search_list_Modules(searchfor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	document.getElementById("search_input").value = searchfor; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	SearchModules(searchfor); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function SearchModules(searchfor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var resultKeys = new Set(); //set
 | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (searchfor.length <= 0) { | 
					
						
							|  |  |  | 		//exit searching mode
 | 
					
						
							|  |  |  | 		document.getElementById("search_input").style.borderColor = "initial"; | 
					
						
							|  |  |  | 		start = 0; | 
					
						
							|  |  |  | 		itemsToShow = olditemstoshow; | 
					
						
							|  |  |  | 		viewInPage(); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	searchingModules.forEach (function(x) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		resultKeys.Union(x.search(searchfor)); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (searchingModules["location"].enabled === true) | 
					
						
							|  |  |  | 		resultKeys.Union(searchingModules["location"].search(searchfor)); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (searchingModules["divemaster"].enabled === true) | 
					
						
							|  |  |  | 		resultKeys.Union(searchingModules["divemaster"].search(searchfor)); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (searchingModules["buddy"].enabled === true) | 
					
						
							|  |  |  | 		resultKeys.Union(searchingModules["buddy"].search(searchfor)); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (searchingModules["notes"].enabled === true) | 
					
						
							|  |  |  | 		resultKeys.Union(searchingModules["notes"].search(searchfor)); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (searchingModules["tags"].enabled === true) | 
					
						
							|  |  |  | 		resultKeys.Union(searchingModules["tags"].search(searchfor)); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (resultKeys.isEmpty()) { | 
					
						
							|  |  |  | 		//didn't find keys
 | 
					
						
							|  |  |  | 		document.getElementById("search_input").style.borderColor = "red"; | 
					
						
							|  |  |  | 		itemsToShow = []; | 
					
						
							|  |  |  | 		viewInPage(); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	//found keys
 | 
					
						
							|  |  |  | 	document.getElementById("search_input").style.borderColor = "initial"; | 
					
						
							|  |  |  | 	itemsToShow = resultKeys.keys; | 
					
						
							|  |  |  | 	start = 0; | 
					
						
							|  |  |  | 	viewInPage(); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | ///////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function SearchModule(enabled) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	this.head = new Node(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	this.enabled = enabled; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | SearchModule.prototype.Enter_search_string = function(str, diveno) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (str == "" || !str) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var res = str.toLowerCase().split(" "); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	for (var i = 0; i < res.length; i++) { | 
					
						
							|  |  |  | 		insertIn(res[i], diveno, this.head); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		numberofwords++; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | SearchModule.prototype.Enter_search_tag = function(tags, diveno) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!tags) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	for (var i = 0; i < tags.length; i++) { | 
					
						
							|  |  |  | 		insertIn(tags[i], diveno, this.head); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		numberofwords++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | SearchModule.prototype.search = function(x) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return searchin(x.toLowerCase(), this.head); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | ////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function insertIn(value, key, node) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	node.key.push(key); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (value.length <= 0) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var this_char = value[0]; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	value = value.substring(1, value.length); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var i; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	for (i = 0; i < node.children.length; i++) { | 
					
						
							|  |  |  | 		if (node.children[i].value == this_char) { | 
					
						
							|  |  |  | 			return insertIn(value, key, node.children[i]); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	node.children[i] = new Node(this_char); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	insertIn(value, key, node.children[i]); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function searchin(value, node) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (value.length <= 0 || node.children.length <= 0) | 
					
						
							|  |  |  | 		return node.key; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var this_char = value[0]; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	value = value.substring(1, value.length); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	for (var i = 0; i < node.children.length; i++) { | 
					
						
							|  |  |  | 		if (node.children[i].value[0] == this_char) { | 
					
						
							|  |  |  | 			return searchin(value, node.children[i]); | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //trips
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var tripsShown; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function toggleTrips() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var trip_button = document.getElementById('trip_button'); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	if (tripsShown) { | 
					
						
							|  |  |  | 		tripsShown = false; | 
					
						
							|  |  |  | 		trip_button.style.backgroundColor = "#dfdfdf"; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		viewInPage(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		showtrips(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 		trip_button.style.backgroundColor = "#5f7f8f"; | 
					
						
							|  |  |  | 		tripsShown = true; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function showtrips() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var divelist = document.getElementById('diveslist'); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	divelist.innerHTML = ""; | 
					
						
							|  |  |  | 	for (var i = 0; i < trips.length; i++) { | 
					
						
							|  |  |  | 		divelist.innerHTML += '<ul id="trip_' + i + '" class="trips" onclick="toggle_trip_expansion(' + i + ')">' + | 
					
						
							|  |  |  | 				      trips[i].name + ' ( ' + trips[i].dives.length + ' dives)' + '</ul>' + '<div id="trip_dive_list_' + i + '"></div>'; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	for (var i = 0; i < trips.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		unexpand_trip(i); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function toggle_trip_expansion(trip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (trips[trip].expanded === true) { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		unexpand_trip(trip); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		expand_trip(trip); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function expand_trip(trip) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	trips[trip].expanded = true; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	var d = document.getElementById("trip_dive_list_" + trip); | 
					
						
							|  |  |  | 	for (var j in trips[trip].dives) { | 
					
						
							|  |  |  | 		d.innerHTML += '<ul id="' + trips[trip].dives[j].number + '" onclick="toggleExpantion(this)" onmouseover="highlight(this)"' + | 
					
						
							|  |  |  | 			       ' onmouseout="unhighlight(this)">' + getlimited(trips[trip].dives[j]) + '</ul>'; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function unexpand_trip(trip) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	trips[trip].expanded = false; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	var d = document.getElementById("trip_dive_list_" + trip); | 
					
						
							|  |  |  | 	d.innerHTML =''; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function getItems() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 	var count = 0; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	for (var i in trips) { | 
					
						
							|  |  |  | 		for (var j in trips[i].dives) { | 
					
						
							|  |  |  | 			items[count++] = trips[i].dives[j]; | 
					
						
							| 
									
										
										
										
											2014-06-01 07:44:35 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | ////////////////////////canvas///////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | Canvas Colors Constants | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | var CAMARONE1 = rgb(0, 0.4, 0); | 
					
						
							|  |  |  | var LIMENADE1 = rgb(0.4, 0.8, 0); | 
					
						
							|  |  |  | var RIOGRANDE1 = rgb(0.8, 0.8, 0); | 
					
						
							|  |  |  | var PIRATEGOLD1 = rgb(0.8, 0.5, 0); | 
					
						
							|  |  |  | var RED1 = rgb(1, 0, 0); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | Some Global variables that hold the current shown dive data. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | var dive_id;    //current shown ID
 | 
					
						
							|  |  |  | var points;     //reference to the samples array of the shown dive.
 | 
					
						
							|  |  |  | var MAX_HEIGHT; //Maximum depth, then its the maximum height for canvas
 | 
					
						
							|  |  |  | var MAX_WIDTH;  //dive duration, then its the maximum width for canvas
 | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Return RGB css color string. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function rgb(r, g, b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	r = Math.floor(r * 255); | 
					
						
							|  |  |  | 	g = Math.floor(g * 255); | 
					
						
							|  |  |  | 	b = Math.floor(b * 255); | 
					
						
							|  |  |  | 	return[ | 
					
						
							|  |  |  | 		"rgb(", | 
					
						
							|  |  |  | 		r, | 
					
						
							|  |  |  | 		",", | 
					
						
							|  |  |  | 		g, | 
					
						
							|  |  |  | 		",", | 
					
						
							|  |  |  | 		b, | 
					
						
							|  |  |  | 		")" | 
					
						
							|  |  |  | 	].join(""); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *This function returns the value scaled to the size of canvas | 
					
						
							|  |  |  | *new scale = (old scale * height of canvas) / max height in dive | 
					
						
							|  |  |  | *to ensure that the dive profile is filling the whole area available | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function scaleHeight(vari) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	var height = document.getElementById("profileCanvas").height; | 
					
						
							|  |  |  | 	max = MAX_HEIGHT; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	return (vari * height) / max; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *This function returns the value scaled to the size of canvas | 
					
						
							|  |  |  | *new scale = (old scale * width of canvas) / max width in dive | 
					
						
							|  |  |  | *to ensure that the dive profile is filling the whole area available | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function scaleWidth(vari) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	var width = document.getElementById("profileCanvas").width; | 
					
						
							|  |  |  | 	max = MAX_WIDTH; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	return (vari * width) / max; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Show Axis information(Numbers on scale) | 
					
						
							|  |  |  | *put a Number every 300 second scaled to canvas width. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function canvas_showAxisInfo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var c = document.getElementById("profileCanvas"); | 
					
						
							|  |  |  | 	var ctx = c.getContext("2d"); | 
					
						
							|  |  |  | 	ctx.font = "27px Georgia"; /*This is better be a variable scale*/ | 
					
						
							|  |  |  | 	for (var i = 0; i < MAX_WIDTH / scaleWidth(5); i++) | 
					
						
							|  |  |  | 		ctx.fillText("" + i * 5 + "", scaleWidth(i * 5 * 60), scaleHeight(MAX_HEIGHT - 150)); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Draw the grid | 
					
						
							|  |  |  | *with spacing = 5 * 60 = 300 | 
					
						
							|  |  |  | *draw line every 5 minutes | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function canvas_showGrid() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	var cnv = document.getElementById("profileCanvas"); | 
					
						
							|  |  |  | 	var cnvWidth = cnv.width; | 
					
						
							|  |  |  | 	var cnvHeight = cnv.height; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	var lineOptions = { | 
					
						
							|  |  |  | 		separation : scaleWidth(300), | 
					
						
							|  |  |  | 		color : '#AAAAAA' | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	var ctx = cnv.getContext('2d'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ctx.strokeStyle = lineOptions.color; | 
					
						
							|  |  |  | 	ctx.strokeWidth = 0.5; | 
					
						
							|  |  |  | 	ctx.beginPath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var iCount = null; | 
					
						
							|  |  |  | 	var i = null; | 
					
						
							|  |  |  | 	var x = null; | 
					
						
							|  |  |  | 	var y = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//draw horizontal lines
 | 
					
						
							|  |  |  | 	iCount = Math.floor(cnvWidth / lineOptions.separation); | 
					
						
							|  |  |  | 	for (i = 1; i <= iCount; i++) { | 
					
						
							|  |  |  | 		x = (i * lineOptions.separation); | 
					
						
							|  |  |  | 		ctx.moveTo(x, 0); | 
					
						
							|  |  |  | 		ctx.lineTo(x, cnvHeight); | 
					
						
							|  |  |  | 		ctx.stroke(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//draw vertical lines
 | 
					
						
							|  |  |  | 	iCount = Math.floor(cnvHeight / lineOptions.separation); | 
					
						
							|  |  |  | 	for (i = 1; i <= iCount; i++) { | 
					
						
							|  |  |  | 		y = (i * lineOptions.separation); | 
					
						
							|  |  |  | 		ctx.moveTo(0, y); | 
					
						
							|  |  |  | 		ctx.lineTo(cnvWidth, y); | 
					
						
							|  |  |  | 		ctx.stroke(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ctx.closePath(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *The Main function used for drawing canvas lines | 
					
						
							|  |  |  | *it automatically calcualte the slope of the line | 
					
						
							|  |  |  | *and choose its color. | 
					
						
							|  |  |  | *This is the function that should be used internally. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function canvas_drawline(ctx, begin, end) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	drawline(ctx, begin, end, getcolor(begin, end)); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Draw a line in the canvas with the given | 
					
						
							|  |  |  | *starting point, ending point, and color. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function drawline(ctx, begin, end, col) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	ctx.strokeStyle = col; | 
					
						
							|  |  |  | 	ctx.beginPath(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	ctx.moveTo(scaleWidth(begin[0]), scaleHeight(begin[1])); | 
					
						
							|  |  |  | 	ctx.lineTo(scaleWidth(end[0]), scaleHeight(end[1])); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	ctx.stroke(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Choose Color for different speeds. | 
					
						
							|  |  |  | *this need to be fixed to go with subsurface conversion. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function getcolor(begin, end) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var slope = (end[1] - begin[1]) / (end[0] - begin[0]); | 
					
						
							|  |  |  | 	if (Math.abs(slope) > 300) | 
					
						
							|  |  |  | 		return RED1; | 
					
						
							|  |  |  | 	if (Math.abs(slope) > 180) | 
					
						
							|  |  |  | 		return PIRATEGOLD1; | 
					
						
							|  |  |  | 	if (Math.abs(slope) > 110) | 
					
						
							|  |  |  | 		return RIOGRANDE1; | 
					
						
							|  |  |  | 	if (Math.abs(slope) > 70) | 
					
						
							|  |  |  | 		return LIMENADE1; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	return CAMARONE1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Return the HTML string for a dive cylinder entry in the table. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function get_cylinder_HTML(cylinder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return '<tr><td class="Cyl">' + cylinder.Type + '</td><td class="Cyl">' + cylinder.Size + '</td><td class="Cyl">' + cylinder.WPressure + '</td>' + | 
					
						
							|  |  |  | 	       '<td class="Cyl">' + cylinder.SPressure + '</td><td class="Cyl">' + cylinder.EPressure + '</td><td class="Cyl">' + cylinder.O2 + '</td></tr>'; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Return HTML table of cylinders of a dive. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function get_cylinders_HTML(dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var result = ""; | 
					
						
							|  |  |  | 	result += '<h2>Dive equipments</h2><table><tr><td class="Cyl">Type</td><td class="Cyl">Size</td><td class="Cyl">Work Pressure</td><td class="Cyl">Start Pressure</td><td class="Cyl">End Pressure</td><td class="Cyl">O2</td></tr>'; | 
					
						
							|  |  |  | 	for (var i in dive.Cylinders) { | 
					
						
							|  |  |  | 		result += get_cylinder_HTML(dive.Cylinders[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	result += '</table>'; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Return HTML main data of a dive | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function get_dive_HTML(dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return '<h2>Dive Information</h2><table><tr><td class="words">Date: </td><td>' + dive.date + | 
					
						
							|  |  |  | 	       '</td><td class="words">     Time: </td><td>' + dive.time + | 
					
						
							|  |  |  | 	       '</td><td class="words">     Location: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' + | 
					
						
							|  |  |  | 	       dive.location + '</a>' + | 
					
						
							|  |  |  | 	       '</td></tr></table><table><tr><td class="words">Rating:</td><td>' + putRating(dive.rating) + | 
					
						
							|  |  |  | 	       '</td><td class="words">   Visibilty:</td><td>' + putRating(dive.visibility) + | 
					
						
							|  |  |  | 	       '</td></tr></table>' + | 
					
						
							|  |  |  | 	       '<table><tr><td class="words">Air temp: </td><td>' + dive.temperature.air + | 
					
						
							|  |  |  | 	       '</td><td class="words">    Water temp: </td><td>' + dive.temperature.water + | 
					
						
							|  |  |  | 	       '</td></tr></table><table><tr><td class="words">DiveMaster: </td><td>' + dive.divemaster + | 
					
						
							|  |  |  | 	       '</td></tr><tr><td class="words"><p>Buddy: </p></td><td>' + dive.buddy + | 
					
						
							|  |  |  | 	       '</td></tr><tr><td class="words">Suit: </td><td>' + dive.suit + | 
					
						
							|  |  |  | 	       '</td></tr><tr><td class="words">Tags: </td><td>' + putTags(dive.tags) + | 
					
						
							|  |  |  | 	       '</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes + '</div>'; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Main canvas draw function | 
					
						
							|  |  |  | *this calls the axis and grid initialization functions. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function canvas_draw() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	var c = document.getElementById("profileCanvas"); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	c.width = window.innerWidth; | 
					
						
							|  |  |  | 	c.height = window.innerHeight; | 
					
						
							|  |  |  | 	canvas_showGrid(); | 
					
						
							|  |  |  | 	canvas_showAxisInfo(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	var ctx = c.getContext("2d"); | 
					
						
							|  |  |  | 	ctx.lineWidth = 4 //variable width
 | 
					
						
							|  |  |  | 		//draw starting line, draw all samples then draw the final line.
 | 
					
						
							|  |  |  | 		canvas_drawline(ctx, [0,0], points[0]); | 
					
						
							|  |  |  | 	for (var i = 1; i < points.length; i++) { | 
					
						
							|  |  |  | 		canvas_drawline(ctx, points[i - 1], points[i]); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	canvas_drawline(ctx, points[points.length - 1], [MAX_WIDTH,0]); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Initialize the detailed view, | 
					
						
							|  |  |  | *set the global variables | 
					
						
							|  |  |  | *Fill the dive data | 
					
						
							|  |  |  | *Hide the list and show the canvas view. | 
					
						
							|  |  |  | *this is called to view the dive details. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function showDiveDetails(dive) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	//set global variables
 | 
					
						
							|  |  |  | 	dive_id = dive; | 
					
						
							|  |  |  | 	points = items[dive_id].samples; | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	MAX_HEIGHT = items[dive_id].maxdepth * 1.1; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 	MAX_WIDTH = items[dive_id].duration; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//draw the canvas and initialize the view
 | 
					
						
							|  |  |  | 	canvas_draw(); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	document.getElementById("diveinfo").innerHTML = get_dive_HTML(items[dive_id]); | 
					
						
							|  |  |  | 	document.getElementById("dive_equipments").innerHTML = get_cylinders_HTML(items[dive_id]); | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//hide the list of dives and show the canvas.
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | 	document.getElementById("diveListPanel").style.display = 'none'; | 
					
						
							|  |  |  | 	document.getElementById("divePanel").style.display = 'block'; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | *Show the list view and hide the detailed list view. | 
					
						
							|  |  |  | *this function have to clear any data saved by showDiveDetails | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function unshowDiveDetails(dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	document.getElementById("diveListPanel").style.display = 'block'; | 
					
						
							|  |  |  | 	document.getElementById("divePanel").style.display = 'none'; | 
					
						
							| 
									
										
										
										
											2014-06-10 04:45:31 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-14 19:20:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function nextDetailedDive() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (dive_id < items.length) { | 
					
						
							| 
									
										
										
										
											2014-06-14 19:20:37 +03:00
										 |  |  | 		showDiveDetails(++dive_id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:51 +03:00
										 |  |  | function prevDetailedDive() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (dive_id > 0) { | 
					
						
							| 
									
										
										
										
											2014-06-14 19:20:37 +03:00
										 |  |  | 		showDiveDetails(--dive_id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |