// Validate Input Form
function validate() {

   // Min Output Frequency
   if (document.mainform.vcomin.value == "") {
      alert('Please enter a value for MIN OUTPUT FREQUENCY.');
      return false;
   }

   if (isNaN(document.mainform.vcomin.value)) {
      alert('MIN OUTPUT FREQUENCY must be a number.');
      return false;
   }

   if (document.mainform.vcomin.value <= 0) {
      alert('The value of MIN OUTPUT FREQUENCY must be greater than 0.');
      return false;
   }

   // Max Output Frequency
   if (document.mainform.vcomax.value == "") {
      alert('Please enter a value for MAX OUTPUT FREQUENCY.');
      return false;
   }

   if (isNaN(document.mainform.vcomax.value)) {
      alert('MAX OUTPUT FREQUENCY must be a number.');
      return false;
   }

   if (document.mainform.vcomax.value <= 0) {
      alert('The value of MAX OUTPUT FREQUENCY must be greater than 0.');
      return false;
   }

   if (parseFloat(document.mainform.vcomin.value) > parseFloat(document.mainform.vcomax.value)) {
      alert('The MIN OUTPUT FREQUENCY must be less than or equal to the MAX OUTPUT FREQUENCY.');
      return false;
   }

   // Channel Spacing
   vcomin_value = parseFloat(document.mainform.vcomin.value) * 1e+3;

   if (document.mainform.spacing.value == "") {
      alert('Please enter a value for CHANNEL SPACING.');
      return false;
   }

   if (isNaN(document.mainform.spacing.value)) {
      alert('CHANNEL SPACING must be a number.');
      return false;
   }

   if (document.mainform.spacing.value <= 0) {
      alert('The value of CHANNEL SPACING must be greater than 0.');
      return false;
   }

   if (parseFloat(document.mainform.spacing.value) > parseFloat(vcomin_value)) {
      alert('The CHANNEL SPACING must be less than the MIN OUTPUT FREQUENCY.');
      return false;
   }

   if (document.mainform.xtal.value * 1e3 % document.mainform.spacing.value >= .02) {
      alert('The CHANNEL SPACING must divide evenly into the CRYSTAL FREQUENCY.  For application specific help on this, visit the CHANNEL SPACING help section.');
      return false;
   }

   // Crystal Frequency
   if (document.mainform.xtal.value == "") {
      alert('Please enter a value for CRYSTAL FREQUENCY.');
      return false;
   }

   if (isNaN(document.mainform.xtal.value)) {
      alert('CRYSTAL FREQUENCY must be a number.');
      return false;
   }

   if (document.mainform.xtal.value <= 0) {
      alert('The value of CRYSTAL FREQUENCY must be greater than 0.');
      return false;
   }

   // Vcc Max
   if (document.mainform.VccMax.value == "") {
      alert('Please enter a value for MAX POWER SUPPLY.');
      return false;
   }

   if (isNaN(document.mainform.VccMax.value)) {
      alert('MAX POWER SUPPLY must be a number.');
      return false;
   }

   if (document.mainform.VccMax.value <= 0) {
      alert('The value of MAX POWER SUPPLY must be greater than 0.');
      return false;
   }

} // validate()

// Display a new window on the screen
function new_window(dest,h_size,w_size) {

   random = Math.round(Math.random() * 100000);

   popWindow = window.open(dest,random,'toolbar=yes,history=no,location=no,scrollbars=yes,resizable=yes,width=' + h_size +',height=' + w_size);
   if (navigator.appName.indexOf("Microsoft") == -1) {
      if (navigator.appVersion.charAt(0) >= '3') {
         popWindow.focus();
      }
   }
} // new_window()

function xtalhelp() {
   popWindow = window.open('/appinfo/webench/EasyPLL/help/CrystalFrequency.cgi?fch=' + document.mainform.spacing.value,"floater",'toolbar=yes, history=no,location=no,scrollbars=yes,resizable=yes,width=500,height=550');
}

function easypll() {

   var nextURL   = 'http://webench.national.com/appinfo/webench/EasyPLL/easypll.cgi?';
   nextURL	+= '&vcomin=' + document.mainform.vcomin.value;
   nextURL	+= '&vcomax=' + document.mainform.vcomax.value;
   nextURL	+= '&spacing=' + document.mainform.spacing.value;
   nextURL	+= '&xtal=' + document.mainform.xtal.value;
   nextURL	+= '&VccMax=' + document.mainform.VccMax.value;
  
   window.location = nextURL;

}
