var current_from;
var current_to;
var current_group;
var sel_adj_count = 0;

//module events
function modeventPriceGroupCount(group_count)
{
  var o;
//alert("group count : "+group_count);
if(group_count == 1)
{
 o = document.getElementById('display_second_segment');
 o.style.display = 'none';
}
else
if(group_count == 2)
{
 o = document.getElementById('display_second_segment');
 o.style.display = '';

}//if
}//func

function modeventNewSelection(group,from,to)
{ // User selected a new range from the cal.
 var o;
 
  to = to - (24*60*60); // adjust so last moment is last night stay (cal returns last moment as checkout day)

 //notifiy availability module
 res_availability_Set(from,to,group);
 res_booking_details_SetView(from,to,group);

 current_group = group;
 current_from = from;
 current_to = to;
 
 sel_adj_count++;
// alert(sel_adj_count);
 if(sel_adj_count == 3)
  {
    checkAvailability();
  }
}//func:


function modeventUpdateGrandTotal(grand_total)
{ // User selected a new range from the cal.
 var o;

 o = document.getElementById('OrderTotal');
 o.value = grand_total;
}//func:

/////////////////////

function zold2006_10_06_checkout()
{
   var o;
   var a = new Array();


   set_status_text(checkout_button_processing_html);

   //load params 'a'
   a = get_form_fields();
   
  
   
   pos_transaction(a);
}//func:



function checkout()
{
var o;
o = document.getElementById('extra_form_fields');
o.innerHTML =
 "<input type=hidden name='from' value ="+current_from+">"+
 "<input type=hidden name='to' value ="+current_to+">"+
 "<input type=hidden name='group' value ="+current_group+">"+
 "";
document.form_guest_details.submit();
}


function setRoomType(type)
{
   calavail_view_setRoomType(type);
}//function


function init()
{ var o;
  o = document.getElementById('guest_info');
  o.style.display = 'none';
  
 // o = document.getElementById('this_room_type');
 
  setRoomType(this_room_type); // should be set on room page layout.
}


function checkAvailability()
{
  var o;

  o = document.getElementById('availability_div');
  o.style.display = "";


  o = document.getElementById('continue_to_availability_check_button');
  o.style.display = 'none';
  

}

function continue_to_guest_info()
{//show the guest info page.
  var o;
  o = document.getElementById('guest_info');
  o.style.display = '';
  
  o = document.getElementById('continue_to_guest_info_button');
  o.style.display = 'none';
  
  o = document.getElementById('FirstName');
  o.focus();
}

function close_guest_info()
{//show the guest info page.
  var o;
  o = document.getElementById('guest_info');
  o.style.display = 'none';
}


function set_status_text(t)
{
  var o;
  o = document.getElementById('checkout_button');
  o.innerHTML = t;
}



//module events
//[ 2.ab ]
function event_transaction_error(fail_type,fail_reason)
{
  var o;

  if(fail_type = "validation")
  {
     o = document.getElementById("messages");
     o.innerHTML = fail_reason;

     set_status_text(checkout_button_try_again_html);
  }
  else
     alert("transaction failed: "+fail_type+" "+fail_reason);
}

//[ 2.ab ]
function event_transaction_ok(tr_id)
{ //This transaction cleared... make a guest account.
  var o;

   //remember the transaction id
   //transaction_id = tr_id;
   

   //alert("Creating Account.");

    var a = new Array();

    o = document.getElementById('FirstName');
    a['FirstName'] = o.value;
    o = document.getElementById('LastName');
    a['LastName'] = o.value;

    a['name'] = a['FirstName']+" "+a['LastName'];

    o = document.getElementById('Email');
    a['email'] = o.value;
    a['notes'] = "";
    a['transaction_id'] = tr_id;
    reservation_system_guests_CreateAccount(a);
}//func:


//[ 3.ab ]
function event_NewAccountCreated(guest_id)
{ //This guest account created... book room.

    //set_status_text("Booking Room... Please Wait.");

    //book
    reservation_system_RequestReservation(current_from, current_to, current_group, guest_id);

}//func:

//[ 4.ab ]
function event_BookingFailed()
{ //WIERD...didn't complete transaction... give warning


     o = document.getElementById("messages");
     o.innerHTML = "We could not book your room.  Please call for more information.";

    set_status_text("");


}//func:


//[ 4.ab ]
function event_BookingSuccess()
{ //transaction complete...goto thank you page.
var o;
o = document.getElementById('extra_form_fields');
o.innerHTML =
 "<input type=hidden name='from' value ="+current_from+">"+
 "<input type=hidden name='to' value ="+current_to+">"+
 "<input type=hidden name='group' value ="+current_group+">"+
 "";
document.form_guest_details.submit();

}//func:
