﻿// (c) UNITCOM u. ISSB
var g_uiTimeout = 10000;
var g_dLastModified = null;
var newLink = "../buy.html?search=";
LinksId = new Array("text01", "text02", "text03", "text04", "text05", "text06", "text07", "text08", "text09");
var myUrl = "/playlist/playlist.xml"; 
String.prototype.superTrim = function()
{
    return (this.replace(/\s+/g, " ").replace(/\s+$/, "").replace(/^\s+/, ""));
}
var g_xmlHttp = GetXmlHttpObject();
if (!g_xmlHttp)
    alert("Ihr Internet-Browser unterstützt AJAX nicht! Die Informationen können nicht abgerufen werden.");
var LinksZahl = (LinksId.length) - 1;
myXML01 = new Array();
var xmlDoc;
function GetXmlHttpObject()
{
    var xmlHttp = null;
    try
    {
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                xmlHttp = null;
            }
        }
    }
    return xmlHttp;
}
function stateChangedHeaders()
{
    if (g_xmlHttp.readyState != 4)
        return;
    dLastModified = g_xmlHttp.getResponseHeader("Last-Modified");
    if (g_dLastModified != dLastModified)
    {
        g_dLastModified = dLastModified;
        setTimeout('RequestPlayList(false);', 500);
    }
    else if (!dLastModified)
    {
        setTimeout('RequestPlayList(false);', 500);
    }
}
function stateChangedRequestData()
{
    if (g_xmlHttp.readyState != 4)
        return;
    g_dLastModified = g_xmlHttp.getResponseHeader("Last-Modified");
    xmlDoc = g_xmlHttp.responseXML.documentElement;
    if (!xmlDoc)
        return;

    var temp = 0;
    for (var i = 0; i <= LinksZahl; i++)
    {
        if (xmlDoc.getElementsByTagName("Artist")[i])
        {
            myXML01[temp] = xmlDoc.getElementsByTagName('Artist')[i].childNodes[0].nodeValue.superTrim();
            myXML01[temp + 2] = newLink;
            y = myXML01[temp].split(" ");
            zz = y.length;
            zx = 0;
            while (zx < zz)
            {
                myXML01[temp + 2] += y[zx] + "+";
                zx++;
            }
            myXML01[temp + 1] = xmlDoc.getElementsByTagName('Title')[i].childNodes[0].nodeValue.superTrim();
            y = myXML01[temp + 1].split(" ");
            if (y[0])
                myXML01[temp + 2] += y[0];
            temp += 3;
        }
        else
        {
            myXML01[temp] = " ";
            myXML01[temp + 1] = " ";
            myXML01[temp + 2] = " ";
            temp += 3;
        }
    }
    var temp = 0;
    for (var i = 0; i <= LinksZahl; i++)
    {
        document.getElementById(LinksId[i]).innerHTML = "<a href=\""+ myXML01[temp+2] +"\" target=\"_blank\" title=\"Diesen Titel kaufen!\"  onfocus=\"this.blur()\">"+ myXML01[temp] +" <img src=\"../_img/_symbols/buy.gif\" width=10 height=10 border=0 /> - " + myXML01[temp + 1]+"</a>";
        temp += 3;
    }
    document.getElementById('myNewLink1').innerHTML = myXML01[0] + " - " + myXML01[1];
    document.getElementById('myNewLink2').innerHTML = myXML01[3] + " - " + myXML01[4];
}
function RequestPlayList(bHeadOnly)
{
    g_xmlHttp = GetXmlHttpObject();
    if (!g_xmlHttp)
        return;
    strRequestUrl = myUrl + "?parm=" + Math.random() + "&time=" + new Date().getTime().toString();
    if (bHeadOnly)
    {
        g_xmlHttp.onreadystatechange = stateChangedHeaders;
        g_xmlHttp.open("HEAD", strRequestUrl, true);
    }
    else
    {
        g_xmlHttp.onreadystatechange = stateChangedRequestData;
        g_xmlHttp.open("GET", strRequestUrl, true);
    }
    g_xmlHttp.send(null);
}
window.setInterval("RequestPlayList(true);", g_uiTimeout);

