﻿flatID=1;
var fl_count=0;
var position=0;
var galerry_domen="img.flatlux.info";
var url=location.host;
function search_form()
{
	jQuery.getJSON('http://ajax.flatlux.info/index.php?page=search_form&lng='+lng+'&url='+url+'&callback=?', {}, function(search2)
	{
		jQuery('#search_form').html(search2.search_from);
		jQuery("#search_form").show();
	});
}




function flats_search()
{
	jQuery("#show_flat").hide();

	if (document.getElementById('select_price'))
	{
  		var price = document.getElementById("select_price").value;
	}else
	{
		var price = 0;
	}
	if (document.getElementById('select_class'))
	{
  		var class2 = document.getElementById("select_class").value;
	}else
	{
		var class2 = 0;
	}
	if (document.getElementById('select_metro'))
	{
  		var metro = document.getElementById("select_metro").value;
	}else
	{
		var metro = 0;
	}
	if (document.getElementById('select_district'))
	{
  		var district = document.getElementById("select_district").value;
	}else
	{
		var district = 0;
	}
	if (document.getElementById('select_rooms_count'))
	{
  		var rooms_count = document.getElementById("select_rooms_count").value;
	}else
	{
		var rooms_count = 0;
	}


	if (document.getElementById('select_format'))
	{
  		var select_format = document.getElementById("select_format").value;
	}else
	{
		var select_format = 0;
	}

	jQuery.getJSON('http://ajax.flatlux.info/index.php?page=search_new&select_class='+class2+'&select_format='+select_format+'&url='+url+'&select_metro='+metro+'&select_district='+district+'&select_price='+price+'&rooms_count='+rooms_count+'&lng='+lng+'&callback=?', {}, function(searching)
	{
		fl_count=searching.search_count;
		jQuery("#leftmore").hide();
		if(fl_count<4)
		{
			jQuery("#rightmore").hide();
		}else
		{
			jQuery("#rightmore").show();
		}
		position=0;
		
		jQuery("#widthbox").animate({left: position}, '1500' );
		jQuery('#searched_flats').html(searching.search_from_flats);
		jQuery("#lenta_kvartir").show();
		
	});

}






function booking_tobook()
{
	var sId = flatID;
	if(document.getElementById('contact_info'))
	{
		var ur2 ="";
		ur2="&from="+document.getElementById("from").value;
		ur2=ur2+"&first_name="+document.getElementById("first_name").value;
		ur2=ur2+"&last_name="+document.getElementById("last_name").value;
		ur2=ur2+"&email="+document.getElementById("email").value;
		ur2=ur2+"&country="+document.getElementById("country").value;
		ur2=ur2+"&city="+document.getElementById("city").value;
		ur2=ur2+"&tel1="+document.getElementById("tel1").value;
		ur2=ur2+"&tel2="+document.getElementById("tel2").value;
		ur2=ur2+"&security_code="+document.getElementById("security_code").value;
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=to_check&flatID='+sId+ur2+'&url='+url+'&lng='+lng+'&callback=?', {}, function(booking)
		{
			jQuery('#error').html('');
			if(booking.error!='')
			{
				jQuery('#error').append(booking.error);
			}else
			{
				var rdate = document.getElementById("f_date_c").value;
				var r2date = document.getElementById("f_date_c2").value;
				if(document.getElementById('contact_info'))
				{
					var ur='';
					for (i = 1; i <= 10; i++)
					{
						if(document.getElementById('s'+i))
						{
         							if (document.getElementById('s'+i).checked)
							{
								ur=ur+'&'+document.getElementById('s'+i).value+'=1';
								if(document.getElementById('s'+i).value=="internet")
								{
									ur=ur+'&internet_days_counts='+document.getElementById('internet_days_counts').value;
								}
							}
						}
					}
					var ur2 ="";
					ur2="&from="+document.getElementById("from").value;
					ur2=ur2+"&first_name="+document.getElementById("first_name").value;
					ur2=ur2+"&last_name="+document.getElementById("last_name").value;
					ur2=ur2+"&email="+document.getElementById("email").value;
					ur2=ur2+"&country="+document.getElementById("country").value;
					ur2=ur2+"&city="+document.getElementById("city").value;
					ur2=ur2+"&tel1="+document.getElementById("tel1").value;
					ur2=ur2+"&tel2="+document.getElementById("tel2").value;
					ur2=ur2+"&security_code="+document.getElementById("security_code").value;
					jQuery.getJSON('http://ajax.flatlux.info/index.php?page=booking&submit=to_book&flatID='+sId+ur2+'&url='+url+'&r_date='+rdate+'&r2_date='+r2date+ur+'&url='+url+'&lng='+lng+'&callback=?', {}, function(booking)
					{
						jQuery("#flat_booking").hide();
						if(booking.error)
						{
							jQuery("#booking_end").html(booking.error);
						}
						jQuery("#booking_end").show('');
					});
				}
			}
		});
	}
}

function booking_check()
{
	var sId = flatID;
	if(document.getElementById('contact_info'))
	{
		var ur2 ="";
		ur2="&from="+document.getElementById("from").value;
		ur2=ur2+"&first_name="+document.getElementById("first_name").value;
		ur2=ur2+"&last_name="+document.getElementById("last_name").value;
		ur2=ur2+"&email="+document.getElementById("email").value;
		ur2=ur2+"&country="+document.getElementById("country").value;
		ur2=ur2+"&city="+document.getElementById("city").value;
		ur2=ur2+"&tel1="+document.getElementById("tel1").value;
		ur2=ur2+"&tel2="+document.getElementById("tel2").value;
		ur2=ur2+"&security_code="+document.getElementById("security_code").value;
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=to_check&flatID='+sId+ur2+'&url='+url+'&lng='+lng+'&callback=?', {}, function(booking)
		{
			jQuery('#error').html('');
			if(booking.error!='')
			jQuery('#error').append(booking.error);
		});
	}
}

function booking_form()
{
	
	jQuery.getJSON('http://ajax.flatlux.info/index.php?page=booking_form&lng='+lng+'&url='+url+'&callback=?', {}, function(form2)
	{
		jQuery('#booking_form').html("<script type='text/javascript' src='http://ajax.flatlux.info/includes/calendar/calendar-setup.js'></script>");
		jQuery('#booking_form').append(form2.book);
		Calendar.setup
		({
        			inputField     :    'f_date_c',  // id of the input field
        			ifFormat       :    '%d-%m-%Y',      // format of the input field
        			button         :    'f_trigger_c',  // trigger for the calendar (button ID)
        			align          :    'Tl',           // alignment (defaults to 'Bl')
        			singleClick    :    true
		});
    		Calendar.setup
		({
        			inputField     :    'f_date_c2',     // id of the input field
        			ifFormat       :    '%d-%m-%Y',      // format of the input field
        			button         :    'f_trigger_c2',  // trigger for the calendar (button ID)
        			align          :    'Tl',           // alignment (defaults to 'Bl')
        			singleClick    :    true
		});
		booking_refresh();
	});
	
}

function booking_refresh()
{
	var rdate = document.getElementById("f_date_c").value;
	var r2date = document.getElementById("f_date_c2").value;
	var sId = flatID;
	

		var ur='';
		for (i = 1; i <= 10; i++)
		{
			if(document.getElementById('s'+i))
			{
         				if (document.getElementById('s'+i).checked)
				{
					ur=ur+'&'+document.getElementById('s'+i).value+'=1';
					if(document.getElementById('s'+i).value=="internet")
					{
						ur=ur+'&internet_days_counts='+document.getElementById('internet_days_counts').value;
					}
				}
			}
		}

	jQuery.getJSON('http://ajax.flatlux.info/index.php?page=booking&flatID='+sId+'&r_date='+rdate+'&r2_date='+r2date+''+ur+'&url='+url+'&lng='+lng+'&callback=?', {}, function(booking)
	{
		jQuery('#table_flatID').html('');
		jQuery('#table_flatID').append(booking.table_flatID);
		jQuery('#table_flat_name').html('');
		jQuery('#table_flat_name').append(booking.table_flat_name);
		jQuery('input#f_date_c').attr("value",booking.r_date);
		jQuery('input#f_date_c2').attr("value",booking.r2_date);
		jQuery('#day_price').html('');
		jQuery('#day_price').append(booking.new_day_price);
		jQuery('.cur').html('');
		jQuery('.cur').append(booking.cur);
		jQuery('#booking_table').html('');
		jQuery('#booking_table').append(booking.booking_table);
		jQuery('#total_price').html('');
		jQuery('#total_price').append(booking.total_price);
		jQuery('#all_services').html('');
		jQuery('#all_services').append(booking.all_services);
		jQuery('#full_price').html('');
		jQuery('#full_price').append(booking.full_price);
	});
}


jQuery(document).ready(function()
{
	jQuery("#lenta_kvartir").hide();

	jQuery('#search').click(function()
	{
		var sId = document.getElementById("flatID").value;
		flatID=sId;
		jQuery("#flat_booking").hide();
		jQuery("#booking_end").hide();
		jQuery("#show_flat").hide();
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=show_flat&flatID='+flatID+'&lng='+lng+'&url='+url+'&callback=?', {}, function(flat)
		{
			jQuery('#flat_id').html('');
			jQuery('#flat_id').append(flat.id);
			jQuery('#flatID').html('');
			jQuery('#flatID').append(flat.id);
			jQuery('#flat_name').html('');
			jQuery('#flat_name').append(' '+flat.name);
			jQuery('#flat_price').html('');
			jQuery('#flat_price').append(flat.price);
			jQuery('#description').html('flat.description');
			jQuery('#reduction').html('');
			jQuery('#reduction').append(flat.reduction);
			jQuery('#goods').html('');
			jQuery('#goods').append(flat.goods);
			jQuery('#gallery').html('');
			jQuery('#gallery').append(flat.gallery);
			jQuery('#photo2').attr("src",'http://'+galerry_domen+'/'+flat.photo_main);       
			jQuery('a#a_photo').attr("href",'http://'+galerry_domen+'/'+flat.photo_main);
			jQuery('#video_div').hide('');        
			jQuery('.photo2').show('');
			jQuery('.single').show('');
			document.title=flat.name;
			if(flat.video=='0')
			{
				jQuery('#video').hide(''); 
			}else
			{
				jQuery('#video').show(''); 
			}
		});   
		jQuery("#show_flat").show();             
	});

	jQuery('#map').click(function()
	{
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=show_flat&flatID='+flatID+'&lng='+lng+'&url='+url+'&callback=?', {}, function(flat)
		{
			jQuery('.photo2').attr("src",'http://'+galerry_domen+'/'+flat.photo_map+'_'+flat.lng+'.gif');
			
				jQuery('a#a_photo').attr("href","javascript:open_window('http://"+galerry_domen+"/"+flat.photo_map+"_"+flat.lng+".gif',1150,740);");
			
			jQuery('#video_div').hide('');   
			jQuery('.photo2').show('');
			jQuery('.single').show('');
		});
	});

	jQuery('.gal').live('click', function()
	{
		var phid = jQuery(this).text();
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=show_photo&flatID='+flatID+'&photoID='+phid+'&lng='+lng+'&url='+url+'&callback=?', {}, function(photo)
		{
			jQuery('.photo2').attr("src",'http://'+galerry_domen+'/'+photo.photo_url);
		
	jQuery('a#a_photo').attr("href","javascript:open_window('http://"+galerry_domen+"/"+photo.photo_url+"',830,630);");
			
			
			jQuery('#video_div').hide('');   
			jQuery('.photo2').show('');
			jQuery('.single').show('');
		});
	});

	jQuery('#book_button').click(function()
	{
		jQuery("#show_flat").hide();
		booking_form();
		jQuery("#flat_booking").show();   
		jQuery("#booking_end").hide();   
         		booking_refresh();
	});

	jQuery('.book_button_new').live('click', function()
	{
		var sId = this.id;
		flatID=sId;
		jQuery("#lenta_kvartir").hide();
		jQuery("#search_form").hide();
		jQuery("#show_flat").hide();
		booking_form();
		jQuery("#flat_booking").show();
		jQuery("#booking_end").hide();   
         		booking_refresh();
	});

	

	jQuery('.service').live('click', function()
	{
		booking_refresh();
	});

	jQuery('.contact').live('change', function()
	{
		booking_check();
	});

	jQuery('#internet_days_counts').live('change', function()
	{
		booking_refresh();
	});

	jQuery('#to_book').live('click', function()
	{
		booking_tobook();
	});

	jQuery('#show_result').click(function()
	{
         		flats_search();
	});

	jQuery('.search_select').live('change', function()
	{
         		flats_search();
	});

	jQuery('#video').click(function()
	{
         		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=video&flatID='+flatID+'&lng='+lng+'&url='+url+'&callback=?', {}, function(flat)
		{
			jQuery('.photo2').attr("src",'nul');
			jQuery('.photo2').hide(''); 
			jQuery('.single').show('');   
			jQuery('#video_div').html('');
			jQuery('#video_div').append(flat.video);
			jQuery('#video_div').show('');
		});
	});

	jQuery('.searched_flat').live('click', function()
	{
		jQuery("#lenta_kvartir").hide();
		var sId = this.id;
		jQuery('.searched_flat').each(function()
		{
				this.style.border='0px solid #000000';
		});  
		this.style.border='2px solid';
		flatID=sId;
		jQuery("#flat_booking").hide();
		jQuery("#booking_end").hide();
		jQuery("#show_flat").hide();
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=show_flat&flatID='+flatID+'&lng='+lng+'&url='+url+'&callback=?', {}, function(flat)
		{
			jQuery('#flat_id').html('');
			jQuery('#flat_id').append(flat.id);
			jQuery('#flat_name').html('');
			jQuery('#flat_name').append(' '+flat.name);
			jQuery('#flat_price').html('');
			jQuery('#flat_price').append(flat.price);
			jQuery('#description').html('');
			jQuery('#description').append(flat.description);
			jQuery('#reduction').html('');
			jQuery('#reduction').append(flat.reduction);
			jQuery('#goods').html('');
			jQuery('#goods').append(flat.goods);
			jQuery('#gallery').html('');
			jQuery('#gallery').append(flat.gallery);

			document.title=flat.name;
	
			jQuery('.photo2').attr("src",'http://'+galerry_domen+'/'+flat.photo_main);     
							jQuery('a#a_photo').attr("href","javascript:open_window('http://"+galerry_domen+"/"+flat.photo_main+"',830,630);");
			
			
			jQuery('#video_div').hide('');   
			jQuery('#photo').show('');  
			jQuery('.single').show('');
			if(flat.video=='0')
			{
				jQuery('#video').hide(''); 
			}else
			{
				jQuery('#video').show(''); 
			}
		});   
		jQuery("#show_flat").show();             
	});

	jQuery('.searched_flat_div').live('click', function()
	{
		
		var sId = this.id;
		jQuery('.searched_flat').each(function()
		{
				this.style.border='0px solid #000000';
		});  
		this.style.border='2px solid';
		flatID=sId;
		jQuery("#flat_booking").hide();
		jQuery("#booking_end").hide();
		jQuery("#show_flat").hide();
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=show_flat&flatID='+flatID+'&lng='+lng+'&url='+url+'&callback=?', {}, function(flat)
		{
			jQuery('#flat_id').html('');
			jQuery('#flat_id').append(flat.id);
			jQuery('#flat_name').html('');
			jQuery('#flat_name').append(' '+flat.name);
			jQuery('#description').html('');
			jQuery('#description').append(flat.description);
			jQuery('#reduction').html('');
			jQuery('#reduction').append(flat.reduction);
			jQuery('#goods').html('');
			jQuery('#goods').append(flat.goods);
			jQuery('#gallery').html('');
			jQuery('#gallery').append(flat.gallery);
	
			jQuery('#flat_price2').html("");
			jQuery('#flat_price2').append(flat.price);
			
			document.title=flat.name;
	
			jQuery('.photo2').attr("src",'http://'+galerry_domen+'/'+flat.photo_main);     
			
				jQuery('a#a_photo').attr("href","javascript:open_window('http://"+galerry_domen+"/"+flat.photo_main+"',830,630);");
			
			
			jQuery('#video_div').hide('');   
			jQuery('.photo2').show(''); 
			jQuery('.single').show('');
			if(flat.video=='0')
			{
				jQuery('#video').hide(''); 
			}else
			{
				jQuery('#video').show(''); 
			}
		});   
		jQuery("#lenta_kvartir").hide();
		jQuery("#show_flat").show();             
	});

	
	
	
	var b =location.hash;
	var temp = new Array();
	temp = b.split('/');
	if(temp[0]=='#flat')
	{
		jQuery('.searched_flat').each(function()
		{
				this.style.border='0px solid';
		});  
		jQuery('#'+temp[0]).each(function()
		{
				this.style.border='2px solid';
		});  
		
		flatID=temp[1];
		jQuery("#flat_booking").hide();
		jQuery("#booking_end").hide();
		jQuery("#show_flat").hide();
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=show_flat&flatID='+flatID+'&lng='+lng+'&url='+url+'&callback=?', {}, function(flat)
		{
			jQuery('#flat_id').html('');
			jQuery('#flat_id').append(flat.id);
			jQuery('#flat_name').html('');
			jQuery('#flat_name').append(' '+flat.name);
			jQuery('#flat_price').html('');
			jQuery('#flat_price').append(flat.price);
			jQuery('#description').html('');
			jQuery('#description').append(flat.description);
			jQuery('#reduction').html('');
			jQuery('#reduction').append(flat.reduction);
			jQuery('#goods').html('');
			jQuery('#goods').append(flat.goods);
			jQuery('#gallery').html('');
			jQuery('#gallery').append(flat.gallery);

			document.title=flat.name;

			jQuery('.photo2').attr("src","http://"+galerry_domen+"/"+flat.photo_main+"");     
							jQuery('a#a_photo').attr("href","javascript:open_window('http://"+galerry_domen+"/"+flat.photo_main+"',830,630);");
			
			
			
			jQuery('#photo').show('');   
			jQuery('.single').show('');
		});   
		jQuery("#show_flat").show();          
	}else
	if(temp[0]=='#category')
	{
		jQuery("#flat_booking").hide();
		var rooms_count = class2 = temp[1];
		jQuery.getJSON('http://ajax.flatlux.info/index.php?page=search_new&'+'&rooms_count='+rooms_count+'&lng='+lng+'&url='+url+'&callback=?', {}, function(searching)
		{
			fl_count=searching.search_count;
			jQuery("#leftmore").hide();
			if(fl_count<4)
			{
				jQuery("#rightmore").hide();
			}else
			{
				jQuery("#rightmore").show();
			}
			position=0;
			jQuery("#show_flat").hide();          
			jQuery("#widthbox").animate({left: position}, '1500' );
			jQuery('#searched_flats').html(searching.search_from_flats);
			jQuery("#lenta_kvartir").show();
			jQuery("#search_form").hide();
		
		});
	}else
	if(temp[0]=='#flat_search')
	{
		search_form();
		jQuery("#show_flat").hide();          
		jQuery("#lenta_kvartir").show();
	}
});



jQuery('.navigation').click(function()	
{
	jQuery("#show_flat").hide();
	jQuery("#flat_booking").hide();
	var b =location.hash;
	var temp = new Array();
	temp = b.split('/');
	var rooms_count = this.id;
	jQuery.getJSON('http://ajax.flatlux.info/index.php?page=search_new&'+'&rooms_count='+rooms_count+'&lng='+lng+'&url='+url+'&callback=?', {}, function(searching)
	{
		fl_count=searching.search_count;
		jQuery("#leftmore").hide();
		if(fl_count<4)
		{
			jQuery("#rightmore").hide();
		}else
		{
			jQuery("#rightmore").show();
		}
		position=0;
		jQuery("#widthbox").animate({left: position}, '1500' );
		jQuery('#searched_flats').html(searching.search_from_flats);
		jQuery("#lenta_kvartir").show();
		jQuery("#search_form").hide();
	});

});	

jQuery('.navigation_search').click(function()	
{
	search_form();
	jQuery("#show_flat").hide();          
	jQuery("#lenta_kvartir").hide();
	jQuery("#flat_booking").hide();
	
});	


