var itemsToShow = new Array(); //list of indexes to all dives to view
var items = new Array();
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
//////////////////////////////////
// //
// View Model //
// //
//////////////////////////////////
/**
*This Method view all items
*View N pages each of sizeofpage size items.
*starting from zero
*/
function showAllDives(){
for(var i=0 ; i < items.length ; i++){
itemsToShow.push(i);
}
olditemstoshow = itemsToShow;
start=0;
viewInPage();
}
/**
*This function view the 'itemstoshow' in pages.
*It start from 'start' variable.
*It showes N pages each of sizeofpage size.
*/
function viewInPage(){
var end = start + sizeofpage -1;
if(end >= itemsToShow.length ) end = itemsToShow.length-1;
updateView(start,end);
}
/**
*addHTML this Method puts the HTML of items of given indexes
*@param {array} indexes array of indexes to put in HTML
*/
function updateView(start,end){
var divelist = document.getElementById('diveslist');
divelist.innerHTML="";
for(var i=start;i<=end;i++){
divelist.innerHTML+='
';
expand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = true;
};
view_pagging(start,end);
}
/**
*addHTML this Method puts the HTML of items of given indexes
*@param {array} indexes array of indexes to put in HTML
*/
function addHTML(indexes){
var divelist = document.getElementById('diveslist');
divelist.innerHTML="";
for(var i=0;i';
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.
*/
function view_in_range(start,end){
var ind = new Array();
if(end>=itemsToShow.length)end=itemsToShow.length-1;
for(var i=start ; i <= end ; i++){
ind.push(i);
}
addHTML(ind);
view_pagging(start,end);
}
function prev_page(){
var end = start+sizeofpage-1;
if(start-sizeofpage>0){
start-=sizeofpage;
}
else{
start=0;
}
if(end-sizeofpage>0){
end-=sizeofpage;
}
if(end>=itemsToShow.length){
end = itemsToShow.length-1;
}
updateView(start,end)
}
function next_page(){
var end = start+sizeofpage-1;
if(end+sizeofpage=itemsToShow.length) break;
unexpand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = false;
}
}
function collapseAll(){
for(var i=start;i=itemsToShow.length) break;
expand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = true;
}
}
function setNumberOfDives(e){
var value = e.options[e.selectedIndex].value;
sizeofpage=parseInt(value);
var end = start + sizeofpage -1;
view_in_range(start,end);
}
function toggleExpantion(ul){
if(!items[ul.id].expanded)
{
expand(ul);
items[ul.id].expanded = true;
}
else
{
unexpand(ul);
items[ul.id].expanded = false;
}
}
function expand(ul){
ul.innerHTML = getlimited(items[ul.id]);
ul.style.padding='2px 10px 2px 10px';
}
function unexpand(ul){
ul.innerHTML = getExpanded(items[ul.id]);
ul.style.padding='3px 10px 3px 10px';
}
///////////////////////////////////////
//
// Dive Model
//
//////////////////////////////////////
function getlimited (dive) {
return ''+dive.subsurface_number+'
'+
'
'+dive.date+'
'+
'
'+dive.time+'
'+
'
'+dive.location+'
'+
'
'+dive.temperature.air+'
'+
'
'+dive.temperature.water+'
';
};
function getExpanded (dive) {
return 'Date: | '+dive.date+
' |      Time: | '+dive.time +
' |      Location: | '+''
+dive.location +''+
' |
Rating: | '+putRating(dive.rating)+
' |    Visibilty: | '+putRating(dive.visibility)+
' |
'+
'Air temp: | '+dive.temperature.air+
' |     Water temp: | '+dive.temperature.water +
' |
DiveMaster: | '+dive.divemaster +
' |
Buddy: | '+dive.buddy +
' |
Suit: | '+dive.suit +
' |
Tags: | '+putTags(dive.tags)+
' |
';
};
function putTags(tags){
var result="";
for(var i in tags){
result+=''+tags[i]+'';
if(i';
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;
function list_sort(sortOn){
switch(sortOn){
case '1' ://number
if(number){
sort_it(sortOn,cmpNumAsc);
number = 1 - number;
}
else{
sort_it(sortOn,cmpNumDes);
number = 1 - number;
}
break;
case '2' ://date
if(date){
sort_it(sortOn,cmpDateAsc);
date = 1 - date;
}
else{
sort_it(sortOn,cmpDateDes);
date = 1 - date;
}
break;
case '3'://time
if(time){
sort_it(sortOn,cmpTimeDes);
time = 1 - time;
}
else{
sort_it(sortOn,cmpTimeAsc);
time = 1 - time;
}
break;
case '4'://Air temp
if(air){
sort_it(sortOn,cmpAtempDes);
air = 1 - air;
}
else{
sort_it(sortOn,cmpAtempAsc);
air = 1 - air;
}
break;
case '5'://Water temp
if(water){
sort_it(sortOn,cmpWtempDes);
water = 1 - water;
}
else{
sort_it(sortOn,cmpWtempAsc);
water = 1 - water;
}
break;
case '6'://Water temp
if(locat){
sort_it(sortOn,cmpLocationDes);
locat = 1 - locat;
}
else{
sort_it(sortOn,cmpLocationAsc);
locat = 1 - locat;
}
break;
}
}
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) < parseInt(items[iSmaller].temperature.air) ;
}
function cmpAtempDes(j,iSmaller){
return parseInt(items[j].temperature.air) > parseInt(items[iSmaller].temperature.air) ;
}
function cmpWtempAsc(j,iSmaller){
return parseInt(items[j].temperature.water) < parseInt(items[iSmaller].temperature.water) ;
}
function cmpWtempDes(j,iSmaller){
return parseInt(items[j].temperature.water) > parseInt(items[iSmaller].temperature.water) ;
}
function sort_it(sortOn,function_){
var res = new Array();
var visited = new Array(itemsToShow.length);
for(var j=0;j= 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'
+trips[i].name+' ( '+trips[i].dives.length+' dives)'+'
'+'';
};
for(var i=0;i'+getlimited(trips[trip].dives[j])+'';
}
}
function unexpand_trip(trip){
trips[trip].expanded = false;
var d = document.getElementById("trip_dive_list_"+trip);
d.innerHTML='';
}
function getItems(){
var count = 0;
for(var i in trips){
for(var j in trips[i].dives){
items[count++]=trips[i].dives[j];
}
}
}