
function disableButton(button) {
	if (document.getElementById(button) != null) {
		document.getElementById(button).disabled = true;
	}
}

/**
 * Funkcja aktywuje/deaktywuje przyciski modyfikuj oraz usuń w zależności
 * od ilości zaznaczonych elementów (checkboxów) reprezentowanych przez list.
 * @param list
 * @param modifyButton
 * @param removeButton
 * @return
 */
function switchButtons(list, editButton, removeButton, viewButton)
{

	count = 0;	
	
	// Jeżeli na stronie wyświetlony jest tylko jeden wiersz, to lista jest checkboxem a nie listą.
	if (list.length > 0)
	{
		for (i = 0; i < list.length; i ++)
		{
			if (list[i].checked == true)
			{
				count += 1;
			}
		}
	}
	else
	{
		if (list.checked == true)
			count = 1;
		else
			count = 0;
	}

	if (count == 1)
	{
		if (editButton != null) {
			document.getElementById(editButton).disabled = false;
		}
		
		if (viewButton != null) {
			document.getElementById(viewButton).disabled = false;
		}
	}
	else
	{
		if (editButton != null) {
			document.getElementById(editButton).disabled = true;
		}
		
		if (viewButton != null) {
			document.getElementById(viewButton).disabled = true;
		}
	}

	if (count >= 1)
	{
		if (removeButton != null) {
			document.getElementById(removeButton).disabled = false;
		}
	}
	else
	{
		if (removeButton != null) {
			document.getElementById(removeButton).disabled = true;
		}
	}
	
	//alert("Count:" + count);
}

 function switchButtons(list, button1, button2)
 {

 	count = 0;	
 	
 	// Jeżeli na stronie wyświetlony jest tylko jeden wiersz, to lista jest checkboxem a nie listą.
 	if (list.length > 0)
 	{
 		for (i = 0; i < list.length; i ++)
 		{
 			if (list[i].checked == true)
 			{
 				count += 1;
 			}
 		}
 	}
 	else
 	{
 		if (list.checked == true)
 			count = 1;
 		else
 			count = 0;
 	}


 	if (count >= 1)
 	{
 		if (button1 != null) {
 			document.getElementById(button1).disabled = false;
 		}
 		if (button2 != null) {
 			document.getElementById(button2).disabled = false;
 		}
 	}
 	else
 	{
 		if (button1 != null) {
 			document.getElementById(button1).disabled = true;
 		}
 		if (button2 != null) {
 			document.getElementById(button2).disabled = true;
 		}
 	}
 	
 	//alert("Count:" + count);
 }

/**
 * Funkcja przełącza div z z trybu none na block i na odwrót.
 * Nazwa div'a musi spełniać format div_<nazwa>
 * Jeżeli jest podany obrazek, to jest podmieniany (na przykład + na -)
 * @param p_id
 * @return
 */
function switchDiv(p_id){

    div = document.getElementById('div_' + p_id);
    img = document.getElementById('img_' + p_id);
    
    if (div.style.display == null || div.style.display == 'none' || div.style.display == '')
    {
        div.style.display = 'block';
        
        if (img != null)
        	img.src = 'images/minus_symbol.png';
    }
    else
    {
        div.style.display = 'none';
        
        if (img != null)
        	img.src = 'images/plus_symbol.png';
    }
}

/**
 * Funkcja ustawia kursor na wybranej kontrolce typu text
 * 
 * @param focusControl -
 *            nazwa kontrolki
 * @return
 */
function placeFocus(focusControl) {

	if (!document.forms || !document.forms[0] || !document.forms[0].elements)
		return;

	var matchedControl = document.getElementById(focusControl);
	
	if (matchedControl != null && matchedControl.type == 'text')
		matchedControl.focus();
}

/**
 * Funkcja dodaje podswietlenie dla wiersza, na ktorym znajduje sie aktualnie kursor
 * 
 * @param displaytagUID
 * @return
 */
function highlightRow(displaytagUID) {
	
    var table = document.getElementById(displaytagUID);
    
    if (table != null) {
    
	    var rows = table.getElementsByTagName("tr");
	    for (i=1; i < rows.length; i++) {
	
	        rows[i].onmouseover = function() { this.className='highlight'; };
	
			if (i%2 == 0)
	        	rows[i].onmouseout = function() { this.className='even'; };
	        else
	        	rows[i].onmouseout = function() { this.className='odd'; };
	    }
    
    }
}


function wait(delay){
  string="pauseforalert("+delay+");";
  setTimeout(string,delay);
}

function pauseforalert(delay){
  //alert("Ok "+delay/1000+" seconds have elapsed");
  window.location = gotourl;
}


