// globalni klientske funkce
function ShowRow(id,t)
{
	document.all[id].style.backgroundColor=b[t];
	document.all[id].style.color=c[t];
}

function Icon(name, file, action, title, c,param) 
{
	if (!c) c='Silver';
 	var txt='<img class="Icon" style="border-color:'+c+'" onmouseover="this.style.borderColor=\'White Gray Gray White\'" onmouseout="this.style.borderColor=\''+c+'\'"';
	txt+=' src="'+file+'" onclick="'+action+'" title="'+title+'" name="'+name+'" ';
	if (param) txt+=param;
	txt+='>';
	return txt;
}

function IIf(condition,valt,valf)	//stejne jako ve VB
{
	if(condition) return valt
	else return valf;
}

function FormTab(str)		//zrusi nasobne tabulatory v retezci
{
	var a=0;
	while (a<str.length) {
		from=str.substr(a,1);
		if (from!='\t') a++;
		else if ((str.substr(a+1,1)=='\t') && (a+1<str.length)) str=str.substring(0,a)+str.substring(a+1,str.length);
		else a++;
	}
	return str;
}

function UnTab(str)		//zrusi tabulatory v retezci
{
	var a=0;
	while (a<str.length) {
		from=str.substr(a,1);
		if (from!='\t') a++;
		else str=str.substring(0,a)+str.substring(a+1,str.length);	  
	}
	return str;
}

function Triad(str,d)
{
	var a=new Array();
	var i;
	while(str.length>3) {
		a[a.length]=str.substr(str.length-3,3);
		str=str.substr(0,str.length-3);
	}
	for(i=0;i<a.length;i++) str+=d+a[a.length-i-1];
	return str;
}

function iStr(rs)
{
	str=String(rs);
	if(str.toUpperCase()=='NULL' || str.toUpperCase()=='UNDEFINED') str='';
	return str;
}

function Zero(p,n)
{
	var s='000000000000'+p;
	return s.substr(s.length-n,n);
}

function IsFull1(a)	//zjisti, zda li jsou v kolekci nejake prvky (kdyz nelze pouzit vlastnost .length)
{
	var idx=0;
	var b;
	for(b in a) 
		if (idx>0) return true
		else idx++;
	return false;
}

function IsFull2(a)	//zjisti, zda li jsou v kolekci nejake prvky (kdyz nelze pouzit vlastnost .length)
{
	var idx=false;
	for(b in a) {
	 	idx=true;
		break;
	}
	return idx;
}

function ItemCount(a,par)	//spocita prvky v kolekci (kdyz nelze pouzit vlastnost length)
{
	var idx=0;
	var b;
	for(b in a) if ((!par) || (a[b])) idx++;
	return idx;
}

function IsNull(x) 
{ 
	if( x==null ) return true;
	if( x=='' ) return true;
	if((''+x) == 'undefined') return true;
	return false;
}

function TrimR(s)
{
	while(s.substr(s.length-1,1)==' ') {
		s=s.substr(0,s.length-1);
	}
	return s;
}

function ToggleDisplay(obj)
{
	if(obj.style.display=='none') obj.style.display='';
	else obj.style.display='none';
}

function SwapBranch(id)
{
	if(document.all['B'+id].style.display=='none') 
		{document.all['B'+id].style.display='';
		 document.all['I'+id].src=IP+'arrow1_c.gif';
	} else {
		document.all['B'+id].style.display='none';
		document.all['I'+id].src=IP+'arrow1_p.gif';
	}
}
function SelectItem(i,typ)
{
	if(typ) {
		document.all['TD'+i].style.borderColor='Black #DDDDDD #DDDDDD Black';
		document.all['TD'+i].style.color='White';
	} else {
		document.all['TD'+i].style.borderColor='#DDDDDD Black Black #DDDDDD';
		document.all['TD'+i].style.color='Black';
	}
}
function SelIcon(obj, brd, src, bck)
{
	obj.style.borderColor=brd;
	obj.src=src;
	obj.style.backgroundImage='url(\''+bck+'\')';
}

function DispTime()
{
	var d=new Date();
	var tim=d.getDate()+'.'+Number(d.getMonth()+1)+'.'+d.getYear()+' '+Zero(d.getHours(),2)+':'+Zero(d.getMinutes(),2);
	document.all.DT.innerText=tim;
	setTimeout("DispTime()",30000)
}
function PrintWin(tab,col,ord)
{
	window.open("print.asp?TAB="+tab+"&COL="+col+"&ORD="+ord,"Tisk","alwaysRaised=Yes,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=400,height=550,dependent=yes");
}

function ShowValue(Obj)
{
 var Bar = document.all.ShowBar;
 var OSelect = document.all[Obj];
 var X = OSelect.offsetParent.offsetLeft + OSelect.offsetParent.offsetWidth + 2;
 var Y = OSelect.offsetParent.offsetTop + OSelect.offsetTop ;

 Bar.style.width = 160;
 Bar.style.fontFamily = 'Arial';
 Bar.style.fontSize = 11;
 Bar.style.left = X  + 'px';
 Bar.style.top = Y  + 'px';
 Bar.style.border='1px solid black';
 Bar.style.backgroundColor = 'infobackground';
 Bar.style.zIndex=10;
 if(OSelect.options) var TextToShow = OSelect.options[OSelect.selectedIndex].text;
 else var TextToShow = OSelect.value;
 if (TextToShow.length > 22)
    {
      Bar.innerHTML = TextToShow;
      Bar.style.display = "";
    }
}
function HideValue()
{
  if (window.event.toElement != null) document.all.ShowBar.style.display = 'none';
}
function IsNumeric( checkStr )//KOntrola zda zadana hodnota je cislo
{
  var checkOK = "0123456789.";
  var isValid = true;

  for( i = 0;  i < checkStr.length;  i++ )
  {
    ch = checkStr.charAt( i );
    for( j = 0;  j < checkOK.length; j++ )
      if( ch == checkOK.charAt( j ) )
        break;
    if( j == checkOK.length )
    {
      isValid = false;
      break;
    }
  }
  return isValid;
}

function IsDate( checkStr ) //Nova kontrolni funkce pro datum
{
  var isValid = true;

  var arrDate = new Array();
  var DatePart = new String();

  if (checkStr.length == 0) return isValid;

  arrDate = checkStr.split(".");



  if (arrDate.length !=3)
   {
      isValid = false;
      return isValid
   }

  DatePart = arrDate[2];

  if (DatePart.length !=4)
   {
      isValid = false;
      return isValid
   }

   if (!IsNumeric(arrDate[0]))
   {

      isValid = false;
      return isValid
   }
   if (!IsNumeric(arrDate[1]))
   {
      isValid = false;
      return isValid
   }
   if (!IsNumeric(arrDate[2]))
   {
      isValid = false;
      return isValid
   }

   if (arrDate[0] > 31)
   {
      isValid = false;
      return isValid
   }
   if (arrDate[1] > 12)
   {
      isValid = false;
      return isValid
   }
  return isValid;
}

function IsEmail(str)
{
	var j = new RegExp(); 
        j.compile("[A-Za-z0-9._-]+@[^.]+\..+"); 
        if (!j.test(str)) return false;
		else return true;
}

function IsURL(str)
{
	var j = new RegExp(); 
		j.compile("^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+"); 
		if (!j.test(str)) return false; 
		else return true;
}