/* variables */
var active_switch = new Array();
var active_switch_actionlist = new Array();
var active_form = new Array();
var user_rating = 0;
var user_rating_freeze = false;
active_switch_actionlist['group'] = 1;
active_switch_actionlist['company'] = 1;
active_switch_actionlist['event'] = 1;
active_switch_actionlist['album'] = 1;
active_switch_actionlist['video'] = 1;
active_switch_actionlist['forum'] = 1;
active_switch_actionlist['user'] = 1;
active_switch_actionlist['files'] = 1;
active_switch_actionlist['gallery'] = 1;

/* have a look at the thread entries */
function switchactionbox(type, id, inHead) {
    if (active_switch[type]) {
        $('#ao-'+type+active_switch[type]).hide();
        $('#ac-'+type+active_switch[type]).show();
    }
    if (id) {
        $('#ac-'+type+id).hide();
        if (null != active_switch_actionlist[type]) {
            if (inHead != null) {
                $('.headerbox #ao-'+type+id+', .headeractionsNew #ao-'+type+id).show();
                $('#ao-'+type+id+', .actionbox, .actionlist').slideDown('fast');
            } else {
                $('#ao-'+type+id+', .genericlist_item .actionbox, .genericlist_item .actionlist').slideDown('fast');
            }
        }
        else if (type == 'image') {
            $('.image_actionbox, #ao-'+type+id).show();
        }
        else {
            $('#ao-'+type+id).slideDown('fast');
        }
        $('#ao-'+type+id+' .actionlist').slideDown('fast');        
        active_switch[type] = id;
    }
    else {
        var headClass = '.headeractionsNew .actionlist, '
        if (inHead == null) headClass = '.genericlist_item '
        if (null != active_switch_actionlist[type]) { $(headClass+'.actionbox').hide(); }
        else if (type == 'image') { $(headClass+'.image_actionbox .actionlist').hide(); }
        active_switch[type] = false;

    }
}


/* general helper functions */
function getObjCookie(name) {
    name = name.replace(/-/g, '');
    var tbxcookie = JSON.parse(getCookie('tbxcookie'));
    var foo = '';
    // fixme: works, but draws an error in firebug
    eval('foo = tbxcookie.vars.'+name);
//    alert('Requested cookie ("'+name+'") is: '+ foo);
//    alert('hard-coded welcome-cookie is: '+tbxcookie.vars.welcome);
    return foo;
}
function setObjCookie(name, value, time, path) {
    name = name.replace(/-/g, '');
    var tbxcookie = JSON.parse(getCookie('tbxcookie'));
    var zeit = new Date();
    var exp = zeit.getTime() + (31 * 24 * 60 * 60 * 1000);
    zeit.setTime(exp);
    // fixme: works, but draws an error in firebug
    eval('tbxcookie.vars.'+escape(name)+' = value');
    setCookie('tbxcookie', JSON.stringify(tbxcookie), zeit);
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, path, domain, secure) {
     var foo = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    "; path=/" +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
    document.cookie = foo;
}

function getById(id) {return document.getElementById(id);}
function crE(t) {return document.createElement(t);}
function crTe(t) {return document.createTextNode(t);}
function sel(t) {return document.selection(t);}

/* benchmark */
var benchmark_sent = false;
function bm() {
    if (benchmark_sent) return false;
    fd = new Date();
    i = document.createElement('img');
    url = '/bm.php?bmb='+(fd.getTime()-st)+'&r='+document.URL;
    url = url + '&bms='+bms+'&bmc='+bmc+'&bmh='+bmh+'&bmwh='+bmwh;
    i.setAttribute('src', url);
    i.setAttribute('alt', '');
    //i.setAttribute('onload', 'window.close()');
    i.style.width = '1px';
    i.style.height = '1px';
    getById('wrapper').appendChild(i);
    benchmark_sent = true;
    //window.close();
}
/* textarea controll */
function add_textarea_events(field, counter, maxlimit) {
    check_textarea_length(field, counter, maxlimit);
}


function textCounter(field, counter, maxlimit) {
    if (getById(field) && getById(field).value.length > maxlimit)
        getById(field).value = getById(field).value.substring(0, maxlimit);
    else if (getById(field))
        getById(counter).innerHTML = maxlimit - getById(field).value.length;
}

function check_textarea_length(field, counter, maxlimit) {
    timer = window.setTimeout('check_textarea_length("'+field+'", "'+counter+'", '+maxlimit+');', 10);
    textCounter(field, counter, maxlimit);
}

/* display functions */

function switchsidepanel(panel, screen) {
    getById(panel+'1').style.display = 'none';
    getById(panel+'2').style.display = 'none';
    getById(panel+screen).style.display = 'block';
    setObjCookie(panel, screen);
}

function show_ad(community_id, zone, cadid, element, position, width, height, style) {
    var jetzt = new Date();
    var src = 'http://adverts.tribax.com/advert.php?ad='+cadid+'&c='+community_id+'&z='+zone+'&t='+jetzt.getTime();
    if (element && element.match(/jquery:/)) {
        selector = element.substr(7, element.length);
        if (navigator.appName.indexOf("Explorer") != -1 && navigator.appName.indexOf("Opera") == -1) { // Opera might disuise itself
            var iframe = $('<iframe bordercolor="0" scrolling="no" style="padding:0px:border:0px solid white;margin:0px;marginBottom:10px;'+style+'" frameborder="0" frameBorder="0" border="0" vspace="0" hspace="0" allowtransparency="true" src="'+src+'"></iframe>');
        } else {
            var iframe = $('<object style="marginBottom:10px;'+style+'" data="'+src+'" type="text/html"> </object>');
        }
        iframe.css('overflow', 'hidden');
        if (width) {
            iframe.css('width', width+'px');
            iframe.attr('width', width);
        }
        if (height) {
            iframe.css('height', height+'px');
            iframe.attr('height', height);
        }
        if (position == 'inner_before') $(selector).prepend(iframe);
        else if (position == 'inner_after') $(selector).append(iframe);
        else if (position == 'outer_before') $(selector).before(iframe);
        else if (position == 'outer_after') $(selector).after(iframe);
        else if (position == 'replace') $(selector).replaceWith(iframe);
    }
    else {
        if (navigator.appName.indexOf("Explorer") != -1 && navigator.appName.indexOf("Opera") == -1) { // Opera might disuise itself
            var iframe = document.createElement('iframe');
            if (style) iframe.setAttribute('style', style);
            iframe.setAttribute('frameborder', 0);
            iframe.setAttribute("frameBorder", "0");
            iframe.setAttribute('border', 0);
            iframe.setAttribute('vspace','0');
            iframe.setAttribute('hspace','0');
            iframe.setAttribute('bordercolor', 'white');
            iframe.setAttribute('scrolling', 'no');
            if (zone) iframe.id = 'adzone'+zone;
            iframe.style.padding = '0px';
            iframe.style.margin = '0px';
            iframe.style.marginBottom = '10px';
            iframe.style.border = '0px solid white';
            if (style) elementApplyStyle(iframe, style);
            iframe.src = src;
        }
        else {
            var iframe = document.createElement('object');
            iframe.style.marginBottom = '10px';
            if (style) iframe.setAttribute('style', style);
            iframe.setAttribute('type', 'text/html');
            if (zone) iframe.id = 'adzone'+zone;
            iframe.setAttribute('data', src);
        }
        iframe.style.overflow = 'hidden';
        if (width) {
            iframe.style.width = width;
            iframe.setAttribute('width', width);
        }
        if (height) {
            iframe.style.height = height;
            iframe.setAttribute('height', height);
        }
        try { // Don't break on non existant page element
            if (element) {
                if (position == 'inner_before') getById(element).parentNode.insertBefore(iframe, getById(element));
                else getById(element).appendChild(iframe);
            }
            else getById('jsadzone'+zone).parentNode.insertBefore(iframe, getById('jsadzone'+zone));
        } catch (e) {}
    }
}

function setheader(screen) {
    $('#open, #close').hide();
    if (screen == 2) {
        $('#close').show();
        $('#img1, #more0').hide();
        $('#more1, #more2,').slideDown('fast');
        $('#headerbx.small').removeClass('small');
    } else {
        $('#open').show();
        $('#img2, #more1, #more2').hide();
        $('#more0').show();
        $('#headerbx').addClass('small');
    }
    $('#img'+screen).show();
    setObjCookie('header', screen * 1);
}

function getObjInnerText (obj) {
    return (obj.innerText) ? obj.innerText
    : (obj.textContent) ? obj.textContent
    : "";
}

function edit_entry(id, action, txt1, txt2, txt3, formaction) {
    var div = getById('entry-body-'+id);
    if (getById('event_entry'+id)) {
        c = getById('event_entry'+id).value;
        while (div.firstChild) {div.removeChild(div.firstChild);}
        div.innerHTML = c;
    }
    else {
        var c = div.innerHTML;
        d = document.createElement('div');
        f = document.createElement('form');
        if (formaction == null) f.setAttribute('action', '.');
        else f.setAttribute('action', formaction);
        f.setAttribute('method', 'post');

        i1  = document.createElement('input');
        i1.setAttribute('type', 'hidden');
        i1.setAttribute('name', 'action');
        i1.value = action;

        i2  = document.createElement('input');
        i2.setAttribute('type', 'hidden');
        i2.setAttribute('name', 'entry_id');
        i2.value = id;


        ta = document.createElement('textarea');
        ta.setAttribute('name', 'body');
        ta.setAttribute('id', 'body_'+id);
        ta.value = c;
        
        is = document.createElement('input');
        is.setAttribute('type', 'submit');
        is.value = 'speichern';
        is.className = 'btn';
        ih = document.createElement('input');
        ih.setAttribute('type', 'hidden');
        ih.setAttribute('id', 'event_entry'+id);
        ih.setAttribute('value', c);
        while (div.firstChild) {div.removeChild(div.firstChild);}

        f.appendChild(ta);
        //f.appendChild(scrpt);
        f.appendChild(i1);
        f.appendChild(i2);
        f.appendChild(is);
        f.appendChild(ih);
        /*d.style.height = '275px';*/
        d.appendChild(f);
        div.appendChild(d);
        $('#body_'+id).tinymce(tinymce_basic_config);
    }
}

function submit_post(target, param_str, confirm_msg){
    if (param_str.charAt(0) == '?' || param_str.charAt(0) == '&') {
        param_str = param_str.substr(1);
    }
    $('body').append('<form id="hiddenform" name="hiddenform" method="post" action="'+target+'" style="display:none;"></form>');
    params = param_str.split('&');
    for (i = 0;i < params.length; i++) {
        p = params[i].split('=');
        $('#hiddenform').append('<input type="hidden" name="'+ p[0]+'" value="'+p[1]+'" />');
    }

    if (confirm_msg == false || confirm(confirm_msg)){
    	document.getElementById('hiddenform').submit();
    }
    else {
        $('#hiddenform').remove();
        return false;
    }
}

function show_elemnt(id){
    if (getById(id)) getById(id).style.display = 'block'
}
function hide_elemnt(id){
    if (getById(id)) getById(id).style.display = 'none'
}

/**
 * IE has trouble correctly drawing screen elements in stacking order. It always
 * draws form elements last, regardless of their actual z-index, thus obscuring
 * drop downs and other elements.
 */
function compat_ie_dropdowns()
{
    var srch = document.getElementById('header-wrapper').getElementsByTagName('ul');
    for (var i = 0; i < srch.length; i++) {
        if (srch[i].className && srch[i].className == 'subdrop') {
            srch[i].parentNode.onmouseover = compat_dropdown_on;
            srch[i].onmouseout = compat_dropdown_off;
        }
    }
}

var compatIfMenu = false;
var compatEvSrc = false;
var compatIframeTO = false;

function compat_dropdown_on() {
    compatEvSrc = this;
    window.event.cancelBubble = true;
    window.setTimeout('compat_dropdown_on_do();', 100);
}

function compat_dropdown_on_do() {
    var node = compatEvSrc;
    if (node.parentNode && node.parentNode.nodeName == 'UL' && node.parentNode.className == 'subdrop') {
        node = node.parentNode;
    } else if (node.parentNode.parentNode && node.parentNode.parentNode.nodeName == 'UL'
            && node.parentNode.parentNode.className == 'subdrop') {
        node = node.parentNode.parentNode;
    }

    if (compatIframeTO) {
        window.clearTimeout(compatIframeTO);
        compatIframeTO = false;
    }
    if (compatIfMenu) { // Another menu is open. Close it first
        compat_dropdown_off_do();
    }

    var srch = node.getElementsByTagName('ul');
    for (var i = 0; i < srch.length; i++) {
        if (srch[i].className && srch[i].className == 'subdrop') {
            node = srch[i];
            break;
        }
    }
    node.style.left = '0px';
    node.style.top = '25px';
    node.style.display = 'block';
    node.style.position = 'absolute';

    var iframe = document.createElement('iframe');
    iframe.src = 'about:blank';
    iframe.id = 'drop_iframe';
    iframe.frameborder = 0;
    iframe.style.width = node.offsetWidth.toString() + 'px';
    iframe.style.height = node.offsetHeight.toString() + 'px';
    node.parentNode.insertBefore(iframe, node);
    compatIfMenu = node;
}

function compat_dropdown_off() {
    if (compatIframeTO) window.clearTimeout(compatIframeTO);
    compatIframeTO = window.setTimeout('compat_dropdown_off_do();', 750);
}

function compat_dropdown_off_do() {
    var iframe = document.getElementById('drop_iframe');
    try {
        iframe.parentNode.removeChild(iframe);
        compatIfMenu.style.display = 'none';
    } catch (e) {}
    compatIfMenu = false;
    compatIframeTO = false;
}

function elementApplyStyle(ele, styl) {
    var styls = styl.split(';');
    var len = styls.length;
    for (var i = 0; i < len; i++) {
        if (styls[i].length == 0) continue; // Empty def., probably at the end
        var styl = styls[i].split(':');
        styl[0] = StyleCSStoJS(styl[0]);
        try {ele.style[styl[0]] = styl[1];} catch (e) {} // Don't break on illegal defs.
    }
}

function StyleCSStoJS(prop) {
    prop = prop.toLowerCase();
    return prop.replace(/\-a/g, 'A').replace(/\-b/g, 'B').replace(/\-c/g, 'C').replace(/\-d/g, 'D')
            .replace(/\-h/g, 'H').replace(/\-i/g, 'I').replace(/\-l/g, 'L').replace(/\-n/g, 'N').replace(/\-p/g, 'P')
            .replace(/\-r/g, 'R').replace(/\-s/g, 'S').replace(/\-v/g, 'V').replace(/\-w/g, 'W');
}

function chat_add2url(finalURL, srcEle) {
    var finalURL, bgColor, txtColor, barBgColor, posBarColor;

    if (typeof(srcEle) != 'object') {
        srcEle = document.getElementById(srcEle);
        if (typeof(srcEle) != 'object') return; // Element not found
    }

    bgColor = getStyle(srcEle, 'background-color');
    if (!bgColor) bgColor = getStyle(srcEle, 'background');
    txtColor = getStyle(srcEle, 'color');
    barBgColor = getStyle(srcEle, 'border-top-color');
    if (!barBgColor) barBgColor = getStyle(srcEle, 'border-color');

    finalURL += '&bg=' + rgb2Hex(txtColor, true);
    finalURL += '&leftbg=' + rgb2Hex(barBgColor, true);
    finalURL += '&rightbg=' + rgb2Hex(barBgColor, true);
    finalURL += '&rightbghover=' + rgb2Hex(barBgColor, true);
    finalURL += '&voltrack=' + rgb2Hex(bgColor, true);
    finalURL += '&volslider=' + rgb2Hex(txtColor, true);
    finalURL += '&lefticon=' + rgb2Hex(txtColor, true);
    finalURL += '&righticon=' + rgb2Hex(txtColor, true);
    finalURL += '&righticonhover=' + rgb2Hex(txtColor, true);
    finalURL += '&loader=' + rgb2Hex(barBgColor, true);

    return finalURL;
}


/**
 * Converts CSS rgb(x,y,z) to classic #xxyyzz notation
 * @param string  CSS rgb(x,y,z) setting
 *[@param bool  Whether to cut the # in front; Default: false (leave it in)]
 * @return  string  either #xxyyzz or xxyyzz (if param 2 is set to true)
 */
function rgb2Hex(rgb, flash) {
    if (rgb.match(/^rgb/)) {
        var tmp = /^rgb\((\d+),\s?(\d+),\s?(\d+)\)/;
        tmp.exec(rgb);
        rgb = '#' + dec2Hex(RegExp.$1) + dec2Hex(RegExp.$2) + dec2Hex(RegExp.$3);
    }
    if (flash && rgb.substr(0,1) == '#') rgb = rgb.substr(1);
    return rgb;
}

/**
 * Simple dec -> hex converter
 * @param  int  decimal value; range: 0 ... 255
 * @return  string  hex value. has always two digits!
 */
function dec2Hex(dez)
{
    dez = parseInt(dez);
    var tbl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
    var H1, H2;
    H1 = parseInt(dez/16);
    H2 = dez - (H1*16);
    return tbl[H1].toString() + tbl[H2].toString();
}

/**
 * Third party code below
 */

// Ermittle Style eines Elements
function getStyle(element, property) {
    // Beim IE kann man (über currentStyle - IE5+) keine Eigenschaften
    // abfragen, die kombinierte Werte enthalten (border, borderBottom, ...)
    // Andererseits gibt es zu clip hier auch clipTop, clipRight, clipBottom & ClipLeft.
    var result = '';

    obj = getObject(element);

    if (obj) {
        if (window.getComputedStyle) {
            result = window.getComputedStyle(obj, '').getPropertyValue(property);
        } else if (obj.currentStyle) {
            result = obj.currentStyle[propertyToStyle(property)];
        } else if (obj.style) {
            result = obj.style[propertyToStyle(property)];
        }
    }
    return result;
}

// Style-Schreibweise von CSS auf JS ändern
function propertyToStyle(property) {
    // 1. Eigenschaften mit reserviertem Bezeichner: Unterscheidung nach JScript- bzw. JavaScript-Syntax
    if (property == 'float') {
        property = ((typeof(window.cssFloat) == 'undefined') ? 'style' : 'css') + property.charAt(0).toUpperCase()+property.substring(1);
    } else if (property.indexOf("-") >= 0) { // 2. Eigenschaften mit Bindestrich
        syntax = property.split("-");               // CSS-Syntax am "-" auftrennen, ...
        property = syntax[0];                       // ... ersten Teil übernehmen und ...
        for(var i = 1; i < syntax.length; i++) {    // ... folgende Teile mit großem Anfangsbuchstaben
            property += syntax[i].charAt(0).toUpperCase()+syntax[i].substring(1);
        }
    }
    return property;
}

// Ermittle Objekt (veränderbare Priorität: object/id/name/tagname) 050708
function getObject(element, number) {
    var obj = false, lastParam, type, types, i;
    if (element) {
        // Letzten, optionalen Parameter ermitteln (type)
        lastParam = getObject.arguments[getObject.arguments.length-1];
        // Erwünschten Abfragetyp sichern: object/id/name/tagname (voreingestellte Typen und Reihenfolge der Abfrage)
        type = (typeof(lastParam) == 'string' && getObject.arguments.length>1)
                ? lastParam.toLowerCase().replace(',', '\/')
                : 'object/id/name/tagname';
        // Wenn element bereits Objekt ist und auch dieser Typ sein darf
        if (typeof(element) == 'object' && type.indexOf('object') >= 0) {
            obj = element;
        } else if (document.getElementById) {
            number = (typeof(number) == 'number')?number:0;
            types = type.split('/');
            for (i in types) {
                if (types[i] == 'id' && document.getElementById(element)) {
                    obj = document.getElementById(element);break;
                } else if (types[i] == 'name' && document.getElementsByName(element) && document.getElementsByName(element)[number]) {
                    obj = document.getElementsByName(element)[number];break;
                } else if (types[i] == 'tagname' && document.getElementsByTagName(element) && document.getElementsByTagName(element)[number]) {
                    obj = document.getElementsByTagName(element)[number];break;
                }
            }
        }
    }
    return obj;
}

/* JS Functions for object rating */
function rating_over(type, value, rid) {
    if (user_rating_freeze == false) {
        if (typeof(rid) != 'number') rid = '';
        //$('#rate-item'+rid+' a.item-rating').show();
        user_rating = $('#rate-item'+rid+' a.item-rating-full').size();
        $('#rate-item'+rid+' *').removeClass('item-rating-full');
        for (x=1;x<=value;x++) {
            $('#rate-item'+rid+' .rating-'+x).addClass('item-rating-full');
        }
    }
}
function rating_out(type, value, rid) {
    if (user_rating_freeze == false) {
        if (typeof(rid) != 'number') rid = '';
        //$('#rate-item'+rid+' a.item-rating').hide();
        for (x=1;x<=value;x++) {
            $('#rate-item'+rid+' .rating-'+x).removeClass('item-rating-full');
        }
        for (x=1;x<=user_rating;x++) {
            $('#rate-item'+rid+' .rating-'+x).addClass('item-rating-full');
        }
        $('#rating-background-slider'+rid).addClass('item-rating-full');
    }
}

function submit_rating(type, value, rid){
    user_rating_freeze = true;          
    if (typeof(rid) != 'number') {
        $('#rate-item-form input[name=value]').attr('value', value);
        document.getElementById('rate-item-form').submit();
    }
    else {
        $('#rate-item-form'+rid+' input[name=value]').attr('value', value);
        document.getElementById('rate-item-form'+rid).submit();
    }
}

/* JS Functions for advanced search */
var date_search_string = new Array;
var text_search_string = new Array;

function switch_search_form () {
    if (getById('advsearchform').style.display == 'none') {
		getById('advsearchform').style.display = 'block';
		getById('smplsearchform').style.display = 'none';
        while (getById('advsearchlnk').firstChild) {getById('advsearchlnk').removeChild(getById('advsearchlnk').firstChild);}
        getById('advsearchlnk').appendChild(crTe(j19164));
    }
    else {
		getById('advsearchform').style.display = 'none';
		getById('smplsearchform').style.display = 'block';
        while (getById('advsearchlnk').firstChild) {getById('advsearchlnk').removeChild(getById('advsearchlnk').firstChild);}
        getById('advsearchlnk').appendChild(crTe(j19165));
        //reset_conditions();
    }
}

function reset_conditions(){
    conditions = new Array();
    add_empty_condition();
    alert_conditions();
}

function add_empty_condition(){
    update_conditions();
    condition = new Object();
    condition.key = 'search';
    condition.val = '';
    conditions.push(condition);
    alert_conditions();
}

function add_condition(key, val){
    update_conditions();
    condition = new Object();
	condition.key = key;
	condition.val = val;
    conditions.push(condition);
    alert_conditions();
}

function del_condition(condition) {
    update_conditions();
    conditions.splice(condition, 1);
	text_search_string[condition] = '';
	date_search_string[condition] = '';
    alert_conditions();
}

function update_conditions() {
    for (i = 0;i < conditions.length;i++) {
        conditions[i].key = getById('condition_key_'+i)[getById('condition_key_'+i).selectedIndex].value;
        if (getById('condition_value_'+i)) {
            conditions[i].val = getById('condition_value_'+i).value;
        }
    }
}

var field_id = new Array();
function alert_conditions() {
    while (getById('conditions').firstChild) {getById('conditions').removeChild(getById('conditions').firstChild);}
    div = crE('label');
    div.className = 'first';
    div.appendChild(crTe(j19179));
    getById('conditions').appendChild(div);

    div = crE('label');
    div.className = 'second';
    div.appendChild(crTe(j19180));
    getById('conditions').appendChild(div);
	
	over = crE('div');
	over.setAttribute('id', 'dateformat');
    over.className = 'scf';
		ov1 = crE('div');
		ov1.className = 'event_search_date_format_left';
		if (typeof(date_format) != 'undefined') {ov1.appendChild(crTe('('+date_format+')'));}
		over.appendChild(ov1);
		ov2 = crE('div');
		ov2.className = 'event_search_date_format_right';
		if (typeof(date_format) != 'undefined') {ov2.appendChild(crTe('('+date_format+')'));}
		over.appendChild(ov2);
	div.appendChild(over);
	getById('dateformat').style.display='none';
    
    condition_options = new Array;
    for (var j=0; j < getById('condition_key').options.length; j++) {
        trg = false;
        for (i = 0;i < conditions.length;i++) {
            if (conditions[i].key == getById('condition_key').options[j].value) {
				trg = true;
				if(getById('condition_key').options[j].value == 'date_range') getById('dateformat').style.display='block';
            }
        }
        if (!trg) condition_options.push(getById('condition_key').options[j].value)
    }
    trig_dp = false;
    for (i = 0;i < conditions.length;i++) {

		div = crE('div');
        div.className = 'condition scf';
        sel = crE('select');
		sel.setAttribute('tabindex', '499');
        sel.onchange = function(){update_conditions();alert_conditions();};
        sel.setAttribute('id', 'condition_key_'+i);
        sel.setAttribute('name', 'condition_key_'+i);
        for (var j=0; j < getById('condition_key').options.length; j++) {
            if (jQuery.inArray(getById('condition_key').options[j].value, condition_options) != -1 || getById('condition_key').options[j].value == '' || getById('condition_key').options[j].value == conditions[i].key) {
				opt = crE('option');
				opt.appendChild(crTe(getById('condition_key').options[j].firstChild.data));
				opt.value = getById('condition_key').options[j].value;
				if (opt.value == conditions[i].key) {
					opt.selected = true;                    
				}
				sel.appendChild(opt);
			}
        }
        div.appendChild(sel);
		
		if (typeof(text_search_string[i]) == 'undefined') {text_search_string[i] = '';}
		if (typeof(date_search_string[i]) == 'undefined') {date_search_string[i] = '';}
		
        if (conditions[i].key != '') {
			if (conditions[i].key == 'date_range'){
				trig_dp = true;
                inp = crE('input');
                inp.setAttribute('id', 'condition_value_'+i);
                inp.setAttribute('name', 'condition_value_'+i);
                inp.setAttribute('type', 'hidden');
				inp.value = conditions[i].val;
                div.appendChild(inp);
				
				pos = conditions[i].val.indexOf('|');				
						
				if (pos == 10 || pos == 0) {
					date_min = conditions[i].val.substring(0, pos);
					date_max = conditions[i].val.substring(pos+1);
				}
				else {
					date_min = '';
					date_max = '';
					if (date_search_string[i] != '') {
						pos2 = date_search_string[i].indexOf('|');
						if (pos2 == 10 || pos2 == 0) {
							date_min = date_search_string[i].substring(0, pos2);
							date_max = date_search_string[i].substring(pos2+1);	
						}
					}
					else if (pos != 0) {
						text_search_string[i] = conditions[i].val;
					}
				}
				
				d1 = crE('div');
				d1.className = 'event_search_datepicker1';
					field_id.push('dp_min_value_'+i);
					inp = crE('input');
	                inp.setAttribute('id', 'dp_min_value_'+i);
	                inp.setAttribute('name', 'dp_min_value_'+i);
	                inp.setAttribute('type', 'text');
					inp.setAttribute('tabindex', '500');
					inp.setAttribute('onchange', 'update_date_range_user(this.value,'+i+')');
					inp.value = date_min;
					inp.className = 'text form_text DatePicker search_event_date';
	                d1.appendChild(inp);
				div.appendChild(d1);
				
				d3 = crE('div');
					d3.setAttribute('id', 'bis_date');
					d3.appendChild(crTe('-'));
				div.appendChild(d3);
				
				d2 = crE('div');
				d2.className = 'event_search_datepicker1';
	                field_id.push('dp_max_value_'+i);
					inp = crE('input');
	                inp.setAttribute('id', 'dp_max_value_'+i);
	                inp.setAttribute('name', 'dp_max_value_'+i);
	                inp.setAttribute('type', 'text');
					inp.setAttribute('tabindex', '500');
					inp.setAttribute('onchange', 'update_date_range_user(this.value,'+i+')');
	                inp.value = date_max;
	                inp.className = 'text form_text DatePicker search_event_date';
	                d2.appendChild(inp);
				div.appendChild(d2);
            }
            else {
                inp = crE('input');
				inp.setAttribute('id', 'condition_value_'+i);
                inp.setAttribute('name', 'condition_value_'+i);
                inp.setAttribute('type', 'text');
				inp.setAttribute('tabindex', '500');
				pos = conditions[i].val.indexOf('|');
				
				if ((pos != 10 && pos != 0) || text_search_string[i] != '') {
					if (text_search_string[i] != '') {
						inp.value = text_search_string[i];
						if (conditions[i].val == text_search_string[i]) {
							date_search_string[i] = date_search_string[i];
						}
						else {
							date_search_string[i] = conditions[i].val;
						}
					}
					else {
						inp.value = conditions[i].val;
					}
				}
				else {
					date_search_string[i] = conditions[i].val;
				}
				inp.className = 'text form_text ';
                div.appendChild(inp);
            }
        }	
        if (i != 0) {
            lnk = crE('a');
            lnk.setAttribute('href', 'java'+'script:del_condition('+i+')');
            lnk.className = 'del-item';
            lnk.appendChild(crTe(j19167));
            div.appendChild(lnk);
        }
        getById('conditions').appendChild(div);
    }
    if (trig_dp) {
        if (typeof(year_range) == 'undefined' || typeof(min_date) == 'undefined' || typeof(max_date) == 'undefined') {
			for(i=0;i<field_id.length;i++) {
				$('#advsearchform #'+field_id[i]).datepicker({constrainInput:false,altField:'#'+field_id[i],altFormat:dp_format,showOn:'button',buttonImage:'/images/datepicker-trans.gif',buttonImageOnly:true,changeMonth:true,changeYear:true,dateFormat:'yy-mm-dd',firstDay:1,dayNamesMin:[j20296, j20290, j20291, j20292, j20293, j20294, j20295 ],monthNamesShort:[j20297, j20298, j20299, j20300, j20301, j20302, j20303, j20304, j20305, j20306, j20307, j20308],prevText:'«',nextText:'»', onClose: update_date_range}); 
			}
		}
        else {
            for(i=0;i<field_id.length;i++) {
				$('#advsearchform #'+field_id[i]).datepicker({constrainInput:false,altField:'#'+field_id[i],altFormat:dp_format,showOn:'button',buttonImage:'/images/datepicker-trans.gif',buttonImageOnly:true,changeMonth:true,changeYear:true,dateFormat:'yy-mm-dd',firstDay:1,dayNamesMin:[j20296, j20290, j20291, j20292, j20293, j20294, j20295 ],monthNamesShort:[j20297, j20298, j20299, j20300, j20301, j20302, j20303, j20304, j20305, j20306, j20307, j20308],prevText:'«',nextText:'»', onClose: update_date_range,  yearRange:year_range, minDate:min_date, maxDate:max_date}); 
		   }
        }
        $("#ui-datepicker-div").css('display', 'none');                        
    }  
    if (conditions.length != getById('condition_key').options.length) {
		div = crE('div');
        div.className = 'add-item';
        div.onclick = function(){add_empty_condition();};
        div.appendChild(crTe(j19166));
        getById('conditions').appendChild(div);
    }
	inp = crE('input');
    inp.setAttribute('type', 'submit');
	inp.value = j19168;
	inp.setAttribute('tabindex', '501');
	inp.className = 'btn form_submit';
	if (trig_dp && item_not_event == 0) {
	    action = $('#advsearchform form').attr('action');
	    pos = action.indexOf('/event');
	    inp.onclick = function(){$('#advsearchform form').attr('action', action.substring(0, pos+6)+'2'+action.substring(pos+7))};    
	}
	if (trig_dp && item_not_event == 1) { 
	    action = $('#advsearchform form').attr('action');
	    pos = action.indexOf('/files');
	    inp.onclick = function(){$('#advsearchform form').attr('action', action.substring(0, pos+6)+'0'+action.substring(pos+7))};    
	}
    getById('conditions').appendChild(inp);
} 

function update_keys(ptype){
    if (typeof(ptype) != 'undefined' || getById('proftype')) {
        for (i=getById('condition_key').length-1;i>=0;i--) {
            if (getById('condition_key').options[i].value != '' && getById('condition_key').options[i].value != 'search_nick' && getById('condition_key').options[i].value != 'search_firstname' && getById('condition_key').options[i].value != 'search_lastname' && getById('condition_key').options[i].value != 'search') {
                getById('condition_key').remove(i);
            }
        }
        if (typeof(ptype) == 'undefined') ptype = getById('proftype').options[getById('proftype').selectedIndex].value;
        if (ptype != ''){
            for (i=0;i<prof_types[ptype].length;i++) {
                opt = crE('option');
                opt.value = prof_types[ptype][i][0]
                opt.appendChild(crTe(prof_types[ptype][i][1]));
                getById('condition_key').appendChild(opt);
            }
        }
        jq_alert_conditions();
    }
}

/* Andvanced search functions refactored (now with JQ) */
function jq_alert_conditions() {
    $('#conditions').empty();
    if (typeof(date_format) != 'undefined') {
        $('#conditions').append('<div id="dateformat" class="scf" style="display:none;"><div class="event_search_date_format_left">('+date_format+')</div><div class="event_search_date_format_right">('+date_format+')</div></div>');
    }
		
    condition_options = new Array;
    for (var j=0; j <  $('#condition_key option').length; j++) {
        trg = false;
        for (i = 0;i < conditions.length;i++) {
            if (conditions[i].key == $('#condition_key option:eq('+j+')').val()) {
				trg = true;
				if($('#condition_key option:eq('+j+')').val() == 'date_range') $('#dateformat').css('display', 'block');
            }
        }
        if (!trg) condition_options.push($('#condition_key option:eq('+j+')').val())
    }
    trig_dp = false;
    for (i = 0;i < conditions.length;i++) {
        $('#conditions').append('<div class="condition scf"><select id="condition_key_'+i+'" name="condition_key_'+i+'" onchange="jq_update_conditions();jq_alert_conditions();"></select></div>')

        for (var j=0; j < $('#condition_key option').length; j++) {
            if (jQuery.inArray($('#condition_key option:eq('+j+')').val(), condition_options) != -1 || $('#condition_key option:eq('+j+')').val() == '' || $('#condition_key option:eq('+j+')').val() == conditions[i].key) {
				if ($('#condition_key option:eq('+j+')').val() == conditions[i].key) sel = ' selected="selected"';
                else sel ='';            
                $('#condition_key_'+i).append('<option value="'+$('#condition_key option:eq('+j+')').val()+'"'+sel+'>'+$('#condition_key option:eq('+j+')').html()+'</option>');
			}
        }
		
		if (typeof(text_search_string[i]) == 'undefined') {text_search_string[i] = '';}
		if (typeof(date_search_string[i]) == 'undefined') {date_search_string[i] = '';}
		
        if (conditions[i].key != '') {
			if (conditions[i].key == 'date_range'){
				trig_dp = true;
                $('#conditions .condition:last').append('<input type="hidden" id="condition_value_'+i+'" name="condition_value_'+i+'" value="'+conditions[i].val+'" />');  				
				pos = conditions[i].val.indexOf('|');				
						
				if (pos == 10 || pos == 0) {
					date_min = conditions[i].val.substring(0, pos);
					date_max = conditions[i].val.substring(pos+1);
				}
				else {
					date_min = '';
					date_max = '';
					if (date_search_string[i] != '') {
						pos2 = date_search_string[i].indexOf('|');
						if (pos2 == 10 || pos2 == 0) {
							date_min = date_search_string[i].substring(0, pos2);
							date_max = date_search_string[i].substring(pos2+1);	
						}
					}
					else if (pos != 0) {
						text_search_string[i] = conditions[i].val;
					}
				}
				$('#conditions .condition:last').append('<div class="event_search_datepicker1"><input id="dp_min_value_'+i+'" name="dp_min_value_'+i+'" type="text" class="txtfld DatePicker search_event_date" onchange="update_date_range_user(this.value,'+i+')" value="'+date_min+'" /><div id="bis_date">-</div><input id="dp_max_value_'+i+'" name="dp_max_value_'+i+'" type="text" class="txtfld DatePicker search_event_date" onchange="update_date_range_user(this.value,'+i+')" value="'+date_max+'" /></div>');				
                field_id.push('dp_min_value_'+i);
                field_id.push('dp_max_value_'+i);
            }
            else {
				pos = conditions[i].val.indexOf('|');				
				if ((pos != 10 && pos != 0) || text_search_string[i] != '') {
					if (text_search_string[i] != '') {
						inp_value = text_search_string[i];
						if (conditions[i].val == text_search_string[i]) {
							date_search_string[i] = date_search_string[i];
						}
						else {
							date_search_string[i] = conditions[i].val;
						}
					}
					else {
						inp_value = conditions[i].val;
					}
				}
				else {
					date_search_string[i] = conditions[i].val;
                    inp_value = '';
				}
                $('#conditions .condition:last').append('<input id="condition_value_'+i+'" name="condition_value_'+i+'" type="text" value="'+inp_value+'" class="txtfld" />');              
            }
        }	
        if (i != 0) {
            $('#conditions .condition:last').append('<a href="javascript:void(0);" onclick="jq_del_condition('+i+')" class="del-item">'+j19167+'</a>');
        }
    }
    if (trig_dp) {
        if (typeof(year_range) == 'undefined' || typeof(min_date) == 'undefined' || typeof(max_date) == 'undefined') {
			for(i=0;i<field_id.length;i++) {
				$('#advsearchform #'+field_id[i]).datepicker({constrainInput:false,altField:'#'+field_id[i],altFormat:dp_format,showOn:'button',buttonImage:'/images/datepicker-trans.gif',buttonImageOnly:true,changeMonth:true,changeYear:true,dateFormat:'yy-mm-dd',firstDay:1,dayNamesMin:[j20296, j20290, j20291, j20292, j20293, j20294, j20295 ],monthNamesShort:[j20297, j20298, j20299, j20300, j20301, j20302, j20303, j20304, j20305, j20306, j20307, j20308],prevText:'«',nextText:'»', onClose: update_date_range}); 
			}
		}
        else {
            for(i=0;i<field_id.length;i++) {
				$('#advsearchform #'+field_id[i]).datepicker({constrainInput:false,altField:'#'+field_id[i],altFormat:dp_format,showOn:'button',buttonImage:'/images/datepicker-trans.gif',buttonImageOnly:true,changeMonth:true,changeYear:true,dateFormat:'yy-mm-dd',firstDay:1,dayNamesMin:[j20296, j20290, j20291, j20292, j20293, j20294, j20295 ],monthNamesShort:[j20297, j20298, j20299, j20300, j20301, j20302, j20303, j20304, j20305, j20306, j20307, j20308],prevText:'«',nextText:'»', onClose: update_date_range,  yearRange:year_range, minDate:min_date, maxDate:max_date}); 
		   }
        }
        $("#ui-datepicker-div").css('display', 'none');                        
    }  
    if (conditions.length != $('#condition_key option').length) {
        $('#conditions').append('<div class="add-item" onclick="jq_add_empty_condition();">'+j19166+'</div>')
    }
    $('#conditions').append('<input type="submit" value="'+j19168+'" class="btn" />')
	if (trig_dp && item_not_event == 0) {
	    action = $('#advsearchform form').attr('action');
	    pos = action.indexOf('/event');
	    $('#conditions .sbmtbtn').onclick(function(){$('#advsearchform form').attr('action', action.substring(0, pos+6)+'2'+action.substring(pos+7))});    
	}
	if (trig_dp && item_not_event == 1) { 
	    action = $('#advsearchform form').attr('action');
	    pos = action.indexOf('/files');
	    $('#conditions .sbmtbtn').onclick(function(){$('#advsearchform form').attr('action', action.substring(0, pos+6)+'0'+action.substring(pos+7))});    
	}
}        

function jq_reset_conditions(){
    conditions = new Array();
    jq_add_empty_condition();
    jq_alert_conditions();
}

function jq_add_empty_condition(){
    jq_update_conditions();
    condition = new Object();
    condition.key = 'search';
    condition.val = '';
    conditions.push(condition);
    jq_alert_conditions();
}

function jq_add_condition(key, val){
    jq_update_conditions();
    condition = new Object();
	condition.key = key;
	condition.val = val;
    conditions.push(condition);
    jq_alert_conditions();
}

function jq_del_condition(condition) {
    jq_update_conditions();
    conditions.splice(condition, 1);
	text_search_string[condition] = '';
	date_search_string[condition] = '';
    jq_alert_conditions();
}

function jq_update_conditions() {
    for (i = 0;i < conditions.length;i++) {
        conditions[i].key = $('#condition_key_'+i+' option:selected').val();
        if ($('#condition_value_'+i).length != 0) {
            conditions[i].val =  $('#condition_value_'+i).val();
        }
    }
}

function set_rows(value) {
    getById('rows_id').value = value;
    getById('rows_id2').value = value;
}

function set_order(value) {
    getById('order_id').value = value;
    getById('order_id2').value = value;
}

function update_date_range (dateText, inst) { 
    field_no = inst.id.substring(13);
	$('#condition_value_'+field_no).val($('#dp_min_value_'+field_no).val()+'|'+$('#dp_max_value_'+field_no).val());
}

function update_date_range_user (date, id) {
	$('#condition_value_'+id).val($('#dp_min_value_'+id).val()+'|'+$('#dp_max_value_'+id).val());
}

conditions = new Array();

/**
 * WARNING this function is deprecated use JQuery.inArray() instead 
 * 
 * @param array haystack
 * @param string needle
 * @param int start position
 */
function indexOfArray(array, string, start) {
    for (var i = (start || 0); i < array.length; i++) {
        if (array[i] == string) {
            return i;
        }
    }
}

/**
 * adds markup for video player
 * @param  string  jquery selector
 * @param  string  path to flv
 */
function video_include(selector, fileName, width, height, domain) {   
    if ($(selector).count != 0) {
        if (domain != '') domain = 'http://'+domain;      
        if ( $.browser.msie && $.browser.version < 8) {
            var type = 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"';
        }else{
            var type = 'type="application/x-shockwave-flash"';
        }
        bgColor = $(selector).css('background-color');
        fgColor = $(selector).css('color');
        $(selector).empty().append('<object '+type+' data="'+domain+'/swf/videoplayer.swf"  height="'+height+'" width="'+width+'"id="flvplayer" >'+
        '<param name="movie" value="'+domain+'/swf/videoplayer.swf" />'+
        '<param name="quality" value="high" />'+        
        '<param name="wmode" value="opaque" />'+
        '<param name="allowFullScreen" value="true" />'+
        '<param name="flashvars" value="movie='+fileName+'&autoload=on&volume=70&bgcolor=0x' + rgb2Hex(bgColor, true) + '&fgcolor=0x' + rgb2Hex(fgColor, true) + '&postimage=" />'+
        '</object>'); 
    }    
}

function show_loading(){
    /**/
}

function hide_loading(){
    /**/
}
function show_error(){
    /**/
}

function taf_pop(item_id, type, email, message){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20510, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 310});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 310);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20510);
        $('#modaldialog').dialog('open');        
    }    
    $('#modaldialog').html('<div id="tell-friend" class="formarea"><form method="post" class="scf" action="."><input type="hidden" class="hidden" name="action" value="tell-friend" /><input type="hidden" class="hidden" name="id" value="'+item_id+'" /><input type="hidden" class="hidden" name="type" value="'+type+'" /><label for="cf-email" class="bold_text">'+h8104+'</label><input type="text" name="email" id="cf-email" class="input_text" value="'+email+'" maxlength="255" tabindex="600" /><label for="message" class="bold_text">'+h12367+'</label><textarea class="list_tell_friend" rows="6" cols="40" name="message" id="message" tabindex="601">'+message+'</textarea><p class="txtcounter">'+h19183+' <span id="txt_counter"></span> '+h19184+'.</p><input type="submit" value="'+h19190+'" class="btn" tabindex="602" /><small>'+h20511+'</small></form></div>');    
    $(document).ready(function(){$('#message').maxChar(21845, {indicator: 'txt_counter'});});
}        

function chown_pop(obj_id, except_cu_id) {
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20512, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 305});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 305);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20512);
        $('#modaldialog').dialog('open');        
    }       
     $('#modaldialog').html('<div id="chown" class="formarea"><div class="pseudoform scf"></div></div>');
    object_id = obj_id;
    except_community_user_id = except_cu_id;
    chown_get_community_users(0, null);    
}

function chown_get_community_users (pointer, search) {            
    query = {except_community_user_id: except_community_user_id,community_id: community_id, pointer: pointer, rows: 6, search:search};    
    $.ajax({data: 'action=get_community_users&query='+JSON.stringify(query), success: chown_show_community_users})
}
function chown_show_community_users (data, textStatus) {       
    $('#chown .pseudoform').empty();
    if (data.info.search != null) search_str = data.info.search;
    else search_str = '';
    $('#chown .pseudoform').append('<div class="scf"><div class="top_right"><input type="text" onkeyup="chown_check_submit_key(event, 0, $(\'#chown_search\').val())" class="text form_text" id="chown_search" value="'+search_str+'" /><input type="button" name="search" value="'+h19168+'" class="btn form_submit" onclick="chown_get_community_users (0, $(\'#chown_search\').val())" /></div></div>');
    if (data.results.length > 0) {
        chown_show_pager(data.info);        
        for(x = 0;x < data.results.length;x++){
            if (data.results[x].nick != null) name = data.results[x].nick;
            else name = data.results[x].user.person.firstname+' '+data.results[x].user.person.lastname;
            $('#chown .pseudoform').append('<div class="list_item user" onclick="submit_post(\'.\', \'action=chown&amp;objet_id='+object_id+'&amp;cu_id='+data.results[x].id+'\', false);"><div class="ullogo"><img src="/images/user-'+data.results[x].id+'-0.jpg" /></div><div class="ulname"><strong>'+$('<div/>').text(name).html()+'</strong></div></div>');
        }        
    }
    else {
        $('#chown .pseudoform').append('<div class="nocontent">'+h19173+'</div>');
    }
}
function chown_show_pager(info){   
    $('#chown .pager').remove();
    if (info.rows_total > 1){
        $('#chown .pseudoform').append('<div class="pager"></div>');        
                        
        currpage = Math.ceil(info.pointer / info.rows)+1;
        pages = Math.ceil(info.rows_total / info.rows);                
        if (currpage.toString().substr(-1) == 0 && currpage) start = currpage-1;
        else start = currpage;

        if (info.search == null) info.search = '';       
        
        if (currpage > 1) {
            $('#chown .pager').append('<a onclick="chown_get_community_users(0, \''+info.search+'\');">&lt;&lt;</a>');
            $('#chown .pager').append('<a class="stepf" onclick="chown_get_community_users('+(currpage-2)*info.rows+', \''+info.search+'\');">&lt;</a>');
        }
        $('#chown .pager').append(h50102+' ');        
        i = 0;
        while (i <= 10 && (Math.floor(start / 10) * 10 + i) < info.rows_total / info.rows) {
            i++;
            if (i == 1 && (Math.floor(start / 10))) { 
                pointer = ((Math.floor(start/10)*10) -1) * info.rows;                          
                $('#chown .pager').append('<a onclick="chown_get_community_users('+pointer+', \''+info.search+'\');">...</a>');                                                              
            }
            if (i <= 10 && currpage!=(Math.floor(start / 10) * 10 + i)) {
                page_num = Math.floor(start / 10) * 10 + i;
                pointer = ((Math.floor(start/10)*10+i) -1) * info.rows;
                $('#chown .pager').append('<a onclick="chown_get_community_users('+pointer+', \''+info.search+'\');">'+page_num+'</a>');
            }
            else if (currpage == (Math.floor(start / 10) * 10 + i)) {
                page_num = Math.floor(start / 10) * 10 + i;
                $('#chown .pager').append('<strong>'+page_num+'</strong>');             
            }
            else {
                pointer = ((Math.floor(start/10)*10+i) -1) * info.rows;
                $('#chown .pager').append('<a onclick="chown_get_community_users('+pointer+', \''+info.search+'\');">...</a>');
            }
        }        
        if (currpage < Math.ceil(info.rows_total / info.rows)) {
            $('#chown .pager').append('<a class="stepb" onclick="chown_get_community_users('+(currpage)*info.rows+', \''+info.search+'\');">&gt;</a>');
            $('#chown .pager').append('<a onclick="chown_get_community_users('+(pages-1)*info.rows+', \''+info.search+'\');">&gt;&gt;</a>');
        }        
    }
}
function chown_check_submit_key(event, p1, p2) {
    if (event.keyCode == 13) {
        get_community_users (p1, p2);
    }
}
function tag_pop(cu_id, tags){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20514, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 50});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 50);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20514);
        $('#modaldialog').dialog('open');        
    }    
    $('#modaldialog').html('<div id="tag" class="formarea"><form method="post" class="scf" action="."><input type="hidden" class="hidden" name="action" value="bookmark" /><input type="hidden" class="hidden" name="id" value="'+cu_id+'" /><label for="tf-tags"><strong>'+h10101+'</strong> ('+h13264+')</label><input type="text" name="tags" id="tf-tags" class="input_text" value="'+tags.replace('"', '&quot;')+'" maxlength="255" tabindex="510" /><input type="submit" value="'+h10102+'" class="btn" tabindex="511" /> <small>'+h20519+'</small></form></div>');        
}    
function note_pop(object_id, note){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20515, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 270});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 270);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20515);
        $('#modaldialog').dialog('open');        
    }   
    $('#modaldialog').html('<div id="note" class="formarea"><form method="post" action="." class="scf"><input type="hidden" name="action" value="add-object-note" /><input type="hidden" name="object_id" value="'+object_id+'" /><label for="tf-note"><strong>'+h20358+'</strong></label><textarea name="note" id="note" cols="40" rows="6" tabindex="512">'+note.replace('"', '&quot;')+'</textarea><p class="txtcounter">'+h19183+' <span id="txt_counter"></span> '+h19184+'.</p><input type="submit" value="'+h20360+'" class="btn" tabindex="513"/><small>'+h20518+'</small></form></div>');   
    $(document).ready(function(){$('#note').maxChar(21845, {indicator: 'txt_counter'});});
}
function ping_pop(cu_id, type){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: '', dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 230});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 230);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', '');
        $('#modaldialog').dialog('open');        
    }   
    $('#modaldialog').html('<div id="ping" class="formarea"><form method="post" action="." class="scf"><input type="hidden" name="action" value="ping-user" /><input type="hidden" name="id" value="'+cu_id+'" /><input type="hidden" name="type" id="png_type" value="'+type+'" /><span class="fright helptext h10" style="position:relative;"></span><label for="ping_msg">'+h12367+'</label><textarea name="message" id="ping_msg" style="height:80px;" cols="40" rows="6" tabindex="508" ></textarea><p class="txtcounter">'+h19183+' <span id="ping_counter"></span> '+h19184+'.</p><input type="submit" value="'+h13241+'" class="btn" tabindex="509"/></form></div>');   
    $(document).ready(function(){$('#ping_msg').maxChar(140, {indicator: 'ping_counter'});});
}               
function friendship_pop(cu_id){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20516, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 280});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 280);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20516);
        $('#modaldialog').dialog('open');        
    }   
    $('#modaldialog').html('<div id="contact" class="formarea"><form method="post" class="scf" action="."><input type="hidden" name="action" value="add-friend" /><input type="hidden" name="id" value="'+cu_id+'" /></form></div>');      
    if (friend_categories.length > 0) {
        $('#contact form').append('<select name="category" tabindex="514"></select>');  
        for(x = 0;x < friend_categories.length;x++){
             $('#contact form select').append('<option value="'+friend_categories[x].id+'">'+friend_categories[x].name+'</option>');
        }
    }    
    $('#contact form').append('<label for="send_message">'+h11203+'</label><textarea id="send_message" name="message" cols="40" rows="6" tabindex="515"></textarea><p class="txtcounter">'+h19183+' <span id="txt_counter"></span> '+h19184+'.</p><input type="submit" value="'+h10105+'" class="btn" tabindex="516"/> ');
    $(document).ready(function(){$('#send_message').maxChar(21845, {indicator: 'txt_counter'});});
}                                         

function contact_offline_pop(cu_id){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20517, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 510});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 500);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20517);
        $('#modaldialog').dialog('open');        
    }
    $('#modaldialog').html('<div id="contact-offline" class="formarea"><form method="post" class="scf" action="."><input type="hidden" name="action" value="contact-user" /><input type="hidden" name="id" value="'+cu_id+'" /><label for="cf-name" class="bold_text">'+h20509+'</label><input type="text" name="name" id="cf-name" class="input_text" value="" maxlength="255" tabindex="520" /><label for="cf-email" class="bold_text">'+h8104+'</label><input type="text" name="email" id="cf-email" class="input_text" value="" maxlength="255" tabindex="521" /><label for="cf-captcha" class="bold_text">'+h19191+'</label><img src="/captcha.png?id='+cu_id+'" id="captcha'+cu_id+'" class="captcha" alt="captcha" /><a href="javascript:reload_captcha('+cu_id+');" class="reload-captcha hbgc04"></a><label for="cf-captcha" class="clear">'+h19192+'</label><input type="text" name="captcha" id="cf-captcha" class="input_text" value="" maxlength="8" tabindex="522" /><label for="offline_message" class="bold_text">'+h12367+'</label><textarea class="list_tell_friend" id="offline_message" name="message" cols="40" rows="6" tabindex="523"></textarea><p class="txtcounter">'+h19183+' <span id="offline_counter"></span> '+h19184+'.</p><input type="submit" value="'+h19190+'" class="btn" tabindex="524"/></form></div>');
    $(document).ready(function(){$('#offline_message').maxChar(21845, {indicator: 'offline_counter'});});
}
function reload_captcha(id){
    getById('captcha'+id).src = '/captcha.png?id='+id+'&tamp;='+ (new Date()).getTime();
}
function vcard_pop(cuid){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20243, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 300, height: 'auto'});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 'auto');
        $('#modaldialog').dialog('option', 'width', 300);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20243);             
        $('#modaldialog').dialog('open');
    }    
    var permalink = 'http://'+window.location.hostname+'/vcard/'+cuid+'/?encoding=win';
    $('#modaldialog').html('<form action="/vcard/'+cuid+'/" id="inline_pop_form" method="post"><div style="margin-bottom:10px;"><input id="encoding1" type="radio" name="encoding" value="win" checked="checked" onchange="javascript:vcard_show_permalink('+cuid+', 1);" /><label for="encoding1" style="display:inline;margin-left:5px;">'+h20251+'</label></div><div style="margin-bottom:10px;"><input id="encoding2" type="radio" name="encoding" value="utf8" onchange="javascript:vcard_show_permalink('+cuid+', 0);" /><label for="encoding2" style="display:inline;margin-left:5px;">'+h20252+'</label></div><div style="margin-bottom:5px;" id="vcard_permalink"><strong>'+h20253+':</strong><br /> <a href="'+permalink+'">'+trim_permalink(permalink)+'</a></div><input type="submit" class="btn" value="'+h20249+'" onclick="return submit_inline_pop();" style="float:right !important;" /></form>');    
}
function vcard_show_permalink(cuid, mode){
   $('#vcard_permalink').empty();
   var permalink = 'http://'+window.location.hostname+'/vcard/'+cuid+'/';
   if (mode == 1) permalink = permalink + '?encoding=win';
    $('#vcard_permalink').append('<strong>'+h20253+':</strong><br /> <a href="'+permalink+'">'+trim_permalink(permalink)+'</a>');
}
function attendees_pop(event_url){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20513, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 300, height: 'auto'});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 'auto');
        $('#modaldialog').dialog('option', 'width', 300);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20513);        
        $('#modaldialog').dialog('open');
    }    
    var permalink = 'http://'+window.location.hostname+event_url+'attendees-export.html?format=csv';
    
    $('#modaldialog').html('<form action="'+event_url+'attendees-export.html" id="inline_pop_form" method="post"><div style="margin-bottom:10px;"><input id="format1" type="radio" name="format" value="csv" checked="checked" onchange="javascript:attendees_show_permalink(\''+event_url+'\', 0);" /><label for="format1" style="display:inline;margin-left:5px;">'+h20465+'</label></div><div style="margin-bottom:10px;"><input id="format2" type="radio" name="format" value="excel" onchange="javascript:attendees_show_permalink(\''+event_url+'\', 1);" /><label for="format2" style="display:inline;margin-left:5px;">'+h20466+'</label></div><div style="margin-bottom:5px;" id="attendees_permalink"><strong>'+h20253+':</strong><br /> <a href="'+permalink+'">'+trim_permalink(permalink)+'</a></div><input type="submit" class="btn" value="'+h20249+'" onclick="return submit_inline_pop();" style="float:right !important;" /></form>');            
}
function attendees_show_permalink(event_url, mode){
   $('#attendees_permalink').empty();
   var permalink = 'http://'+window.location.hostname+event_url+'attendees-export.html';
   if (mode == 0) permalink = permalink + '?format=csv';
   else if (mode == 1) permalink = permalink + '?format=excel';
    $('#attendees_permalink').append('<strong>'+h20253+':</strong><br /> <a href="'+permalink+'">'+trim_permalink(permalink)+'</a>');
}
function trim_permalink(str){
    if (str.length > 35) {
        str = str.substring(0, 15)+' ... '+str.substring(str.length-15, str.length);
    }
    return str;
}
function submit_inline_pop(){
    $('#modaldialog').dialog('close');
    getById('inline_pop_form').submit();
    return false;
}
function application_reply_pop(cu_id){
    if (!getById('modaldialog')) {
        $('body').append('<div id="modaldialog"></div>');
        $('#modaldialog').dialog({bgiframe: true, modal: true, title: h20517, dialogClass: 'tribax-modal tribax-dialog bgc06', draggable: false, resizable: false, width: 404, height: 290});
    }    
    else {
        $('#modaldialog').dialog('option', 'height', 290);
        $('#modaldialog').dialog('option', 'width', 404);
        $('#modaldialog').dialog('option', 'dialogClass', 'tribax-modal tribax-dialog bgc06');
        $('#modaldialog').dialog('option', 'title', h20517);        
        $('#modaldialog').dialog('open');
    }    
    
    $('#modaldialog').html('<div id="application-reply" class="formarea"><form method="post" action="." class="scf"><input type="hidden" name="action" value="application-reply" /><input type="hidden" name="applicant" value="'+cu_id+'" /><label for="body" class="bold_text">'+h12367+'</label><textarea name="body" id="send_reply" cols="40" rows="6" tabindex="525"></textarea><p class="txtcounter">'+h19183+' <span id="txt_counter"></span> '+h19184+'.</p><div style="margin-bottom:10px;"><input id="givemail" type="checkbox" name="from" value="1" tabindex="526" /> <label for="givemail" style="display:inline;margin-left:5px;">'+h13266+'</label></div><input type="submit" value="'+h13241+'" class="btn" tabindex="527" /></form></div>');
    
    $(document).ready(function(){$('#send_reply').maxChar(21845, {indicator: 'txt_counter'});});
}

/**
 * Get a display name string
 * @param object user|mini_user
 * @package new invitation management
 **/
function getDisplayName(obj) {
    if (undefined != obj.display_name) {
        switch (c_srn)
        {
            case "3":
                return obj.user.person.lastname+', '+obj.user.person.firstname;
                break;
            case "2":
                return obj.display_name;
                break;
            case "1":
                if (undefined != obj.user.person.lastname && undefined != obj.user.person.firstname) {
                    return obj.user.person.lastname+', '+obj.user.person.firstname;
                } else {
                    return obj.display_name
                }
                break;
            default:
                if (undefined != obj.user.nick) {
                    return obj.user.nick;
                } else {
                    return obj.user.person.lastname+', '+obj.user.person.firstname;
                }
        }
    } else {
        return obj.name;
    }

}


