var req;
var mboutput;

function seeqpodClose() {
   document.getElementById('light').style.display='none';
}
function seeqpodRelated(artist, title, todo) {
   seeqpodSearch(artist,title,2);
}
function seeqpodSearch(artist, title, todo) {
//if todo == 1 don't do MusicBrainz search
//if todo == 2 discover related at seeqpod
   var output = '';
   var search = artist + '+' + title;
   var artistd = decodeURIComponent(artist);
   artistd = artistd.replace(/\+/g,' ');
   var titled = decodeURIComponent(title);
   titled = titled.replace(/\+/g,' ');
   document.getElementById('light').style.display='block';
   
//   output += '<div style="float:right;"><a href="javascript:void(0)" onclick="seeqpodClose()"><img src=/audio_player/close_button.gif></a></div>';
/*   if(todo ==2) {
      output += '<hr><object type="application/x-shockwave-flash" width="400" height="20"';
      output += 'data="http://www.DogstarRadio.com/xspf_player/xspf_player_slim.swf?autoplay=true&playlist_url=http://www.DogstarRadio.com/xspf_player/xspf_seeqpod.php?discover%3D1%26artist%3D' + artist + '%26title%3D' + title + '">';
      output += '<param name="movie" ';
      output += 'value="http://www.DogstarRadio.com/xspf_player/xspf_player_slim.swf?autoplay=true&playlist_url=http://www.DogstarRadio.com/xspf_player/xspf_seeqpod.php?discover%3D1%26artist%3D' + artist + '%26title%3D' + title + '" />';
      output += '</object>   ';   
   }
   else {
      output += '<hr><object type="application/x-shockwave-flash" width="400" height="20"';
      output += 'data="http://www.DogstarRadio.com/xspf_player/xspf_player_slim.swf?autoplay=true&playlist_url=http://www.DogstarRadio.com/xspf_player/xspf_seeqpod.php?search=' + search + '">';
      output += '<param name="movie" ';
      output += 'value="http://www.DogstarRadio.com/xspf_player/xspf_player_slim.swf?autoplay=true&playlist_url=http://www.DogstarRadio.com/xspf_player/xspf_seeqpod.php?search=' + search + '" />';
      output += '</object>   ';
   }
   output += '<br>Artist:<input id="newsearcha" type=text name=newsearcha size=20 value="' + artistd + '" onChange="seeqpodSearch(document.getElementById(\'newsearcha\').value,document.getElementById(\'newsearcht\').value)">';
   output += ' &nbsp; Title:<input id="newsearcht" type=text name=newsearcht size=20 value="' + titled + '" onChange="seeqpodSearch(document.getElementById(\'newsearcha\').value,document.getElementById(\'newsearcht\').value)">';
   output += '<input type=submit value="Search" onClick="seeqpodSearch(document.getElementById(\'newsearcha\').value,document.getElementById(\'newsearcht\').value)">';
   output += '<input type=submit value="Discover Related" onClick="seeqpodRelated(document.getElementById(\'newsearcha\').value,document.getElementById(\'newsearcht\').value)">';
*/
//   output += '<span style="float:right;">Powered by <a target=_blank href=http://www.Seeqpod.com>Seeqpod</a> and <a target=_blank href=http://musicplayer.sourceforge.net/>XSPF Web Music Player</a></span><br>';
//   output += '<input type=submit value="Close" onclick="seeqpodClose()"><p>';
//   output += '<iframe src="http://rcm.amazon.com/e/cm?t=dogstarradio-20&o=1&p=9&l=st1&mode=music&search=' + artist + '&fc1=000000&lt1=&lc1=3366FF&bg1=FFFFFF&f=ifr" marginwidth="0" marginheight="0" width="180" height="150" border="0" frameborder="0" style="border:none;" scrolling="no"></iframe>';
   output += '<div id="musicBrainzResults"></div>';
   document.getElementById('light').innerHTML = output;
   
   if(todo == 1) {
      document.getElementById('musicBrainzResults').innerHTML = mboutput;
   }
   else {
        req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
        try {
                        req = new XMLHttpRequest();
//req = GXmlHttp.create();
        } catch(e) {
                        req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
        try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
                try {
                        req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e) {
                        req = false;
                }
                }
    }
        if(req) {
                req.onreadystatechange = processReqChange;
                req.open("GET", 'http://www.dogstarradio.com/xspf_player/xspf_musicbrainz.php?artist=' + artist + '&title=' + title , true);
                req.send("");
        }
     }
}





function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            updateDivs();
        } 
    }
}

function updateDivs() {

//   var mboutput = req.responseXML.getElementsByTagName("result");
//   alert(mboutput[0].childNodes[0].nodeValue);
    
//   document.getElementById('musicBrainzResults').innerHTML = mboutput[0].childNodes[0].nodeValue;
   mboutput = req.responseText;
    
   document.getElementById('musicBrainzResults').innerHTML = mboutput;
}
