var tipPFC = "Percentage of calories from<br>Protein/Fat/Carbohydrates";
var tipSupset = '<p class="p0"><b>Superset combines several exercises.</b></p>'
  +'<p class="p5">For example, you do 10 reps of Barbell Bench Press followed by 8 reps of Dumbbell Bench Press without any rest in between.';
  +'This is one set of your combination exersise - one superset.</p>'
  +'<p class="p5"><i>Supersets put a lot of stress on your body, do not do them every workout.</i></p>';
function exPopup(exId) {
  return exPopupMs(exId, "");
}
function exPopupMs(exId, ms, ind) {
  wnd = window.open("expopup.jsp?id="+exId+"&ms="+ms+"&ind="+ind, "exPopup", "width=570,height=500,scrollbars,resizable");
  wnd.focus();
  return false;
}
function exBodyMap() {
  wnd = window.open("img/body_map.jpg", "bodyMap", "width=410,height=420");
  wnd.focus();
  return false;
}
function msgPopup(name) {
  wnd = window.open(name, "msgPopup", "width=550,height=500,scrollbars,resizable");
  wnd.focus();
  return false;
}
function hlpPopup() {
  wnd = window.open("help/default.htm", "hlpPopup", "width=640,height=500,scrollbars,resizable");
  wnd.focus();
  return false;
}
function banPopup(name) {
  wnd = window.open(name, "", "");
  wnd.focus();
}
function setSelVal(sel, val) {
  for (var i=0; i<sel.options.length; i++) {
    if (sel.options[i].value==val) {
      sel.selectedIndex=i;
      break;
    }
  }
}
function chkSel(sel) {
  var opt = sel.options[sel.selectedIndex];
  if (opt.value==0 && opt.text!="") {
    for (var i=sel.selectedIndex; i<sel.options.length; i++) {
      opt = sel.options[i];
      if (opt.value!=0) {
        sel.selectedIndex=i;
        break;
      }
    }
  }
}
function foodPopup(foodId, unitNo) {
  wnd = window.open("food.do?food="+foodId+"&unit="+unitNo+"&popview=1", "foodView", "width=570,height=500,scrollbars,resizable");
  wnd.focus();
  return false;
}
function getCookie(name) {
  var result='';
  aCookies = document.cookie.split(';');
  var s;
  for (var i=0; i<aCookies.length; i++) {
    s = trimLeft(aCookies[i]);
    if (s.indexOf(name+'=')==0) {
      result=s.substr(name.length+1);
      break;
    }
  }
  return result;
}
//
// == String
//
function trimLeft(s) {
  var len = s.length;
  var code, start = 0;
  for (var i = 0; i < len; i++) {
    code = s.charCodeAt(i);
    if ((code == 9) || (code == 10) || (code == 13) || (code == 32))
      start = i+1; // store the next position
    else break;
  }
  return s.substr(start);
}
function trimRight(s) {
  var len = s.length;
  var code, end = s.length-1;
  for (var i = end; i >= 0; i--) {
    code = s.charCodeAt(i);
    if ((code == 9) || (code == 10) || (code == 13) || (code == 32))
      end = i-1; // store the previous position
    else break;
  }
  return s.substr(0,len-(len-(end+1)));
}
function trim(s) {
  return TrimLeft(TrimRight(s));
}
function fillExsListbox(cb, exs, unlistedName, selected, line, newUnlisted) {
  for (var i=0; i<exs.length; i++) {
    if (exs[i]>0) {
      cb.options[i] = new Option(window.top.exs[exs[i]], exs[i], false, false);
    } else {
      cb.options[i] = new Option(unlistedName, exs[i], false, false);
    }
  }
  if (line!=null) {
    var n = Number(line);
    if (!isNaN(n) && n>0) {
      line = ""; for (var i=0; i<n; i++) line += "-";
    }
    cb.options[cb.length] = new Option(line, 0, false, false);
  }
  if (newUnlisted!=null && newUnlisted!=0) cb.options[cb.length] = new Option(" Not Listed ", newUnlisted, false, false);
  for (var i=0; i<cb.length; i++) { if (cb.options[i].value==selected) { cb.selectedIndex=i; break; } }
  if (cb.selectedIndex==-1) cb.selectedIndex = 0;
}

