/*global document */
/*jslint devel: true */ /* doesn't flag alert */
var input_yyyy = 0;
var input_mm   = 0;
//  daysinmonth = [0,ja,fb,mr,ap,my,jn,jl,au,se,oc,no,de];
var daysinmonth = [0,31,29,31,30,31,30,31,31,30,31,30,31];
function validate_yyyy (idyyyy) {
  if (!document.getElementById) {return true;}
  var numericExpression = /^[0-9]+$/;
  var yyyy = document.getElementById(idyyyy).value;
  if (yyyy.length != 4 /* || yyyy.substr(0,1) == '0' */ || !yyyy.match(numericExpression)) {
    alert("Year specified is invalid\nPlease reenter as 4 digits");
    document.getElementById(idyyyy).focus();
    return false;}
  input_yyyy = yyyy;
  if (yyyy % 4 === 0 && ((yyyy % 100 !== 0) || (yyyy % 400 === 0))) {daysinmonth[2] = 29;} else {daysinmonth[2] = 28;}
  return true;
  }
function validate_mm (idmm) {
  if (!document.getElementById) {return true;}
  var mm = document.getElementById(idmm).value;
  var numericExpression = /^[0-9]+$/;
  if (!mm.match(numericExpression) || mm < 1 || mm > 12) {
    alert("Please select month");
    document.getElementById(idmm).focus();
    return false;}
  input_mm = mm;
  return true;
  }
function validate_dd (iddd) {
  if (!document.getElementById) {return true;}
  var monthnames=["","January","February","March","April","May","June","July","August","September","October","November","December"];
  var dd = document.getElementById(iddd).value;
  var numericExpression = /^[0-9]+$/;
  if (!dd.match(numericExpression) || dd < 1 || dd > daysinmonth[input_mm]) {
    alert("Invalid day of month for " + monthnames[input_mm] + " " + input_yyyy);
    document.getElementById(iddd).focus();
    return false;}
  return true;
  }
function validate_cdlo (iddd) {
  if (!document.getElementById) {return true;}
  var dd = document.getElementById(iddd).value;
  var numericExpression = /^[0-9]+$/;
  if (!dd.match(numericExpression) || dd > 99) {
    alert("Please enter candle lighting offset in minutes between 0 and 99");
    document.getElementById(iddd).focus();
    return false;}
  return true;
  }
function validate_loc (iddd) {
  if (!document.getElementById) {return true;}
  var onlywhitespace = /^\s*$/;
  var dd = document.getElementById(iddd).value;
  if (dd.match(onlywhitespace)) {
    return false;}
  return true;
  }
function validate_yyyymmdd (idyyyy, idmm, iddd) {
  if (!validate_yyyy (idyyyy)) {return false;}
  if (!validate_mm   (idmm  )) {return false;}
  if (!validate_dd   (iddd  )) {return false;}
  return true;
  }