/* 
 * Company : Holidayzone Pty Ltd Melbourne Australia
 * Created on :25/05/2010   4:01:46 PM
  
 */


// this will load checkin date picker in basic search part

$(function() {
		$("#checkin").datepicker(
                {

                    showOn: 'button',
                    buttonImage: 'http://www.bookdirect2save.com.au/property_template/images/cal.gif',
                    buttonImageOnly: true,
                    buttonText:"Calendar To Select Date",
                    duration: 'fast',
                    showAnim:'',
                    numberOfMonths: 1,
		    showButtonPanel: false,
                    maxDate: '+31D +14M',
                    minDate: 0,
                    dateFormat:'yy-mm-dd',
                    altField: '#checkin_month_year',
                    altFormat: 'yy-mm',
                    onClose: update_checkin

                }
            );
	});

  // this will load checkout date picker in basic search part
        $(function() {
		$("#checkout").datepicker(
                {

                    showOn: 'button',
                    buttonImage: 'http://www.bookdirect2save.com.au/property_template/images/cal.gif',
                    buttonImageOnly: true,
                    buttonText:"Calendar To Select Date",
                    duration: 'fast',
                    showAnim:'',
                    numberOfMonths: 1,
		    showButtonPanel: false,
                    maxDate: '+31D +14M',
                    minDate: 0,
                    dateFormat:'yy-mm-dd',
                    altField: '#checkout_month_year',
                    altFormat: 'yy-mm',
                    onClose: update_checkout

                }
            );
	});
        // This function will update checkin date and validate the checkin date in basic search part
function update_checkin(date) {
  // only take day part
    $('#checkin_day').val(date.substring(8));
     // clear all fields
    document.getElementById("checkin_day").className="";
    document.getElementById("checkin_month_year").className="";
    document.getElementById("checkout_day").className="";
    document.getElementById("checkout_month_year").className="";
    // clear all divs
    document.getElementById("error_checkin_day").style.display="none";
    document.getElementById("error_checkin_month_year").style.display="none";
    document.getElementById("error_checkout_day").style.display="none";
    document.getElementById("error_checkout_month_year").style.display="none";
    // get the checkin date
    var checkin_date=document.getElementById("checkin").value;
    // validate checkin date
    if(!check_checkin_date(checkin_date))
        {
                process_error("checkin_month_year:Checkin date cannot be in past.,checkin_day:");

        }

     else
         {
                            // var checkout_date=document.getElementById("checkout").value;
              //                // call update_calendar function to update checkout calendar.
                                update_calendar('checkout',"checkout_day",checkin_date,"nights");
//                if(check_dates(checkin_date,checkout_date))
//                {
//                    var nights=days_between(checkin_date,checkout_date);
//
//                   if(nights<120)
//                       {
//                          //  document.getElementById("nights").innerHTML=nights;
//                       }
//                       else
//                           {
//                              var info_string="Length of stay cannot be more than 120 nights.\nIf you want to book hotel for more than 120 nights then please contact the administrator.";
//                                       alert(info_string);
//                           }
//                }

         }

}
// This function will update checkout date and validate the checkout date in basic search part
function update_checkout(date) {
    $('#checkout_day').val(date.substring(8));
    // clear all fields
    document.getElementById("checkout_day").className="";
    document.getElementById("checkout_month_year").className="";
    // clear all divs
    document.getElementById("error_checkout_day").style.display="none";
    document.getElementById("error_checkout_month_year").style.display="none";

    var checkin_date=document.getElementById("checkin").value;
    var checkout_date=document.getElementById("checkout").value;
    if(check_dates(checkin_date,checkout_date))
    {
        // calculate nights.
        var nights=days_between(checkin_date,checkout_date);
          if(nights<120)
                       {
                            document.getElementById("nights").innerHTML=nights;
                       }
                       else
                           {
                           var info_string="Length of stay cannot be more than 120 nights.\nIf you want to book hotel for more than 120 nights then please contact the administrator.";
                                        alert(info_string);
                           }
    }
    else
        {
            process_error("checkout_month_year:Checkout date must be after checkin date.,checkout_day:");
        }
}

