var imgChanged = 0;
var imgId = 0;
function imgOver(id, filename) {
	imgId = id;
	imgChanged = document.getElementById(id).src;
	document.getElementById(id).src = filename;
}

function imgOut () 
{
	document.getElementById(imgId).src = imgChanged;
	imgId = 0;
	imgChanged = 0;
}

idShown = 0;
idSelected = 0;
prevColor = "#777777";
chosenAuto = false;

function showBlock (id)
{
	if(document.getElementById(idShown))
		document.getElementById(idShown).style.display='none';
	document.getElementById(id).style.display='block';
	idShown = id;
}

function SetIdShown(id)
{
	idShown = id;
}

function chooseAuto()
{
	chosenAuto = true;
}

function submitDate(year, month, day)
{
		document.getElementById("kalendarz_year").value=year;
		document.getElementById("kalendarz_month").value=month;
		document.getElementById("kalendarz_day").value=day;
		if(idSelected)
		{
			document.getElementById(idSelected).style.backgroundColor='transparent';
			document.getElementById(idSelected).childNodes[0].style.color=prevColor;
		}
		document.getElementById("d_"+year+month+day).style.backgroundColor='#F89A32';
		document.getElementById("d_"+year+month+day).childNodes[0].style.color="#FFFFFF";
		idSelected="d_"+year+month+day;
		
		
}

var msgsPl = new Array();
msgsPl['auto'] = 'Wybierz samochód';
msgsPl['miasto'] = 'Wybierz miasto';
msgsPl['data'] = 'Wybierz datę';
msgsPl['godzina_p'] = 'Wybierz godzinę początkową';
msgsPl['godzina_k'] = 'Wybierz godzinę końcową';
msgsPl['godzina_o'] = 'Godzina końcowa musi być późniejsza niż godzina początkowa';

var msgsDe = new Array();
msgsDe['auto'] = 'Wählen Sie  den Wagen!';
msgsDe['miasto'] = 'Wählen Sie den Ort!';
msgsDe['data'] = 'Wählen Sie das Datum!';
msgsDe['godzina_p'] = 'Wählen Sie die Uhrzeit vom Anfang!';
msgsDe['godzina_k'] = 'Wählen Sie die Uhrzeit vom Ende!';
msgsDe['godzina_o'] = 'Die Uhrzeit vom Ende muss später als die Uhrzeit vom Anfang sein.';

if(lng == 'pl')
	msgs = msgsPl;
else
	msgs = msgsDe;

function submitForm()
{
	szform = document.forms['szybkarezerwacja'];
	if(!szform.elements[4].checked && !szform.elements[5].checked && !szform.elements[6].checked)
	{
		alert(msgs['auto']);
		return;
	}
	
	if(!szform.elements['miasto'].selectedIndex)
	{
		alert(msgs['miasto']);
		return;
	}
	if(document.getElementById("kalendarz_year").value=='0' || document.getElementById("kalendarz_month").value=='0' || document.getElementById("kalendarz_day").value=='0')
	{
		alert(msgs['data']);
		return;
	}
	if(!szform.elements['godzina'].selectedIndex)
	{
		alert(msgs['godzina_p']);
		return;
	}
	else if(!szform.elements['godzina_do'].selectedIndex)
	{
		alert(msgs['godzina_k']);
		return;
	}
	else if(parseInt(szform.elements['godzina_do'].selectedIndex) < parseInt(szform.elements['godzina'].selectedIndex))
	{
		alert(msgs['godzina_o']);
		return;
	}
	szform.submit();
}


costIn = new Array();
costIn[1] = 1.4;
costIn[2] = 2;
costIn[3] = 1.7;

costOut = new Array();
costOut[1] = 1.7;
costOut[2] = 2.4;
costOut[3] = 2.2;

cost = new Array();

costPerPersonZl = 20;
costPerHourZl = 50;


function updateCost(value)
{
	if(value)
	{
		cost = costOut;
	}
	else
	{
		cost = costIn;
	}
	countCost();
}

function rnd(value, digits)
{
	num = new Number(value);
	return num.toFixed(digits);

}

function countCost()
{
	samochod = document.forms['kalkulator'].elements['samochod'].value;
	document.forms['kalkulator'].elements['km_sum'].value = rnd(cost[samochod]*document.forms['kalkulator'].elements['km'].value, 1);
	document.forms['kalkulator'].elements['postoj_sum'].value = costPerHourZl*document.forms['kalkulator'].elements['postoj'].value;
	document.forms['kalkulator'].elements['osoby_sum'].value = costPerPersonZl*document.forms['kalkulator'].elements['osoby'].value;
	document.forms['kalkulator'].elements['total_sum'].value = rnd(parseFloat(document.forms['kalkulator'].elements['km_sum'].value) + parseFloat(document.forms['kalkulator'].elements['postoj_sum'].value) + parseFloat(document.forms['kalkulator'].elements['osoby_sum'].value), 1);
}
