// Declaring required variables
var digits = "0123456789";
// non-digit characters whiAch are allowed in ico numbers
var icoNumberDelimiters = "()- ";
// characters which are allowed in international ico numbers
// (a leading + is OK)
var validWorldIcoChars = icoNumberDelimiters + "+";
// Minimum no of digits in an international ico no.
var minDigitsInIIcoNumber = 8;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalIco(strIco){
s=stripCharsInBag(strIco,validWorldIcoChars);
return (isInteger(s) && s.length == minDigitsInIIcoNumber);
}

function checkICO(){
	var Ico=document.formular.ico

	if ((Ico.value==null)||(Ico.value=="")){
		alert("Vložte IČO")
		Ico.focus()
		return false
	}
	if (checkInternationalIco(Ico.value)==false){
		alert("Vložte správné IČO/KÓD!\nIČO/KÓD musí obsahovat 8 číslic 0-9")
		Ico.value=""
		Ico.focus()
		return false
	}
	return true
 }
function visi(nr)
{
if (document.layers)
 {
 vista = (document.layers[nr].visibility == 'hide') ? 'show' : 'hide'
 document.layers[nr].visibility = vista;
 }
 else if (document.all)
 {
 vista = (document.all[nr].style.visibility == 'hidden') ? 'visible' : 'hidden';
 document.all[nr].style.visibility = vista;
 }
 else if (document.getElementById)
 {
 vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden';
 document.getElementById(nr).style.visibility = vista;

 }
}

function blocking(nr)
{
 if (document.layers)
 {
 current = (document.layers[nr].display == 'none') ? 'block' : 'none';
 document.layers[nr].display = current;
 }
 else if (document.all)
 {
 current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
 document.all[nr].style.display = current;
 }
 else if (document.getElementById)
 {
 vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
 document.getElementById(nr).style.display = vista;
 }
}

function clearText(field){

    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}
function zeptatPocet(url,varname) {
  var pocet;
  pocet=window.prompt("Zadejte počet",1);
  document.location=url+"&"+varname+"="+pocet;
}
function sel(xObject, zal)
{
  var x,y,i,ii
  x = document.getElementById("zalozky").childNodes;
  for (i=0;i<x.length;i++)
  {
  if (x[i].nodeType==1 && Boolean(x[i].nodeName=="A"))
  {
  x[i].className="z1";
  }
  }
  xObject.className="z2";
  y = document.getElementById("pole").childNodes;
  for (ii=0;ii<y.length;ii++)
  {
  if (y[ii].nodeType==1 && Boolean(y[ii].nodeName=="DIV"))
  {
  y[ii].className="p1";
  }
  }
  document.getElementById(zal).className="form";
}
var value = 0;
function fadeout(){

	if(value < 255) {
		value += 10;
		document.getElementById("msgFade").style.color="rgb(255,"+value+","+value+")";
		ID = setTimeout("fadeout()",20);
	}
	else {
		clearTimeout(ID);
	}

}
function fade(){
	setTimeout("fadeout()",5000);
}

var namesVec = new Array("bullet_add.png", "bullet_delete.png");
var root ='ico/';
function swapImg(ima){
// divides the path
nr = ima.getAttribute('src').split('/');
// gets the last part of path, ie name
nr = nr[nr.length-1]
// former was .split('.')[0];

if(nr==namesVec[0]){ima.setAttribute('src',root+namesVec[1]);}
else{ima.setAttribute('src',root+namesVec[0]);}

}

