
var http_root = "";

function setFocus(elName)
{
	var el = document.getElementById(elName);
	if(el)
	{
		el.focus();
	}
} // setFocus

function submitForm(form)
{
	el = document.getElementById(form);
	if(el.submit)
	{
		el.submit();
	}
} // submitForm

function changeStyle(el, className)
{
	el.className = className;
} // changeStyle

function pop(theURL,w,h,name,feat)
{
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;

	if(!feat)
	{
		feat = 'fullscreen=0,toolbar=0,status=0,scrollbars=1,menubar=0,location=0,resizable=0,channelmode=0,directories=0';
	}

	feat += ',width=' + w + ',height=' + h + ',top=' + t +',left=' + l;

	window.open(theURL, name, feat);
} // pop

function checkAll(form, what, prefix)
{
	if(!prefix)
	{
		prefix = '';
	}

	for (var i = 0; i < form.elements.length; i++)
	{
		var e = form.elements[i];
		if ( (e.type == 'checkbox') && (e.name.substr(0, prefix.length) == prefix))
		{
			if(form[what.name].checked != e.checked)
			{
				e.click();
			}
		}
	}
}

function resizeWindowFrom(referer)
{
	var el = document.getElementById(referer);

	if(el && el.clientHeight && el.clientWidth)
	{
		var nw = el.clientWidth + 24;
		var nh = el.clientHeight + 80;

		if(nh > screen.availHeight * 0.9)
		{
			nh = screen.availHeight * 0.9;
		}

		if(nw > screen.availWidth * 0.9)
		{
			nw = screen.availWidth * 0.9;
		}

		window.resizeTo(nw, nh);
		window.moveTo((screen.width - nw) / 2, (screen.height - nh) / 2);
	}
} // resizeWindowFrom

function div_show(id)
{
	var div = document.getElementById(id);
	if(div && div.style)
	{
		div.style.display = 'block';
	}
} // div_show

function div_hide(id)
{	var div = document.getElementById(id);
	if(div && div.style)
	{
		div.style.display = 'none';
	}
} // div_hide

function div_show_hide(id)
{
	var div = document.getElementById(id);
	if(div && div.style)
	{
		if(div.style.display == 'none')
		{
			div_show(id);
		} else {
			div_hide(id);
		}
	}
} // div_show_hide

function toFloat(val)
{
	return isNaN(val) ? 0 : parseFloat(val);
} // toFloat

function toInt(val)
{
	return isNaN(val) ? 0 : parseInt(val);
} // toInt

function confirmAction(msg, href)
{
	if(confirm(msg))
	{
		location.href = href;
	}
} // confirmAction

function getElement(elName)
{
	var el = document.getElementById(elName);

	return el;
} // getElement

function isChecked(id)
{
	var id = getElement(id);

	return id && id.checked;
} // isChecked

function check_tps_mitnes(el, id)
{
	if(el.checked)
	{
		div_show(id);
	} else {
		div_hide(id);
	}
} // check_tps_mitnes

function getCalendar(fieldName)
{
	window.open(http_root + '/calendar/calendar.php?field_name=' + fieldName, 'cal', 'width=180,height=180,resizable=no,status=no,scrollbars=no,titlebar=no');
} // getCalendar

function expand(img, div_id)
{
	div_show(div_id);
	img.src = http_root + '/img/expanded.gif';
	img.title = 'Sakļaut';
	img.alt = 'Sakļaut';
} // expand

function collapse(img, div_id)
{
	div_hide(div_id);
	img.src = http_root + '/img/expand.gif';
	img.title = 'Izvērst';
	img.alt = 'Izvērst';
} // expand

function expand_collapse(img, div_id)
{
	var div = document.getElementById(div_id);
	if(div && div.style)
	{
		if(div.style.display == 'none')
		{
			expand(img, div_id);
		} else {
			collapse(img, div_id);
		}
	}
} // expand_collapse

