// FUNCTION TO VERIFY MIPS INPUT PARAMETERS

function check_MIPS_input( Nrepeat )
{
    var check_Nrepeat = its_integer( Nrepeat );

    // alert("Hmmm " + check_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 MIPS PARAMS ARE INVALID:

function mips_input_error( theform, frametime, Nrepeat )
{
   alert("Bad input of MIPS parameters.");

   clear_report(theform);

   theform.selected_radio.value += "MIPS: exposure time = " + frametime + " sec ; Number of cycles = " + Nrepeat + "\n\nERROR: MIPS number of cycles must be a positive integer.";

}

// FUNCTION TO VERIFY IRS INPUT PARAMETERS

function check_IRS_input( Nrepeat, wavelength, mode, normfac )
{

    var check_Nrepeat = its_integer( Nrepeat );
    var check_wavelength = its_floating_point( wavelength );
    var check_normfac = its_floating_point( normfac );

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

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

    // IF wavelength != float OR IS NON-PHYSICAL (neg), WARN:

    if( !check_wavelength || wavelength <= 0.0) 
    {   
       return false;
    }

    // IF normfac != float OR IS NON-PHYSICAL (neg), WARN:

    if( !check_normfac || normfac <= 0.0) 
    {   
       return false;
    } 

    // Make sure entered wavelength is within range for selected mode:

    if( mode == "SH" )
    {
       if( wavelength < 10.0 || wavelength > 19.5 )
       {
          return false;
       }
    }
    else if( mode == "LH" )
    {
       if( wavelength < 19.3 || wavelength > 37.0 )
       {
          return false;
       }
    }
    else if( mode == "SL2" )
    {
       if( wavelength < 5.2 || wavelength > 8.7 )
       {
          return false;
       }
    }
    else if( mode == "SL1" )
    {
       if( wavelength < 7.4 || wavelength > 14.0 )
       {
          return false;
       }
    }
    else if( mode == "LL2" )
    {
       if( wavelength < 14.0 || wavelength > 21.3 )
       {
          return false;
       }
    }
    else if( mode == "LL1" )
    {
       if( wavelength < 19.5 || wavelength > 38.0 )
       {
          return false;
       }
    }
    else
    {
       alert("Bad IRS mode. SPEC-PET is confused! Please reset the form and/or reload the webpage.");
       return false;
    }

    return true;

}

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

function irs_input_error( theform, mode, frametime, Nrepeat, wavelength )
{
   alert("Bad input of IRS parameters.");

   clear_report(theform);

   theform.selected_radio.value += "IRS: " + mode + " mode ; Ramp duration = " + frametime + " sec ; Number of cycles = " + Nrepeat + "\n\nOutput wavelength = " + wavelength + " microns\n\nERROR: IRS number of cycles must be a positive integer.\n       Wavelength must be a float, within mode range.";

}




