function openWindow(file, width, height)
{
	var win = window.open(file, '_popup', 'width='+width+', height='+height+', resizable=yes, scrollbars=no, toolbar=no, location=no, directories=no, status=yes, menubar=no');
	win.focus();
}

function openBlank(file)
{
	var win = window.open(file, '_blank');
	win.focus();
}

function deleteForm(path)
{
	if(!confirm("Czy napewno chcesz skasować?")) return;
	document.location.href=path;
}

function setValueInForm(id, value)
{
	var obj = window.opener.document.getElementById(id);
	if(obj != undefined)
	{
		obj.value = value;
	}
	else
	{
		alert("Nie można wpisać wartości ponieważ formularz został zamknięty.");
	}
	window.close();
}

function mediaPreview(id, width, height)
{
    openWindow('preview.php?id='+id, width, height);
}

function ustawKosztWizyty(id)
{
	var koszty = new Array(0, 100, 100, 160, 60, 150, 40, 250, 300, 250, 200, 400, 200, 300, /* old */100, 80, 100, 120, 180, 120, 100, 280, 100, 140);
	var ru = document.getElementById("rodzaj_uslugi"+id).selectedIndex;
	if(ru>=0 && ru<=23)
	{
		document.getElementById("koszt_wizyty"+id).value=koszty[ru];
	}
	ustawKosztCalkowity();
}

function ustawKosztCalkowity()
{
	var x=document.getElementsByTagName("input");
	var sum = 0;
	for(i=0; i<x.length; i++)
	{
		if((x[i].id).substr(0,12) == 'koszt_wizyty')
		{
			sum += Number(x[i].value);
		}
	}
	document.getElementById("kosztCalkowity").innerHTML = sum;
	document.getElementById("doWyplaty").innerHTML = sum/2;
}

function showInfoInne()
{
	if(document.getElementById("info_o_dcp").selectedIndex == 6)
	{
		document.getElementById("info_inne").style.display = '';
	}
	else
	{
		document.getElementById("info_inne").style.display = 'none';
	}
}

function handle_action(link)
{
	document.location.href=link;
}

function submitForm(field, value)
{
	document.getElementById(field).value = value;
	document.getElementById("mainForm").submit();
}

function validate_rb(field)
{
	for(var i=0; i<document.forms.main.elements.length; i++)
	{
		if(document.forms.main.elements[i].name.replace('[]', '') == field)
			if(document.forms.main.elements[i].checked) 
			return true;
	}
	alert(" \"" + name + "\"");
	return false;
}


function validate_ne(name, field)
{
    if(document.forms.main[field].value.length == 0)
	{
	    alert("Pole \"" + name + "\" nie może być puste.");
		return false;
	}
	else return true;
}


function sprawdzFormularzPlatnosci()
{
	for(var i=0; i<document.forms.payform.elements.length; i++)
	{
		if(document.forms.payform.elements[i].name.replace('[]', '') == "pay_type")
			if(document.forms.payform.elements[i].checked)
			{
				document.forms.payform.submit();
				return true;
			}
	}

	alert("Musisz wskazać sposób płatności.");
	return false;
}
