window.onload =function() {

	var tabEls = document.getElementsByClassName("tab");
	var width = document.getElementById("private").offsetWidth;
	var newWidth = width;
	var elWidth = 0;
	for (var i=0; i <= (tabEls.length-1); i++) {
		elWidth =tabEls[i].offsetWidth;
		if (elWidth > newWidth) {
			newWidth = elWidth;
		}
	}
	if (newWidth > width) {
		newWidth += 20;
		document.getElementById("private").style.width = newWidth + 'px';
	}
}
 

function firstUpper(name) {
	//prvni pismeno velke
	
	var el = document.getElementById(name);
	var tmp;
	
	if (el.value.length > 0) {
		tmp = el.value.charAt(0).toUpperCase();
		if (el.value.length > 1) {
			tmp = tmp + el.value.substring(1, el.value.length);
		}
		el.value = tmp;
	}
	return true;
	
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array; 

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function markAllRows(container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }

    return true;
}

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function unMarkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
    }

    return true;
}

function markRow( row_id ) {
    var row = document.getElementById(row_id);
    var unique_id;
    var checkbox;
	  checkbox = row.getElementsByTagName( 'input' )[0];

    if ( checkbox && checkbox.type == 'checkbox' ) {
      unique_id = checkbox.name;

      if (checkbox.checked == true) { 
      	row.className += ' marked';
        marked_row[unique_id] = true;
		    return true;

      } else { 
      	row.className = row.className.replace(' marked', '');
        marked_row[unique_id] = false;
				checkbox.checked = false;
        return false;
      }
      
    }

}  


function payment_list_show_dnu() {

	if (document.getElementById('s_datem').checked) {
		document.getElementById('payment-list-zobrazit-dnu').style.display='table-row';
		document.getElementById('payment-list-zobrazit-dnu2').style.display='table-row';		
	} else {
		document.getElementById('payment-list-zobrazit-dnu').style.display='none';
		document.getElementById('payment-list-zobrazit-dnu2').style.display='none';

	}
}

var appWindow = null;

function OpenWindow(link, features)
{
  appWindow = window.open(link, 'appwindow', features);
  //Pozor, definice proměnné msg musí být napsána na jednom řádku!
  appWindow.focus()
}

function closeWindow() 
{
  if (appWindow != null) 
  {
    if (!appWindow.closed) 
    {
      appWindow.close();
    }
    appWindow = null;
  }
}

function toggle(obj) {
    var el = document.getElementById(obj);
    el.style.display = (el.style.display != 'none' ? 'none' : '' );
}
	
function initialCap(field) {
	   field.value = field.value.substr(0, 1).toUpperCase() + field.value.substr(1);
	}


function getSize($size) {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  
	  if ($size = 'width')
		 return myWidth; 	
	  
	  return myHeight;
}

function checkLength(element, minLength) {

	if (element.value.length < minLength) {
		alert('Položka musí obsahovat nejméně ' + minLength + ' znaků!');	
	}
}


