var calIsOpen = false;
var w = null;

function openWindow(name, url, attributes)
{
	if (calIsOpen && w!=null && !w.closed) {
		w.focus();
	} else {
		w = window.open(url, name, attributes);
		calIsOpen = true;
	}
}

function setDays(days, pickDrop) {
//upraveno pro bez "header row" selectu

	daysSet = eval("document.selecter.rent" + pickDrop + "Day.options;")

	var option29 = new Option("29", "29");
	var option30 = new Option("30", "30");
	var option31 = new Option("31", "31");

	if (days == daysSet.length) {
	//do nothing
		return
	} else if (days < daysSet.length) {
	//delete
		for (i=daysSet.length; i>=days; i--) {
			daysSet[i] = null;
		}
	} else {
	//add
		for (i=daysSet.length+1; i<=days; i++) {
			eval("daysSet[i]=option"+i);
		}
	}
}

//this will select the appropriate day in DAY dropdown on page
function selectDay(day,pickDrop) {
	if (day == "" || day==null || day.isNaN) day = tomorrowDay+1; //preselect tomorrow
	var daysDropDown;
	eval("daysDropDown=document.selecter.rent"+pickDrop+"Day.options");

	if (day>daysDropDown.length-1 || day==0 || isNaN(parseInt(day,10))) {
	//do nothing
		return
		//alert("selectDay function: doing nothing;");
	} else {
	//select the day
		daysDropDown[parseInt(day-1,10)].selected=true;
		//alert("selectDay function: selecting day "+day+". Operation is: "+pickDrop);
	}
}

//this will select the appropriate day in DAY dropdown on page
function selectHourMinute(hour, minute, pickDrop) {
	if (hour == "" || hour==null) hour = "10";
	if (minute == "" || minute==null) minute = "00";

	var hoursDropDown;
	eval("hoursDropDown=document.selecter.rent"+pickDrop+"Hour.options");

	for (i=0; i < hoursDropDown.length; i++) {
		if ( hoursDropDown[i].value == hour ) hoursDropDown[i].selected = true;
	}

	var minutesDropDown;
	eval("minutesDropDown=document.selecter.rent"+pickDrop+"Min.options");

	for (i=0; i < minutesDropDown.length; i++) {
		if ( minutesDropDown[i].value == minute ) minutesDropDown[i].selected = true;
	}
}

function selectMonthByIndex(monthIndex) {
	if (monthIndex>-1 && monthIndex < 17) {
		document.selecter.rentPickupMonthYear.options[monthIndex].selected=true;
	}
}

function selectMonthByString(monthString,pickDrop) {
	if (monthString == "" || monthString==null) monthString = (tomorrowMonth+1)+"-"+tomorrowYear;

	var monthsSet;
	eval("monthsSet=document.selecter.rent"+pickDrop+"MonthYear.options");

	for (i=0; i < monthsSet.length; i++) {
		if ( monthsSet[i].value == monthString ) {
			monthsSet[i].selected = true;
		}
	}
}

function changeCarCategory(category) {
	if (String(category).length == 0) {
		return
	}
	document.selecter.rentCarCategoryFullName.value = document.selecter.rentCarCategory.options[document.selecter.rentCarCategory.selectedIndex].text;
}
