/*
* FeedReader
* =============================================================
* Following script reads feeds in a corss-domain environment
* utilizing Google API (feeds).
*
* _FEEDURL : URL of requested feed
*
* _FACILITY : Set in view template for displaying a particular
* facility or set of facilities.
*
* _VIEW : The view to display in the browser (home | top | list)
*
* V2 (not impl.)
* -----------------
* _AUTO (true | false) : Is set will refresh the feed ad the
* specified _INTERVAL.
*
* _INTERVAL : Integer value in milliseconds for auto refresh.
*/
var dateDisplayed=false;
// DOM Manipulation and onload business logic to control views of the ER wait times.
$(document).ready(function (){
//alert(_VIEW);
// show the container selected (above)
window.setTimeout(showContainer,150);
// set tooltip text...
$('.tooltip .content').html('
ER wait times are approximate and provided for informational purposes only. If you are having a medical emergency,
call 9-1-1.
');
$('.lbl a').mouseenter(function (){
$('.tooltip').fadeIn('fast');
});
$('.lbl a').mouseleave(function (){
$('.tooltip').hide();
});
// load the rss feed and call the render method...
loadFeed();
//setInterval("loadFeed()", 120 * 1000); // 2 minutes
});
// global vars...
var numPerGroup=3;
var groupNum=0;
function showContainer(){
$('#ctr-erwait-'+_VIEW).show();
}
function loadFeed(){
// render the feed...
//alert(_FEEDURL[0].replace("http://eastflamkt.two.icu.ehc.com",""));
// loop over the feed URLs and create feeds for
if (isArray(_FEEDURL)){ // if this is an array of URLs...
for (var i=0;i<_FEEDURL.length;i++){
$.ajax({
type: "GET",
url: _FEEDURL[i].replace("http://eastflamkt.two.icu.ehc.com",""),
dataType: "xml",
success: function(xml){
renderFeed(xml);
}
});
}
} else { // otherwise it's a single load...
$.ajax({
type: "GET",
url: _FEEDURL[0].replace("http://eastflamkt.two.icu.ehc.com",""),
dataType: "xml",
success: function(xml){
renderFeed(xml);
}
});
}
}
// Helper ethods
function renderFeed(result) {
if (!result.error) {
var items = result.getElementsByTagName('item');
$('#ctr-error').hide();
// set the publish date of the RSS feed and display it...
var dateVal = items[0].getElementsByTagName('pubDate')[0].firstChild.nodeValue;
//alert(items.length);
for (var i = 0; i < items.length; i++) {
var item = items[i];
// append contents from the feedto our display container...
var title = item.getElementsByTagName('title')[0].firstChild.nodeValue;
var date = item.getElementsByTagName('pubDate')[0].firstChild.nodeValue;
var time = item.getElementsByTagName('description')[0].firstChild.nodeValue;
var link = item.getElementsByTagName('link')[0].firstChild.nodeValue;
// Exit the loop if "_FACILITY" is defined and it doesn't match this
// current entry.
if (matchFacility(title)) continue;
// append contents from the feedto our display container...
var shortName=title.replace(" ","").replace("-","");
//populate the data....
$("#"+shortName+" .hosp-name").html(renderLink(link,title,"_blank"));
$("#"+shortName+" .hosp-min").html(time);
}
// append the date stamp to the container
if (!dateDisplayed) {
$("#ctr-erwait-top, #ctr-erwait-home, #ctr-erwait-list").append("" + dateVal + "
");
// append some styles to the date labels...
if (_FACILITY!="Frankfort" && _FACILITY!="Parkland" && _FACILITY!="Terre Haute") {
var htmlStr="";
htmlStr+="";
$("body").append(htmlStr);
}
}
dateDisplayed=true;
} else {
$('#ctr-error').show();
$('#ctr-error h2').html("Error");
try {
$('#ctr-error p').html("Error communicating with RSS feed (" + _FEEDURL + "): " + reuslt.error.message);
} catch (err){
$('#ctr-error p').html("Error communicating with RSS feed (" + _FEEDURL + ")");
}
}
}
function renderLink(href,title,target){
if (arguments.length < 3) target = "_self";
if (href.indexOf("http")==-1) { href = "http://" + href; }
// replace 'www' with 'er'
if (_VIEW != 'list') href = href.replace("www","er");
// return the link for display...
return "" + title + "";
}
function matchFacility(facility){
if ((typeof _FACILITY != "undefined") && (_FACILITY.indexOf(facility)==-1) && (_FACILITY!="")){
return true;
} else {
return false;
}
}
function isArray(obj){
return(obj instanceof Array)?true:false;
}
function getContingencyMessage(){
return this.contingencyMessage;
}
function getFullDate(dateString) {
return new Date(dateString).toLocaleDateString();
}
function getTime(dateString) {
return new Date(dateString).toLocaleTimeString();
}
function getFullDateTime(dateString) {
return getFullDate(dateString) + ' ' + getTime(dateString);
}
function getAbbrDate(dateString) {
return new Date(dateString).toDateString();
}
function getAbbrDateTime(dateString) {
return getAbbrDate(dateString) + ' ' + getTime(dateString);
}
function isStaleWaitTime(dateString) {
var currLocalDate = new Date();
return ((currLocalDate.getTime()-Date.parse(dateString)) >=5400000) ? true : false;
}
function contingencyWaitTimeCheck(erWaitTime,dateString) {
return (erWaitTime == '---' || isStaleWaitTime(dateString)) ? getContingencyMessage() : erWaitTime;
}