function Calendar (myPay) {
// initialize the member variables for this instance
var state_elm = '';
var elm_num = '';
var special_state = '';
var update_prices = '';
var total_products = '';
var all_product_calendars_exist = true;
var calendars_exist = true;
var maximum_heights_set = false;
pay=myPay;
pay_tab = false;
// initialize the member function references
this.get_products=get_products;
this.get_price_breakdown=get_price_breakdown;
this.get_total_price_info=get_total_price_info;
//this.check_calendars_written=check_calendars_written;
this.display_calendars=display_calendars;
this.set_heights=set_heights;
this.select_calendar=select_calendar;
this.get_calendar=get_calendar;
this.get_calendar_body=get_calendar_body;
this.check_all_product_calendars_exist=check_all_product_calendars_exist;
this.check_calendars_exist=check_calendars_exist;
this.show_hide_product_select=show_hide_product_select;
this.display_calendar=display_calendar;
this.update_calendar=update_calendar;
this.set_select_to_default=set_select_to_default;
this.get_calendar_key=get_calendar_key;
this.update_price=update_price;
this.modify_availability=modify_availability;
this.reset_state=reset_state;
this.what_key=what_key;
function get_products() {
var newURL= 'http://www.rocklandsboulders.com/bookings/get_product_select';
jQuery.ajax ({
data: "",
type: "POST",
url: newURL,
success: function(data){
$('#calendar-div-left').prepend(data);
select_calendar('product_select');
}
})
}
function get_price_breakdown() {
var newURL= 'http://www.rocklandsboulders.com/bookings/get_price_breakdown';
jQuery.ajax ({
data: "",
type: "POST",
url: newURL,
success: function(data){
if ($('#cal-key-holder').attr('id') == 'cal-key-holder') {
$('#calendar-div-right').prepend(data);
}
else {
$('#calendar-div-right').append(data);
}
}
})
}
function get_total_price_info() {
maximum_heights_set = false;
var complete = false;
//$('#overlay').fadeIn("medium",function(){
//$('
').attr('id', 'booking_system_loader').attr('src', 'http://www.rocklandsboulders.com/images/booking_system_loader.gif').attr('style','left:525px;top:230px;position:absolute;z-index:100;').appendTo('#main-container');
var newURL= 'http://www.rocklandsboulders.com/bookings/get_total_price_info';
jQuery.ajax ({
data: "",
type: "POST",
url: newURL,
success: function(data){
//tabs
$('#tabs > ul').tabs();
$('#avail_link').focus();
$('#pay_link').click(function () {
pay=myPay;
pay.display_pay();
pay_tab = true;
});
$('#avail_link').click(function () {
pay_tab = false;
});
$('#details_link').click(function () {
pay_tab = false;
});
$('#price_link').click(function () {
pay_tab = false;
});
$('#contact_link').click(function () {
pay_tab = false;
});
data=data.split('&/&/&/&/&');
var total_price_info=data[data.length-1];
$('
').attr('id', 'all-calendar-info').appendTo('#fragment-1');
$('#all-calendar-info').prepend(total_price_info);
$('
').attr('id', 'calendar-div-left').attr('class', 'fl').appendTo('#all-calendar-info');
$('
').attr('id', 'calendar_holder').attr('class', 'holder').attr('style', 'margin-left:0;').appendTo('#calendar-div-left');
$('
').attr('id', 'calendars').attr('style', 'visibility:hidden;').appendTo('#calendar_holder');
$('
').attr('id', 'calendar-div-right').attr('class', 'fl').appendTo('#all-calendar-info');
total_products=data[0];
total_products=total_products.replace('total_products=','');
num_products=data[data.length-2];
num_products=num_products.replace('count_products=','')
get_products();
get_price_breakdown();
if (num_products == 0) {
$('#booking_system_loader').remove();
$('#tabs').fadeIn('slow');
}
else {
product_calendar_array=new Array();
for (var i=1; i<=num_products; i++) {
var product_details=data[i].split('&');
var product_id=product_details[0];
product_id=product_id.replace('product_id=','');
if ((product_details.length) > 2) {
for (var j=(product_details.length-1); j>0; j--) {
var item_id=product_details[j];
item_id=item_id.replace('item_id=','');
if (j==(product_details.length-1)) {
get_calendar(product_id, item_id);
}
else {
update_calendar(product_id, item_id);
}
}
}
else {
item_id=product_details[1];
item_id=item_id.replace('item_id=','');
get_calendar(product_id, item_id);
}
product_calendar_array.push(product_id);
}
if (i-1 == num_products) {
display_calendars(product_id, product_calendar_array)
}
}
}
})
//});
}
function display_calendars(product_id, product_calendar_array) {
var t=setInterval(function(){
if ($('#calendar_body_'+ product_id).children('td').length == 3) {
for (var c=0; c
overlay_height) {
$('#overlay').css('height', new_overlay_height);
}
//set fragment-1 height
if (new_fragment_1_height > fragment_1_height) {
$('#fragment-1').css('height', fragment_1_height);
}
//set calendar height
$('#calendars').css('height', calendars_height);
}
else {
//get height of calendar table
product_calendar_height=$('table.cal-header').css('height');
product_calendar_height=product_calendar_height.replace('px', '');
product_calendar_height=parseInt(product_calendar_height);
overlay_height=overlay_height+product_calendar_height;
fragment_1_height=fragment_1_height+product_calendar_height;
calendars_height=calendars_height+product_calendar_height;
//set overlay height
$('#overlay').css('height', overlay_height);
//set fragment-1 height
$('#fragment-1').css('height', fragment_1_height);
//set calendar height
$('#calendars').css('height', calendars_height);
}
if (check_all_product_calendars_exist()) {
maximum_heights_set = true;
}
}
}
function select_calendar(select_id) {
$('#'+select_id).unbind('change');
$('#'+select_id).change(function(){
var item_id="";
var product_id=$('#'+select_id).val();
if ($('#product-select-div').css('display') == 'block') {
if ($('#'+product_id).attr('id') != product_id) {
$('#product_select').fadeOut('fast', function () {
$('#product-select-status').html('loading...');
$('#product-select-status').fadeIn('fast', function () {
calendars_exist=check_calendars_exist();
get_calendar(product_id, item_id);
display_calendar(product_id, calendars_exist);
});
});
}
}
set_select_to_default(select_id, product_id);
});
}
function get_calendar(product_id, item_id) {
if ($('#'+product_id).attr('id')!= product_id) {
var newURL= 'http://www.rocklandsboulders.com/bookings/get_cal_head';
jQuery.ajax ({
data: "product_id="+product_id+"&item_id="+item_id+"",
type: "POST",
url: newURL,
success: function(data){
if ($('#cal-key').attr('id') != 'cal-key') {
get_calendar_key();
$('#calendars').append(data);
get_calendar_body(product_id, item_id);
}
else {
$('#calendars').append(data);
get_calendar_body(product_id, item_id);
}
}
})
}
}
function get_calendar_body(product_id, item_id) {
var newURL= 'http://www.rocklandsboulders.com/bookings/get_cal';
jQuery.ajax ({
data: "product_id="+product_id+"&item_id="+item_id+"&bookings_table=bookings_calendar",
type: "POST",
url: newURL,
success: function(data){
data=data.split('&/&/&/&/&');
var calendar=data[5];
var split_data=new Array();
for (var i=0; i').attr('id', 'cal-key-holder').attr('class', 'holder').appendTo('#calendar-div-right');
$('').attr('id', 'cal-key').appendTo('#cal-key-holder');
$('').attr('id', 'cal-key-head').appendTo('#cal-key');
$('').attr('id', 'cal-key_head_row').appendTo('#cal-key-head');
$('| ').attr('id', 'cal-key_head_cell').attr('class', 'cal-key').appendTo('#cal-key_head_row');
$('#cal-key_head_cell').html(' calendar key ');
$(' |
').attr('id', 'cal-key_body').appendTo('#cal-key');
$('').attr('id', 'cal-key_body_row').attr('class', 'cal-key').appendTo('#cal-key_body');
$('| ').attr('id', 'cal-key_table_cell').appendTo('#cal-key_body_row');
$('#cal-key_table_cell').html(' available ');
$(' |
').attr('id', 'cal-key_body_row_2').attr('class', 'cal-key').appendTo('#cal-key_body');
$('| ').attr('id', 'cal-key_table_cell_2').appendTo('#cal-key_body_row_2');
$('#cal-key_table_cell_2').html(' booked ');
$(' |
').attr('id', 'cal-key_body_row_3').attr('class', 'cal-key').appendTo('#cal-key_body');
$('| ').attr('id', 'cal-key_table_cell_3').appendTo('#cal-key_body_row_3');
$('#cal-key_table_cell_3').html(' temp booked by you ');
}
function update_price (product_id, product_name, item_id, item_name, price, total_price){
price=parseFloat(price);
price=price.toFixed(2);
$('#pb_product_'+product_id+'_item_'+item_id).html(''+item_name+': £'+price+'');
if (total_price != '') {
total_price=parseFloat(total_price);
total_price=total_price.toFixed(2);
$('#para_total_price').html('Your total price is now at £'+total_price+'');
$('#para_total_price').fadeIn('fast');
}
}
function modify_availability(product_id, id_item, date, the_num, e, temp_table_name){
//catch key press
var special_state="";
var the_key= what_key(e);
if (the_key!="ko") {
special_state=the_key;
}
if ($('#modify_'+date).attr('id') != 'modify_'+date+'') {
//set up ajax
$('#item_'+id_item+'_link_'+date).css('display', 'none');
$(' ').attr('id', 'modify_'+date+'').attr('src', 'http://www.rocklandsboulders.com/images/calendar-loader.gif').attr('alt','loading').appendTo('#item_'+id_item+'_row_'+date+'');
var newURL= 'http://www.rocklandsboulders.com/bookings/update_cal';
jQuery.ajax ({
data: "product_id="+product_id+"&id_item="+id_item+"&the_date="+date+"&temp_table_name="+temp_table_name,
type: "POST",
url: newURL,
success: function(data){
data=data.split('&/&/&/&/&');
var split_data=new Array();
for (var i=0; i |