
$(document).ready(function(){
$('#inlineCal').datepicker({
closeAtTop: false, 
mandatory: true,
showOtherMonths: false, 
showStatus: false,
dayNamesMin: ['S','M','T','W','T','F','S'],
yearRange: '-0:+1',
minDate:'-7d',
maxDate: '14d', 
statusForDate: highlightToday,
onSelect: alertDate, // invoke alertDate function
onClose: function(date) { alert('Closed with ' + date); }
});
// Demonstrate the callback on select
function alertDate(date) {
var startDate = date;
//alert('The date is ' + date);
document.scheduleForm.action = "/schedule.jsp?startDate=" + startDate;
document.scheduleForm.submit();
}
// Demonstrate the callback for date status
function highlightToday(date, inst) {
var today = new Date();
today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
return $.datepicker.dateStatus(date, inst) +
(today.getTime() == date.getTime() ? ' (today)' : '');
}
});
function loadScheduleTab(startDate) {
/*
if (timzone == "" || timezone== null) {
timezone = 0;
} */
document.scheduleForm.action = "/schedule.jsp?startDate=" + startDate;
document.scheduleForm.submit();
}
function loadSchedule(startDate, timzone) {
//alert(startDate);
if (timzone == "" || timezone== null) {
timezone = 0;
}
document.scheduleForm.action = "/schedule.jsp?startDate=" + startDate ;
document.scheduleForm.submit();
}
/********************************************************
* function diffDates : returns difference two between dates as fraction ex. 1.0, 1.5, .49
*
* params : d1 date string in mm/dd/yyyy format (base date)
* d2 second date in mm/dd/yyyy format
* returns : difference in dates as number
*
********************************************************/
function diffDates(d1, d2)
{
//log.debug("Called diffDates with arg(s) d1 =" + d1 + " d2 =" + d2);
base_date = new Date(d1);
compare_date = new Date(d2);
diffXY = Math.round(base_date - compare_date)/86400000;
diffXYPrecision = diffXY.toPrecision(2);
//log.debug(Math.abs(diffXYPrecision));
return(diffXYPrecision);
}
function isValidDate(day, baseDay)
{
today = baseDay == null ? new Date() : new Date(baseDay);
schedule_date = new Date(day);
diffXY = Math.round(today - schedule_date)/86400000;
diffXYPrecision = diffXY.toPrecision(2);
todayAsString = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();
delta = diffDates(todayAsString,day);
lookBack = delta >=0 ? true : false;
lookForward = delta < 0 ?true : false;	
if(lookBack && Math.abs(delta) > 7 || lookForward && Math.abs(delta) > 14)
{
alert("Programming Schedule is only available for 1 week in the past or 2 weeks into the future.");
return false;
}
return true;
}
$(document).ready(function(){
//handle schedule Row selection 
$(".scheduleRow1").click(function () {
scheduleRowHandler(this);
});
$(".scheduleRow2").click(function () {
scheduleRowHandler(this);
});
function scheduleRowHandler(row) {
var linkId = $(row).attr("linkid");
var titleId = $(row).attr("titleid");
var titleType = $(row).attr("titletype");
var franchiseId = $(row).attr("franchiseId");
var descId = "#descr_" + linkId;
var previousDetail = $("#scheduleBdy2").attr("isopen");
var detail = $(row).children().filter('#details').find('#descr_'+ linkId).find("#detailContent");
var rowText = $(row).children().filter('#rowText');
var isOpen = $(descId).attr("isopen");
if ($(descId).attr("isopen") != "yes") {
$(descId).attr("isopen","yes" );
//get the detail info 
var detailLnk = "/schedule/schedule_details.jsp?titleId=" + titleId + "&titleType=" + titleType + "&franchiseId=" + franchiseId;
$(detail).load(detailLnk); 
$(descId).slideDown("slow");
//change the miniArrow
//$("#link_" + linkId).html("<a href='#' class='minischedarrow'>^</a>");
$(row).addClass("highlightRowBG");
$(rowText).addClass("highlightRow");
} else {
$(descId).attr("isopen","no");
$(descId).slideUp("slow");
$(row).removeClass("highlightRowBG");
$(rowText).removeClass("highlightRow");
}
}
function scheduleRowHandler2(row) {
$(".scheduleRowSelected").removeAttr("id");
//var link = $("scheduleRow1").attr("linkid");
var id = $(row).attr("id");
var linkId = $(row).attr("linkid");
var descId = "#descr_" + linkId;
var previousDetail = $("#scheduleBdy2").attr("isopen");
if (previousDetail == descId) {
if($(descId).is(":hidden")) {
$(descId).slideDown("slow");
$("#link_" + linkId).html("<a href='#' class='minischedarrow'>^</a>");
} else {
$(descId).slideUp("fast");
$("#link_" + linkId).html("<a href='#' class='minischedarrow'>>></a>");
}
} else {
//update the selected row to orange
$("#scheduleRowSelected").removeAttr("id");
//set the new selected row
$(row).attr("id","scheduleRowSelected");
// ***added the detail code here**** 
// $('#detailContent').load('schedule_details.jsp?titleId=330275');
if($(descId).is(":hidden")) {
//close the previously open detail
if(previousDetail != "empty" || previousDetail != "" || previousDetail == descId) {
if ($(previousDetail).not(":hidden")) {
$(previousDetail).slideUp("fast");
$("#link_" + linkId).html("<a href='#' class='minischedarrow'>>></a>");
}
}
$(descId).slideDown("slow");
//store the open detail in the schedulebdy div 
$("#scheduleBdy2").attr("isopen",descId );
//change the miniArrow
$("#link_" + linkId).html("<a href='#' class='minischedarrow'>^</a>");
}
}
}
$("#remindMe").click(function () {
var titleId = $("#remindMe").attr("titleId"); 
var slot = $("#remindMe").attr("slot");
launchRemindMe(titleId, slot);
return false;
});
function launchRemindMe(titleId, remindMeDate) {
window.open("/processors/remindme_v2.jsp?titleId=" + titleId + "&slot=" + remindMeDate + ",'reminder','width=230,height=350,resizable=no,scrollbars=yes,status=no,menubar=no'");
//return false;
}
function showDescriptionJquery(id) {
$("#link_" + id).click(function () {
if($("div.details_" + id).is(":hidden")) {
$("div.details_" + id).slideDown("slow");
} else {
$("div.details_" + id).slideUp("slow");
}
return false;
});
}
});

