// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


$(document).ready(function($) {
	$("[id^='lrupdate_numberRooms']").each(function() {
		this.selectedIndex = 0;
	});

$().ajaxStart(function() {
	$('#ajaxgif').show();  	
}),

$('.lrupdate_roomdetails').hide(),
$('.lrupdate_cancellationdetails').hide(),
$('.lrupdate_hideroom').hide(),
$('.lrupdate_hidecancellation').hide(),
setDetailLinks(),

$().ajaxStop(function() {
$('#ajaxgif').fadeOut('slow');  	
}),


$('#hidden_overview').hide(),
$('a#hide_overview_p2').hide(),

$("a#show_overview_p2").click(function (e) { 
     //alert('here1');
     // stop normal link click
	e.preventDefault();
	$(this).hide();
	//$('#overview_text').hide();
    $('a#hide_overview_p2').show();
	$('#hidden_overview').show();
}),


$("a#hide_overview_p2").click(function (e) { 
     //alert('here2');
     // stop normal link click
     e.preventDefault();
     $(this).hide();
     $('#hidden_overview').hide();
     $('a#show_overview_p2').show();
     //$('#overview_text').show();
     
     /*
     $('#hidden_overview').slideUp(
	   function() {
	     $('#overview_text').slideDown("slow");
	   })*/
}),

$("#close").click(function (e) { 
     // stop normal link click
     e.preventDefault();
     $('#error_container').hide("fast");
     $('#greyedout').hide("fast");
}),

$(".lrupdate_room").click(function (e) { 
     // stop normal link click
     e.preventDefault();
     $(this).siblings().children('.lrupdate_cancellationdetails').slideUp("slow");
     $(this).siblings().children('.lrupdate_roomdetails').slideDown("slow");
}),
$(".lrupdate_room").click(function (e) { 
     // stop normal link click
     e.preventDefault();
     $(this).siblings().children('.lrupdate_cancellationdetails').slideUp("slow");
     $(this).siblings().children('.lrupdate_roomdetails').slideDown("slow");
}),

$(".lrupdate_cancellation").click(function (e) { 
     // stop normal link click
     e.preventDefault();
     $(this).siblings().children('.lrupdate_roomdetails').slideUp("slow");
     $(this).siblings().children('.lrupdate_cancellationdetails').slideDown("slow");
}),
	
$("#sdate").change(function(e){
     // stop normal link click
     $.get('/lrupdate_matrix.php', { method: 'get', dateChange: 'true', sdate: $('#sdate').val(), nights: $('#nights').val(), hotel_id: $('#lr_hotelID').val(), lang: $('#lr_lang').val(), cur: $('#selectedCurrency').val()}, function(response) {
     	$("#matrix").html(response)
        $('.lrupdate_roomdetails').hide()
        $('.lrupdate_cancellationdetails').hide()
	$('.lrupdate_hideroom').hide(),
	$('.lrupdate_hidecancellation').hide(),
	setDetailLinks()
     })
}),

$("#selectedCurrency2").change(function(e){
	// act as if main currency option had been changed
	$('#selectedCurrency').val($(this).val());
	return $("#selectedCurrency").change();

     // stop normal link click
     $.get('/lrupdate_matrix.php', { method: 'get', dateChange: 'true', sdate: $('#sdate').val(), nights: $('#nights').val(), hotel_id: $('#lr_hotelID').val(), lang: $('#lr_lang').val(), cur: $(this).val()}, function(response) {
     	$("#matrix").html(response)
        $('.lrupdate_roomdetails').hide()
        $('.lrupdate_cancellationdetails').hide()
	$('.lrupdate_hideroom').hide(),
	$('.lrupdate_hidecancellation').hide(),
	setDetailLinks()
     })
}),

$(".not_selected_section2").mouseout(function() {
	$(this).css({'background-color' : '#FFE3B3', 'color' : '#FFB842'})
	$(this).children("a").css({ 'color' : '#FFB43F'});

}),

$(".not_selected_section2").click(function() {
	url = $(this).children("a").attr('href');
	window.location.href = url;
}),

$(".not_selected_section2").mouseover(function() {
	$(this).addClass("over");
	$(this).css({'background-color' : '#FFB43F', 'color' : '#000000'});
	$(this).children("a").css({ 'color' : '#000000'});
}),

$("#nights").change(function(e){
     // stop normal link click
     $.get('/lrupdate_matrix.php', { method: 'get', nightsChange: 'true', nights: $(this).val(), sdate: $('#sdate').val(), hotel_id: $('#lr_hotelID').val(), lang: $('#lr_lang').val(), cur: $('#selectedCurrency').val()}, function(response) {
     	$("#matrix").html(response)
        $('.lrupdate_roomdetails').hide()
        $('.lrupdate_cancellationdetails').hide()
	$('.lrupdate_hideroom').hide(),
	$('.lrupdate_hidecancellation').hide(),
	setDetailLinks()
     })
}),
$('#f2').bind('submit', function() {
            $(this).ajaxSubmit({
		dataType: 'json',
		resetForm: false,
		beforeSubmit: function(formData, form, opts) {
			$('input[type=submit], input[type=image]', this).attr('disabled', 'disabled');
		},
		success: function(json) {
			$('input[type=submit], input[type=image]', this).removeAttr('disabled');

			if(json.status == false)
			{
				$('#greyedout').show();
				showPopWin(json, '/_lrupdate_errors.html', 400, 100);
			} else {
				$('#f2').attr({
					action: 'https://www.asiarooms.com/book'
				});
				$('#f2').unbind();
				
				$('#f2').submit();
			}
		}
            });
            return false; // <-- important!
})

$("#bookNowButton").css({display: 'block'});
if ($.browser.safari && self.navigator.userAgent.indexOf('Chrome') == -1) {
	$("#bookNowButton").css({'margin-top': '-30px'});
}
// end of dom ready
});


function setDetailLinks() {

	$(".lrupdate_showcancellation").click(function (e) { 
	     // stop normal link click
	     e.preventDefault();
	     $(this).hide("fast");
	     $(this).parent().children('.lrupdate_hidecancellation').show("fast");
	     $(this).parent().children('.lrupdate_roomdetails').hide("fast");
	     $(this).parent().children('.lrupdate_hideroom').hide("fast");
	     $(this).parent().children('.lrupdate_showroom').show("fast");
	     $(this).parent().children('.lrupdate_cancellationdetails').show("fast");

	}),

	$(".lrupdate_hidecancellation").click(function (e) { 
	     // stop normal link click
	     e.preventDefault();
	     $(this).hide("fast");
	     $(this).parent().children('.lrupdate_showcancellation').show("fast");
	     $(this).parent().children('.lrupdate_cancellationdetails').hide("fast");
	}),
	
	$(".lrupdate_showroom").click(function (e) { 
	     // stop normal link click
	     e.preventDefault();
	     $(this).hide("fast");
	     $(this).parent().children('.lrupdate_hideroom').show("fast");
	     $(this).parent().children('.lrupdate_cancellationdetails').hide("fast");
	     $(this).parent().children('.lrupdate_hidecancellation').hide("fast");
	     $(this).parent().children('.lrupdate_showcancellation').show("fast");
	     $(this).parent().children(".lrupdate_roomdetails").show("fast");
	}),

	$(".lrupdate_hideroom").click(function (e) { 
	     // stop normal link click
	     e.preventDefault();
             $(this).hide("fast");
	     $(this).parent().children('.lrupdate_showroom').show("fast");
	     $(this).parent().children('.lrupdate_roomdetails').hide("fast");
	}),

	$(".lrupdate_numberRooms").change(function (e) { 
	     // stop normal link click
	     e.preventDefault();
	     var room = $(this);
	     $.get('/lrupdate_matrix.php', { method: 'get', roomChange: 'true', perRooms: room.val(), children: room.attr("child"), adult: room.attr("adult"), roomref: room.attr("roomref")}, function(response) {
		room.siblings('.guestinfo').html(response);
	     })
	})
}

function clearEvents() {

	$('.lrupdate_room').queue( [ ] ).stop();
	$('.lrupdate_cancellation').queue( [ ] ).stop();
	$('.lrupdate_numberRooms').queue( [ ] ).stop();
}

function formattedError(msg) {
	return msg;
}

function closegrey() {
	$('#greyedout').hide("fast");
}
