			var firstDate = new Date();
var lastDate = new Date();
var cmeventOffset = 1000 * 60 * 60 * (4); // offset + dst
var cmOffsetHour = 0; // 5 - 1; // offset + dst
var flmonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var weekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
/* make the initial ajax request */
//function initComment() 
//{
// commentAjax.makeRequest('GET', initComment, commentList, true);
$(document).ready(function() {
$.ajax({
url: initComment,
type: 'GET',
dataType: 'xml',
timeout: 15000,
error: function(){
alert('An error has occured, please reload the page.');
},
success: function(xml){
commentList(xml);
}
});
//}
});
function commentList(xmlDoc)
{
var commentHTML = "";
//if(commentAjax.checkReadyState() == "success") {
// var xmlDoc = commentAjax.request.responseXML;
// get status
var statusNodes = xmlDoc.getElementsByTagName("status");
var status = statusNodes[0].childNodes[0].nodeValue;
// if status = success
if (status == "Success")
{					
// set the count
var countNode = xmlDoc.getElementsByTagName("count");
var count = 0;
if (countNode.length > 0)
{
count = countNode[0].childNodes[0].nodeValue;
}
// get comment node
var commentNodes = xmlDoc.getElementsByTagName("comment");
// loop through and set the comments div comments
for (i=0;i<commentNodes.length;i++) {
commentData = commentNodes.item(i).childNodes;
commentCell = '';
cdate = '';
name = '';
state = '';
country = '';
subject = '';
body = '';
for (var j=0; j<commentData.length; j++){
switch(commentData.item(j).nodeName){
case "date": cdate = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
default:break;
}
}
if (cdate != "")
{
// parse the xml date
firstDate.setTime(cdate);
// set the time to midnight
// firstDate.setHours(0,0,0);
// format the date by users locale
//console.debug(firstDate.toLocaleString());
//console.debug(firstDate.toUTCString());
}
}
// now get the latest comment
// commentAjax.makeRequest('GET', lastComment, lastCommentList, true);
$.ajax({
url: lastComment,
type: 'GET',
dataType: 'xml',
timeout: 15000,
error: function(){
alert('An error has occured, please reload the page.');
},
success: function(xml){
lastCommentList(xml);
}
});
}
// }
}
function lastCommentList(xmlDoc)
{
var commentHTML = "";
//if(commentAjax.checkReadyState() == "success") {
// var xmlDoc = commentAjax.request.responseXML;
// get status
var statusNodes = xmlDoc.getElementsByTagName("status");
var status = statusNodes[0].childNodes[0].nodeValue;
// if status = success
if (status == "Success")
{					
// set the count
var countNode = xmlDoc.getElementsByTagName("count");
var count = 0;
if (countNode.length > 0)
{
count = countNode[0].childNodes[0].nodeValue;
}
// get comment node
var commentNodes = xmlDoc.getElementsByTagName("comment");
// loop through and set the comments div comments
for (i=0;i<commentNodes.length;i++) {
commentData = commentNodes.item(i).childNodes;
commentCell = '';
cdate = '';
name = '';
state = '';
country = '';
subject = '';
body = '';
for (var j=0; j<commentData.length; j++){
switch(commentData.item(j).nodeName){
case "date": cdate = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
default:break;
}
}
if (cdate != "")
{
// parse the xml cdate
lastDate.setTime(cdate);
// set the time to midnight
// lastDate.setHours(0,0,0);
// format the cdate by users locale
//console.debug(lastDate.toLocaleString());
//console.debug(lastDate.toUTCString());
}
}
// now build the option list
buildOptionList()
// populate today's comments
loadComments();
}
// }
}
function buildOptionList()
{
var dateOptionList = document.getElementById("dateList");
if (dateOptionList != null)
{
// apply the offset to the firstdate and set the time to midnight
var tempDate = new Date(firstDate.getTime());
// set the time to midnight
tempDate.setUTCHours(0);
tempDate.setUTCMinutes(0);
tempDate.setUTCSeconds(1);
//console.debug(tempDate.toUTCString());
// create a new date w/ the offset
var startDate = tempDate;
// get the millis
var startMillis = startDate.getTime() + cmeventOffset;
//console.debug(startMillis);
// set the end date to +1 day
var endDate = new Date((lastDate.getTime()));
endDate.setUTCHours(23);
endDate.setUTCMinutes(59);
endDate.setUTCSeconds(59);
//console.debug(endDate.toUTCString());
// add a day
var endMillis = endDate.getTime() + cmeventOffset; //(1000 * 60 * 60 * 24) + 
//console.debug(endMillis);
var newDate = startMillis;
// alert(startDate + "-" + endDate);
// create an array
var dateOptionArray = new Array();
while (endMillis > newDate)
{
var optionDate = new Date();
optionDate.setTime(newDate + cmeventOffset);
// add items to the array
var optionText = weekdays[optionDate.getUTCDay()]+", " + optionDate.getUTCDate() + " " +flmonths[optionDate.getUTCMonth()]+ ", " + optionDate.getUTCFullYear();
var optionsArray = [optionText,(newDate)]
dateOptionArray.push(optionsArray);
newDate += 86400000;
}
// set first option item
dateOptionList.options[0] = new Option('Latest Comments','');
var optionCnt = 1;
// reverse through array to build option list
for (x = (dateOptionArray.length -1); x >= 0 ; x--)
{
dateOptionList.options[optionCnt] = new Option(dateOptionArray[x][0],dateOptionArray[x][1]);
optionCnt++;
}
}
}
function dayCommentRequest(dateform)
{
var datelist = document.getElementById(dateform);
if (datelist != null && datelist.selectedIndex != 0)
{
var day = datelist[datelist.selectedIndex].value;
// alert(new Date(eval(day)));
var datetxt = datelist[datelist.selectedIndex].text;
// set the date header
document.getElementById("fanTitle").innerHTML = '<h1 class="blueText3">Fanbook<br/>'+datetxt+'</h1>';
var interval = 86400000; // millis in a day
var number = "";
if (maxComments > 0)
{
number = "&n="+maxComments;
}
var commentURI = "/eipatron/discussionThread.do?c="+pageId+"&order=DESC&start="+day+"&interval="+interval+number;
// document.getElementById("comments").innerHTML = commentURI;
// commentAjax.makeRequest('GET', commentURI, getCommentList, true);
$.ajax({
url: commentURI,
type: 'GET',
dataType: 'xml',
timeout: 15000,
error: function(){
alert('An error has occured, please reload the page.');
},
success: function(xml){
getCommentList(xml);
}
});
} else {
loadComments();
}
}
function moreCommentRequest(tstamp)
{
//alert(tstamp)
// TO DO: 
//				set header based on this date
//				get millis since midnight and 
//				subtract this from interval			
var moreDate = new Date();
if (tstamp != null && tstamp != "")
{
moreDate.setTime(tstamp);
}
else 
{
return;
}
// set this date to midnight (local time)
moreDate.setHours(cmOffsetHour,0,0);
document.getElementById("fanTitle").innerHTML = '<h1 class="blueText3">Fanbook<br/>'+weekdays[moreDate.getUTCDay()]+' '+ moreDate.getUTCDate() +' '+flmonths[moreDate.getUTCMonth()]+', '+ moreDate.getUTCFullYear()+'</h1>';
var midnightOffset = tstamp - moreDate.getTime();
var interval = 86400000 - midnightOffset; // figure out how to subtract time from tstamp comment to end of day
var number = "";
if (maxComments > 0)
{
number = "&n="+maxComments;
}
var commentURI = "/eipatron/discussionThread.do?c="+pageId+"&order=DESC&start="+tstamp+"&interval="+interval+number;
// commentAjax.makeRequest('GET', commentURI, getCommentList, true);
$.ajax({
url: commentURI,
type: 'GET',
dataType: 'xml',
timeout: 15000,
error: function(){
alert('An error has occured, please reload the page.');
},
success: function(xml){
getCommentList(xml);
}
});
}
function loadComments()
{
var currentDate = new Date(lastDate.getTime());
currentDate.setHours(1,0,1); // set the time to midnight + offset (+1hr)
// var currentDateStr = "Latest Comments"
var currentDateStr = weekdays[currentDate.getUTCDay()]+", " + currentDate.getUTCDate() + " "+flmonths[currentDate.getUTCMonth()]+ ", " + currentDate.getUTCFullYear();
// set the date header
document.getElementById("fanTitle").innerHTML = '<h1 class="blueText3">Fanbook Latest Comments<br/>'+currentDateStr+'</h1>';
var id = "mast_fanbook";
var interval = 86400000; // millis in a day
var number = "&n=100";
if (maxComments > 0)
{
number = "&n="+maxComments;
}
var commentURI = latestComments + "?c="+pageId+"&order=DESC&start="+(currentDate.getTime())+"&interval="+interval+number;
//document.getElementById("comments").innerHTML = commentURI;
// commentAjax.makeRequest('GET', commentURI, getCommentList, true);
$.ajax({
url: commentURI,
type: 'GET',
dataType: 'xml',
timeout: 15000,
error: function(){
alert('An error has occured, please reload the page.');
},
success: function(xml){
getCommentList(xml);
}
});			 
}
function getCommentList(xmlDoc)
{
var commentHTML = "";
// if(commentAjax.checkReadyState() == "success") {
//	var xmlDoc = commentAjax.request.responseXML;
// var txtDoc = commentAjax.request.responseText;
// var xmlDoc = convertMS(txtDoc);
// get status
var statusNodes = xmlDoc.getElementsByTagName("status");
var status = "";
try
{
status = statusNodes[0].childNodes[0].nodeValue;
}
catch(err)
{
alert(err);
return;					
}
// if status = success
if (status == "Success")
{					
// set the count
var countNode = xmlDoc.getElementsByTagName("count");
var count = 0;
if (countNode.length > 0)
{
count = countNode[0].childNodes[0].nodeValue;
}
if (count == 0)
{
// Set the comment count
// commentCount(count);
commentHTML += "<p>No commments available for today.</p>";
}
// get comment node
var commentNodes = xmlDoc.getElementsByTagName("comment");
var commentLength = maxComments -1;
// determine if we need to page
if (commentNodes.length < maxComments || maxComments == 0)
{
commentLength = commentNodes.length;
}
// loop through and set the comments div comments
for (i=0;i<commentLength;i++) {
commentData = commentNodes.item(i).childNodes;
commentCell = '';
cdate = '';
name = '';
state = '';
country = '';
subject = '';
body = '';
for (var j=0; j<commentData.length; j++){
switch(commentData.item(j).nodeName){
case "name": name = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "subject": subject = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "country": country = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "date": cdate = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
// case "state": state = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
case "body": body = commentData.item(j).hasChildNodes() ? commentData.item(j).firstChild.nodeValue : ""; break;
default:break;
}
}
if (i % 2) 
{
commentHTML += "<div class='even'>";
} 
else
{
commentHTML += "<div class='odd'>";
}
if (body != "")
commentHTML += body;
commentHTML += "<div class='fanInfo'>";
if (name != "")
{
commentHTML += "Posted by " + name + "<br/>";
//if (state != "")
//	commentHTML += ", " + state;
if (country != "")
commentHTML += country + "<br/>";
}
if (cdate != "")
{
// create a date object
var d = new Date();
// parse the xml date
d.setTime((eval(cdate) - cmeventOffset));
// format the time
var hour = d.getUTCHours();
var hour_pad = "";
if (hour < 10)
{
hour_pad = "0";
}
var min = d.getUTCMinutes();
var min_pad = "";
if (min < 10)
{
min_pad = "0";
}
commentHTML += hour_pad + hour + ":" + min_pad + min;
}
//if (subject != "")
//	commentHTML += "<b>Re:" + subject + "</b><br/>";
//commentHTML += "<div class='cpostinfo'>"; 		 	
//commentHTML += "</div>";
commentHTML += "</div></div>";
}
// alert(commentHTML);
/*if (count >= maxComments && maxComments > 0)
{
commentHTML += "<p align='right'>";
var timeStamp = "";
var moreCommentData = commentNodes.item(maxComments -1).childNodes;
for (var j=0; j<moreCommentData.length; j++){
switch(moreCommentData.item(j).nodeName){
case "date": timeStamp = moreCommentData.item(j).hasChildNodes() ? moreCommentData.item(j).firstChild.nodeValue : ""; break;
default:break;
}
}
commentHTML += "<a href='javascript:moreCommentRequest("+timeStamp+")'>More Comments...</a>";
commentHTML += "</p>";
}*/
if (count > 0)
{
commentHTML += "<p align='right' style='margin-right: 40px;'><a href='#'><img src='/images/misc/mas_ms_060000_backtotop.gif' width='81' height='15' border='0' alt='Back to Top'/></a></p>";
}
commentsDiv = document.getElementById('comments');
commentsDiv.innerHTML = commentHTML;
}
// }
}
// addLoadEvent(initComment);
