////////////////////////////////////////////////////////////////////////////////
//
// Variable arrays for the 'positions' list (used for TopPoints)
// 
////////////////////////////////////////////////////////////////////////////////

var positions_text_array = new Array();
var positions_value_array = new Array();
    positions_text_array[0] = '1';     positions_value_array[0] = '1';
    positions_text_array[1] = '2';     positions_value_array[1] = '2';
    positions_text_array[2] = '3';     positions_value_array[2] = '3';
    positions_text_array[3] = '4';     positions_value_array[3] = '4';
    positions_text_array[4] = '5';     positions_value_array[4] = '5';
    positions_text_array[5] = '6';     positions_value_array[5] = '6';
    positions_text_array[6] = '7';     positions_value_array[6] = '7';
    positions_text_array[7] = '8';     positions_value_array[7] = '8';
    positions_text_array[8] = '9';     positions_value_array[8] = '9';
    positions_text_array[9] = '10';    positions_value_array[9] = '10';



////////////////////////////////////////////////////////////////////////////////
// UpdateParams_RaceNews() 
//
// Calling Parameters:
//            feature_id   the index of the parameters that need to be changed.
//
//
////////////////////////////////////////////////////////////////////////////////
function UpdateParams_RaceNews(feature_id)
{
var division_select_box;
var racedate_select_box;

var prompt_span;
var old_prompt_text;

    // Update the division prompt
    prompt_span = document.getElementById( "param1prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Division: </b>" ;

    // Update the racedate prompt
    prompt_span = document.getElementById( "param2prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Date: </b>" ;

    // Update the 'division' select box
    division_select_box = document.getElementById( "param1_" + feature_id );
    division_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(division_select_box, division_text_array, division_value_array);

    // Update the 'racedate' select box
    racedate_select_box = document.getElementById( "param2_" + feature_id );
    racedate_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(racedate_select_box, racedate_text_array, racedate_value_array);

}

////////////////////////////////////////////////////////////////////////////////
// UpdateParams_RaceNewsBriefs() 
//
// Calling Parameters:
//            feature_id   the index of the parameters that need to be changed.
//
//
////////////////////////////////////////////////////////////////////////////////
function UpdateParams_RaceNewsBriefs(feature_id)
{
var division_select_box;
var racedate_select_box;

var prompt_span;
var old_prompt_text;

    // Update the division prompt
    prompt_span = document.getElementById( "param1prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Division: </b>" ;

    // Update the racedate prompt
    prompt_span = document.getElementById( "param2prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Date: </b>" ;

    // Update the 'division' select box
    division_select_box = document.getElementById( "param1_" + feature_id );
    division_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(division_select_box, division_text_array, division_value_array);

    // Update the 'racedate' select box
    racedate_select_box = document.getElementById( "param2_" + feature_id );
    racedate_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(racedate_select_box, racedate_text_array, racedate_value_array);

}


////////////////////////////////////////////////////////////////////////////////
// UpdateParams_RaceWinnerPhoto() 
//
// Calling Parameters:
//            feature_id   the index of the parameters that need to be changed.
//
//
////////////////////////////////////////////////////////////////////////////////
function UpdateParams_RaceWinnerPhoto(feature_id)
{
var division_select_box;
var racedate_select_box;

var prompt_span;
var old_prompt_text;

    // Update the division prompt
    prompt_span = document.getElementById( "param1prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Division: </b>" ;

    // Update the racedate prompt
    prompt_span = document.getElementById( "param2prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Date: </b>" ;

    // Update the 'division' select box
    division_select_box = document.getElementById( "param1_" + feature_id );
    division_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(division_select_box, division_text_array, division_value_array);

    // Update the 'racedate' select box
    racedate_select_box = document.getElementById( "param2_" + feature_id );
    racedate_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(racedate_select_box, racedate_text_array, racedate_value_array);

}




////////////////////////////////////////////////////////////////////////////////
// UpdateParams_MiscTextHtmlFile() 
//
// Calling Parameters:
//            feature_id   the index of the parameters that need to be changed.
//
//
////////////////////////////////////////////////////////////////////////////////

function UpdateParams_MiscTextHtmlFile(feature_id)
{
var file_select_box;
var unused_select_box;

var prompt_span;
var old_prompt_text;

    // Update the file prompt
    prompt_span = document.getElementById( "param1prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>File: </b>" ;

    // Update the not used prompt
    prompt_span = document.getElementById( "param2prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "Not Used: " ;

    // Update the 'file' select box
    file_select_box = document.getElementById( "param1_" + feature_id );
    file_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(file_select_box, mischtmlfile_text_array, mischtmlfile_value_array);

    // Update the unused select box
    unused_select_box = document.getElementById( "param2_" + feature_id );
    unused_select_box.disabled = true;
    ReplaceSelectList_OptionJsonArray(unused_select_box, null, null);

}

////////////////////////////////////////////////////////////////////////////////
// UpdateParams_MiscImage() 
//
// Calling Parameters:
//            feature_id   the index of the parameters that need to be changed.
//
//
////////////////////////////////////////////////////////////////////////////////

function UpdateParams_MiscImage(feature_id)
{
var file_select_box;
var unused_select_box;

var prompt_span;
var old_prompt_text;

    // Update the file prompt
    prompt_span = document.getElementById( "param1prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>File: </b>" ;

    // Update the not used prompt
    prompt_span = document.getElementById( "param2prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "Not Used: " ;

    // Update the 'file' select box
    file_select_box = document.getElementById( "param1_" + feature_id );
    file_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(file_select_box, miscimage_text_array, miscimage_value_array);

    // Update the unused select box
    unused_select_box = document.getElementById( "param2_" + feature_id );
    unused_select_box.disabled = true;
    ReplaceSelectList_OptionJsonArray(unused_select_box, null, null);

}



////////////////////////////////////////////////////////////////////////////////
// UpdateParams_MiscPDF() 
//
// Calling Parameters:
//            feature_id   the index of the parameters that need to be changed.
//
//
////////////////////////////////////////////////////////////////////////////////

function UpdateParams_MiscPDF(feature_id)
{
var file_select_box;
var unused_select_box;

var prompt_span;
var old_prompt_text;

    // Update the file prompt
    prompt_span = document.getElementById( "param1prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>File: </b>" ;

    // Update the not used prompt
    prompt_span = document.getElementById( "param2prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "Not Used: " ;

    // Update the 'file' select box
    file_select_box = document.getElementById( "param1_" + feature_id );
    file_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(file_select_box, miscimage_text_array, miscimage_value_array);

    // Update the unused select box
    unused_select_box = document.getElementById( "param2_" + feature_id );
    unused_select_box.disabled = true;
    ReplaceSelectList_OptionJsonArray(unused_select_box, null, null);

}


////////////////////////////////////////////////////////////////////////////////
// UpdateParams_TopPoints() 
//
// Calling Parameters:
//            feature_id   the index of the parameters that need to be changed.
//
//
////////////////////////////////////////////////////////////////////////////////
function UpdateParams_TopPoints(feature_id)
{
var division_select_box;
var positions_select_box;

var prompt_span;
var old_prompt_text;

    // Update the division prompt
    prompt_span = document.getElementById( "param1prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Division: </b>" ;

    // Update the # of positions prompt
    prompt_span = document.getElementById( "param2prompt_" + feature_id );
    old_prompt_text = prompt_span.InnerHTML;
    prompt_span.innerHTML = "<b>Positions: </b>" ;

    // Update the 'division' select box
    division_select_box = document.getElementById( "param1_" + feature_id );
    division_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(division_select_box, division_text_array, division_value_array);

    // Update the 'positions' select box
    positions_select_box = document.getElementById( "param2_" + feature_id );
    positions_select_box.disabled = false;
    ReplaceSelectList_OptionJsonArray(positions_select_box, positions_text_array, positions_value_array);

}




////////////////////////////////////////////////////////////////////////////////
// This function updates all the select lists when a feature is 
// changed
////////////////////////////////////////////////////////////////////////////////
function UpdateSelectLists(feature_select_box)
{
var  feature_select_id;
var  feature_id;  

    // get the element id and reduce it to only the numerical
    feature_select_id = feature_select_box.id;
    feature_id = feature_select_id.slice(8)

    ////////////////////////////////////////////////////////////////////////////
    // Call a function to reconfigure the parameter fields based on the selected
    // feature.
    ////////////////////////////////////////////////////////////////////////////

    if (feature_select_box.value == "RaceNews")
  	UpdateParams_RaceNews(feature_id);
    else if (feature_select_box.value == "RaceNewsBriefs")
  	UpdateParams_RaceNewsBriefs(feature_id);
    else if (feature_select_box.value == "RaceWinnerPhoto")
  	UpdateParams_RaceWinnerPhoto(feature_id);
    else if (feature_select_box.value == "MiscellaneousTextHtmlFile")
  	UpdateParams_MiscTextHtmlFile(feature_id);
    else if (feature_select_box.value == "MiscellaneousImage")
  	UpdateParams_MiscImage(feature_id);
    else if (feature_select_box.value == "MiscellaneousPDFFile")
  	UpdateParams_MiscImage(feature_id);
    else if (feature_select_box.value == "TopPoints")
  	UpdateParams_TopPoints(feature_id);
    else
        alert("Other");

}





/////////////////////////////////////////////////////////////////////
// This function removes all the exisitng options from a select list
// and adds the options from a json array back into select list
/////////////////////////////////////////////////////////////////////

function ReplaceSelectList_OptionJsonArray(select_box, text_array, value_array)
{
var old_length;

    // remove the existing options
    old_length = select_box.length;
    for(var i=0; i < old_length; i++)
    {
        select_box.remove(0)
    }
    // add in the new options.
    if(text_array == null)
        return;
    for(var i=0; i < text_array.length; i++)
    {
        var new_option=document.createElement('option');
        new_option.text = text_array[i];
        new_option.value = value_array[i];
        select_box.add(new_option);     
    }
}



  



