
function playSound(audiofile) {
  var name = navigator.userAgent.toLowerCase();
  var netscape = (name.indexOf("mozilla")!=-1 && name.indexOf("compatible")==-1 && name.indexOf("opera")==-1);
  if (netscape) {
     // for NS:
     document.write("<embed src='" + audiofile + "' width='0' height='0'  autostart='true' name='startSound'/>");   
  } else {
     // for IE:
     document.write("<bgsound src='" + audiofile + "' />");
  }
}


function autostartAudio(audiofile) {
  // decide if we have to play the sound based on the referrer:
  var currentUrl = document.URL;
  var referrerUrl = document.referrer;
  if (referrerUrl.length<1){
     playSound(audiofile);
  } else {
     var drefDomain = "";
     if (referrerUrl.indexOf(".com/")>-1) {
         drefDomain = referrerUrl.replace(/http:\/\/(\S*\.com)\/\S*/i, '$1');
     }

     //document.write("Ref: "+referrerUrl+"<br>");
     //document.write("drefDomain: "+drefDomain +"<br>");
     //document.write("currentUrl: "+currentUrl+"<br>"); 

     if (currentUrl.indexOf(drefDomain)<0) {
        playSound(audiofile);
     }
  }
}