
var MaxLengthLock = false;

function MaxLengthCount(fieldObj)
{
  if (!MaxLengthLock)
  {
    MaxLengthLock = true;
    if (fieldObj.value.length > 200)
    {
      alert("Velikost textu je omezena na 200 znaků!");
      fieldObj.value = fieldObj.value.substring(0,200);
    }
    var percentage = parseInt(100 - (( 200 - fieldObj.value.length) * 100)/200);
    document.getElementById(fieldObj.id + "_PBar").style.width = parseInt((parseInt(fieldObj.offsetWidth)*percentage)/100)+"px";
    MaxLengthLock = false;
  }
} 

function validateNumber(inp) {
	rx = /[^0-9]/;
	if(rx.test(inp.value)) {
		alert('Zadejte číslo ve správném formátu 1234. Pouze celé číslo bez desetinných míst.'+inp.id);
		
		globalvar = document.getElementById(inp.id);
		setTimeout("globalvar.focus()",1);
		document.getElementById(inp.id).select();
	}
}
function testLogin(inp) {
	rx = /^([0-9a-zA-Z\.\-\_]{3,100})$/;
	if(!rx.test(inp.value)) {
		alert('Povolené znaky jsou malá a velká písmena bez diakritiky, čísla, tečka, pomlčka a podtržítko. Minimální délka je 3 znaky. Zakázaná slova jsou aukce, shop a inzerce.');
	}
}

function AddFavorite(linkObj,addUrl,addTitle)
{
  if (document.all && !window.opera)
  {
    window.external.AddFavorite(addUrl,addTitle);
    return false;
  }
  else if (window.opera && window.print)
  {
    linkObj.title = addTitle;
    return true;
  }
  else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
  {
    if (window.confirm('Přidat oblíbenou stránku jako nový panel?'))
    {
      window.sidebar.addPanel(addTitle,addUrl,'');
      return false;
    }
  }
  window.alert('Po potvrzení stiskněte CTRL-D stránka bude přidána k vašim oblíbeným odkazům.');
  return false;
}

function alternate_init() {
	// Find all tables with class sortable and make them sortable
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		//if (((' '+thisTbl.className+' ').indexOf(\"alternate_rows\") != -1) && (thisTbl.id)) {
			alternate(thisTbl);
		//}
	}
}

function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	// Take object table and get all it's tbodies.
	var tableBodies = table.getElementsByTagName("tbody");
	// Loop through these tbodies
	for (var i = 0; i < tableBodies.length; i++) {
		// Take the tbody, and get all it's rows
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		// Loop through these rows
		for (var j = 0; j < tableRows.length; j++) {
			// Check if j is even, and apply classes for both possible results
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			} 
		}
	}
}

window.onload = function() {
	alternate_init();
    changeTypeFilter(document.forms[0]);
}


