;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           EIS_CHECK_SAA_EVENT
;
; PURPOSE
;           eis_mk_plan gui class definition
;
; NOTES
;           Return 0 for SAA NOT found
;
; CATEGORY
;           EIS timeline planning
;
; WRITTEN
;           John A Rainne, 14-Jan-2007, RAL
;
; VERSION
;           v0.1 JAR, 8-Jan-2007
;               Included a dialog to ask for new time if SAA detected.
;           v0.2 JAR, 16-March-2007
;               Replaced GE and LE with GT and LT in the WHERE statement.
;               This was due to a request from David Brooks-san. 
;-
;************************************************************************
FUNCTION eis_check_saa_event , tlbID , obev , cp_tai

; Weed out SAA events only
saa_list   = WHERE(obev[*].name EQ 'saa' , saa_count)
IF (saa_count EQ 0) THEN RETURN , 0

; OK, so we have some SAA events
saa_obev = obev[saa_list]
; Add a 5 minute exclusion zone before and after SAA start and stop
saa_obev[*].start_time = saa_obev[*].start_time - (5.*60.)
saa_obev[*].stop_time  = saa_obev[*].stop_time  + (5.*60.)

; Find if the cursor time falls into any of these events
saa_valid = WHERE(  (cp_tai GT saa_obev[*].start_time)  AND             $
                    (cp_tai LT saa_obev[*].stop_time )  , saa_found     $
                     )
; Did we find any offending SAA events? IF not, then return 0
IF (saa_found EQ 0) THEN RETURN , 0

; We did, eh? Better suggest a new time.
print,anytim2utc(saa_obev[saa_valid[0]].start_time,/stime)
print,anytim2utc(saa_obev[saa_valid[0]].stop_time ,/stime)
new_start = saa_obev[saa_valid[0]].stop_time

question = eis_saa_dialog(new_start , tlbID)

CASE question OF
    "No"     : RETURN , 0
    "Yes"    : RETURN , new_start
    "Cancel" : RETURN , -1
ENDCASE


RETURN , 0

END
