  function callorder(strMusicChoice) {
    var newURL = "http://" + window.location.host + window.location.pathname + "?";
    var query = window.location.search.substring(1);
    var pairs = query.split("&");
    var musicChoice = strMusicChoice;
    var blnMusicChoiceSet = false;

    var url = window.location.pathname;
    if (url.indexOf("custom.pd") > 0 || url.indexOf("custompdb.pd") > 0) 
    {
      document.customForm.submit();
      return
    }

    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 == 'mc') {
        newURL += "mc=" + strMusicChoice + "&";
        blnMusicChoiceSet = true;
      } else {
        newURL += argname + "=" + value + "&";
      }
    } 
    if (!blnMusicChoiceSet) {
      newURL += "mc=" + strMusicChoice + "&";
    }
    window.self.location.href = newURL; 
  }
  
  function musicHandler(blnFlipOn)
  {
    var blnMusicOn;
    var newURL = "http://" + window.location.host + window.location.pathname + "?";
    var query = window.location.search.substring(1);
    var pairs = query.split("&");
    var musicChoice = "crescendo.mid";

    var url = window.location.pathname;
    if (url.indexOf("custom.pd") > 0 || url.indexOf("custompdb.pd") > 0)
    {
      for (var i = 0; i < document.customForm.elements.length; i++) 
      {
        var e = document.customForm.elements[i];
        if (e.name == 'mc') {
          musicChoice = e.value;
        }
      }
      if (blnFlipOn)
      {
        document.customForm.pnMusicOn.value = 'Y'
      }
      if (typeof blnFlipOn == "undefined") {
        if (document.customForm.pnMusicOn.value == 'Y')
        {
          blnMusicOn = true;
        } else {
          blnMusicOn = false;
        }
        writeMusicMid(blnMusicOn, musicChoice);
      } else {
        if (blnFlipOn) {
          document.customForm.pnMusicOn.value = 'Y';
        } else {
          document.customForm.pnMusicOn.value = 'N';
        }
        document.customForm.submit();
      }
      return
    }

    if (typeof blnFlipOn == "undefined") {
      blnMusicOn = true;
    } else {
      blnMusicOn = blnFlipOn;
    }

    if (document.getElementsByName("mc").length > 0)
    {
        musicChoice = document.getElementsByName("mc")[0].value;
        if (musicChoice == "nomusic")
        {
          blnMusicOn = false;
        }
    }

    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") {
      ridOfChoice();
      writeMusicMid(blnMusicOn, musicChoice);
    } else {
      if (blnMusicOn) {
        newURL += "blnMusicOn=Y&"
      } else {
        newURL += "blnMusicOn=N&";
      }
      window.self.location.href = newURL;
    }
  }

  function ridOfChoice()
  {
    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 writeMusicMid(blnMusicOn, musicChoice)
  {
    var mcWebPath = "http://www.imgag.com/product/musicchoice/";
    var productWebPath = "http://www.imgag.com/product/full/ap/3043365/";
    if (blnMusicOn)
    {
      if (musicChoice == "" || musicChoice == "originalcardmusic.mid" || musicChoice == "music.mid")
      {
        document.write('<embed src="' + productWebPath + 'music.mid" HIDDEN=true AUTOSTART=true loop=true></embed><noembed><bgsound src="' + productWebPath + 'music.mid" loop="INFINITE"></noembed>');
      } else {
        document.write('<embed src="' + mcWebPath + musicChoice + '" HIDDEN=true AUTOSTART=true loop=true></embed><noembed><bgsound src="' + mcWebPath + musicChoice + '" 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"; 
    }
  }

  musicHandler();

