
var _URL='ws';var _currentHash;var _timer;function start(){historyReset();_timer=setTimeout(onTick,500);return _go('home');}
function stop(){_go('exit');}
function onTick(){clearTimeout(_timer);if(document.location.hash!=null){var hash=document.location.hash.substr(1);if(hash!=_currentHash){_currentHash=hash;WebRequest.execute('GET','a=back');}}
_timer=setTimeout(onTick,500);}
function onHome(){clearTimeout(_timer);return start();}
function onSignout(){clearTimeout(_timer);historyReset();_timer=setTimeout(onTick,500);return _go('signout');}
function o(source,id){source.className='selected';return _go('li',id);}
function onMenuItem(id){return _go('mi');}
function onTextArea(obj){var attr=obj.attributes['href'];var href=attr!=null?attr.value:"";if(startsWith(href,"http:")||startsWith(href,"tel:")||startsWith(href,"mailto:")){return true;}else{_go('ta',href);return false;}}
function onBack(){return _go('back',null);}
function onNext(){return _go('next',null);}
function onPrevious(){return _go('previous',null);}
function onSave(){var textarea=document.getElementById('p');var param=(textarea!=null)?textarea.value:_getDate().getTime();return _goPost('editsave',param);}
function onCancel(){return _go('editcancel',null);}
function onSignin(){var email=document.getElementById('email').value;var password=document.getElementById('password').value;if(email.length==0){alert("Please enter a valid email");return false;}
else if(password.length==0){alert("Please enter a password");return false;}
var param=email+"|"+password;return _go('signin',param);}
function _go(action,param){var data="a="+action;if(param!=null)data+="&p="+encodeURIComponent(param);WebRequest.execute('GET',data);return false;}
function _goPost(action,param){var data="a="+action+"&p="+encodeURIComponent(param);WebRequest.execute('POST',data);return false;}
function onResponse(html){if(html.substr(0,4)=='<!--'){var index=html.indexOf('-->');if(index>0){var script=html.slice(4,index);eval(script);}}else{document.body.innerHTML=html;scrollTop();historyAdd();}}
function historyAdd(){_currentHash++;document.location.hash=_currentHash;}
function historyReset(){_currentHash=0;document.location.hash=_currentHash;}
function WebRequest(){}
WebRequest.execute=function(method,data){var xmlhttp=new XMLHttpRequest();var url=_URL;WebRequest.data=data;if(method=='GET'){if(data!=null&&data!=''){var sep=(url.indexOf('?')>=0)?'&':'?';url+=sep+data;}
xmlhttp.open('GET',url);}
else{xmlhttp.open('POST',url,true);xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}
xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){onResponse(xmlhttp.responseText);}else{alert('There was a problem with the request.\r\n\r\nUrl: '+url+'\r\nData:'+data+'\r\nHttp Response Code: '+xmlhttp.status+' '+xmlhttp.statusText+'\r\nDescription: '+xmlhttp.responseText);}}}
xmlhttp.send((method=='GET')?null:data);}
function promptText(title,text){var newtext=prompt(title,text);if(newtext!=null&&newtext!=text){return _goPost('editsave',newtext);}else{onCancel();}}
function promptDate(title,date){writePageStart(title);_buf.push('<div class=date><select id=day></select><select id=month onchange="onDateChange()"></select><select id=year onchange="onDateChange()"></select></div>');writePageStop();setDate(date);}
function promptTextArea(title,text){writePageStart(title);_buf.push('<textarea id=p style="height:150px" onblur="scrollTop()" >',text,'</textarea>');writePageStop();}
var _buf=[''];function writePageStart(title){_buf.push('<div id=toolbar><h1');_buf.push((title.length<12)?' class=small ':'');_buf.push('>',title,'</h1>');_buf.push('<a class="button leftbutton" onclick="onCancel()">Cancel</a><a class="button bluebutton" onclick="onSave()">Save</a>');_buf.push('</div><div id=main class=roundlist>');}
function writePageStop(){_buf.push('</div>');document.body.innerHTML=_buf.join('');_buf=[''];scrollTop();}
function setDate(epochTime){var date=new Date();date.setTime(epochTime);var year=document.getElementById('year');if(year.options.length==0){for(i=2000;i<=2020;i++)_addOption(year,i,i);}
year.selectedIndex=date.getFullYear()-2000;var month=document.getElementById('month');if(month.options.length==0){for(i=0;i<=11;i++)_addOption(month,MONTHS[i],i);}
month.selectedIndex=date.getMonth();_updateDaysCombo(date);}
var MONTHS=['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec'];var DAYS=['Sun','Mon','Tue ','Wed','Thu','Fri','Sat'];function _addOption(select,text,value){var option=document.createElement('option');option.text=text;option.value=value;select.add(option);}
function _getValue(select){var sel=document.getElementById(select);return sel.options[sel.selectedIndex].value;}
function _getDate(){var day=_getValue('day');var month=_getValue('month');var year=_getValue('year');var date=new Date();date.setFullYear(year,month,day);return date;}
function _getDaysInMonth(date){var year=date.getFullYear();var month=date.getMonth();return[31,((!(year%4)&&((year%100)||!(year%400)))?29:28),31,30,31,30,31,31,30,31,30,31][month];}
function _getDayOfWeek(year,month,day){var date=new Date();date.setFullYear(year,month,day);return DAYS[date.getDay()]+' '+(i<10?'0'+i:i);}
function _updateDaysCombo(date){var day=document.getElementById('day');while(day.options.length>0){day.remove(0);}
var nbDays=_getDaysInMonth(date);for(i=1;i<=nbDays;i++){_addOption(day,_getDayOfWeek(date.getFullYear(),date.getMonth(),i),i);}
day.selectedIndex=date.getDate()-1;}
function onDateChange(){var newDate=_getDate();_updateDaysCombo(newDate);}
window.onorientationchange=function(){scrollTop();}
function scrollTop(){var y=(window.navigator.standalone==true)?0:100;setTimeout(scrollTo,y,0,1);}
function search(obj){var ul=document.getElementById("l");if(ul==null||ul.childNodes==null)return;var ul2=document.getElementById("l2");if(ul2==null){return;}
var str=obj.value.toLowerCase();if(str==null||str.length==0){ul2.style.display='none';ul.style.display='';ul2.innerHTML='';return;}
var buf=[];var count=ul.childNodes.length;for(var i=0;i<count;i++){var child=ul.childNodes[i];var text=child.innerText.toLowerCase().split(' ');for(var j=0;j<text.length;j++){if(text[j].match("^"+str)==str){buf.push(child.outerHTML);break;}}}
ul2.innerHTML=buf.join('');ul2.style.display='';ul.style.display='none';}
function startsWith(str1,str2){return str1.match("^"+str2)==str2;}