function toggleInputAccess(elId)
{
	var el = document.getElementById(elId);
	if(el == null)
	{
		return false;
	}
	if(el.disabled == 1)
	{
		el.disabled = 0;
	}
	else
	{
		el.disabled = 1;
	}
	return true;
}
function toggleInputAccess_2(elId, parentElId)
{
	var el = document.getElementById(elId);
	var parentEl = document.getElementById(parentElId);
	if(el == null || parentEl == null)
	{
		return false;
	}
	if(parentEl.value)
	{
		el.disabled = 0;
	}
	else
	{
		el.disabled = 1;
	}
	if(parentEl.disabled)
	{
		el.disabled = 1;
	}
	return true;
}
function toggleInputAccess_3(elId, parentElId)
{
	var el = document.getElementById(elId);
	var parentEl = document.getElementById(parentElId);
	if(el == null || parentEl == null)
	{
		return false;
	}
	if(parentEl.value)
	{
		el.disabled = 1;
	}
	else
	{
		el.disabled = 0;
	}
	if(parentEl.disabled)
	{
		el.disabled = 0;
	}
	return true;
}

function js_in_array(the_needle, the_haystack, simpleMatch){
    var the_hay = the_haystack.toString();
    if(!the_hay || !the_needle || (the_hay == ''))
    {
        return false;
    }
    for(var i in the_haystack)
    {
        var the_hay = the_haystack[i];
        if(simpleMatch)
        {
            the_hay = the_hay.toString().toLowerCase();
            the_needle = the_needle.toString().toLowerCase();
        }
        if(the_hay == the_needle)
        {
            return i;
        }
    }
    return false;
}
var nearbyInputIds = [];
function processSelectedOptions(idStorage, selectedElOptions)
{
	for(var i = 0; i < idStorage.length; i++)
	{
		el = document.getElementById(idStorage[i]);
		if(el.selectedIndex > 0)
		{
			selectedElOptions[i] = el.options[el.selectedIndex].value;
		}
	}
}
function toggleNearbyOptions(idStorage)
{
	var selectedElOptions = [];
	processSelectedOptions(idStorage, selectedElOptions);
	_toggleNearbyOptions(idStorage, selectedElOptions)
}
function _toggleNearbyOptions(idStorage, selectedElOptions)
{
	processSelectedOptions(idStorage, selectedElOptions);
	for(var i = 0; i < idStorage.length; i++)
	{
		el = document.getElementById(idStorage[i]);
		for(var j = 0; j < el.options.length; j++)
		{
			el.options[j].disabled = 0;
			in_array_i = js_in_array(el.options[j].value, selectedElOptions);
			if(in_array_i && in_array_i != i && !el.options[j].disabled)
			{
				el.options[j].disabled = 1;
			}
		}
	}
}
function toggleNearbySelects(idStorage)
{
	if(idStorage.length == 1)
	{
		return;
	}
	for(var i = 0; i < idStorage.length - 1; i++)
	{
		el = document.getElementById(idStorage[i]);
		nextEl = document.getElementById(idStorage[i+1]);
		if(el.disabled || !el.selectedIndex)
		{
			if(!nextEl.disabled)
			{
				nextEl.disabled = 1;
				toggleInputAccess_2('direction_' + (i+2) + '_id', nextEl.id);
			}	
			continue;
		}
		nextEl.disabled = 0;
		toggleInputAccess_2('direction_' + (i+2) + '_id', nextEl.id);
	}
}
function check_float_value(elementId, field_title)
{
	element = document.getElementById(elementId);
	var strValue = element.value;
	floatValue = parseFloat(strValue);
	if (floatValue != false && String(strValue) != String(floatValue))
	{
		element.focus();
		element.select();
		alert(field_title+ ': ' + number_str_float);
	}
}
function check_int_value(elementId, field_title)
{
	element = document.getElementById(elementId);
	var strValue = element.value;
	intValue = parseInt(strValue);
	if (intValue != false && String(strValue) != String(intValue))
	{
		element.focus();
		element.select();
		alert(field_title+ ': ' + number_str_int);
	}
}