// <![CDATA[
var tempX = 0;
var tempY = 0;
var curH = 0;
var hX = 0;
var deffontSize = new Array();
var won = null;
var heads, hnum;

function video_onplay(article_id) {
    phpSend('add_view/'+article_id);
}

function video_onfullscreen(article_id) {
    if(!$('video_'+article_id)) return;
    var ratio = $('video_'+article_id).getWidth()/$('video_'+article_id).getHeight();
    //$('video_'+article_id).setStyle('position:absolute;width:'+$('content').getWidth()+'px;left:0;top:'+$('content').positionedOffset().top+';height:500px');
    $('video_'+article_id).setStyle('width:'+$('content').getWidth()+'px;height:'+($('content').getWidth()/ratio)+'px;');
}

function nextMon(way) {
    if(way == 0) lunacur++;
    if(way == 1) lunacur += -1;
    if(lunacur >= lunile.length) lunacur += -1;
    if(lunacur < 0) lunacur = 0;
    for(i=0;i<lunile.length;i++)
        $('luna'+i).hide()
    $('luna'+lunacur).show();
    $('moname').innerHTML = lunile[lunacur];
}

var interv = null;
function csLogin() {
    if($('fbname') && $('fbname').innerHTML) {
        clearInterval(interv);
        phpSend('facebook_login');
    }
}

function facebook_login() {
    if($('fb_test'))
        $('fb_test').remove();
    var deb = d.createElement('div');
    deb.id = 'fb_test';
    deb.className = 'hidden';
    deb.innerHTML = '<fb:name uid="loggedinuser" id="fbname" useyou="false" linked="false"></fb:name>';
    $(d.body).appendChild(deb);
    interv = setInterval('csLogin()',100);
    FB.XFBML.Host.parseDomTree(); 
}

function initHeads() {
    heads = d.getElementsByClassName('headlines');
    if(!heads.length) return;
    for(var i=1;i<heads.length;i++) {
        heads[i].hide();
    }
    heads.executer = new PeriodicalExecuter(function(pe) { setHead();} , 4);
    hnum = d.getElementsByClassName('hnum');
    if(hnum[0])
        hnum[0].addClassName('on');
    for(var i=0;i<hnum.length;i++) {
        hnum[i].onclick = function() {
            setHead(parseInt(this.innerHTML));
            this.blur();
            return false;
        }
    }
}

function setHead(i) {
    new Effect.Fade(heads[curH], {duration:0.5});
    if(hnum[curH])
        hnum[curH].removeClassName('on');
    if(!i) {
        curH += 1;
        if(curH >= heads.length)
            curH = 0;
    } else {
        if(i-1 == curH) return;
        curH = i-1;
        heads.executer.stop();
    }
    new Effect.Appear(heads[curH], {duration:0.6});
    if(hnum[curH])
        hnum[curH].addClassName('on');
}

function switch_content(id, content) {
    if($(id).hasClassName('hidden')) {
        $(id).removeClassName('hidden');
        $(id).hide();
    }
    Effect.Fade(id, {
        duration : 0.5,
        afterFinishInternal : function(effect) {
            $(id).update(content);
            Effect.Appear(id, {duration : 0.5});
            setTimeout('setHeights()', 100);
        }
    });
}

String.prototype.toPhp = function() {
    var val = this.toString();
    val = val.replace(/\n/g, '<br>');
    val = val.replace(/&/g, '[]amp;');
    val = val.replace(/\//g, '[]slash;');
    val = val.replace(/%/g, '[]suta;');
    val = val.replace(/#/g, '[]diez;');
    val = val.replace(/\?/g, '[]ask;');
    val = val.replace(/“/g, '"');
    val = val.replace(/”/g, '"');
    return val;
}
String.prototype.brnl = function() {
    var val = this.toString();
    val = val.replace(/<br>/g, '\n');
    return val;
}
String.prototype.nlbr = function() {
    var val = this.toString();
    val = val.replace(/\n/g, '<br>');
    return val;
}
String.prototype.toFloat = function() {
    var val = this.toString();
    val = val.replace(/,/g, '.');
    var ind = val.match(/0|1|2|3|4|5|6|7|8|9/);
    if(ind && ind.index)
        val = val.substring(ind.index);
    val = parseFloat(val);
    if(isNaN(val))
        val = 0;
    return val;
}

function email_valid(str) {
    return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)) ? true : false;
}

function getAHash() {
    if(window.lastAnchor && window.lastAnchor == location.hash) return;
    window.lastAnchor = location.hash;
    var hash = location.hash.substring(1);
    if(hash.split('/').length < 3) return;
    phpSend(hash);
}

function init() {
    setHeights();
    initTabs();
    correctPNG();
    initAjax();
    initForms();
    initRels();
    initMenu();
    initFront();
    //initHeads();
    if($('arti_feat_day') && $('arti_feats')) {
        var ch = Math.max($('arti_feat_day').getHeight(), $('arti_feats').getHeight());
        $('arti_feat_day').down().setStyle('height:'+(ch-36)+'px');
        $('arti_feats').setStyle('height:'+ch+'px');
    }
}

function popMessage(message, stay) {
    if(!message) return;
    popInit();
    popLoad('<div class="pop"><div class="top"></div><div class="pop">'+message+'</div><div class="bot"></div></div>');
    if(!stay)
        setTimeout('popClose()', 4000);
}

function initFront() {
    if(!$('weather')) return;
    setTimeout('phpSend(\'front_options\')', 100);
    //phpSend('front_options');
}

function initMenu() {
    if(!isie6) return;
    $$(".menu").each(function(el) {
        if(el.tagName == 'UL') {
            el.immediateDescendants().each(function(elu) {
                Event.observe(elu, 'mouseover', function() {this.addClassName('hover');});
                Event.observe(elu, 'mouseout', function() {this.removeClassName('hover');});
            });
        }
    });
}

function addToForm(fname, inputname, value, type) {
    if(!type) type = 'hidden';
    if(!d[fname]) {
        debug('error'); 
        return;
    }
    var deb = d.createElement('input');
    deb.type = type;
    deb.name = inputname;
    deb.value = value;
    d[fname].appendChild(deb);
}

function initAjax() {
    getAHash();
    if ("onhashchange" in window)
        window.onhashchange = getAHash;
    else
        Event.observe(document, 'click', function() { setTimeout('getAHash()', 10); });
}

function resetInput(ins) {
    ins.removeClassName('err');
    if(ins.previous() && ins.previous().tagName == 'LABEL')
        ins.previous().removeClassName('err');
    else if(ins.next() && ins.next().tagName == 'LABEL')
        ins.next().removeClassName('err');
    if($(ins.spid)) {
        $(ins.spid).removeClassName('ok');
        $(ins.spid).removeClassName('err');
    }
    if(ins.type && ins.type == 'radio') {
        $A(document.getElementsByTagName('input')).each(function(el) { 
            if(el.type == 'radio' && el.name == ins.name)
                if($(el.spid)) {
                    $(el.spid).removeClassName('ok');
                    $(el.spid).removeClassName('err');
                }
        });
    }
    
}

function validateInput(ins) {
    resetInput(ins);
    //span start
    if(!window.spids)
        window.spids = [];
    if(!ins.spid) {
        window.spids.push(window.spids.length);
        ins.spid = 'spid_'+window.spids[window.spids.length-1];
        var span = document.createElement('DIV');
        span.id = ins.spid;
        $(document.body).appendChild(span);
        var element = ins;
        var valueL = 0;
        do {
          valueL += element.offsetLeft || 0;
          element = element.offsetParent;
          if (element && element.tagName.toUpperCase() == 'BODY') break;
        } while (element);
        //valueL = ins.positionedOffset().left;
        $(ins.spid).setStyle('position:'+($('popload') && !isie6 ? 'fixed' : 'absolute')+';margin-left:1px;left:'+(valueL+ins.getWidth())+'px;top:'+(ins.positionedOffset().top-3)+'px;z-index:101');
    }
    //span end
    //check start
    if(ins.type == 'radio' && ins.hasClassName('req')) {
        var form = ins;
        while(form.tagName != 'FORM')
            if(form.up())
                form = form.up();
            else
                break;
        var result = false;
        form.getElements().each(function(el) {
            if(el.name == ins.name && el.checked)
                result = true;
        });
        if(result) {
            if(ins.checked) {
                ins.addClassName('ok');
                $(ins.spid).addClassName('ok');
            }
            return true;
        } else {
            ins.addClassName('err');
            if(ins.previous() && ins.previous().tagName == 'LABEL')
                ins.previous().addClassName('err');
            else if(ins.next() && ins.next().tagName == 'LABEL')
                ins.next().addClassName('err');
            $(ins.spid).addClassName('err');
            return false;
        }
    }
    if(
        (ins.value && ins.value != ins.defval && ins.name.match('email') && !email_valid(ins.value)) ||
        (ins.value && ins.hasClassName('int') && !parseFloat(ins.value)) ||
        (ins.hasClassName('req') && 
            (
                (ins.type && ins.type == 'checkbox' && !ins.checked) ||
                (ins.type && (ins.type == 'password' || ins.type == 'text') && (!ins.value || ins.value == ins.defval)) ||
                (ins.tagName == 'TEXTAREA' && (!ins.value || ins.value == ins.defval)) ||
                (ins.tagName == 'SELECT' && (!ins.value || ins.value == ins.defval || ins.value == '0'))
            )
        )
    ) {
        ins.addClassName('err');
        if(ins.previous() && ins.previous().tagName == 'LABEL')
            ins.previous().addClassName('err');
        else if(ins.next() && ins.next().tagName == 'LABEL')
            ins.next().addClassName('err');
        $(ins.spid).addClassName('err');
        return false;
    } else {
        ins.addClassName('ok');
        $(ins.spid).addClassName('ok');
        return true;
    }
    //check end
}


function initForms() {
    //byclassname = $$(".req")
    var elements = [];
    $A(document.getElementsByTagName('input')).each(function(el) {
        if(el.type == 'radio' || el.type == 'checkbox' || el.type == 'text' || el.type == 'password')
            elements.push(el);
    });
    $A(document.getElementsByTagName('textarea')).each(function(el) { elements.push(el); });
    $A(document.getElementsByTagName('select')).each(function(el) { elements.push(el); });
    elements.each(function(ins) {
        if(ins.parsed) return;
        ins.parsed = true;
        if($(ins).hasClassName('req')) {
            ins.defval = ins.className.substring(ins.className.match('req').index+4);
            if(ins.type && ins.type != 'radio' && ins.previous() && ins.previous().tagName == 'LABEL')
                ins.previous().innerHTML += '*';
            else if(ins.type && ins.type != 'radio' && ins.next() && ins.next().tagName == 'LABEL')
                ins.next().innerHTML += '*';
        }
        if(isie6 && ins.type && ins.type == 'text')
            $(ins).addClassName('text');
        if(ins.previous() && ins.previous().tagName == 'LABEL')
            ins.previous().observe('click', function() { this.next().focus(); });
        else if(ins.next() && ins.next().tagName == 'LABEL')
            ins.next().observe('click', function() { this.previous().focus(); });
        if(ins.hasClassName('def'))
            ins.defval = ins.className.substring(ins.className.match('def').index+4);
        if(ins.defval && !ins.value && ((ins.type && ins.type == 'text') || ins.tagName == 'TEXTAREA'))
            ins.value = ins.defval;
        Event.observe(ins, 'focus', function(event) {
            if(this.value == this.defval)
                this.value = '';
            this.addClassName('over');
            resetInput(this);
            this.focused = true;
        });
        Event.observe(ins, 'blur', function(event) {
            if(this.defval && !this.value)
                this.value = this.defval;
            this.removeClassName('over');
            this.focused = false;
            validateInput(this);
        });
        Event.observe(ins, 'mouseover', function(event) {
            this.addClassName('over');
        });
        Event.observe(ins, 'mouseout', function(event) {
            if(!this.focused)
                this.removeClassName('over');
        });
    });
    
    $A(d.forms).each(function(el) {
        if(el.parsed) return;
        el.parsed = true;
        if(!el.action)
            el.action = location.hash ? location.href.substring(0,location.href.indexOf('#')) : location.href;
        
        el.elsubmit = el.onsubmit ? el.onsubmit.toString().replace(/[\s\S]+{\n|\n}/gi, '').replace(/this./gi, 'el.').replace(/(return\s+)(\w+)/gi, '$2') : '';
        el.onsubmit = function() {}
        
        Event.observe(el, 'submit', function(event) {
            //var radioNames = [];
            //this.getInputs('radio').each(function(ins) {});
            var err = false;
            this.getElements().each(function(ins) {
                if((!ins.type || ins.type == 'radio' || ins.type == 'checkbox' || ins.type == 'text' || ins.type == 'password' || ins.type == 'textarea') && !validateInput(ins))
                    err = true;
            });
            if(err) {
                if(!$('formerr')) {
                    var deb = d.createElement('div');
                    deb.id = 'formerr';
                    $(d.body).appendChild(deb);
                    $('formerr').update(formerrort);
                    $('formerr').addClassName('formerr');
                    $('formerr').setStyle('float:left;');
                    $('formerr').setStyle('z-index:200;position:'+(isie6 ? 'absolute' : 'fixed')+';top:'+(isie6 ? document.viewport.getScrollOffsets().top+5 : 5)+'px;left:'+parseInt(document.viewport.getDimensions().width/2 - $('formerr').getWidth()/2)+'px');
                }
                $('formerr').show();
                event.stop();
            } else {
                if(el.elsubmit)
                    if(eval(el.elsubmit) == false)
                        event.stop();
                if($('formerr')) $('formerr').hide();
                this.getElements().each(function(ins) {
                    if(ins.defval && ins.defval == ins.value)
                        ins.value = '';
                    if(ins.type && ins.type == 'submit')
                        ins.disabled = true;
                });
                var deb = d.createElement('input');
                deb.type = 'hidden';
                deb.name = 'validated';
                deb.value = '1';
                this.appendChild(deb);
                if(this.action.match('ajax')) {
                    this.request({ onSuccess: function(transport) { 
                        var response = transport.responseText;
                        if(response) {
                            if(response.match('eval:')) {
                                var ev = response.substring(response.indexOf('eval:')+5);
                                response = response.substring(0, response.indexOf('eval:'));
                                eval(ev);
                            }
                            if(response)
                                debug(response);
                            if(window.spids)
                                window.spids.each(function(el) {
                                    if($('spid_'+el)) 
                                        $('spid_'+el).removeClassName('ok');
                                });
                        } else {
                            location.href = (location.hash ? location.href.substring(0,location.href.indexOf('#')) : location.href);
                            if(isie) event.returnValue=false;
                        }
                    } });
                    event.stop();
                    deb.remove();
                }
            }
        });
    });
}

function initTabs() {
    $$(".tabs").each(function (element) {
        $A(element.getElementsByTagName('a')).each(function (el) {
            el.onclick = function(event) {
                $A($(this).up().getElementsByTagName('a')).each(function(ael) {
                    if(!$(ael.rel).hasClassName('hidden'))
                        $(ael.rel).addClassName('hidden');
                    if($(ael).hasClassName('active'))
                        $(ael).removeClassName('active');
                });
                $(this.rel).removeClassName('hidden');
                this.addClassName('active');
                this.blur();
                return false;
            }
        });
    });
}

window.onscroll = function() {
    if(!isie6) return;
    var dim = d.viewport.getScrollOffsets();
    if($('debug'))
        $('debug').style.top = (dim.top+5)+'px';
    if($('popload'))
        $('popload').style.top = dim.top+'px';
    if($('formerr'))
        $('formerr').style.top = (dim.top+5)+'px';
}

function fSize(inc) {
    var fo = d.getElementsByClassName('abody');
    if(fo.length < 1) return;
    var fos = 0;
    for(var i=0;i<fo.length;i++) {
        fos = parseInt(fo[i].getStyle('fontSize'));
        if(!deffontSize[i]) deffontSize[i] = fos;
        if(inc == 2) if(fos < deffontSize[i]+8) fos++;
        if(inc == 1) if(fos > deffontSize[i]-2) fos--;
        fo[i].style.fontSize = fos+'px';
        var desce = fo[i].descendants();
        for(var j=0;j<desce.length;j++)
        if(desce[j].nodeName != 'BR') {
            fos = parseInt(desce[j].getStyle('fontSize'));
            if(!deffontSize[i+'b'+j]) deffontSize[i+'b'+j] = fos;
            if(inc == 2) if(fos < deffontSize[i+'b'+j]+8) fos++;
            if(inc == 1) if(fos > deffontSize[i+'b'+j]-2) fos--;
            desce[j].style.fontSize = fos+'px';
        }
    }
}

function mtip(tex) {
    if(!$('mshtip')) {
        var deb = d.createElement('div');
        deb.id = 'mshtip';
        deb.style.color = '#333';
        deb.style.backgroundColor = '#fcffde';
        deb.style.fontSize = '11px';
        deb.style.border = '1px solid #cccccc';
        deb.style.position = 'absolute';
        deb.style.padding = '7px 12px 7px 12px';
        deb.style.zIndex = '100';
        deb.onclick = function() { won = true; };
        $(d.body).appendChild(deb);
    }
    if(tex) {
        $('mshtip').style.left = (tempX - $('mshtip').getWidth() - 15)+'px';
        $('mshtip').innerHTML = tex;
        var vdim = (d.body).firstDescendant().getHeight();
        var mtop = Math.min(vdim-$('mshtip').getHeight(), tempY);
        mtop += -2;
        if(mtop < 0) mtop = 0;
        $('mshtip').style.top = mtop+'px';
        var vdim = (d.body).firstDescendant().getWidth();
        var mleft = Math.min(vdim-$('mshtip').getWidth(), tempX);
        mleft = mleft < tempX ? tempX-$('mshtip').getWidth() - 15 : mleft+15;
        if(mleft < 0) mleft = 0;
        $('mshtip').style.left = mleft+'px';
        $('mshtip').show();
        won = true;
        $(d.body).onclick = function() {
            if(!won) {
                mtip();
                $(d.body).onclick = function() {};
            } else 
                won = false;
        };
    } else
        $('mshtip').hide();
}

function hint(care, tex) {
    if(!$('mshint')) {
        var deb = d.createElement('div');
        deb.id = 'mshint';
        deb.setStyle('color:#fff;font:12px Arial;height:35px;position:absolute;z-index:100');
        deb.innerHTML = '<div style="height:25px">'+
                '<div style="float:left;width:3px;height:25px;background:url('+im+'hintl.png) no-repeat;"></div>'+
                '<div style="background:url('+im+'hintr.png) top repeat-x;float:left;height:21px;padding:4px 15px 0 14px"></div>'+
                '<div style="float:left;width:3px;height:25px;background:url('+im+'hinto.png) no-repeat;"></div>'+
            '</div>'+
            '<div style="background:url('+im+'hinti.png) 19px 0 no-repeat;height:11px;position:relative;top:-1px;"></div>';
        deb.setOpacity(0.8);
        $(d.body).appendChild(deb);
    }
    if(care && tex) {
        $('mshint').down().down().next().innerHTML = tex;
        var dims = care.positionedOffset();
        $('mshint').style.left = parseInt(dims.left+care.getWidth()/2-30)+'px';
        $('mshint').style.top = (dims.top-35)+'px';
        $('mshint').show();
    } else
        $('mshint').hide();
}

d.onmousemove = getMouseXY;
function getMouseXY(e) {
    if(isie) {
        tempX = event.clientX + d.documentElement.scrollLeft;
        tempY = event.clientY + d.documentElement.scrollTop;
    } else {
        tempX = e.pageX;
        tempY = e.pageY;
    }
    if (tempX < 0) tempX = 0;
    if (tempY < 0) tempY = 0;
}

function setHeights() {
    if(!$('content')) return;
    window.onresize = function() {};
    $('content').setStyle('height:auto');
    var hei = d.viewport.getDimensions().height
        -$('header').getHeight()-parseInt($('header').getStyle('padding-top'))-parseInt($('header').getStyle('padding-bottom'))
        -parseInt($('header').getStyle('margin-top'))-parseInt($('header').getStyle('margin-bottom'))
        -$('footer').getHeight()-parseInt($('footer').getStyle('padding-top'))-parseInt($('footer').getStyle('padding-bottom'))
        -parseInt($('footer').getStyle('margin-top'))-parseInt($('footer').getStyle('margin-bottom'))
        -parseInt($('content').getStyle('padding-top'))-parseInt($('content').getStyle('padding-bottom'))
        -parseInt($('content').getStyle('margin-top'))-parseInt($('content').getStyle('margin-bottom'));
    if(hei > $('content').getHeight())
        $('content').setStyle('height:'+hei+'px');
    popSize();
    setTimeout('window.onresize = setHeights',100);
}

function latin1(str) {
    if(!str) return;
    str = str.toString();
    var entities = {}, histogram = {}, decimal = 0, symbol = '';    
    // ascii decimals for better compatibility
    //entities['34']  = '[]quot;';
    //entities['38']  = '[]amp;';
    //entities['60']  = '[]lt;';
    //entities['62']  = '[]gt;';
    //entities['160'] = '[]nbsp;';
    entities['161'] = '[]iexcl;';
    entities['162'] = '[]cent;';
    entities['163'] = '[]pound;';
    entities['164'] = '[]curren;';
    entities['165'] = '[]yen;';
    entities['166'] = '[]brvbar;';
    entities['167'] = '[]sect;';
    entities['168'] = '[]uml;';
    entities['169'] = '[]copy;';
    entities['170'] = '[]ordf;';
    entities['171'] = '[]laquo;';
    entities['172'] = '[]not;';
    entities['173'] = '[]shy;';
    entities['174'] = '[]reg;';
    entities['175'] = '[]macr;';
    entities['176'] = '[]deg;';
    entities['177'] = '[]plusmn;';
    entities['178'] = '[]sup2;';
    entities['179'] = '[]sup3;';
    entities['180'] = '[]acute;';
    entities['181'] = '[]micro;';
    entities['182'] = '[]para;';
    entities['183'] = '[]middot;';
    entities['184'] = '[]cedil;';
    entities['185'] = '[]sup1;';
    entities['186'] = '[]ordm;';
    entities['187'] = '[]raquo;';
    entities['188'] = '[]frac14;';
    entities['189'] = '[]frac12;';
    entities['190'] = '[]frac34;';
    entities['191'] = '[]iquest;';
    entities['192'] = '[]Agrave;';
    entities['193'] = '[]Aacute;';
    entities['194'] = '[]Acirc;';
    entities['195'] = '[]Atilde;';
    entities['196'] = '[]Auml;';
    entities['197'] = '[]Aring;';
    entities['198'] = '[]AElig;';
    entities['199'] = '[]Ccedil;';
    entities['200'] = '[]Egrave;';
    entities['201'] = '[]Eacute;';
    entities['202'] = '[]Ecirc;';
    entities['203'] = '[]Euml;';
    entities['204'] = '[]Igrave;';
    entities['205'] = '[]Iacute;';
    entities['206'] = '[]Icirc;';
    entities['207'] = '[]Iuml;';
    entities['208'] = '[]ETH;';
    entities['209'] = '[]Ntilde;';
    entities['210'] = '[]Ograve;';
    entities['211'] = '[]Oacute;';
    entities['212'] = '[]Ocirc;';
    entities['213'] = '[]Otilde;';
    entities['214'] = '[]Ouml;';
    entities['215'] = '[]times;';
    entities['216'] = '[]Oslash;';
    entities['217'] = '[]Ugrave;';
    entities['218'] = '[]Uacute;';
    entities['219'] = '[]Ucirc;';
    entities['220'] = '[]Uuml;';
    entities['221'] = '[]Yacute;';
    entities['222'] = '[]THORN;';
    entities['223'] = '[]szlig;';
    entities['224'] = '[]agrave;';
    entities['225'] = '[]aacute;';
    entities['226'] = '[]acirc;';
    entities['227'] = '[]atilde;';
    entities['228'] = '[]auml;';
    entities['229'] = '[]aring;';
    entities['230'] = '[]aelig;';
    entities['231'] = '[]ccedil;';
    entities['232'] = '[]egrave;';
    entities['233'] = '[]eacute;';
    entities['234'] = '[]ecirc;';
    entities['235'] = '[]euml;';
    entities['236'] = '[]igrave;';
    entities['237'] = '[]iacute;';
    entities['238'] = '[]icirc;';
    entities['239'] = '[]iuml;';
    entities['240'] = '[]eth;';
    entities['241'] = '[]ntilde;';
    entities['242'] = '[]ograve;';
    entities['243'] = '[]oacute;';
    entities['244'] = '[]ocirc;';
    entities['245'] = '[]otilde;';
    entities['246'] = '[]ouml;';
    entities['247'] = '[]divide;';
    entities['248'] = '[]oslash;';
    entities['249'] = '[]ugrave;';
    entities['250'] = '[]uacute;';
    entities['251'] = '[]ucirc;';
    entities['252'] = '[]uuml;';
    entities['253'] = '[]yacute;';
    entities['254'] = '[]thorn;';
    entities['255'] = '[]yuml;';
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal)
        histogram[symbol] = entities[decimal];
    }
    var pat;
    for (var key in histogram) {
        pat = new RegExp(key,"g");
        str = str.replace(pat, histogram[key]);
    }
    return str;
}

function phpSend(getline, id) {
    if(!getline) {
        debug('Invalid Request');
        return;
    }
    getline = latin1(getline);
    if(getline.substring(0,4) != 'http')
        getline = root+'ajax/'+getline;
    new Ajax.Request(getline, {
        method:'get',
        onSuccess: function(transport) {
            if(id) {
                $(id+'ajaxload').remove();
                if($(id).offsetHeight == 32) $(id).style.height = '';
            }
            var response = transport.responseText;
            if(response.match('eval:')) {
                var ev = response.substring(response.indexOf('eval:')+5);
                response = response.substring(0, response.indexOf('eval:'));
                eval(ev);
            }
            if(id)
                $(id).update(response);
            if(response.match(/<input|<select|<textarea/g))
                initForms();
            setHeights();
        },
        onLoading: function() {
            if(!id) return;
            if($(id).hasClassName('hidden'))
                $(id).removeClassName('hidden');
            if(!$(id).visible())
                $(id).show();
            var dim = $(id).getDimensions();
            var offs = $(id).cumulativeOffset();
            dim['width'] += -(parseInt($(id).getStyle('padding-right'))+parseInt($(id).getStyle('padding-left')));
            dim['height'] += -(parseInt($(id).getStyle('padding-top'))+parseInt($(id).getStyle('padding-bottom')));
            offs['left'] += parseInt($(id).getStyle('padding-left'));
            offs['top'] += parseInt($(id).getStyle('padding-top'));
            if(dim['height'] <= 0) {
                $(id).style.height = '32px';
                dim['height'] = 32;
            }
            if(dim['width'] <= 0) {
                $(id).style.width = '32px';
                dim['width'] = 32;
            }
            var deb = d.createElement('div');
            deb.id = id+'ajaxload';
            $(d.body).appendChild(deb);
            $(id+'ajaxload').style.position = 'absolute';
            if(isie6) {
                $(id+'ajaxload').style.backgroundColor = "#000000";
                $(id+'ajaxload').style.backgroundColor = "transparent";
                $(id+'ajaxload').style.backgroundImage = "url("+im+"default/blank.gif)";
                $(id+'ajaxload').runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+im+"default/overlay.png',sizingMethod='scale')";
            } else
                $(id+'ajaxload').style.backgroundImage = 'url('+im+'overlay.png)';
            $(id+'ajaxload').innerHTML = '<div align="center" style="padding-top:'+(dim['height'] > 32 ? parseInt(dim['height']/2) - 16 : 0)+'px"><img height="'+(dim['height'] < 32 ? dim['height'] : 32)+'" src="'+im+'loading.gif" alt="please wait..."></div>';
            $(id+'ajaxload').style.zIndex = '100';
            $(id+'ajaxload').style.width = dim['width']+'px';
            $(id+'ajaxload').style.height = dim['height']+'px';
            $(id+'ajaxload').style.left = offs['left']+'px';
            $(id+'ajaxload').style.top = offs['top']+'px';
        }
    });
}

function popInit(nobg) {
    if($('popload')) $('popload').remove();
    var dim = d.viewport.getDimensions();
    var deb = d.createElement('div');
    deb.id = 'popload';
    deb.style.position = isie6 ? 'absolute' : 'fixed';
    if(!nobg) {
        if(isie6) {
            //deb.style.backgroundColor = "#000000";
            //deb.style.backgroundColor = "transparent";
            //deb.style.backgroundImage = "url("+im+"blank.gif)";
            //deb.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+im+"overlay_dark.png',sizingMethod='scale')";
        } else
            deb.style.backgroundImage = 'url('+im+'overlay_dark.png)';
    }
    deb.innerHTML = '<div id="popdiv"></div><img id="popim" src="'+im+'loading_dark.gif" alt="please wait..."><div id="popclose"><img src="'+im+'close.png" alt="Close"><div id="popcloset">'+closet+'</div></div>';
    $(d.body).appendChild(deb);
    $('popload').setStyle('z-index:100;left:0;top:'+(isie6 ? d.viewport.getScrollOffsets().top : 0)+'px;width:'+dim.width+'px;height:'+dim.height+'px');
    $('popclose').setStyle('position:'+(isie6 ? 'absolute' : 'fixed')+';display:none');
    $('popim').setStyle('padding-top:'+parseInt(dim.height/2 - 16)+'px;padding-left:'+parseInt(dim.width/2 - 16)+'px');
    $('popdiv').setStyle('overflow:auto;float:left;display:none;');
    $('popclose').onmouseover = function() { $('popcloset').addClassName('over');popSize();};
    $('popclose').onmouseout = function() { $('popcloset').removeClassName('over'); popSize();};
    $('popclose').onclick = popClose;
    Event.observe(window,'keypress',function(event) {
        if(event.keyCode == 27)
            popClose();
        else if($('popimnext') && (event.charCode == 110 || event.keyCode == 39))
            $('popimnext').onclick();
        else if($('popimprev') && (event.charCode == 112 || event.keyCode == 37))
            $('popimprev').onclick();
    }); 
}

function popSize() {
    if(!$('popload')) return;
    var dim = d.viewport.getDimensions();
    $('popdiv').setStyle('height:auto;width:auto');
    //if(!window.popsize)
        //window.popsize = {width: $('popdiv').getWidth(), height: $('popdiv').getHeight()}
    //var ph = window.popsize.height;
    //var pw = window.popsize.width;
    var ph = $('popdiv').getHeight();
    var oldph = ph;
    var pw = $('popdiv').getWidth();
    var oldpw = pw;
    var ml = parseInt(dim.width/2 - (pw/2));
    var mt = parseInt(dim.height/2 - (ph/2));
    if(mt < 0 && ml < 0) {
        mt = 0;
        ml = 0;
        ph = dim.height+17;
        pw = dim.width+17;
    } else if(mt < 0) {
        mt = 0;
        ph = dim.height;
        pw += 17;
    } else if(ml < 0) {
        ml = 0;
        ph += 17;
        pw = dim.width;
    }
    $('popdiv').setStyle('margin-left:'+(isie6 ? parseInt(ml/2) : ml)+'px;margin-top:'+mt+'px;height:'+ph+'px;width:'+pw+'px');
    $('popclose').setStyle('left:'+(pw+ml-$('popclose').getWidth()-(oldph > ph ? 17 : 0))+'px;top:'+mt+'px');
}

function popLoad(html) {
    if(!$('popload')) return;
    $('popim').hide();
    if(typeof(html) == 'object') {
        $('popdiv').appendChild(html);
        if(html.innerHTML.match(/<input|<select|<textarea/g))
            initForms();
    } else {
        $('popdiv').update(html);
        if(html.match(/<input|<select|<textarea/g))
            initForms();
    }
    popSize();
    $('popdiv').show();
    $('popclose').show();
}

function popClose() {
    Event.stopObserving(window, 'keypress');
    $('popload').remove();
    if(window.spids)
        window.spids.each(function(el) {
            if($('spid_'+el)) 
                $('spid_'+el).remove();
        });
    if($('formerr'))
        $('formerr').hide();
    return;
    $('popim').show();
    $('popdiv').update('');
    $('popdiv').setStyle('margin:0;width:auto;height:auto;');
    $('popclose').setStyle('left:0;top:0');
    $('popclose').hide();
}

function popImg(srcu, rels) {
    popInit();
    var imgu = new Image;
    imgu.onload = function() {
        var prop = this.width/this.height;
        if(this.width > d.viewport.getDimensions().width - 40)
            this.width = d.viewport.getDimensions().width - 40;
        if(this.height > d.viewport.getDimensions().height - 40) {
            this.height = d.viewport.getDimensions().height - 40;
            this.width = prop*this.height;
        }
        var deba = d.createElement('div');
        var debi = d.createElement('div');
        debi.className = 'popimg';
        debi.style.width = this.width+'px';
        if(rels) {
            for(var i in popimrels[rels])
                if(typeof(popimrels[rels][i]) == 'object' && popimrels[rels][i][0] == srcu) {
                    relc = parseInt(i);
                    break;
                }
            if(relc != 0) {
                var deb = d.createElement('span');
                deb.className = 'popimg popl';
                deb.id = 'popimprev';
                deb.style.width = parseInt(this.width/2)+'px';
                deb.style.height = this.height+'px';
                deb.href = '#';
                deb.onclick = function() {
                    popClose();
                    popImg(popimrels[rels][parseInt(relc-1)][0], rels);
                    return false;
                }
                debi.appendChild(deb);
            }
            if(relc != popimrels[rels].length-1) {
                var deb = d.createElement('span');
                deb.className = 'popimg popr';
                deb.id = 'popimnext';
                deb.style.width = parseInt(this.width/2)+'px';
                deb.style.height = this.height+'px';
                deb.style.marginLeft =parseInt(this.width/2)+'px';
                deb.href = '#';
                deb.onclick = function() {
                    popClose();
                    popImg(popimrels[rels][parseInt(relc+1)][0], rels);
                    return false;
                }
                debi.appendChild(deb);
            }
            debi.appendChild(this);
            var deb2 = d.createElement('div');
            deb2.innerHTML = popimrels[rels][relc][1];
            debi.appendChild(deb2);
            deba.appendChild(debi);
            var deb = d.createElement('div');
            deb.className = 'popdist';
            var deb1 = d.createElement('div');
            deb1.className = 'float right';
            if(relc != 0) {
                var a1 = d.createElement('a');
                a1.innerHTML = '&laquo; '+pic_previous;
                a1.onclick = function() {
                    popClose();
                    popImg(popimrels[rels][parseInt(relc-1)][0], rels);
                    return false;
                }
            } else {
                var a1 = d.createElement('span');
                a1.innerHTML = '&laquo; '+pic_previous;
                a1.style.color = '#999';
            }
            deb1.appendChild(a1);
            var s1 = d.createElement('span');
            s1.innerHTML = ' || ';
            deb1.appendChild(s1);
            if(relc != popimrels[rels].length-1) {
                var a2 = d.createElement('a');
                a2.innerHTML = pic_next+' &raquo;';
                a2.onclick = function() {
                    popClose();
                    popImg(popimrels[rels][parseInt(relc+1)][0], rels);
                    return false;
                }
           } else {
                var a2 = d.createElement('span');
                a2.innerHTML = pic_next+' &raquo;';
                a2.style.color = '#999';
            }
            deb1.appendChild(a2);
            deb.appendChild(deb1);
            var deb2 = d.createElement('div');
            deb2.innerHTML = pic_display.replace('[num]', relc+1).replace('[total]', popimrels[rels].length);
            deb.appendChild(deb2);
            deba.appendChild(deb);
        } else {
            debi.appendChild(this);
            deba.appendChild(debi);
        }
        popLoad(deba);
        if(isie6) {
            if($('popimprev')) {
                Event.observe('popimprev', 'mouseover', function() {this.addClassName('plhover')});
                Event.observe('popimprev', 'mouseout', function() {this.removeClassName('plhover')});
            }
            if($('popimnext')) {
                Event.observe('popimnext', 'mouseover', function() {this.addClassName('prhover')});
                Event.observe('popimnext', 'mouseout', function() {this.removeClassName('prhover')});
            }
        }
    }
    imgu.src = srcu;
}

var popimrels = {};
var relc = 0;
function initRels() {
    var i = {};
    $A(d.links).each(function(el) {
        if(el.rel && el.rel.match('images')) {
            if(!i[el.rel])
                i[el.rel] = 0;
            if(!popimrels[el.rel])
                popimrels[el.rel] = {};
            popimrels[$(el).rel][i[$(el).rel]] = new Array(el.href, ((el.next() && el.next().getStyle('display') == 'none') ? el.next().innerHTML : ''));
            el.onclick = function() {
                popImg(el.href, el.rel);
                return false;
            }
            i[el.rel]++;
        }
    });
    for(j in i)
        popimrels[j].length = i[j];
}

function popPage(pag) {
    if(!pag) return;
    if(pag.substring(0,4) != 'http')
        pag = root+'ajax/'+pag;
    new Ajax.Request(pag, {
        method:'get',
        onSuccess: function(transport) {
            popLoad(transport.responseText);
        },
        onLoading: function() {
            popInit();
        }
    });
}

var pngc = null;
var pngI = 0;
var pngs = [];
function correctPNG() {
    var imgName;
    for(i=0; i < d.images.length;i++) {
        imgName = d.images[i].src.toUpperCase();
        if(imgName.substring(imgName.length-3, imgName.length) == "PNG")
            pngs.push(d.images[i]);
    }
    pngc = setInterval('setPNG()', 10);
}

function setPNG() {
    if(pngI == pngs.length) clearInterval(pngc);
    if(!pngs[pngI]) return;
    var img = pngs[pngI];
    var imgID = (img.id) ? 'id="' + img.id + '" ' : '';
    var imgClass = (img.className) ? 'class="' + img.className + '" ' : '';
    var imgTitle = (img.title) ? 'title="' + img.title + '" ' : '';
    var imgonclick = (img.onclick) ? img.onclick.toString().substring(22,(img.onclick.toString().length-2)) : '';
    var imgClick = (imgonclick) ? 'onclick="'+ imgonclick + '" ' : '';
    var imgonmouseover = (img.onmouseover) ? img.onmouseover.toString().substring(22,(img.onmouseover.toString().length-2)) : '';
    var imgMouseOver = (imgonmouseover) ? 'onmouseover="'+ imgonmouseover + '" ' : '';
    var imgonmouseout = (img.onmouseout) ? img.onmouseout.toString().substring(22,(img.onmouseout.toString().length-2)) : '';
    var imgMouseOut = (imgonmouseout) ? 'onmouseout="'+ imgonmouseout + '" ' : '';
    var imgStyle = '';
    if($(img).getStyle('background-image') != 'none') imgStyle += 'background-image:'+$(img).getStyle('background-image').replace(/"/g,'')+';';
    if($(img).getStyle('background-color') != 'transparent') imgStyle += 'background-color:'+$(img).getStyle('background-color')+';';
    if(imgStyle) {
        imgStyle += 'background-repeat:'+$(img).getStyle('background-repeat')+';';
        imgStyle += 'background-position-x:'+$(img).getStyle('background-position-x')+';';
        imgStyle += 'background-position-y:'+$(img).getStyle('background-position-y')+';';
    }
    var ori = new Array('left','right','top','bottom');
    var imgDim = new Array($(img).getWidth(),$(img).getHeight());
    for(var i=0;i<ori.length;i++) {
        var borderWid = parseInt($(img).getStyle('border-'+ori[i]+'-width'));
        if(borderWid) {
            imgStyle += 'border-'+ori[i]+':'+borderWid+'px solid '+$(img).getStyle('border-'+ori[i]+'-color')+';';
            if(i > 1) imgDim[1] += -borderWid;
            else imgDim[0] += -borderWid;
        }
        var padd = parseInt($(img).getStyle('padding-'+ori[i]));
        if(padd) {
            imgStyle += 'padding-'+ori[i]+':'+padd+'px;';
            if(i > 1) imgDim[1] += -padd;
            else imgDim[0] += -padd;
        }
        var marg = parseInt($(img).getStyle('margin-'+ori[i]));
        if(marg) imgStyle += 'margin-'+ori[i]+':'+marg+'px;';
    }
    if($(img).getStyle('position') != 'static') {
        imgStyle += 'position:'+$(img).getStyle('position')+';';
        if($(img).getStyle('left')) imgStyle += 'left:'+$(img).getStyle('left')+';';
        if($(img).getStyle('top')) imgStyle += 'left:'+$(img).getStyle('top')+';';
    }
    imgStyle += 'z-index:'+$(img).getStyle('z-index')+';';
    imgStyle += 'width:'+imgDim[0]+'px;';
    imgStyle += 'height:'+imgDim[1]+'px;';
    imgStyle += 'display:'+$(img).getStyle('display')+';';
    imgStyle += 'float:'+$(img).getStyle('float')+';';
    img.outerHTML = '<span style="'+imgStyle+'" ' + imgID + imgClass + imgTitle + imgClick + imgMouseOver + imgMouseOut + '><span style="display:block;width:'+imgDim[0]+'px;height:'+imgDim[1]+'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + img.src + '\', sizingMethod=\'scale\');"></span></span> ';
    //pngI += pngI-3;
    //if(pngI < 0) pngI = 0;
    pngI += 1;
}
/*
var pngc = null;
var pngI = 0;
function correctPNG() {
    if(isie6)
        pngc = new PeriodicalExecuter(function(pe) { setPNG();} , 0.1);
}

function setPNG() {
    pngI++;
    if(pngI == d.images.length) pngc.stop();
    if(!d.images[pngI]) return;
    var img = d.images[pngI];
    var imgName = img.src.toUpperCase();
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
        var imgID = (img.id) ? 'id="' + img.id + '" ' : '';
        var imgClass = (img.className) ? 'class="' + img.className + '" ' : '';
        var imgTitle = (img.title) ? 'title="' + img.title + '" ' : '';
        var imgonclick = (img.onclick) ? img.onclick.toString().substring(22,(img.onclick.toString().length-2)) : '';
        var imgClick = (imgonclick) ? 'onclick="'+ imgonclick + '" ' : '';
        var imgonmouseover = (img.onmouseover) ? img.onmouseover.toString().substring(22,(img.onmouseover.toString().length-2)) : '';
        var imgMouseOver = (imgonmouseover) ? 'onmouseover="'+ imgonmouseover + '" ' : '';
        var imgonmouseout = (img.onmouseout) ? img.onmouseout.toString().substring(22,(img.onmouseout.toString().length-2)) : '';
        var imgMouseOut = (imgonmouseout) ? 'onmouseout="'+ imgonmouseout + '" ' : '';
        var imgStyle = '';
        if($(img).getStyle('background-image') != 'none') imgStyle += 'background-image:'+$(img).getStyle('background-image').replace(/"/g,'')+';';
        if($(img).getStyle('background-color') != 'transparent') imgStyle += 'background-color:'+$(img).getStyle('background-color')+';';
        if(imgStyle) {
            imgStyle += 'background-repeat:'+$(img).getStyle('background-repeat')+';';
            imgStyle += 'background-position-x:'+$(img).getStyle('background-position-x')+';';
            imgStyle += 'background-position-y:'+$(img).getStyle('background-position-y')+';';
        }
        var ori = new Array('left','right','top','bottom');
        var imgDim = new Array($(img).getWidth(),$(img).getHeight());
        for(var i=0;i<ori.length;i++) {
            var borderWid = parseInt($(img).getStyle('border-'+ori[i]+'-width'));
            if(borderWid) {
                imgStyle += 'border-'+ori[i]+':'+borderWid+'px solid '+$(img).getStyle('border-'+ori[i]+'-color')+';';
                if(i > 1) imgDim[1] += -borderWid;
                else imgDim[0] += -borderWid;
            }
            var padd = parseInt($(img).getStyle('padding-'+ori[i]));
            if(padd) {
                imgStyle += 'padding-'+ori[i]+':'+padd+'px;';
                if(i > 1) imgDim[1] += -padd;
                else imgDim[0] += -padd;
            }
            var marg = parseInt($(img).getStyle('margin-'+ori[i]));
            if(marg) imgStyle += 'margin-'+ori[i]+':'+marg+'px;';
        }
        if($(img).getStyle('position') != 'static') {
            imgStyle += 'position:'+$(img).getStyle('position')+';';
            if($(img).getStyle('left')) imgStyle += 'left:'+$(img).getStyle('left')+';';
            if($(img).getStyle('top')) imgStyle += 'left:'+$(img).getStyle('top')+';';
        }
        imgStyle += 'z-index:'+$(img).getStyle('z-index')+';';
        imgStyle += 'width:'+imgDim[0]+'px;';
        imgStyle += 'height:'+imgDim[1]+'px;';
        imgStyle += 'display:'+$(img).getStyle('display')+';';
        imgStyle += 'float:'+$(img).getStyle('float')+';';
        img.outerHTML = '<span style="'+imgStyle+'" ' + imgID + imgClass + imgTitle + imgClick + imgMouseOver + imgMouseOut + '><span style="display:block;width:'+imgDim[0]+'px;height:'+imgDim[1]+'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + img.src + '\', sizingMethod=\'scale\');"></span></span> ';
        pngI = pngI-2;
        if(pngI < 0) pngI = 0;
    }
}
*/
// ]]>