function showNewWindow( openHref, w, h ) {
    var params = "width=" + w + ",height=" + h + ",location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes";
    /*
     if ( !browser.opera ) {
     params = params + ",left=" + ((screen.width - w) / 2) + ",top=" + ((screen.height - h) / 2);
     }
     */

    var newWindow = window.open(openHref, 'newWindow', params);
    newWindow.focus();

}

//wykorzystywana do aktualizacji pola textarealimited
function updateLimitDesc( form, field, limitName, maxLen, alertText ) {
    var txt = form.elements[field].value;
    var txtLen = txt.length;
    var numLeft = 0;

    if ( txtLen > maxLen ) {
        form.elements[field].value = txt.substring(0, maxLen);
        //        alert(alertText);
    } else {
        numLeft = maxLen - txtLen;

    }

    form.elements[limitName].value = numLeft;
}

//na razie ta fukcyjka ponizej jest nieuzywana
function doSubmitOnEnterPress( aEvent, form, exec ) {
    alert(aEvent.type);
    alert(aEvent.target.name);
    alert(aEvent.modifiers);
    if ( window.Event ) {
        kodKlawisza = aEvent.which;
    } else {
        kodKlawisza = aEvent.keyCode;
    }

    if ( kodKlawisza == 13 ) {//Enter
        form.execute.value = exec;
        form.submit();
    }

}

function selectAllCheckbox( form, property, check ) {
    if ( form.elements[property] != null ) {
        var len = form.elements[property].length;
        if ( len > 0 ) {
            for ( i = 0; i < form.elements[property].length; i++ ) {
                if ( !form.elements[property][i].disabled ) {
                    form.elements[property][i].checked = check;
                }
            }
        } else {
            if ( !form.elements[property].disabled ) {
                form.elements[property].checked = check;
            }
        }
    }
}

function showAnswer( num ) {
    if ( document.getElementById("answer" + num).style.display == "none" ) {
        document.getElementById("answer" + num).style.display = "block";
    } else {
        document.getElementById("answer" + num).style.display = "none";
    }
}

function countSelectedCheckboxes( form, property ) {
    var len = form.elements[property].length;
    var c = 0;
    if ( len > 0 ) {
        for ( i = 0; i < form.elements[property].length; i++ ) {
            if ( form.elements[property][i].checked ) {
                c++;
            }
        }
    } else {
        if ( form.elements[property].checked ) {
            c = 1;
        }
    }
    return c;
}


function checkListSelection( form, property, alertMsg ) {
    if ( countSelectedCheckboxes(form, property) == 0 ) {
        alert(alertMsg);
        return false;
    }
    return true;
}

function hideSelectNewEntry( comboFieldId, textFieldId ) {
    var comboField = document.getElementById(comboFieldId);
    var textField = document.getElementById(textFieldId);
    if ( comboField.value == '-1' ) {
        textField.disabled = false;
        textField.style.display = 'block';
    } else {
        textField.disabled = false;
        textField.style.display = 'none';
    }
}


function zoomTextarea(obj)
{
    obj.rows = obj.rows + 5;
}

function zoomOutTextarea(obj)
{
    obj.rows = obj.rows - 5;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
