function deleteWorkout(workoutId){
  document.location = "requestHandler?command=deleteWorkout&Id=" + workoutId;
}

function addWorkout(date){
    theUrl = "requestHandler?command=addWorkout&Date=" + date;
    Modalbox.show("Add workout", ajax(theUrl), {width:600, height:700});
}

function editWorkout(id){
    theUrl = "requestHandler?command=editWorkout&Id=" + id;
    Modalbox.show("Edit workout", ajax(theUrl), {width:600, height:700});
}

function editDay(date){
    theUrl = "requestHandler?command=editDay&Date=" + date;
    Modalbox.show("Edit " + date, ajax(theUrl), {width:600, height:700});
}

function deleteRace(raceId){
  document.location = "requestHandler?command=deleteRace&Id=" + raceId;
}

function deletePeriod(periodId){
  document.location = "requestHandler?command=deletePeriod&Id=" + periodId;
}

function addPeriod(date){
   theUrl = "requestHandler?command=addPeriod&Date=" + date;
   Modalbox.show("Add Period", ajax(theUrl), {width:600, height:750});
}

function editPeriod(id){
   theUrl = "requestHandler?command=editPeriod&Id=" + id;
   Modalbox.show("Edit Period", ajax(theUrl), {width:600, height:750});
}

function addRace(){
   theUrl = "requestHandler?command=addRace";
   Modalbox.show("Add Race", ajax(theUrl), {width:700, height:700});
}

function editRace(id){
   theUrl = "requestHandler?command=editRace&Id=" + id;
   Modalbox.show("Edit Race", ajax(theUrl), {width:700, height:750});
}

function editGoals(year){
   theUrl = "requestHandler?command=editGoals&Year=" + year; 
   Modalbox.show("Edit Goals", ajax(theUrl), {width:600});
}

function addShare(){
   theUrl = "requestHandler?command=addShare";
   Modalbox.show("Add Share", ajax(theUrl), {width:700, height:700});
}

function deleteShare(shareId){
   document.location = "requestHandler?command=deleteShare&Id=" + shareId;
}

function viewSharedAccount(email){
   document.location = "requestHandler?command=viewSharedAccount&Email=" + email;
}

function editComment(date){
   theUrl = "requestHandler?command=editComments&Date=" + date;
   Modalbox.show("Edit Comments", ajax(theUrl), {width:700, height:700});
}

function exportWeek(date){
  theUrl = "requestHandler?command=exportWeek&Date=" + date;
  Modalbox.show("Export Week", ajax(theUrl), {width:600, height:500});
}

function showWeekFor(d,m,y){
   document.location='requestHandler?command=showWeek&Date=' + d + '/' + m + '/' + y;
}

function showNavigator(date) {
   theUrl = 'requestHandler?command=showOpenNavigator&Date=' + date;
   new Ajax.Updater('calendarNavigatorHolder', theUrl, {method:'get'}); 
}

function hideNavigator(date) {
   theUrl = 'requestHandler?command=showClosedNavigator&Date=' + date;
   new Ajax.Updater('calendarNavigatorHolder', theUrl, {method:'get'}); 
}

function switchOut(a, b){
  document.getElementById(a).style.display = 'none';
  document.getElementById(b).style.display = 'block';
}

function changeUnits(activity) {
  document.getElementById(unitsFor(activity.value)).selected = true;
}

function unitsFor(activity) {
  if (activity == "Swim") return "m";
  if (activity == "Bike") return "km";
  if (activity == "Run") return "km";
  return "text";
}

function distanceNumbers(distance, distanceUnits){
  if (distanceUnits == "text") return;
  numbersOnly(distance);
}

function changeTimezone(){
   theUrl = "requestHandler?command=editTimezone";
   Modalbox.show("Change Timezone", ajax(theUrl), {width:600});
}

function cancelForm(){

	Modalbox.hide();
  //history.back;
}

function ajax(theUrl){
  return theUrl + "&aUn=" + new Date().valueOf() + "&RequestType=AJAX";
}

function numbersOnly(obj){
  reg = /[^0-9]/g;
  obj.value =  obj.value.replace(reg,"");
}

function decimalsOnly(obj){
  //reg = ^\d*\.?\d*$;
  reg = /[^0-9.]/g;
  obj.value =  obj.value.replace(reg,"");  
}