var PricesTable = new PricesTableClass();
function PricesTableClass() 
{
	this.Discounts = null;
	this.setDiscount = function (value) 
	{
		this.Discounts = value;
		this.updateTable();
	};
	this.Currency = 'UAH';
	this.setCurrency = function(value) 
	{
		this.Currency = value;
		this.updateTable();
	};
	this.Hotel = null;
	this.setHotel = function(value)
	{
		this.Hotel = value;
		this.updateTable();
	};
	this.City = null;
	this.setCity = function (value)
	{
		this.City = value;
	};
    this.SortType = 'price';
	this.setSortType = function (value)
	{
		this.SortType = value;
		this.updateTable();
	};
	this.updateTable = function ()
	{
		if(this.StartDate != null && this.EndDate != null 
				&& this.StartDate != "" && this.EndDate != "")
		{
			$.getJSON( '/ajax_functions/nzb_places.php', {f:'get_pricestable2', city:this.City, object:this.Hotel, currency:this.Currency, discount:this.Discounts, endDate:this.EndDate, startDate:this.StartDate, sortType:this.SortType, lang:lang4url},
					function(json){
						$('#PricesTableContainer').html(json.msg);
						});
			
			update_prepay_percent(this.StartDate,this.EndDate,this.Hotel);
			
		}
		else
		{
		$.getJSON( '/ajax_functions/nzb_places.php', {f:'get_pricestable', object:this.Hotel, currency:this.Currency, discount:this.Discounts, lang:lang4url}, 
			function(json){
				$('#PricesTableContainer').html(json.msg)});
		}
	};
	this.updateTable2 = function ()
	{
		
	};
	this.baseInit = function(hotelSet, discountsSet, currencySet)
	{
		this.Hotel = hotelSet;
		this.Discounts = discountsSet;
		this.Currency = currencySet;
		this.updateTable();
	}
	this.StartDate = null;
	this.setStartDate = function(value)
	{
		this.StartDate = value;
	}
	this.EndDate = null;
	this.setEndDate = function(value)
	{
		this.EndDate = value;
	}
	this.RoomType = null;
	this.setRoomType = function(value)
	{
		this.RoomType = value;
	}
}


function updateDiscounts(el) {
	var value = 0;
	if (el.id != "BookITDiscount") {
		if (el.checked) {
			value = parseFloat(el.value);
		} else {
			value = 0;
		}
		for (var i = 1; i <= CountOfDiscountCards; i++) {
			if (el.id != 'NezabaromCardDiscount_' + i) {
				$('#NezabaromCardDiscount_' + i).attr('checked', false);
			}
		}
		if ($('#BookITDiscount').attr('checked')) {
			value += parseFloat($('#BookITDiscount').val());
		} 
	} else {
		for (var i = 1; i <= CountOfDiscountCards; i++) {
			if ($('#NezabaromCardDiscount_' + i).attr('checked')) {
				value = parseFloat($('#NezabaromCardDiscount_' + i).val());
			}
		}
		if (el.checked) {
			value += parseFloat(el.value);
		} 
	}
	PricesTable.setDiscount(value);
}
function setCurrency(value) {
	PricesTable.setCurrency(value);
}
function updateStartDate(value){
	if(value!=''){
		PricesTable.setStartDate(value);

        if($('#EndDate').val() == ''){
            var splitValue=value.split('.');
            var dat=new Date(Date.parse(''+splitValue[1]+'/'+splitValue[0]+'/'+splitValue[2]+''));
            dat.setDate(dat.getDate()+1);

            if(dat.getDate()<10) var day='0'+dat.getDate();
            else var day=dat.getDate();

            if((dat.getMonth()+1)<10) var month='0'+(dat.getMonth()+1);
            else var month=(dat.getMonth()+1);

            var endDate=day+'.'+month+'.'+dat.getFullYear();

            $('#EndDate').val(endDate);
            updateEndDate(endDate);
        }


        $('#sortAndCurrency').hide();

        PricesTable.updateTable();
	}
}
function updateEndDate(value){
	PricesTable.setEndDate(value);
    if($('#StartDate').val() != ''){
        PricesTable.updateTable();
    }
}

/*
function getFreeRoomsCount() {
	if (PricesTable.StartDate != null && PricesTable.EndDate != null && PricesTable.RoomType != null) 
	{
		$.getJSON( '/ajax_functions/nzb_places.php', {f:'get_freeroomscount', hotel:PricesTable.Hotel, start:PricesTable.StartDate, end:PricesTable.EndDate, type:PricesTable.RoomType}, 
				function(json){
					json.roomCount = parseInt(json.roomCount);
					if(json.roomCount > 3){
						$('#freeRoomsCount').html("3+"); }
					else{
						$('#freeRoomsCount').html(" "+json.roomCount); }
					$('#freeRoomsCountTitle').show();
				});
	}
}
*/
function getSoonEntranceUrl() {
	var params = "";
	if (PricesTable.StartDate != 0) {
		params += "&srt=" + PricesTable.StartDate;
	}
	if (PricesTable.EndDate != 0) {
		params += "&end=" + PricesTable.EndDate;
	}
	params += "&bookitdate"
	return params;
}

function getBookingHref(hotelId, cityId, roomtype, start, end)
{
	//var roomsCount = $('select#roomsCount_'+roomtype+'').val();
	document.location.href = 'http://bookit.com.ua/configurator/?&object='+hotelId+'&city='+cityId+'&roomtype='+roomtype+'&start='+start+'&end='+end+'&roomsCount=1';
} 

function getBookingHrefTO(hotelId, cityId, roomtype, start, end)
{
	//var roomsCount = $('select#roomsCount_'+roomtype+'').val();
	document.location.href = 'http://bookit.com.ua/configurator/?&object='+hotelId+'&city='+cityId+'&roomtype='+roomtype+'&start='+start+'&end='+end+'&roomsCount=1&isSaleTO=1';
} 
