
var rsrEnabled = true;
var rsrLang,rsrCountry,rsrTrans,rsrLoad;
String.prototype.trim = function() {return this.replace(/^[\s]+|[\s]+$/gi,'');};
function rsrGetMonth(month){
return (typeof refSMonth !== 'undefined')?refSMonth[month-1]:month;
}
function rsrGetTranslations(){

var translations = {};
$('input','#rsr_translations').each(function(i,element){
if(element.value !== 'undefined'){
translations[element.name.slice(4)] = element.value;
}else{
translations[element.name.slice(4)] = '';
}
});
return translations;
}
function rsr_set_cookie(name,value,days,cookie) {

var str,
local = window.localStorage,
date = new Date(),
expiry;
if (local && cookie !== true) {

local[name] = value;
}
else {

if (typeof days === 'number') {
date.setDate(date.getDate() + days);
expiry = date.toUTCString();
str = name.trim() +'='+ value.trim() +'; expires='+ expiry +'; path=/';
document.cookie = str;
return str;
}
else {
str = name.trim() +'='+ value.trim() +'; path=/';
document.cookie = str;
return str;
}
}
}
function rsr_get_cookie(wanted_cookie, cookie) {

var i=0,
local = window.localStorage,
full_string = document.cookie,
tmp_array,
name,
val,
tmp,
begin;
if (local && cookie !== true) {
return local[wanted_cookie];
}
else {
if (full_string !== '' && typeof full_string !== 'undefined') {
tmp_array = full_string.split(';');
for (i;i<tmp_array.length;i+=1) {
tmp = tmp_array[i];
begin = tmp.indexOf('=');
name = tmp.substr(0,begin).trim();
val = tmp.substr(begin+1).trim();
if (name === wanted_cookie) {return val;}
}
}
}
return false;
}
function rsr_delete_cookie(wanted_cookie, cookie) {

var local = window.localStorage;
if (local && cookie !== true) {
if (local[wanted_cookie] !== null) {
local.removeItem(wanted_cookie);
return true;
}
else {return false;}
}
else {
rsr_set_cookie(wanted_cookie,'',-1,cookie);
return true;
}
}
function rsr_convert_date(unix,locale) {

var conversion;
if (typeof unix === 'undefined' || typeof locale === 'undefined') {return false;}
else {
conversion = new Date((unix*1000));
if (locale !== 'us') {return conversion.getDate() +'/'+ (conversion.getMonth()+1) +'/'+ (conversion.getFullYear()-2000);}
else {return (conversion.getMonth()+1) +'/'+ conversion.getDate() +'/'+ (conversion.getFullYear()-2000);}
}
}
function rsr_month_to_number(str) {

var i,rex;
if (typeof str !== 'undefined') {
rex = new RegExp(str,'i');
for (i=0;i<=11;i+=1) {
if (rex.test(refSMonth[i])) {return i;}
}
}
return false;
}
function rsr_parse_string(cookie_string) {

var i = 0,
tmp_all,
tmp_details,
tmp_flights,
tmp_segments,
tmp_flight_details,
tmp_flight_date,
tmp_options,
journey_details = [],
count = 0;
if (typeof cookie_string !== 'undefined' || cookie_string !== null) {
tmp_all = (cookie_string.indexOf('||') !== false) ? cookie_string.split('||') : [cookie_string];




for (i=0;i<tmp_all.length;i+=1) {
journey_details[count] = {};
tmp_details = tmp_all[i].split('&&');
tmp_options = tmp_details.pop().split(',');
if (tmp_options.length !== 4) {return false;}
else {
journey_details[count].options = {};
journey_details[count].options.adults = tmp_options[0];
journey_details[count].options.children = tmp_options[1];
journey_details[count].options.infants = tmp_options[2];
journey_details[count].options.cabin = tmp_options[3];
}
if (tmp_details.length > 0) {
tmp_flights = [];

tmp_segments = tmp_details[0].split(':');
tmp_flight_details = tmp_segments[0].split(',');
journey_details[count].outbound = {};
journey_details[count].outbound.reference = tmp_flight_details[0];
journey_details[count].outbound.depart = {};
journey_details[count].outbound.depart.code = tmp_flight_details[1];
journey_details[count].outbound.depart.name = tmp_flight_details[2];
tmp_flight_date = tmp_flight_details[3].split('@');
journey_details[count].outbound.depart.date = tmp_flight_date[0];
journey_details[count].outbound.depart.time = tmp_flight_date[1];
journey_details[count].outbound.depart.locale = tmp_flight_date[2];
tmp_flight_details = tmp_segments[1].split(',');
journey_details[count].outbound.arrival = {};
journey_details[count].outbound.arrival.code = tmp_flight_details[0];
journey_details[count].outbound.arrival.name = tmp_flight_details[1];
tmp_flight_date = tmp_flight_details[2].split('@');
journey_details[count].outbound.arrival.date = tmp_flight_date[0];
journey_details[count].outbound.arrival.time = tmp_flight_date[1];
journey_details[count].outbound.arrival.locale = tmp_flight_date[2];

if (tmp_details.length === 2) {
tmp_segments = tmp_details[1].split(':');
tmp_flight_details = tmp_segments[0].split(',');
journey_details[count].inbound = {};
journey_details[count].inbound.reference = tmp_flight_details[0];
journey_details[count].inbound.depart = {};
journey_details[count].inbound.depart.code = tmp_flight_details[1];
journey_details[count].inbound.depart.name = tmp_flight_details[2];
tmp_flight_date = tmp_flight_details[3].split('@');
journey_details[count].inbound.depart.date = tmp_flight_date[0];
journey_details[count].inbound.depart.time = tmp_flight_date[1];
journey_details[count].inbound.depart.locale = tmp_flight_date[2];
tmp_flight_details = tmp_segments[1].split(',');
journey_details[count].inbound.arrival = {};
journey_details[count].inbound.arrival.code = tmp_flight_details[0];
journey_details[count].inbound.arrival.name = tmp_flight_details[1];
tmp_flight_date = tmp_flight_details[2].split('@');
journey_details[count].inbound.arrival.date = tmp_flight_date[0];
journey_details[count].inbound.arrival.time = tmp_flight_date[1];
journey_details[count].inbound.arrival.locale = tmp_flight_date[2];
}
}
count += 1;
}
return journey_details;
}
else {return false;}
}
function rsr_rebuild_cookie(original) {

var i=0,
len = original.length,
final_string = '',
tmp_conditional = '',
tmp_string,
parent;
for (i=0;i<len;i+=1) {
parent = original[i];
tmp_string = '';
tmp_string += parent.outbound.reference +',';
tmp_string += parent.outbound.depart.code +','+ parent.outbound.depart.name +',';
tmp_string += parent.outbound.depart.date +'@'+ parent.outbound.depart.time +'@'+ parent.outbound.depart.locale;
tmp_string += ':';
tmp_string += parent.outbound.arrival.code +','+ parent.outbound.arrival.name +',';
tmp_string += parent.outbound.arrival.date +'@'+ parent.outbound.arrival.time +'@'+ parent.outbound.arrival.locale;
if (typeof parent.inbound !== 'undefined') {

tmp_string += '&&';
tmp_string += parent.inbound.reference +',';
tmp_string += parent.inbound.depart.code +','+ parent.inbound.depart.name +',';
tmp_string += parent.inbound.depart.date +'@'+ parent.inbound.depart.time +'@'+ parent.inbound.depart.locale;
tmp_string += ':';
tmp_string += parent.inbound.arrival.code +','+ parent.inbound.arrival.name +',';
tmp_string += parent.inbound.arrival.date +'@'+ parent.inbound.arrival.time +'@'+ parent.inbound.arrival.locale;
}
tmp_string += '&&';
tmp_string += parent.options.adults +','+ parent.options.children +','+ parent.options.infants +','+ parent.options.cabin;
tmp_conditional = (i !== (len-1)) ? '||' : '';
tmp_string += tmp_conditional;
final_string += tmp_string;
}
return final_string;
}
function rsr_unix_time(day,month,year) {

if (typeof day === 'undefined') {return false;}
else if (typeof month === 'undefined') {return false;}
else if (typeof year === 'undefined') {return false;}
return ~~((new Date(year,month,day).getTime())/1000);
}
function rsr_test_dates(flight,server) {

return (flight < server) ? false : true;
}
function rsrUpdateResultsCookie(){


var resultsCookie = rsr_get_cookie('RSR_RESULTS'),
tempCookie = rsr_get_cookie('RSR_TEMP'),
disabledCookie = rsr_get_cookie('RSR_DISABLED',true);
if(disabledCookie === '1'){

return false;
}
if((resultsCookie === false || resultsCookie === null || typeof resultsCookie === 'undefined') && (tempCookie === false || tempCookie === null || typeof tempCookie === 'undefined')){

return 'blank';
}

if(tempCookie !== false && tempCookie !== null && typeof tempCookie !== 'undefined'){
if(resultsCookie === 'empty' || resultsCookie === false || resultsCookie === null || typeof resultsCookie === 'undefined'){
resultsCookie = tempCookie;
}else{
resultsCookie = tempCookie + '||' + resultsCookie;
}
rsr_set_cookie('RSR_RESULTS',resultsCookie,365);
rsr_delete_cookie('RSR_TEMP');
}
return resultsCookie;
}
function rsr_get_page_data() {

var page = $('input[name="pageid"]', $('#t-page-info-fragment')).val(),
locale = $('input[name="country"]', $('#t-page-info-fragment')).val(),
tmp,
data,
parent = $('div#RSR', $('div#t-main-fragment')),
departure_city = $('input#rsr_DepartureCity', parent).val(),
departure_code = $('input#rsr_DepartureCode', parent).val(),
departure_date = $('input#rsr_DepartureDate', parent).val().split('-'),
arrival_city = $('input#rsr_DestinationCity', parent).val(),
arrival_code = $('input#rsr_DestinationCode', parent).val(),
return_date = $('input#rsr_ReturnDate', parent).val().split('-'),
cabin = $('input#rsr_Cabin', parent).val(),
adults = $('input#rsr_Adults', parent).val(),
children = $('input#rsr_Children', parent).val(),
infants = $('input#rsr_Infants', parent).val();
if (rsr_get_cookie('RSR_DISABLED',true) === '1') {return false;}
if (page === 'FSCALENDAR' || page === 'FSFLIGHTLIST' || page === 'FSCALENDARANDFLIGHTLIST') {

$('input#change', $('form#cys')).click(function() {
rsrUpdateResultsCookie();
});
data = '**,';
data += departure_code +','+ departure_city +',';
tmp = departure_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
data += ':';
data += arrival_code +','+ arrival_city +',';
data += '**@**@'+locale;
tmp = return_date;
if (tmp[0] !== '') {
data += '&&';
data += '**,';
data += arrival_code +','+ arrival_city +',';

tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
data += ':';
data += departure_code +','+ departure_city +',';
data += '**@**@'+locale;
}
data += '&&';
data += adults +','+ children +','+ infants +','+ cabin;
if (page === 'FSFLIGHTLIST' || page === 'FSCALENDARANDFLIGHTLIST') {

$('input#continue', 'form#flightList').add('#redContinueButtonFlightsDoNotMatch','#airportDoNotMatch').click(function() {
var outbound_selected = $('div.cjHolderSelected', 'div#obJourneys'),
inbound_selected = $('div.cjHolderSelected', 'div#ibJourneys'),
outbound_ffs_parent = $('div#outBoundFlightList'),
inbound_ffs_parent = $('div#inBoundFlightList'),
extractedDepart,
extractedArrive,
tmp_month_name_depart,
tmp_month_name_arrive,
tmp_month_num,
tmp_day_num,
tmp_depart_time,
tmp_depart_date_string,
tmp_arrival_date_sting,
tmp_arrival_time,
tmp_day_num_arrive,
tmp_depart_date,
tmp_flight_code,
extracted;
if (page === 'FSFLIGHTLIST') {

if (outbound_selected.length > 0) {
tmp_depart_time = outbound_selected.find('td.dep p');
tmp_arrival_time = outbound_selected.find('td.arr p');
tmp_flight_code = outbound_selected.find('td.oper p a.peripheralLink');
if (tmp_depart_time.length > 1) {
tmp_depart_time = outbound_selected.find('td.dep p strong').html();
tmp_arrival_time = outbound_selected.find('td.arr p strong').html();
tmp_flight_code = outbound_selected.find('td.oper:first p a.peripheralLink').html();
}
else {
if (tmp_depart_time.children('strong').length > 0) {tmp_depart_time = tmp_depart_time.children('strong').html();}
else {tmp_depart_time = tmp_depart_time.html();}
if (tmp_arrival_time.children('strong').length > 0) {tmp_arrival_time = tmp_arrival_time.children('strong').html();}
else {tmp_arrival_time = tmp_arrival_time.html();}
tmp_flight_code = tmp_flight_code.html();
}
}
else {
tmp_depart_time = '**';
tmp_arrival_time = '**';
tmp_flight_code = '**';
}
data = tmp_flight_code +',';
data += departure_code +','+ departure_city +',';
extracted = tmp_depart_time.split('&nbsp;');
tmp_month_num = rsr_month_to_number(extracted[3]);

if (tmp_month_num !== '') {
tmp = departure_date;
tmp = rsr_unix_time(extracted[2],tmp_month_num,tmp[0]);
data += tmp +'@'+ extracted[0].replace(':','-') +'@'+ locale;
}
else {
tmp = departure_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}

data += ':';
data += arrival_code +','+ arrival_city +',';

extracted = tmp_arrival_time.split('&nbsp;');
tmp_month_num = rsr_month_to_number(extracted[3]);

if (tmp_month_num !== '') {
tmp = departure_date;
tmp = rsr_unix_time(extracted[2],tmp_month_num,tmp[0]);
data += tmp +'@'+ extracted[0].replace(':','-') +'@'+ locale;
}
else {
tmp = departure_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}

if (return_date[0] !== '') {

data += '&&';
if (inbound_selected.length > 0) {
tmp_depart_time = inbound_selected.find('td.dep p');
tmp_arrival_time = inbound_selected.find('td.arr p');
tmp_flight_code = inbound_selected.find('td.oper p a.peripheralLink');
if (tmp_depart_time.length > 1) {
tmp_depart_time = inbound_selected.find('td.dep p strong').html();
tmp_arrival_time = inbound_selected.find('td.arr p strong').html();
tmp_flight_code = inbound_selected.find('td.oper:first p a.peripheralLink').html();
}
else {
if (tmp_depart_time.children('strong').length > 0) {tmp_depart_time = tmp_depart_time.children('strong').html();}
else {tmp_depart_time = tmp_depart_time.html();}
if (tmp_arrival_time.children('strong').length > 0) {tmp_arrival_time = tmp_arrival_time.children('strong').html();}
else {tmp_arrival_time = tmp_arrival_time.html();}
tmp_flight_code = tmp_flight_code.html();
}
}
else {
tmp_depart_time = '**';
tmp_arrival_time = '**';
tmp_flight_code = '**';
}

data += tmp_flight_code + ',';
data += arrival_code +','+ arrival_city +',';
extracted = tmp_depart_time.split('&nbsp;');
tmp_month_num = rsr_month_to_number(extracted[3]);


if (tmp_month_num !== '') {
tmp = return_date;
tmp = rsr_unix_time(extracted[2],tmp_month_num,tmp[0]);
data += tmp +'@'+ extracted[0].replace(':','-') +'@'+ locale;
}
else {
tmp = return_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}
data += ':';
data += departure_code +','+ departure_city +',';

extracted = tmp_arrival_time.split('&nbsp;');
tmp_month_num = rsr_month_to_number(extracted[3]);

if (tmp_month_num !== '') {
tmp = return_date;
tmp = rsr_unix_time(extracted[2],tmp_month_num,tmp[0]);
data += tmp +'@'+ extracted[0].replace(':','-') +'@'+ locale;
}
else {
tmp = return_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}
}
data += '&&';
data += adults +','+ children +','+ infants +','+ cabin;

} else if(page === 'FSCALENDARANDFLIGHTLIST') {
outbound_selected = $('td.selected', outbound_ffs_parent);
inbound_selected = $('td.inSelected', inbound_ffs_parent);

departure_date = $('tr:first span.FlightData span.depDate', '#outboundDates').html();
departure_date = ['20'+departure_date.slice(4,6),departure_date.slice(2,4),departure_date.slice(0,2)];
if(return_date[0] !== '' ){
return_date = $('tr:first span.FlightData span.depDate', '#inboundDates').html();
return_date = ['20'+return_date.slice(4,6),return_date.slice(2,4),return_date.slice(0,2)];
}



if (outbound_selected.length > 0) {
tmp_depart_time = outbound_selected.eq(0).find('span.time').html().trim();
tmp_depart_date_string = outbound_selected.eq(0).find('span.date').html().trim();
tmp_depart_date = outbound_selected.eq(2).find('span.FlightData span.depDate').html();
tmp_arrival_time = outbound_selected.eq(1).find('span.time').html().trim();
tmp_arrival_date_sting = outbound_selected.eq(1).find('span.date').html().trim();
tmp_flight_code = outbound_selected.eq(2).find('span.FlightData span.Carrier').html() + outbound_selected.eq(2).find('span.FlightData span.FlightNumber').html();
}
else {
tmp_depart_time = '**';
tmp_arrival_time = '**';
tmp_flight_code = '**';
}

data = tmp_flight_code +',';
data += departure_code +','+ departure_city +',';
extractedDepart = tmp_depart_date_string.split(' ');
tmp_month_name_depart = extractedDepart[1];
tmp_month_num = Number(tmp_depart_date.slice(2,4));
tmp_day_num = Number(tmp_depart_date.slice(0,2));



if (tmp_month_num !== '') {
tmp = departure_date;
tmp = rsr_unix_time(tmp_day_num,tmp_month_num-1,tmp[0]);

data += tmp +'@'+ tmp_depart_time.replace(':','-') +'@'+ locale;
}
else {
tmp = departure_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}

data += ':';
data += arrival_code +','+ arrival_city +',';

extractedArrive = tmp_arrival_date_sting.split(' ');
tmp_day_num_arrive = extractedArrive[0];
tmp_month_name_arrive = extractedArrive[1];



if (tmp_day_num_arrive !== '') {

if(tmp_month_name_depart !== tmp_month_name_arrive) {
if(tmp_day_num_arrive > tmp_day_num){

tmp_month_num = tmp_month_num -1;
if(tmp_month_num === 0){
tmp_month_num = 12;
}
}else{

tmp_month_num = tmp_month_num +1;
if(tmp_month_num === 13){
tmp_month_num = 1;
}
}
}

tmp = departure_date;
tmp = rsr_unix_time(tmp_day_num_arrive,tmp_month_num-1,tmp[0]);

data += tmp +'@'+ tmp_arrival_time.replace(':','-') +'@'+ locale;
}
else {
tmp = departure_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}


if (return_date[0] !== '') {
data += '&&';
if (inbound_selected.length > 0) {
tmp_depart_time = inbound_selected.eq(0).find('span.time').html().trim();
tmp_depart_date_string = inbound_selected.eq(0).find('span.date').html().trim();
tmp_depart_date = inbound_selected.eq(2).find('span.FlightData span.depDate').html();
tmp_arrival_time = inbound_selected.eq(1).find('span.time').html().trim();
tmp_arrival_date_sting = inbound_selected.eq(1).find('span.date').html().trim();
tmp_flight_code = inbound_selected.eq(1).find('span.FlightData span.Carrier').html() + inbound_selected.eq(2).find('span.FlightData span.FlightNumber').html();
}
else {
tmp_depart_time = '**';
tmp_arrival_time = '**';
tmp_flight_code = '**';
}


data += tmp_flight_code +',';
data += arrival_code +','+ arrival_city +',';
extractedDepart = tmp_depart_date_string.split(' ');
tmp_month_name_depart = extractedDepart[1];
tmp_month_num = Number(tmp_depart_date.slice(2,4));
tmp_day_num = Number(tmp_depart_date.slice(0,2));



if (tmp_month_num !== '') {
tmp = return_date;
tmp = rsr_unix_time(tmp_day_num,tmp_month_num-1,tmp[0]);

data += tmp +'@'+ tmp_depart_time.replace(':','-') +'@'+ locale;
}
else {
tmp = return_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}

data += ':';
data += departure_code +','+ departure_city +',';

extractedArrive = tmp_arrival_date_sting.split(' ');
tmp_day_num_arrive = extractedArrive[0];
tmp_month_name_arrive = extractedArrive[1];



if (tmp_month_num !== '') {

if(tmp_month_name_depart !== tmp_month_name_arrive) {
if(tmp_day_num_arrive > tmp_day_num){

tmp_month_num = tmp_month_num -1;
if(tmp_month_num === 0){
tmp_month_num = 12;
}
}else{

tmp_month_num = tmp_month_num +1;
if(tmp_month_num === 13){
tmp_month_num = 1;
}
}
}
tmp = return_date;
tmp = rsr_unix_time(tmp_day_num_arrive,tmp_month_num-1,tmp[0]);

data += tmp +'@'+ tmp_arrival_time.replace(':','-') +'@'+ locale;
}
else {
tmp = return_date;
tmp = rsr_unix_time(tmp[2],Number(tmp[1])-1,tmp[0]);
data += tmp + '@**@'+locale;
}
}
data += '&&';
data += adults +','+ children +','+ infants +','+ cabin;
}
rsr_set_cookie('RSR_TEMP',data,365);
return data;
});

}
rsr_set_cookie('RSR_TEMP',data,365);
return data;
}
return false;
}
function rsrFormatTime(time){

return time.split('-').join(':');
}
function rsrFormatDate(unix){

var date, dateParts;
date = rsr_convert_date(unix,rsrCountry);
dateParts = date.split('/');
if(rsrCountry !== 'us'){
dateParts[1] = rsrGetMonth(dateParts[1]);
}else{
dateParts[0] = rsrGetMonth(dateParts[0]);
}
dateParts[2] = '20'+ dateParts[2];
return dateParts.join(' ');
}
function rsrCloseAll() {

$('.rsrPopup', '#rsr_container').hide();
$('.rsrInfoActive', '#rsr_container').removeClass('rsrInfoActive');
$('.rsr', '#rsr_container').removeClass('rsrActive');
$('html').unbind('click.rsr');
}
function rsrRemoveFlight(rsrToDeleteNum){

var cookie = rsr_parse_string(rsr_get_cookie('RSR_RESULTS'));
cookie.splice(rsrToDeleteNum,1);
rsr_set_cookie('RSR_RESULTS',rsr_rebuild_cookie(cookie),365);
}
function rsrFlightTimeValid(data){

var rsrUnixServerDateTime = new Date(rsrTrans.server_time),
rsrUnixServerDate;
rsrUnixServerDate = rsr_unix_time(rsrUnixServerDateTime.getDate(),rsrUnixServerDateTime.getMonth(),rsrUnixServerDateTime.getFullYear());
return (data.outbound.depart.date === rsrUnixServerDate)? false : rsr_test_dates(data.outbound.depart.date,rsrUnixServerDate);
}
function rsrIsDuplicate(resultsToPrint,index){

var x,
tmp = resultsToPrint.slice(),
current = tmp[index];
tmp[index] = false;
for(x in tmp){
if (typeof tmp[x] !== 'undefined' && tmp[x] !== false) {
if(tmp[x].hash === current.hash){
if(tmp[x].type ==='full' && current.type ==='basic'){

return true;
}else if(tmp[x].type ==='basic' && current.type ==='full'){

return x;
}else{

return true;
}
}
}
}
return false;
}
function rsrAddRsr(rsrData){

var rsrHaveTimes = true,
rsrReturn = true,
rsrPaxMixArray =[],
rsrPaxMix,
rsrUrl,
rsrTable,
rsrDiv;
if(rsrData.outbound.depart.time === '**'){rsrHaveTimes = false;}
if(typeof rsrData.inbound === 'undefined'){rsrReturn = false;}
if(rsrData.options.adults !== '0'){rsrPaxMixArray.push(rsrData.options.adults + ((rsrData.options.adults >1)?' '+ rsrTrans.adults:' '+ rsrTrans.adult));}
if(rsrData.options.children !== '0'){rsrPaxMixArray.push(rsrData.options.children + ((rsrData.options.children >1)?' '+ rsrTrans.children:' '+ rsrTrans.child));}
if(rsrData.options.infants !== '0'){rsrPaxMixArray.push(rsrData.options.infants + ((rsrData.options.infants >1)?' '+ rsrTrans.infants:' '+ rsrTrans.infant));}
rsrPaxMix = rsrPaxMixArray.join(' - ');
rsrUrl = '/main/fx?source=rsrHomepage&eId=111009&ad='+ rsrData.options.adults +'&ch='+ rsrData.options.children +'&inf='+ rsrData.options.infants +'&cabin='+ rsrData.options.cabin +'&to='+ ((rsrData.outbound.arrival.code.length === 6)? rsrData.outbound.arrival.code.substr(3,3) : rsrData.outbound.arrival.code) +'&from='+ ((rsrData.outbound.depart.code.length === 6)? rsrData.outbound.depart.code.substr(3,3) :rsrData.outbound.depart.code) +'&depDate='+ rsr_convert_date(rsrData.outbound.depart.date,rsrCountry);
if(rsrReturn === true){
if(rsrHaveTimes === true){
rsrTable = '<tr><td colspan="3" class="rsrRoute">'+ rsrData.outbound.depart.name +' - '+ rsrData.outbound.arrival.name +'</td></tr><tr><td rowspan="2" class="rsrPlaneOut"></td><td class="rsrPart">'+ rsrTrans.departs +'</td><td class="rsrTime">'+ rsrFormatTime(rsrData.outbound.depart.time) +' - '+ rsrFormatDate(rsrData.outbound.depart.date) +'</td></tr><tr class="rsrLine"><td class="rsrPart">'+ rsrTrans.arrives +'</td><td class="rsrTime">'+ rsrFormatTime(rsrData.outbound.arrival.time) +' - '+ rsrFormatDate(rsrData.outbound.arrival.date) +'</td></tr><tr><td colspan="3" class="rsrRoute">'+ rsrData.inbound.depart.name +' - '+ rsrData.inbound.arrival.name +'</td></tr><tr><td rowspan="2" class="rsrPlaneIn"></td><td class="rsrPart">'+ rsrTrans.departs +'</td><td class="rsrTime">'+ rsrFormatTime(rsrData.inbound.depart.time) +' - '+ rsrFormatDate(rsrData.inbound.depart.date) +'</td></tr><tr class="rsrLine"><td class="rsrPart">'+ rsrTrans.arrives +'</td><td class="rsrTime">'+ rsrFormatTime(rsrData.inbound.arrival.time) +' - '+ rsrFormatDate(rsrData.inbound.arrival.date) +'</td></tr><tr><td></td><td colspan="2" class="rsrPax">'+ rsrPaxMix +'</td></tr><tr class="rsrLine"><td></td><td colspan="2">'+ rsrTrans[rsrData.options.cabin] +'</td></tr>';
rsrUrl += '&retDate='+ rsr_convert_date(rsrData.inbound.depart.date, rsrCountry) +'&myDatesAreFixedSelected=true';
}else{
rsrTable = '<tr><td colspan="3" class="rsrRoute">'+ rsrData.outbound.depart.name +' - '+ rsrData.outbound.arrival.name +'</td></tr><tr class="rsrLine"><td class="rsrPlaneOut"></td><td class="rsrPart">'+ rsrTrans.departs +'</td><td>'+ rsrFormatDate(rsrData.outbound.depart.date) +'</td></tr><td colspan="3" class="rsrRoute">'+ rsrData.inbound.depart.name +' - '+ rsrData.inbound.arrival.name +'</td></tr><tr class="rsrLine"><td class="rsrPlaneIn"></td><td class="rsrPart">'+ rsrTrans.departs +'</td><td>'+ rsrFormatDate(rsrData.inbound.depart.date) +'</td></tr><tr><td></td><td colspan="2" class="rsrPax">'+ rsrPaxMix +'</td></tr><tr class="rsrLine"><td></td><td colspan="2">'+ rsrTrans[rsrData.options.cabin] +'</td></tr>';
rsrUrl += '&retDate='+ rsr_convert_date(rsrData.inbound.depart.date, rsrCountry);
}
}else{
if(rsrHaveTimes === true){
rsrTable = '<tr><td colspan="3" class="rsrRoute">'+ rsrData.outbound.depart.name +' - '+ rsrData.outbound.arrival.name +'</td></tr><tr><td rowspan="2" class="rsrPlaneOut"></td><td class="rsrPart">'+ rsrTrans.departs +'</td><td class="rsrTime">'+ rsrFormatTime(rsrData.outbound.depart.time) +' - '+ rsrFormatDate(rsrData.outbound.depart.date) +'</td></tr><tr class="rsrLine"><td class="rsrPart">'+ rsrTrans.arrives +'</td><td class="rsrTime">'+ rsrFormatTime(rsrData.outbound.arrival.time) +' - '+ rsrFormatDate(rsrData.outbound.arrival.date) +'</td></tr><tr><td></td><td colspan="2" class="rsrPax">'+ rsrPaxMix +'</td></tr><tr class="rsrLine"><td></td><td colspan="2">'+ rsrTrans[rsrData.options.cabin] +'</td></tr>';
rsrUrl += '&myDatesAreFixedSelected=true';
}else{
rsrTable = '<tr><td colspan="3" class="rsrRoute">'+ rsrData.outbound.depart.name +' - '+ rsrData.outbound.arrival.name +'</td></tr><tr class="rsrLine"><td class="rsrPlaneOut"></td><td class="rsrPart">'+ rsrTrans.departs +'</td><td>'+ rsrFormatDate(rsrData.outbound.depart.date) +'</td></tr><tr><td></td><td colspan="2" class="rsrPax">'+ rsrPaxMix +'</td></tr><tr class="rsrLine"><td></td><td colspan="2">'+ rsrTrans[rsrData.options.cabin] +'</td></tr>';
}
}
rsrDiv = '<div class="rsr"><div class="rsrIcons"><a href="#" title="'+ rsrTrans.detailsAltTag+'" class="rsrInfo">&nbsp;</a><a href="#" title="'+ rsrTrans.clearAltTag+'" class="rsrDelete">&nbsp;</a><div class="rsrPopup"><div class="rsrPopupBg"><div class="rsrPopupInner"><span class="rsrClose"></span><h4>'+ rsrTrans.searchDetails +'</h4><table><tbody>' + rsrTable + '</tbody></table><div class="button secondary rsrSearch"><a href="'+ rsrUrl +'">'+ rsrTrans.search +'</a></div><div class="clearBoth"></div></div></div><div class="rsrPopupBottom">&nbsp;</div></div></div><a class="tertiaryLink rsrSearch" href="'+ rsrUrl +'">'+ rsrData.outbound.depart.name +' - '+ rsrData.outbound.arrival.name +'</a>';
if(rsrReturn === true){
return rsrDiv + '<p>'+ rsrFormatDate(rsrData.outbound.depart.date) +' - '+ rsrFormatDate(rsrData.inbound.depart.date) +' </p></div>';
}else{
return rsrDiv + '<p>'+ rsrFormatDate(rsrData.outbound.depart.date) +'</p></div>';
}
}
function rsrShowClearModal(type){

var pHeight;
if(type === 'clear'){
$('span.rsrQuestion','#rsrClearModal').text(rsrTrans.clearQuestion);
}else{
$('span.rsrQuestion','#rsrClearModal').text(rsrTrans.disableQuestion);
}
$('#rsrClearModal').fadeIn(700);
if($('#rsrClearAll').length === 0){
$('p','#rsrClearModal').css({'padding-top':0});

pHeight = $('#rsrClearModal p').height();
if(($('#rsrButtonsArea').height() -3) < pHeight){
$('#rsrButtonsArea').css({'height':pHeight});
}
}

$('#rsrClearYes').click(function (event){
event.preventDefault();
if(type === 'clear'){
rsr_set_cookie('RSR_RESULTS','empty',365);
$('#rsr_container').empty();
rsrLoad();
}else{
rsr_delete_cookie('RSR_RESULTS');
rsr_delete_cookie('RSR_TEMP');
rsr_set_cookie('RSR_DISABLED','1',365, true);
$('#rsr_container').empty();
rsrLoad();
}
});
}
function rsrShowDeleteModal(rsr){

var divHeight, divWidth;
$('.rsrDeleteModal','#rsr_container').hide();
if($('.rsrDeleteModal', rsr).length > 0){
$('.rsrDeleteModal',rsr).fadeIn(700);
}else{
$(rsr).css('cursor','default');
divHeight = rsr.innerHeight() - 4;
divWidth = rsr.innerWidth() - 3;
rsr.append('<div class="rsrDeleteModal" style="display:none;width:'+ divWidth +'px;height:'+ divHeight +'px;"><p>'+ rsrTrans.deleteQuestion +' <span class="nobreak"><a href="#" class="rsrDeleteYes">'+ rsrTrans.yes +'</a> <a href="#" class="rsrDeleteNo">'+ rsrTrans.no +'</a></span></p></div>');
$('.rsrDeleteModal',rsr).fadeIn(700);
}

$('.rsrDeleteNo',rsr).click(function (event){
event.preventDefault();
$('.rsrDeleteModal','#rsr_container').fadeOut(700);
});
$('.rsrDeleteYes',rsr).click(function (event){
event.preventDefault();
rsrRemoveFlight($(rsr).prevAll('.rsr').length);
$(rsr).remove();

if($('.rsr','#rsr_container').length < 1){
rsr_set_cookie('RSR_RESULTS','empty',365);
$('#rsr_container').empty();
rsrLoad();
}else{

$('.rsr','#rsr_container').addClass('x').removeClass('x');
}
});
}
rsrLoad = function(){

var disabled = rsr_get_cookie('RSR_DISABLED', true),
resultsCookie = rsrUpdateResultsCookie(),
rsrHtml = '',
data,
count = 0,
x,
i ,
rsrButtonsArea,
isDuplicate,
printed = [],
resultsToPrint = [];
rsrLang = $('input[name="language"]', '#t-page-info-fragment').val();
rsrCountry = $('input[name="country"]', '#t-page-info-fragment').val();
rsrTrans = rsrGetTranslations();
if(resultsCookie === 'blank'){
return false;
}

rsrHtml += '<h3>'+ rsrTrans.title +'</h3>';
if(disabled === '1'){

rsrHtml += '<div class="hr">&nbsp;</div><div id="rsrButtonsArea"><a href="#" class="tertiaryLink" id="rsrEnable">'+ rsrTrans.enableButton +'</a><div class="clearBoth"></div></div>';
}else if(resultsCookie !== 'empty'){

data = rsr_parse_string(resultsCookie);
for(i=0;i<data.length;i++){

if(rsrFlightTimeValid(data[i]) === true){

resultsToPrint[count] = {};
resultsToPrint[count].data = data[i];
resultsToPrint[count].type = ((data[i].outbound.depart.time === '**')? 'basic' : 'full');
resultsToPrint[count].hash = data[i].options.cabin + data[i].options.adults + data[i].options.children + data[i].options.infants + data[i].outbound.depart.code + data[i].outbound.depart.date +data[i].outbound.arrival.code;
if(typeof data[i].inbound !== 'undefined'){
resultsToPrint[count].hash += data[i].inbound.depart.code + data[i].inbound.depart.date +data[i].inbound.arrival.code;
}
isDuplicate = rsrIsDuplicate(resultsToPrint,count);
if(isDuplicate === false){
count = count+1;
}else if(isDuplicate !== true){

resultsToPrint[isDuplicate] = resultsToPrint[count];
}
}
}


if(count > 0){
for(x=0;x<count;x++){
if(resultsToPrint[x] !== 'null'){

resultsToPrint[x].content = rsrAddRsr(resultsToPrint[x].data);
printed[x] = resultsToPrint[x].data;
}

if(printed.length === 5){
break;
}
}

rsr_set_cookie('RSR_RESULTS',rsr_rebuild_cookie(printed),365);

for(x=0;x<count;x++){
if(typeof resultsToPrint[x].content !== 'undefined'){

rsrHtml += resultsToPrint[x].content;
}
}
rsrHtml += '<span id="rsr_bottom_image"></span><div class="hr">&nbsp;</div><div id="rsrButtonsArea"><div id="rsrClearModal" style="display:none;"><p><span class="rsrQuestion">&nbsp;</span> <span class="nobreak"><a href="#" id="rsrClearYes">'+ rsrTrans.yes +'</a> <a href="#" id="rsrClearNo">'+ rsrTrans.no +'</a></span></p></div>';
rsrHtml += '<div id="rsrClearAll" class="button secondary"><span>'+ rsrTrans.clearButton +'</span></div><div class="clearBoth"></div>';
rsrHtml += '<a href="#" class="tertiaryLink" id="rsrDisable">'+ rsrTrans.disableButton +'</a><div class="clearBoth"></div></div>';
}else{

rsr_set_cookie('RSR_RESULTS','empty',365);
resultsCookie = 'empty';
}
}
if(resultsCookie === 'empty'){

rsrHtml += '<p id="rsrEmptyMessage">'+ rsrTrans.emptyNotice +'</p><div class="hr">&nbsp;</div><div id="rsrButtonsArea"><div id="rsrClearModal" style="display:none;"><p><span class="rsrQuestion">&nbsp;</span> <span class="nobreak"><a href="#" id="rsrClearYes">'+ rsrTrans.yes +'</a> <a href="#" id="rsrClearNo">'+ rsrTrans.no +'</a></span></p></div><a href="#" class="tertiaryLink" id="rsrDisable">'+ rsrTrans.disableButton +'</a><div class="clearBoth"></div></div>';
}
if($('#rsr_container').length>0){

$('#planTripBody').css('backgroundPosition','left top');

$('#rsr_container').prepend(rsrHtml).show();
if(resultsCookie === 'empty'){
$('#rsrClearYes').addClass('disable');
}

rsrButtonsArea = $('#rsrButtonsArea');
$('#rsrClearModal').height(rsrButtonsArea.height() -3).width(rsrButtonsArea.width() -2);

$('.rsrDelete', '#rsr_container').hover(function (){
$(this).addClass('rsrDeleteHover');
}, function (){
$(this).removeClass('rsrDeleteHover');
});
$('.rsrInfo', '#rsr_container').hover(function (){
$(this).addClass('rsrInfoHover');
}, function (){
$(this).removeClass('rsrInfoHover');
});
$('.rsrInfo', '#rsr_container').click(function (event){
event.preventDefault();
var popup, rsr, alreadyOpen;
popup = $(this).siblings('.rsrPopup');
alreadyOpen = $(popup).is(':visible');
$('.rsrDeleteModal','#rsr_container').remove();
rsrCloseAll();
if(alreadyOpen === false){
$(this).addClass('rsrInfoActive');
rsr = $(this).closest('.rsr');
$(rsr).addClass('rsrActive');
popup.show();
$('html').bind('click.rsr',function (event){
if ($(event.target).closest('.rsrPopup').length === 0 && !$(event.target).hasClass('rsrInfo')){
rsrCloseAll();
}
});
}
});
$('.rsrDelete', '#rsr_container').click(function (event){
event.preventDefault();
var rsr = $(this).closest('.rsr');
rsrShowDeleteModal(rsr);
});
$('.rsrClose', '#rsr_container').click(function (){
rsrCloseAll();
});
$('#rsrClearAll').click(function (){
rsrShowClearModal('clear');
});
$('#rsrDisable').click(function (event){
event.preventDefault();
rsrShowClearModal('disable');
});
$('#rsrEnable').click(function (event){
event.preventDefault();
rsr_delete_cookie('RSR_DISABLED',true);
rsr_set_cookie('RSR_RESULTS','empty',365);
$('#rsr_container').empty();
rsrLoad();
});
$('#rsrClearNo').click(function (event){
event.preventDefault();
$('#rsrClearModal').fadeOut(700);
$('#rsrButtonsArea').css({'height':'auto'});
});
}
};
if(rsrEnabled === true){
$(document).ready(function (){

if($('input[name="pageid"]', '#t-page-info-fragment').val() === 'HOME'){
rsrLoad();
}else if($('input[name="pageid"]', '#t-page-info-fragment').val() === 'PLANTRIP'){
rsrUpdateResultsCookie();
}else if($('input[name="pageid"]', '#t-page-info-fragment').val() === 'COMPJRNY'){
rsrUpdateResultsCookie();
}else{
rsr_get_page_data();
}
});
}
