/* ******* Global variables: ********* */


//Max time interval in seconds that a user can request data extraction for
var MAX_TIME_INTERVAL = 7200;

//Max number of stations a user can request data from in one form submission
var MAX_STATIONS = 4;

//Array to verify the user has entered a valid month
var months = new Array();
months[1] = "jan";
months[2] = "feb";
months[3] = "mar";
months[4] = "apr";
months[5] = "may";
months[6] = "jun";
months[7] = "jul";
months[8] = "aug";
months[9] = "sep";
months[10] = "oct";
months[11] = "nov";
months[12] = "dec";


//Array to keep track of the station buttons the user has clicked on
var selectedStations = new Array();
selectedStations[0]=0;
selectedStations[1]=0;
selectedStations[2]=0;
selectedStations[3]=0;
selectedStations[4]=0;
selectedStations[5]=0;
selectedStations[6]=0;
selectedStations[7]=0;
selectedStations[8]=0;
selectedStations[9]=0;
selectedStations[10]=0;
selectedStations[11]=0;
selectedStations[12]=0;
selectedStations[13]=0;
selectedStations[14]=0;
selectedStations[15]=0;
selectedStations[16]=0;
selectedStations[17]=0;
selectedStations[18]=0;
selectedStations[19]=0;
selectedStations[20]=0;
selectedStations[21]=0;
selectedStations[22]=0;
selectedStations[23]=0;
selectedStations[24]=0;
selectedStations[25]=0;
selectedStations[26]=0;
selectedStations[27]=0;
selectedStations[28]=0;
selectedStations[29]=0;
selectedStations[30]=0;
selectedStations[31]=0;
selectedStations[32]=0;
selectedStations[33]=0;
selectedStations[34]=0;
selectedStations[35]=0;
selectedStations[36]=0;
selectedStations[37]=0;
selectedStations[38]=0;
selectedStations[39]=0;
selectedStations[40]=0;
selectedStations[41]=0;
selectedStations[42]=0;
selectedStations[43]=0;
selectedStations[44]=0;
selectedStations[45]=0;
selectedStations[46]=0;
selectedStations[47]=0;
selectedStations[48]=0;
selectedStations[49]=0;
selectedStations[50]=0;
selectedStations[51]=0;
selectedStations[52]=0;
selectedStations[53]=0;
selectedStations[54]=0;
selectedStations[55]=0;
selectedStations[56]=0;
selectedStations[57]=0;

/* STATION MODIFICATION INSERT
 * ADD STATION:
 * add an additional array element for every station you add
 * e.g. if the current last index above is 27, i.e. the
 *     line above is: 'selectedStations[27] = 0;' then add the
 *     line 'selectedStations[28] = 0;' 
 *
 * REMOVE STATION: if you are removing a station from the interface,
 * remove the array element with the highest index, currently 27.
 * 
 *    Note: the overall number of array elements should match
 *     your overall number of stations
*/


//A list of all the stations. This is used to build the string of
//stations the user has selected. This string of stations is then
//sent to the server to determine which stations to get data from.

var stations = new Array();
stations[0] = "afa";
stations[1] = "ath";
stations[2] = "bmls";
stations[3] = "bld";
stations[4] = "bou";
stations[5] = "ccnv";
stations[6] = "crt";
stations[7] = "cm1";
stations[8] = "cm2";
stations[9] = "fit";
stations[10] = "hfk";
stations[11] = "hur";
stations[12] = "jic";
stations[13] = "drby";
stations[14] = "kas";
stations[15] = "lal";
stations[16] = "moh";
stations[17] = "fyts";
stations[18] = "cbk";
stations[19] = "hots";
stations[20] = "sgd";
stations[21] = "slu";
stations[22] = "spk";
stations[23] = "teo";
stations[24] = "loys";
stations[25] = "tih";
stations[26] = "ptrs";
stations[27] = "pine";
stations[28] = "cam";
stations[29] = "rpc";
stations[30] = "tmt";
stations[31] = "rmus";
stations[32] = "swno";
stations[33] = "ukia";
stations[34] = "ksh";
stations[35] = "lyh";
stations[36] = "ycb";
stations[37] = "glyn"; /*mcmac */
stations[38] = "benn"; /*mcmac */
stations[39] = "viol"; /*mcmac */
stations[40] = "rich"; /*mcmac */
stations[41] = "sana"; /*mcmac */
stations[42] = "pgeo"; /*themis */
stations[43] = "ekat"; /*themis */
stations[44] = "chbg"; /*themis */
stations[45] = "gbay"; /*themis */
stations[46] = "inuv"; /*themis */
stations[47] = "kapu"; /*themis */
stations[48] = "kian"; /*themis */
stations[49] = "mcgr"; /*themis */
stations[50] = "nain"; /*themis */
stations[51] = "tpas"; /*themis */
stations[52] = "whit"; /*themis */
stations[53] = "kuuj"; /*themis */
stations[54] = "snap"; /*themis */
stations[55] = "yknf"; /*themis */
stations[56] = "sgd1";
stations[57] = "tble";

/* stationsOrdered: This array lists the stations in increasing order of longitude for use in the Station Locator section, where the user can use the right and left arrows to walk around the globe to see what stations are available. 
*/

var stationsOrdered = 
['tih','hur','crt','kas','thj','cdp','yon','hfk','qgz','cm2','whn','bji','cm1','jih','mzl','moh','sgd','ath','lal','spk','bou','bld','afa','teo','slu','cbk','fit','jic', 'cam', 'rpc', 'tmt', 'com', 'ded', 'dlg', 'ksh', 'lyh', 'ycb', 'glyn', 'benn', 'viol', 'rich', 'sana' , 'pgeo', 'ekat'];


/* STATION MODIFICATION INSERT
 * ADD STATION:
 *  add an additional array element for every station you add
 * e.g. if the current last index above is 27, i.e. the
 *     line above is: 'stations[27] = "yon";' then add the
 *    line 'stations[28] = "xxx";' where xxx is the 3 letter
 *    (lower-case) code of the new station
 *
 * REMOVE STATION:
 * if you are removing a station from the interface, remove the 
 * array element corresponding to the station you wish to remove
 * and renumber the array element indices so that there are no gaps
 * e.g. if before the station removal the indices ran from 0-27, after
 * the removal and renumbering, the indices should run from 0-26.
 *
 *    Note: the overall number of array elements should match
 *    your overall number of stations
*/

//Capitalization of all stations. This is necessary because the
//flat files have the station names capitalized.

var stations_caps = new Array();
stations_caps[0]="AFA";
stations_caps[1]="ATH";
stations_caps[2]="BMLS";
stations_caps[3]="BLD";
stations_caps[4]="BOU";
stations_caps[5]="CCNV";
stations_caps[6]="CRT";
stations_caps[7]="CM1";
stations_caps[8]="CM2";
stations_caps[9]="FIT";
stations_caps[10]="HFK";
stations_caps[11]="HUR";
stations_caps[12]="JIC";
stations_caps[13]="DRBY";
stations_caps[14]="KAS";
stations_caps[15]="LAL";
stations_caps[16]="MOH";
stations_caps[17]="FYTS";
stations_caps[18]="CBK";
stations_caps[19]="HOTS";
stations_caps[20]="SGD";
stations_caps[21]="SLU";
stations_caps[22]="SPK";
stations_caps[23]="TEO";
stations_caps[24]="LOYS";
stations_caps[25]="TIH";
stations_caps[26]="PTRS";
stations_caps[27]="PINE";
stations_caps[28] = "CAM";
stations_caps[29] = "RPC";
stations_caps[30] = "TMT";
stations_caps[31] = "RMUS";
stations_caps[32] = "SWNO";
stations_caps[33] = "UKIA";
stations_caps[34] = "KSH";
stations_caps[35] = "LYH";
stations_caps[36] = "YCB";
stations_caps[37] = "GLYN"; /*mcmac*/
stations_caps[38] = "BENN"; /*mcmac*/
stations_caps[39] = "VIOL"; /*mcmac*/
stations_caps[40] = "RICH"; /*mcmac*/
stations_caps[41] = "SANA"; /*mcmac*/
stations_caps[42] = "PGEO"; /*themis*/
stations_caps[43] = "EKAT"; /*themis*/
stations_caps[44] = "CHGB"; /*themis*/
stations_caps[45] = "GBAY"; /*themis*/
stations_caps[46] = "INUV"; /*themis*/
stations_caps[47] = "KAPU"; /*themis*/
stations_caps[48] = "KIAN"; /*themis*/
stations_caps[49] = "MCGR"; /*themis*/
stations_caps[50] = "NAIN"; /*themis*/
stations_caps[51] = "TPAS"; /*themis*/
stations_caps[52] = "WHIT"; /*themis*/
stations_caps[53] = "KUUJ"; /*themis*/
stations_caps[54] = "SNAP"; /*themis*/
stations_caps[55] = "YKNF"; /*themis*/
stations_caps[56] = "SGD1";
stations_caps[57] = "TBLE";

/* STATION MODIFICATION INSERT
 * ADD STATION:
 * add an additional array element for every station you add
 * e.g. if the current last index above is 27, i.e. the
 *    line above is: 'stations_caps[27] = "YON";' then add the
 *     line 'stations_caps[28] = "XXX";' where XXX is the 3 letter
 *     (upper-case) code of the new station
 *
 * REMOVE STATION:
 * if you are removing a station from the interface, remove the 
 * array element corresponding to the station you wish to remove
 * and renumber the array element indices so that there are no gaps
 * e.g. if before the station removal the indices ran from 0-27, after
 * the removal and renumbering, the indices should run from 0-26.
 *
 *    Note: the overall number of array elements should match
 *     your overall number of stations
*/


/* STATION MODIFICATION INSERT
 * ADD STATION: 
 * add an additional array element for every station you add
 * e.g. if the current last index above is 27, i.e. the
 * line above is: 'stationInfo[27] = "availability/yon_chart_frame.html";',
 * then add the line 
 * 'stationInfo[28] = "availability/xxx_chart_frame.html";' 
 * where xxx is the 3 letter (lower-case) code of the new station
 *
 * REMOVE STATION:
 * if you are removing a station from the interface, remove the 
 * array element corresponding to the station you wish to remove
 * and renumber the array element indices so that there are no gaps
 * e.g. if before the station removal the indices ran from 0-27, after
 * the removal and renumbering, the indices should run from 0-26.
 *
 * Note: the overall number of array elements should match
 * your overall number of stations
*/


//Create image objects for all the maps and buttons

if (document.images) {


// **** Preload Map Panels ****

var map_menu_item0=new Image()
map_menu_item0.src="graphics/maps/map_panel_afa.gif"

var map_menu_item1=new Image()
map_menu_item1.src="graphics/maps/map_panel_ath.gif"

var map_menu_item2=new Image()
map_menu_item2.src="graphics/maps/map_panel_cm1.gif"

var map_menu_item3=new Image()
map_menu_item3.src="graphics/maps/map_panel_bji.gif"

var map_menu_item4=new Image()
map_menu_item4.src="graphics/maps/map_panel_bld.gif"

var map_menu_item5=new Image()
map_menu_item5.src="graphics/maps/map_panel_bou.gif"

var map_menu_item6=new Image()
map_menu_item6.src="graphics/maps/map_panel_cdp.gif"

var map_menu_item7=new Image()
map_menu_item7.src="graphics/maps/map_panel_crt.gif"

var map_menu_item8=new Image()
map_menu_item8.src="graphics/maps/map_panel_fit.gif"

var map_menu_item9=new Image()
map_menu_item9.src="graphics/maps/map_panel_hfk.gif"

var map_menu_item10=new Image()
map_menu_item10.src="graphics/maps/map_panel_hur.gif"

var map_menu_item11=new Image()
map_menu_item11.src="graphics/maps/map_panel_jic.gif"

var map_menu_item12=new Image()
map_menu_item12.src="graphics/maps/map_panel_jih.gif"

var map_menu_item13=new Image()
map_menu_item13.src="graphics/maps/map_panel_kas.gif"

var map_menu_item14=new Image()
map_menu_item14.src="graphics/maps/map_panel_lal.gif"

var map_menu_item15=new Image()
map_menu_item15.src="graphics/maps/map_panel_moh.gif"

var map_menu_item16=new Image()
map_menu_item16.src="graphics/maps/map_panel_mzl.gif"

var map_menu_item17=new Image()
map_menu_item17.src="graphics/maps/map_panel_cbk.gif"

var map_menu_item18=new Image()
map_menu_item18.src="graphics/maps/map_panel_qgz.gif"

var map_menu_item19=new Image()
map_menu_item19.src="graphics/maps/map_panel_sgd.gif"

var map_menu_item20=new Image()
map_menu_item20.src="graphics/maps/map_panel_slu.gif"

var map_menu_item21=new Image()
map_menu_item21.src="graphics/maps/map_panel_spk.gif"

var map_menu_item22=new Image()
map_menu_item22.src="graphics/maps/map_panel_teo.gif"

var map_menu_item23=new Image()
map_menu_item23.src="graphics/maps/map_panel_thj.gif"

var map_menu_item24=new Image()
map_menu_item24.src="graphics/maps/map_panel_tih.gif"

var map_menu_item25=new Image()
map_menu_item25.src="graphics/maps/map_panel_whn.gif"

var map_menu_item26=new Image()
map_menu_item26.src="graphics/maps/map_panel_cm2.gif"

var map_menu_item27=new Image()
map_menu_item27.src="graphics/maps/map_panel_yon.gif"

var map_menu_item28=new Image()
map_menu_item28.src="graphics/maps/map_panel_cam.gif"

var map_menu_item29=new Image()
map_menu_item29.src="graphics/maps/map_panel_rpc.gif"

var map_menu_item30=new Image()
map_menu_item30.src="graphics/maps/map_panel_tmt.gif"

var map_menu_item31=new Image()
map_menu_item31.src="graphics/maps/map_panel_com.gif"

var map_menu_item32=new Image()
map_menu_item32.src="graphics/maps/map_panel_ded.gif"

var map_menu_item33=new Image()
map_menu_item33.src="graphics/maps/map_panel_dlg.gif"

var map_menu_item34=new Image()
map_menu_item34.src="graphics/maps/map_panel_ksh.gif"

var map_menu_item35=new Image()
map_menu_item35.src="graphics/maps/map_panel_lyh.gif"

var map_menu_item36=new Image()
map_menu_item36.src="graphics/maps/map_panel_ycb.gif"

/*MCMAC*/
var map_menu_item37=new Image()
map_menu_item37.src="graphics/maps/map_panel_ycb.gif"

var map_menu_item38=new Image()
map_menu_item38.src="graphics/maps/map_panel_ycb.gif"

var map_menu_item39=new Image()
map_menu_item39.src="graphics/maps/map_panel_ycb.gif"

var map_menu_item40=new Image()
map_menu_item40.src="graphics/maps/map_panel_ycb.gif"

var map_menu_item41=new Image()
map_menu_item41.src="graphics/maps/map_panel_ycb.gif"

/*themis */

var map_menu_item42=new Image()
map_menu_item42.src="graphics/maps/map_panel_ycb.gif"

var map_menu_item43=new Image()
map_menu_item43.src="graphics/maps/map_panel_ycb.gif"

/* STATION MODIFICATION INSERT
 * ADD STATION:
 * add the 2 lines described below for every station
 *   you wish to add.
 * e.g. if the last menu item above is numbered27, i.e. the
 *     above 2 lines are: 
 *
 *        var map_menu_item27=new Image()
 *        map_menu_item27.src="graphics/maps/map_panel_yon.gif"
 *
 *    then add the lines:
 *
 *       var map_menu_item28=new Image()
 *        map_menu_item28.src="graphics/maps/map_panel_xxx.gif"
 *
 *     where xxx is the 3 letter (lower-case) code of the new station
 * 
 * REMOVE STATION: Delete the 2 lines described above for the station
 * you wish to remove from the interface and renumber the menu items
 * so that there are no gaps in their numbering. 
 * e.g. if before the station removal the item numbers ran from 0-27, after
 * the removal and renumbering, they should run from 0-26.
 * 
 *    Note: the overall number of map image elements should match
 *     your overall number of stations
*/

// Preload off button images. These are the gif images for the unselected 
// buttons.

var button_afa_off=new Image()
button_afa_off.src="graphics/newbuttons/afa_off.gif"

var button_ath_off=new Image()
button_ath_off.src="graphics/newbuttons/ath_off.gif"

var button_bji_off=new Image()
button_bji_off.src="graphics/newbuttons/bji_off.gif"

var button_bld_off=new Image()
button_bld_off.src="graphics/newbuttons/bld_off.gif"

var button_bou_off=new Image()
button_bou_off.src="graphics/newbuttons/bou_off.gif"

var button_cdp_off=new Image()
button_cdp_off.src="graphics/newbuttons/cdp_off.gif"

var button_crt_off=new Image()
button_crt_off.src="graphics/newbuttons/crt_off.gif"

var button_cm1_off=new Image()
button_cm1_off.src="graphics/newbuttons/bji_off.gif"

var button_cm2_off=new Image()
button_cm2_off.src="graphics/newbuttons/whn_off.gif"

var button_fit_off=new Image()
button_fit_off.src="graphics/newbuttons/fit_off.gif"

var button_hfk_off=new Image()
button_hfk_off.src="graphics/newbuttons/hfk_off.gif"

var button_hur_off=new Image()
button_hur_off.src="graphics/newbuttons/hur_off.gif"

var button_jic_off=new Image()
button_jic_off.src="graphics/newbuttons/jic_off.gif"

var button_jih_off=new Image()
button_jih_off.src="graphics/newbuttons/jih_off.gif"

var button_kas_off=new Image()
button_kas_off.src="graphics/newbuttons/kas_off.gif"

var button_lal_off=new Image()
button_lal_off.src="graphics/newbuttons/lal_off.gif"

var button_moh_off=new Image()
button_moh_off.src="graphics/newbuttons/moh_off.gif"

var button_mzl_off=new Image()
button_mzl_off.src="graphics/newbuttons/mzl_off.gif"

var button_cbk_off=new Image()
button_cbk_off.src="graphics/newbuttons/cbk_off.gif"

var button_qgz_off=new Image()
button_qgz_off.src="graphics/newbuttons/qgz_off.gif"

var button_sgd_off=new Image()
button_sgd_off.src="graphics/newbuttons/sgd_off.gif"

var button_slu_off=new Image()
button_slu_off.src="graphics/newbuttons/slu_off.gif"

var button_spk_off=new Image()
button_spk_off.src="graphics/newbuttons/spk_off.gif"

var button_teo_off=new Image()
button_teo_off.src="graphics/newbuttons/teo_off.gif"

var button_thj_off=new Image()
button_thj_off.src="graphics/newbuttons/thj_off.gif"

var button_tih_off=new Image()
button_tih_off.src="graphics/newbuttons/tih_off.gif"

var button_whn_off=new Image()
button_whn_off.src="graphics/newbuttons/whn_off.gif"

var button_yon_off=new Image()
button_yon_off.src="graphics/newbuttons/yon_off.gif"


var button_cam_off=new Image()
button_cam_off.src="graphics/newbuttons/cam_off.gif"

var button_rpc_off=new Image()
button_rpc_off.src="graphics/newbuttons/rpc_off.gif"

var button_tmt_off=new Image()
button_tmt_off.src="graphics/newbuttons/tmt_off.gif"

var button_com_off=new Image()
button_com_off.src="graphics/newbuttons/com_off.gif"

var button_ded_off=new Image()
button_ded_off.src="graphics/newbuttons/ded_off.gif"

var button_dlg_off=new Image()
button_dlg_off.src="graphics/newbuttons/dlg_off.gif"

var button_ksh_off=new Image()
button_ksh_off.src="graphics/newbuttons/ksh_off.gif"

var button_lyh_off=new Image()
button_lyh_off.src="graphics/newbuttons/lyh_off.gif"

var button_ycb_off=new Image()
button_ycb_off.src="graphics/newbuttons/ycb_off.gif"

/*mcmac*/
var button_glyn_off=new Image()
button_glyn_off.src="graphics/newbuttons/mcmac/glyn_off.gif"

var button_benn_off=new Image()
button_benn_off.src="graphics/newbuttons/mcmac/benn_off.gif"

var button_viol_off=new Image()
button_viol_off.src="graphics/newbuttons/mcmac/viol_off.gif"

var button_rich_off=new Image()
button_rich_off.src="graphics/newbuttons/mcmac/rich_off.gif"

var button_sana_off=new Image()
button_sana_off.src="graphics/newbuttons/mcmac/sana_off.gif"

/*themis*/
var button_pgeo_off=new Image()
button_pgeo_off.src="graphics/newbuttons/themis/pgeo_off.gif"

var button_ekat_off=new Image()
button_ekat_off.src="graphics/newbuttons/themis/ekat_off.gif"

var button_chbg_off=new Image()
button_chbg_off.src="graphics/newbuttons/themis/chbg_off.gif"

var button_gbay_off=new Image()
button_gbay_off.src="graphics/newbuttons/themis/gbay_off.gif"

var button_inuv_off=new Image()
button_inuv_off.src="graphics/newbuttons/themis/inuv_off.gif"

var button_kapu_off=new Image()
button_kapu_off.src="graphics/newbuttons/themis/kapu_off.gif"

var button_kian_off=new Image()
button_kian_off.src="graphics/newbuttons/themis/kian_off.gif"

var button_kuuj_off=new Image()
button_kuuj_off.src="graphics/newbuttons/themis/kuuj_off.gif"

var button_mcgr_off=new Image()
button_mcgr_off.src="graphics/newbuttons/themis/mcgr_off.gif"

var button_nain_off=new Image()
button_nain_off.src="graphics/newbuttons/themis/nain_off.gif"

var button_snap_off=new Image()
button_snap_off.src="graphics/newbuttons/themis/snap_off.gif"

var button_tpas_off=new Image()
button_tpas_off.src="graphics/newbuttons/themis/tpas_off.gif"

var button_whit_off=new Image()
button_whit_off.src="graphics/newbuttons/themis/whit_off.gif"

var button_yknf_off=new Image()
button_yknf_off.src="graphics/newbuttons/themis/yknf_off.gif"

var button_bmls_off=new Image()
button_bmls_off.src="graphics/newbuttons/themis/bmls_off.gif"

var button_ccnv_off=new Image()
button_ccnv_off.src="graphics/newbuttons/themis/ccnv_off.gif"

var button_drby_off=new Image()
button_drby_off.src="graphics/newbuttons/themis/drby_off.gif"

var button_fyts_off=new Image()
button_fyts_off.src="graphics/newbuttons/themis/fyts_off.gif"

var button_hots_off=new Image()
button_hots_off.src="graphics/newbuttons/themis/hots_off.gif"

var button_loys_off=new Image()
button_loys_off.src="graphics/newbuttons/themis/loys_off.gif"

var button_ptrs_off=new Image()
button_ptrs_off.src="graphics/newbuttons/themis/ptrs_off.gif"

var button_pine_off=new Image()
button_pine_off.src="graphics/newbuttons/themis/pine_off.gif"

var button_rmus_off=new Image()
button_rmus_off.src="graphics/newbuttons/themis/rmus_off.gif"

var button_sgd1_off=new Image()
button_sgd1_off.src="graphics/newbuttons/themis/sgd1_off.gif"

var button_swno_off=new Image()
button_swno_off.src="graphics/newbuttons/themis/swno_off.gif"

var button_tble_off=new Image()
button_tble_off.src="graphics/newbuttons/themis/tble_off.gif"

var button_ukia_off=new Image()
button_ukia_off.src="graphics/newbuttons/themis/ukia_off.gif"

/* STATION MODIFICATION INSERT
 * ADD STATION:
 * add the 2 lines described below for every station
 *    you wish to add.
 *
 *     Add the lines:
 *      var button_xxx_off=new Image()
 *       button_xxx_off.src="graphics/newbuttons/xxx_off.gif"
 *
 *     where xxx is the 3 letter (lower-case) code of the new station
 * 
 * REMOVE STATION: Delete the 2 lines described above for the station
 * you wish to remove from the interface and renumber the button numbers
 * so that there are no gaps in their numbering. 
 * e.g. if before the station removal the button numbers ran from 0-27, after
 * the removal and renumbering, they should run from 0-26.
 * 
 *     Note: the overall number of OFF button images should match
 *     your overall number of stations
*/



// Preload on button images. These are the gif images for the selected 
// buttons.

var button_afa_on=new Image()
button_afa_on.src="graphics/newbuttons/afa_on.gif"

var button_ath_on=new Image()
button_ath_on.src="graphics/newbuttons/ath_on.gif"

var button_bji_on=new Image()
button_bji_on.src="graphics/newbuttons/bji_on.gif"

var button_bld_on=new Image()
button_bld_on.src="graphics/newbuttons/bld_on.gif"

var button_bou_on=new Image()
button_bou_on.src="graphics/newbuttons/bou_on.gif"

var button_cdp_on=new Image()
button_cdp_on.src="graphics/newbuttons/cdp_on.gif"

var button_crt_on=new Image()
button_crt_on.src="graphics/newbuttons/crt_on.gif"

var button_cm1_on=new Image()
button_cm1_on.src="graphics/newbuttons/bji_on.gif"

var button_cm2_on=new Image()
button_cm2_on.src="graphics/newbuttons/whn_on.gif"

var button_fit_on=new Image()
button_fit_on.src="graphics/newbuttons/fit_on.gif"

var button_hfk_on=new Image()
button_hfk_on.src="graphics/newbuttons/hfk_on.gif"

var button_hur_on=new Image()
button_hur_on.src="graphics/newbuttons/hur_on.gif"

var button_jic_on=new Image()
button_jic_on.src="graphics/newbuttons/jic_on.gif"

var button_jih_on=new Image()
button_jih_on.src="graphics/newbuttons/jih_on.gif"

var button_kas_on=new Image()
button_kas_on.src="graphics/newbuttons/kas_on.gif"

var button_lal_on=new Image()
button_lal_on.src="graphics/newbuttons/lal_on.gif"

var button_moh_on=new Image()
button_moh_on.src="graphics/newbuttons/moh_on.gif"

var button_mzl_on=new Image()
button_mzl_on.src="graphics/newbuttons/mzl_on.gif"

var button_cbk_on=new Image()
button_cbk_on.src="graphics/newbuttons/cbk_on.gif"

var button_qgz_on=new Image()
button_qgz_on.src="graphics/newbuttons/qgz_on.gif"

var button_sgd_on=new Image()
button_sgd_on.src="graphics/newbuttons/sgd_on.gif"

var button_slu_on=new Image()
button_slu_on.src="graphics/newbuttons/slu_on.gif"

var button_spk_on=new Image()
button_spk_on.src="graphics/newbuttons/spk_on.gif"

var button_teo_on=new Image()
button_teo_on.src="graphics/newbuttons/teo_on.gif"

var button_thj_on=new Image()
button_thj_on.src="graphics/newbuttons/thj_on.gif"

var button_tih_on=new Image()
button_tih_on.src="graphics/newbuttons/tih_on.gif"

var button_whn_on=new Image()
button_whn_on.src="graphics/newbuttons/whn_on.gif"

var button_yon_on=new Image()
button_yon_on.src="graphics/newbuttons/yon_on.gif"


var button_cam_on=new Image()
button_cam_on.src="graphics/newbuttons/cam_on.gif"

var button_rpc_on=new Image()
button_rpc_on.src="graphics/newbuttons/rpc_on.gif"

var button_tmt_on=new Image()
button_tmt_on.src="graphics/newbuttons/tmt_on.gif"

var button_com_on=new Image()
button_com_on.src="graphics/newbuttons/com_on.gif"

var button_ded_on=new Image()
button_ded_on.src="graphics/newbuttons/ded_on.gif"

var button_dlg_on=new Image()
button_dlg_on.src="graphics/newbuttons/dlg_on.gif"

var button_ksh_on=new Image()
button_ksh_on.src="graphics/newbuttons/ksh_on.gif"

var button_lyh_on=new Image()
button_lyh_on.src="graphics/newbuttons/lyh_on.gif"

var button_ycb_on=new Image()
button_ycb_on.src="graphics/newbuttons/ycb_on.gif"

/*mcmac*/
var button_glyn_on=new Image()
button_glyn_on.src="graphics/newbuttons/mcmac/glyn_on.gif"

var button_benn_on=new Image()
button_benn_on.src="graphics/newbuttons/mcmac/benn_on.gif"

var button_viol_on=new Image()
button_viol_on.src="graphics/newbuttons/mcmac/viol_on.gif"

var button_rich_on=new Image()
button_rich_on.src="graphics/newbuttons/mcmac/rich_on.gif"

var button_sana_on=new Image()
button_sana_on.src="graphics/newbuttons/mcmac/sana_on.gif"

/*themis */
var button_pgeo_on=new Image()
button_pgeo_on.src="graphics/newbuttons/themis/pgeo_on.gif"

var button_ekat_on=new Image()
button_ekat_on.src="graphics/newbuttons/themis/ekat_on.gif"

var button_chbg_on=new Image()
button_chbg_on.src="graphics/newbuttons/themis/chbg_on.gif"

var button_gbay_on=new Image()
button_gbay_on.src="graphics/newbuttons/themis/gbay_on.gif"

var button_inuv_on=new Image()
button_inuv_on.src="graphics/newbuttons/themis/inuv_on.gif"

var button_kapu_on=new Image()
button_kapu_on.src="graphics/newbuttons/themis/kapu_on.gif"

var button_kuuj_on=new Image()
button_kuuj_on.src="graphics/newbuttons/themis/kuuj_on.gif"

var button_mcgr_on=new Image()
button_mcgr_on.src="graphics/newbuttons/themis/mcgr_on.gif"

var button_nain_on=new Image()
button_nain_on.src="graphics/newbuttons/themis/nain_on.gif"

var button_snap_on=new Image()
button_snap_on.src="graphics/newbuttons/themis/snap_on.gif"

var button_tpas_on=new Image()
button_tpas_on.src="graphics/newbuttons/themis/tpas_on.gif"

var button_whit_on=new Image()
button_whit_on.src="graphics/newbuttons/themis/whit_on.gif"

var button_yknf_on=new Image()
button_yknf_on.src="graphics/newbuttons/themis/yknf_on.gif"

var button_bmls_on=new Image()
button_bmls_on.src="graphics/newbuttons/themis/bmls_on.gif"

var button_ccnv_on=new Image()
button_ccnv_on.src="graphics/newbuttons/themis/ccnv_on.gif"

var button_drby_on=new Image()
button_drby_on.src="graphics/newbuttons/themis/drby_on.gif"

var button_fyts_on=new Image()
button_fyts_on.src="graphics/newbuttons/themis/fyts_on.gif"

var button_hots_on=new Image()
button_hots_on.src="graphics/newbuttons/themis/hots_on.gif"

var button_loys_on=new Image()
button_loys_on.src="graphics/newbuttons/themis/loys_on.gif"

var button_ptrs_on=new Image()
button_ptrs_on.src="graphics/newbuttons/themis/ptrs_on.gif"

var button_pine_on=new Image()
button_pine_on.src="graphics/newbuttons/themis/pine_on.gif"

var button_rmus_on=new Image()
button_rmus_on.src="graphics/newbuttons/themis/rmus_on.gif"

var button_sgd1_on=new Image()
button_sgd1_on.src="graphics/newbuttons/themis/sgd1_on.gif"

var button_swno_on=new Image()
button_swno_on.src="graphics/newbuttons/themis/swno_on.gif"

var button_tble_on=new Image()
button_tble_on.src="graphics/newbuttons/themis/tble_on.gif"

var button_ukia_on=new Image()
button_ukia_on.src="graphics/newbuttons/themis/ukia_on.gif"

/* STATION MODIFICATION INSERT
 * ADD STATION: 
 * add the 2 lines described below for every station
 *    you wish to add.
 *
 *     Add the lines:
 *      var button_xxx_on=new Image()
 *       button_xxx_on.src="graphics/newbuttons/xxx_on.gif"
 *
 *     where xxx is the 3 letter (lower-case) code of the new station
 * 
 * REMOVE STATION: Delete the 2 lines described above for the station
 * you wish to remove from the interface and renumber the button numbers
 * so that there are no gaps in their numbering. 
 * e.g. if before the station removal the button numbers ran from 0-27, after
 * the removal and renumbering, they should run from 0-26.
 * 
 *     Note: the overall number of ON button images should match
 *     your overall number of stations
*/


}


/* *********** Java Script FUNCTIONS ************ */



function showSearchResults() {
with(document.searchForm) {
  var fromYear = document.searchForm.fromYearSearch.options[document.searchForm.fromYearSearch.selectedIndex].value;
  var toYear = document.searchForm.toYearSearch.options[document.searchForm.toYearSearch.selectedIndex].value;
  var fromDOY = document.searchForm.fromDOYSearch.value;
  var toDOY = document.searchForm.toDOYSearch.value;
  
  //Get month/day if there are no DOY
  var fromMonth = ""; var fromDay=""; var toMonth=""; var toDay="";
  if (parseInt(fromDOY) ==  0) {
	var fromMonth = document.searchForm.fromMonthSearch.options[document.searchForm.fromMonthSearch.selectedIndex].value;
  	var fromDay = document.searchForm.fromDaySearch.options[document.searchForm.fromDaySearch.selectedIndex].value;
	if (!ValidateMonthDaySearch(fromYear, fromMonth, fromDay)) {
		return;
	}
	fromDOY =convert_daymonth_2_doy(fromYear, fromMonth, fromDay);
  }

  //Get month/day if there are no DOY
  if (parseInt(toDOY) == 0) {
	var toMonth = document.searchForm.toMonthSearch.options[document.searchForm.toMonthSearch.selectedIndex].value;
  	var toDay = document.searchForm.toDaySearch.options[document.searchForm.toDaySearch.selectedIndex].value;
	if (!ValidateMonthDaySearch(toYear, toMonth, toDay)) {
		return;
	}
	toDOY = convert_daymonth_2_doy(toYear, toMonth, toDay);
  }

  if (ValidateDateDoySearch(fromYear, fromDOY, toYear, toDOY)) {

     	// Build string of stations 
	if (document.searchForm.searchStations.selectedIndex == 0) {
	  var selectedStations = "";
	  for (var k=1; k<document.searchForm.searchStations.options.length; k++) {
	    selectedStations = selectedStations +  document.searchForm.searchStations.options[k].value + ",";
	  }
	  
	} else {
	  var numStations = document.searchForm.searchStations.length;
	  var indx = 0;
	  var selectedStations = "";
	  for (var i=0; i<numStations; i++) {
	    if (document.searchForm.searchStations.options[i].selected) {
		selectedStations += document.searchForm.searchStations.options[i].value + ",";
	    }
	  }
	  if (numStations == 0) selectedStations += ",";
	}

        //Set value of stations hidden input field
	document.searchForm.stations.value = selectedStations;

	//Set values of searchfrom and searchto hidden input fields
	if (fromDOY < 10)
		var addF = "-00";
	else if (fromDOY < 100)
		var addF = "-0";
	else
		var addF = "-";
	
	if (toDOY < 10)
		var addT = "-00";
	else if (toDOY < 100)
		var addT = "-0";
	else
		var addT = "-";
		
	document.searchForm.searchFrom.value = fromYear + addF + fromDOY;
	document.searchForm.searchTo.value = toYear + addT + toDOY;

        // Submit form to call search script. Output will be targeted to popup window
	// defined for the form "searchForm" in the html body of the ground magnetometer page.
        
	//var SearchPopup = window.open('', 'SearchPopup','width=650,height=320,resizable=yes,location=no, menubar=no,toolbar=no');
	submit();
	pausecomp(1250);
	var SearchPopup = window.open('dataFrame.html', 'SearchPopup','width=650,height=320,resizable=yes,location=no, menubar=no,toolbar=no');
	//window.setTimeout(window.open('dataFrame.html', 'SearchPopup','width=650,height=320,resizable=yes,location=no, menubar=no,toolbar=no'), 10000);
        
	//window.open('dataAvailabilityFrame.html', '','width=650,height=320,resizable=yes,location=no, menubar=no,toolbar=no');
        //window.open('dataAvailabilityFrame.html', 'SearchPopup','width=650,height=320,resizable=yes,location=no, menubar=no,toolbar=no');

    
	}
}
}


function pausecomp(Amount) {
	d = new Date() //today's date
	while (1) {
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > Amount ) {break;}
	}
}

/**************************************************************
 * FUNCTION: ValidateDateDoySearch                            *
 *                                                            *
 * Arguments: 4 - the start year and day of year and end year *
 *            and day of year passed in as strings or integers*
 *                                                            *
 * Description: This function is called to validate the date  *
 *              entered for availability search.              *
 **************************************************************/


function ValidateDateDoySearch(fromYear, fromDOY, toYear, toDOY) {

  //Convert string to integer in case arguments are passed as strings
  fromYear = parseInt(fromYear);
  fromDOY = parseInt(fromDOY);
  toYear = parseInt(toYear);
  toDOY = parseInt(toDOY);

  if ((toYear < fromYear) || ((fromDOY > 366) || (toDOY > 366)) || ((fromYear == toYear) && (toDOY < fromDOY))) {
    alert("You have entered an invalid search date. Please fix this before running Search again!");
    return false;
  } else {
    if ((fromYear == toYear) && ((toDOY - fromDOY) >= 28)) {
      alert("The maximum search date interval is 4 weeks. \n\nPlease shorten the interval of your search to be no more than 4 weeks.");
      return false;
    } else if ((toYear - fromYear) > 1) {
      alert("The maximum search date interval is 4 weeks. \n\nYou have entered an interval of over a year. Please shorten the interval of your search to be no more than 4 weeks."); 
      return false;   
    } else if ((toYear > fromYear) && (((365 - fromDOY) + toDOY) >= 28)) {
      alert("The maximum search date interval is 4 weeks. \n\nPlease shorten the interval of your search to be no more than 4 weeks.");
      return false;
    } else {
      return true;
    }
  }

}

function ValidateMonthDaySearch(Year, Month, Day) {
	//Convert
	Day = parseInt(Day);
	Year = parseInt(Year);
	Month = parseInt(Month);
	var daysOfMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
	//Check if anything was entered
	if (Month==0 || Day == 0) {
		alert("You have not entered any dates. Please try again.");
    	return false;
	}
	
	//it's a leap year
	if (Year % 4 == 0 && Month == 2) {
		if (Day > 29) {
			alert(Month + "You have entered an invalid date. Please fix this before running Search again.");
    		return false;
		}
	}
	
	if (Day > daysOfMonth[Month-1]) {
		alert("You have entered an invalid  date. Please fix this before running Search again.");
    	return false;
	}
	return true;
}
	
	/*****************************************************
	* This function converts a day and month to DOY
	******************************************************/
function convert_daymonth_2_doy (year_in, month_in, day_in) {
	//convert YEAR month day ---> YEAR DOY 
	// input: year month day 
	// output: year doy 
	
	year_in = parseInt(year_in);
	month_in = parseInt(month_in);
	day_in = parseInt(day_in);
	
	//initialize all 4 local variables to 0 
  	var num=0; var month=0; var doy=0; var leap_day=0;
 
  	//names of months
  	var monthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
 	//days for each month in a non leap year
  	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31);
 
 	//find the numeric month
  	/*for (num=0; num < 12; num++) {
	  if (month_in == monthNames[num]) {
		  month = num;
		  num=12;  //used to break out of the for loop
	  } //else {print $monthNames[$num]," not found.\n";}
  	}*/
	
	//we changed it so we already have the numeric month
	month = month_in-1;

  	//add the days up
  	for(num=0; num < month; num++) {
	  	doy += monthDays[num];
  	}
  	doy += day_in;

 	//add for leap year
  	if ( year_in % 4 ==0 && month >= 2) {
	  doy += 1;
  }
  //print $year_in . " " . $mon_in . " " . $day_in;
  //print $doy;  
  return doy;
}


/**************************************************************
 * FUNCTION: ChangeMapIn                                      *
 *                                                            *
 * Arguments: 1 - a single quoted string number corresponding *
 *            to the station for which you would like to view *
 *            the location of that station on the map. eg '1' *
 *                                                            *
 * Description: This function is called when the mouse moves  *
 *              over a particular station button. It passes   *
 *              its station number to the function so that the*
 *              map will display its location map.To determine*
 *              what number is associated with a particular   * 
 *              station look up above (where the images are   *
 *              created) and check the map_menu_item # for the*
 *              station.                                      *
 **************************************************************/

function ChangeMapIn(imgNumb) {
  if (document.images) {
    document['StationMap'].src = eval("map_menu_item"+ imgNumb + ".src");
  }

  document.locatorForm.stationLocatorSelection.selectedIndex = eval(imgNumb);

}


function validateSelection() {
 //alert(document.theForm.stationLocatorSelection.selectedIndex);
}

function ChangeStationMap() {
  var selStation = document.locatorForm.stationLocatorSelection.options[document.locatorForm.stationLocatorSelection.selectedIndex].value;

  var fileName = "graphics/maps/map_panel_" + selStation + ".gif";
  
  document.StationMap.src = fileName;

}


/**************************************************************
 * FUNCTION:  GetNumSelectedStations                          *
 *                                                            *
 * Arguments: 0                                               *
 *                                                            *
 * Return value: integer number of stations selected          *
 *                                                            *
 * Description: This function determines how many stations    *
 *              have been selected by counting the number     *
 *              of array elements in the selectedStations     *
 *              array that have a value of 1                  *
 **************************************************************/

function GetNumSelectedStations() {
     var num_selected = 0;
     for (var i=0; i<selectedStations.length; i++) { 
       if (selectedStations[i] == 1) {
         num_selected++;
       }
     }
      return num_selected;
}


/**************************************************************
 * FUNCTION: SelectStation                                    *
 *                                                            *
 * Arguments: 2 - a single quoted string containing the 3     *
 *                letter abbreviation for the station and an  * 
 *                integer corresponding to the station's #.   *
 *                To determine what number is associated with *
 *                a particular station look up above (where   * 
 *                the stations array is created) and check the*
 *                index of the array for the station.         *
 *                                                            *
 * Description: This function is called when the user clicks a*
 *              station button. If the station has already    *
 *              been clicked, this function unclicks the      *
 *              button by returning the button to its normal  *
 *              color and resetting the selectedStations array*
 *              value for this station to 0. If the station   *
 *              button was unclicked before the user clicked  *
 *              it, this function checks if the maximum # of  *
 *              stations have already been clicked. If not, it*
 *              clicks the button by changing the button's    *
 *              color to the selected color and sets the value*
 *              in the selectedStations array for this station*
 *              to 1.                                         *
 **************************************************************/

function SelectStation(imgName,stationNum) {

      if (selectedStations[stationNum] == 0) {
        if (GetNumSelectedStations() < MAX_STATIONS) {
          selectedStations[stationNum] = 1;
          document[imgName].src = eval(imgName + "_on.src");
        } else {
          alert("The maximum number of stations to choose is: "+MAX_STATIONS+".\n\nTo unselect any of your currently selected stations, just click on the associated station button again.");
        }
      } else {
        selectedStations[stationNum] = 0;
        document[imgName].src = eval(imgName + "_off.src");
      }

}


/**************************************************************
 * FUNCTION: SelectStationStyles                              *
 * This function is currently not used, but could be used if  *
 *  at a later time you decide to use stylesheet to control   *
 *  the button selected and unselected look rather than images*
 * Currently, we are required to use buttons due to the old   *
 * browsers we have to support.	                              *
 *                                                            *
 *                                                            *
 * Arguments: 2 - a single quoted string containing the 3     *
 *                letter abbreviation for the station and an  * 
 *                integer corresponding to the station's #.   *
 *                To determine what number is associated with *
 *                a particular station look up above (where   * 
 *                the stations array is created) and check the*
 *                index of the array for the station.         *
 *                                                            *
 * Description: This function is called when the user clicks a*
 *              station button. If the station has already    *
 *              been clicked, this function unclicks the      *
 *              button by returning the button to its normal  *
 *              color and resetting the selectedStations array*
 *              value for this station to 0. If the station   *
 *              button was unclicked before the user clicked  *
 *              it, this function checks if the maximum # of  *
 *              stations have already been clicked. If not, it*
 *              clicks the button by changing the button's    *
 *              color to the selected color and sets the value*
 *              in the selectedStations array for this station*
 *              to 1.                                         *
 **************************************************************/

function SelectStationStyles(station,stationNum) {
  var dom;
  dom = findDOM(station, 0);

      if (selectedStations[stationNum] == 0) {
        if (GetNumSelectedStations() < MAX_STATIONS) {
          selectedStations[stationNum] = 1;
          dom.className = 'stationButtonOn';
        } else {
          alert("The maximum number of stations to choose is: "+MAX_STATIONS+".\n\nTo unselect any of your currently selected stations, just click on the associated station button again.");
        }
      } else {
        selectedStations[stationNum] = 0;
        dom.className = 'stationButton';
      }

}


/**************************************************************
 * FUNCTION: MouseOverStation                                 *
 *                                                            *
 * Arguments: 2 - a single quoted string containing the 3     *
 *                letter abbreviation for the station and an  * 
 *                integer corresponding to the station's #.   *
 *                To determine what number is associated with *
 *                a particular station look up above (where   * 
 *                the stations array is created) and check the*
 *                index of the array for the station.         *
 *                                                            *
 * Description: This function is called when the mouse moves  *
 *              over a station button. If the station was     *
 *              previusly clicked, this function changes the  * 
 *              button's color to the unclicked color and vice*
 *              -versa if the button was previously unclicked.*
 **************************************************************/


function MouseOverStation(imgName, stationNum) {
      if (selectedStations[stationNum] == 0) {
	document[imgName].src = eval(imgName + "_on.src");
      } else {
	document[imgName].src = eval(imgName + "_off.src");
      }
}

/**************************************************************
 * FUNCTION: MouseOutStation                                  *
 *                                                            *
 * Arguments: 2 - a single quoted string containing the 3     *
 *                letter abbreviation for the station and an  * 
 *                integer corresponding to the station's #.   *
 *                To determine what number is associated with *
 *                a particular station look up above (where   * 
 *                the stations array is created) and check the*
 *                index of the array for the station.         *
 *                                                            *
 * Description: This function is called when the mouse moves  *
 *              outside a station button. It returns the      *
 *              button's color to its original color (either  *
 *              clicked or unclicked) before the mouse moved  *
 *              over it.                                      *
 **************************************************************/

function MouseOutStation(imgName,stationNum) {
      if (selectedStations[stationNum] == 0) {
        document[imgName].src = eval(imgName + "_off.src");
      } else {
        document[imgName].src = eval(imgName + "_on.src");
      }
}


/**************************************************************
 * FUNCTION:  GetStationList                                  *
 *                                                            *
 * Arguments: 0                                               *
 *                                                            *
 * Description: This function first iterates over the selected*
 *              Stations array and builds a string with all   *
 *              the names of the stations the user has        *
 *              selected and a separate string with all the   *
 *              names capitalized. It checks for the 2 invalid*
 *              cases of either no stations chosen and/or more*
 *              than the max # stations selected. It issues   *
 *              warnings in these cases and returns false so  * 
 *              that the function which called this fxn does  *
 *              not submit the form. Otherwise, it sets the 2 *
 *              hidden form parameters, 'station_list' and    *
 *              'station_list_caps' to the list of station    *
 *              strings and returns true, so that the calling * 
 *              function will submit the form.                *
 **************************************************************/

function GetStationList() {

 //The with command prevents the need to use the prefix: document.Magneto
 //(the name of the form) when accessing form elements.
 with(document.Magneto) {
   var station_list_str;
   var station_list_caps_str;
   var num_selected = 0;

   //Build a string of the selected stations and one with capitalization
   for (var i=0; i<selectedStations.length; i++) {
     if (selectedStations[i] ==1) {
       if (num_selected == 0) {
         station_list_str = stations[i];
         station_list_caps_str = stations_caps[i];
       } else {
         station_list_str = station_list_str + " " + stations[i];
         station_list_caps_str = station_list_caps_str + " " + stations_caps[i];
     }
       num_selected++;
   }
 }

   //Issue warnings if an invalid # of stations have been chosen
   //otherwise set form elements to the strings created above.
   if (num_selected > 4) {
       alert("The maximum number of stations to choose is 4");
       return false;
    } else {
      if (num_selected < 1) {
        //alert("Please click on the station buttons above for which you would like data and try submitting again");
        alert("You have not selected any stations. Please do so by clicking on the station buttons above");
        return false;
      } else {
        station_list_caps.value = station_list_caps_str;
        station_list.value = station_list_str;
        return true;
      }
    }
  }
}

/* ******************************************************************** 
 * Function: ValidDateFormat                                          *
 *                                                                    *
 * Arguments: 1-the date string entered by the user in the text box   *
 *            under the 'Set Time Interval' heading.                  *
 *                                                                    *
 * Return value: Boolean (True or False)                              *
 *                                                                    *
 * Description: This function returns true if the dateString has a    *
 *              dateString has a valid format and false otherwise.    *
 *              A valid format for the date string is:                *
 *              yyyy mmm dd hh:mm:ss   e.g. 1998 apr 22 00:10:00          *
 *              It ensures that there are spaces between date elements*
 *              and colons between time elements                      *
 *              and that the month is a valid one.                    *
 * *******************************************************************/

function ValidDateFormat(dateString) {

 /***** Check for blank spaces between the yy,mmm,ddd *****/
 if (dateString.substring(4,5) != " ") {
          return false;
 }

 if (dateString.substring(8,9) != " ") {
          return false;
 }

 if (dateString.substring(11,12) != " ") {
          return false;
 }

 /***** Check for colons in the time *****/
 if (dateString.substring(14,15) != ":") {
          return false;
 }
        
 if (dateString.substring(17,18) != ":") {
          return false;
 }

 /* Check for valid month */
   if (MonthStringToInt(dateString.substring(5,8)) < 0) {
     return false;
   }

 return true;

}

/* ******************************************************************** 
 * Function:  MonthStringToInt                                        *
 *                                                                    *
 * Arguments: 1-a string valued month, e.g. "mar"                     *
 *                                                                    *
 * Return value: the integer number month associated with the input   *
 *               month string. If the input month is an invalid month *
 *               -2 is returned.                                      *
 * *******************************************************************/

// Returns the integer value of the month or -1 if not a valid month
function MonthStringToInt(monthStr) {
  for (var i=1; i<=12; i++) {
    if (monthStr == months[i]) {
      return i;
    }
  }
  return -2;
}


/* ******************************************************************** 
 * Function: ValidTimeInterval                                        *
 *                                                                    *
 * Arguments: 2-two strings containing the start and stop time        *
 *            intervals specified by the user.                        *
 *                                                                    *
 * Return value: Boolean (True or False) true if a valid time interval*
 *               false if not.                                        *
 *                                                                    *
 * Description: This function checks the time interval specified is   *
 *              valid (i.e. stop - stop time is greater than 0 and    *
 *              less than the MAX_TIME_INTERVAL). It uses the         *
 *              JavaScript function: Date.UTC to convert a string date*
 *              to seconds since 1970. If the interval is invalid,    *
 *              this function issues an alert to the user and then    *
 *              returns false so that the form is not submitted. It   *
 *              returns true if the time interval is valid.           *
 * *******************************************************************/

function ValidTimeInterval(startTimeInterval, stopTimeInterval) {

   TimeIntervalErrorMsg = "The maximum time interval is 2 hours."
   NegativeTimeIntervalErrorMsg = "The stop time must be GREATER than the start time."
  
   /* Parse the strings to get the date and time of each string above */
   start_year = startTimeInterval.substring(0,4)
   start_month = startTimeInterval.substring(5,8)
   start_day = startTimeInterval.substring(9,11)
   start_hour = startTimeInterval.substring(12,14)
   start_min = startTimeInterval.substring(15,17)
   start_sec = startTimeInterval.substring(18,20)

   stop_year = stopTimeInterval.substring(0,4)
   stop_month = stopTimeInterval.substring(5,8)
   stop_day = stopTimeInterval.substring(9,11)
   stop_hour = stopTimeInterval.substring(12,14)
   stop_min = stopTimeInterval.substring(15,17)
   stop_sec = stopTimeInterval.substring(18,20)

   start_month_int = MonthStringToInt(start_month)
   stop_month_int = MonthStringToInt(stop_month)

   startSecs = Date.UTC(start_year, start_month_int, start_day, 
      start_hour, start_min, start_sec) / 1000.0
   stopSecs = Date.UTC(stop_year, stop_month_int, stop_day, 
      stop_hour, stop_min, stop_sec) / 1000.0

   //Issue a warning for too long an interval set
   if ((stopSecs - startSecs) > MAX_TIME_INTERVAL) {
     alert(TimeIntervalErrorMsg)  
     return false
   }

   //Issue a warning if the start time is later than the stop time
   if ((stopSecs - startSecs) <= 0) {
      alert(NegativeTimeIntervalErrorMsg);
      return false;
   }


   return true
}


/* ******************************************************************** 
 * Function: getClicked                                               *
 *                                                                    *
 * Arguments: 1-a string containing the group name of a set of radio  *
 *            buttons for which you would like to know which of the   *
 *            radio button options has been clicked by the user       *
 * Return value: string value of the option chosen by the user        *
 *                                                                    *
 * Description: This function iterates over the FORM: Magneto and     *
 *              looks for form elements with the group name equal to  *
 *              the one specified as the argument to this function and*
 *              finds which of the options for that form element are  *
 *              checked. This is an inefficient method, but the only  *
 *              current way of doing this for Netscape browsers       *
 * *******************************************************************/


function getClicked(groupName) {
  for (i=0; i < document.Magneto.elements.length; i++) {
    if ((document.Magneto.elements[i].checked) && (document.Magneto.elements[i].name == groupName)) {
        return document.Magneto.elements[i].value;
    }
  }
  return 0;
}

/* ******************************************************************** 
 * Function:  ValidateDate                                            *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function runs all the above function tests to    *
 *              ensure that all the form settings are valid. If they  *
 *              are, it submits the form request, if not, it issues   *
 *              popup alerts to inform the user of the cause of the   *
 *              problem.                                              *
 * *******************************************************************/

function ValidateDate() {
 with(document.Magneto) {

   /* Print starting data extraction in the main window's status bar */
   self.status="Data Extraction In Progress ...";

   /* GET the start and stop strings entered by the user 
   startStr = start.value
   stopStr = stop.value
    */

   /* GET the start and stop inputs entered by the user */
   startYear = fromYear.selectedIndex 
   startDoy = fromDOY.value 
   endYear = toYear.selectedIndex
   endDoy = toDOY.value 
   
   //Get month/day if there are no DOY
  
   if (parseInt(startDoy) ==  0) {
	   var fromMonth = fromMonthE.options[fromMonthE.selectedIndex].value;
  	   var fromDay = fromDayE.options[fromDayE.selectedIndex].value;
	   if (!ValidateMonthDaySearch(startYear, fromMonth, fromDay)) {
		   return;
		}
	   startDoy =convert_daymonth_2_doy(startYear, fromMonth, fromDay);
   }

   //Get month/day if there are no DOY
   if (parseInt(endDoy) == 0) {
	   var toMonth = toMonthE.options[toMonthE.selectedIndex].value;
  	   var toDay = toDayE.options[toDayE.selectedIndex].value;
	   if (!ValidateMonthDaySearch(endYear, toMonth, toDay)) {
		   return;
	   }
	   endDoy = convert_daymonth_2_doy(endYear, toMonth, toDay);
  }
  
  /* Create error message strings for all types of possible errors */
   formatError = "Invalid Time Format. The correct format is:  yyyy mmm dd hh:mm:ss    e.g. 1998 mar 23 00:10:12"
   availabilityError = "Data is not available for the time interval you requested. Please see the available times for this station in the column to your right."
   TimeIntervalErrorMsg = "The maximum time interval is 28 days."

   /* Check that validity of the input*/
   if (ValidateDateDoySearch (startYear, startDoy, endYear, endDoy)) {
      if (GetStationList()) {
		  fromDOY.value = startDoy;
		  toDOY.value = endDoy;
           //Create or Open the window of an appropriate size for the output plot
           if (getClicked("plot_size") == "small") {
              var DataWindow = window.open("","DataPopup","width=725,height=725,resizable=yes,menubar=no,scrollbars=yes");

           } else {
              var DataWindow = window.open("","DataPopup","width=1500,height=1200,resizable=yes,menubar=no,scrollbars=yes");
           }

           // Bring the data window to the front of the screen (in case it is hidden by other windows or closed)
           DataWindow.focus();

            submit();
        }
      }
    }
    DataWindow.status = "Data Extraction in progress.";
    self.status="Data Extraction finished."; 
}

/* ******************************************************************** 
 * Function: viewAllAvailability                                      *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function opens up a popup window for displaying  *
 * the chart of all station availability.
 * *******************************************************************/

    function viewAllAvailability() {
      var win = window.open("all_station_availability.html","",
   "width=650,height=600,resizable=yes,scrollbars=yes,menubar=yes");
      win.focus();
    }


/* ******************************************************************** 
 * Function: nextStation                                              *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function looks at what station is currently      *
 * selected in the Station Locator section and then automatically     *
 * selects the next station map in increasing longitude. This         *
 * function is called when the user clicks on the right arrow in the  *
 * Station Locator section.                                           *
 * *******************************************************************/

    function nextStation () {
	var fileName;
	var current = document.locatorForm.stationLocatorSelection.selectedIndex;
  	var curVal = document.locatorForm.stationLocatorSelection[current].value

	for (var i=0; i<stationsOrdered.length; i++) {
	  if (stationsOrdered[i] == curVal) {
	    current = i;
  	  }
     	}

	if (current < (stationsOrdered.length-1)) {
	  current++;
	} else {
	  current = 0;
	}

	fileName = "graphics/maps/map_panel_" + stationsOrdered[current] + ".gif";
	document.StationMap.src = fileName;


	//Select station in list:
	for (var i=0; i<document.locatorForm.stationLocatorSelection.length; i++) { 
	  if (document.locatorForm.stationLocatorSelection[i].value == stationsOrdered[current]) {
	    document.locatorForm.stationLocatorSelection.selectedIndex = i;
	  }
	}
    }


/* ******************************************************************** 
 * Function: previousStation                                          *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function looks at what station is currently      *
 * selected in the Station Locator section and then automatically     *
 * selects the previous station map in decreasing longitude. This     *
 * function is called when the user clicks on the left arrow in the   *
 * Station Locator section.                                           *
 * *******************************************************************/

    function previousStation () {
	var fileName;
	var current = document.locatorForm.stationLocatorSelection.selectedIndex;
  	var curVal = document.locatorForm.stationLocatorSelection[current].value

	for (var i=0; i<stationsOrdered.length; i++) {
	  if (stationsOrdered[i] == curVal) {
	    current = i;
  	  }
     	}

	if (current > 0) {
	  current--;
	} else {
	  current = stationsOrdered.length-1;
	}

	fileName = "graphics/maps/map_panel_" + stationsOrdered[current] + ".gif";
	document.StationMap.src = fileName;


	//Select station in list:
	for (var i=0; i<document.locatorForm.stationLocatorSelection.length; i++) { 
	  if (document.locatorForm.stationLocatorSelection[i].value == stationsOrdered[current]) {
	    document.locatorForm.stationLocatorSelection.selectedIndex = i;
	  }
	}
    }


/* ******************************************************************** 
 * Function: updateDateSearch                                         *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function is called when the user enters a year in*
 *              the start year (for the availability search) and      *
 *              automatically sets the stop year to be the same year  *
 *              since that will be the common case and will save the  *
 *              user some time.                                       *
 * *******************************************************************/

    function updateDateSearch() {
      document.searchForm.toYearSearch.selectedIndex = document.searchForm.fromYearSearch.selectedIndex;
      var selectedDOY = parseInt(document.searchForm.fromDOYSearch.value) + 1;
      //document.searchForm.toDOYSearch.value=selectedDOY;
    }


/* ******************************************************************** 
 * Function: updateDate                                               *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function is called when the user enters a year in*
 *              the start year (for the data extraction) and          *
 *              automatically sets the stop year to be the same year  *
 *              since that will be the common case and will save the  *
 *              user some time.                                       *
 * *******************************************************************/

    function updateDate() {
      document.Magneto.toYear.selectedIndex = document.Magneto.fromYear.selectedIndex;
      //document.Magneto.toDOY.value = document.Magneto.fromDOY.value;
    }


/* ******************************************************************** 
 * Function: setPlotFormat                                            *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function disables the plotting parameters for    *
 *              plot size and plot mode if the Ascii data extraction  *
 *              option is selected, since the plotting options are not*
 *              relevant in this case.                                *
 * *******************************************************************/

    function setPlotFormat() {
      if (document.Magneto.type[0].checked) {
	  document.Magneto.plot_size[0].disabled = true;
	  document.Magneto.plot_mode[0].disabled = true; 
	  document.Magneto.plot_size[1].disabled = true;
	  document.Magneto.plot_mode[1].disabled = true; 
      } else {
	  document.Magneto.plot_size[0].disabled = false;
	  document.Magneto.plot_mode[0].disabled = false; 
	  document.Magneto.plot_size[1].disabled = false;
	  document.Magneto.plot_mode[1].disabled = false; 
      }
    }



/* ******************************************************************** 
 * Function: GetInfo                                                  *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function opens a popup window to display the     *
 *              Info window containing help menus for the user.       *
 * *******************************************************************/

function GetInfo() {

   /* Print msg in the main window's status bar */
   self.status="Generating Info Window ...";
   
var InfoWindow = window.open("info.html","InfoPopup",
   "width=650,height=600,resizable=yes,scrollbars=yes,menubar=yes");

 InfoWindow.focus();

}


/* ******************************************************************** 
 * Function: ChangePlotDateType                                       *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function is used to toggle between the plot date *
 * entry as a calendar date vs day of year date. This function is     *
 * currently only called from index_alternate.html.                   *
 *                                                                    *
 * This function relies on including the javascript file "findDOM.js" *
 * in the index file since this function calls the findDOM function   *
 * to identify the calendar date or doy table and hide/show them as   *
 * appropriate.
 * *******************************************************************/

function ChangePlotDateType() {

  if (document.Magneto.plotTimeType[0].checked) {
    var dom = findDOM('calendarDate',1);
    dom.display = 'block';

    var dom = findDOM('doyDate',1);
    dom.display = 'none';
  } else {
    var dom = findDOM('calendarDate',1);
    dom.display = 'none';

    var dom = findDOM('doyDate',1);
    dom.display = 'block';

  }
  
}


/* ******************************************************************** 
 * Function: ChangeSearchDateType                                     *
 *                                                                    *
 * Arguments: 0                                                       *
 *                                                                    *
 * Return value: none                                                 *
 *                                                                    *
 * Description: This function is used to toggle between the search    *
 * date entry as a calendar date vs day of year date. This function   *
 * is currently only called from index_alternate.html.                   *
 *                                                                    *
 * This function relies on including the javascript file "findDOM.js" *
 * in the index file since this function calls the findDOM function   *
 * to identify the calendar date or doy table and hide/show them as   *
 * appropriate.
 * *******************************************************************/

function ChangeSearchDateType() {

  if (document.searchForm.searchTimeType[0].checked) {
    var dom = findDOM('searchCalendarDate',1);
    dom.display = 'block';

    var dom = findDOM('searchDOYDate',1);
    dom.display = 'none';
  } else {
    var dom = findDOM('searchCalendarDate',1);
    dom.display = 'none';

    var dom = findDOM('searchDOYDate',1);
    dom.display = 'block';

  }
  
}
