/*** go fce *********************/
function goTo(uri)
{
	o = parent.frameBody
	if(o == null){o=this}
	o.location=uri;
}

/* i.e features: directories=no,location=no,menubar=no,status=no,resizable=yes,scrollbars=auto */
function openWindow(uri, windowName, features){
	openWindowDim(900, 600, uri, windowName, features);
}
function openWindowDim(w, h, uri, windowName, features){
	if(features==null || features.length == 0)
		features = "directories=no,location=no,menubar=no,status=no,resizable=yes,scrollbars=auto";
	var 
		winLeft = w > 0?(screen.width - w) / 2 : 0,
		winTop = h > 0?(screen.height - h) / 2 : 0;
	if (winLeft < 0) winLeft = 0; if (winTop < 0) winTop = 0;
	features = 
		(h>0?'height=' + h + ',':'') +
		(w>0?'width=' + w + ',':'') +
		(winTop>0?'top=' + winTop + ',':'') +
		(winLeft>0?'left=' + winLeft + ',':'') + 
		features;
	var win = window.open(uri, windowName, features);
	win.window.focus();
}

/*
*	Kontrola zadaneho cisla aby bylo celociselne a v rozmezi(vcetne) minValue a maxValue.
*	Pokud nesplnuje podminky je nastavena hodnota na defaultValue.
*	Pouziva se na onChange u textboxu atp. <input type="text" onChange="checkInputValueInteger(0, 10, 0)" ...
*/
function checkInputValueInteger(minValue, maxValue, defaultValue)
{
	if(!isInt(Math.abs(event.srcElement.value)) || parseInt(event.srcElement.value,10) < minValue || parseInt(event.srcElement.value,10) > maxValue)
		event.srcElement.value = defaultValue;
}
function checkInputValueFloat(minValue, maxValue, defaultValue)
{
	if(!isFloat(Math.abs(event.srcElement.value)) || parseFloat(event.srcElement.value) < minValue || parseFloat(event.srcElement.value) > maxValue)
		event.srcElement.value = defaultValue;
}
function checkInputValueNifosDate(defaultValue)
{
	if(getValidNifosDate(event.srcElement.value) == null)
		event.srcElement.value = defaultValue;
}

/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
	RETVAL:
		The formatted number!
 **********************************************************************/
function FormatNumber(num, decimalNum, bolLeadingZero)
{ 
	if (isNaN(parseInt(num,10))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
		
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);

	var spl = tmpNumStr.split("."), dec;
	dec = spl.length > 1 ? spl[1]:"";
	for (i = spl.length > 1 ? spl[1].length : 0; i < decimalNum; i++)
		dec += "0";
	tmpNumStr = spl[0] + "." + dec;

	return tmpNumStr;		// Return our formatted string!
}


/* controls */
function listBoxRemoveAll( strListBox )
{
	var oListBox = document.getElementById(strListBox);
	var rowCount = oListBox.options.length;
	for( var i = rowCount - 1; i >= 0; i-- )
		oListBox.options[i] = null;
}
function listBoxAdd( strListBox, arItems/*"[value][delim][name]"*/, delim )
{
	var oListBox = document.getElementById(strListBox);
	alert(arItems);
	for (var i = 0; i < arItems.length; i++)
	{
		var s = new String(arItems[i]);
		ss = s.split(delim);
		oListBox.options[oListBox.options.length] = new Option(ss[1],ss[0]);
	}
}
function hideControl(id)
{
	o = document.getElementById(id);
	if(o!=null)
		o.style["display"] = "none";
}
function showControl(id)
{
	o = document.getElementById(id);
	if(o!=null)
		o.style["display"] = "";
}
function setControlVisibility(id, show)
{
	if(show)
		showControl(id);
	else
		hideControl(id);
}
function toggleControl(id)
{
	o = document.getElementById(id);
	if(o!=null)
		o.style["display"] = (o.style["display"]==""?"none":"");
}
function setControlValue(id, value)
{
	o = document.getElementById(id);
	if(o!=null) o.value = value;
}
function getControlValue(id)
{
	o = document.getElementById(id);
	return o!=null ? o.value : null;
}
/***
 *** Cookies
 ***/
function getCookie(name, defaultValue)
{ 
	var start = document.cookie.indexOf(name+"="); 
	var len = start+name.length+1; 
	if ((!start) && (name != document.cookie.substring(0,name.length))) return defaultValue; 
	if (start == -1) return defaultValue; 
	var end = document.cookie.indexOf(";",len); 
	if (end == -1) end = document.cookie.length; 
	return unescape(document.cookie.substring(len,end)); 
} 

function setCookie(name, value, expires, path, domain, secure)
{ 
	var cookieString = name + "=" +escape(value) + 
	   ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
	   ( (path) ? ";path=" + path : "") + 
	   ( (domain) ? ";domain=" + domain : "") + 
	   ( (secure) ? ";secure" : ""); 
	document.cookie = cookieString; 
} 

function deleteCookie(name, path, domain)
{ 
	if (getCookie(name))
		document.cookie = name + "=" + 
			( (path) ? ";path=" + path : "") + 
			( (domain) ? ";domain=" + domain : "") + 
			";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
} 
