function dechex(number){
    if(number < 0){
        number = 0xFFFFFFFF+number+1;
    }
    return parseInt(number,10).toString(16);
}
function hexdec(hex_string){
    hex_string = (hex_string+'').replace(/[^a-f0-9]/gi, '');
    return parseInt(hex_string, 16);
}
function strlen (string){
    var str = string+'';
    var i = 0, chr = '', lgth = 0;
    if(!this.php_js || !this.php_js.ini || !this.php_js.ini['unicode.semantics'] || this.php_js.ini['unicode.semantics'].local_value.toLowerCase() !== 'on'){
        return string.length;
    }
    var getWholeChar = function (str, i){
        var code = str.charCodeAt(i);
        var next = '', prev = '';
        if(0xD800 <= code && code <= 0xDBFF){
            if(str.length <= (i+1)){
                throw 'High surrogate without following low surrogate';
            }
            next = str.charCodeAt(i+1);
            if (0xDC00 > next || next > 0xDFFF){
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i)+str.charAt(i+1);
        } else if (0xDC00 <= code && code <= 0xDFFF){
            if(i === 0){
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i-1);
            if(0xD800 > prev || prev > 0xDBFF){
                throw 'Low surrogate without preceding high surrogate';
            }
            return false;
        }
        return str.charAt(i);
    };
    for(i=0, lgth=0; i < str.length; i++){
        if((chr = getWholeChar(str, i)) === false){
            continue;
        }
        lgth++;
    }
    return lgth;
}
function nul(waarde,cijfers){
    var w_length = strlen(''+waarde);
    var aantal_nul = cijfers-w_length;
    var w_return = '';
    if(aantal_nul > 0){
        for(i=0; i<aantal_nul; i++){
            w_return += "0";
        }
        w_return += waarde;
        return(w_return);
    } else {
        return(waarde);
    }
}
function randomColor(){
    var r = nul(dechex(Math.floor(Math.random()*255)),2);
    var g = nul(dechex(Math.floor(Math.random()*255)),2);
    var b = nul(dechex(Math.floor(Math.random()*255)),2);
    return("#"+r+g+b);
}
function oposite(hex){
    var r = hex[0]+hex[1];
    var g = hex[2]+hex[3];
    var b = hex[4]+hex[5];
    r = nul(dechex(255-hexdec(r)),2);
    g = nul(dechex(255-hexdec(g)),2);
    b = nul(dechex(255-hexdec(b)),2);
    return(r+g+b);
}
function colorBW(hex){
    var r = hex[0]+hex[1];
    var g = hex[2]+hex[3];
    var b = hex[4]+hex[5];
    r = hexdec(r);
    g = hexdec(g);
    b = hexdec(b);
    if(r+b+g > (255*3)/2){
        return(true);
    } else {
        return(false);
    }
}
function getPasswordNum(lbound, ubound){
    return(Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getPasswordChar(number, lower, upper, other) {
    var numberChars = "0123456789";
    var lowerChars = "abcdefghijklmnopqrstuvwxyz";
    var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
    var charSet = '';
    if(number == true){
        charSet += numberChars;
    }
    if(lower == true){
        charSet += lowerChars;
    }
    if(upper == true){
        charSet += upperChars;
    }
    return charSet.charAt(getPasswordNum(0, charSet.length));
}
function getPassword(length, number, lower, upper, other) {
    var rc = "";
    for(var idx = 0; idx < length; ++idx){
        rc = rc + getPasswordChar(number, lower, upper, other);
    }
    return rc;
}