function DHTMLSound(surl) {
  document.getElementById('dummyspan').innerHTML="<embed src='"+surl+"' height=0 width=0 autostart=true loop=false>";
  document.chat.chat.blur();
}

// Start cookie functions which will set the Chat Mode Cookie for one week
function saveChatMode(){
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + 1000*60*60*24*7); 
document.cookie="chatModeCookie="+chatMode+";expires="+expire.toGMTString();
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = ""
 if (document.cookie.length > 0) {
  offset = document.cookie.indexOf(search)
  if (offset != -1) {
   offset += search.length
   end = document.cookie.indexOf(";", offset)
   if (end == -1)
    end = document.cookie.length;
   returnvalue=unescape(document.cookie.substring(offset, end))
  }
 }
 return returnvalue;
}

function getChatMode(){
 chatMode=get_cookie("chatModeCookie")
}
// End Cookie Functions 


function readMessages_1 (restartTimer) {
   var url = xmlBaseURL + league_id + ' _chat.xml?random= ' + get_random_string();
   try {
      makeHttpRequest(url, 'parseChatXML_1', 1);
   } catch (e) {
      url = window.location.protocol + "//" + window.location.host + "/fflnetdynamic" + year + "/" + league_id + '_chat.xml?random=' + get_random_string();
      makeHttpRequest(url, 'parseChatXML_1', 1);
   }
   if (restartTimer) {
      chatTimer = setTimeout("readMessages_1(true)", checkEverySeconds * 1000 );
   } 
}

function PlayDHTMLSound() {
  DHTMLSound(newPost);
}

function parseChatXML_1 (chatXML) {
   var messages = chatXML.getElementsByTagName("message")
   var lastMessageId = messages[0].getAttribute("id")
   var lastMessageTime = parseInt(lastMessageId)
   var lastMessagePostedBy = messages[0].getAttribute("franchise_id")
   if(lastMessageTime>chatServerTime) {
/*    if(lastMessagePostedBy!=franchise_id) { */
     PlayDHTMLSound(); 
/*    } */
    chatServerTime=lastMessageTime
   }
}

function togglesound(mode) {
 if(mode=='') {               // If cookie hasn't been set for user then use default mode
  mode=defaultChatMode 
 }
 if(mode=='on') {
  readMessages_1(true)
  document.getElementById("chat_sound_on").style.display="block"
  document.getElementById("chat_sound_off").style.display="none"
  chatMode='on'
  saveChatMode()
 } else {
  clearInterval(chatTimer)
  document.getElementById("chat_sound_on").style.display="none"
  document.getElementById("chat_sound_off").style.display="block" 
  chatMode='off'
  saveChatMode()
 }
}

function ringDoorBell() {
  if(chatMode=='on') DHTMLSound(doorBell)
}