var AN = 0;
var H3 = 0;
var H2 = 0;
var H1 = 0;
var HH = 0;

function rezerwuj(hours, an, h3, h2, h1, hh)
{
	AN = an;
	H3 = h3;
	H2 = h2;
	H1 = h1;
	HH = hh;
	var today=new Date();
	var h = today.getHours()+1;
	var inst = document.getElementById('calOkno');
	inst.style.display = "block";
	inst.style.position = "absolute";
	inst.style.zIndex = "100";
	inst.style.top = "20%";
	inst.style.left = "40%";
	//inst.style.background = "#6e0042";
	inst.style.padding = "5px";
	document.getElementById('from0').value = hours;
	document.getElementById('from1').value = h;
	document.getElementById('from2').value = '00';
	document.getElementById('to0').value = hours;
	document.getElementById('to1').value = h;
	document.getElementById('to2').value = '30';
	+' '+h+':30';
	checkP();
}

function checkP()
{
	var from = document.getElementById('from0').value+' '+document.getElementById('from1').value+':'+document.getElementById('from2').value+':00';
	var to = document.getElementById('to0').value+' '+document.getElementById('to1').value+':'+document.getElementById('to2').value+':00';
	var diff;
	var price;
	price = 0;
	from = from.replace(/-/g, "/");
	to = to.replace(/-/g, "/");
	from = Date.parse(from);
	to = Date.parse(to);
	if(from > to)
	{
		document.getElementById('earn').value = 'Time error';
		return;
	}
	diff = (to-from)/60000;
	price = Math.floor(diff/720)*AN;
	if(Math.floor(diff/720) != 0)
		diff = diff-Math.floor(diff/720)*720;
	price = H3*Math.floor(diff/180);
	if(Math.floor(diff/180) != 0)
		diff = diff-Math.floor(diff/180)*180;
	price += Math.floor(diff/120)*H2;
	if(Math.floor(diff/120) != 0)
		diff = diff-Math.floor(diff/120)*120;
	price += Math.floor(diff/60)*H1;
	if(Math.floor(diff/60) != 0)
		diff = diff-Math.floor(diff/60)*60;
	price += Math.floor(diff/30)*HH;
	document.getElementById('earn').value = price;
}

function sprawdz(hours, hnext, day)
{
	var inst = document.getElementById('calOknoSprawdz');
	inst.style.display = "block";
	inst.style.position = "absolute";
	inst.style.zIndex = "100";
	inst.style.width = "300px";
	inst.style.top = "20%";
	inst.style.left = "40%";
	inst.style.background = "#6e0042";
	inst.style.padding = "5px";
	document.getElementById("hO0").value = hours;
	document.getElementById("hO1").value = hours;
	document.getElementById("hN0").value = hnext;
	document.getElementById("hN1").value = hnext;
	document.getElementById("hD0").value = day;
	document.getElementById("hD1").value = day;
}

function setP(an, h3, h2, h1, hh)
{
	AN = an;
	H3 = h3;
	H2 = h2;
	H1 = h1;
	HH = hh;
	var inst = document.getElementById('calOknoSetP');
	inst.style.display = "block";
	inst.style.position = "absolute";
	inst.style.zIndex = "100";
	inst.style.width = "300px";
	inst.style.top = "20%";
	inst.style.left = "40%";
	inst.style.background = "#6e0042";
	inst.style.padding = "5px";
}

function SendRequest(plik, id){      
    var req = mint.Request();
    req.Send(plik, id);
}

function checkID(item)
{
	if(item.value.length == 11)
	{
		SendRequest('cal_showopins.php?t='+item.value, 'haveOpin');
		if(document.getElementById('haveOpin').innerHTML != '0')
			document.getElementById('linkOpin').style.display = "inline";
		else
			document.getElementById('linkOpin').style.display = "none";
	}
	else
	{
		document.getElementById('linkOpin').style.display = "none";
		document.getElementById('haveOpin').innerHTML = '0';
	}
}