' + (settings.subsurfaceNumbers === '0' ? dive.number + 1 : dive.subsurface_number) + '
' +
'
' + dive.date + '
' +
'
' + dive.time + '
' +
'
' + dive.location + '
' +
'
' + dive.temperature.air + '
' +
'
' + dive.temperature.water + '
';
};
function getExpanded(dive)
{
var res = '';
for (var i = 0; i < rating; i++)
result += ' ★ ';
for (var i = rating; i < 5; i++)
result += ' ☆ ';
result += '
';
return result;
}
///////////////////////////////////////
//
// Sorting
//
/////////////////////////////////////
/*
this variables keep the state of
each col. sorted asc or des
*/
var number = true;
var time = true;
var date = true;
var air = true;
var water = true;
var locat = true;
/*
This variable keep the state of the col.
which is sorted upon it.
*/
var sort_based_on = 1; // sorting is based on number by default.
function change_sort_col(sortOn)
{
sort_based_on = sortOn;
toggle_sort_state(sortOn);
list_sort(sortOn);
}
function list_sort(sortOn)
{
switch (sortOn) {
case '1': //number
if (number) {
sort_it(sortOn, cmpNumAsc);
} else {
sort_it(sortOn, cmpNumDes);
}
break;
case '2': //date
if (date) {
sort_it(sortOn, cmpDateAsc);
} else {
sort_it(sortOn, cmpDateDes);
}
break;
case '3': //time
if (time) {
sort_it(sortOn, cmpTimeDes);
} else {
sort_it(sortOn, cmpTimeAsc);
}
break;
case '4': //Air temp
if (air) {
sort_it(sortOn, cmpAtempDes);
} else {
sort_it(sortOn, cmpAtempAsc);
}
break;
case '5': //Water temp
if (water) {
sort_it(sortOn, cmpWtempDes);
} else {
sort_it(sortOn, cmpWtempAsc);
}
break;
case '6': //Location
if (locat) {
sort_it(sortOn, cmpLocationDes);
} else {
sort_it(sortOn, cmpLocationAsc);
}
break;
}
}
function toggle_sort_state(sortOn)
{
switch (sortOn) {
case '1': //number
number = 1 - number;
break;
case '2': //date
date = 1 - date;
break;
case '3': //time
time = 1 - time;
break;
case '4': //Air temp
air = 1 - air;
break;
case '5': //Water temp
water = 1 - water;
break;
case '6': //Location
locat = 1 - locat;
break;
}
}
/*
*sorting interface for different coloumns
*/
function cmpLocationAsc(j, iSmaller)
{
return items[j].location < items[iSmaller].location;
}
function cmpLocationDes(j, iSmaller)
{
return items[j].location > items[iSmaller].location;
}
function cmpNumAsc(j, iSmaller)
{
return items[j].subsurface_number < items[iSmaller].subsurface_number;
}
function cmpNumDes(j, iSmaller)
{
return items[j].subsurface_number > items[iSmaller].subsurface_number;
}
function cmpTimeAsc(j, iSmaller)
{
return items[j].time < items[iSmaller].time;
}
function cmpTimeDes(j, iSmaller)
{
return items[j].time > items[iSmaller].time;
}
function cmpDateAsc(j, iSmaller)
{
return items[j].date < items[iSmaller].date;
}
function cmpDateDes(j, iSmaller)
{
return items[j].date > items[iSmaller].date;
}
function cmpAtempAsc(j, iSmaller)
{
return parseInt(items[j].temperature.air, 10) < parseInt(items[iSmaller].temperature.air, 10);
}
function cmpAtempDes(j, iSmaller)
{
return parseInt(items[j].temperature.air, 10) > parseInt(items[iSmaller].temperature.air, 10);
}
function cmpWtempAsc(j, iSmaller)
{
return parseInt(items[j].temperature.water, 10) < parseInt(items[iSmaller].temperature.water, 10);
}
function cmpWtempDes(j, iSmaller)
{
return parseInt(items[j].temperature.water, 10) > parseInt(items[iSmaller].temperature.water, 10);
}
function sort_it(sortOn, function_)
{
var res = new Array();
var visited = new Array(itemsToShow.length);
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) {
iSmaller = j;
}
}
}
visited[iSmaller] = true;
res.push(itemsToShow[iSmaller]);
}
itemsToShow = res;
start = 0;
viewInPage();
}
///////////////////////////////////////
//
// Searching
//
//////////////////////////////////////
function Set()
{
this.keys = new Array();
}
Set.prototype.contains = function(key)
{
return (this.keys.indexOf(key) >= 0) ? true : false;
}
Set.prototype.push = function(key)
{
if (!this.contains(key)) {
this.keys.push(key);
}
};
Set.prototype.isEmpty = function()
{
return this.keys.length <= 0 ? true : false;
};
Set.prototype.forEach = function(do_) {
this.keys.forEach (do_);
};
Set.prototype.Union = function(another_set)
{
if (another_set === null) {
return;
}
for (var i = 0; i < another_set.keys.length; i++) {
this.push(another_set.keys[i]);
};
};
Set.prototype.intersect = function(another_set)
{
if (another_set === null) {
return;
}
var result = new Array();
for (var i = 0; i < another_set.keys.length; i++) {
if(this.contains(another_set.keys[i])) {
result.push(another_set.keys[i]);
}
};
this.keys = result;
};
function Node(value)
{
this.children = new Array();
this.value = value;
this.key = new Set();
}
function Search_list_Modules(searchfor, searchOptions)
{
document.getElementById("search_input").value = searchfor;
SearchModules(searchfor, searchOptions);
}
function SearchModules(searchfor, searchOptions)
{
unshowDiveDetails(dive_id);
var resultKeys = new Set(); //set
if (searchfor.length <= 0) {
//exit searching mode
document.getElementById("search_input").style.borderColor = "initial";
start = 0;
itemsToShow = olditemstoshow;
list_sort(sort_based_on);
viewInPage();
return;
}
var keywords = searchfor.split(" ");
if (searchOptions === null) {
searchOptions = {};
searchOptions.location = searchingModules["location"].enabled;
searchOptions.divemaster = searchingModules["divemaster"].enabled;
searchOptions.buddy = searchingModules["buddy"].enabled;
searchOptions.notes = searchingModules["notes"].enabled;
searchOptions.tags = searchingModules["tags"].enabled;
}
for (var i = 0; i < keywords.length; i++) {
var keywordResult = new Set();
if (searchOptions.location === true)
keywordResult.Union(searchingModules["location"].search(keywords[i]));
if (searchOptions.divemaster === true)
keywordResult.Union(searchingModules["divemaster"].search(keywords[i]));
if (searchOptions.buddy === true)
keywordResult.Union(searchingModules["buddy"].search(keywords[i]));
if (searchOptions.notes === true)
keywordResult.Union(searchingModules["notes"].search(keywords[i]));
if (searchOptions.tags === true)
keywordResult.Union(searchingModules["tags"].search(keywords[i]));
if (resultKeys.isEmpty()) {
resultKeys.Union(keywordResult);
} else {
resultKeys.intersect(keywordResult);
}
}
if (resultKeys.isEmpty()) {
//didn't find keys
document.getElementById("search_input").style.borderColor = "red";
itemsToShow = [];
viewInPage();
return;
}
//found keys
document.getElementById("search_input").style.borderColor = "initial";
itemsToShow = resultKeys.keys;
start = 0;
list_sort(sort_based_on);
viewInPage();
}
///////////////////////////////////////
function SearchModule(enabled)
{
this.head = new Node();
this.enabled = enabled;
}
SearchModule.prototype.Enter_search_string = function(str, diveno)
{
if (str === "" || !str)
return;
var res = str.toLowerCase().split(" ");
for (var i = 0; i < res.length; i++) {
insertIn(res[i], diveno, this.head);
numberofwords++;
}
}
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);
numberofwords++;
}
}
SearchModule.prototype.search = function(x)
{
return searchin(x.toLowerCase(), this.head);
}
////////////////////////////////////////
function insertIn(value, key, node)
{
node.key.push(key);
if (value.length <= 0)
return;
var this_char = value[0];
value = value.substring(1, value.length);
var i;
for (i = 0; i < node.children.length; i++) {
if (node.children[i].value == this_char) {
return insertIn(value, key, node.children[i]);
}
}
node.children[i] = new Node(this_char);
insertIn(value, key, node.children[i]);
}
function searchin(value, node)
{
if (value.length <= 0 || node.children.length <= 0)
return node.key;
var this_char = value[0];
value = value.substring(1, value.length);
for (var i = 0; i < node.children.length; i++) {
if (node.children[i].value[0] == this_char) {
return searchin(value, node.children[i]);
}
}
return null;
}
//trips
var tripsShown;
/**
*This is the main function called to show/hide trips
*/
function toggleTrips()
{
var trip_button = document.getElementById('trip_button');
if (tripsShown) {
tripsShown = false;
trip_button.style.backgroundColor = "#dfdfdf";
viewInPage();
} else {
showtrips();
trip_button.style.backgroundColor = "#5f7f8f";
tripsShown = true;
}
}
function showtrips()
{
var divelist = document.getElementById('diveslist');
divelist.innerHTML = "";
for (var i = 0; i < trips.length; i++) {
divelist.innerHTML += '