function updateprovince(selectedcitygroup){
	var citieslist=document.classic.province;
	citieslist.options.length=0
	
	if (selectedcitygroup>0){
		for (i=0; i<cities[selectedcitygroup].length; i++){
			citieslist.options[citieslist.options.length]=new Option(cities[selectedcitygroup][i].split("|")[0], cities[selectedcitygroup][i].split("|")[1])
		}
	}
	var selectId=$('#province').get(0);
	$.jNice.SelectUpdate(selectId);
}

function updateprovinceleftmenu(selectedcitygroup, dbid){
	var citieslist=document.citiesForm.citiesLeftMenu;
	citieslist.options.length=0
	if (selectedcitygroup>0){
		for (i=0; i<cities_left[selectedcitygroup].length; i++)
			citieslist.options[citieslist.options.length]=new Option(cities_left[selectedcitygroup][i].split("|")[0], cities_left[selectedcitygroup][i].split("|")[1])
	}
	var selectId=$('#citiesLeftMenu').get(0);
	$.jNice.SelectUpdate(selectId);
	$("#selectedLeftColumn").html('<li>'+dbid+'</li>');
	$("#selectedRegion").val(dbid);
	$("#selectedCity").val('');
}

function addValue(){
	$("#selectedCity").val($('#citiesLeftMenu :selected').html());
	$("#selectedLeftColumn").html('<li>'+$("#selectedRegion").val()+'</li><li>'+$("#selectedCity").val()+'</li>');
}

function sendSelectionData(lang) { 
	selectedRegion = $('#selectedRegion').val();
	selectedCity = $('#selectedCity').val();
	
	//url = 'http://sports-rental.info/search.aspx?ext=1&nodummy=1&flt=rag';
	url ='http://www.sports-rental.info/search.aspx?ext=1&flt=rag&lang='+lang;
	if(selectedCity) 
		url += '&type=area&search=' + urlencode(selectedCity.toLowerCase());
	else if(selectedRegion) 
		url += '&type=region&search=' + urlencode(selectedRegion.toLowerCase());
	var date_from = $('#date_from').val();
	var date_to = $('#date_to').val();
	url += '&df=' +  date_from.substr(6,4)+'/'+date_from.substr(3,2)+"/"+date_from.substr(0,2);
	url += '&du=' + date_to.substr(6,4)+'/'+date_to.substr(3,2)+"/"+date_to.substr(0,2);
	
	var wH=$(window).height(),pH=$('#popup').outerHeight(),middle=wH/2-pH/2;
	$('#popup iframe').attr('height', $(window).height()-100);
	sTop=$(document).scrollTop();
	$('#popup').css('top',sTop+30);
	$('#popup,#overlay').fadeIn();
	$(document).bind('scroll.popup',function() {
		if(wH>pH) {
			var top=$('#popup').css('top'),sTop=$(document).scrollTop();
			$('#popup').stop(true,true).animate({'top':parseInt(middle)+sTop},700)
		}
	})
	$('#closeDown').click(function() {
		$(document).unbind('scroll.popup');
		$('#popup,#overlay').fadeOut();
	})
	$('#popup iframe').attr('src', url);

}	

function urlencode (str) {
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

$(function() {
	var today = new Date(); 
	var dd = today.getDate();
	var mindateS = '';
	if(today.getHours() <= 12) {
		today.setDate(today.getDate()+1);
		mindateS = today;
	}
	else {
		var day = new Date();
		day.setDate(day.getDate()+2);
		mindateS = day;
	}

	$( "#date_from" ).datepicker({dateFormat: "dd/mm/yy", minDate: mindateS });
	
	
	
	$( "#date_to" ).datepicker({dateFormat: "dd/mm/yy", minDate: mindateS});
	
	
	var selectId=$('#region').get(0);
	if(selectId && selectId.length > 0)	$.jNice.SelectUpdate(selectId);
	var selectId=$('#province').get(0);
	if(selectId && selectId.length > 0)	$.jNice.SelectUpdate(selectId);
	
});
 
