//bron room search
function addzero( value ){
	while( value.length<2 ) value = String("0") + value;
	return value;
}  
function SaveBronDates() {
	if ($('b_checkin_day') && $('b_checkout_day') && $('b_checkin_month') && $('b_checkout_month')) {
		setCookie("b_checkin_day",$('b_checkin_day').value,5);
		setCookie("b_checkin_month",$('b_checkin_month').value,5);
		setCookie("b_checkout_day",$('b_checkout_day').value,5);
		setCookie("b_checkout_month",$('b_checkout_month').value,5);
	}
}
function GetBronDates() {
	var today = new Date();
	var day= today.getDate();
	var month= today.getMonth()+1;
	var fullYear=today.getFullYear();
	var tmp_b_checkin_day=getCookie("b_checkin_day");
	var tmp_b_checkin_month=getCookie("b_checkin_month").substr(5);
	var tmp_b_checkin_year=getCookie("b_checkin_month").substr(0,4);
	var tmp_b_checkout_day=getCookie("b_checkout_day");
	var tmp_b_checkout_month=getCookie("b_checkout_month").substr(5);
	var tmp_b_checkout_year=getCookie("b_checkout_month").substr(0,4);
	//Есть куки?
	if (tmp_b_checkin_year=='' || tmp_b_checkin_month=='' || tmp_b_checkin_day=='' ||
		tmp_b_checkout_year=='' || tmp_b_checkout_month=='' || tmp_b_checkout_day=='') return;
	//Верные даты?
	if (tmp_b_checkin_year<fullYear || tmp_b_checkin_month<month || tmp_b_checkin_day<day ||
		tmp_b_checkout_year<fullYear || tmp_b_checkout_month<month || tmp_b_checkout_day<day) return;
	//Если пучком, то работаем
	alert
	$('b_checkin_day').value=tmp_b_checkin_day;
	$('b_checkin_month').value=tmp_b_checkin_year+'-'+tmp_b_checkin_month;
	$('b_checkout_day').value=tmp_b_checkout_day;
	$('b_checkout_month').value=tmp_b_checkout_year+'-'+tmp_b_checkout_month;
}

function checkDateOrder(frm, ci_day, ci_month_year, co_day, co_month_year) {
	if (document.getElementById) {
		var frm = document.getElementById(frm);
		// create date object from checkin values
		// set date to 12:00 to avoid problems with one
		// date being wintertime and the other summertime
		var my = frm[ci_month_year].value.split("-");
	    var ci = new Date (my[0], my[1]-1, frm[ci_day].value, 12, 0, 0, 0);

        // create date object from checkout values
	    my = frm[co_month_year].value.split("-");
	    var co = new Date (my[0], my[1]-1, frm[co_day].value, 12, 0, 0, 0);

		// if checkin date is at or after checkout date,
		// add a day full of milliseconds, and set the
		// selectbox values for checkout date to new value
	    if (ci >= co){
    	    co.setTime(ci.getTime() + 1000 * 60 * 60 * 24);
	        frm[co_day].value =  co.getDate();
    	    var com = co.getMonth()+1;
	        frm[co_month_year].value = co.getFullYear() + "-" + com;
    	}
	}
}
function preSetCallendar() {
	if (!$('b_checkin_month') || !$('b_checkout_month')) return;
	//Заполняем select
	var monthArray=new Array("&#x42F;&#x43D;&#x432;&#x430;&#x440;&#x44C;","&#x424;&#x435;&#x432;&#x440;&#x430;&#x43B;&#x44C;","&#x41C;&#x430;&#x440;&#x442;","&#x410;&#x43F;&#x440;&#x435;&#x43B;&#x44C;","&#x41C;&#x430;&#x439;","&#x418;&#x44E;&#x43D;&#x44C;","&#x418;&#x44E;&#x43B;&#x44C;","&#x410;&#x432;&#x433;&#x443;&#x441;&#x442;","&#x421;&#x435;&#x43D;&#x442;&#x44F;&#x431;&#x440;&#x44C;","&#x41E;&#x43A;&#x442;&#x44F;&#x431;&#x440;&#x44C;","&#x41D;&#x43E;&#x44F;&#x431;&#x440;&#x44C;","&#x414;&#x435;&#x43A;&#x430;&#x431;&#x440;&#x44C;");
	var today = new Date();
	var month= today.getMonth();
	var year = today.getFullYear()%100;
	var fullYear=today.getFullYear();	
	year=new String(year);
	year=addzero(year);
	var countMonth=month;
	for(var i=0;i<12;i++,countMonth++){
		if(countMonth%12==0 && i>0){
		   countMonth=0;
		   year++;
		   year=new String(year);
		   year=addzero(year);
		   fullYear++;
		}
		$('b_checkin_month').innerHTML=$('b_checkin_month').innerHTML+"<option value=\""+fullYear+"-"+(countMonth+1)+"\">"+monthArray[countMonth]+" &#39;"+year+"\n";
		$('b_checkout_month').innerHTML=$('b_checkout_month').innerHTML+"<option value=\""+fullYear+"-"+(countMonth+1)+"\">"+monthArray[countMonth]+" &#39;"+year+"\n";
	}
	//Инициализируем
    var currentDate = new Date(); 
	var currentYear = 1900 + currentDate.getYear();
    var dailyMS = 24*60*60*1000;
    var arrivalDate = new Date(currentDate.getTime());
    var departureDate = new Date(currentDate.getTime() + 1*dailyMS);
    var arrivalYearMonth = 1900+arrivalDate.getYear() + "-" + 1+arrivalDate.getMonth();
	var arrivalDay = arrivalDate.getDate();
    var departureYearMonth = 1900+departureDate.getYear() + "-" + 1+departureDate.getMonth(); 
	var departureDay = departureDate.getDate();
    var a=document.b_frm;
    if ((a.checkin_monthday.selectedIndex == 0) && (a.checkout_monthday.selectedIndex == 0)){
        a.checkin_monthday.options[arrivalDay-1].selected = true;
        a.checkout_monthday.options[departureDay-1].selected = true;
	}
	var frm = document.getElementById('b_frm');
	// create date object from checkin values
	// set date to 12:00 to avoid problems with one
	// date being wintertime and the other summertime
	var my = frm['b_checkin_month'].value.split("-");
	var ci = new Date (my[0], my[1]-1, frm['b_checkin_day'].value, 12, 0, 0, 0);

    // create date object from checkout values
	my = frm['b_checkout_month'].value.split("-");
	var co = new Date (my[0], my[1]-1, frm['b_checkout_day'].value, 12, 0, 0, 0);
	if (ci >= co){
		co.setTime(ci.getTime() + 1000 * 60 * 60 * 24);
		frm['b_checkout_day'].value =  co.getDate();
		var com = co.getMonth()+1;
		frm['b_checkout_month'].value = co.getFullYear() + "-" + com;
    }
	GetBronDates();
}
function BookingFormSend() {
	$('b_frm').submit();
}
//old
function changeHotelRandomPhoto(path, name, imgId, photoId) {
	$('img_hotel_random_photo').src= path + '/' + name;
	curHotelPhotoId = photoId;
	type = path.substr(path.lastIndexOf('.', path) + 1);
	getCurPhotoSize(photoId, type);
}
function randomPhotoOnClick(){
    window.open(_onclickHref, 'photo', 'width='+_onclickW+',height='+_onclickH);
}
function PhotoOnClick(href,w,h){
    window.open(href, 'photo', 'width='+w+',height='+h);
}
function getCurPhotoSize(id, type) {
	JsHttpRequest.query('/ajax', { 'm': 'photos2obj->getPhotoSizeById','id': id,'type': type },
		function(result, errors) {
			if (result) {
				if (result['error']) {
					alert('Ошибка!');
				} else {
					$('span_randomphoto').innerHTML = '[' + result['w'] + ' x ' + result['h'] + ']';
					$('a_randomphoto').href = '#';
					_onclickHref = result['href'];
					_onclickW = result['w'];
					_onclickH = result['h'];
				}
			}
		}, true // true - не кешируется
	);
}
function showResponses(mode) {
	if (!$('div_resp_more')) return;

	if (mode == 'show') {
		$('div_link_resp_all').style.display = 'none';
		$('div_link_resp_hide').style.display = 'block';
		$('div_resp_more').style.display = 'block';
	} else {
		$('div_link_resp_all').style.display = 'block';
		$('div_link_resp_hide').style.display = 'none';
		$('div_resp_more').style.display = 'none';
	}
}
function checkSuburbs(mode){
	var checked = false;
	if (mode == 'checkall'){
		$('div_check_all_suburbs').style.display = 'none';
		$('div_reset_all_suburbs').style.display = 'inline';
		checked = true;
	}else{
		$('div_check_all_suburbs').style.display = 'inline';
		$('div_reset_all_suburbs').style.display = 'none';
		checked = false;	
	}
	for (var i = 0; i < suburbs_count; i++)	$('input_suburb_' + i).checked = checked;
}
function submitSearchForm(){
	$('form_hotel_search').submit();
}
function hotelPhotosListMore() {
	if (!$('hotel_photos_list_more')) return; 
	if (!$('hotel_photos_list_more_l')) return; 
	$('hotel_photos_list').innerHTML=$('hotel_photos_list').innerHTML+''+$('hotel_photos_list_more').innerHTML;
	$('hotel_photos_list_more').innerHTML='';
	$('hotel_photos_list_more_l').style.display='none';
	var ttips = document.getElementsByClassName('shtip');
	for( var i = 0; i < ttips.length; i++ ){
		ttips[i].onmouseover = showTip;
		ttips[i].onmouseout = hideTip;
		ttips[i].onmousemove = moveTip;
	}
}
