﻿function tvSelected(type) {
    var countryComboDiv = document.getElementById("byCountry");

    var countryCombo = document.getElementById(countryComboClientID);

    countrySelected(countryCombo);
}



function radioTypeSelected(type) {
    var countryComboDiv = document.getElementById("byCountry");
    var genreComboDiv = document.getElementById("byGenre");

    var countryCombo = document.getElementById(countryComboClientID);
    var genreCombo = document.getElementById(genreComboClientID);

    switch (type) {
        case 1:
            //countryComboDiv.style.display = "none";
            //genreComboDiv.style.display = "block";
            genreCombo.options[0].selected == true;
            genreSelected(genreCombo);
            break;
        case 2:
            //countryComboDiv.style.display = "block";
            //genreComboDiv.style.display = "none";
            countrySelected(countryCombo);
            break;
    }
}

function countrySelected(dropDownList) {
    var idx = dropDownList.selectedIndex;
    if (idx != -1) {
        var countryID = dropDownList.options[idx].value;
        if (countryID != -1)
            PageMethods.GetRadioStationsByCountry(countryID, onSucceeded, onFailed);
    }
}


function genreSelected(dropDownList) {
    var idx = dropDownList.selectedIndex;
    if (idx != -1) {
        var id = dropDownList.options[idx].value;
        if (id != -1)
            PageMethods.GetRadioStationsByGenre(id, onSucceeded, onFailed);
    }
}

function onSucceeded(result, userContext, methodName) {
    //here populate the stations combobox
    var combo = document.getElementById(radioStationsClientId);
    var objType;
    if (combo != null) {
        populateStations(combo, result);
        //select the first one
        if (combo.options[0]!=null)
        {
            combo.options[0].selected == true;
            if (typeof(combo.options[0].attributes["TP"])!='undefined' && combo.options[0].attributes["TP"]!=null)
                objType = combo.options[0].attributes["TP"].value;
            else
                objType = "EMPTY";
            selectRadioStation(combo.options[0].value, objType);
        }
    }
}


function radioStationSelected() {
    var combo = document.getElementById(radioStationsClientId);
    var selIdx = combo.selectedIndex;
    var objType;
    var source = combo.options[selIdx].value;
     if (typeof(combo.options[0].attributes["TP"])!='undefined' && combo.options[0].attributes["TP"]!=null)
        objType = combo.options[0].attributes["TP"].value;
    else
        objType = "EMPTY";
    
    selectRadioStation(source, objType);
}

function selectRadioStation(source, type) {
    if (tv==true)
    {
        switch (type) {
        case "MP":
            document.getElementById("mpDiv").style.display = 'block';
            document.getElementById("FLData").style.display = 'none';
            document.getElementById("FLParam").style.display = 'none';
            document.MediaPlayer.Url = source;
            break;
        case "flashData":
            document.getElementById("mpDiv").style.display = 'none';
            document.getElementById("FLData").style.display = 'block';
            document.getElementById("FLParam").style.display = 'none';
            document.live_embed_player_flash.data = source;
            break;
        case "flashParam":
            document.getElementById("mpDiv").style.display = 'none';
            document.getElementById("FLData").style.display = 'none';
            document.getElementById("FLParam").style.display = 'block';
            document.live_embed_player_flash.movie = source;        
            break;
            
        }        
    }
    else
    {
        var browser=navigator.appName;
        if (browser=="Netscape")
            document.mozPlayer.src  = source;        
        else
            if (browser=="Microsoft Internet Explorer")
                document.MediaPlayer.fileName = source;
        
    }
}

function onFailed(error, userContext, methodName) {
    //rmeove all items from a combo
}

function populateStations(combo, stationsList) {

    // Clear out the list of teams
    clearOptions(combo);

    for (var i = 0; i < stationsList.length; i++) {
        var station = stationsList[i];
        addToOptionList(combo, station.caption, station.url, station.type);
    }
}


function clearOptions(optionList) {

    // Always clear an option list from the last entry to the first
    for (x = optionList.length; x >= 0; x--) {
        optionList[x] = null;
    }
}


function addToOptionList(optionList, optionText, optionValue, stationType) {
    // Add option to the bottom of the list
    var option = new Option(optionText, optionValue);
    option.setAttribute('TP', stationType);
    optionList[optionList.length] = option;
    
}