

//// počítání napsaných, nebo zbyvajicich znaku
//if numChars is 0, functions return num of char, else returns num chars remains
//if idReturn is null, functions returs value
function counterText(id, numChars, idReturn, endText) {

		  var countObj = document.getElementById(id);
		  var napsane_znaky = countObj.value.length;
		  var delka_textu = napsane_znaky;
		  
		  if (numChars == 0) {
		  	if (idReturn == null) {
		  	  return (delka_textu + endText);
		  	}
		  	else
		  	{
		  	  document.getElementById(idReturn).value = zbyvajici_znaky + endText;
		  	}
		  }
		  else {
		  	var maxdelka = numChars;
		  	var zbyvajici_znaky = maxdelka - delka_textu;
		  
		  	//F.sb.disabled=(char_in==0);
		  	if (zbyvajici_znaky < 0) {
		  	    		  	  textAlert = "Nadpis může obsahovat maximálně " + maxdelka + " znaků";
		    	alert(textAlert);
			    countObj.value = countObj.value.substring(0, maxdelka);
			    napsane_znaky = maxdelka;
			    delka_textu = napsane_znaky;
		    	zbyvajici_znaky = 0;
		  	}
		  	
		  	if (idReturn == null) {
		  	  return (zbyvajici_znaky + endText);
		  	}
		  	else
		  	{
		  	  document.getElementById(idReturn).value = zbyvajici_znaky + endText;
		  	}
		  	
		  }
}

// Dotaz na potvrzeni
function askConfirm(hlaska, url) {
	if (confirm(hlaska)) {
		return location.href = url;
	}
}

function askConfirmSubmit(hlaska, formId, formAction) {
	if (confirm(hlaska)) {
		var myForm = document.getElementById(formId);

		if (formAction != "") {
      myForm.action = formAction;
    }

		myForm.submit();
	}
}

// Dotaz pro zadani hodnoty
function myPrompt(text, url, defaultValue) {
	returned = prompt(text, defaultValue);

	if (returned != null && returned != "") {
    	return location.href = url + returned;
	}
}

// vyplneni hesla do textboxu
function fillPassword(id_textbox1, id_textbox2)
{
	// 6 znaku a povoleny pouze mala pismena a cisla
	var heslo = getPassword(6, false, true, true, false, false, true, true, false, false);
	
	document.getElementById(id_textbox1).value = heslo;
	
	if (id_textbox2 != "")
		document.getElementById(id_textbox2).value = heslo;
		
	alert("Náhodné heslo bylo nastaveno...");
}

// Generovani hesla
function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,
	latterNumber, latterLower, latterUpper, latterOther) {
	var rc = "";
	if (length > 0)
		rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
	for (var idx = 1; idx < length; ++idx) {
		rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
	}
	return rc;
}
function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar(number, lower, upper, other, extra) {
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
	var charSet = extra;
	if (number == true)
		charSet += numberChars;
	if (lower == true)
		charSet += lowerChars;
	if (upper == true)
		charSet += upperChars;
	if (other == true)
		charSet += otherChars;
	return charSet.charAt(getRandomNum(0, charSet.length));
}

// prace s jednim check boxem
function setCheckbox(the_form, do_check, basename)
{
   if (typeof(document.forms[the_form].elements[basename]) != 'undefined') {
       document.forms[the_form].elements[basename].checked = do_check;
   }

   return true;
}


// posledni unchecked checkbox provede neco jinemu checkboxu
function lastCheckbox(the_form, basecheck, do_check, targetcheck)
{
	var ukazatel = 0;

/*
    var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
                  ? document.forms[the_form].elements['selected_db[]']
                  : (typeof(document.forms[the_form].elements[basecheck]) != 'undefined')
          ? document.forms[the_form].elements[basecheck]
          : document.forms[the_form].elements['selected_fld[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;
*/

    var elts      = document.forms[the_form].elements[basecheck];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) 
	{
        for (var i = 0; i < elts_cnt; i++) 
		{
            if (elts[i].checked == true)
            {
				ukazatel = 1;
			}
        }
    }

	if (elts.checked == true)
	{
		ukazatel = 1;
	}

	if (ukazatel == 0) 
	{
		document.forms[the_form].elements[targetcheck].checked = do_check;
	}
    
	return true;
}


// vsechny check boxy v urcitem formulari
function setAllCheckBoxes(FormName, CheckValue, FieldName)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}


// formular povoli pouze psani cisel
// pouziti: onkeypress="return onKeyPressBlockChars(event);"
// neni funkcni v Opere
function onKeyPressBlockChars(event)
{
	//verify for netscape/mozilla
	var isNS4 = (navigator.appName=="Netscape")?1:0;

	var unicode=event.keyCode? event.keyCode : event.charCode

	//alert(unicode)
	
	// povoleno zpetne lomitko, tabulator, enter
	if (unicode != 8 && unicode != 9 && unicode != 13)
	{
		if(!isNS4)
		{
			if(unicode < 48 || unicode > 57) event.returnValue = false;
		}
		else
		{
			if(unicode < 48 || unicode > 57) return false;
		}
	}
} 

// skryvani a zobrazeni polozek, pokud je skryta, zobrazi ji a naopak
function showHideAuto(id) {
        state = (document.getElementById(id).style.display=='' ? 0 : 1);
        document.getElementById(id).style.display = (state ? '' : 'none');
}

// skryje, nebo zobrazi polozku (false, true)
function showHide(id, show) {
        document.getElementById(id).style.display = (show ? '' : 'none');
}

// skryvani a zobrazeni polozek, posledni skryje a novou zobrazi
var xr = new Array(0,0,0,0);
function bclick(c, r) {
        if (xr[c] != r) {
                b_deactivate(c, xr[c]);
                b_activate(c, r);
        }
}
function b_activate(c, r) {
        state = (document.getElementById('id' + c + 'a' + r).style.display=='' ? 0 : 1);
        document.getElementById('id' + c + 'a' + r).style.display = (state ? '' : 'none');
        xr[c] = r;
}
function b_deactivate(c, r) {
        state = (document.getElementById('id' + c + 'a' + r).style.display=='' ? 0 : 1);
		document.getElementById('id' + c + 'a' + r).style.display = (state ? '' : 'none');
}
  
// zmena obrazku na mouse over
/** pouziti
<body onload="MM_preloadImages('pics/bt_profil_.gif','pics/bt_produkty_.gif','pics/bt_kontakty_.gif')">

<a href="profil.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bt_profil1','','pics/bt_profil_.gif',1)"><img src="pics/bt_profil.gif" alt="Profil" name="bt_profil1" width="126" height="20" border="0" id="bt_profil1" /></a>
 */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//////

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function cell_rollover(cell, classname) {
  if (document.all || document.getElementById) {
    cell.classBackup = cell.className;
    cell.className   = classname;
  }
}

function cell_rollout(cell)
{
  if (document.all || document.getElementById) {
    cell.className   = cell.classBackup;
  }
}

 
///// pouze zkusebni

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentClassName = theCells[0].className;
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentClassName = theCells[0].className;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].ClassName = newColor;
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].ClassName = newColor;
            }
        }
    } // end 5

    return true;
} 
