/* Shows confirmation window
* @param string sVal confirmation message
* @return boolean
*/
function sure(sVal)
{
    if (typeof(sVal) == 'undefined' )
        sVal = 'Are you sure ?';
    return confirm(sVal);
}


/* Opens new window
* @param string sUrl URL to open
* @param string sName id of window f.e 'new_win' (not a title!)
* @param int nWidth
* @param int nHeight
* @return boolean false
*/
function openWin(sUrl, sName, nWidth, nHeight)
{
    var oWin = window.open(sUrl, sName, 'left=' + Math.ceil((screen.width - nWidth)/2) + ',top=' + Math.ceil((screen.height - nHeight)/2) + ',width=' + nWidth + ',height=' + nHeight + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,channelmode=0,fullscreen=0');
/*
    oWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Photo</title></head><body style="margin: 0px">');
    oWin.document.write('<img scr="' + sUrl + '" border="0" hspace="0" vspace="0" >');
    oWin.document.write('</body></html>');
*/
    oWin.focus();
    return false;
}


/* Check/uncheck all checkboxes
* @param string sName name of checkboxes group
* @param boolean bVal true- check, false-uncheck
* @return boolean true
*/
function selectAll(sName, bVal)
{
    a = document.getElementsByName(sName);
    for (i=0; i<a.length; ++i)
        a[i].checked = bVal;
    return true;
}


/* return value of the first selected checkbox in group
* @param string sName name of checkboxes group
* @return sting value or ''
*/
function getSelectedVal(sName)
{
    var a = document.getElementsByName(sName);
    for(i=0; i<a.length; ++i)
        if (a[i].checked)
            return a[i].value;

    return '';
}

/* Checks maximum, changes counter value
* @param object oTxt text area to validate
* @param object oCounter input field with counter
* @param integer iMax maximum number of characters
* @return boolean true
*/
function checkMaxChar(oTxt, oCounter, iMax)
{
    oTxt.value = oTxt.value.substr(0, iMax);
    oCounter.value = (iMax - oTxt.value.length);
    return true;
}