function OptionCopySet(source, destination)
{
	index = source.selectedIndex;
	destination.options[index].selected = true;
}

function SelectOption(list, value)
{
	var index = GetOptionIndex(list, value);
	if ( index ) list.options[index].selected = true;
}

function DeleteOption(source, value)
{
	var index;
	index = GetOptionIndex(source, value);
	if ( index > -1 ) source.options[index] = null;
}

function FieldValueCopy(source, destination)
{
	value = source.value;
	destination.value = value;
}
function usunSpacje(inpucik)
{
	
	var str=inpucik.value;
	var str=str.replace(/ /g, '');
	str=str.replace(/-/g,'');
	inpucik.value=str;
	
	
}

function AddressCopy(form)
{
	if ( form.thesame.checked )
	{
		FieldValueCopy(form.city, form.city2);
		FieldValueCopy(form.postal_code1, form.postal_code1_2);
		FieldValueCopy(form.postal_code2, form.postal_code2_2);
		FieldValueCopy(form.street, form.street2);
		FieldValueCopy(form.street_nr, form.street_nr2);
		FieldValueCopy(form.flat_nr, form.flat_nr2);
		FieldValueCopy(form.city, form.post2);
		FieldValueCopy(form.commune, form.commune2);
		FieldValueCopy(form.post, form.post2);
		OptionCopySet(form.province, form.province2);
		GetOptions(form.province2, form.city_area2, "city_areas", "OptionCopySet(document.forms['" + form.name + "'].city_area, document.forms['" + form.name + "'].city_area2)");
	}
}

function GetOptions(list, destination, what, onload, dir)
{
	if ( !dir ) dir = '';
	var req = mint.Request();
	req.getJSON = true;
	req.OnSuccess = function()
	{
		response = req.responseJSON;
		destination.disabled = false;
		ClearOptions(destination);

		switch ( what )
		{
			case 'departments':
				label 	= 'Urząd Skarbowy';
				value 	= '0';
			break;
			case 'city_areas':
				label 	= 'wybierz powiat';
				value 	= '0';
			break;
			default:
				label 	= 'wybierz';
				value 	= '0';
			break;
		}

		destination.options[0] = new Option(label, value);
		if ( response.length < 1 ) return;
		for ( i = 0; i < response.length; i++ )
		{
			label = response[i]['label'];
			value = response[i]['value'];
			id = i + 1;
			destination.options[id] = new Option(label, value);
	    	}

		if ( IsS(onload) ) eval(onload);
	}

	ClearOptions(destination);
	destination.options[0] = new Option('Proszę czekać', 0);
	destination.disabled = true;
	id = list.options[list.selectedIndex].value;
	req.Send('json.' + what + '.php?id=' + id);
}

function ClearOptions(list)
{
	for ( i = list.options.length; i >= 0; i-- ) list.options[i] = null;
}

function GetOptionIndex(list, value, by)
{
	var index = -1;
	for ( i = 0; i < list.length; i++ )
	{
		if ( !by ) { if ( list.options[i].value == value ) index = i; }
		else { if ( list.options[i].text == value ) index = i; }
	}

	return index = index > -1 ? index : false;
}

function checkChecked(checkbox)
{
	
	if(checkbox.checked==true)
		document.getElementById('chorobowe').disabled=false;
	else
	{	
		document.getElementById('chorobowe').checked=false;
		document.getElementById('chorobowe').disabled=true;
	}
	return;
}