
var XView;function XcViewLeague(league,show,year,clubIndex)
{this.page={league:league.toString(),show:show.toString(),year:year.toString()};this.current={league:this.page.league,show:this.page.show,year:this.page.year};this.clubIndex=clubIndex;this.clubEnabled=true;this.league=[];this.leagueCount=0;this.selLeague={};this.selShow={};this.selYear={};this.goButton={};this.expired="0";this.classValidText="txtBlack";this.classInvalidText="txtLtGray";this.classValidSelect="select120";this.classInvalidSelect="select120Gray";this.baseUrl="";this.viewParam="vx";this.expiredFilter="2";}
XcViewLeague.prototype.init=function(leagues)
{var form,i,action;form=document.forms["leagueForm"];if(form)
{this.selLeague=form.leagueView;this.selLeague.onchange=function(){XView.changeLeague();};this.selLeague.onkeyup=function(){XView.changeLeague();};this.selShow=form.showView;this.selShow.onchange=function(){XView.changeShow();};this.selShow.onkeyup=function(){XView.changeShow();};this.selYear=form.year;this.selYear.onchange=function(){XView.changeYear();};this.selYear.onkeyup=function(){XView.changeYear();};this.goButton=document.getElementById("bg");this.goButton.onclick=function(){XView.showLeague();return false;};if(form.expired&&form.expired.value==="1")
{this.expired=this.expiredFilter;}}
this.league=leagues;this.leagueCount=this.league.length;action=form.action;this.baseUrl=action.substring(0,action.indexOf("view.php"))+"leagues/";this.changeYear();};XcViewLeague.prototype.changeLeague=function()
{this.current.league=this.selLeague[this.selLeague.selectedIndex].value;this.toggleClub(true);this.toggleGo();};XcViewLeague.prototype.changeShow=function(internal)
{this.current.show=this.selShow[this.selShow.selectedIndex].value;this.toggleClub(false);this.toggleGo();};XcViewLeague.prototype.changeYear=function()
{var year,valid,selIndex,newIndex,leagueSelValue,leagueValue;this.current.year=this.selYear[this.selYear.selectedIndex].value;if(this.current.year!=="all")
{year=parseInt(this.selYear.options[this.selYear.selectedIndex].value,10);}
else
{year=this.current.year;}
selIndex=0;newIndex=0;for(i=0;i<this.leagueCount;i+=1)
{leagueSelValue=undefined;if(this.selLeague[selIndex])
{leagueSelValue=this.selLeague[selIndex].value;}
leagueValue=this.league[i].value;valid=true;if(year!=="all")
{if(this.league[i].start)
{valid=(year>=this.league[i].start);}
if(this.league[i].end)
{valid=(year<=this.league[i].end);}}
if(valid)
{if(leagueSelValue!==leagueValue)
{this.addOption(this.selLeague,selIndex,this.league[i].value,this.league[i].name);}
if(leagueValue===this.current.league)
{newIndex=selIndex;}
selIndex+=1;}
else
{if(leagueSelValue===leagueValue)
{this.selLeague.remove(selIndex);}}}
this.selLeague.selectedIndex=newIndex;this.changeLeague();};XcViewLeague.prototype.toggleClub=function(fromLeague)
{var i,selLeagueValue,leagueLocal,changed;selLeagueValue=this.selLeague[this.selLeague.selectedIndex].value;for(i=0;i<this.league.length;i+=1)
{if(selLeagueValue===this.league[i].value)
{leagueLocal=this.league[i].local;break;}}
changed=this.setClub(leagueLocal);if(fromLeague)
{if(changed&&this.selShow.selectedIndex===this.clubIndex)
{this.setShowClass(this.clubEnabled);}}
else
{this.setShowClass(!leagueLocal||this.selShow.selectedIndex!==this.clubIndex);}};XcViewLeague.prototype.setClub=function(leagueLocal)
{var changed;changed=false;if(leagueLocal)
{if(this.clubEnabled)
{this.selShow[this.clubIndex].className=this.classInvalidText;this.clubEnabled=false;changed=true;}}
else
{if(!this.clubEnabled)
{this.selShow[this.clubIndex].className=this.classValidText;this.clubEnabled=true;changed=true;}}
return changed;};XcViewLeague.prototype.setShowClass=function(valid)
{if(valid)
{className=this.classValidSelect;}
else
{className=this.classInvalidSelect;}
this.selShow.className=className;};XcViewLeague.prototype.toggleGo=function()
{if(this.page.league===this.current.league&&this.page.show===this.current.show&&this.page.year===this.current.year)
{this.goButton.disabled=true;return;}
this.goButton.disabled=(this.selShow.className===this.classInvalidSelect);};XcViewLeague.prototype.addOption=function(select,beforeIndex,value,text)
{var last,optNew,optOld;last=(beforeIndex>=select.options.length);optNew=document.createElement("option");optNew.value=value;optNew.text=text;if(!last)
{optOld=select[beforeIndex];try
{select.add(optNew,optOld);}
catch(e)
{select.add(optNew,beforeIndex);}}
else
{try
{select.add(optNew,null);}
catch(e)
{select.add(optNew);}}};XcViewLeague.prototype.showLeague=function()
{var page,qs;page=this.current.year+"-"+this.current.league+".html";if(this.current.show==="1"&&this.expired==="0")
{qs="";}
else
{qs="?"+this.viewParam+"="+this.current.show;qs+=this.expired;}
location.href=this.baseUrl+page+qs;}
function initView(ar)
{var block,sel,i;block=document.getElementById("coordinates");block.style.display="none";sel=document.getElementById('coordSelect');if(!sel)
{return;}
sel.options.length=ar.length+1;sel.options[0].value='';sel.options[0].text='Show';for(i=0;i<sel.options.length-1;i++)
{sel.options[i+1].value=ar[i]['value'];sel.options[i+1].text=ar[i]['name'];}
toggleView("vfWitness");toggleView("vfTracklog");toggleView("vfAdmin");}
function coordSelect(select)
{var block=document.getElementById("coordinates");if(!select.value)
{if(select.options[0].text=="Hide")
{select.options[0].text="Show";block.style.display="none";}
else
{select.options[0].text="Hide";block.style.display="block";}
return;}
var ar=Cds[select.value];if(!ar)
{return;}
if(block.style.display=="none")
{block.style.display="block";select.options[0].text="Hide";}
for(var id in ar)
{if(!ar.hasOwnProperty(id))
{continue;}
var coord=document.getElementById(id);if(coord)
{coord.innerHTML=ar[id];}}}
function toggleView(baseId)
{var base,link,content;base=document.getElementById(baseId);if(!base)
{return;}
link=document.getElementById(baseId+"-link");content=document.getElementById(baseId+"-content");if(content.style.visibility==="hidden")
{link.className="viewLinkHide";content.style.visibility="visible";content.style.display="block";base.className="toggleViewOn";}
else
{link.className="viewLinkShow";content.style.visibility="hidden";content.style.display="none";base.className="toggleViewOff";}
if(link.title.indexOf("Hide")==0)
{link.title=link.title.replace(/Hide/,"Show");}
else
{link.title=link.title.replace(/Show/,"Hide");}
base.firstChild.title=link.title;}
function showClub(id,name)
{var block=document.getElementById("block"+id);var caption=document.getElementById("caption"+id);var link=document.getElementById("link"+id);var pic=document.getElementById("pic"+id);if(block.style.display==="none")
{block.style.display="block";caption.innerHTML="Hide Other Pilots";link.title="Hide non-scoring "+name+" pilots";pic.className="viewLinkHide";}
else
{block.style.display="none";caption.innerHTML="Show Other Pilots";link.title="Show non-scoring "+name+" pilots";pic.className="viewLinkShow";}}
function getCookie(name)
{if(document.cookie.length>0)
{var start=document.cookie.indexOf(name+"=");if(start>0)
{start+=name.length+1;var end=document.cookie.indexOf(";",start);if(end===-1)
{end=document.cookie.length;}
return unescape(document.cookie.substring(start,end));}}
return null;}
function adminClick(flag)
{document.leagueForm['adminTask'].value=flag;}
function pilotSelectClick()
{var bhpa=document.getElementById("bhpaBlock");var name=document.getElementById("nameBlock");if(document.leagueForm.pilotSelect[0].checked==true)
{bhpa.style.display="none";name.style.display="block";document.leagueForm.pilot.focus();}
else
{bhpa.style.display="block";name.style.display="none";document.leagueForm.pilotNo.focus();}}
function isBlank(sValue)
{var sWhitespace=" \t\n\r";if((sValue==null)||(sValue.length==0))
return true;var sChar='';for(var i=0;i<sValue.length;i++){sChar=sValue.charAt(i);if(sWhitespace.indexOf(sChar)==-1)
return false;}
return true;}
function paymentSelect(start)
{var Sel=document.leagueForm['paymentStatus'];var Orig=document.leagueForm['paymentStatusOrig'].value;if(typeof(start)!='undefined'){Sel.options.selectedIndex=Orig;}
if(Sel.selectedIndex==Orig){document.leagueForm['nextButton'].disabled=true;}else{document.leagueForm['nextButton'].disabled=false;document.leagueForm['nextButton'].focus();}}
function updatePilot(flag)
{document.leagueForm.submit();}
function externalLinks()
{if(!document.getElementsByTagName)return;var anchors=document.getElementsByTagName("a");for(var i=0;i<anchors.length;i++)
{var anchor=anchors[i];if(anchor.getAttribute("href")&&anchor.getAttribute("rel")=="external")
{anchor.target="_blank";}}} 
if(!this.JSON){this.JSON={};}
(function(){function f(n){return n<10?'0'+n:n;}
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
f(this.getUTCMonth()+1)+'-'+
f(this.getUTCDate())+'T'+
f(this.getUTCHours())+':'+
f(this.getUTCMinutes())+':'+
f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
if(typeof rep==='function'){value=rep.call(holder,key,value);}
switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
v=partial.length===0?'[]':gap?'[\n'+gap+
partial.join(',\n'+gap)+'\n'+
mind+']':'['+partial.join(',')+']';gap=mind;return v;}
if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+
mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
return str('',{'':value});};}
if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
return reviver.call(holder,key,value);}
cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
throw new SyntaxError('JSON.parse');};}}()); 
var app;var map;function unloadXcPlayer()
{if(app)
{app.unload();}
if(typeof GUnload==="function")
{GUnload();}}
function checkUnload()
{var text;var unsaved=app.Story.unsaved();if(unsaved)
{if(unsaved===1)
{text="an unsaved story";}
else if(unsaved>1)
{text=unsaved+" unsaved stories";}
if(text)
{text="You have "+text+" that will be lost when you leave this page.";return text;}}
if(app.Story.baseStatus===app.constants.STORY_STATUS_NONE&&app.Story.status===app.constants.STORY_STATUS_PRIVATE)
{text="Your storyboard has not been published. It will be deleted at the end of the XC year.";}
return text;}
function get(id)
{return document.getElementById(id);}
function isArray(value)
{var s=typeof value;if(s==="object"&&value)
{return(typeof value.length==="number"&&!(value.propertyIsEnumerable("length"))&&typeof value.splice==="function");}
else
{return false;}}
function setVisibility(index,selectedIndex,obj)
{if(!obj)
{return;}
if(index===selectedIndex)
{obj.style.visibility="visible";obj.style.display="block";}
else
{obj.style.visibility="hidden";obj.style.display="none";}}
function formatInt(val)
{var s="";if(val===undefined)
{return s;}
s=val.toString();if(s.length===1)
{return"0"+s;}
else
{return s;}}
function timeFromSecs(secs,hm)
{var modH,h,m,s,result;h=0;m=0;s=0;result="";if((!secs&&secs!==0)||secs===-1)
{return result;}
h=Math.floor(secs/3600);modH=secs%3600;if(modH>0)
{m=Math.floor(modH/60);s=modH%60;}
if(hm===undefined)
{result=formatInt(h)+":"+formatInt(m)+":"+formatInt(s);}
else
{result=h+":"+formatInt(m);}
return result;}
function sortNum(a,b)
{if(a>b)
{return 1;}
else if(a<b)
{return-1;}
else
{return 0;}}
function cookieWrite(name,value,days)
{var expires;if(days)
{var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();}
else
{expires="";}
document.cookie=name+"="+encodeURIComponent(value)+expires+"; path=/";}
function cookieRead(name)
{var nameEQ=name+"=";var ar=document.cookie.split(';');var s;for(var i=0;i<ar.length;i+=1)
{s=ar[i];while(s.charAt(0)===" ")
{s=s.substring(1,s.length);}
if(s.indexOf(nameEQ)===0)
{return decodeURIComponent(s.substring(nameEQ.length,s.length));}}
return null;}
function cookieDelete(name)
{cookieWrite(name," ",-1);}
function togglePlay()
{var button=get("playButton");button.blur();if(app.player.dataMax===0)
{return;}
if(app.player.playing)
{app.stopPlayingTrack();button.value="Play";app.data.display.style.backgroundColor="#fff";}
else
{if(!map.getInfoWindow().isHidden())
{map.closeInfoWindow();}
button.value="Pause";app.data.display.style.backgroundColor="#d9ffd9";app.startPlayingTrack();}}
function closestVertex(name,latLng)
{var smallest=30000000;var distance;var mainIndex=0;var line;var len2;var index;var len1=app.Polylines.lines[name].length;for(var i=0;i<len1;i+=1)
{line=app.Polylines.lines[name][i];len2=line.getVertexCount();if(i>0)
{mainIndex-=1;}
for(var j=0;j<len2;j+=1)
{distance=line.getVertex(j).distanceFrom(latLng);if(distance<smallest)
{smallest=distance;index=mainIndex;}
mainIndex+=1;}}
return index;}
function actionMarkerStory(mainIndex,story)
{var params;if(app.player.playing)
{togglePlay();}
if(!app.syncMarkerStory(mainIndex,story))
{return false;}
app.infoWindow.track=true;params=app.getInfoStory(mainIndex,false);app.trackMarker.openInfoWindowHtml(params.html,params.opts);return true;}
function actionMarkerRoute(index)
{var mainIndex,story,dataIndex,html;if(app.player.playing)
{togglePlay();}
mainIndex=app.route.points[index].mainIndex;story=app.Story.getStoryFromMainIndex(mainIndex);if(story)
{actionMarkerStory(story.mainIndex,story);return;}
dataIndex=app.syncMarkerRoute(index);html=app.getInfoRoute(index);if(app.route.useIndex)
{app.hideMarkers(app.route.points[index].mainIndex);app.trackMarker.openInfoWindowHtml(html);app.infoWindow.track=(dataIndex!==undefined);}
else
{app.route.markers[index].openInfoWindowHtml(html);app.infoWindow.track=false;}}
function actionMarkerTrack()
{var story,routeIndex,params;if(app.player.playing)
{togglePlay();}
if(app.markerMap.active)
{if(app.markerMap.type===app.constants.TP_ROUTE)
{actionMarkerRoute(app.markerMap.index);return;}
else if(app.markerMap.type===app.constants.TP_STORY)
{story=app.Story.getStoryFromMainIndex(app.markerMap.index);if(story)
{actionMarkerStory(app.markerMap.index,story);return;}
else
{routeIndex=app.getRouteIndex("mainIndex",app.markerMap.index);if(routeIndex!==undefined)
{actionMarkerRoute(routeIndex);}
else
{app.unmapMarker();}
return;}}}
if(app.route.useIndex)
{routeIndex=app.getRouteIndex("dataIndex",app.data.index);if(routeIndex!==undefined)
{actionMarkerRoute(routeIndex);return;}}
app.infoWindow.track=true;params=app.getInfoTrack(app.data.index,false);app.trackMarker.openInfoWindowHtml(params.html,params.opts);}
function actionIWClose()
{if(!app.infoWindow.refreshing)
{if(app.Story.iwEditId!==undefined)
{app.Story.cmdClosedEdit();}
app.showHiddenMarkers();}
else
{app.infoWindow.refreshing=false;}}
function actionIWOpen()
{app.infoWindow.refreshing=false;}
function actionSelTrack()
{this.blur();var value=this.options[this.selectedIndex].value;app.showTrack(value);}
function actionSelMap()
{var mapSelect,mapIndex,mapType,arMaps,registered,i,len;mapSelect=get("mapSelect");mapSelect.blur();mapIndex=mapSelect.selectedIndex;mapType=app.getMapType(mapIndex);arMaps=map.getMapTypes();registered=false;for(i=0,len=arMaps.length;i<len;i+=1)
{if(arMaps[i]===mapType)
{registered=true;break;}}
if(!registered)
{map.addMapType(mapType);}
map.setMapType(mapType);}
function changeShowWork(index,changeTrack)
{var latLng,sel,err;if(app.highlights[index].dataIndex!==-1)
{app.data.index=app.highlights[index].dataIndex;}
latLng=app.gLatLngFromData(app.data.index);if(!app.view.atDefault)
{map.panTo(latLng);}
app.updateMarkerEx(latLng,{moveSlider:1,changeShow:1});if(changeTrack)
{app.showTrack(app.highlights[index].track,{fromShow:true});sel=get("showSelect");sel.options[sel.selectedIndex].text=app.highlights[index].title;sel.style.fontWeight="normal";sel.disabled=false;document.body.style.cursor="auto";}}
function actionSelShow()
{var index,iw;this.blur();index=this.selectedIndex;if(app.highlights[index].dataIndex<0)
{app.updateShowSelect();return;}
iw=app.iwState();if(iw.editing)
{app.updateShowSelect();return;}
if(iw.showing)
{map.closeInfoWindow();}
if(app.highlights[index].track&&app.highlights[index].track!==app.Polylines.active)
{this.options[index].text="Loading...";this.style.fontWeight="bold";this.disabled=true;document.body.style.cursor="wait";setTimeout(function()
{changeShowWork(index,true);},1);}
else
{changeShowWork(index,false);}}
function actionSelUnits()
{if(this.selectedIndex!==undefined)
{this.blur();app.Units.setCurrentIndex(this.selectedIndex);}
app.writeScale();app.refreshUnits();app.refreshData();app.refreshInfoWindow();}
function actionCbZoomTo()
{var iw,zoom,latLng;this.blur();iw=app.iwState(true);if(this.checked)
{zoom=app.flight.zoomToZoom;latLng=app.gLatLngFromData(app.data.index);}
else
{zoom=app.flight.zoom;latLng=app.flight.boundsCenter;}
if(iw.showing)
{map.setZoom(zoom);}
else
{map.setCenter(latLng,zoom);}}
function actionCbDefault()
{var iw;this.blur();iw=app.iwState(true);if(iw.editing)
{if(!confirm("You will lose changes to the story you are entering."))
{app.toggleCheckbox(this.id,true,!this.checked);return;}
else
{app.Story.cmdClosedEdit();}}
if(iw.showing)
{map.closeInfoWindow();}
if(!map.getInfoWindow().isHidden())
{map.closeInfoWindow();}
if(map.getZoom()===app.flight.zoom)
{map.panTo(app.flight.boundsCenter);}
else
{map.setCenter(app.flight.boundsCenter,app.flight.zoom);}}
function actionCbRoute()
{this.blur();app.showRoute(this.checked);}
function actionCbStoryboard()
{this.blur();app.Story.showMarkers(this.checked,true);}
function actionClickMoreDetail()
{this.blur();app.disableMap();GDownloadUrl(app.trackFile,GEvent.callback(app,app.processDownload));}
function actionClickPoly(latLng)
{var iw,name,index;iw=app.iwState();if(iw.editing)
{return;}
name=app.Polylines.active;index=closestVertex(name,latLng);if(index!==undefined)
{if(index!==app.data.index)
{app.data.index=index;app.updateMarker(app.gLatLngFromData(index));}}}
function actionClickTab()
{this.blur();app.Tabs.selectTab(this);return false;}
function actionClickTabNote()
{this.blur();var content=get(this.id+"-content");var caption=get(this.id+"-caption");if(content.style.visibility==="hidden")
{content.style.visibility="visible";caption.innerHTML="Hide";}
else
{content.style.visibility="hidden";caption.innerHTML="Show";}
return false;}
function actionSelStatsUnits()
{this.blur();var ar=this.id.split("-");if(ar.length!==4)
{return;}
app.Tabs.refreshStatsData(ar[2],this.selectedIndex);}
function actionSelOptions()
{var ar,name,option,check;this.blur();ar=this.id.split("-");if(ar.length!==4)
{return;}
else
{name=ar[2];option=ar[3];}
app.Options.setOption(name,option,this.selectedIndex);check=app.Options.isDefault(name);app.Tabs.refreshOptionsDefault(name,check);}
function actionCbOptionsDefault()
{this.blur();var ar=this.id.split("-");if(ar.length!==4)
{return;}
app.Tabs.refreshOptionsSelects(ar[2],false);app.Tabs.refreshOptionsDefault(ar[2]);}
function actionDragSlider()
{var index,latLng;if(!app.player.enabled)
{return;}
index=app.getDataIndexFromSlider();if(index!==app.data.index)
{latLng=app.gLatLngFromData(index);app.data.index=index;if(!app.view.innerBounds.containsLatLng(latLng))
{map.panTo(latLng);if(app.player.playing)
{app.player.panning=true;return;}}
app.updateMarkerEx(latLng);}}
function actionClickSliderBack()
{this.blur();if(app.player.playing)
{return;}
if(app.data.index-1<0)
{return;}
else
{app.data.index-=1;}
app.stepTrack(true);}
function actionClickSliderNext()
{this.blur();if(app.player.playing)
{return;}
if(app.data.index+1>app.player.dataMax)
{return;}
else
{app.data.index+=1;}
app.stepTrack(true);}
function actionMsOverSlider()
{if(!app.player.playing)
{this.style.cursor="pointer";}}
function actionMsOverSpeed()
{if(app.player.playing)
{this.style.cursor="pointer";}}
function actionMsOutButton()
{this.style.cursor="default";}
function actionClickSpeedDown()
{alert("down");}
function actionClickSpeedUp()
{alert("up");}
function actionClickRouteZoom(index)
{var latLng;this.blur();if(!map.getInfoWindow().isHidden())
{map.closeInfoWindow();}
latLng=app.gLatLngFromArray(app.route.points[index].latLon);map.setCenter(latLng,app.flight.zoomToZoom);actionMarkerRoute(index);}
function hideMessage()
{var el=get("loading");el.style.display="none";el.style.visibility="hidden";}
function showMessage(params)
{var el;if(params.title)
{el=get("loadingTitle");el.innerHTML=params.title;}
el=get("loadingMsg");if(!params.error)
{el.style.color="black";}
else
{el.style.color="red";}
el.innerHTML=params.msg;el=get("loading");if(el.display!=="block")
{el.style.display="block";el.style.visibility="visible";}
if(params.error&&!app.Tabs.enabled)
{app.Tabs.enableTabs();}}
function XcMapTypeControl()
{}
function createXcMapTypeControl()
{XcMapTypeControl.prototype=new GControl();XcMapTypeControl.prototype.initialize=function(map)
{var container=document.createElement("div");var select=document.createElement("select");select.id="mapSelect";select.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";select.style.fontSize="10px";select.style.fontWeight="normal";select.style.color="#000";select.style.backgroundColor="#fff";select.width="115px";var option=document.createElement("option");option.text="Map";option.value=0;select.options.add(option);option=document.createElement("option");option.text="Satellite Map";option.value=1;select.options.add(option);option=document.createElement("option");option.text="Hybrid Map";option.value=2;select.options.add(option);option=document.createElement("option");option.text="Terrain Map";option.value=3;select.options.add(option);select.selectedIndex=0;select.title="Select background map type";container.appendChild(select);map.getContainer().appendChild(container);return container;};XcMapTypeControl.prototype.getDefaultPosition=function()
{return new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,7));};}
function XcData(data,trackData)
{this.storage=data;this.trackData=trackData;this.type=trackData.info.main.type;}
XcData.prototype.getData=function()
{if(this.type===0)
{this.processData();}
else if(this.type===1)
{this.decodeData();}
return this.setStatus();};XcData.prototype.processData=function()
{this.storage.mainIndex=this.processWork(app.constants.DATA_MAIN_INDEX);this.storage.time=this.processWork(app.constants.DATA_TIME);this.getSecs();this.storage.height=this.processWork(app.constants.DATA_HEIGHT);this.storage.climb=this.processWork(app.constants.DATA_CLIMB);this.storage.speed=this.processWork(app.constants.DATA_SPEED);this.storage.distance=this.processWork(app.constants.DATA_DISTANCE);this.storage.points=this.processWork(app.constants.DATA_POINTS);};XcData.prototype.processWork=function(name)
{var ar=[];if(!this.trackData[name]||!isArray(this.trackData[name]))
{return ar;}
else
{return this.trackData[name];}};XcData.prototype.decodeData=function(old)
{var ar;this.storage.mainIndex=this.decode(app.constants.DATA_MAIN_INDEX);ar=this.decode(app.constants.DATA_TIME);this.convertSecsToTime(ar);this.storage.height=this.decode(app.constants.DATA_HEIGHT);this.storage.climb=this.decode(app.constants.DATA_CLIMB);this.storage.speed=this.decode(app.constants.DATA_SPEED);this.storage.distance=this.decode(app.constants.DATA_DISTANCE);this.storage.points=this.decodePolyline(this.trackData.points);};XcData.prototype.setStatus=function()
{var status=0;if(!this.checkData("points")||!this.checkData(app.constants.DATA_TIME)||!this.checkData(app.constants.DATA_DISTANCE))
{return status;}
if(!this.checkData(app.constants.DATA_SPEED))
{status=1;}
else
{if(!this.checkData(app.constants.DATA_HEIGHT))
{status=2;}
else
{if(this.checkData(app.constants.DATA_CLIMB))
{status=3;}}}
return status;};XcData.prototype.checkData=function(data)
{return(this.storage[data]&&this.storage[data].length>1);};XcData.prototype.decode=function(name)
{var ar,encoded,precision,offset;ar=[];if(!this.trackData[name])
{return ar;}
precision=parseInt(this.trackData[name].charAt(0),10);offset=parseInt(this.trackData[name].charAt(1),10);encoded=this.trackData[name].substr(2);ar=this.decodeNumbers(encoded,precision,offset);return ar;};XcData.prototype.decodePolyline=function(encoded)
{var len,index,ar,lat,lng,b,shift,result,dlat,dlng;len=0;index=0;ar=[];lat=0;lng=0;if(encoded)
{len=encoded.length;}
while(index<len)
{shift=0;result=0;do
{b=encoded.charCodeAt(index)-63;index+=1;result|=(b&31)<<shift;shift+=5;}while(b>=32);dlat=result&1?~(result>>1):result>>1;lat+=dlat;shift=0;result=0;do
{b=encoded.charCodeAt(index)-63;index+=1;result|=(b&31)<<shift;shift+=5;}while(b>=32);dlng=result&1?~(result>>1):result>>1;lng+=dlng;ar[ar.length]=[lat*1e-5,lng*1e-5];}
return ar;};XcData.prototype.decodeNumbers=function(encoded,precision,offset)
{var len,index,ar,arIndex,num,dNum,b,shift,result,x;len=0;index=0;ar=[];arIndex=0;num=0;x=Math.pow(10,precision);if(encoded)
{len=encoded.length;}
while(index<len)
{shift=0;result=0;do
{b=encoded.charCodeAt(index)-63;index+=1;result|=(b&31)<<shift;shift+=5;}while(b>=32);dNum=result&1?~(result>>1):result>>1;num=offset?num+dNum:dNum;ar[arIndex]=precision?Math.round(num)/x:num;arIndex+=1;}
return ar;};XcData.prototype.convertSecsToTime=function(arSecs)
{var len,start,i;len=arSecs.length;if(!len)
{return;}
start=arSecs[0];this.storage.time[0]=timeFromSecs(start);this.storage.secs[0]=0;for(i=1;i<len;i+=1)
{this.storage.time[i]=timeFromSecs(arSecs[i]);this.storage.secs[i]=arSecs[i]-start;}};XcData.prototype.getSecs=function()
{var start,i,len,ar,secs;if(!this.storage.time[0])
{return;}
start=this.hmsToSecs(this.storage.time[0]);this.storage.secs[0]=0;len=this.storage.time.length;for(i=1;i<len;i+=1)
{secs=this.hmsToSecs(this.storage.time[i]);if(secs===undefined)
{this.storage.secs[i]=-1;}
else
{if(secs<start)
{secs+=86400;}
this.storage.secs[i]=secs-start;}}};XcData.prototype.hmsToSecs=function(hms)
{var ar,h,m,s;if(!hms)
{return;}
ar=hms.split(":");if(ar.length!==3)
{return;}
h=parseInt(ar[0],10);if(isNaN(h)||h<0||h>23)
{return;}
m=parseInt(ar[1],10);if(isNaN(m)||m<0||m>59)
{return;}
s=parseInt(ar[2],10);if(isNaN(s)||s<0||s>59)
{return;}
return(h*3600)+(m*60)+s;};function XcPolyEncoder()
{this.data=[];this.points=[];this.colorMap={from:0,to:0,from2:0,to2:0};this.highlights=[];this.max=0;this.min=0;this.name="";this.polyMax=100;this.polyMin=80;this.deltaValue=0;this.deltaStep=0;this.deltaSecs=false;this.secs=[];this.result=[];}
XcPolyEncoder.prototype.getPolyline=function(data,name,stats)
{var prop,secsDelta;this.name=name;this.data=data[name];this.points=data.points;this.secs=data.secs;this.createColorMap(name);if(!app.checkAppStatus(name))
{return this.writePolylineSingle();}
this.min=stats[name].min.value;this.max=stats[name].max.value;for(prop in stats[name])
{if(stats[name].hasOwnProperty(prop))
{this.highlights[stats[name][prop].index]=stats[name][prop].value;}}
if(name===app.constants.DATA_HEIGHT)
{this.deltaValue=100;this.deltaStep=20;return this.writePolylinesDelta();}
else
{if(name===app.constants.DATA_CLIMB)
{this.deltaValue=1.0;this.deltaStep=0.2;}
else if(name===app.constants.DATA_SPEED)
{this.deltaValue=10;this.deltaStep=2;}
secsDelta=Math.round(stats.duration/this.polyMax);return this.writePolylinesSecs(secsDelta);}};XcPolyEncoder.prototype.rgbInRange=function(value,low,high)
{var red=0;var green=0;var blue=0;var factor=0;var brightness=1;var nano=Math.round(low+(value*(high-low)));if(nano>=380&&nano<=439)
{red=-(nano-440)/(440-380);blue=1;}
else if(nano>=440&&nano<=489)
{green=(nano-440)/(490-440);blue=1;}
else if(nano>=490&&nano<=509)
{green=1;blue=-(nano-510)/(510-490);}
else if(nano>=510&&nano<=579)
{green=1;red=(nano-510)/(580-510);}
else if(nano>=580&&nano<=644)
{red=1;green=-(nano-645)/(645-580);}
else if(nano>=645)
{red=1;green=0;}
if(nano>=380&&nano<=419)
{factor=0.3+0.7*(nano-380)/(420-380);}
else if(nano>=420&&nano<=700)
{factor=1;}
else if(nano>=701&&nano<=780)
{factor=0.3+0.7*(780-nano)/(780-700);}
else if(nano>=780)
{factor=0;}
red=Math.floor(this.adjustNano(red,factor,brightness));green=Math.floor(this.adjustNano(green,factor,brightness));blue=Math.floor(this.adjustNano(blue,factor,brightness));var r="#";if(red<16)
{r+="0";}
r+=red.toString(16);if(green<16)
{r+="0";}
r+=green.toString(16);if(blue<16)
{r+="0";}
r+=blue.toString(16);return r;};XcPolyEncoder.prototype.adjustNano=function(color,factor,brightness)
{var gamma=0.8;if(color===0)
{return 0;}
return 255*Math.pow(color*factor*brightness,gamma);};XcPolyEncoder.prototype.createColorMap=function(name)
{var blue=440;var cyan=490;var yellow=580;var red=645;if(name===app.constants.DATA_HEIGHT)
{this.colorMap.low=red;this.colorMap.high=blue;}
else if(name===app.constants.DATA_CLIMB)
{this.colorMap.low=yellow;this.colorMap.high=red;this.colorMap.low2=cyan;this.colorMap.high2=blue;}
else if(name===app.constants.DATA_SPEED)
{this.colorMap.low=blue;this.colorMap.high=red;}};XcPolyEncoder.prototype.writePolylinesDelta=function()
{var arPoints=[];var writeData=false;var value=0;var gLatLngs;var forceWrite=false;var repeat="none";var count=0;var len=this.points.length;var lastValue;var color="";var delta=this.deltaValue;while(true)
{for(var i=0;i<len;i+=1)
{arPoints[arPoints.length]={point:this.points[i],index:i};if(i===0)
{lastValue=this.data[0];if(this.name===app.constants.DATA_HEIGHT)
{color=this.getColor(this.data[0]);}
continue;}
if(i===len-2)
{continue;}
else if(i===len-1)
{writeData=true;if(this.name===app.constants.DATA_HEIGHT)
{color=this.getColor(this.data[i]);}}
else if(this.highlights[i]!==undefined)
{forceWrite=true;continue;}
else
{if(forceWrite)
{writeData=true;forceWrite=false;}
else
{value=Math.abs(lastValue-this.data[i]);writeData=(value>=delta&&arPoints.length>2);}}
if(writeData)
{if(!color)
{color=this.getColorFromHighlights(arPoints);if(!color)
{color=this.getColorFromMedian(arPoints,true);}}
gLatLngs=this.getGLatLngs(arPoints);this.result[this.result.length]={gLatLngs:gLatLngs,color:color};arPoints=[{point:this.points[i],index:i}];lastValue=this.data[i];color="";}
if(this.result.length>this.polyMax)
{break;}}
if(this.result.length>this.polyMax)
{if(this.name!==app.constants.DATA_HEIGHT&&count===0)
{return false;}
if(count>0&&repeat==="deltaDown")
{repeat="break";delta-=this.deltaStep;}
else
{repeat="deltaUp";delta+=this.deltaStep;}}
else if(this.result.length<this.polyMin)
{if(count>0)
{if(repeat==="deltaUp")
{break;}
else
{if(delta<=this.deltaValue-(this.deltaStep*2))
{break;}
else
{repeat="deltaDown";delta-=this.deltaStep;}}}
else if(repeat==="break")
{break;}
else
{repeat="deltaDown";delta-=this.deltaStep;}}
else
{repeat="";}
if(repeat)
{count+=1;this.result=[];arPoints=[];}
else
{this.deltaValue=delta;break;}
if(count>40)
{return false;}}
return true;};XcPolyEncoder.prototype.writePolylinesSecs=function(secsDelta)
{var arPoints=[];var writeData=false;var value=0;var lastValue=0;var gLatLngs;var forceWrite=false;var len=this.points.length;var duration=0;var startSecs=0;var color="";if(this.writePolylinesDelta())
{return true;}
else
{this.result=[];}
this.deltaValue=secsDelta;this.deltaSecs=true;for(var i=0;i<this.points.length;i+=1)
{arPoints[arPoints.length]={point:this.points[i],index:i};duration=this.secs[i]-startSecs;if(i===0)
{lastValue=this.data[0];continue;}
if(i===len-2)
{continue;}
else if(i===len-1)
{writeData=true;}
else if(this.highlights[i]!==undefined)
{forceWrite=true;continue;}
else
{if(forceWrite)
{writeData=true;forceWrite=false;}
else
{value=Math.abs(lastValue-this.data[i]);writeData=(duration>=this.deltaValue&&arPoints.length>2);}}
if(writeData)
{if(!color)
{color=this.getColorFromHighlights(arPoints);if(!color)
{if(this.name===app.constants.DATA_SPEED)
{color=this.getColorFromMedian(arPoints);}
else
{color=this.getColorFromAverage(arPoints);}}}
gLatLngs=this.getGLatLngs(arPoints);this.result[this.result.length]={gLatLngs:gLatLngs,color:color};arPoints=[{point:this.points[i],index:i}];color="";duration=0;startSecs=this.secs[i];}}
return true;};XcPolyEncoder.prototype.writePolylineSingle=function()
{var i,len,color,gLatLngs;color=this.getColor(0);gLatLngs=[];for(i=0,len=this.points.length;i<len;i+=1)
{gLatLngs[i]=app.gLatLngFromArray(this.points[i]);}
this.result[0]={gLatLngs:gLatLngs,color:color};return len>1;};XcPolyEncoder.prototype.getColorFromHighlights=function(ar)
{var result="";var len=ar.length;for(var i=0;i<len;i+=1)
{if(this.highlights[ar[i].index]!==undefined)
{result=this.getColor(this.highlights[ar[i].index]);break;}}
return result;};XcPolyEncoder.prototype.getColorFromAverage=function(ar)
{var len=ar.length;var value=0;for(var i=0;i<len;i+=1)
{value+=this.data[ar[i].index];}
return this.getColor(value/len);};XcPolyEncoder.prototype.getColorFromMedian=function(ar)
{var medArray=[];var len=ar.length;for(var i=0;i<len;i+=1)
{medArray[i]=this.data[ar[i].index];}
medArray.sort(function(a,b)
{return a-b;});var h=Math.floor(len/2);if(len%2===0)
{return this.getColor((medArray[h+1]+medArray[h])/2);}
else
{return this.getColor(medArray[h]);}};XcPolyEncoder.prototype.getColorFromValues=function(ar,max)
{var len=ar.length;var value=this.data[ar[0].index];for(var i=0;i<len;i+=1)
{if(max!==undefined&&max===true)
{if(value>this.data[ar[i].index])
{value=this.data[ar[i].index];}}
else
{if(value<this.data[ar[i].index])
{value=this.data[ar[i].index];}}}
return this.getColor(value);};XcPolyEncoder.prototype.getColor=function(value)
{var valueDiff;var negative=false;var valueRelPos=0;var max=this.max;var min=this.min;if(value>max)
{value=max;}
else if(value<min)
{value=min;}
if(this.name===app.constants.DATA_CLIMB)
{negative=value<=0;if(!negative)
{min=0;}
else
{max=min*-1;min=0;value=value*-1;}}
valueDiff=max-min;if(valueDiff>0)
{valueRelPos=(value-min)/(valueDiff);}
if(negative)
{return this.rgbInRange(valueRelPos,this.colorMap.low2,this.colorMap.high2);}
else
{return this.rgbInRange(valueRelPos,this.colorMap.low,this.colorMap.high);}
var index=Math.floor((this.gradientMap.length-1)*valueRelPos);return this.gradientMap[index];};XcPolyEncoder.prototype.pointsToGLatLngs=function(points)
{var gLatLngs=[];for(var i=0;i<points.length;i+=1)
{gLatLngs[gLatLngs.length]=new GLatLng(points[i][0],points[i][1]);}
return gLatLngs;};XcPolyEncoder.prototype.getGLatLngs=function(ar)
{var gLatLngs=[];var len=ar.length;for(var i=0;i<len;i+=1)
{gLatLngs[i]=new GLatLng(ar[i].point[0],ar[i].point[1]);}
return gLatLngs;};function XcPolyline()
{this.active="";this.supportsHide=undefined;this.lines={};this.lines.height=[];this.lines.climb=[];this.lines.speed=[];this.polyEvents={};this.polyEvents.height=[];this.polyEvents.climb=[];this.polyEvents.speed=[];this.route=null;this.routeCylinders=[];this.routeShowing=false;}
XcPolyline.prototype.showPolyline=function(name,stats)
{var newPoly,routeShowing,i,len,poly,event;if(this.active===name)
{return false;}
newPoly=false;if(this.lines[name].length===0)
{newPoly=true;if(!this.createPolyline(name,stats))
{return false;}}
if(this.active)
{this.hidePolyline(this.active);}
routeShowing=this.routeShowing;if(routeShowing)
{this.toggleRoute(false);}
for(i=0,len=this.lines[name].length;i<len;i+=1)
{poly=this.lines[name][i];if(newPoly||!this.supportsHide)
{map.addOverlay(this.lines[name][i]);event=GEvent.addListener(poly,'click',actionClickPoly);this.polyEvents[name][this.polyEvents[name].length]=event;}
else
{poly.show();}}
this.active=name;if(routeShowing)
{this.toggleRoute(true);}
return true;};XcPolyline.prototype.createPolyline=function(name,stats)
{var Encoder,ar,i,len,poly;Encoder=new XcPolyEncoder();if(!Encoder.getPolyline(app.data,name,stats))
{return false;}
ar=Encoder.result;for(i=0,len=ar.length;i<len;i+=1)
{poly=new GPolyline(ar[i].gLatLngs,ar[i].color,4,0.999999);this.lines[name][this.lines[name].length]=poly;}
if(this.supportsHide===undefined&&len)
{this.supportsHide=poly.supportsHide();}
return len>0;};XcPolyline.prototype.hidePolyline=function(name)
{if(this.lines[name].length===0)
{return;}
for(var i=0;i<this.lines[name].length;i+=1)
{if(this.supportsHide)
{this.lines[name][i].hide();}
else
{map.removeOverlay(this.lines[name][i]);GEvent.removeListener(this.polyEvents[name][i]);}}
if(!this.supportsHide)
{this.polyEvents[name]=[];}};XcPolyline.prototype.destroyPolylines=function()
{var name,i,len;for(name in this.lines)
{if(this.lines.hasOwnProperty(name))
{for(i=0,len=this.lines[name].length;i<len;i+=1)
{map.removeOverlay(this.lines[name][i]);GEvent.removeListener(this.polyEvents[name][i]);}
this.lines[name]=[];this.polyEvents[name]=[];}}
this.active="";};XcPolyline.prototype.createRoute=function(route)
{var gLatLngs,i,len;gLatLngs=[];for(i=0,len=route.points.length;i<len;i+=1)
{gLatLngs[i]=app.gLatLngFromArray(route.points[i].latLon);if(route.points[i].cylinder)
{this.addCylinder(gLatLngs[i],route.points[i].cylinder);}}
if(route.startFinish)
{gLatLngs[gLatLngs.length]=app.gLatLngFromArray(route.points[0].latLon);}
if(gLatLngs.length>1)
{this.route=new GPolyline(gLatLngs,"#ff0000",2,0.6);}
return gLatLngs;};XcPolyline.prototype.toggleRoute=function(show)
{var i,len;if(show)
{map.addOverlay(this.route);}
else
{map.removeOverlay(this.route);}
for(i=0,len=this.routeCylinders.length;i<len;i+=1)
{if(show)
{map.addOverlay(this.routeCylinders[i]);}
else
{map.removeOverlay(this.routeCylinders[i]);}}
this.routeShowing=show;};XcPolyline.prototype.addCylinder=function(cnt,radius)
{var latC,lngC,points,i,lat,lng,poly;radius=radius/1000;latC=cnt.distanceFrom(new GLatLng(cnt.lat()+0.1,cnt.lng()))/100;lngC=cnt.distanceFrom(new GLatLng(cnt.lat(),cnt.lng()+0.1))/100;points=[];for(i=0;i<=360;i+=10)
{lat=cnt.lat()+radius/latC*Math.cos(i*Math.PI/180);lng=cnt.lng()+radius/lngC*Math.sin(i*Math.PI/180);points[points.length]=new GLatLng(lat,lng);}
poly=new GPolygon(points,"#ff0000",1,0.9,"#ff0000",0.2);this.routeCylinders[this.routeCylinders.length]=poly;};function XcUnits(heightMetres)
{this.heightMetres=heightMetres;this.currentIndex=0;this.playerIndex=0;this.data=[];this.captions=[];this.names={};this.setNamesAndCaptions();}
XcUnits.prototype.setNamesAndCaptions=function()
{this.names.height=app.constants.DATA_HEIGHT;this.names.climb=app.constants.DATA_CLIMB;this.names.speed=app.constants.DATA_SPEED;this.names.distance=app.constants.DATA_DISTANCE;var base={};base[this.names.height]={text:"metres",shortText:"m"};base[this.names.climb]={text:"m/sec",shortText:"m/s"};base[this.names.speed]={text:"km/h"};base[this.names.distance]={text:"km"};this.captions[app.constants.UNITS_METRIC]=base;base={};base[this.names.height]={text:"feet",shortText:"ft"};base[this.names.climb]={text:"ft/min",shortText:"ft/m"};base[this.names.speed]={text:"mph"};base[this.names.distance]={text:"miles"};this.captions[app.constants.UNITS_IMPERIAL]=base;base={};base[this.names.climb]={text:"knots",shortText:"kts"};base[this.names.speed]={text:"knots",shortText:"kts"};this.captions[app.constants.UNITS_KNOTS]=base;};XcUnits.prototype.init=function(first)
{var arUnits,stdLength;arUnits=[];if(first)
{arUnits=this.getDefaultUnits();this.writeData(arUnits,"Default");if(!this.heightMetres)
{arUnits=this.getUnits(app.constants.UNITS_METRIC);this.writeData(arUnits,"Metric");}
arUnits=this.getUnits(app.constants.UNITS_IMPERIAL);this.writeData(arUnits,"Imperial");}
else
{stdLength=2;if(!this.heightMetres)
{stdLength+=1;}
if(this.data.length>stdLength)
{this.data.pop();}}
arUnits=this.getUnitsToSave();if(arUnits.length===1)
{if(arUnits[0]===app.constants.OPTS_UNITS_DEFAULT)
{this.currentIndex=0;}
if(arUnits[0]===app.constants.OPTS_UNITS_METRIC)
{this.currentIndex=this.data.length-2;}
if(arUnits[0]===app.constants.OPTS_UNITS_IMPERIAL)
{this.currentIndex=this.data.length-1;}}
else
{this.writeData(arUnits,"Custom");this.currentIndex=this.data.length-1;}
this.playerIndex=this.currentIndex;};XcUnits.prototype.writeData=function(arUnits,text)
{var data,i,name;data={text:text};i=0;for(name in this.names)
{if(this.names.hasOwnProperty(name)&&arUnits[i]!==undefined)
{data[name]=arUnits[i];i+=1;}}
this.data[this.data.length]=data;};XcUnits.prototype.ucFirst=function(value)
{if(!value)
{return"";}
var start=value.substring(0,1);var end=value.substring(1);return start.toUpperCase()+end;};XcUnits.prototype.getUnitsToSave=function()
{var arUnits=[];var units,test;units=app.Options.units.join();test=this.getDefaultUnits(true);if(units===test)
{arUnits[0]=app.constants.OPTS_UNITS_DEFAULT;return arUnits;}
test=this.getUnits(app.constants.UNITS_METRIC,true);if(units===test)
{arUnits[0]=app.constants.OPTS_UNITS_METRIC;return arUnits;}
test=this.getUnits(app.constants.UNITS_IMPERIAL,true);if(units===test)
{arUnits[0]=app.constants.OPTS_UNITS_IMPERIAL;return arUnits;}
return app.Options.units;};XcUnits.prototype.getFullUnits=function(value)
{var arUnits=[];if(value===app.constants.OPTS_UNITS_METRIC)
{arUnits=this.getUnits(app.constants.UNITS_METRIC);}
else if(value===app.constants.OPTS_UNITS_IMPERIAL)
{arUnits=this.getUnits(app.constants.UNITS_IMPERIAL);}
else
{arUnits=this.getDefaultUnits();}
return arUnits;};XcUnits.prototype.getDefaultUnits=function(string)
{var ar=[];var h,x;if(this.heightMetres)
{h=app.constants.UNITS_METRIC;}
else
{h=app.constants.UNITS_IMPERIAL;}
x=app.constants.UNITS_METRIC;ar=[h,x,x,x];if(string)
{return ar.join();}
else
{return ar;}};XcUnits.prototype.getUnits=function(value,string)
{var ar=[];ar=[value,value,value,value];if(string)
{return ar.join();}
else
{return ar;}};XcUnits.prototype.getFullData=function(name,value,bold)
{var uFlag,caption,data;var result={name:"",value:""};uFlag=this.getUnitFlag(name);caption=this.getCaptionShort(name,uFlag);data=this.formatData(value,name);result.name=this.ucFirst(name);if(!bold)
{result.value=data+" "+caption;}
else
{result.value="<b>"+data+"</b> "+caption;}
return result;};XcUnits.prototype.metric=function(data,name)
{var digits=0;if(name!==app.constants.DATA_HEIGHT)
{digits=1;}
return data.toFixed(digits);};XcUnits.prototype.imperial=function(data,name)
{var value;if(name===app.constants.DATA_HEIGHT)
{return Math.round(data*3.2808399);}
if(name===app.constants.DATA_CLIMB)
{return Math.round((data*3.2808399)*60);}
if(name===app.constants.DATA_SPEED)
{value=data*0.621371192;return value.toFixed(1);}
if(name===app.constants.DATA_DISTANCE)
{value=data*0.621371192;return value.toFixed(1);}};XcUnits.prototype.knots=function(data,name)
{var value;if(name===app.constants.DATA_CLIMB)
{value=(data/1.852)*3.6;}
else if(name===app.constants.DATA_SPEED)
{value=data/1.852;}
else
{value=0;}
return value.toFixed(1);};XcUnits.prototype.getCaption=function(name,uFlag)
{if(uFlag===undefined)
{uFlag=this.data[this.playerIndex][name];}
var result=this.captions[uFlag][name].text;if(!result)
{result="";}
return result;};XcUnits.prototype.getCaptionShort=function(name,uFlag)
{if(uFlag===undefined)
{uFlag=this.data[this.playerIndex][name];}
var result=this.captions[uFlag][name].shortText;if(!result)
{result=this.getCaption(name,uFlag);}
return result;};XcUnits.prototype.formatData=function(data,name,params)
{var uFlag=this.data[this.playerIndex][name];var forScale=false;if(typeof params==="object")
{if(params.uFlag!==undefined)
{uFlag=params.uFlag;}
if(params.forScale!==undefined)
{forScale=params.forScale;}}
var func="metric";if(uFlag===app.constants.UNITS_IMPERIAL)
{func="imperial";}
else if(uFlag===app.constants.UNITS_KNOTS)
{func="knots";}
if(func==="metric"&&!forScale)
{return data;}
else
{return this[func](data,name);}};XcUnits.prototype.getUnitFlag=function(name,forCurrent)
{var index=this.playerIndex;if(forCurrent!==undefined)
{index=this.currentIndex;}
return this.data[index][name];};XcUnits.prototype.getUnitsDisplayTable=function()
{var s,height,climb,speed,distance;height=this.getCaption(app.constants.DATA_HEIGHT);climb=this.getCaption(app.constants.DATA_CLIMB);speed=this.getCaption(app.constants.DATA_SPEED);distance=this.getCaption(app.constants.DATA_DISTANCE);s="<table class=\"mapDataTable1\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100\"><tbody>";s+="<tr><td class=\"tblLabelIt\">Height:</td><td>"+height+"</td></tr>";s+="<tr><td class=\"tblLabelIt\">Climb:</td><td>"+climb+"</td></tr>";s+="<tr><td class=\"tblLabelIt\">Speed:</td><td>"+speed+"</td></tr>";s+="<tr><td class=\"tblLabelIt\">Distance:</td><td>"+distance+"</td></tr>";s+="</tbody></table>";return s;};XcUnits.prototype.writeUnitsSelect=function()
{var sel=get("unitsSelect");if(!sel)
{return;}
var len=this.data.length;sel.options.length=len;for(var i=0;i<len;i+=1)
{sel.options[i].value=i;sel.options[i].text=this.data[i].text;}
sel.selectedIndex=this.playerIndex;};XcUnits.prototype.setCurrentIndex=function(index)
{this.playerIndex=index;};function XcTabs()
{this.stats={};this.enabled=false;this.lastUnits="";this.noContent={};this.storyStatus=0;this.activeColor="#F9893E";this.inactiveColor="#007070";this.emptyColor="#ccc";this.id="xcTabNav";this.linkClass="xcTabLink";this.activeClass="xcTabActive";this.baseId="xcTab";this.tabIds=["map","player","charts","stats","story","opts","help"];this.activeTabId="";this.playerTabId=this.getTabId(this.tabIds[1]);this.statsBaseId=this.getTabId(this.tabIds[3]);this.storyTabId=this.getTabId(this.tabIds[4]);this.optsBaseId=this.getTabId(this.tabIds[5]);}
XcTabs.prototype.init=function(stats,noContent)
{this.stats=stats;this.setActiveTab();this.setNoContent(noContent);this.setNotes();this.enableTabs(true);this.updateStatsUnits(true);this.initOptions();};XcTabs.prototype.setActiveTab=function()
{var tabId=app.Options.tabs[0];if(tabId>this.tabIds.length)
{tabId=0;}
this.activeTabId=this.getTabId(this.tabIds[tabId]);};XcTabs.prototype.setNoContent=function(arNoContent)
{if(!arNoContent)
{return;}
var tabId;for(var i=0;i<arNoContent.length;i+=1)
{tabId=this.getTabId(this.tabIds[arNoContent[i]]);this.noContent[tabId]=true;}};XcTabs.prototype.getLinkClass=function(tabId)
{if(this.noContent[tabId])
{return this.linkClassEmpty;}
else
{return this.linkClass;}};XcTabs.prototype.updateStatsUnits=function(init)
{var ar=[];var sel,index,unitsName;for(var name in this.stats)
{if(this.stats.hasOwnProperty(name))
{ar[0]=name;ar[1]="units";sel=get(this.getTabId(this.statsBaseId,ar));if(sel)
{unitsName=this.translateName(name);if(init)
{this.initStatsUnits(sel,unitsName);}
index=app.Units.getUnitFlag(unitsName,true);sel.selectedIndex=index;this.refreshStatsData(name,index);}}}};XcTabs.prototype.initStatsUnits=function(sel,name)
{sel.onchange=actionSelStatsUnits;var arOptions=[];var i,text;for(i=0;i<app.Units.captions.length;i+=1)
{if(app.Units.captions[i][name])
{text=app.Units.captions[i][name].text;arOptions[i]=app.Units.ucFirst(text);}}
sel.options.length=arOptions.length;for(i=0;i<arOptions.length;i+=1)
{sel.options[i].value=i;sel.options[i].text=arOptions[i];}};XcTabs.prototype.enableTabs=function(first)
{var lis,link,tab,visibility,display,loadPlayer,i;lis=this.getTabs();loadPlayer=(first!==undefined&&this.activeTabId===this.playerTabId);for(i=0;i<lis.length;i+=1)
{link=lis[i].firstChild;if(!loadPlayer)
{link.onclick=actionClickTab;}
if(first)
{if(link.id===this.activeTabId)
{lis[i].className=this.activeClass;visibility="visible";display="block";}
else
{visibility="hidden";display="none";}
tab=get(this.getTabId(link.id,"content"));if(tab)
{tab.style.visibility=visibility;tab.style.display=display;}}
if(!loadPlayer)
{if(lis[i].className!==this.activeClass)
{link.className=this.getLinkClass(link.id);if(!first&&link.id===this.storyTabId)
{this.setStoryTab(link);}}
else
{this.activeTabId=link.id;}}}
if(!loadPlayer)
{this.enabled=true;}
else
{app.loadXcPlayer();}};XcTabs.prototype.disableTabs=function(fromClick)
{this.enabled=false;var lis=this.getTabs();var link;for(var i=0;i<lis.length;i+=1)
{link=lis[i].firstChild;link.onclick=null;link.className="";if(lis[i].className===this.activeClass&&fromClick)
{lis[i].className="";}
if(link.id===this.storyTabId)
{link.style.color=this.emptyColor;}}};XcTabs.prototype.selectTab=function(tabLink)
{var loadPlayer,link,tab,lastTabId;if(!this.enabled)
{return;}
loadPlayer=(tabLink.id===this.playerTabId&&app.scriptUrl);if(loadPlayer)
{this.disableTabs(true);}
if(!loadPlayer)
{link=get(this.activeTabId);link.parentNode.className="";link.className=this.getLinkClass(this.activeTabId);}
tab=get(this.getTabId(this.activeTabId,"content"));if(tab)
{tab.style.visibility="hidden";tab.style.display="none";}
tabLink.parentNode.className=this.activeClass;tabLink.className="";tab=get(this.getTabId(tabLink.id,"content"));if(tab)
{tab.style.visibility="visible";tab.style.display="block";}
lastTabId=this.activeTabId;this.activeTabId=tabLink.id;if(!loadPlayer)
{this.setStoryTab(tabLink);}
if(this.activeTabId===this.optsBaseId)
{this.lastUnits=app.Options.units.join();}
if(lastTabId===this.optsBaseId)
{if(this.lastUnits!==app.Options.units.join())
{app.Units.init();if(app.data.points.length>0)
{app.Units.writeUnitsSelect();actionSelUnits();}
this.updateStatsUnits();}}
if(loadPlayer)
{setTimeout(function()
{app.loadXcPlayer();},1);}
else if(tabLink.id===this.playerTabId)
{app.iwCheckReshow();}};XcTabs.prototype.getTabs=function()
{return get(this.id).getElementsByTagName("li");};XcTabs.prototype.setStoryTab=function(param)
{var link;if(typeof param==="object")
{if(param.id===this.storyTabId)
{link=param;}}
else
{this.storyStatus=param;}
if(!link)
{link=get(this.storyTabId);}
if(this.storyStatus<=app.constants.STORY_STATUS_PUBLISHED)
{var color;if(this.activeTabId===this.storyTabId)
{color=this.activeColor;}
else
{if(this.noContent[this.storyTabId])
{color=this.emptyColor;}
else
{color=this.inactiveColor;}}
link.style.color=color;}
else if(this.storyStatus===app.constants.STORY_STATUS_PRIVATE)
{link.style.color="#70dbdb";}
else if(this.storyStatus===app.constants.STORY_STATUS_UNSAVED)
{link.style.color="#e4a138";}};XcTabs.prototype.setNotes=function()
{var ar,i,len,main,content,caption,tab,show;ar=[];for(i=0,len=this.tabIds.length;i<len;i+=1)
{ar=["notes"];show=false;show=true;tab=get(this.getTabId(this.tabIds[i]));if(tab&&tab.id)
{if(this.noContent[tab.id])
{show=true;}}
main=get(this.getTabId(this.tabIds[i],ar));if(!main)
{continue;}
ar[1]="content";content=get(this.getTabId(this.tabIds[i],ar));if(!content)
{continue;}
ar[1]="caption";caption=get(this.getTabId(this.tabIds[i],ar));if(!caption)
{continue;}
main.onclick=actionClickTabNote;if(!show)
{content.style.visibility="hidden";caption.innerHTML="Show";}}};XcTabs.prototype.getTabId=function(tabId,params)
{var s="";if(params)
{if(typeof(params)==="string")
{s=params;}
else
{s=params.join("-");}
s="-"+s;}
if(tabId.indexOf("-")>=0)
{return tabId+s;}
else
{return this.baseId+"-"+tabId+s;}};XcTabs.prototype.isPlayerTab=function()
{return(this.activeTabId===this.playerTabId);};XcTabs.prototype.refreshStatsData=function(name,uFlag)
{var unitsName=this.translateName(name);if(uFlag===undefined)
{uFlag=app.Units.getUnitFlag(name,true);}
var caption=app.Units.getCaptionShort(unitsName,uFlag);var id,td,data,s;var params={uFlag:uFlag};for(var prop in this.stats[name])
{if(this.stats[name].hasOwnProperty(prop))
{id=this.statsBaseId+"-"+name+"-"+prop;td=get(id);if(td)
{data=app.Units.formatData(this.stats[name][prop],unitsName,params);s=data;s+=" "+caption;td.innerHTML=s;}}}};XcTabs.prototype.translateName=function(name)
{if(name==="tracklog")
{return app.constants.DATA_DISTANCE;}
else
{return name;}};XcTabs.prototype.initOptions=function()
{var el,id,name,i;var arParams=[];for(name in app.Options.base)
{if(app.Options.base.hasOwnProperty(name))
{arParams[0]=name;for(i=0;i<app.Options.base[name].values.length;i+=1)
{arParams[1]=app.Options.base[name].values[i];id=this.getTabId(this.optsBaseId,arParams);el=get(id);if(el)
{el.onchange=actionSelOptions;}}
this.refreshOptionsSelects(name,true,true);var check=app.Options.isDefault(name);this.refreshOptionsDefault(name,check);arParams[1]="default";id=this.getTabId(this.optsBaseId,arParams);el=get(id);if(el)
{el.onclick=actionCbOptionsDefault;}}}};XcTabs.prototype.refreshOptionsSelects=function(name,currentValues,first)
{var sel,id;var arParams=[];arParams[0]=name;var arValues=[];if(currentValues)
{arValues=app.Options[name];}
else
{arValues=app.Options.getDefaultOptions(name);app.Options[name]=arValues;if(!first)
{app.Options.saveOptions();}}
if(app.Options.base[name].values.length!==arValues.length)
{return;}
for(var i=0;i<app.Options.base[name].values.length;i+=1)
{arParams[1]=app.Options.base[name].values[i];id=this.getTabId(this.optsBaseId,arParams);sel=get(id);if(sel)
{sel.selectedIndex=arValues[i];}}};XcTabs.prototype.refreshOptionsDefault=function(name,check)
{var id,cb,span;var arParams=[];arParams[0]=name;arParams[1]="default";id=this.getTabId(this.optsBaseId,arParams);cb=get(id);arParams[1]="defaultCaption";id=this.getTabId(this.optsBaseId,arParams);span=get(id);if(cb&&span)
{if(check===undefined)
{check=cb.checked;}
else
{cb.checked=check;}
if(check)
{cb.disabled=true;span.style.color="#c0c0c0";}
else
{cb.disabled=false;span.style.color="#000";}}};function XcOptions()
{this.tabs=[];this.player=[];this.units=[];this.base={};this.setOpts();}
XcOptions.prototype.setOpts=function()
{var base;base={};base.values=["first"];base.defaultIndex=0;this.base.tabs=base;base={};base.values=["map"];base.defaultIndex=2;this.base.player=base;base={};base.values=[app.constants.DATA_HEIGHT,app.constants.DATA_CLIMB,app.constants.DATA_SPEED,app.constants.DATA_DISTANCE];base.defaultIndex=-1;this.base.units=base;}
XcOptions.prototype.init=function()
{var name;for(name in this.base)
{if(this.base.hasOwnProperty(name))
{this[name]=this.getDefaultOptions(name);}}
var options=cookieRead("xcp");if(!options)
{this.saveOptions();return;}
var arOptions=options.split(";");var opts={};var arPairs,arValues,x;for(var i=0;i<arOptions.length;i+=1)
{arPairs=[];arValues=[];arPairs=arOptions[i].split(":");if(arPairs.length!==2||!arPairs[0]||arPairs[1].length===0)
{this.saveOptions();return;}
opts[arPairs[0]]=[];arValues=arPairs[1].split(",");for(var j=0;j<arValues.length;j+=1)
{x=parseInt(arValues[j],10);if(isNaN(x))
{this.saveOptions();return;}
else
{opts[arPairs[0]][j]=x;}}}
if(opts[app.constants.OPTS_TABS]===undefined||opts[app.constants.OPTS_PLAYER]===undefined||opts[app.constants.OPTS_UNITS]===undefined)
{this.saveOptions();return;}
var arUnits;if(opts[app.constants.OPTS_UNITS].length===1)
{arUnits=app.Units.getFullUnits(opts[app.constants.OPTS_UNITS][0]);}
else
{arUnits=opts[app.constants.OPTS_UNITS];}
this.tabs=opts[app.constants.OPTS_TABS];this.player=opts[app.constants.OPTS_PLAYER];this.units=arUnits;};XcOptions.prototype.saveOptions=function()
{var arUnits=app.Units.getUnitsToSave();var s=app.constants.OPTS_TABS+":"+this.tabs.join();s+=";"+app.constants.OPTS_PLAYER+":"+this.player.join();s+=";"+app.constants.OPTS_UNITS+":"+arUnits.join();cookieWrite("xcp",s,360);};XcOptions.prototype.getDefaultOptions=function(name,string)
{var ar,len,i;ar=[];if(name==="units")
{ar=app.Units.getDefaultUnits();}
else
{len=this.base[name].values.length;for(var i=0;i<len;i+=1)
{ar[i]=this.base[name].defaultIndex;}}
if(string)
{return ar.join();}
else
{return ar;}};XcOptions.prototype.setOption=function(name,option,index)
{var len,i;len=this.base[name].values.length
for(i=0;i<len;i+=1)
{if(option===this.base[name].values[i])
{this[name][i]=index;this.saveOptions();return;}}};XcOptions.prototype.getOption=function(name,option)
{var len,i;len=this.base[name].values.length;for(i=0;i<len;i+=1)
{if(option===this.base[name].values[i])
{return this[name][i];}}
return 0;};XcOptions.prototype.isDefault=function(name)
{var opts=this[name].join();var defOpts=this.getDefaultOptions(name,true);return defOpts===opts;};function XcAjax(id)
{this.id=id;this.method="";this.url="";this.data=null;this.http=this.initHttp();}
XcAjax.prototype.initHttp=function()
{if(typeof XMLHttpRequest!=="undefined")
{return new XMLHttpRequest();}
try
{return new ActiveXObject("Msxml2.XMLHTTP");}
catch(e1)
{try
{return new ActiveXObject("Microsoft.XMLHTTP");}
catch(e2)
{}}};XcAjax.prototype.get=function(url,callback,mimeType)
{if(!callback||!this.hasHttp())
{return false;}
this.method="GET";if(mimeType)
{this.mimeType=mimeType;}
var nocache="nocache="+Math.random();var ar=url.split("?");if(ar.length===2)
{ar[1]+="&amp;"+nocache;}
else
{ar[1]=nocache;}
this.url=ar.join("?");this.execute(callback,mimeType);return true;};XcAjax.prototype.post=function(url,callback,data,mimeType)
{if(!callback||!this.hasHttp())
{return false;}
this.method="POST";this.url=url;if(!data)
{data="";}
if(data.indexOf("=")===-1)
{this.data="json="+encodeURIComponent(data);}
else
{this.data=encodeURIComponent(data);}
this.execute(callback,mimeType,true);return true;};XcAjax.prototype.execute=function(callback,mimeType,post)
{var id,http,response,timer;if(!mimeType)
{mimeType="text/plain";}
id=this.id;http=this.http;http.open(this.method,this.url,true);timer=setTimeout(function()
{if(http)
{http.abort();if(http)
{callback("",0,id);}}},20000);if(mimeType==="text/xml")
{if(this.http.overrideMimeType)
{this.http.overrideMimeType(this.mimeType);}}
if(post)
{http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}
http.onreadystatechange=function()
{if(http.readyState===4)
{try
{clearTimeout(timer);if(mimeType==="text/xml")
{response=http.responseXML;}
else
{response=http.responseText;}
callback(response,http.status,id);}
finally
{http=null;}}};http.send(this.data);};XcAjax.prototype.hasHttp=function()
{return(this.http!==undefined);};function XcStoryUpdate(id,mainIndex)
{this.id=id;this.mainIndex=mainIndex;this.action=0;this.msg="";this.title="";this.text="";this.data=null;}
XcStoryUpdate.prototype.localRecord=function()
{return{id:this.id,mainIndex:this.mainIndex,action:this.action,msg:this.msg,text:this.text,active:1,fail:1};};XcStoryUpdate.prototype.serverRecord=function()
{return{mainIndex:this.mainIndex,action:this.action,title:this.title,text:this.text,data:this.data};};function ajaxCallback(doc,statusCode,id)
{var result,n,ar;result={id:id,status:app.Story.cnst.ERR_SERVER};if(!doc&&!statusCode)
{result.status=app.Story.cnst.ERR_NETWORK;}
else if(parseInt(statusCode,10)===200)
{ar=doc.split("-",2);if(ar[0]==="xcstory")
{n=parseInt(ar[1],10);if(!isNaN(n))
{if("xcstory-"+n===doc)
{result.status=n;}}}}
else if(parseInt(statusCode,10)===401)
{result.status=app.Story.cnst.ERR_LOGIN;}
app.Story.updateServerReturn(result);}
function XcStory()
{this.baseEdit=0;this.edit=0;this.ajaxUrl="";this.ajaxValues=null;this.type=0;this.baseStatus=0;this.status=0;this.iwEditId=undefined;this.tabEditId=undefined;this.iwStoryId=undefined;this.boards=[];this.icon=null;this.updates=[];this.updateId=0;this.cnst={LNK_GRP_EDIT:1,LNK_GRP_SAVED:2,LNK_GRP_UNSAVED:3,LNK_GRP_NEW:4,INDEX_DUMMY:-200,INDEX_FULL:-100,ACTION_UPDATE:1,ACTION_DELETE:2,ACTION_PUBLISH:3,ACTION_DELETE_ALL:4,TYPE_BOARD:1,TYPE_FULL:2,ERR_LOGIN:-2,ERR_NETWORK:-1,ERR_SERVER:0,ERR_NONE:1};}
XcStory.prototype.initFromApp=function(story)
{this.baseStatus=story.status;this.status=story.status;if(story.script)
{if(this.getAjaxSettings(story.script))
{this.baseEdit=story.edit;this.edit=story.edit;}}
if(this.status===app.constants.STORY_STATUS_PUBLISHED&&this.edit)
{this.edit=0;}
if(story.boards)
{this.initStoryboards(story.boards);}
this.setTabStories();if(this.baseEdit)
{setVisibility(1,1,get("storyInfoAdd"));window.onbeforeunload=checkUnload;}};XcStory.prototype.getAjaxSettings=function(script)
{var Ajax,year,flight,timezone;Ajax=new XcAjax();if(!Ajax.hasHttp())
{Ajax=null;return false;}
else
{Ajax=null;}
this.ajaxUrl=script.name;year=script.values.year;flight=script.values.flight;timezone=script.values.timezone;this.ajaxValues={year:year,flight:flight,timezone:timezone};return true;};XcStory.prototype.initStoryboards=function(boards)
{var i,len,story,tabTitle,text;tabTitle=0;for(i=0,len=boards.length;i<len;i+=1)
{if(boards[i].mainIndex===this.cnst.INDEX_DUMMY)
{continue;}
tabTitle+=1;story=this.newStory(boards[i].mainIndex,0,boards[i].data,boards[i].title);text=this.getText(boards[i].mainIndex,true);if(this.baseEdit)
{story.text=text;}
this.setStoryText(boards[i].mainIndex,text);story.tabTitle="Story "+tabTitle;story.saved=1;story.newStory=0;story.newTab=0;this.insertStory(story,false,true);}
if(this.boards.length===1)
{if(this.boards[0].mainIndex===this.cnst.INDEX_FULL)
{this.type=this.cnst.TYPE_FULL;}
else
{this.type=this.cnst.TYPE_BOARD;}}
else
{this.type=this.cnst.TYPE_BOARD;}};XcStory.prototype.initFromData=function(timezone)
{var i,len;this.icon=app.getMapIcon("story");if(this.ajaxUrl&&this.ajaxValues)
{this.ajaxValues.timezone=timezone;}
if(this.boards.length===0)
{return;}
for(i=0,len=this.boards.length;i<len;i+=1)
{this.boards[i].dataIndex=app.getDataIndex(this.boards[i].mainIndex);}
if(this.type===this.cnst.TYPE_FULL)
{return;}
for(i=0,len=this.boards.length;i<len;i+=1)
{this.createMarker(this.boards[i]);}
if(len&&this.baseStatus===app.constants.STORY_STATUS_PRIVATE)
{this.showMarkers(true);}
else if(len&&this.baseStatus===app.constants.STORY_STATUS_PUBLISHED&&this.edit)
{this.showMarkers(true);}
else
{app.toggleCheckbox("cbStoryboard",len>0);}};XcStory.prototype.showTabStories=function(edit)
{if(this.boards.length===0)
{setVisibility(1,1,get("storyTabInfo"));setVisibility(0,1,get("storyTabBoards"));setVisibility(0,1,get("storyTabEdit"));this.setNotesLinks(false);}
else
{setVisibility(0,1,get("storyTabInfo"));if(edit)
{setVisibility(0,1,get("storyTabBoards"));setVisibility(1,1,get("storyTabEdit"));}
else
{setVisibility(1,1,get("storyTabBoards"));setVisibility(0,1,get("storyTabEdit"));}
if(this.type!==this.cnst.TYPE_FULL&&this.boards.length===1&&this.boards[0].newTab)
{this.setNotesLinks(true);}
else
{this.setNotesLinks(edit);}}
this.setTab();};XcStory.prototype.setTabStories=function()
{var i,len;for(i=0,len=this.boards.length;i<len;i+=1)
{this.storyForTab(this.boards[i].mainIndex,false,this.boards[i]);}
this.showTabStories(false);};XcStory.prototype.getText=function(mainIndex,tidy)
{var text="";var id=this.getTextId(mainIndex);var el=get(id);if(el)
{text=el.innerHTML.replace(/<br *\/?>/gi,"\n");}
if(tidy)
{text=this.tidyText(text);}
return text;};XcStory.prototype.getTextId=function(mainIndex)
{return"story-text-"+mainIndex;};XcStory.prototype.setNotesLinks=function(hide)
{var el,s;if(!this.baseEdit)
{return;}
el=get("storyNotesLinks");if(hide)
{setVisibility(0,1,el);}
else
{s=this.getNotesLinks();if(s)
{el.innerHTML=s;setVisibility(1,1,el);}
else
{setVisibility(0,1,el);}}};XcStory.prototype.getNotesLinks=function()
{var s,unsaved;s="";unsaved=this.unsaved();if(this.status===app.constants.STORY_STATUS_NONE)
{s+="<div class=\"storyNotesLinks\">";s+=this.writeLink("Add",this.cnst.INDEX_FULL,false);s+="</div>";}
else if(this.status===app.constants.STORY_STATUS_PRIVATE)
{if(unsaved)
{s+="<div class=\"storyNotesLinks\">";s+=this.writeLink("SaveAll",0,false,unsaved);s+="</div>";}
s+="<div class=\"storyNotesLinks\">";s+=this.writeLink("Publish",0,false,unsaved);s+="</div>";s+="<div class=\"storyNotesLinks\">";s+=this.writeLink("DeleteAll",0,false);s+="</div>";}
else if(this.status===app.constants.STORY_STATUS_PUBLISHED)
{if(this.baseEdit&&!this.edit)
{s+="<div class=\"storyNotesLinks\">";s+=this.writeLink("EditAll",0,false,unsaved);s+="</div>";}
else
{if(unsaved)
{s+="<div class=\"storyNotesLinks\">";s+=this.writeLink("SaveAll",0,false,unsaved);s+="</div>";}
s+="<div class=\"storyNotesLinks\">";s+=this.writeLink("DeleteAll",0,false);s+="</div>";}}
if(s)
{s="<div id=\"storyNotesOptions\">Storyboard Options</div>"+s;}
return s;};XcStory.prototype.clearLinks=function(div)
{var ar,i,len;if(div&&div.innerHTML)
{ar=div.getElementsByTagName("a");for(i=0,len=ar.length;i<len;i+=1)
{ar[i].onclick=null;}}};XcStory.prototype.showTabLinks=function(links,mainIndex)
{var div;div=get("story-loading-"+mainIndex);setVisibility(0,1,div);div=get("story-links-"+mainIndex);this.clearLinks(div);div.innerHTML=links;setVisibility(1,1,div);};XcStory.prototype.setTab=function()
{var status=this.status;if(this.unsaved())
{status=app.constants.STORY_STATUS_UNSAVED;}
app.Tabs.setStoryTab(status);};XcStory.prototype.setStatus=function(status)
{var orig,el,s;orig=this.status;if(status===undefined)
{if(this.boards.length===0)
{this.status=app.constants.STORY_STATUS_NONE;if(this.baseStatus===app.constants.STORY_STATUS_PUBLISHED)
{this.baseStatus=app.constants.STORY_STATUS_NONE;}}
else
{if(this.baseStatus===app.constants.STORY_STATUS_PUBLISHED)
{this.status=app.constants.STORY_STATUS_PUBLISHED;}
else
{this.status=app.constants.STORY_STATUS_PRIVATE;}}}
else
{if(status===app.constants.STORY_STATUS_PUBLISHED)
{this.baseStatus=app.constants.STORY_STATUS_PUBLISHED;}
this.status=status;}
if(orig!==this.status)
{el=get("storyNotesStatus");s="None";if(this.status===app.constants.STORY_STATUS_PRIVATE)
{s="<span class=\"storyNotesPrivate\">Private</span>";}
else if(this.status===app.constants.STORY_STATUS_PUBLISHED)
{s="Published";}
el.innerHTML=s;el=get("storyNotesPrivate");if(this.status===app.constants.STORY_STATUS_PRIVATE)
{setVisibility(1,1,el);}
else
{setVisibility(0,1,el);}}};XcStory.prototype.storyForIW=function(dataIndex,edit,mainIndex)
{var result,story,details;result={html:"",opts:{},links:"",nav:"",mainIndex:undefined};if(mainIndex===undefined)
{story=this.getStoryFromDataIndex(dataIndex);}
else
{story=this.getStoryFromMainIndex(mainIndex);}
if(!story)
{if(this.edit&&this.type!==this.cnst.TYPE_FULL)
{result.links=this.writeLink("Add",dataIndex,true);}
this.iwEditId=undefined;this.iwStoryId=undefined;return result;}
this.iwStoryId=story.mainIndex;if(edit)
{this.iwEditId=story.mainIndex;}
else
{this.iwEditId=undefined;}
app.hideMarkers(story.mainIndex);details=this.setStory(story,edit);if(edit)
{result.opts.noCloseOnClick=true;}
result.links=details.iwLinks;if(!edit&&!details.text)
{return result;}
var s="<div class=\"infoBoxLarge\">";if(details.alert)
{s+=details.alert;}
if(!edit)
{s+=this.getHeader(story,1);s+="<div id=\"storyBox\">";s+="<div class=\"storyTextBox\">";s+=details.text.replace(/\n/g,"<br />");s+="</div>";s+="</div>";}
else
{s+=this.getHeader(story,2);s+="<textarea id=\"storyIwInputBox\" rows=\"5\" cols=\"50\">";s+=details.text;s+="</textarea>";}
s+=details.iwLinks;if(!edit)
{s+=this.getStoryNav();}
s+="</div>";result.html=s;return result;};XcStory.prototype.getStoryNav=function()
{var s="";s+="<div class=\"storyLinksNav\">";s+="<div class=\"storyLinksNavLeft\">";s+="<a href=\"javascript:void(0);\" class=\"storyLinkBack\"></a>";s+="</div>";s+="<div class=\"storyLinksNavLeft\">";s+="<a href=\"javascript:void(0);\" class=\"storyLinkNext\"></a>";s+="</div>";s+="<div class=\"storyLinksNavLeft\">";s+="<a href=\"javascript:void(0);\" class=\"storyLinkFlyBack\"</a>";s+="</div>";s+="<div class=\"storyLinksNavLeft\">";s+="<a href=\"javascript:void(0);\" class=\"storyLinkFlyNext\"></a>";s+="</div>";return s;};XcStory.prototype.storyForTab=function(mainIndex,edit,story)
{var fromBatch,details,div,ta;if(story)
{fromBatch=true;}
else
{story=this.getStoryFromMainIndex(mainIndex);}
if(!story)
{this.tabEditId=undefined;return;}
if(edit)
{this.tabEditId=story.mainIndex;}
else
{this.tabEditId=undefined;}
details=this.setStory(story,edit);if(edit)
{div=get("storyTabEditLinks");this.clearLinks(div);div.innerHTML=details.tabLinks;this.showTabStories(edit);ta=get("storyTabInputBox");ta.value=details.text;this.inputFocus(true);return;}
else
{if(story.newTab)
{this.writeTabStoryTitles(story.mainIndex);div=get("story-tabFrame-"+story.mainIndex);div.className="storyTabFrame";story.newTab=0;}
div=get("story-alert-"+mainIndex);if(details.alert)
{div.innerHTML=details.alert;setVisibility(1,1,div);}
else
{setVisibility(0,1,div);}
if(details.tabLinks)
{this.showTabLinks(details.tabLinks,mainIndex);}
if(!fromBatch)
{this.showTabStories(edit);}}};XcStory.prototype.storyForRoute=function(index,zoom)
{var result,dataIndex,point;result={html:"",opts:{},links:"",mainIndex:undefined};if(app.route.useIndex)
{dataIndex=app.route.points[index].dataIndex;if(dataIndex!==undefined)
{if(this.edit&&this.type!==this.cnst.TYPE_FULL)
{result.links=this.writeLink("AddRoute",index,true);}}}
else
{if(zoom)
{result.links=this.writeLink("Zoom",index,true);}
else
{result.links=this.writeLink("ZoomOut",index,true);}}
return result;};XcStory.prototype.setStory=function(story,edit)
{var result,status;result={alert:"",iwLinks:"",tabLinks:"",text:""};result.text=this.getText(story.mainIndex);status={mainIndex:story.mainIndex,show:0,story:0,saved:0,newStory:0,updateMsg:""};if(this.edit)
{if(!edit)
{status.show=1;if(result.text)
{status.story=1;status.saved=story.saved;}}}
else
{status.show=1;}
status.newStory=story.newStory;result.alert=this.getAlert(status);result.iwLinks=this.getLinks(status,true);if(!status.updateMsg)
{result.tabLinks=this.getLinks(status);}
return result;};XcStory.prototype.getAlert=function(status)
{var update,i,len,s;s="";if(status.show)
{for(i=0,len=this.updates.length;i<len;i+=1)
{if(this.updates[i].mainIndex===status.mainIndex)
{update=this.updates[i];break;}}
if(update)
{if(update.active)
{status.updateMsg=update.msg;}
else if(update.fail!==this.cnst.ERR_NONE)
{s="Last update failed";if(update.fail===this.cnst.ERR_LOGIN)
{s+=" - access denied. Please sign in and try again.";}
else if(update.fail===this.cnst.ERR_NETWORK)
{s+=" - network error. Please try again.";}
else if(update.fail===this.cnst.ERR_SERVER)
{s+=" - server error. Please try again.";}
return"<div class=\"storyAlert\">"+s+"</div>";}}
if(status.story&&!status.saved)
{if(status.newStory)
{s="This entry has not been saved and will only last while you remain on this web page.";s+=" Click <b>Save Story</b> to upload it to the server.";}
else
{s="Your changes have not been saved and will only last while you remain on this web page.";s+=" Click <b>Save Changes</b> to upload them to the server.";}}}
else
{s="Enter your story here.";s+=" Click <b>Preview</b> to view and save it.";}
if(s)
{s="<div class=\"storyInfo\">"+s+"</div>";}
return s;};XcStory.prototype.getLinks=function(status,iw)
{var s;s="";if(iw)
{if(this.type===this.cnst.TYPE_FULL)
{return s;}
if(status.updateMsg)
{s+="<div id=\"iwLoading\" class=\"storyLoading\">";s+=status.updateMsg;s+="</div>";return s;}
else
{s+="<div id=\"iwLoading\" class=\"storyLoading hidden\"></div>";s+="<div id=\"iwStoryLinks\" class=\"storyLinks\">";}}
if(status.show)
{if(this.edit)
{if(status.saved)
{s+=this.writeGroupLinks(this.cnst.LNK_GRP_SAVED,status.mainIndex,iw);}
else
{if(status.newStory)
{s+=this.writeGroupLinks(this.cnst.LNK_GRP_NEW,status.mainIndex,iw);}
else
{s+=this.writeGroupLinks(this.cnst.LNK_GRP_UNSAVED,status.mainIndex,iw);}}}}
else
{s+=this.writeGroupLinks(this.cnst.LNK_GRP_EDIT,status.mainIndex,iw);}
if(iw)
{s+="</div>";}
return s;};XcStory.prototype.writeGroupLinks=function(group,index,iw)
{var s,newStory;s="";if(group===this.cnst.LNK_GRP_EDIT)
{s+="<div class=\"storyLinksLeft\">";s+=this.writeLink("Preview",index,iw);s+="</div>";s+="<div class=\"storyLinksRight\">";s+=this.writeLink("Cancel",index,iw);s+="</div>";s+="<div class=\"clear\"></div>";return s;}
s+="<div class=\"storyLinksLeft\">";s+=this.writeLink("Edit",index,iw);s+="</div>";s+="<div class=\"storyLinksRight\">";if(group===this.cnst.LNK_GRP_SAVED)
{s+=this.writeLink("Delete",index,iw);}
else if(group===this.cnst.LNK_GRP_UNSAVED)
{s+=this.writeLink("Save",index,iw,newStory);s+=this.writeLink("Discard",index,iw,newStory);s+=this.writeLink("Delete",index,iw);}
else if(group===this.cnst.LNK_GRP_NEW)
{newStory=true;s+=this.writeLink("Save",index,iw,newStory);s+=this.writeLink("Discard",index,iw,newStory);}
s+="</div>";s+="<div class=\"clear\"></div>";return s;};XcStory.prototype.writeLink=function(name,index,iw,extra)
{var link,s;link=this.getLinkData(name,index,iw,extra);s="<a href=\"javascript:void(0);\"";s+=" class=\""+link.className+"\"";s+=" title=\""+link.title+"\"";s+=" onclick=\""+link.onclick+"\"";s+=">"+link.text+"</a>";return s;};XcStory.prototype.getLinkData=function(name,index,iw,extra)
{var className,title,onclick,text,params;className="storyLink"+name;title="";text="";if(name==="Add")
{if(iw)
{title="Add a story to this position";text="Add Story";}
else
{title="Add your full story";text="Add Full Story";className="storyLinkAddFull";}}
else if(name==="AddRoute")
{title="Add a story to this position";text="Add Story";className="storyLinkAdd";}
else if(name==="Edit")
{title="Edit this story";text="Edit";}
else if(name==="Preview")
{title="See how your story will look";text="Preview";}
else if(name==="Save")
{title="Save your changes on the server";if(extra)
{text="Save Story";}
else
{text="Save Changes";}}
else if(name==="Discard")
{if(extra)
{title="Delete this story";text="Delete";className="storyLinkDelete";}
else
{title="Discard your changes";text="Discard Changes";}}
else if(name==="Cancel")
{title="Cancel this edit";text="Cancel";}
else if(name==="Delete")
{title="Delete this story";text="Delete";}
else if(name==="Publish")
{if(extra)
{title="Save & Publish this storyboard";text="Save & Publish";}
else
{title="Publish this storyboard";text="Publish";}
onclick="this.blur();app.Story.cmdSaveAll(1);";}
else if(name==="SaveAll")
{title="Save all stories";text="Save";onclick="this.blur();app.Story.cmdSaveAll();";}
else if(name==="DeleteAll")
{title="Delete this storyboard";text="Delete";onclick="this.blur();app.Story.cmdDeleteAll();";}
else if(name==="EditAll")
{title="Edit this storyboard";text="Edit";onclick="this.blur();app.Story.cmdEditAll();";}
else if(name==="Zoom")
{title="Zoom to this position";text="Zoom To";onclick="actionClickRouteZoom(";onclick+=index;onclick+=");";}
else if(name==="ZoomOut")
{title="Zoom out to default view";text="Zoom Out";onclick="actionCbDefault();";}
if(!onclick)
{params=index+",";params+=(iw?1:0);onclick="this.blur();app.Story.cmd";onclick+=name;onclick+="Story(";onclick+=params;onclick+=");";}
if(onclick)
{onclick+="return false;"}
return{className:className,title:title,onclick:onclick,text:text};};XcStory.prototype.getHeader=function(story,infoWindow)
{var ar,name,value,cols,position,bold;ar=[];cols=2;ar[0]={name:"title",value:story.title};ar[1]={name:"time",value:(story.data.time?story.data.time:"")};if(infoWindow===2)
{return app.getIWHeader(ar,cols);}
if(infoWindow===1)
{value=app.getIWTrackData(story.data,-1);if(value)
{ar[ar.length]=value;}
else
{cols=1;}}
else
{if(story.mainIndex===this.cnst.INDEX_FULL)
{return app.getIWHeader(ar,2);}
if(app.appStatus===3)
{this.getHeaderData(story,app.constants.DATA_HEIGHT,ar);if(story.dataIndex!==0)
{this.getHeaderData(story,app.constants.DATA_DURATION,ar);this.getHeaderData(story,app.constants.DATA_SPEED,ar);this.getHeaderData(story,app.constants.DATA_DISTANCE,ar);this.getHeaderData(story,app.constants.DATA_CLIMB,ar);}}
else if(app.appStatus===2)
{this.getHeaderData(story,app.constants.DATA_SPEED,ar);if(story.dataIndex!==0)
{this.getHeaderData(story,app.constants.DATA_DURATION,ar);this.getHeaderData(story,app.constants.DATA_DISTANCE,ar);cols=3;}}
else if(app.appStatus===1)
{if(story.dataIndex!==0)
{value=timeFromSecs(story.data.secs,true);if(value)
{this.getHeaderData(story,"duration",ar);this.getHeaderData(story,"distance",ar);cols=3;}
else
{this.getHeaderData(story,"distance",ar);}}
else
{cols=1;}}}
app.getIWTrackPos(story.data.points,ar);return app.getIWHeader(ar,cols);};XcStory.prototype.getHeaderData=function(story,name,arOut)
{var value,bold;if(name==="duration")
{value=timeFromSecs(story.data.secs,true)+" hrs";arOut[arOut.length]={name:"Duration",value:value};}
else
{value=story.data[name];bold=this.isHighlight(story.title,name);arOut[arOut.length]=app.Units.getFullData(name,value,bold);}};XcStory.prototype.isHighlight=function(title,name)
{var value;if(title==="Max Height"||title==="Lowest Save")
{value=app.constants.DATA_HEIGHT;}
else if(title==="Max Climb"||title==="Min Climb")
{value=app.constants.DATA_CLIMB;}
else if(title==="Max Speed")
{value=app.constants.DATA_SPEED;}
else
{return;}
if(value)
{return(name?name===value:name);}};XcStory.prototype.getInputText=function(iw,opts)
{if(!opts)
{opts={};}
var ta;var text="";if(iw)
{ta=get("storyIwInputBox");}
else
{ta=get("storyTabInputBox");}
if(ta)
{if(opts.clear&&!opts.ret)
{ta.value="";return;}
else
{text=this.tidyText(ta.value);}
if(opts.clear)
{ta.value="";}}
return text;};XcStory.prototype.cmdAddRouteStory=function(routeIndex,iw)
{this.cmdAddStory(routeIndex,iw,app.route.points[routeIndex]);};XcStory.prototype.cmdAddStory=function(index,iw,route)
{var dataIndex,data,story,title,mainIndex;data={};if(!iw)
{dataIndex=this.cnst.INDEX_FULL;}
else
{if(!route)
{dataIndex=index;data.points=app.data.points[dataIndex];}
else
{dataIndex=route.dataIndex;data.points=route.latLon;}
data.time=app.data.time[dataIndex];data.secs=app.data.secs[dataIndex];if(app.appStatus>2)
{data.height=app.data.height[dataIndex];}
if(app.appStatus>1)
{data.climb=app.data.climb[dataIndex];data.speed=app.data.speed[dataIndex];}
data.distance=app.data.distance[dataIndex];}
if(iw)
{if(!route)
{title=app.getHighlightCaption(dataIndex);mainIndex=app.getMainIndex(dataIndex);}
else
{title=app.getRouteCaption(dataIndex,route.caption);mainIndex=route.mainIndex;}}
else
{title="Full Story";mainIndex=dataIndex;}
story=this.getStoryFromMainIndex(mainIndex);if(story)
{this.cmdEditStory(mainIndex,iw);return;}
story=this.newStory(mainIndex,dataIndex,data,title);this.insertStory(story,iw);if(!this.createTabStory(story))
{this.removeStory(story);return;}
if(iw)
{this.showTabStories();}
else
{this.iwShow(story,{anyIndex:1});}
this.cmdEditStory(mainIndex,iw);};XcStory.prototype.createTabStory=function(story)
{var el,div,i,len,arDivs,arId,info,parent,refEl;el=get("story-"+this.cnst.INDEX_DUMMY);if(!el)
{return;}
div=el.cloneNode(true);div.style.display="none";div.style.visibility="hidden";div.id="story-"+story.mainIndex;arDivs=div.getElementsByTagName("div");for(i=0,len=arDivs.length;i<len;i+=1)
{arId=[];arId=arDivs[i].id.split("-");if(arId.length>1)
{arId[arId.length-1]=story.mainIndex;arDivs[i].id=arId.join("-").replace(/--/,"-");}}
info=this.getPositions(story.mainIndex);refEl=get("story-"+info.arIndex[info.pos+1]);if(!refEl)
{refEl=null;}
parent=el.parentNode;parent.insertBefore(div,refEl);el=get("story-header-"+story.mainIndex);el.innerHTML=this.getHeader(story,0);el=get("story-text-"+story.mainIndex);el.innerHTML="";this.writeTabStoryTitles(story.mainIndex);div=get("story-"+story.mainIndex);setVisibility(1,1,div);return true;};XcStory.prototype.getPositions=function(mainIndex)
{var i,len,result={pos:-1,arIndex:[]};for(i=0,len=this.boards.length;i<len;i+=1)
{result.arIndex[result.arIndex.length]=this.boards[i].mainIndex;}
result.arIndex.sort(sortNum);for(i=0,len=result.arIndex.length;i<len;i+=1)
{if(result.arIndex[i]===mainIndex)
{result.pos=i;break;}}
return result;};XcStory.prototype.writeTabStoryTitles=function(mainIndex,removing)
{var info,i,len,tabTitle;info=this.getPositions(mainIndex);if(info.pos===info.arIndex.length-1)
{if(removing)
{return;}
else
{tabTitle="Story "+(info.pos+1);this.setTabStoryTitle(info.arIndex[info.pos],tabTitle);return;}}
else
{if(removing)
{info.arIndex.splice(info.pos,1);}}
for(i=0,len=info.arIndex.length;i<len;i+=1)
{tabTitle="Story "+(i+1);this.setTabStoryTitle(info.arIndex[i],tabTitle);}};XcStory.prototype.setTabStoryTitle=function(mainIndex,title)
{var story,el;story=this.getStoryFromMainIndex(mainIndex);if(!story)
{return;}
story.tabTitle=title;el=get("story-title-"+mainIndex);el.innerHTML=title;};XcStory.prototype.checkForEdit=function(story,iw,fromSave)
{var s;if(iw&&story.mainIndex===this.tabEditId)
{s="You are editing this story on the Storyboard page.";}
else if(!iw&&story.mainIndex===this.iwEditId)
{if(!fromSave)
{s="You are editing this story on the XC Player page.";}
else
{s="You are editing ";s+=story.tabTitle;s+=" on the XC Player page.";}}
if(s)
{alert(s);}
else
{return true;}};XcStory.prototype.cmdEditStory=function(mainIndex,iw)
{var story,params;story=this.getStoryFromMainIndex(mainIndex);if(!this.checkForEdit(story,iw))
{return;}
if(iw)
{this.iwShowEdit(story);}
else
{this.storyForTab(mainIndex,true);}};XcStory.prototype.inputFocus=function(tab)
{var ta;if(tab)
{ta=get("storyTabInputBox");}
else
{ta=get("storyIwInputBox");}
if(ta)
{ta.focus();}};XcStory.prototype.cmdSaveStory=function(mainIndex,iw)
{var story;story=this.getStoryFromMainIndex(mainIndex);if(!story)
{return;}
if(!this.checkForEdit(story,iw))
{return;}
if(!iw)
{this.iwShow(story,{iw:iw});}
this.updateServer(story,this.cnst.ACTION_UPDATE,iw);};XcStory.prototype.cmdDiscardStory=function(mainIndex,iw)
{var story,s;story=this.getStoryFromMainIndex(mainIndex);if(!story)
{return;}
if(!this.checkForEdit(story,iw))
{return;}
if(story.newStory)
{s="Delete this story?";}
else
{s="Discard changes and revert to last saved?";}
if(!confirm(s))
{return;}
if(story.newStory)
{this.cmdCancelStory(mainIndex,iw,story);}
else
{this.setStoryText(mainIndex,story.text);story.saved=1;this.storyForTab(mainIndex,false);this.iwShow(story,{iw:iw});}};XcStory.prototype.cmdCancelStory=function(mainIndex,iw,story)
{var inputText,text,s,deleted;if(!story)
{story=this.getStoryFromMainIndex(mainIndex);if(!story)
{if(iw)
{app.trackMarker.closeInfoWindow();}
return;}
inputText=this.getInputText(iw);text=this.getText(mainIndex);if(inputText)
{if(story.newStory)
{s="Delete this story?";}
else if(inputText!==text)
{s="Your changes will be lost";}
if(s)
{if(!confirm(s))
{if(iw)
{this.inputFocus();}
return;}}
this.getInputText(iw,{clear:1});}
if(!text)
{this.removeStory(story);deleted=true;}}
else
{this.removeStory(story);deleted=true;}
if(!deleted)
{this.storyForTab(mainIndex,false);this.iwShow(story,{iw:iw});}};XcStory.prototype.cmdClosedEdit=function()
{var story;story=this.getStoryFromMainIndex(this.iwStoryId);this.iwEditId=undefined;this.iwStoryId=undefined;if(!story)
{return;}
if(!this.getText(story.mainIndex))
{this.removeStory(story);}};XcStory.prototype.cmdDeleteStory=function(mainIndex,iw)
{var story,s;story=this.getStoryFromMainIndex(mainIndex);if(!story)
{if(iw)
{app.trackMarker.closeInfoWindow();}
return;}
if(!this.checkForEdit(story,iw))
{return;}
if(this.status===app.constants.STORY_STATUS_PUBLISHED)
{if(this.boards.length===1)
{s="Delete this published storyboard?";}
else
{s="Delete this published story?";}}
else
{s="Delete this saved story?";}
if(!confirm(s))
{if(iw)
{this.inputFocus();}
return;}
if(story.text)
{if(!iw)
{this.iwShow(story);}
this.updateServer(story,this.cnst.ACTION_DELETE,iw);}
else
{this.cmdCancelStory(mainIndex,story);}};XcStory.prototype.cmdSaveAll=function(publish)
{var arBatch,i,len,updating,mainAction;arBatch=[];for(i=0,len=this.boards.length;i<len;i+=1)
{if(!this.checkForEdit(this.boards[i],false,true))
{return;}
updating=false;if(!this.boards[i].saved)
{this.updatePrepareBatch(arBatch,this.boards[i],this.cnst.ACTION_UPDATE);updating=true;}
else if(publish)
{this.updatePrepareBatch(arBatch,this.boards[i],this.cnst.ACTION_PUBLISH);updating=true;}
if(updating)
{this.iwShow(this.boards[i]);}}
if(publish)
{mainAction=this.cnst.ACTION_PUBLISH;}
else
{mainAction=this.cnst.ACTION_UPDATE;}
this.updateServerBatch(arBatch,mainAction);};XcStory.prototype.cmdDeleteAll=function()
{var arBatch,arLocal,s,i,len,story;arBatch=[];arLocal=[];if(this.status===app.constants.STORY_STATUS_PUBLISHED)
{s="Delete this published storyboard?";}
else
{s="Delete this storyboard?";}
if(!confirm(s))
{return;}
for(i=0,len=this.boards.length;i<len;i+=1)
{if(this.boards[i].newStory)
{arLocal[arLocal.length]=this.boards[i].mainIndex;}
else
{this.updatePrepareBatch(arBatch,this.boards[i],this.cnst.ACTION_DELETE);}
this.iwShow(this.boards[i]);}
for(i=0,len=arLocal.length;i<len;i+=1)
{if(i===0)
{this.setNotesLinks(true);}
story=this.getStoryFromMainIndex(arLocal[i]);this.cmdCancelStory(story.mainIndex,false,story);}
if(arBatch.length)
{this.updateServerBatch(arBatch,this.cnst.ACTION_DELETE_ALL);}
else
{this.setNotesLinks(false);}};XcStory.prototype.cmdEditAll=function()
{this.edit=1;this.setTabStories();this.iwShow(undefined,{anyIndex:1});if(app.scriptLoaded()&&!get("cbStoryboard").checked)
{this.showMarkers(true);}};XcStory.prototype.newStory=function(mainIndex,dataIndex,data,title)
{return{mainIndex:mainIndex,dataIndex:dataIndex,data:data,marker:null,event:null,title:title,text:"",tabTitle:"",saved:0,newStory:1,newTab:1};};XcStory.prototype.insertStory=function(story,iw,fromInit)
{var el;this.boards[this.boards.length]=story;if(!fromInit)
{el=get("storyNotesStories");el.innerHTML=this.boards.length;if(this.boards.length===1)
{if(this.boards[0].mainIndex===this.cnst.INDEX_FULL)
{this.type=this.cnst.TYPE_FULL;}
this.setStatus();}}
if(app.scriptLoaded()&&this.type!==this.cnst.TYPE_FULL)
{this.createMarker(story);if(!get("cbStoryboard").checked)
{this.showMarkers(true);}
else
{this.showMarkers(false,true);this.showMarkers(true);}
if(iw)
{app.hideMarkers(story.mainIndex);}}};XcStory.prototype.createMarker=function(story)
{var point;if(story.mainIndex===this.cnst.INDEX_FULL)
{return;}
if(story.dataIndex!==undefined)
{point=app.gLatLngFromData(story.dataIndex);}
else
{point=app.gLatLngFromArray(story.data.points);}
if(story.marker)
{story.marker.setLatLng(point);}
else
{story.marker=new GMarker(point,{icon:this.icon,title:"Read story"});story.event=GEvent.addListener(story.marker,"click",function()
{actionMarkerStory(story.mainIndex);});}};XcStory.prototype.showMarkers=function(show,fromClick)
{var i,len;for(i=0,len=this.boards.length;i<len;i+=1)
{if(!this.boards[i].marker)
{continue;}
if(show)
{map.addOverlay(this.boards[i].marker);}
else
{map.removeOverlay(this.boards[i].marker);}}
if(!fromClick)
{app.toggleCheckbox("cbStoryboard",len>0,show);}};XcStory.prototype.removeEvents=function()
{var i,len;for(i=0,len=this.boards.length;i<len;i+=1)
{if(this.boards[i].event)
{GEvent.removeListener(this.boards[i].event);}}};XcStory.prototype.removeStory=function(story)
{var el,parent,i,len;if(story.marker)
{map.removeOverlay(story.marker);GEvent.removeListener(story.event);}
el=get("story-"+story.mainIndex);if(el)
{parent=el.parentNode;parent.removeChild(el);this.writeTabStoryTitles(story.mainIndex,true);}
for(i=0,len=this.boards.length;i<len;i+=1)
{if(story.mainIndex===this.boards[i].mainIndex)
{this.boards.splice(i,1);break;}}
el=get("storyNotesStories");el.innerHTML=this.boards.length;if(this.boards.length===0)
{this.type=this.cnst.TYPE_BOARD;this.setStatus();app.toggleCheckbox("cbStoryboard",false,false);}
this.showTabStories();this.iwShow(story,{anyIndex:1,deleted:1});};XcStory.prototype.cmdPreviewStory=function(mainIndex,iw)
{var text,story;text=this.getInputText(iw);if(!text)
{alert("There is nothing to preview");this.inputFocus(!iw);return;}
story=this.getStoryFromMainIndex(mainIndex);if(!story)
{return;}
if(!this.checkForEdit(story,iw))
{return;}
story.saved=(text===story.text?1:0);this.setStoryText(mainIndex,text);this.storyForTab(mainIndex,false);this.iwShow(story,{iw:iw});};XcStory.prototype.getStoryFromDataIndex=function(dataIndex)
{for(var i=0;i<this.boards.length;i+=1)
{if(this.boards[i].dataIndex===dataIndex)
{return this.boards[i];}}};XcStory.prototype.getStoryFromMainIndex=function(mainIndex)
{for(var i=0;i<this.boards.length;i+=1)
{if(this.boards[i].mainIndex===mainIndex)
{return this.boards[i];}}};XcStory.prototype.setStoryText=function(mainIndex,text)
{var id=this.getTextId(mainIndex);var el=get(id);if(el)
{el.innerHTML=text.replace(/\n/g,"<br />");}};XcStory.prototype.unsaved=function()
{var unsaved=0;for(var i=0,l=this.boards.length;i<l;i+=1)
{if(!this.boards[i].saved)
{unsaved+=1;}}
return unsaved;};XcStory.prototype.updateServer=function(story,action,iw)
{var rec;this.updateId+=1;rec=this.newUpdate(this.updateId,story,action);this.updateServerBatch([rec],action,iw);};XcStory.prototype.updatePrepareBatch=function(arBatch,story,action)
{if(arBatch.length===0)
{this.updateId+=1;}
arBatch[arBatch.length]=this.newUpdate(this.updateId,story,action);};XcStory.prototype.newUpdate=function(id,story,action)
{var Update;Update=new XcStoryUpdate(id,story.mainIndex);Update.action=action;if(action===this.cnst.ACTION_UPDATE)
{Update.title=story.title;Update.text=this.getText(story.mainIndex);Update.data=story.data;}
return Update;};XcStory.prototype.updateServerBatch=function(updates,mainAction,iw)
{var dataObj,values,records,data,Ajax,i,len;if(!updates.length)
{return;}
records=this.getUpdateServerRecords(updates,mainAction);values=this.ajaxValues;values.mainAction=mainAction;dataObj={values:values,records:records};data=JSON.stringify(dataObj);Ajax=new XcAjax(updates[0].id);if(Ajax.post(this.ajaxUrl,ajaxCallback,data))
{this.setNotesLinks(true);for(i=0,len=updates.length;i<len;i+=1)
{updates[i].msg=this.getUpdateMsg(mainAction);this.addUpdate(updates[i]);this.showLoadingMsg(updates[i],iw);}}};XcStory.prototype.getUpdateServerRecords=function(updates,mainAction)
{var ar,i,len,action;ar=[];if(mainAction===this.cnst.ACTION_DELETE_ALL)
{return ar;}
for(i=0,len=updates.length;i<len;i+=1)
{action=updates[i].action;if(action===this.cnst.ACTION_UPDATE||action===this.cnst.ACTION_DELETE)
{ar[ar.length]=updates[i].serverRecord();}}
return ar;};XcStory.prototype.addUpdate=function(update)
{for(var i=0;i<this.updates.length;i+=1)
{if(this.updates[i].mainIndex===update.mainIndex)
{this.updates[i]=update.localRecord();return;}}
this.updates[this.updates.length]=update.localRecord();};XcStory.prototype.updateServerReturn=function(result)
{var i,len,remove,story,deleted;if(result.status<this.cnst.ERR_LOGIN||result.status>this.cnst.ACTION_DELETE_ALL)
{result.status=this.cnst.ERR_SERVER;}
remove={start:null,count:0};for(i=0,len=this.updates.length;i<len;i+=1)
{if(this.updates[i].id===result.id)
{this.updates[i].active=0;story=this.getStoryFromMainIndex(this.updates[i].mainIndex);if(!story)
{continue;}
if(result.status>0)
{deleted=(this.updates[i].action===this.cnst.ACTION_DELETE);remove.count+=1;if(remove.start===null)
{remove.start=i;}
this.updateSuccess(this.updates[i],story);if(result.status===this.cnst.ACTION_PUBLISH)
{this.updates[i].action=this.cnst.ACTION_PUBLISH;if(this.edit)
{this.edit=0;this.setStatus(app.constants.STORY_STATUS_PUBLISHED);}
setVisibility(0,1,get("story-loading-"+story.mainIndex));}}
else
{this.updates[i].fail=result.status;}
if(!deleted)
{this.storyForTab(story.mainIndex,false);this.iwShow(story);}}}
if(remove.start!==null)
{this.updates.splice(remove.start,remove.count);}};XcStory.prototype.updateSuccess=function(update,story)
{update.fail=this.cnst.ERR_NONE;if(update.action===this.cnst.ACTION_DELETE)
{this.removeStory(story);}
else if(update.action===this.cnst.ACTION_UPDATE)
{story.text=update.text;story.saved=1;story.newStory=0;}};XcStory.prototype.iwShow=function(story,opts)
{var open,showing,params;if(!opts)
{opts={};}
if(!opts.iw)
{open=(map&&!map.getInfoWindow().isHidden());if(!opts.anyIndex)
{open=(open&&this.iwStoryId===story.mainIndex);}
showing=(open&&app.Tabs.isPlayerTab());}
if(opts.iw||showing)
{app.infoWindow.track=true;if(opts.deleted)
{app.refreshInfoWindow();return;}
else
{params=app.getInfoStory(story.mainIndex,false);app.infoWindow.refreshing=true;app.trackMarker.openInfoWindowHtml(params.html,params.opts);}}
else if(open)
{app.iwSetReshow();}};XcStory.prototype.iwShowEdit=function(story)
{var params;params=app.getInfoStory(story.mainIndex,true);app.infoWindow.refreshing=true;app.infoWindow.track=false;app.trackMarker.openInfoWindowHtml(params.html,params.opts);setTimeout(function()
{app.Story.inputFocus();},200);};XcStory.prototype.showLoadingMsg=function(update,iw)
{var div;if(iw)
{div=get("iwStoryLinks");setVisibility(0,1,div);div=get("iwLoading");if(div)
{div.innerHTML=update.msg;setVisibility(1,1,div);}}
div=get("story-links-"+update.mainIndex);setVisibility(0,1,div);div=get("story-loading-"+update.mainIndex);if(div)
{div.innerHTML=update.msg;setVisibility(1,1,div);}};XcStory.prototype.getUpdateMsg=function(mainAction)
{var s="Updating this story...";if(mainAction===this.cnst.ACTION_UPDATE)
{s="Saving this story...";}
else if(mainAction===this.cnst.ACTION_DELETE)
{s="Deleting this story...";}
else if(mainAction===this.cnst.ACTION_DELETE_ALL)
{s="Deleting storyboard...";}
else if(mainAction===this.cnst.ACTION_PUBLISH)
{s="Publishing storyboard...";}
return s;};XcStory.prototype.tidyText=function(text)
{function matchToUpper(match)
{return match.toUpperCase();}
var clean=text.replace(/<([a-z0-9\"\'\\\/=\:])*>/gi,"");clean=clean.replace(/</g,"&lt;");clean=clean.replace(/>/g,"&gt;");clean=clean.replace(/[\u2018\u2019\u201A\u201B\u2032\u2035]/g,"'");clean=clean.replace(/[\u201C\u201D\u201E\u201F\u2033\u2036]/g,"\"");var ar=clean.split("\n");var arOut=[];var firstPara=false;var lineBreak=0;var s;for(var i=0,len=ar.length;i<len;i+=1)
{s=ar[i].replace(/^\s+/,"").replace(/\s+$/,"").replace(/\s{2,}/g," ");if(!firstPara)
{if(s)
{firstPara=true;}
else
{continue;}}
if(s)
{lineBreak=0;s=app.Units.ucFirst(s);s=s.replace(/\s([\.:!\?,;])/g,"$1");s=s.replace(/([:!\?,;])([\.:!\?,;]{1,})/g,"$1");s=s.replace(/([\.:!\?,;])([^\s\.])/g,"$1 $2");s=s.replace(/[\.:!\?]\s([a-z])/g,matchToUpper);s=s.replace(/[,;]$/g,"");s=s.replace(/([^\.:!\?])$/g,"$1.");}
else
{if(lineBreak===1)
{continue;}
else
{lineBreak=1;}}
arOut[arOut.length]=s;}
return arOut.join("\n").replace(/\s+$/,"");};function XcScaleData()
{this.max="No data";this.maxMid="";this.mid="";this.minMid="";this.min="";}
function XcObjStats(name)
{this.ok=true;this.max={value:0,index:0};this.min={value:0,index:0};if(name===app.constants.DATA_HEIGHT)
{this.low={value:0,index:0};}}
function XcApp()
{this.trackFile="";this.trackData=undefined;this.imageDir="";this.scriptUrl="";this.appStatus=0;this.Options={};this.Polylines={};this.Story={};this.Tabs={};this.Units={};this.trackMarker={};this.data={};this.data.mainIndex=[];this.data.points=[];this.data.height=[];this.data.climb=[];this.data.speed=[];this.data.distance=[];this.data.time=[];this.data.secs=[];this.data.display={};this.data.index=0;this.stats={};this.stats.height={};this.stats.climb={};this.stats.speed={};this.stats.duration=0;this.stats.trackInterval=0;this.scales={};this.player={};this.player.slider={};this.player.sliderDiv={};this.player.sliderX=0;this.player.range=0;this.player.dataMax=0;this.player.playing=false;this.player.panning=false;this.player.paused=false;this.player.enabled=false;this.flight={};this.flight.zoom=0;this.flight.zoomToZoom=14;this.flight.bounds={};this.flight.boundsCenter={};this.view={};this.view.mapSize=null;this.view.innerBounds={};this.view.innerPoints={};this.view.atDefault=false;this.view.poly=null;this.indexInfo={};this.route={};this.route.useIndex=false;this.route.startFinish=false;this.route.name="";this.route.icon=null;this.route.points=[];this.route.markers=[];this.hiddenMarkers=[];this.infoWindow={refreshing:false,track:false,reshow:false};this.markerMap={active:0,type:0,index:null,dataIndex:0,dataNext:0,dataBack:0};this.highlights=[];this.domEvents=[];this.mapEvents=[];this.constants={TP_TRACK:0,TP_ROUTE:1,TP_STORY:2,DATA_MAIN_INDEX:"mainIndex",DATA_POINTS:"points",DATA_TIME:"time",DATA_HEIGHT:"height",DATA_CLIMB:"climb",DATA_SPEED:"speed",DATA_DISTANCE:"distance",DATA_DURATION:"duration",UNITS_METRIC:0,UNITS_IMPERIAL:1,UNITS_KNOTS:2,OPTS_TABS:"vft",OPTS_PLAYER:"vfp",OPTS_UNITS:"vfu",OPTS_UNITS_DEFAULT:0,OPTS_UNITS_METRIC:1,OPTS_UNITS_IMPERIAL:2,STORY_STATUS_NONE:0,STORY_STATUS_PUBLISHED:1,STORY_STATUS_PRIVATE:2,STORY_STATUS_UNSAVED:3};}
XcApp.prototype.init=function(params)
{var heightMetres,stats,noContent;heightMetres=false;if(params.track)
{this.trackFile=params.track.file;this.trackData=params.track.data;}
if(params.imageDir)
{this.imageDir=params.imageDir;}
if(params.script)
{this.scriptUrl=params.script;}
if(params.heightMetres)
{heightMetres=params.heightMetres;}
if(params.route)
{this.initRouteFromApp(params.route);}
this.Options=new XcOptions();this.Units=new XcUnits(heightMetres);this.Tabs=new XcTabs();this.Story=new XcStory();this.Options.init();this.Units.init(true);if(params.stats)
{stats=params.stats;}
if(params.noContent)
{noContent=params.noContent;}
this.Tabs.init(stats,noContent);if(params.story)
{this.Story.initFromApp(params.story);}};XcApp.prototype.loadXcPlayer=function()
{var title,msg,params;if(!this.trackFile)
{if(!this.trackData)
{title="Unable to load flight";msg="Track data not available";params={title:title,msg:msg,error:1};showMessage(params);return;}}
if(typeof GUnload!=="function")
{this.loadScript();return;}
if(!GBrowserIsCompatible())
{title="Unable to load flight";msg="Your browser is not compatible with Google Maps";params={title:title,msg:msg,error:1};showMessage(params);return;}
if(this.trackFile)
{this.initTrackFromFile();}
else
{this.initTrackFromData();}};XcApp.prototype.loadScript=function()
{var script;if(typeof GUnload==="function"||this.scriptLoaded())
{return;}
script=document.createElement("script");script.type="text/javascript";script.src=this.scriptUrl;this.scriptUrl=null;document.body.appendChild(script);};XcApp.prototype.scriptLoaded=function()
{return(typeof GUnload==="function"&&!this.scriptUrl);};XcApp.prototype.initTrackFromFile=function()
{var title,msg,params;title="Loading track";msg="Downloading data... please wait";params={title:title,msg:msg,error:0};showMessage(params);GDownloadUrl(this.trackFile,GEvent.callback(this,this.processDownload));};XcApp.prototype.initTrackFromData=function()
{var title,msg,params;params={title:"Loading track",msg:"Processing data... please wait",error:0};showMessage(params);setTimeout(function()
{app.initXcPlayer();},10);};XcApp.prototype.getInnerBounds=function()
{var size=map.getSize();if(!this.view.mapSize||!size.equals(this.view.mapSize))
{this.view.mapSize=size;var swPx=new GPoint(0,size.height);var nePx=new GPoint(size.width,0);var top=40;var right=20;var bottom=30;var left=65;swPx.x+=left;nePx.x-=right;swPx.y-=bottom;nePx.y+=top;this.view.innerPoints.sw=swPx;this.view.innerPoints.ne=nePx;}
var sw=map.fromContainerPixelToLatLng(this.view.innerPoints.sw);var ne=map.fromContainerPixelToLatLng(this.view.innerPoints.ne);this.view.innerBounds=new GLatLngBounds(sw,ne);};XcApp.prototype.initMap=function()
{var gbOptions,mapIndex,arMap,event;if(map!==undefined)
{return;}
mapIndex=this.Options.getOption("player","map");arMap=[this.getMapType(mapIndex)];var mapOptions={mapTypes:arMap};map=new GMap2(get("mapCanvas"),mapOptions);map.setCenter(this.flight.boundsCenter,0,arMap[0]);var msize=new GSize(300,300);this.flight.zoom=map.getBoundsZoomLevel(this.flight.bounds,msize);if(this.flight.zoom===0)
{this.flight.zoom=6;}
map.setCenter(this.flight.boundsCenter,this.flight.zoom,arMap[0]);this.getInnerBounds();if(!this.view.innerBounds.containsBounds(this.flight.bounds))
{this.flight.zoom-=1;map.zoomOut();this.getInnerBounds();}
this.view.atDefault=true;map.savePosition();event=GEvent.bind(map,"zoomend",this,this.zoomEnd);this.mapEvents[this.mapEvents.length]=event;event=GEvent.bind(map,"movestart",this,this.moveStart);this.mapEvents[this.mapEvents.length]=event;event=GEvent.bind(map,"moveend",this,this.moveEnd);this.mapEvents[this.mapEvents.length]=event;event=GEvent.bind(map,"dragstart",this,this.mapOrViewChanging);this.mapEvents[this.mapEvents.length]=event;event=GEvent.bind(map,"maptypechanged",this,this.mapOrViewChanging);this.mapEvents[this.mapEvents.length]=event;var pos;pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(7,7));map.addControl(new GLargeMapControl3D(),pos);pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(80,7));map.addControl(new GScaleControl(),pos);createXcMapTypeControl();map.addControl(new XcMapTypeControl());var mapSelect=get("mapSelect");if(mapSelect)
{mapSelect.selectedIndex=mapIndex;}
this.trackMarker=new GMarker(this.flight.boundsCenter,{clickable:true,title:"Details"});event=GEvent.addListener(this.trackMarker,"click",actionMarkerTrack);this.mapEvents[this.mapEvents.length]=event;event=GEvent.addListener(this.trackMarker,"infowindowopen",actionIWOpen);this.mapEvents[this.mapEvents.length]=event;event=GEvent.addListener(this.trackMarker,"infowindowclose",actionIWClose);this.mapEvents[this.mapEvents.length]=event;map.addOverlay(this.trackMarker);this.player.sliderDiv=get("slider");var sliderBar=get("sliderBar");this.player.range=sliderBar.offsetWidth-this.player.sliderDiv.offsetWidth;this.player.slider=new GDraggableObject(this.player.sliderDiv,{container:sliderBar});this.data.display=get("dataTable");};XcApp.prototype.initRouteFromApp=function(route)
{var len,i;len=route.points.length;if(len<2)
{return;}
this.route.name=route.name;this.route.useIndex=route.useIndex;this.route.startFinish=route.startFinish;this.route.points=route.points;};XcApp.prototype.initRouteFromData=function()
{var i,len,point;if(this.route.useIndex)
{for(i=0,len=this.route.points.length;i<len;i+=1)
{this.route.points[i].dataIndex=this.getDataIndex(this.route.points[i].mainIndex);}}
this.toggleCheckbox("cbRoute",this.route.points.length>0);};XcApp.prototype.getMapIcon=function(name)
{var icon=new GIcon();icon.image=this.imageDir+"map-icon-"+name+".png";icon.iconSize=new GSize(12,20);icon.shadow=this.imageDir+"map-icon-shadow.png";icon.shadowSize=new GSize(22,20);icon.iconAnchor=new GPoint(6,20);icon.infoWindowAnchor=new GPoint(5,1);icon.printImage=this.imageDir+"map-icon-"+name+".gif";icon.imageMap=[4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0];icon.transparent=this.imageDir+"map-icon-transparent.png";return icon;};XcApp.prototype.getMapType=function(index)
{switch(index)
{case 0:return G_NORMAL_MAP;case 1:return G_SATELLITE_MAP;case 2:return G_HYBRID_MAP;case 3:return G_PHYSICAL_MAP;default:return G_HYBRID_MAP;}};XcApp.prototype.addDomEvents=function()
{var el,event;el=get("mapSelect");event=GEvent.addDomListener(el,"change",function()
{setTimeout(actionSelMap,10);});this.domEvents[this.domEvents.length]=event;el=get("trackSelect");event=GEvent.addDomListener(el,"change",actionSelTrack);this.domEvents[this.domEvents.length]=event;el=get("unitsSelect");event=GEvent.addDomListener(el,"change",actionSelUnits);this.domEvents[this.domEvents.length]=event;el=get("showSelect");event=GEvent.addDomListener(el,"change",actionSelShow);this.domEvents[this.domEvents.length]=event;el=get("cbZoomTo");event=GEvent.addDomListener(el,"click",actionCbZoomTo);this.domEvents[this.domEvents.length]=event;if(this.route.points.length>0)
{el=get("cbRoute");event=GEvent.addDomListener(el,"click",actionCbRoute);this.domEvents[this.domEvents.length]=event;}
el=get("cbStoryboard");event=GEvent.addDomListener(el,"click",actionCbStoryboard);this.domEvents[this.domEvents.length]=event;el=get("cbDefault");event=GEvent.addDomListener(el,"click",actionCbDefault);this.domEvents[this.domEvents.length]=event;if(this.trackFile)
{el=get("moreDetailLink");event=GEvent.addDomListener(el,"click",actionClickMoreDetail);this.domEvents[this.domEvents.length]=event;}
event=GEvent.addDomListener(this.player.slider,"drag",actionDragSlider);this.domEvents[this.domEvents.length]=event;el=get("sliderArrowBack");event=GEvent.addDomListener(el,"click",actionClickSliderBack);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseover",actionMsOverSlider);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseout",actionMsOutButton);this.domEvents[this.domEvents.length]=event;el=get("sliderArrowNext");event=GEvent.addDomListener(el,"click",actionClickSliderNext);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseover",actionMsOverSlider);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseout",actionMsOutButton);this.domEvents[this.domEvents.length]=event;el=document.getElementById("speedButtonDown");event=GEvent.addDomListener(el,"click",actionClickSpeedDown);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseover",actionMsOverSpeed);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseout",actionMsOutButton);this.domEvents[this.domEvents.length]=event;el=get("speedButtonUp");event=GEvent.addDomListener(el,"click",actionClickSpeedUp);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseover",actionMsOverSpeed);this.domEvents[this.domEvents.length]=event;event=GEvent.addDomListener(el,"mouseout",actionMsOutButton);this.domEvents[this.domEvents.length]=event;el=get("playButton");event=GEvent.addDomListener(el,"click",togglePlay);this.domEvents[this.domEvents.length]=event;};XcApp.prototype.removeDomEvents=function()
{var i,len;for(i=0,len=this.domEvents.length;i<len;i+=1)
{GEvent.removeListener(this.domEvents[i]);}
this.domEvents=[];};XcApp.prototype.removeMapEvents=function()
{var i,len;for(i=0,len=this.mapEvents.length;i<len;i+=1)
{GEvent.removeListener(this.mapEvents[i]);}
this.mapEvents=[];};XcApp.prototype.unload=function()
{this.removeDomEvents();this.removeMapEvents();if(this.Polylines.destroyPolylines)
{this.Polylines.destroyPolylines();}
this.Story.removeEvents();};XcApp.prototype.zoomEnd=function(oldLevel,newLevel)
{if(this.player.playing&&!this.player.paused)
{togglePlay();}};XcApp.prototype.mapOrViewChanging=function()
{if(this.player.playing)
{togglePlay();}};XcApp.prototype.moveStart=function()
{if(this.player.playing&&!this.player.panning)
{this.player.paused=true;}
map.savePosition();};XcApp.prototype.moveEnd=function()
{var zoom,inside;zoom=map.getZoom();this.getInnerBounds();inside=this.view.innerBounds.containsBounds(this.flight.bounds);this.view.atDefault=(zoom===this.flight.zoom&&this.view.innerBounds.containsBounds(this.flight.bounds));this.toggleCheckbox("cbDefault",!this.view.atDefault,this.view.atDefault);if(zoom>=this.flight.zoomToZoom&&this.flight.bounds.intersects(this.view.innerBounds))
{this.toggleCheckbox("cbZoomTo",true,true);}
else
{this.toggleCheckbox("cbZoomTo",true,false);}
if(this.player.playing)
{this.startPlayingTrack(true);}};XcApp.prototype.enablePlayer=function()
{this.player.dataMax=this.data.points.length-1;this.player.enabled=true;get("playButton").disabled=false;};XcApp.prototype.checkDownload=function(data,resp)
{var response,title,params,msg,json;response=parseInt(resp,10);title="Sorry, there has been an error";if(response===-1)
{msg="Timeout downloading data (-1)";}
else if(response!==200)
{msg="Track data file not found ("+response+")";}
else if(data===undefined)
{msg="No track data found (200)";}
if(msg!==undefined)
{params={title:title,msg:msg,error:1};showMessage(params);return;}
try
{json=eval("("+data+")");return json;}
catch(err)
{msg="Error in track data";params={title:title,msg:msg,error:1};showMessage(params);return;}};XcApp.prototype.processDownload=function(data,response)
{var params;this.trackData=this.checkDownload(data,response);if(this.trackData===undefined)
{if(this.data.points.length>0)
{setTimeout(function()
{app.enableMap();},2500);}
return;}
params={title:"",msg:"Processing data... please wait",error:0};showMessage(params);setTimeout(function()
{app.initXcPlayer();},10);};XcApp.prototype.initXcPlayer=function()
{var first,mainIndex,Data,ar,track,el;first=this.data.points.length===0;if(!first)
{mainIndex=this.getMainIndex(this.data.index);}
Data=new XcData(this.data,this.trackData);this.appStatus=Data.getData();if(!this.appStatus)
{showMessage({title:"Unable to load flight",msg:"Track data is missing",error:1});return;}
if(this.trackData.info.main.more)
{ar=this.trackFile.split(".");ar[ar.length-2]+="-"+this.trackData.info.main.more;this.trackFile=ar.join(".");}
else
{this.trackFile="";}
if(first)
{this.getFlightBounds(this.trackData.info.bounds);this.initMap();this.stats.duration=this.data.secs[this.data.secs.length-1];}
this.initRouteFromData();this.Story.initFromData(this.trackData.info.main.timezone);this.stats.trackInterval=this.trackData.info.main.delta;this.getStats(this.trackData.info.stats);this.writeShowSelect();this.initScales();if(first)
{track=this.writeTrackSelect();this.Units.writeUnitsSelect();this.refreshUnits();this.Polylines=new XcPolyline();}
else
{track=this.Polylines.active;this.Polylines.destroyPolylines();}
this.showTrack(track,{fromInit:true});el=get("trackInterval");if(!this.stats.trackInterval)
{setVisibility(0,1,el);}
else
{if(this.stats.trackInterval===1)
{el.innerHTML="Interval: "+this.stats.trackInterval+" sec";}
else
{el.innerHTML="Interval: "+this.stats.trackInterval+" secs";}
setVisibility(1,1,el);}
el=get("moreDetail");if(this.trackFile)
{el.style.visibility="visible";el.style.display="block";}
else
{el.style.visibility="hidden";el.style.display="none";}
if(first)
{this.data.index=0;this.updateMarker(this.gLatLngFromData(this.data.index));this.trackMarker.show();}
else
{this.data.index=this.getDataIndex(mainIndex);this.updateMap();}
this.trackData=null;this.enableMap();};XcApp.prototype.updateMap=function()
{this.infoWindow.refreshing=true;if(this.markerMap.active)
{if(this.markerMap.type===this.constants.TP_ROUTE)
{if(!map.getInfoWindow().isHidden())
{actionMarkerRoute(this.markerMap.index);}
else
{this.syncMarkerRoute(this.markerMap.index);}}
else
{this.syncMarkerStory(this.markerMap.index);}}
this.infoWindow.refreshing=false;};XcApp.prototype.getFlightBounds=function(bounds)
{var iLat,iLng,sw,ne;iLat=bounds.sw[0];iLng=bounds.sw[1];sw=new GLatLng(this.data.points[iLat][0],this.data.points[iLng][1]);iLat=bounds.ne[0];iLng=bounds.ne[1];ne=new GLatLng(this.data.points[iLat][0],this.data.points[iLng][1]);this.flight.bounds=new GLatLngBounds(sw,ne);this.flight.boundsCenter=this.flight.bounds.getCenter();};XcApp.prototype.enableMap=function()
{this.enablePlayer();this.addDomEvents();hideMessage();get("mapCanvas").style.background="#f5f5ff";get("mapCanvas").style.visibility="visible";get("dataTable2").style.visibility="visible";if(!this.Tabs.enabled)
{this.Tabs.enableTabs();}};XcApp.prototype.disableMap=function()
{var title,msg,params;this.Tabs.disableTabs();title="Loading detailed track";msg="Downloading data... please wait";params={title:title,msg:msg,error:0};showMessage(params);get("mapCanvas").style.visibility="hidden";this.removeDomEvents();if(app.player.playing)
{togglePlay();}
get("playButton").disabled=true;};XcApp.prototype.getStats=function(stats)
{var arNames,i,prop,index,name;arNames=[];arNames[0]=app.constants.DATA_HEIGHT;arNames[1]=app.constants.DATA_CLIMB;arNames[2]=app.constants.DATA_SPEED;for(i=0;i<3;i+=1)
{name=arNames[i];this.stats[name]=new XcObjStats(name);for(prop in stats[name])
{if(stats[name].hasOwnProperty(prop))
{index=stats[name][prop];this.stats[name][prop].index=index;this.stats[name][prop].value=this.data[name][index];if(this.stats[name][prop].value===undefined||isNaN(this.stats[name][prop].value))
{this.stats[name].ok=false;break;}}}}};XcApp.prototype.initScales=function()
{var name,max,maxMid,mid,minMid,min;this.scales.height=new XcScaleData();this.scales.climb=new XcScaleData();this.scales.speed=new XcScaleData();for(name in this.scales)
{if(this.scales.hasOwnProperty(name))
{if(!this.stats[name].ok)
{continue;}
if(name===app.constants.DATA_CLIMB)
{if(this.appStatus!==3)
{continue;}
max=this.stats[name].max.value;min=this.stats[name].min.value;maxMid=max/2;mid=0;minMid=min/2;}
else
{if(!this.checkAppStatus(name))
{continue;}
max=this.stats[name].max.value;min=this.stats[name].min.value;maxMid=(((max-min)/4)*3)+min;mid=((max-min)/2)+min;minMid=((max-min)/4)+min;}
this.scales[name].max=max;this.scales[name].maxMid=maxMid;this.scales[name].mid=mid;this.scales[name].minMid=minMid;this.scales[name].min=min;}}};XcApp.prototype.showTrack=function(name,opts)
{if(!opts)
{opts={};}
if(!this.Polylines.showPolyline(name,this.stats))
{return;}
if(opts.fromShow)
{this.updateSelect("trackSelect",name);}
this.writeScale();if(opts.fromInit===undefined)
{this.refreshInfoWindow();}};XcApp.prototype.updateSelect=function(id,value)
{var select,i,len;select=get(id);if(select.options[select.selectedIndex].value===value)
{return;}
for(i=0,len=select.options.length;i<len;i+=1)
{if(select.options[i].value===value)
{select.selectedIndex=i;break;}}};XcApp.prototype.writeScale=function()
{var name,image,caption,data,params;if(!this.Polylines.active)
{return;}
name=this.Polylines.active;image=get("scaleImage");if(name===app.constants.DATA_HEIGHT)
{image.style.backgroundPosition="top left";}
else if(name===app.constants.DATA_CLIMB)
{image.style.backgroundPosition="-10px 0px";}
else if(name===app.constants.DATA_SPEED)
{image.style.backgroundPosition="-20px 0px";}
if(this.checkAppStatus(name)&&this.stats[name].ok)
{data=new XcScaleData();params={forScale:true};data.max=this.Units.formatData(this.scales[name].max,name,params);data.maxMid=this.Units.formatData(this.scales[name].maxMid,name,params);data.mid=this.Units.formatData(this.scales[name].mid,name,params);data.minMid=this.Units.formatData(this.scales[name].minMid,name,params);data.min=this.Units.formatData(this.scales[name].min,name,params);caption=" "+this.Units.getCaption(name);data.max+="<span style=\"font-weight: normal\">"+caption+"</span>";}
else
{data=this.scales[name];}
get("scaleMax").innerHTML=data.max;get("scaleMaxMid").innerHTML=data.maxMid;get("scaleMid").innerHTML=data.mid;get("scaleMinMid").innerHTML=data.minMid;get("scaleMin").innerHTML=data.min;};XcApp.prototype.checkAppStatus=function(name)
{if(this.appStatus===3)
{return true;}
if(this.appStatus===2)
{return(name===app.constants.DATA_SPEED);}};XcApp.prototype.createRouteMarker=function(point,index,title)
{var event;this.route.markers[index]=new GMarker(point,{icon:this.route.icon,title:title});event=GEvent.addListener(this.route.markers[index],"click",function()
{actionMarkerRoute(index);});this.mapEvents[this.mapEvents.length]=event;};XcApp.prototype.showRoute=function(show)
{var gLatLngs,i,len;if(!this.Polylines.route)
{this.route.icon=this.getMapIcon("route");gLatLngs=this.Polylines.createRoute(this.route);for(i=0,len=this.route.points.length;i<len;i+=1)
{this.createRouteMarker(gLatLngs[i],i,this.route.points[i].caption);}}
for(i=0,len=this.route.markers.length;i<len;i+=1)
{if(show)
{map.addOverlay(this.route.markers[i]);}
else
{this.route.markers[i].closeInfoWindow();map.removeOverlay(this.route.markers[i]);}}
this.Polylines.toggleRoute(show);};XcApp.prototype.getRouteIndex=function(searchIndex,index)
{var i,len;for(i=0,len=app.route.points.length;i<len;i+=1)
{if(this.route.points[i][searchIndex]===index)
{return i;}}};XcApp.prototype.gLatLngFromData=function(index)
{return new GLatLng(this.data.points[index][0],this.data.points[index][1]);};XcApp.prototype.gLatLngFromArray=function(array)
{return new GLatLng(array[0],array[1]);};XcApp.prototype.writeShowSelect=function()
{var index,sel,opts,trackName,i,len,j;opts=[];sel=get("showSelect");index=0;opts[opts.length]={dataIndex:index,title:"Takeoff",track:""};index=this.data.points.length-1;opts[opts.length]={dataIndex:index,title:"Landing",track:""};if(this.appStatus===3)
{if(this.stats[app.constants.DATA_HEIGHT].ok)
{trackName=app.constants.DATA_HEIGHT;index=this.stats[app.constants.DATA_HEIGHT].max.index;opts[opts.length]={dataIndex:index,title:"Max Height",track:trackName};index=this.stats[app.constants.DATA_HEIGHT].low.index;if(index&&index!==this.data.points.length-1)
{opts[opts.length]={dataIndex:index,title:"Lowest Save",track:trackName};}}
if(this.stats[app.constants.DATA_CLIMB].ok)
{trackName=app.constants.DATA_CLIMB;index=this.stats[app.constants.DATA_CLIMB].max.index;opts[opts.length]={dataIndex:index,title:"Max Climb",track:trackName};index=this.stats[app.constants.DATA_CLIMB].min.index;opts[opts.length]={dataIndex:index,title:"Min Climb",track:trackName};}}
if(this.appStatus>=2&&this.stats[app.constants.DATA_SPEED].ok)
{trackName=app.constants.DATA_SPEED;index=this.stats[app.constants.DATA_SPEED].max.index;opts[opts.length]={dataIndex:index,title:"Max Speed",track:trackName};}
index=-1;opts[opts.length]={dataIndex:index,title:"Track point",track:""};sel.options.length=opts.length;for(i=0,len=opts.length;i<len;i+=1)
{sel.options[i].value=opts[i].dataIndex;sel.options[i].text=opts[i].title;this.highlights[i]=opts[i];this.highlights[i].links=[];for(j=0;j<len;j+=1)
{if(opts[j].dataIndex===this.highlights[i].dataIndex&&j!==i)
{this.highlights[i].links[this.highlights[i].links.length]=j;}}}};XcApp.prototype.writeTrackSelect=function()
{var sel;sel=get("trackSelect");sel.options.length=3;sel.options[0].value=app.constants.DATA_HEIGHT;sel.options[0].text="by Height";sel.options[1].value=app.constants.DATA_CLIMB;sel.options[1].text="by Climb";sel.options[2].value=app.constants.DATA_SPEED;sel.options[2].text="by Speed";if(this.appStatus===2)
{sel.selectedIndex=2;}
else
{sel.selectedIndex=0;}
return sel.options[sel.selectedIndex].value;};XcApp.prototype.getDataIndexFromSlider=function()
{var pos,valueRelPos;pos=parseInt(this.player.sliderDiv.style.left,10);this.player.sliderX=pos;valueRelPos=pos/this.player.range;if(isNaN(valueRelPos))
{valueRelPos=0;}
return Math.floor(this.player.dataMax*valueRelPos);};XcApp.prototype.syncMarkerRoute=function(index)
{var dataIndex,latLng;if(this.route.useIndex)
{dataIndex=this.route.points[index].dataIndex;if(dataIndex!==undefined)
{if(dataIndex!==this.data.index)
{this.data.index=dataIndex;latLng=this.gLatLngFromData(dataIndex);this.updateMarker(latLng);}}
else
{latLng=this.gLatLngFromArray(this.route.points[index].latLon);this.mapMarker(latLng,this.constants.TP_ROUTE,index);}}
return dataIndex;};XcApp.prototype.syncMarkerStory=function(mainIndex,story)
{var dataIndex,latLng;if(!story)
{story=this.Story.getStoryFromMainIndex(mainIndex);if(!story)
{return;}}
dataIndex=story.dataIndex;if(dataIndex!==undefined)
{if(dataIndex!==this.data.index)
{this.data.index=dataIndex;latLng=this.gLatLngFromData(dataIndex);this.updateMarker(latLng);}}
else
{latLng=this.gLatLngFromArray(story.data.points);this.mapMarker(latLng,this.constants.TP_STORY,mainIndex,story.data);}
return true;};XcApp.prototype.mapMarker=function(latLng,type,index,data)
{var p0,p1,pointsDistance,mappedDistance;this.markerMap.type=type;this.markerMap.index=index;this.data.index=closestVertex(this.Polylines.active,latLng);this.markerMap.dataIndex=this.data.index;if(this.data.index===0)
{this.markerMap.dataNext=1;this.markerMap.dataBack=0;}
else
{p1=app.gLatLngFromData(this.data.index);p0=app.gLatLngFromData(this.data.index-1);pointsDistance=p0.distanceFrom(p1);mappedDistance=p0.distanceFrom(latLng);if(pointsDistance>mappedDistance)
{this.markerMap.dataNext=this.data.index;this.markerMap.dataBack=this.data.index-1;}
else
{this.markerMap.dataNext=this.data.index+1;this.markerMap.dataBack=this.data.index;}}
this.updateMarkerEx(latLng,{moveSlider:1,mapping:1});};XcApp.prototype.unmapMarker=function()
{var latLng;latLng=this.gLatLngFromData(this.markerMap.dataIndex);this.updateMarkerEx(latLng,{moveSlider:1,mapping:0});};XcApp.prototype.updateMarker=function(latLng,fromChangeShow)
{this.moveMarker(latLng);this.moveSlider();this.refreshData(fromChangeShow);};XcApp.prototype.updateMarkerEx=function(latLng,opts)
{if(!opts)
{opts={};}
if(opts.mapping!==undefined)
{this.markerMap.active=0;}
this.moveMarker(latLng,opts.userClick);if(opts.moveSlider||opts.userClick)
{this.moveSlider();}
if(opts.mapping)
{this.markerMap.active=1;}
this.refreshData(opts.changeShow);};XcApp.prototype.moveMarker=function(latLng,userClick)
{var diff;if(this.markerMap.active&&userClick)
{diff=this.markerMap.dataIndex-this.data.index;if(Math.abs(diff)===1)
{this.markerMap.dataIndex=this.data.index;if(diff===1)
{this.data.index=this.markerMap.dataBack;}
else
{this.data.index=this.markerMap.dataNext;}
if(this.data.index!==this.markerMap.dataIndex)
{latLng=this.gLatLngFromData(this.data.index);}}}
this.markerMap.active=0;if(!this.infoWindow.refreshing)
{if(!map.getInfoWindow().isHidden())
{this.trackMarker.closeInfoWindow();}
this.showHiddenMarkers();}
this.trackMarker.setLatLng(latLng);};XcApp.prototype.showHiddenMarkers=function()
{var i,len;len=this.hiddenMarkers.length;if(!len)
{return;}
for(i=0;i<len;i+=1)
{if(this.hiddenMarkers[i].marker)
{this.hiddenMarkers[i].marker.show();}}
this.hiddenMarkers=[];};XcApp.prototype.hideMarkers=function(mainIndex)
{var i,len;for(i=0,len=this.route.points.length;i<len;i+=1)
{if(this.route.points[i].mainIndex===mainIndex)
{if(this.route.markers[i])
{this.hideMarker(this.route.markers[i],mainIndex,app.constants.TP_ROUTE);}
break;}}
for(i=0,len=this.Story.boards.length;i<len;i+=1)
{if(this.Story.boards[i].mainIndex===mainIndex)
{if(this.Story.boards[i].marker)
{this.hideMarker(this.Story.boards[i].marker,mainIndex,app.constants.TP_STORY);}
break;}}};XcApp.prototype.hideMarker=function(marker,mainIndex,type)
{var i,len;if(!marker.isHidden())
{marker.hide();}
for(i=0,len=this.hiddenMarkers.length;i<len;i+=1)
{if(this.hiddenMarkers[i].mainIndex===mainIndex&&this.hiddenMarkers[i].type===type)
{return;}}
this.hiddenMarkers[len]={marker:marker,mainIndex:mainIndex,type:type};};XcApp.prototype.getSliderX=function(dataIndex)
{var valueRelPos;valueRelPos=dataIndex/this.player.dataMax;if(isNaN(valueRelPos))
{valueRelPos=0;}
this.player.sliderX=Math.floor(this.player.range*valueRelPos);return this.player.sliderX;};XcApp.prototype.moveSlider=function()
{var pt=new GPoint(this.getSliderX(this.data.index),0);this.player.slider.moveTo(pt);};XcApp.prototype.startPlayingTrack=function(endMove)
{if(endMove===undefined)
{if(this.data.index===this.player.dataMax)
{this.data.index=0;}
this.player.playing=true;}
this.player.paused=false;setTimeout(function()
{app.playTrack();},500);};XcApp.prototype.playTrack=function()
{if(!this.player.playing||this.player.paused)
{return;}
if(this.data.index+1>this.player.dataMax)
{togglePlay();return;}
else
{this.data.index+=1;}
if(this.stepTrack())
{setTimeout(function()
{app.playTrack();},200);}
else
{this.data.index-=1;}};XcApp.prototype.stopPlayingTrack=function()
{this.player.playing=false;this.updateShowSelect();};XcApp.prototype.stepTrack=function(userClick)
{var latLng;latLng=this.gLatLngFromData(this.data.index);this.player.panning=false;if(!this.view.innerBounds.containsLatLng(latLng))
{this.player.panning=true;map.panTo(latLng);if(!userClick)
{return false;}}
if(userClick)
{this.updateMarkerEx(latLng,{userClick:1});}
else
{this.updateMarker(latLng);}
return true;};XcApp.prototype.refreshData=function(fromChangeShow)
{var data,name;if(this.refreshMappedData())
{return;}
data={};data.time=this.data.time[this.data.index];data.duration=timeFromSecs(this.data.secs[this.data.index],true);data.distance=this.Units.formatData(this.data.distance[this.data.index],name);if(this.appStatus===3)
{data.height=this.Units.formatData(this.data.height[this.data.index],"height");data.climb=this.Units.formatData(this.data.climb[this.data.index],"climb");data.speed=this.Units.formatData(this.data.speed[this.data.index],"speed");}
else if(this.appStatus===2)
{data.height="";data.climb="";data.speed=this.Units.formatData(this.data.speed[this.data.index],"speed");}
else
{if(!data.time)
{data.time="No data";}
data.height="";data.climb="";data.speed="";}
this.writePlayerData(data);if(fromChangeShow===undefined)
{this.updateShowSelect();}};XcApp.prototype.refreshMappedData=function()
{var story;if(!this.markerMap.active)
{return false;}
if(this.markerMap.type===this.constants.TP_ROUTE)
{this.clearPlayerData();return true;}
story=this.Story.getStoryFromMainIndex(this.markerMap.index);if(story)
{this.refreshDataFromStory(story.data);return true;}};XcApp.prototype.refreshDataFromStory=function(storyData)
{var data,name;data={};data.time=storyData.time;data.duration=timeFromSecs(storyData.secs,true);for(name in this.Units.names)
{if(this.Units.names.hasOwnProperty(name))
{data[name]=this.Units.formatData(storyData[name],name);}}
this.writePlayerData(data);};XcApp.prototype.writePlayerData=function(data,clear)
{var s,caption,width;s="<table class=\"mapDataTable1\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tbody>";s+="<tr><td>Time:</td><td><b>"+data.time+"</b></td></tr>";s+="<tr><td>Height:</td><td><b>"+data.height+"</b></td></tr>";s+="<tr><td>Climb:</td><td><b>"+data.climb+"</b></td></tr>";s+="<tr><td>Speed:</td><td><b>"+data.speed+"</b></td></tr>";s+="</tbody></table>";this.data.display.innerHTML=s;if(clear)
{get("dataTable2").innerHTML="";return;}
caption=" "+this.Units.getCaption("distance");if(this.Units.getUnitFlag("distance")===this.constants.UNITS_METRIC)
{width=60;}
else
{width=65;}
s="<table class=\"mapDataTable2\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";s+="<tbody><tr>";if(!data.duration)
{s+="<td width=\"105\">&nbsp;</td>";}
else
{s+="<td width=\"50\">Duration:</td>";s+="<td width=\"50\"><b>"+data.duration+"</b> hrs</td>";s+="<td width=\"5\">&nbsp;</td>";}
s+="<td width=\"100\">Takeoff Distance:</td>";s+="<td width=\""+width+"\"><b>"+data.distance+"</b>"+caption+"</td>";s+="</tr></tbody></table>";get("dataTable2").innerHTML=s;};XcApp.prototype.clearPlayerData=function()
{var data={time:"No data",height:"",climb:"",speed:"",duration:"",distance:""};this.writePlayerData(data,true);get("showSelect").selectedIndex=7;};XcApp.prototype.updateShowSelect=function()
{var sel,i,len,found;if(this.player.playing)
{return;}
sel=get("showSelect");for(i=0,len=sel.options.length;i<len;i+=1)
{if(this.data.index===parseInt(sel.options[i].value,10))
{found=true;sel.selectedIndex=i;break;}}
if(!found)
{sel.selectedIndex=sel.options.length-1;}};XcApp.prototype.refreshUnits=function()
{var s,el;s=this.Units.getUnitsDisplayTable();el=get("unitsDisplay");el.innerHTML=s;};XcApp.prototype.refreshInfoWindow=function()
{if(map&&!map.getInfoWindow().isHidden())
{if(this.infoWindow.track)
{actionMarkerTrack();}}};XcApp.prototype.iwState=function(noMsg)
{var result;result={showing:0,editing:0};if(!map.getInfoWindow().isHidden())
{result.showing=1;if(this.Story.iwEditId!==undefined)
{result.editing=1;if(!noMsg)
{alert("Please finish entering your story");}}}
return result;};XcApp.prototype.iwSetReshow=function()
{app.infoWindow.refreshing=true;map.closeInfoWindow();app.infoWindow.reshow=true;};XcApp.prototype.iwCheckReshow=function()
{if(this.infoWindow.reshow)
{actionMarkerTrack();this.infoWindow.reshow=false;}};XcApp.prototype.getDataIndex=function(mainIndex)
{var len,i,dataIndex;len=this.data.mainIndex.length;dataIndex=undefined;for(i=0;i<len;i+=1)
{if(this.data.mainIndex[i]===mainIndex)
{dataIndex=i;break;}}
return dataIndex;};XcApp.prototype.getMainIndex=function(dataIndex)
{var mainIndex=0;if(this.data.mainIndex[dataIndex]!==undefined)
{mainIndex=this.data.mainIndex[dataIndex];}
return mainIndex;};XcApp.prototype.getInfoRoute=function(index)
{var zoom,info,ar,caption,dataIndex;zoom=(map.getZoom()<this.flight.zoomToZoom);info=this.Story.storyForRoute(index,zoom);ar=[];ar[0]={name:"title",value:this.route.name};caption="<b>"+this.route.points[index].caption+"</b>";if(this.route.useIndex)
{dataIndex=this.route.points[index].dataIndex;if(dataIndex!==undefined)
{ar[ar.length]={name:"time",value:this.data.time[dataIndex]};caption=this.getRouteCaption(dataIndex,caption);ar[ar.length]={name:"Point",value:caption};}
else
{ar[ar.length]={name:"Point",value:caption};}
this.getRouteData(dataIndex,info,ar);}
else
{ar[ar.length]={name:"Point",value:caption};}
if(this.route.points[index].cylinder!==undefined)
{ar[ar.length]={name:"Cylinder",value:this.route.points[index].cylinder+"m"};}
this.getIWTrackPos(this.route.points[index].latLon,ar);return this.writeIWHtml(ar,info.links);};XcApp.prototype.getInfoTrack=function(dataIndex,edit)
{var info,s,ar,name,value;info=this.Story.storyForIW(dataIndex,edit);if(info.html)
{s=info.html;}
else
{ar=[];ar[0]={name:"title",value:this.getHighlightCaption(dataIndex)};ar[1]={name:"time",value:this.data.time[dataIndex]};this.getIWTrackData(this.data,dataIndex,ar);this.getIWTrackPos(this.data.points[dataIndex],ar);s=this.writeIWHtml(ar,info.links);}
return{html:s,opts:info.opts};};XcApp.prototype.getInfoStory=function(mainIndex,edit)
{var info;info=this.Story.storyForIW(null,edit,mainIndex);if(info.html)
{return{html:info.html,opts:info.opts};}};XcApp.prototype.writeIWHtml=function(data,links)
{var s;s="<div class=\"infoBoxSmall\">";s+=this.getIWHeader(data,1);if(links)
{s+="<div class=\"storyLink\">";s+=links;s+="</div>";}
s+="</div>";return s;};XcApp.prototype.getRouteData=function(dataIndex,info,arOut)
{var name,data;name=this.Polylines.active;if(dataIndex===undefined)
{name=this.Units.ucFirst(this.Polylines.active);data="Data unavailable";if(info.links)
{data+=" ";data+=info.links;info.links="";}
arOut[arOut.length]={name:name,value:data};}
else
{this.getIWTrackData(this.data,dataIndex,arOut);}};XcApp.prototype.getRouteCaption=function(dataIndex,caption)
{var s;if(!caption)
{caption="";}
s=this.getHighlightCaption(dataIndex);if(s&&s!=="Track point")
{if(caption)
{caption+=" - also ";}
caption+=s;}
return caption;};XcApp.prototype.getIWTrackPos=function(arLatLon,arOut)
{var latLon="";if(arLatLon&&arLatLon.length===2)
{latLon=arLatLon[0].toFixed(5);latLon+=", ";latLon+=arLatLon[1].toFixed(5);}
if(arOut)
{arOut[arOut.length]={name:"Position",value:latLon};}};XcApp.prototype.getIWTrackData=function(data,index,arOut)
{var result,name,value;name=this.Polylines.active;value=(index!==-1?data[name][index]:data[name]);if(value===undefined)
{return;}
if(this.appStatus===3)
{result=this.Units.getFullData(name,value);}
else if(this.appStatus===2)
{if(name==="speed")
{result=this.Units.getFullData(name,value);}}
if(result&&arOut)
{arOut[arOut.length]=result;}
else
{return result;}};XcApp.prototype.getIWHeader=function(arData,cols)
{var s,start,classRef,colSpanTh,colSpanTd,i,i2,len;classRef="";colSpanTitle="";colSpanTd="";start=1;s="<table class=\"infoTable\"";s+=" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";s+="<colgroup>";if(cols===3)
{s+="<col width=\"13%\" /> <col width=\"17%\" />";s+="<col width=\"13%\" /> <col width=\"17%\" />";s+="<col width=\"13%\" /> <col width=\"*\" />";colSpanTitle=" colspan=\"5\"";}
else if(cols===2)
{s+="<col width=\"15%\" /> <col width=\"35%\" />";s+="<col width=\"15%\" /> <col width=\"35%\" />";colSpanTitle=" colspan=\"3\"";}
else
{s+="<col width=\"25%\" /> <col width=\"45%\" /> <col width=\"30%\" />";colSpanTitle=" colspan=\"2\"";}
s+="</colgroup><tbody>";s+="<tr>";s+="<th";s+=colSpanTitle;s+=" class=\"tblTitle\">";s+=arData[0].value;s+="</th>";s+="<th class=\"tblCaption\">";if(arData[1].name==="time")
{s+=arData[1].value;start=2;}
else
{s+="&nbsp;";}
s+="</th>";s+="</tr>";if(cols>1)
{classRef=" class=\"tblDiv\"";}
else
{colSpanTd=" colspan=\"2\"";}
i=start;len=arData.length;while(i<len)
{s+="<tr>";for(i2=0;i2<cols;i2+=1)
{s+="<td class=\"tblLabel\">";if(arData[i]&&arData[i].name)
{s+=arData[i].name;}
s+=":</td>";s+="<td";s+=colSpanTd;if(i2!==cols-1)
{s+=classRef;}
s+=">";if(arData[i]&&arData[i].value)
{s+=arData[i].value;}
s+="</td>";i+=1;}
s+="</tr>";}
s+="</tbody></table>";return s;};XcApp.prototype.getHighlightCaption=function(index)
{var s,sel,selIndex,linkIndex,i,len;s="Track point";sel=get("showSelect");selIndex=sel.selectedIndex;if(selIndex===sel.options.length-1)
{return s;}
if(parseInt(sel.options[selIndex].value,10)===index)
{s=this.highlights[selIndex].title;for(i=0,len=this.highlights[selIndex].links.length;i<len;i+=1)
{linkIndex=this.highlights[selIndex].links[i];s+=", "+this.highlights[linkIndex].title;}}
return s;};XcApp.prototype.toggleCheckbox=function(name,show,check)
{var cb,color,text;cb=get(name);if(cb)
{if(show!==cb.disabled&&((check===undefined)?true:(check===cb.checked)))
{return;}
if(show)
{cb.disabled=false;color="#000";}
else
{cb.disabled=true;color="#c0c0c0";}
text=get(name+"-text");if(text)
{text.style.color=color;}
if(check!==undefined)
{cb.checked=check;}}};
