function getArgs(location) {
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split("&");
  for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    if (pos == -1) continue;
    var argname = pairs[i].substring(0,pos);
    var value = pairs[i].substring(pos+1);
    args[argname] = unescape(value);
  }
  return args;
}
function GenQuerryString(QS) {
  var ans = "type=" + QS.type + "&model=" + QS.model + "&rgn=" + QS.rgn;
  ans = ans + "&graph=" + QS.graph + "&proj=" + QS.proj + "&cycle=" + QS.cycle
  ans = ans + "&date=" + QS.date + "&help=" + QS.help + "&verif=" + QS.verif;
  return ans;
}

function ValidateGraph() {
  if (QS.type == "pop") {
    if ((QS.graph == "map-mae") || (QS.graph == "map-bias") ||
        (QS.graph == "map-heidke") || (QS.graph == "map-relfreq") ||
        (QS.graph == "map-hit")) {
      QS.graph = "map-brier";
      return 0;
    } else if ((QS.graph == "plot-mae") || (QS.graph == "plot-bias") ||
         (QS.graph == "plot-heidke") || (QS.graph == "plot-relfreq") ||
         (QS.graph == "plot-hit")) {
      QS.graph = "plot-brier";
      return 0;
    } else if ((QS.graph == "text-mae") || (QS.graph == "text-bias") ||
         (QS.graph == "text-heidke") || (QS.graph == "text-relfreq") ||
         (QS.graph == "text-hit")) {
      QS.graph = "text-brier";
      return 0;
    } else if (QS.graph == "plot-avp-bias") {
      QS.graph = "plot-avp";
      return 0;
    }
  } else if ((QS.type == "max") || (QS.type == "min")) {
    if ((QS.graph == "map-brier") || (QS.graph == "map-heidke") ||
        (QS.graph == "map-relfreq") || (QS.graph == "map-hit")) {
      QS.graph = "map-mae";
      return 0;
    } else if ((QS.graph == "plot-brier") || (QS.graph == "plot-heidke") ||
        (QS.graph == "plot-relfreq") || (QS.graph == "plot-hit")) {
      QS.graph = "plot-mae";
      return 0;
    } else if ((QS.graph == "text-brier") || (QS.graph == "text-heidke") ||
         (QS.graph == "text-relfreq") || (QS.graph == "text-hit")) {
      QS.graph = "text-mae";
      return 0;
    }
  } else if ((QS.type == "td") || (QS.type == "temp") ||
             (QS.type == "rh") || (QS.type == "wg")) {
    if ((QS.graph == "map-brier") || (QS.graph == "map-heidke") ||
        (QS.graph == "map-relfreq") || (QS.graph == "map-hit")) {
      QS.graph = "map-mae";
      return 0;
    } else if ((QS.graph == "plot-brier") || (QS.graph == "plot-heidke") ||
        (QS.graph == "plot-relfreq") || (QS.graph == "plot-hit") ||
        (QS.graph == "plot-avp") || (QS.graph == "plot-avp-bias")) {
      QS.graph = "plot-mae";
      return 0;
    } else if ((QS.graph == "text-brier") || (QS.graph == "text-heidke") ||
         (QS.graph == "text-relfreq") || (QS.graph == "text-hit")) {
      QS.graph = "text-mae";
      return 0;
    }
  } else if ((QS.type == "ws")) {
    if ((QS.graph == "map-brier") || (QS.graph == "map-hit") ||
        (QS.graph == "map-relfreq")) {
      QS.graph = "map-mae";
      return 0;
    } else if ((QS.graph == "plot-brier") || (QS.graph == "plot-hit") ||
               (QS.graph == "plot-relfreq") || (QS.graph == "plot-avp") ||
               (QS.graph == "plot-avp-bias")) {
      QS.graph = "plot-mae";
      return 0;
    } else if ((QS.graph == "text-brier") || (QS.graph == "text-hit") ||
               (QS.graph == "text-relfreq")) {
      QS.graph = "text-mae";
      return 0;
    }
  } else if ((QS.type == "wdir")) {
    if ((QS.graph == "map-bias") || (QS.graph == "map-brier") ||
        (QS.graph == "map-hit")) {
      QS.graph = "map-mae";
      return 0;
    } else if ((QS.graph == "plot-bias") || (QS.graph == "plot-brier") ||
               (QS.graph == "plot-hit") || (QS.graph == "plot-avp") ||
               (QS.graph == "plot-avp-bias")) {
      QS.graph = "plot-mae";
      return 0;
    } else if ((QS.graph == "text-bias") || (QS.graph == "text-brier") ||
        (QS.graph == "text-hit")) {
      QS.graph = "text-mae";
      return 0;
    }
  } else if ((QS.type == "sky")) {
    if ((QS.graph == "map-mae") || (QS.graph == "map-bias") ||
        (QS.graph == "map-brier") || (QS.graph == "map-relfreq")) {
      QS.graph = "map-heidke";
      return 0;
    } else if ((QS.graph == "plot-mae") || (QS.graph == "plot-bias") ||
        (QS.graph == "plot-brier") || (QS.graph == "plot-relfreq") ||
        (QS.graph == "plot-avp") || (QS.graph == "plot-avp-bias")) {
      QS.graph = "plot-heidke";
      return 0;
    } else if ((QS.graph == "text-mae") || (QS.graph == "text-bias") ||
        (QS.graph == "text-brier") || (QS.graph == "text-relfreq")) {
      QS.graph = "text-heidke";
      return 0;
    }
  }
  return 1;
}

function ValidateProj() {
//
// Handle Jerry's plot's
//
  if ((QS.graph == "plot-mae") || (QS.graph == "plot-bias") ||
      (QS.graph == "plot-brier") || (QS.graph == "plot-avp") ||
      (QS.graph == "plot-avp-bias") || (QS.graph == "plot-heidke") ||
      (QS.graph == "plot-relfreq") || (QS.graph == "plot-hit") ||
      (QS.graph == "text-data")) {
    if (QS.proj != "all") {
      QS.proj = "all";
      return 0;
    }
  } else if (QS.proj == "all") {
    if (QS.type == "pop") {
      QS.proj = "012";
      return 0;
    } else if ((QS.cycle == "00") && (QS.type == "max")) {
      QS.proj = "024";
      return 0;
    } else if ((QS.cycle == "12") && (QS.type == "max")) {
      QS.proj = "012";
      return 0;
    } else if ((QS.cycle == "00") && (QS.type == "min")) {
      QS.proj = "012";
      return 0;
    } else if ((QS.cycle == "12") && (QS.type == "min")) {
      QS.proj = "024";
      return 0;
    } else if ((QS.type == "td") || (QS.type == "temp") || (QS.type == "rh") ||
               (QS.type == "wg") || (QS.type == "ws") || (QS.type == "wdir") ||
               (QS.type == "sky")) {
      QS.proj = "003";
      return 0;
    }
  }
//
// Handle Max/Min switching.
//
  if (QS.type == "max") {
    if (QS.cycle == "00") {
      if (QS.proj <= "024") {
        QS.proj = "024";
        return 0;
      } else if (QS.proj <= "048") {
        QS.proj = "048";
        return 0;
      } else if (QS.proj <= "072") {
        QS.proj = "072";
        return 0;
      } else if (QS.proj <= "096") {
        QS.proj = "096";
        return 0;
      } else if (QS.proj <= "120") {
        QS.proj = "120";
        return 0;
      } else if (QS.proj <= "144") {
        QS.proj = "144";
        return 0;
      } else if (QS.proj <= "168") {
        QS.proj = "168";
        return 0;
      }
    } else {
      if (QS.proj <= "024") {
        QS.proj = "012";
        return 0;
      } else if (QS.proj <= "048") {
        QS.proj = "036";
        return 0;
      } else if (QS.proj <= "072") {
        QS.proj = "060";
        return 0;
      } else if (QS.proj <= "096") {
        QS.proj = "084";
        return 0;
      } else if (QS.proj <= "120") {
        QS.proj = "108";
        return 0;
      } else if (QS.proj <= "144") {
        QS.proj = "132";
        return 0;
      } else if (QS.proj <= "168") {
        QS.proj = "156";
        return 0;
      }
    }
  } else if (QS.type == "min") {
    if (QS.cycle == "00") {
      if (QS.proj <= "024") {
        QS.proj = "012";
        return 0;
      } else if (QS.proj <= "048") {
        QS.proj = "036";
        return 0;
      } else if (QS.proj <= "072") {
        QS.proj = "060";
        return 0;
      } else if (QS.proj <= "096") {
        QS.proj = "084";
        return 0;
      } else if (QS.proj <= "120") {
        QS.proj = "108";
        return 0;
      } else if (QS.proj <= "144") {
        QS.proj = "132";
        return 0;
      } else if (QS.proj <= "168") {
        QS.proj = "156";
        return 0;
      }
    } else {
      if (QS.proj <= "024") {
        QS.proj = "024";
        return 0;
      } else if (QS.proj <= "048") {
        QS.proj = "048";
        return 0;
      } else if (QS.proj <= "072") {
        QS.proj = "072";
        return 0;
      } else if (QS.proj <= "096") {
        QS.proj = "096";
        return 0;
      } else if (QS.proj <= "120") {
        QS.proj = "120";
        return 0;
      } else if (QS.proj <= "144") {
        QS.proj = "144";
        return 0;
      } else if (QS.proj <= "168") {
// For Min Temp there is no 12Z 168 hour projection.
        QS.proj = "144";
        return 0;
      }
    }
  }
  if ((QS.type == "pop") || (QS.type == "td") || (QS.type == "ws") ||
      (QS.type == "temp") || (QS.type == "rh") || (QS.type == "wdir") ||
      (QS.type == "sky")) {
    if (QS.cycle == "12") {
      if (QS.proj >= "156") {
        QS.proj = 156;
        return 0;
      }
    }
  }
  if (QS.type == "wg") {
    if (QS.cycle == "12") {
      if (QS.proj >= "060") {
      QS.proj = "060";
      return 0;
      }
    }
  }
  return 1;
}
