//used by UPD musicfilter
function noOrderFormMusicHandler(blnFlipOn, musicChoicePath, choice, origMusicPath, origMusic)
{
    var blnMusicOn;
    var newURL = "http://" + window.location.host + window.location.pathname + "?";
    var query = window.location.search.substring(1);
    var pairs = query.split("&");
    var musicChoice = choice;

    if (typeof blnFlipOn == "undefined") {
      blnMusicOn = true;
    } else {
      blnMusicOn = blnFlipOn;
    }

    var optObj = document.getElementById("mc");
    if (optObj) {
      musicChoice = optObj.options[optObj.selectedIndex].value;
    }

    for (var i=0; i < pairs.length; i++) {
      var pos = pairs[i].indexOf('=');
      if (pos == -1) continue;
      var argname = pairs[i].substring(0,pos);
      var value = pairs[i].substring(pos+1);
      if (argname == 'blnMusicOn') {
        if (typeof blnFlipOn == "undefined") {
          if (value == "Y") {
            blnMusicOn = true;
          } else {
            blnMusicOn = false;
          }
        } 
      } else {
        if (argname == "mc") {
          musicChoice = value;
        }
        newURL += argname + "=" + value + "&";
      }
    } 

    if (typeof blnFlipOn == "undefined") {
      ridOfMusicChoice();
      if (musicChoice == "nomusic")
      {
        blnMusicOn = false;
      }
      if ((musicChoice == '') || (musicChoice == origMusic)) {
         writeMusicTag(blnMusicOn, origMusicPath + origMusic);
      } else {
         writeMusicTag(blnMusicOn, musicChoicePath + musicChoice);
      }
    } else {
      if (blnMusicOn) {
        newURL += "blnMusicOn=Y&"
      } else {
        newURL += "blnMusicOn=N&";
      }
      window.self.location.href = newURL;
    }
}

function ridOfMusicChoice()
{
    var url = window.location.pathname;
    if ((url.indexOf("view.pd") > 0) || (url.indexOf(".html") > 0))
    {
      if (document.getElementById("musicchoice"))
      {
        document.getElementById("musicchoice").style.display = "none";
      }
    }
}

function writeMusicTag(blnMusicOn, musicPath)
{
    if (blnMusicOn)
    {
      document.write('<embed src="' + musicPath + '" HIDDEN=true AUTOSTART=true loop=true></embed><noembed><bgsound src="' + musicPath + '" loop="INFINITE"></noembed>');
      //alert('<embed src="' + musicPath + '" HIDDEN=true AUTOSTART=true loop=true></embed><noembed><bgsound src="' + musicPath + '" loop="INFINITE"></noembed>');
      document.getElementById("btnFlipOn").style.display = "none"; 
      document.getElementById("btnFlipOff").style.display = "block"; 
    } else {
      document.getElementById("btnFlipOn").style.display = "block"; 
      document.getElementById("btnFlipOff").style.display = "none"; 
    }
}
