<!--
//Change by Rob to reset array.
function delete_all_from_SB(selObj)
{
    if( !SB_option_test(selObj) ) return;
    while (selObj.options.length) selObj.options[0] = null;
    selObj.options[0] = new Option("City", "", false, true);
}

// checks if the browser can add/del items from a select box.
function SB_option_test(selObj)
{
	var lgth = selObj.options.length;
    selObj.options[lgth] = new Option('');  // add an item
	if (selObj.options[lgth])
    {
        // if we were able to add an item, this works.
        // remove the dummy item and return true.
        selObj.options[lgth] = null;
        return true;
    }
    return true;
}

function add_item_to_SB(selObj, key, val, isSelected)
{
    if( !SB_option_test(selObj) ) return;

    var i = selObj.options.length;
    selObj.options[i] = new Option(val, key, false, isSelected);
}

// populate the top boxes.
function populate_SB(selObj, optionArr, topItem)
{
    delete_all_from_SB(selObj);

    add_item_to_SB(selObj, '', topItem);

    for( var i = 0; i < optionArr.length; i++ )
    {
        add_item_to_SB(selObj, escape(optionArr[i]), optionArr[i], false);
    }

    selObj.options[0].selected = true;

}

// same as above except - uses a nested array with key value pairs.
// used to populate the city boxes.
function populate_SB2(selObj, optionArr, topItem)
{
    delete_all_from_SB(selObj);

    add_item_to_SB(selObj, '', topItem);

    for( var i = 0; i < optionArr.length; i++ )
    {
        add_item_to_SB(selObj, optionArr[i][0], optionArr[i][1], false);
    }
    selObj.options[0].selected = true;
}


/******************************************************************
* Given a select list (p_selectList) and a region (p_region),
* places items that match in the p_cities array into p_selectList.
* The p_cities array is CITY:CITY_CODE|REGION_CODE.
******************************************************************/
function PopulateCitySelectList (p_selectList, p_region, p_cities)
{
	var i = 1;
	var cityRegion = p_selectList.options[p_selectList.selectedIndex].value;
	delete_all_from_SB(p_selectList);
	p_selectList.disabled = false;

    while (i < p_cities.length) {

       	//alert("Selected: '" + p_region.value + "'\nRegion List: '"+ p_cities[i].substring(p_cities[i].indexOf(";") + 1, p_cities[i].length)+"'");
		//alert("Selected: " + p_cities[i] + "\nCity Name: "+ cityName + "\nCity Value: " + cityValue);

    	//If the city is in the selected region, add it to the city select list.
    	if (p_region.options[p_region.selectedIndex].value == p_cities[i].substring(p_cities[i].indexOf("|") + 1, p_cities[i].length)) {
    		var cityName = p_cities[i].substring(0, p_cities[i].indexOf(":"));
    		var cityValue = p_cities[i].substring(p_cities[i].indexOf(":") + 1, p_cities[i].indexOf("|"));

       		p_selectList.options[p_selectList.options.length] = new Option(unescape(cityName), cityValue, false, false);
       	}

       	++i;
	}
	p_selectList.options[0].selected = true;
}


/******************************************************************
* Given a select list (p_selectList) in the p_cities array into
* p_selectList. The p_cities array is CITY:CITY_CODE.
******************************************************************/
function PopulateInternationalCitySelectList (p_selectList, p_cities)
{
	var i = 1;
	delete_all_from_SB(p_selectList);

    while (i < p_cities.length) {

		var cityName = p_cities[i].substring(0, p_cities[i].indexOf(":"));
		var cityValue = p_cities[i].substring(p_cities[i].indexOf(":") + 1, p_cities[i].length);

		p_selectList.options[p_selectList.options.length] = new Option(unescape(cityName), cityValue, false, false);

       	++i;
	}
	p_selectList.options[0].selected = true;
}


/******************************************************************
* The page to go when a user selects a city.
******************************************************************/
function GetWeather (p_citySelectList)
{
	var url;

	if (p_citySelectList.options[p_citySelectList.options.selectedIndex].value != "") {
		url =  "/servlet/HTMLTemplate/!ctvDynNews/Weather/Weather?City="
//alert(p_citySelectList.options[p_citySelectList.options.selectedIndex].value);
		url += escape(p_citySelectList.options[p_citySelectList.options.selectedIndex].value);
		document.location = url;
	}
}


/******************************************************************
* Initializes all select lists in the weather page.
******************************************************************/
function SetUpSelectLists (p_selectList, p_cities)
{
	//Reset all the select lists.
	for (var i = 0; i < document.locationsForm.elements.length; i++) {
		document.locationsForm.elements[i].selectedIndex = 0;
	}
	PopulateInternationalCitySelectList (p_selectList, p_cities);
}

//-->

