// Variables
if(typeof(servertime) === 'undefined'){var servertime = new Date();} //if perl script not working uses client date
var today = new Date(servertime);
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);

var yesterday = new Date(servertime);
yesterday.setDate(today.getDate() - 1);
yesterday.setHours(23);
yesterday.setMinutes(59);
yesterday.setSeconds(59);

var tomorrow = new Date(servertime);
tomorrow.setDate(today.getDate() + 1);
tomorrow.setHours(0);
tomorrow.setMinutes(0);
tomorrow.setSeconds(0);

var past = new Date("1 Jan 1990");

var future = new Date("31 Dec 2050");

var all = 100000;
var desc = true;
var asc = false;

function siteNavHeight() {
	var sitetopnavwidth = 0;
	
	//Makes Multiple rows.
	$('#siteTopNav ul li').each(function(){
		sitetopnavwidth += $(this).outerWidth(true);
	});
	
		if (sitetopnavwidth <= 990) {
			$('#siteTopNav ul').height('40px');
		}
		if (sitetopnavwidth > 990) {
			$('#siteTopNav ul').height('80px');
		}
		if (sitetopnavwidth > 1980) {
			$('#siteTopNav ul').height('120px');
		}

}

function homeTopAutoHeight(){
	var modcontactheight = 0;
	var modcarouselheight = 0;
	try {
		if ($('#modContact').length > 0) {
			$('#modContact > *').each(function(){
				modcontactheight += $(this).outerHeight(true);
			});
		}
		
		for (var i = 1; i < 20; i++) {
			modcarouselheight = 0;
			if ($('#modCarousel').length > 0) {
				$('#tmpSlide-' + i + ' h4').each(function(){
					modcarouselheight += $(this).outerHeight(true);
				});
				
				$('#tmpSlide-' + i + ' p').each(function(){
					modcarouselheight += $(this).outerHeight(true);
				});
				
				if (modcarouselheight > modcontactheight) {
					modcontactheight = modcarouselheight;
				}
			}
		}
		
		if ($('#modContact').length > 0 && $('#modCarousel').length > 0) {
		
			var modcarouselheight = modcontactheight + 20;
			var contactMinHeight = 278;
			if($('#tmpSlideshowControls')[0]){contactMinHeight+=22;}
			if($('#navControls')[0]){contactMinHeight+=22;}
			var carouselMinHeight = contactMinHeight + 20;
			if (modcontactheight > contactMinHeight) {
				$('#modContact').height(modcontactheight + 'px');
				$('#modCarousel').height(modcarouselheight + 'px');
			}
			else {
				$('#modContact').height(contactMinHeight+'px');
				$('#modCarousel').height(carouselMinHeight+'px');
			}
		}
	} 
	catch (ex) {
		//alert(ex);
	}
}

function actionBarAutoHeight() {
	var actionbarwidth = 0;
	
	//Makes Multiple rows.
	$('div#actionBar>*').each(function(){
		actionbarwidth += $(this).outerWidth(true);
	});
	if(actionbarwidth<=970){$('#actionBar').height('44px');}
	if(actionbarwidth>970){$('#actionBar').height('88px');}
	if(actionbarwidth>1940){$('#actionBar').height('132px');}
}

// Adds row striping to any table, tbody, ol, or ul that has class=shaded.  Styled with CSS
$(document).ready(function(){
    try {
        /* Table Shading */
        $('div#modNews table tr:nth-child(odd)').addClass('alt');
        $('table.shaded tr:nth-child(even)').addClass('rowEven');
        $('table.shaded tr:nth-child(odd)').addClass('rowOdd');
        $('tbody.shaded tr:nth-child(even)').addClass('rowEven');
        $('tbody.shaded tr:nth-child(odd)').addClass('rowOdd');
        $('ol.shaded li:nth-child(even)').addClass('rowEven');
        $('ol.shaded li:nth-child(odd)').addClass('rowOdd');
        $('ul.shaded li:nth-child(even)').addClass('rowEven');
        $('ul.shaded li:nth-child(odd)').addClass('rowOdd');
        /* lightbox applied to id=lightbox a links */
        $('#lightbox a').lightBox();
		if (!isMobile) {
			setInterval(siteNavHeight, 1000);
			if ($('#modCarousel').length > 0 || $('#modContact').length > 0) {
				setInterval(homeTopAutoHeight, 100);
			}
			if ($('#actionBar').length > 0) {
				setInterval(actionBarAutoHeight, 1000);
			}
		}
    }
    catch (ex) {
        // alert("Table Shading: " + ex);
    }
});

// Breadcrumb : Builds the breadcrumb dynamically from breadcrumbarray[][] defined in each sitehead
function buildbreadcrumb(){
    try {
        var breadcrumbarray = mybreadcrumb(); // pulls mybreadcrumb() from sitebreadcrumb.js
        var breadcrumbtxt = "<span class='hide'>Site&nbsp;Breadcrumb:&nbsp;</span>";
        var foundfirstmatch = false; // build link from this point plus $parentfolder
        var makebullet = false; // no bullet on first append
        var homefolder = "";
        var indexfolder = "";
        var parentfolder = "";
        // 5 lines below - breaks out parentfolder from home folder
        var rootArray = breadcrumbarray[0][0].split('\/');
        for (var h = 0, hh = rootArray.length - 1; h < hh; h++) {
            parentfolder += rootArray[h] + "\/";
        }
        breadcrumbarray[0][0] = rootArray[rootArray.length - 1];
        
        //loops through the url testing segments against breadcrumbarray build in sitebreadcrumb.js
        //appends breadcrumb items found in breadcrumbarray
        //builds link dynamically, uses description text in breadcrumb array
        //descripton text in breadcrumb array should match the <h3> text on that tested folder's index page
        for (var i = 0, ii = $.url.segment(); i < ii; i++) {
            for (var j = 0, jj = breadcrumbarray.length; j < jj; j++) {
                var myparents = breadcrumbarray[j][0].split('\/');
                var testme = ($.url.segment(i) == myparents[myparents.length - 1]);
                for (var g = 1, gg = myparents.length; g < gg; g++) {
                    testme = testme && ($.url.segment(i - g) == myparents[myparents.length - (g + 1)]);
                }
                
                if (testme) {
                    var thislink = "\/";
                    if (parentfolder) {
                        thislink += parentfolder;
                    }
                    if (!foundfirstmatch) {
                        homefolder = i;
                        foundfirstmatch = true;
                    }
                    indexfolder = i;
                    for (var k = homefolder; k <= indexfolder; k++) {
                        thislink += $.url.segment(k) + "\/";
                    }
                    thislink += "index.shtml";
                    if ($.url.segment(indexfolder + 1) == "index.shtml" || $.url.segment(indexfolder + 1) === null) {
                    }
                    else {
                        if (makebullet) {
                            breadcrumbtxt += " &nbsp;&bull;&nbsp; ";
                        }
                        breadcrumbtxt += '<a href="' + thislink + '">' + breadcrumbarray[j][1] + '<\/a>';
                    }
                    makebullet = true;
                }
            }
        }
        $('#siteBreadcrumb p').html(breadcrumbtxt);
    } 
    catch (ex) {
        // alert("Build Breadcrumb: " + ex);
    }
}

// Breadcrumb : Grabs either second <h3> or first <h3> tag and appends to breadcrumb text
$('#mainContent').ready(function(){
    try {
        //if (!(($.url.attr("file") == "index.shtml") || ($.url.attr("file") == null))) {
        var pageName = $('.breadcrumb span').html();
        if (pageName === null) {
            pageName = $('.breadcrumb').html();
        }
        if (pageName === null) {
            pageName = $('h3:nth-child(2) span').html();
        }
        if (pageName === null) {
            pageName = $('h3:nth-child(2)').html();
        }
        if (pageName === null) {
            pageName = $('h3 span').html();
        }
        if (pageName === null) {
            pageName = $('h3').html();
        }
        if (pageName !== null) {
            var h3lines = pageName.split('<br>');
            pageName = h3lines[0];
            $('div#siteBreadcrumb p').append(" &nbsp;&bull;&nbsp; <span>" + pageName + "<\/span>");
        }
        //}
    } 
    catch (ex) {
        // alert("Breadcrumb H3 Copy: " + ex);
    }
});

// functions that require the URL (de-linking <a> tags, class on sitetopnav current <li>)
$(document).ready(function(){
    try {
        var thisPage;
        
        if ($.url.attr("file")) {
            thisPage = $.url.attr("directory") + $.url.attr("file");
        }
        else {
            thisPage = $.url.attr("directory") + "index.shtml";
        }
        $('#siteTopNav a').each(function(){
            try {
                if (thisPage.match($(this).attr('href'))) {
                    $(this).removeAttr('href');
                    $(this).css('text-decoration', 'none');
                    $(this).parent().removeClass('current');
                    $(this).parent().addClass('currentHome');
                }
            } 
            catch (ex) { //alert("De-Link Inside: " + ex);
            }
        });
        $('#leftSidebar a').each(function(){
            try {
                if (thisPage.match($(this).attr('href'))) {
                    $(this).css('color', 'black');
                }
            } 
            catch (ex) { //alert("De-Link Inside: " + ex);
            }
        });
        $('#contentWrapper a').each(function(){
            try {
                if (thisPage.match($(this).attr('href'))) {
                    $(this).removeAttr('href');
                    $(this).css('text-decoration', 'none');
                }
            } 
            catch (ex) { //alert("De-Link Inside: " + ex);
            }
        });
        $('div.fileExt a').each(function(){
            try {
                if ($(this).attr('href').match(".pdf")) {
                    $(this).after(' (PDF)');
                }
                if (($(this).attr('href').match("granicus") || $(this).attr('href').match("vimeo")) || $(this).attr('href').match(".wmv")) {
                    $(this).after('<a class="videoIcon" href="' + $(this).attr('href') + '">&nbsp;</a>');
                }
            } 
            catch (ex) { //alert("De-Link Inside: " + ex);
            }
        });
        $('#siteBottomNav a').each(function(){
            try {
                if (thisPage.match($(this).attr('href'))) {
                    $(this).removeAttr('href');
                    $(this).css('text-decoration', 'none');
                    $(this).css('color', 'black');
                }
            } 
            catch (ex) { //alert("De-Link Inside: " + ex);
            }
        });
    } 
    catch (ex) {
        // alert("De-Link Outside: " + ex);
    }
});

// used in Site Top Navigation to mark the current button
function markcurrent(){
    try {
        var thisPage;
        if (!isMobile) {
			siteNavHeight();
		}
		
        if ($.url.attr("file")) {
            thisPage = $.url.attr("directory") + $.url.attr("file");
        }
        else {
            thisPage = $.url.attr("directory") + "index.shtml";
        }
        
        // current button for home pages - Check page URL so it doesn't always de-link when in sub folder section.
		// assuming home page is the first button.
        $('#siteTopNav a:lt(1)').each(function(){
            try {
				$(this).html($(this).html()+'<span class="hide">&nbsp;Tab<span>');
                if (thisPage.match($(this).attr('href'))) {
					$(this).html($(this).html()+'<span class="hide">&nbsp;-&nbsp;Selected<span>');
                    $(this).parent().addClass('current');
                }
            } 
            catch (ex) {
                // alert("Current Button LT(1): " + ex);
            }
        });
        
        // current button for non-home sub-folder pages
        $('#siteTopNav a:gt(0)').each(function(){
            try {
				$(this).html($(this).html()+'<span class="hide">&nbsp;Tab<span>');
                var tmp = $.url.attr("path");
                if (($.url.attr("path")).match($.url.setUrl($(this).attr('href')).attr('directory'))) {
					$(this).html($(this).html()+'<span class="hide">&nbsp;-&nbsp;Selected<span>');
                    $(this).parent().addClass('current');
                }
                $.url.setUrl(tmp);
            } 
            catch (ex) {
                // alert("Current Button GT(0): " + ex);
            }
        });
    } 
    catch (ex) {
        // alert("Current Button Outside: " + ex);
    }
}

// added to bottom of any Side Navigation to collapse the sub-navigation ULs
function collapsesidenav(){
    try {
        $('#leftSidebar li ul').hide(); // hide all sublists.
        $('#leftSidebar li ul.nocollapse').show(); // hide all sublists.
        $('#leftSidebar>ul>li>a').each(function(){
            var tmp = $.url.attr("path");
            if (($.url.attr("path")).match($.url.setUrl($(this).attr('href')).attr('directory'))) {
                $(this).siblings().show();
                if ($(this).hasClass('delink')) {
                    $(this).removeAttr('href');
                    $(this).css('text-decoration', 'none');
                    $(this).css('color', 'black');
                }
            }
            $.url.setUrl(tmp);
        });
        $('#leftSidebar>ul>li>ul>li>a').each(function(){
            var tmp = $.url.attr("path");
            if (($.url.attr("path")).match($.url.setUrl($(this).attr('href')).attr('directory'))) {
                $(this).siblings().show();
                if ($(this).hasClass('delink')) {
                    $(this).removeAttr('href');
                    $(this).css('text-decoration', 'none');
                    $(this).css('color', 'black');
                }
            }
            $.url.setUrl(tmp);
        });
        $('#leftSidebar>ul>li>ul>li>ul>li>a').each(function(){
            var tmp = $.url.attr("path");
            if (($.url.attr("path")).match($.url.setUrl($(this).attr('href')).attr('directory'))) {
                $(this).siblings().show();
                if ($(this).hasClass('delink')) {
                    $(this).removeAttr('href');
                    $(this).css('text-decoration', 'none');
                    $(this).css('color', 'black');
                }
            }
            $.url.setUrl(tmp);
        });
    } 
    catch (ex) {
        // alert("collapsesidenav(): " + ex);
    }
}

// listserv.js : clears the value from the input field in email signup form.
function clearText(thefield){
    if (thefield.defaultValue == thefield.value) {
        thefield.value = "";
    }
}

function check_cdfs(form){
    return true;
}

function doSubmit(){
    if (check_cdfs(document.survey)) {
        window.open('', 'signup', 'resizable=1,scrollbars=0,width=150,height=150');
        return true;
    }
    else {
        return false;
    }
}

// readXML - returns JSON object with all data in any XML document.
// pass - URL to XML file
// return - JSON object

function readXML(file){

    try {
    
        var carousel = [];
        
        if (window.XMLHttpRequest) {
        
            xhttp = new XMLHttpRequest();
            
        }
        
        else {
        
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
            
        }
        
        xhttp.open("GET", file, false);
        
        xhttp.send("");
        
        xmlDoc = xhttp.responseXML;
        
        //adds blank item to xmlDoc.  Fix for error if there is only one item in the xml file.
        var newel = xmlDoc.createElement("item");
        var x = xmlDoc.getElementsByTagName("channel")[0];
        x.appendChild(newel);
        
        if (xmlDoc) {
        
            return $.xml2json(xmlDoc);
            
        }
    } 
    catch (ex) {
    
        // alert("readXML: " + ex);
    
    }
    
}

// filterDates - use XML dynamic content
// pass: JSON object, start date, end date
// adds 'filter' object to JSON with true/false if it falls within date range
// return: JSON object

function filterDates(jsonObject, start, end, cat){
    try {
        start = new Date(start);
        end = new Date(end);
        for (var i = 0, ii = jsonObject.item.length - 1; i < ii; i++) {
            if (!cat || jsonObject.item[i].category == cat) {
                if (!jsonObject.item[i].index) {
                    if (jsonObject.item[i].pubDate) {
                        if (jsonObject.item[i].pubDate.alt) {
                            if (new Date(jsonObject.item[i].pubDate.text) < start || new Date(jsonObject.item[i].pubDate.text) > end) {
                                jsonObject.item[i].filter = false;
                            }
                            else {
                                jsonObject.item[i].filter = true;
                                jsonObject.item[i].index = (Date.parse(jsonObject.item[i].pubDate.text)) / 1000;
                            }
                        }
                        else {
                            if (new Date(jsonObject.item[i].pubDate) < start || new Date(jsonObject.item[i].pubDate) > end) {
                                jsonObject.item[i].filter = false;
                            }
                            else {
                                jsonObject.item[i].filter = true;
                                jsonObject.item[i].index = (Date.parse(jsonObject.item[i].pubDate)) / 1000;
                            }
                        }
                    }
                    else {
                        jsonObject.item[i].filter = false;
                    }
                }
                else {
                    if (!(isNaN(jsonObject.item[i].index))) {
                        jsonObject.item[i].index = parseFloat(jsonObject.item[i].index);
                    }
                    jsonObject.item[i].filter = true;
                }
            }
        }
        return jsonObject;
    } 
    catch (ex) {
        //alert("filterDates: " + ex);
    }
}

// sortJson - use XML dynamic content
// pass: JSON object and true/false for descending date order
// sorts entire JSON object by 'item.pubDate'
// return: JSON object

function sortJson(jsonObject, descending){
    try {
        var temp = {};
        var sorted = false;
		var i, ii;
        if (descending) {
            while (!sorted) {
                sorted = true;
                for (i = 0, ii = jsonObject.item.length - 1; i < ii; i++) {
                    if ((!jsonObject.item[i].filter && jsonObject.item[i + 1].filter) || (jsonObject.item[i].index < jsonObject.item[i + 1].index)) {
                        temp = jsonObject.item[i];
                        jsonObject.item[i] = jsonObject.item[i + 1];
                        jsonObject.item[i + 1] = temp;
                        sorted = false;
                    }
                }
            }
        }
        else {
            while (!sorted) {
                sorted = true;
                for (i = 0, ii = jsonObject.item.length - 1; i < ii; i++) {
                    if ((jsonObject.item[i].filter && !jsonObject.item[i + 1].filter) || (jsonObject.item[i].index > jsonObject.item[i + 1].index)) {
                        temp = jsonObject.item[i];
                        jsonObject.item[i] = jsonObject.item[i + 1];
                        jsonObject.item[i + 1] = temp;
                        sorted = false;
                    }
                }
            }
        }
        return jsonObject;
    } 
    catch (ex) {
        //alert("sortJson: " + ex + ": "+ i);
    }
}

// countJson - use XML dynamic content
// pass: JSON object and number of requested return records (0=all records, 5=five first 'true' objects from top of list, -5=five first 'true' objects from bottom of list)
// marks all objects 'true' that fall out of requested count as 'false'
// returns: JSON object

function countJson(jsonObject, count){
    try {
        var recordCount = 0;
        var tempCount = 0;
        var filterFromTop = true;
        var returnAllRecords = false;
		var i, ii;
        if (!count) {
            count = all;
            returnAllRecords = true;
        }
        if (count < 0) {
            filterFromTop = false;
            count = -count;
        }
        
        for (i = 0, ii = jsonObject.item.length; i < ii; i++) {
            if (jsonObject.item[i].filter === true) {
                recordCount++;
            }
        }
        if (recordCount > count) {
            recordCount = count;
        }
        
        jsonObject.count = recordCount;
        
        if (returnAllRecords) {
            return jsonObject;
        }
        
        if (filterFromTop) {
            tempCount = 0;
            for (i = 0, ii = jsonObject.item.length; i < ii; i++) {
                if (jsonObject.item[i].filter === true) {
                    tempCount++;
                    if (tempCount > recordCount) {
                        jsonObject.item[i].filter = false;
                    }
                }
            }
            
        }
        else {
            tempCount = 0;
            for (i = jsonObject.item.length - 1; i >= 0; i--) {
                if (jsonObject.item[i].filter === true) {
                    tempCount++;
                    if (tempCount > recordCount) {
                        jsonObject.item[i].filter = false;
                    }
                }
            }
        }
        
        return jsonObject;
    } 
    catch (ex) {
        //alert("countJson: " + ex);
    }
    
}

// formatDate - use XML dynamic content
// pass: date
// return: date formatted mm/dd/yy

function formatDate(date){
    try {
        var myDate = new Date(date);
        var myMonth = myDate.getMonth() + 1;
        if (myDate != "Invalid Date" && myMonth >= 1 && myMonth <= 12) {
            var myYear = myDate.getFullYear();
            myYear = myYear.toString().slice(2);
            var tempDate = myMonth + '\/' + myDate.getDate() + '\/' + myYear;
			return tempDate;
        } 
        else {
            return "No Date";
        }
    } 
    catch (ex) {
        //alert("formatDate: " + ex);
    }
}

function formatDateFullMonth(date){
    try {
		var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    	var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
        var myDate = new Date(date);
        var myMonth = myDate.getMonth() + 1;
        if (myDate != "Invalid Date" && myMonth >= 1 && myMonth <= 12) {
            var myYear = myDate.getFullYear();
            //myYear = myYear.toString().slice(2);
			//weekday[d.getDay()]
            var tempDate = monthname[myDate.getMonth()] + ' ' + myDate.getDate() + ', ' + myDate.getFullYear();
			return tempDate;
        } 
        else {
            return "No Date";
        }
    } 
    catch (ex) {
        //alert("formatDate: " + ex);
    }
}

// onlyOnePerDate - use XML dynamic content
// pass: JSON object, primary category, secondary category
// modifies 'filter' object to JSON with false if date matches between primary and secondary categories on secondary category item
// return: JSON object

function onlyOnePerDate(jsonObject, primarycat, secondarycat){
    try {
        for (var i = 0, ii = jsonObject.item.length; i < ii; i++) {
			if (jsonObject.item[i].filter && (jsonObject.item[i].category === primarycat) && jsonObject.item[i].pubDate) {
                var primaryDate = new Date(jsonObject.item[i].pubDate);
                var primaryDay = primaryDate.getDate();
                var primaryMonth = primaryDate.getMonth();
                var primaryYear = primaryDate.getFullYear();
				for (var j = 0, jj = jsonObject.item.length; j < jj; j++) {
					if (jsonObject.item[j].filter && (jsonObject.item[j].category === secondarycat) && jsonObject.item[j].pubDate) {
                        var secondaryDate = new Date(jsonObject.item[j].pubDate);
                        var secondaryDay = secondaryDate.getDate();
                        var secondaryMonth = secondaryDate.getMonth();
                        var secondaryYear = secondaryDate.getFullYear();
						if ((primaryDay === secondaryDay) && (primaryMonth === secondaryMonth) && (primaryYear === secondaryYear)) {
                            jsonObject.item[j].filter = false;
                        }
                    }
                }
                
            }
        }
        return jsonObject;
    } 
    catch (ex) {
        //alert("filterDates: " + ex);
    }
}

// xmlData - use XML dynamic content
// pass: URL of XML, Start Date, End Date, descending(true/false), count(-#, 0, +#)
// return: JSON object with all matching 'item' objects sorted by pubDate and 'item.filter'(true/false)
// this.each(if item.filter == true) output to <div>

function xmlData(file, start, end, sort, count, category){
    try {
        var xmlJson = readXML(file);
        var rssJson = xmlJson.channel;
        var rssDates = filterDates(rssJson, start, end, category);
        var rssDatesSort = sortJson(rssDates, sort); // true is descending, false is ascending
        var rssDatesSortCount = countJson(rssDatesSort, count); // (2) is records 0,1 of many; (-2) is records 5,6 of count(7 total);
        return rssDatesSortCount;
    } 
    catch (ex) {
        //alert("xmlData: " + ex);
    }
}

function xmlCombo(sort, count, json1, json2, json3, json4, json5){
    try {
        var j = 0;
		var i, ii;
        var mergeJson = {};
        mergeJson.item = [];
        if (json1) {
            for (i = 0, ii = json1.item.length; i < ii; i++) {
                if (json1.item[i].filter) {
                    mergeJson.item[j++] = json1.item[i];
                }
            }
        }
        if (json2) {
            for (i = 0, ii = json2.item.length; i < ii; i++) {
                if (json2.item[i].filter) {
                    mergeJson.item[j++] = json2.item[i];
                }
            }
        }
        if (json3) {
            for (i = 0, ii = json3.item.length; i < ii; i++) {
                if (json3.item[i].filter) {
                    mergeJson.item[j++] = json3.item[i];
                }
            }
        }
        if (json4) {
            for (i = 0, ii = json4.item.length; i < ii; i++) {
                if (json4.item[i].filter) {
                    mergeJson.item[j++] = json4.item[i];
                }
            }
        }
        if (json5) {
            for (i = 0, ii = json5.item.length; i < ii; i++) {
                if (json5.item[i].filter) {
                    mergeJson.item[j++] = json5.item[i];
                }
            }
        }
        if (sort === "nosort") {
			return mergeJson;
		} else {
			var jsonSort = sortJson(mergeJson, sort);
			var jsonSortCount = countJson(jsonSort, count); // (2) is records 0,1 of many; (-2) is records 5,6 of count(7 total);
        	return jsonSortCount;
		}
    } 
    catch (ex) {
        //alert("xmlCombo: " + ex);
    }
}

// buildSummaryTable - use XML dynamic content
// pass: JSON object with obj.filter (true/false) for display, sorted
// return: HTML string to display the table and rows <tr> small size summary format
function buildSummaryTable(jsonObj){
    try {
        var results = "";
        $.each(jsonObj.item, function(){
            if (this.filter) {
                if (this.pubDate && this.pubDate.alt) {
                    if (this.link && this.link.alt) {
                        results += '<tr><td class="date">' + this.pubDate.alt +
                        '</td><td>' +
                        this.title +
                        '<ul><li><a href="' +
                        this.link +
                        '" title="' + this.pubDate.alt + ' ' + this.link.alt + '">' +
                        this.link.alt +
                        '</a></li></ul>';
                        if (this.description.display == "true" || this.description.display == "summary") {
                            results += '<br>' + this.description;
                        }
                        results += '</td></tr>';
                    }
                    else {
                        if (this.link) {
                            results += '<tr><td class="date">' + this.pubDate.alt +
                            '</td><td><a href="' +
                            this.link +
                            '" title="' + this.pubDate.alt + ' ' + this.title + '">' +
                            this.title +
                            '</a>';
                            if (this.description.display == "true" || this.description.display == "summary") {
                                results += '<br>' + this.description;
                            }
                            results += '</td></tr>';
                        }
                        else {
                            results += '<tr><td class="date">' + this.pubDate.alt +
                            '</td><td>';
							if (this.description) {
								results += '<strong>' + this.title + '</strong>';
							} else {
								results += this.title;
							}
                            if (this.description.display == "true" || this.description.display == "summary") {
                                results += '<br>' + this.description;
                            }
                            results += '</td></tr>';
                        }
                    }
                }
                else {
                    if (this.link && this.link.alt) {
                        results += '<tr><td class="date">' + formatDate(this.pubDate) +
                        '</td><td>' +
                        this.title +
                        '<ul><li><a href="' +
                        this.link +
                        '" title="' + formatDateFullMonth(this.pubDate) + ' ' + this.link.alt + '">' +
                        this.link.alt +
                        '</a></li></ul>';
                        if (this.description.display == "true" || this.description.display == "summary") {
                            results += '<br>' + this.description;
                        }
                        results += '</td></tr>';
                    }
                    else {
                        if (this.link) {
                            results += '<tr><td class="date">' + formatDate(this.pubDate) +
                            '</td><td><a href="' +
                            this.link +
                            '" title="' + formatDateFullMonth(this.pubDate) + ' ' + this.title + '">' +
                            this.title +
                            '</a>';
                            if (this.description.display == "true" || this.description.display == "summary") {
                                results += '<br>' + this.description;
                            }
                        }
                        else {
                            results += '<tr><td class="date">' + formatDate(this.pubDate) +
                            '</td><td>';
							if (this.description) {
								results += '<strong>' + this.title + '</strong>';
							} else {
								results += this.title;
							}
                            if (this.description.display == "true" || this.description.display == "summary") {
                                results += '<br>' + this.description;
                            }
                        }
                        results += '</td></tr>';
                    }
                }
            }
        });
        if (results === "") {
            results = '<tr><td>Information will be posted when available.</td></tr>';
        }
        results = '<table><tbody class="xml"><tr class="hide"><th scope="col">Date</th><th scope="col">Title</th></tr>' + results + '</tbody></table>';
        return results;
    } 
    catch (ex) {
        //alert("buildSummaryRows: " + ex);
    }
}

// buildDescriptionTable - use XML dynamic content
// pass: JSON object with obj.filter (true/false) for display, sorted
// return: HTML string to display the table and rows <tr> that includes the obj.description, all data in jsonObject.item

function buildDescriptionTable(jsonObj){
    try {
        var results = "";
        $.each(jsonObj.item, function(){
            if (this.filter) {
                if (this.pubDate && this.pubDate.alt) {
                    if (this.link && this.link.alt) {
                        results += '<tr><td class="date">' + this.pubDate.alt + '</td><td>';
						results += '<strong>' + this.title + '</strong><br>';
						if (this.enclosure && this.enclosure.alt) {
                            results += '<img height="' + this.enclosure.height + '" width="' + this.enclosure.width + '" alt="' + this.enclosure.alt + '" src="' + this.enclosure.url + '" style="float:right; padding:5px 0 5px 5px;">';
                        }
                        if (this.description) {
                            results += this.description + '<br>';
                        }
                        else {
                            results += "&bull;&nbsp;";
                        }
                        if (this.link.delink == "description") {
                            results += '<strong>' + this.link.alt + '</strong>';
                        }
                        else {
                            results += '<a href="' + this.link + '" title="' + this.pubDate.alt + ' ' + this.link.alt + '">' + this.link.alt + '</a>';
                        }
                        results += '</td></tr>';
                    }
                    else {
                        results += '<tr><td class="date">' + this.pubDate.alt + '</td><td>';
                        if (this.link) {
                            if (this.link.delink == "description") {
                                if (this.description) {
									results += '<strong>' + this.title + '</strong><br>';
								} else {
									results += this.title + '<br>';
								}
                            }
                            else {
                                results += '<a href="' + this.link + '" title="' + this.pubDate.alt + ' ' + this.title + '">' + this.title + '</a><br>';
                            }
                        }
                        else {
                            if (this.description) {
								results += '<strong>' + this.title + '</strong><br>';
							} else {
								results += this.title + '<br>';
							}
                        }
                        if (this.enclosure && this.enclosure.alt) {
                            results += '<img height="' + this.enclosure.height + '" width="' + this.enclosure.width + '" alt="' + this.enclosure.alt + '" src="' + this.enclosure.url + '" style="float:right; padding:5px 0 5px 5px;">';
                        }
                        if (this.description) {
                            results += this.description;
                        }
                        results += '</td></tr>';
                    }
                }
                else {
                    if (this.link && this.link.alt) {
                        results += '<tr><td class="date">' + formatDate(this.pubDate) + '</td><td>';
						results += '<strong>' + this.title + '</strong><br>';
                        if (this.enclosure && this.enclosure.alt) {
                            results += '<img height="' + this.enclosure.height + '" width="' + this.enclosure.width + '" alt="' + this.enclosure.alt + '" src="' + this.enclosure.url + '" style="float:right; padding:5px 0 5px 5px;">';
                        }
                        if (this.description) {
                        
                            results += this.description + '<br>';
                        }
                        else {
                            results += "&bull;&nbsp;";
                        }
                        if (this.link.delink == "description") {
                            results += '<strong>' + this.link.alt + '</strong>';
                        }
                        else {
                            results += '<a href="' + this.link + '" title="' + formatDateFullMonth(this.pubDate) + ' ' + this.link.alt + '">' + this.link.alt + '</a>';
                        }
                        results += '</td></tr>';
                    }
                    else {
                        results += '<tr><td class="date">' + formatDate(this.pubDate) + '</td><td>';
                        if (this.link) {
                            if (this.link.delink == "description") {
                                if (this.description) {
									results += '<strong>' + this.title + '</strong><br>';
								} else {
									results += this.title + '<br>';
								}
                            }
                            else {
                                results += '<a href="' + this.link + '" title="' + formatDateFullMonth(this.pubDate) + ' ' + this.title + '">' + this.title + '</a><br>';
                            }
                        }
                        else {
                            if (this.description) {
								results += '<strong>' + this.title + '</strong><br>';
							} else {
								results += this.title + '<br>';
							}
                        }
                        if (this.enclosure && this.enclosure.alt) {
                            results += '<img height="' + this.enclosure.height + '" width="' + this.enclosure.width + '" alt="' + this.enclosure.alt + '" src="' + this.enclosure.url + '" style="float:right; padding:5px 0 5px 5px;">';
                        }
                        if (this.description) {
                        
                            results += this.description;
                        }
                        results += '</td></tr>';
                    }
                }
            }
        });
        if (results === "") {
            results = '<tr><td>Information will be posted when available.</td></tr>';
        }
        results = '<table><tbody class="xml"><tr class="hide"><th scope="col">Date</th><th scope="col">Title</th></tr>' + results + '</tbody></table>';
        return results;
    } 
    catch (ex) {
        //alert("buildDescriptionRows: " + ex);
    }
}

// buildListNoDate - use XML dynamic content
// pass: JSON object with obj.filter (true/false) for display, sorted
// return: HTML string to display the <ul><li> Clickable title going to link, and description if avaiable.
function buildListNoDate(jsonObj){
    try {
        var results = "";
        $.each(jsonObj.item, function(){
            if (this.filter) {
				results += '\t<li><a href="' + this.link + '">' + this.title + '</a>';
				if (this.description) {
                    results += '<br>' + this.description;
                }
				results += '</li>\n';
            }
        });
        if (results === "") {
            results = '<p>Information will be posted when available.</p>';
        } else {
			results = '<ul class="buildListNoDate">' + results + '</ul>';
		}
        return results;
    } 
    catch (ex) {
        //alert("buildSummaryRows: " + ex);
    }
}

// buildLinkDateUL - use XML dynamic content
// pass: JSON object with obj.filter (true/false) for display, sorted
// return: HTML string to display the <ul><li> Clickable Date based on Agenda and Meetings.
function buildLinkDateUL(jsonObj){
    try {
        var results = "";
        $.each(jsonObj.item, function(){
            if (this.filter) {
				var niceDate = formatDateFullMonth(this.pubDate);
				results += '\t<li><a href="' + this.link + '" title="' + niceDate + ' ' + this.title + '">' + niceDate + '</a>';
				if (this.description) {
                    results += '<br>' + this.description;
                }
				results += '</li>\n';
            }
        });
        if (results === "") {
            results = '<p>Information will be posted when available.</p>';
        } else {
			results = '<ul>' + results + '</ul>';
		}
        return results;
    } 
    catch (ex) {
        //alert("buildSummaryRows: " + ex);
    }
}

// buildLinkDateTitleUL - use XML dynamic content
// pass: JSON object with obj.filter (true/false) for display, sorted
// return: HTML string to display the <ul><li> Clickable Date based on Agenda and Meetings.
function buildLinkDateTitleUL(jsonObj){
    try {
        var results = "";
		var counter = 1;
        $.each(jsonObj.item, function(){
            if (this.filter) {
				var niceDate = formatDateFullMonth(this.pubDate);
				results += '\t<li';
				if(counter%2){
					results += ' class="alt"';
				}
				counter = counter + 1;
				results += '><a href="' + this.link + '">' + niceDate + ' ' + this.title + '</a>';
				if (this.description) {
                    results += '<br>' + this.description;
                }
				results += '</li>\n';
            }
        });
        if (results === "") {
            results = '<p>Information will be posted when available.</p>';
        } else {
			results = '<ul>' + results + '</ul>';
		}
        return results;
    } 
    catch (ex) {
        //alert("buildSummaryRows: " + ex);
    }
}

// buildCarousel - use XML dynamic content
// pass: JSON object with obj.filter (true/false) for display, sorted
// return: HTML string to display the carousel items div
function buildCarousel(jsonObj, path, category){
    try {
		if(path && category){
			var emergencyJson = xmlCombo('nosort', all, xmlData(path, past, future, desc, all, category));
			jsonObj = xmlCombo('nosort', all, emergencyJson, jsonObj);
			if (emergencyJson.item.length > 0) {
				jQuery.data(document, "emergency", {
					carouselPause: true
				});
			}
		}
        var count = 1;
        var results = "";
        $.each(jsonObj.item, function(){
            if (this.filter) {
                results += '\t<div id="tmpSlide-' + count + '" class="tmpSlide">' + 
				
                '\t\t<div class="tmpSlideCopy">\n' +
                '\t\t\t<h4>' +
                this.title +
                '</h4>\n' +
                '\t\t\t<p>' +
                this.description +
                '</p>\n';
                if (this.link) {
                    results += '\t\t\t<p><a href="' +
                    this.link +
                    '">' +
                    this.link.alt +
                    '</a></p>\n';
                }
                results += '\t\t</div>\n' +
                '\n\t\t<img src="' +
                this.enclosure.url +
                '" width="461" height="277" alt="' +
                this.enclosure.alt +
                '">\n' +
				'\t</div>\n';
                count++;
            }
        });
        results = '<div id="tmpSlideshow"><h2 class="hide">Featured Items</h2><h3 class="hide">Photo Carousel</h3>' + results + '</div>';
        return results;
    } 
    catch (ex) {
        //alert("buildCarousel: " + ex);
    }
}

function buildGallery(jsonObj){
    var lightboxdiv = document.createElement("div");
    lightboxdiv.setAttribute("id", "lightbox");
    var galleryul = document.createElement("ul");
    lightboxdiv.appendChild(galleryul);
    $.each(jsonObj.item, function(){
        var listitem = document.createElement("li");
        var mylink = document.createElement("a");
        mylink.setAttribute("href", this.link);
        mylink.setAttribute("title", this.title);
        var mythumb = document.createElement("img");
        mythumb.setAttribute("src", this.link);
        mythumb.style.width = 200;
        mythumb.style.height = 133;
        mythumb.setAttribute("alt", this.title);
        mylink.appendChild(mythumb);
        listitem.appendChild(mylink);
        var description = document.createTextNode(this.description);
        listitem.appendChild(description);
        galleryul.appendChild(listitem);
    });
    return lightboxdiv;
}

function putFileInHead(filename){
	var fileref;
    if (filename.match(".js")) { //if filename is a external JavaScript file
        fileref = document.createElement('script');
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", filename);
    }
    else 
        if (filename.match(".css")) { //if filename is an external CSS file
            fileref = document.createElement("link");
            fileref.setAttribute("rel", "stylesheet");
            fileref.setAttribute("type", "text/css");
            fileref.setAttribute("href", filename);
        }
    if (typeof fileref != "undefined") {
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}

function createCookie(name, value, mins){
    if (mins) {
        var date = new Date(); //not using server time - client cookie = client date
        date.setTime(date.getTime() + (mins * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else 
        var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name){
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') 
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) 
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name){
    createCookie(name, "", -1);
}

