var priceArr = new Array('CZK|30000:30.000','CZK|50000:50.000','CZK|60000:60.000','CZK|70000:70.000',
			 'CZK|80000:80.000','CZK|90000:90.000','CZK|100000:100.000','CZK|125000:125.000',
			 'CZK|150000:150.000','CZK|175000:175.000','CZK|200000:200.000','CZK|225000:225.000',
			 'CZK|250000:250.000','CZK|300000:300.000','CZK|400000:400.000','CZK|500000:500.000',
			 'CZK|700000:700.000','CZK|900000:900.000','CZK|1100000:1.100.000','CZK|1500000:1.500.000',
			 'CZK|2000000:2.000.000','CZK|3000000:3.000.000','CZK|4000000:4.000.000','CZK|5000000:5.000.000');

function setDefaultValues(defaultPriceFromValue,defaultPriceToValue,defaultYearFromValue,defaultYearToValue)
{
 var priceFrom = document.getElementById('formCarPriceOd');
 var priceTo = document.getElementById('formCarPriceDo');
 var yearFrom = document.getElementById('formCarYearOd');
 var yearTo = document.getElementById('formCarYearDo');

 priceFrom.value = defaultPriceFromValue;
 priceTo.value = defaultPriceToValue;
 changePriceFrom();
 changePriceTo();

 yearFrom.value = defaultYearFromValue;
 yearTo.value = defaultYearToValue;
 changeYearFrom();
 changeYearTo();
}


function initExtraCombos()
{
 initPrices();
 initYears();
}

function initPrices()
{
 initPrice(document.getElementById('formCarPriceOd'),false);
 initPrice(document.getElementById('formCarPriceDo'),true);
 changePriceFrom();
}

function changePriceFrom()
{
 var priceFrom = document.getElementById('formCarPriceOd');
 var priceTo = document.getElementById('formCarPriceDo');
 var valFrom = priceFrom.options[priceFrom.selectedIndex].value;
 var offset = priceTo.length - priceTo.selectedIndex;
 priceTo.options.length = 0;
 initPrice(priceTo,true);
 while(priceTo.length>1 && valFrom != priceTo.options[1].value)priceTo.remove(1);
 if(priceTo.length - offset >=0) priceTo.selectedIndex = priceTo.length - offset;
}
function changePriceTo()
{
 var priceFrom = document.getElementById('formCarPriceOd');
 var priceTo = document.getElementById('formCarPriceDo');
 var valTo = priceTo.options[priceTo.selectedIndex].value;
 var idFrom = priceFrom.selectedIndex;
 priceFrom.options.length = 0;
 initPrice(priceFrom,false);
 if(valTo!='XX')
	 while(priceFrom.length>0 && valTo != priceFrom.options[priceFrom.length-1].value)priceFrom.remove(priceFrom.length-1);
 if(idFrom<=(priceFrom.length-1))priceFrom.selectedIndex = idFrom;
}
function initPrice(price,addFirstBlank)
{
 if(addFirstBlank)addOption(price,'XX','');
 for(var i=0;i<priceArr.length;i++)
 {
  var item = priceArr[i].split(':');
  addOption(price,item[0],item[1]);
 }
}

function initYears()
{
 initYear(document.getElementById('formCarYearOd'),false);
 initYear(document.getElementById('formCarYearDo'),true);
 changeYearFrom();
}

function changeYearFrom()
{
 var yearFrom = document.getElementById('formCarYearOd');
 var yearTo = document.getElementById('formCarYearDo');
 var valFrom = yearFrom.options[yearFrom.selectedIndex].value;
 var offset = yearTo.length - yearTo.selectedIndex;
 yearTo.options.length = 0;
 initYear(yearTo,true);
 while(yearTo.length>1 && valFrom != yearTo.options[1].value)yearTo.remove(1);
 if(yearTo.length - offset >=0) yearTo.selectedIndex = yearTo.length - offset;
}
function changeYearTo()
{
 var yearFrom = document.getElementById('formCarYearOd');
 var yearTo = document.getElementById('formCarYearDo');
 var valTo = yearTo.options[yearTo.selectedIndex].value;
 var idFrom = yearFrom.selectedIndex;
 yearFrom.options.length = 0;
 initYear(yearFrom,false);
 if(valTo!='XX')
	 while(yearFrom.length>0 && valTo != yearFrom.options[yearFrom.length-1].value)yearFrom.remove(yearFrom.length-1);
 if(idFrom<=(yearFrom.length-1))yearFrom.selectedIndex = idFrom;
}

function initYear(year,addFirstBlank)
{
 var actual = new Date().getYear();
 if (actual < 1900)actual = actual+1900;
 if(addFirstBlank)addOption(year,'XX','');
 for(var i=12;i>=0;i--)
 {
  var val = actual - i;
  addOption(year,val,val);
 }
}

function addOption(combo,value,text)
{
 var option = new Option(text,value);
 try
 {
  combo.add(option, null);
 }
 catch(ex)
 {
  combo.add(option);
 }
}

