function initNotifications() {
	receiveData();
	document.getElementById('message_alert').innerHTML = "&nbsp;";
}

//initiates the first data query
function receiveData() {
	
	if (httpReceive.readyState == 4 || httpReceive.readyState == 0) {
		httpReceive.open("GET", baseurl+'ajax/alerts/', true);
    	httpReceive.onreadystatechange = handlehttpReceive; 
		httpReceive.send(null);
	}
	setTimeout('receiveData();',notfDelay);
}

function handlehttpReceive() {
  if (httpReceive.readyState == 4) {
   // DATA RX //
	Results = httpReceive.responseText //.split('---'); // the fields are seperated by ---
    if (Results.length > 2) {
		//for(i=0;i < (Results.length-1);i=i+3) { // goes through the result one message at a time
		insertContent(Results); //[i+1],Results[i+2]); // inserts the new content into the page
		//}
		//lastID = Results[Results.length-4];
	}
	else {
		document.getElementById('message_alert').innerHTML = '';
	}
  }
}


function insertContent(Dat1,Dat2) {
	var Content = document.getElementById('message_alert');
	Content.innerHTML = Dat1; //': '+Dat1+', Data2:' + Dat2 + ' END';
	document.getElementById('message_sound').innerHTML = "<embed src="+baseurl+"images/ring.wav hidden=true autostart=true loop=false>";
	document.getElementById('notification_wrapper').style.display='block';
	document.getElementById('message_alert').style.display='block';
	fadeIn('message_alert',100,1000);
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}



var httpReceive = getHTTPObject();
var httpSendChat = getHTTPObject();

function fadeIn(objId,opacity,speed) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(objId, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", speed);
		}
	}
}
			
function setOpacity(objId, opacity) {
	obj = document.getElementById(objId);
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

