$(document).ready(function (){
	$(":date").dateinput();
	var period = document.getElementById('periods_'+$('#period').val());
	var metro = document.getElementById('metro_'+$('#metro').val());
	var costFrom = document.getElementById('costFrom_'+$('#costFrom').val());
	var costTo = document.getElementById('costTo_'+$('#costTo').val());
	var dayBeg = document.getElementById('dayBeg_'+$('#dayBeg').val());
	var roomlist = document.getElementById('roomlist_'+$('#roomlist').val());
	var flatsList = document.getElementById('flatsList_'+$('#flatsList').val());
	var dayBeg = document.getElementById('dayBeg_'+$('#dayBeg').val());
	var dayEnd = document.getElementById('dayEnd_'+$('#dayEnd').val());
	var carClass = document.getElementById('carClass_'+$('#id_carClass').val());
	var podachaType = document.getElementById('podachaType_'+$('#podachaType').val());
	var airport = document.getElementById('airport_'+$('#id_airport').val());
	var vokzal = document.getElementById('vokzal_'+$('#id_vokzal').val());
	var adres = document.getElementById('adres_'+$('#id_adres').val());
	var naznachType = document.getElementById('naznachType_'+$('#naznachType').val());
	var airport2 = document.getElementById('airport2_'+$('#id_airport2').val());
	var vokzal2 = document.getElementById('vokzal2_'+$('#id_vokzal2').val());
	var adres2 = document.getElementById('adres2_'+$('#id_adres2').val());

	if (period) objSelectDays.Set(period);
	if (metro) objSelectStation.Set(metro);
	if (costFrom) objSelectPriceFrom.Set(costFrom);
	if (costTo) objSelectPriceTo.Set(costTo);
	if (dayBeg) objSelectdayBeg.Set(dayBeg);
	if (roomlist) objSelectroomlist.Set(roomlist);
	if (flatsList){
		objSelectflatsList.Set(flatsList);
		checkFlats($('#flatsList').val());
	}
	if (dayBeg) objSelectdayBeg.Set(dayBeg);
	if (dayEnd) objSelectdayEnd.Set(dayEnd);
	if (carClass) objSelectcarClass.Set(carClass);
	if (podachaType){
		objSelectpodachaType.Set(podachaType);
		showPodacha($('#podachaType').val());
	}
	if (airport) objSelectairport.Set(airport);
	if (vokzal) objSelectvokzal.Set(vokzal);
	if (adres) objSelectadres.Set(adres);
	if (naznachType){
		objSelectnaznachType.Set(naznachType);
		showNaznach($('#naznachType').val());
	}
	if (airport2) objSelectairport2.Set(airport2);
	if (vokzal2) objSelectvokzal2.Set(vokzal2);
	if (adres2) objSelectadres2.Set(adres2);
	roomCheck();
});

function refreshCap(){
	var obj = document.getElementById('cap');
	obj.src = obj.src+'?q='+Math.random();
}

function goodForm(){
	/*if ($('#period').val() != '' && ($('#costFrom').val() != '' || $('#costTo').val() != '')) {
		return true;
	} else {
		if ($('#period').val() == '' && ($('#costFrom').val() == '' && $('#costTo').val() == '')) {
			return true;
			} else {
				return false;
			}
	}*/
	return true;
}


function roomCheck(frmrooms){
	if (typeof(frmrooms) != 'undefined') $('#frmrooms').val(frmrooms);
	var arr = document.getElementsByTagName('a');
	var frmrooms = $('#frmrooms').val();
	for (var a in arr){
		if (arr[a].id){
			var id = arr[a].id.split('_');
			if (id[0] == 'frmrooms'){
				if (id[1] == frmrooms){
					if (id[1] == '5'){
						arr[a].className = 'selected last';
					}else{
						arr[a].className = 'selected';
					}
				}else{
					if (id[1] == '5'){
						arr[a].className = 'last';
					}else{
						arr[a].className = '';
					}
				}
			}
		}
	}
}
