function makeChangedRowChecked(formName, rowNR, usedElement, oldValue, usedBgColor, usageType, isChecked) {

    var elementName = 'rid[' + rowNR + ']';
    var rowCheckbox = formName[elementName];
    var rowElement = formName[usedElement];
    var rowElementOldValue = oldValue;

    if (rowCheckbox == null) {
        rowCheckbox = formName[elementName]
    };

    if (rowCheckbox) {
        var parentTR = getParent(rowCheckbox);
        if (usageType == 'checked') {
            if (isChecked == 'y') {
                if (rowCheckbox.checked) {
                    parentTR.className = (rowCheckbox.checked) ? 'recordset_row_selected' : usedBgColor;
                } else {
                    rowCheckbox.checked = true;
                    parentTR.className = (!rowCheckbox.checked) ? usedBgColor : 'recordset_row_selected';
                }
            } else {
                if (!rowCheckbox.checked) {
                    rowCheckbox.checked = true;
                    parentTR.className = (!rowCheckbox.checked) ? usedBgColor : 'recordset_row_selected';
                } else {
                    parentTR.className = (rowCheckbox.checked) ? 'recordset_row_selected' : usedBgColor;
                }
            }
        } else {
            if (rowElement.value != rowElementOldValue) {
                rowCheckbox.checked = true;
            } else {
                rowCheckbox.checked = false;
            }
            parentTR.className = (rowCheckbox.checked) ? 'recordset_row_selected' : usedBgColor;
        }
    }
    rowCheckbox = null;
}


function checkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 1; i < rows.length; i++ ) {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];
        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(selectedRow[unique_id]) == 'undefined' || !selectedRow[unique_id] ) {
                    rows[i].className += ' recordset_row_selected';
                    selectedRow[unique_id] = true;
                }
            }
        }
    }

    return true;
}

function uncheckAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 1; i < rows.length; i++ ) {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];
        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' recordset_row_selected', '');
            selectedRow[unique_id] = false;
        }
    }

    return true;
}


var selectedRow = new Array;

function initCheckRows() {
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        if ( 'recordset_row_odd' != rows[i].className.substr(0,23) && 'recordset_row_even' != rows[i].className.substr(0,24) ) {
            continue;
        }
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            rows[i].onmouseover = function() {
                this.className += ' recordset_row_hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' recordset_row_hover', '' );
            }
        }
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(selectedRow[unique_id]) == 'undefined' || !selectedRow[unique_id] ) {
                selectedRow[unique_id] = true;
            } else {
                selectedRow[unique_id] = false;
            }

            if ( selectedRow[unique_id] ) {
                this.className += ' recordset_row_selected';
            } else {
                this.className = this.className.replace(' recordset_row_selected', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = selectedRow[unique_id];
            }
        }

        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}
window.onload=initCheckRows;


function textCounter( field, countfield, maxlimit ) {
    if ( field.value.length > maxlimit ) {
        field.value = field.value.substring( 0, maxlimit );
        field.blur();
        field.focus();
        return false;
    } else {
        countfield.value = maxlimit - field.value.length;
    }
}


function fieldRegexpFilter(r_event, r_regexp) {
    var theChar = "", r_founded = false;

    if(document.all) {
        r_event = window.event;
        theChar = String.fromCharCode(r_event.keyCode);
        if(!r_event.shiftKey) theChar = theChar.toLowerCase();
        r_founded = r_regexp.test(theChar);
        r_event.returnValue = r_founded;
    } else if (document.layers) {
        theChar = String.fromCharCode(r_event.which);
        r_founded = r_regexp.test(theChar)
    } else {
        theChar = String.fromCharCode(r_event.charCode);
        r_founded = (r_event.keyCode!=0) || r_regexp.test(theChar);
        r_event.cancelBubble = !r_founded;
    }

    return r_founded;
}


function getParent(el) {
    if (document.all)
    while (el.parentElement != null)
    if (el.tagName == 'TR') return el;
    else el = el.parentElement;
    else if (document.getElementById) {
        if (el.nodeType == 1 && el.tagName.toLowerCase() == 'tr') return el;
        else return getParent(el.parentNode);
    }
}


function trimString(string) {
    return string.replace(/^\s*|\s*$/g,"");
}


// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    do {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);

        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2)) {
            enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
            enc4 = 64;
        }

        output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
        keyStr.charAt(enc3) + keyStr.charAt(enc4);
    } while (i < input.length);

    return output;
}

function decode64(input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }
    } while (i < input.length);

    return output;
}


function openCenteredWindow(file,name,properties,wprefix,hprefix) {
    centeredWindow = window.open(file,name,properties);
    centeredWindow.moveTo(screen.width/2-wprefix,screen.height/2-hprefix);
}


//  (C) Milan Svrlo, released under LGPL
var http_request = false;
function getXhttpRequest(url, onReadyStateFunction) {
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            }
        }
    }
    if (!http_request) {
        alert('Cannot create XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange = onReadyStateFunction;
    http_request.open('GET', url, true);
    http_request.send(null);
}
/*
example of usage :
function check_count() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText + ' any text ...');
}
}
}
onclick="getXhttpRequest('http://server/page.php?', check_count); return false;"
*/


function utf8_encode ( string ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

function base64_encode( data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // +   improved by: Thunder.m
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='

    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof window['atob'] == 'function') {
    //    return atob(data);
    //}

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, enc="", tmp_arr = [];
    data = utf8_encode(data);

    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);

    enc = tmp_arr.join('');

    switch( data.length % 3 ){
        case 1:
        enc = enc.slice(0, -2) + '==';
        break;
        case 2:
        enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}