// FUNCTION TO HANDLE CASE WHEN MIPS SCAN PARAMS ARE INVALID:

function MIPS_scan_input_error( theform, radio_index)
{
   alert("Bad input of MIPS Scan Map parameters. Nrepeat must be a NON-NEGATIVE INTEGER.");

   clear_report(theform);

   theform.selected_radio.value += "\nMIPS: " + theform.MIPS_mode[radio_index].value + " mode\n  Number of scan passes = \"" + theform.MIPS_scan_Nrepeat.value + "\"\n\nERROR: MIPS Scan Nrepeat must be a non-negative integer.";   
}

// FUNCTION TO HANDLE CASE WHEN MIPS PHOTO INPUT PARAMS ARE INVALID:

function MIPS_photo_input_error(theform, radio_index)
{
   alert("Bad input of MIPS Photometry/Super Res. parameters. Nrepeat must be a NON-NEGATIVE INTEGER.");

   clear_report(theform);

   theform.selected_radio.value += "\nMIPS: " + theform.MIPS_mode[radio_index].value + " mode\n  24 microns: Nrepeat = \"" + theform.MIPS_photo_24Nrepeat.value + "\"";

   theform.selected_radio.value += "\n  70 microns: Nrepeat = \"" + theform.MIPS_photo_70Nrepeat.value + "\"";

   theform.selected_radio.value += "\n 160 microns: Nrepeat = \"" + theform.MIPS_photo_160Nrepeat.value + "\"";

   theform.selected_radio.value += "\nERROR: MIPS Photo Nrepeats must be NON-NEGATIVE INTEGERS.";
}

// FUNCTION TO CHECK MIPS PHOTO Nrepeats ARE POSITIVE INTEGERS:

function check_MIPS_photo_N( N24, N70, N160 )
{
   var check_Nrepeat24 = its_integer( N24 );
   var check_Nrepeat70 = its_integer( N70 );
   var check_Nrepeat160 = its_integer( N160 );

   // IF any Nrepeat != INTEGER, OR IS NON-PHYSICAL (neg), WARN:
   if ( !check_Nrepeat24 || !check_Nrepeat70  || !check_Nrepeat160 || 
           N24 <= 0.0 || N70 <= 0.0 || N160 <= 0.0 )
   {
      return false;
   }
   else
   {
      return true;
   } 
}

// FUNCTION TO CHECK BB INPUT PARAMS ARE POSITIVE FLOATS:

function check_bb_input(Teff, normfac, wavelength)
{

   // CHECK VALIDITY OF INPUT: IS IT A FLOAT?

   var check_Teff = its_floating_point(Teff);
   var check_norm = its_floating_point(normfac);
   var check_wave = its_floating_point(wavelength);

   // IF INPUT != FLOAT OR IS NON-PHYSICAL (e.g., neg. temp), FALSE:

   if(! check_Teff || !check_norm || !check_wave || Teff <= 0.0 || normfac <= 0.0 || wavelength <= 0.0) 
   {
      return false;
   }
   else
   {
      return true;
   }
}

// FUNCTION TO HANDLE CASE WHEN BB INPUT PARAMS ARE INVALID:

function bb_input_error(theform, radio_index)
{
   alert("Bad input of blackbody SED parameters.");

   clear_report(theform);

   theform.selected_radio.value += ":\n   * T = \"" +
      theform.Teff.value + "\" K; Fnu(\"" +
      theform.wavelength[radio_index].value + "\" microns) = \"" +
      theform.normfac[radio_index].value + "\" mJy\n\nERROR: Blackbody input must be positive floats.";
}

// FUNCTION TO CHECK MODIFIED BB INPUT PARAMS ARE POSITIVE FLOATS:

function check_modbb_input(Teff, normfac, wavelength, index)
{

  // CHECK VALIDITY OF INPUT: IS IT A FLOAT?

  var check_Teff  = its_floating_point(Teff);
  var check_norm  = its_floating_point(normfac);
  var check_wave  = its_floating_point(wavelength);
  var check_index = its_floating_point(index);

  // IF INPUT != FLOAT OR IS NON-PHYSICAL (e.g., neg. temp), FALSE:

  if(! check_Teff || !check_norm || !check_wave || !check_index || Teff <= 0.0 || normfac <= 0.0 || wavelength <= 0.0) 
  {
     return false;
  }
  else
  {
     return true;
  }
}

// FUNCTION TO HANDLE CASE WHEN MODIFIED BB INPUT PARAMS ARE INVALID:

function modbb_input_error(theform, radio_index)
{
   alert("Bad input of modified blackbody SED parameters.");

   clear_report(theform);

   theform.selected_radio.value += ":\n   * T = \"" +
      theform.Teff_mod.value + "\" K; Fnu(\"" +
      theform.wavelength[radio_index].value + "\" microns) = \"" +
      theform.normfac[radio_index].value + "\" mJy\n   * Index = \"" +  theform.index_mod.value + "\"\n\nERROR: T, normalization and wavelength input must be positive floats.\n       Index must be a float.";
}

// FUNCTION TO CHECK power law INPUT PARAMS ARE OK:

function check_pl_input(index, normfac, wavelength)
{

   // CHECK VALIDITY OF INPUT: IS IT A FLOAT?

   var check_index = its_floating_point(index);
   var check_norm  = its_floating_point(normfac);
   var check_wave  = its_floating_point(wavelength);

   // IF INPUT != FLOAT OR IS NON-PHYSICAL (e.g., neg. norm), FALSE:

   if(! check_index || !check_norm || !check_wave || normfac <= 0.0 || wavelength <= 0.0) 
   {
      return false;
   }
   else
   {
      return true;
   }
}

// FUNCTION TO HANDLE CASE WHEN PL PARAMS ARE INVALID:

function pl_input_error(theform, radio_index)
{
   alert("Bad input of power law SED parameters.");

   clear_report(theform);

   theform.selected_radio.value += ":\n   * Index = \"" +
      theform.alpha.value + "\"; Fnu(\"" +
      theform.wavelength[radio_index].value + "\" microns) = \"" +
      theform.normfac[radio_index].value + "\" mJy\n\nERROR: Power law normalization and wavelength input must be positive floats.\n       Index must be a float.";
}

// FUNCTION TO CHECK named object/composite SED INPUT PARAMS ARE OK:

function check_no_input(normfac, wavelength, redshift)
{

   // CHECK VALIDITY OF INPUT: IS IT A FLOAT?

   var check_redshift = its_floating_point(redshift);
   var check_norm     = its_floating_point(normfac);
   var check_wave     = its_floating_point(wavelength);

   // IF INPUT != FLOAT OR IS NON-PHYSICAL (e.g., neg. norm), FALSE:

   if( !check_redshift || !check_norm || !check_wave || normfac <= 0.0 || wavelength <= 0.0 || redshift < 0.0) 
   {
      return false;
   }
   else
   {
      return true;
   }
}

// FUNCTION TO HANDLE CASE WHEN named object PARAMS ARE INVALID:

function no_input_error(theform, radio_index)
{
   alert("Bad input of Named Object SED parameters.");

   clear_report(theform);

   theform.selected_radio.value += ": " +
          theform.ObjectName[theform.ObjectName.selectedIndex].value +
          "\n   * z = \"" + 
	  theform.redshift_named.value + "\"; Fnu(\"" +
	  theform.wavelength[radio_index].value + "\" microns) = \"" +
	  theform.normfac[radio_index].value + "\" mJy\n\nERROR: Normalization and wavelength input must be positive floats.\n       Redshift must be a non-negative float.";

}

// FUNCTION TO HANDLE CASE WHEN Composite SED PARAMS ARE INVALID:

function composite_input_error(theform, radio_index)
{
   alert("Bad input of Composite SED parameters.");

   clear_report(theform);

   theform.selected_radio.value += ": " +
          theform.SEDType[theform.SEDType.selectedIndex].value +
          "\n   * z = \"" + 
	  theform.redshift_comp.value + "\"; Fnu(\"" +
	  theform.wavelength[radio_index].value + "\" microns) = \"" +
	  theform.normfac[radio_index].value + "\" mJy\n\nERROR: Normalization and wavelength input must be positive floats.\n       Redshift must be a non-negative float.";

}

// FUNCTION TO VERIFY IRAC INPUT PARAMETERS

function check_IRAC_input( Nrepeat )
{

    var check_Nrepeat = its_integer( Nrepeat );

    // IF Nrepeat != INTEGER OR IS NON-PHYSICAL (neg), WARN:

    if( !check_Nrepeat || Nrepeat <= 0.0) 
    {   
       return false;
    } 
    else
    {
       return true;
    }
}

// FUNCTION TO HANDLE CASE WHEN IRAC PARAMS ARE INVALID:

function irac_input_error( theform, mode, frametime, Nrepeat )
{
   alert("Bad input of IRAC parameters.");

   clear_report(theform);

   theform.selected_radio.value += "\nIRAC: " + mode + " mode ; Frame Time = " + frametime + " sec ; Nrepeat = \"" + Nrepeat + "\"\n\nERROR: IRAC Nrepeat input must be a positive integer.";

}


