/* 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).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 = ''
        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 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) {
    document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    "; path=/" +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

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.style.width = '1px';
    i.style.height = '1px';
    getById('wrapper').appendChild(i);
    benchmark_sent = true;
}
/* 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';
    setCookie(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 switchform(type, form) {
    if (active_form[type]) {
        if (active_form[type] == form){
            if (active_switch[type] && null != getById(form + active_switch[type])) form_id = form + active_switch[type];
            else form_id = form;

            getById(form_id).style.display = 'none';
            active_form[type] = false;
        }
        else {
            if (active_switch[type]) {
                form_id_1 = active_form[type] + active_switch[type];
                form_id_2 = form + active_switch[type];
            }
            else{
                form_id_1 = active_form[type];
                form_id_2 = form;
            }
            getById(form_id_1).style.display = 'none';
            getById(form_id_2).style.display = 'block';
            active_form[type] = form
        }
    }
    else {
        if (active_switch[type] && null != getById(form + active_switch[type])) {
            form_id = form + active_switch[type];
        }
        else form_id = form;

        getById(form_id).style.display = 'block';
        active_form[type] = form;
    }
}
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();
    setCookie('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;
        
        ns = document.createElement('span');
        ns.appendChild(document.createTextNode(txt3));

        p = document.createElement('p');
        p.className = 'txtcounter';
        p.appendChild(document.createTextNode(txt1+' '));
        s = document.createElement('span');
        s.setAttribute('id', 'body_'+id+'_count');
        p.appendChild(s);
        p.appendChild(document.createTextNode(' '+txt2));

        scrpt = document.createElement('script');
        scrpt.setAttribute('type', 'text/java'+'script');
        if (null == scrpt.canHaveChildren || scrpt.canHaveChildren) {
            scrpt.appendChild(document.createTextNode('var wysiwyg_'+id+';wysiwyg_'+id+' = new nicEditor().panelInstance("body_'+id+'", null, 21845);'));
        }
        else {
            scrpt.text = 'var wysiwyg_'+id+';wysiwyg_'+id+' = new nicEditor().panelInstance("body_'+id+'", null, 21845);';
        }
				
        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(ns);
        f.appendChild(p);
        //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);
        div.appendChild(scrpt);
    }
}

function submit_post(target, param_str, confirm_msg){
    form = document.createElement('form');
    form.setAttribute('method', 'POST');
    form.setAttribute('action', target);
    form.setAttribute('id', 'hiddenform');
    form.setAttribute('style', 'display:none;');
    params = param_str.split('&');
    for (i = 0;i < params.length; i++) {
        p = params[i].split('=');
        input = document.createElement('input');
        input.setAttribute('name', p[0]);
        input.setAttribute('type', 'hidden');
        input.value = p[1]
        form.appendChild(input);
    }

    if (confirm_msg == false){
    	document.lastChild.lastChild.appendChild(form);
    	document.getElementById('hiddenform').submit();
    }
    else {
        if (confirm(confirm_msg)) {
        	document.lastChild.lastChild.appendChild(form);
        	document.getElementById('hiddenform').submit();
        }
        else{
            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');
		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);
	over.setAttribute('style', 'display:none;')
	div.appendChild(over);
	
    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 (indexOfArray(condition_options, getById('condition_key').options[j].value) != -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';
	                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';
	                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) {
	   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))};    
	}
    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);
            }
        }
        alert_conditions();
    }
}

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();

function indexOfArray(array, string, start) {
    for (var i = (start || 0); i < array.length; i++) {
        if (array[i] == string) {
            return i;
        }
    }
}

/* JS Functions for chown */

function show_loading(){
    if (active_switch[c_form_type] && null != getById(active_form[c_form_type] + active_switch[c_form_type])) form_id = active_form[c_form_type]+active_switch[c_form_type]+' .pseudoform';
    else form_id = active_form[c_form_type]+' .pseudoform';  
        
    $('#'+form_id+' *').css('visibility', 'hidden');
    $('#'+form_id).addClass('ajax-loading');
}

function hide_loading(){
    if (active_switch[c_form_type] && null != getById(active_form[c_form_type] + active_switch[c_form_type])) form_id = active_form[c_form_type]+active_switch[c_form_type]+' .pseudoform';
    else form_id = active_form[c_form_type]+' .pseudoform';  
        
    $('#'+form_id).removeClass('ajax-loading');
    $('#'+form_id+' *').css('visibility', 'visible');
}

function show_error(){
    //alert('something went wrong');
}

function get_community_users (pointer, search) {            
    query = {except_community_user_id: except_community_user_id,community_id: community_id, pointer: pointer, rows: 9, search:search};    
    $.ajax({data: 'action=get_community_users&query='+JSON.stringify(query), success: show_community_users})
}
/* test if enter was pressed and submit pseudo form */
function check_submit_key(event, p1, p2) {
    if (event.keyCode == 13) {
        get_community_users (p1, p2);
    }
}
function show_community_users (data, textStatus) {       
    if (active_switch[c_form_type] && null != getById(active_form[c_form_type] + active_switch[c_form_type])) form_id = active_form[c_form_type]+active_switch[c_form_type]+' .pseudoform';
    else form_id = active_form[c_form_type]+' .pseudoform';  

    $('#'+form_id).empty();
    if (data.info.search != null) search_str = data.info.search;
    else search_str = '';
    $('#'+form_id).append('<hr /><div class="scf"><div class="top_right"><input type="text" onkeyup="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="get_community_users (0, $(\'#chown_search\').val())" /></div></div>');
    if (data.results.length > 0) {
        show_chown_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;
            $('#'+form_id).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><strong>'+$('<div/>').text(name).html()+'</strong></div>');
            //if ((x+1) % 3 == 0 && x+1 != data.results.length) $('#'+form_id).append('<div class="line"></div>');
        }        
    }
    else {
        $('#'+form_id).append('<div class="nocontent">'+h19173+'</div>');
    }
}

function show_chown_pager(info){
    if (active_switch[c_form_type] && null != getById(active_form[c_form_type] + active_switch[c_form_type])) form_id = active_form[c_form_type]+active_switch[c_form_type]+' .pseudoform';
    else form_id = active_form[c_form_type]+' .pseudoform';    
    
    $('.pager').remove();
    if (info.rows_total > 1){
        $('#'+form_id).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) {
            $('.pager').append('<a onclick="get_community_users(0, \''+info.search+'\');">&lt;&lt;</a>');
            $('.pager').append('<a class="stepf" onclick="get_community_users('+(currpage-2)*9+', \''+info.search+'\');">&lt;</a>');
        }
        $('.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;                          
                $('.pager').append('<a onclick="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;
                $('.pager').append('<a onclick="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;
                $('.pager').append('<strong>'+page_num+'</strong>');             
            }
            else {
                pointer = ((Math.floor(start/10)*10+i) -1) * info.rows;
                $('.pager').append('<a onclick="get_community_users('+pointer+', \''+info.search+'\');">...</a>');
            }
        }        
        if (currpage < Math.ceil(info.rows_total / info.rows)) {
            $('.pager').append('<a class="stepb" onclick="get_community_users('+(currpage)*9+', \''+info.search+'\');">&gt;</a>');
            $('.pager').append('<a onclick="get_community_users('+(pages-1)*9+', \''+info.search+'\');">&gt;&gt;</a>');
        }        
    }
}

function switch_chown_form (type, form, obj_id, except_cu_id){
    c_form_type = type;
    switchform(type, form);    
    
    if (active_form[type] != false) {
        object_id = obj_id;
        except_community_user_id = except_cu_id;
        get_community_users(0, null);
    }
    else {
        if (active_switch[type] && null != getById(active_form[type] + active_switch[type])) form_id = active_form[type] + active_switch[type];
        else form_id = active_form[type];    
        
        $('#'+form_id).empty();
        object_id = null;
        except_community_user_id = null;
    }
}

/**
 * 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;       
        bgColor = $(selector).css('background-color');
        fgColor = $(selector).css('color');
        $(selector).empty().append('<object height="'+height+'" width="'+width+'" data="'+domain+'/swf/videoplayer.swf" id="flvplayer" type="application/x-shockwave-flash">'+
        '<param name="quality" value="high" />'+
        '<param name="movie" value="'+domain+'/swf/videoplayer.swf" />'+
        '<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>');    
    }    
}