function catchObject(obj_id)
{
    return document.getElementById(obj_id);
}

function loadXMLDoc(strPath)
{
    var xmlDoc;
    if (window.XMLHttpRequest)
    {
        xmlDoc = new window.XMLHttpRequest();
        xmlDoc.open("GET", strPath, false);
        xmlDoc.send("");
        return xmlDoc.responseXML;
    }
    else if (ActiveXObject("Microsoft.XMLDOM"))
    {   // For IE 5 and IE 6
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.load(strPath);
        return xmlDoc;
    }

    alert("Error loading document: " + strPath);
    return null;
}

function loadVideo(broadcastId)
{
    //var xmlMovieList = loadXMLDoc("broadcast.xml");
    var xmlMovieList = loadXMLDoc("broadcasts.php");
    var movies = xmlMovieList.getElementsByTagName("movie");

    var boolExists = false;
    var intPrevBid = -1;
    var intNextBid = -1;

    for(var n=0; n<movies.length; n++)
    {   // interate all movies and pick dataset given by ID
        if(boolExists && intNextBid<0)
            intNextBid = movies[n].attributes[0].value;

        if(movies[n].attributes[0].value == broadcastId)
        {   // if right movie found fill htmlDOM with informations
            var movie = movies[n];
            //catchObject("swfdesc_title").innerHTML = getMovieValue(movie, "title");
            //catchObject("swfdesc_text").innerHTML = getMovieValue(movie, "description");

            catchObject("swfplayer_param_bid").value = "bid=" + broadcastId;
            boolExists = true;
        }

        if(!boolExists)
            intPrevBid = movies[n].attributes[0].value;
    }
/*
    if(intPrevBid >= 0)
    {
        catchObject('swf_back').href = 'javascript:loadVideo(' + intPrevBid + ');';
        catchObject('swf_back').style.display = 'block';
    }
    else
    {
        catchObject('swf_back').href = '';
        catchObject('swf_back').style.display = 'none';
    }

    if(intNextBid >= 0)
    {
        catchObject('swf_next').href = 'javascript:loadVideo(' + intNextBid + ');';
        catchObject('swf_next').style.display = 'block';
    }
    else
    {
        catchObject('swf_next').href = '';
        catchObject('swf_next').style.display = 'none';
    }*/

    if(!boolExists)
        alert('Es tut uns leid, dieses Video scheint nicht mehr vorhanden zu sein.');
    else
    {
        //createVideoObject(broadcastId);
        catchObject("swfplayer_param_movie").value = "player.swf?bid=" + broadcastId;
                    
        //catchObject('async_frame').src = 'async_actions.php?option=getVideoCounter&bid=' + broadcastId;

        // next line is for an extend-Event displaying ... if for extend this page, all prefs are given in database and backend editor called: addEvent_old.php
        //catchObject('async_frame').src = 'async_actions.php?option=getVideoEvent&bid=' + broadcastId;

        // for non-IE
        catchObject("swfplayer_notieobject").data = "player.swf?bid=" + broadcastId;
    }
    //return boolExists;
}

function getMovieValue(movie, strNode)
{
    return movie.getElementsByTagName(strNode)[0].childNodes[0].nodeValue;
}
