var i, j, k, l, thisTrigger
fieldsToWatch = "#depcity, #arrcity";
outwardDateField = "#outwardDate";
returnDateField = "#returnDate";
targetMessage = "#msg";
today = new Date();
thisYear = today.getFullYear();
thisMonth = today.getMonth();
thisDay = today.getDay();
var endDate = new Date();
endDate.setDate(today.getDate() + 120);
var viewallConfig = {
"width":622,
"height":336
}
var displayCurrentLegend;
var messageOutbound
var messageInbound;
var viewall = $('<iframe src="/dynamic/stations.layer" width="'+viewallConfig.width+'" height="'+viewallConfig.height+'" frameborder="0" id="viewall"/>');
var viewallHotel = $('<iframe src="/dynamic/stations.layer.expedia" width="'+viewallConfig.width+'" height="'+viewallConfig.height+'" frameborder="0" id="viewall_hotel"/>');
function displayCurrentLegend(){
return displayCurrentLegend;
}
function messageInbound(){
return messageInbound;
}
function messageOutbound(){
return messageOutbound;
}
calendarDefaultOutwardConfig = {
"numberOfMonths": 2,
"mandatory": true,
"dateFormat": "dd/mm/yy",
"defaultDate": 0,
"minDate": today,
"maxDate": endDate,
"showOn": "both",
"buttonImage": "/dimg/icons/calendar_button.png",
"buttonImageOnly": true,
"currentText": "",
"beforeShowDay": directServiceDateOutward,
"displayLegend": displayCurrentLegend,
"messageId": messageOutbound
};
calendarDefaultReturnConfig = {
"numberOfMonths": 2,
"mandatory": true,
"dateFormat": "dd/mm/yy",
"defaultDate": 0,
"minDate": today,
"maxDate": endDate,
"showOn": "both",
"buttonImage": "/dimg/icons/calendar_button.png",
"buttonImageOnly": true,
"currentText": "",
"beforeShowDay": directServiceDateReturn,
"displayLegend": displayCurrentLegend,
"messageId": messageInbound
};
var matchedOD = new Object();
matchedOD.outwardDates = new Array;
matchedOD.returnDates = new Array;
matchedOD.outwardDates = [new Array];
matchedOD.returnDates = [new Array];
var bookingHorizon = null;
var bookingHorizonData = null;
function directServiceDateOutward(date){
for (i = 0; i < matchedOD.outwardDates.length; i++) {
if ((date.getMonth() == (matchedOD.outwardDates[i][0] - 1)) && (date.getDate() == matchedOD.outwardDates[i][1])) {
return [true, 'ski_day'];
}
}
return [true, ''];
};
function directServiceDateReturn(date){
for (i = 0; i < matchedOD.returnDates.length; i++) {
if ((date.getMonth() == (matchedOD.returnDates[i][0] - 1)) && (date.getDate() == matchedOD.returnDates[i][1])) {
return [true, 'ski_day'];
}
}
return [true, ''];
};
function watchField()
{
if ($("#depcity").attr("value")) {
originFieldVal = $("#depcity").attr("value")
}
else {
originFieldVal = '';
}
if ($("#arrcity").attr("value")) {
destinationFieldVal = $("#arrcity").attr("value")
}
else {
destinationFieldVal = '';
}
if (dsm.OD.length == 0)
{
$(targetMessage).empty();
$(targetMessage).hide();
matchedOD.outwardDates = [[]];
matchedOD.returnDates = [[]];
displayCurrentLegend = false;
}
for (i = 0; i < dsm.OD.length; i++) {
if (dsm.OD[i].origin.toLowerCase() == originFieldVal.toLowerCase()) {
if ((dsm.OD[i].origin.toLowerCase() == originFieldVal.toLowerCase()) && (destinationFieldVal.toLowerCase() == dsm.OD[i].destination.toLowerCase()))
{
message = $(targetMessage).html();
if (message != dsm.OD[i].message) {
$(targetMessage).empty();
$(targetMessage).hide();
if (dsm.OD[i].message != "") {
$(targetMessage).append(dsm.OD[i].message);
viewall.fadeOut("fast");
$(targetMessage).show("fast");
}
}
matchedOD.outwardDates = dsm.OD[i].outwardDates;
if (dsm.OD[i].bookingHorizon != null)
{
bookingHorizonData = dsm.OD[i].bookingHorizon.split("/");
bookingHorizon = new Date(bookingHorizonData[0], bookingHorizonData[1], bookingHorizonData[2]);
};
if (dsm.OD[i].directServiceType == 'SKI') {
displayCurrentLegend = true;
messageOutbound = "directSkiOutboundMessage";
messageInbound = "directSkiInboundMessage";
}
else 
if (dsm.OD[i].directServiceType == 'AVIGNON') {
displayCurrentLegend = true;
messageOutbound = "directAvignonOutboundMessage";
messageInbound = "directAvignonInboundMessage";
}
else {
displayCurrentLegend = false;
};
matchedOD.returnDates = dsm.OD[i].returnDates;
if (bookingHorizon != null) 
changeHorizon(bookingHorizon);
break;
}
else {
$(targetMessage).empty()
$(targetMessage).hide();
matchedOD.outwardDates = [[]];
matchedOD.returnDates = [[]];
displayCurrentLegend = false;
if (bookingHorizon != null)
{
bookingHorizon = null;
bookingHorizonData = null; 
changeHorizon(calendarDefaultReturnConfig["maxDate"]); 
};
};
}
else {
$(targetMessage).empty();
$(targetMessage).hide();
matchedOD.outwardDates = [[]];
matchedOD.returnDates = [[]];
displayCurrentLegend = false;
if (bookingHorizon != null)
{
bookingHorizon = null;
bookingHorizonData = null;
changeHorizon(calendarDefaultReturnConfig["maxDate"]);
};
};
}
};
function changeHorizon(newHorizon)
{
if(!jQuery.browser.msie)
{
$(outwardDateField).datepicker("disable");
$(returnDateField).datepicker("disable");
}
$(returnDateField).datepicker("change", "maxDate", newHorizon);
$(outwardDateField).datepicker("change", "maxDate", newHorizon);
if(!jQuery.browser.msie)
{ 
$(outwardDateField).datepicker("enable");
$(returnDateField).datepicker("enable"); 
}
}
function viewAll(viewall, thisTrigger){
pos = $(thisTrigger).offset();
triggerHeight = $(thisTrigger).height() + 4;
viewall.css({
"top": pos.top + triggerHeight + "px",
"left": pos.left + "px",
"position": "absolute"
});
viewallHotel.css({
"top": pos.top + triggerHeight + "px",
"left": pos.left + "px",
"position": "absolute"
});
if (viewall.css("display") != "block") {
$("#datepicker_div").hide();
$("#home_col_2, #home_col_3").css({"opacity":0.7})
if ($("#hotel").attr("checked") || $("#car").attr("checked")) {
viewallHotel.fadeIn("fast");
}
else {
viewall.fadeIn("fast");
}
}
addCloseLink();
$("body").unbind("click focus");
$("body").bind("click focus", function(e){
if (e.target != thisTrigger) {
viewall.fadeOut("fast");
viewallHotel.fadeOut("fast")
$("#home_col_2, #home_col_3").css({"opacity":1})
}
})
};
function getTrigger(){
return thisTrigger;
}
function fadeFrame(){
watchField();
viewall.fadeOut("fast");
viewallHotel.fadeOut("fast")
$("#home_col_2, #home_col_3").css({"opacity":1})
}
function addCloseLink(){
frameContent = viewall.contents();
$("a#close", frameContent).one("click", function(){
viewall.fadeOut("fast");
$("#home_col_2, #home_col_3").css({"opacity":1})
return false;
})
frameContentHotel = viewallHotel.contents();
$("a#close", frameContentHotel).one("click", function(){
viewallHotel.fadeOut("fast");
$("#home_col_2, #home_col_3").css({"opacity":1})
return false;
})
}
$(document).ready(function() {
viewall.appendTo("body").hide();
viewallHotel.appendTo("body").hide();
$(targetMessage).hide();
$(outwardDateField).datepicker(calendarDefaultOutwardConfig).focus(function(){
viewall.fadeOut("fast")
});
$(returnDateField).datepicker(calendarDefaultReturnConfig).focus(function(){
viewall.fadeOut("fast")
});
watchField();
$("#adults,#children,#seniors,#youths,#NumAdult0,#NumAdult1,#NumAdult2,#NumChild0,#NumChild1,#NumChild2,#NumSenior0,#NumSenior1,#NumSenior2,#NumYouth0,#NumYouth1,#NumYouth2").plus_minus().numeric();
$("#depcity, #arrcity").bind("focus", function(){
thisTrigger = this;
viewAll(viewall, this)
$("viewAll").focus()
})
$("#viewallDepartureTowns").bind("click", function(){
$('#depcity').focus();
return false;
})
$("#viewallArrivalTowns").bind("click", function(){
$('#arrcity').focus();
return false;
})
$(fieldsToWatch).bind("keyup", function(){
watchField();
})
})
$(document).ready(function() {
$("#NumAdult1,#NumChild1,#NumSenior1,#NumYouth1,#NumAdult2,#NumChild2,#NumSenior2,#NumYouth2").attr({"disabled":"disabled"});
$("#room_2").click( function() {
$("#room_2")[0].checked ? toggleRoom2("enabled") : toggleRoom2("disabled");
} );
$("#room_3").click( function() {
$("#room_3")[0].checked ? toggleRoom3("enabled") : toggleRoom3("disabled");
} );
});
function toggleRoom2(status){
if(status === "disabled") {
$("#NumAdult1,#NumChild1,#NumSenior1,#NumYouth1").attr({"disabled":"disabled"});
} else {
$("#NumAdult1,#NumChild1,#NumSenior1,#NumYouth1").removeAttr("disabled");
} 
}
function toggleRoom3(status){
if(status === "disabled") {
$("#NumAdult2,#NumChild2,#NumSenior2,#NumYouth2").attr({"disabled":"disabled"});
} else {
$("#NumAdult2,#NumChild2,#NumSenior2,#NumYouth2").removeAttr("disabled");
} 
}
$(function(){
var objects = $("form th.listRooms input");
function toggleHighLight() {
objects.each(function() {
if ($(this).attr("checked")) {
$(this).parents("tr").removeClass("newRoom"); // on enlève le grisé sur la ligne
} 
else {
$(this).parents("tr").addClass("newRoom"); // on ajoute le grisé sur la ligne
}
})
}
objects.click(toggleHighLight);
toggleHighLight();
})
