// <![CDATA[
var isopera = false;
var ischrome = false;
var isff = false;
var isie = false;
var isie6 = false;
var isie7 = false;
var isie8 = false;
if(navigator.userAgent.split('Opera').length == 2) isopera = true;
else if(navigator.userAgent.split('Chrome').length == 2) ischrome = true;
else if(navigator.userAgent.split('Firefox').length == 2) isff = true;
else if(navigator.userAgent.split('MSIE').length == 2) {
    isie = true;
    var bv = parseInt(navigator.userAgent.split('MSIE')[1]);
    if(bv <= 6) isie6 = true;
    else if(bv == 7) isie7 = true;
    else if(bv == 8) isie8 = true;
}
var d = document;
var cob = new Array();
var pngI = -1;
var wtime = 5;
var witemwid = 0;
var workwid = 0;
var slmove = 0;
var tempX = 0;
var tempY = 0;
var curH = 1;
var htime = 10;
var hX = 0;
var hInt = 1;
var hCount = 0;
var sltime = 15;
var sli = 0;
var curp = 1;
var deffontSize = new Array();
var effects = new Array();
var drags = new Array();
var won = null;
var acp = false;
var mels = null;
//var melp = 0;
var pimgo = false;

function setcat(el) {
    if(!el.value) {
        el.name = 'pid';
        $('subcat').update(' ');
    } else {
        el.name = '';
        phpSend('getcat/'+el.value, 'subcat');
    }
}

function switchy(care, ne, func) {
    if(!ne || !care) return;
    eval(func);
    var ht = care.innerHTML;
    var el = care.up();
    el.innerHTML = '<b>'+ht+'</b>';
    if(ne == 1) {
        ht = el.next().down().innerHTML;
        el.next().innerHTML = '<a href="#" onclick="switchy(this, 2'+(func ? ', \''+func.addsl()+'\'' : '')+');return false;">'+ht+'</a>';
    } else {
        ht = el.previous().down().innerHTML;
        el.previous().innerHTML = '<a href="#" onclick="switchy(this, 1'+(func ? ', \''+func.addsl()+'\'' : '')+');return false;">'+ht+'</a>';
    }
}

String.prototype.addsl = function() {
    var val = this.toString();
    val = val.replace(/\'/g, '\\\'');
    return val;
}

function initProduct() {
    if(!$('pimg') || !$('imgfocus')) return;
    $('dhand').setOpacity(0.3);
    $('dhand').style.left = parseInt($('pimg').positionedOffset()['left'] + (($('pimg').offsetWidth - $('dhand').offsetWidth))/2)+'px';
    $('dhand').style.top = parseInt($('pimg').positionedOffset()['top'] + (($('pimg').offsetHeight - $('dhand').offsetHeight))/2)+'px';
    $('imgfocus').style.backgroundPosition = parseInt(-1905/2+$('dhand').offsetWidth+($('dhand').offsetWidth/2))+'px '+parseInt(-1176/2+$('dhand').offsetHeight+($('dhand').offsetHeight/2))+'px';
    cob['imgfocus'] = new PeriodicalExecuter(function(pe) {
        if(pimgo) {
            var dhl = tempX - ($('dhand').offsetWidth/2);
            dhl = Math.max(dhl, $('pimg').positionedOffset()['left']);
            dhl = Math.min(dhl, $('pimg').positionedOffset()['left']+$('pimg').offsetWidth - $('dhand').offsetWidth);
            var dht = tempY - ($('dhand').offsetHeight/2);
            dht = Math.max(dht, $('pimg').positionedOffset()['top']);
            dht = Math.min(dht, $('pimg').positionedOffset()['top']+$('pimg').offsetHeight - $('dhand').offsetHeight);
            $('dhand').style.left = parseInt(dhl)+'px';
            $('dhand').style.top = parseInt(dht)+'px';
            dhl = $('pimg').positionedOffset()['left'] - dhl;
            dht = $('pimg').positionedOffset()['top'] - dht;
            dhl = 1905/$('pimg').offsetWidth*dhl;
            dht = 1176/$('pimg').offsetHeight*dht;
            $('imgfocus').style.backgroundPosition = parseInt(dhl)+'px '+parseInt(dht)+'px';
        }
    } , 0.01);
}

function setImage(urlu) {
    $('pimg').src = urlu;
    $('imgfocus').style.backgroundImage = 'url('+urlu+')';
    $('dhand').style.left = parseInt($('pimg').positionedOffset()['left'] + (($('pimg').offsetWidth - $('dhand').offsetWidth))/2)+'px';
    $('dhand').style.top = parseInt($('pimg').positionedOffset()['top'] + (($('pimg').offsetHeight - $('dhand').offsetHeight))/2)+'px';
    $('imgfocus').style.backgroundPosition = parseInt(-1905/2+$('dhand').offsetWidth+($('dhand').offsetWidth/2))+'px '+parseInt(-1176/2+$('dhand').offsetHeight+($('dhand').offsetHeight/2))+'px';
}

function init() {
    setHeights();
    setInputs();
    correctPNG();
    initFlow();
    initMenu();
    initHeads();
    initProduct();
    if(location.href.match('#')) {
        var anch = location.href.substring(location.href.indexOf('#')+1);
        if($(anch) && $(anch).onclick)
            $(anch).onclick();
    }
}

function initHeads() {
    if($('headline1')) {
        var heads = d.getElementsByClassName('headline');
        hCount = heads.length;
        cob['heads'] = new PeriodicalExecuter(function(pe) { nextHead();} , htime);
        var hnum = d.getElementsByClassName('hnum');
        for(var i=0;i<hnum.length;i++)
            for(var j=0;j<hCount;j++) {
                var nl = document.createElement('a');
                nl.innerHTML = j+1;
                if(j == i) nl.className = 'on';
                nl.onclick = function() {
                    setHead(parseInt(this.innerHTML));
                    this.blur();
                    return false;
                }
                hnum[i].appendChild(nl);
            }
    }
}

function nextHead() {
    if(!hInt) return;
    new Effect.Fade('headline'+curH, {duration:0.5, from: 1, to: 0});
    setTimeout('$(\'headline'+curH+'\').style.left = \'-2000px\'',550);
    setTimeout('$(\'headline'+curH+'\').setOpacity(1)',550);
    setTimeout('$(\'headline'+curH+'\').style.display = \'\'',550);
    if(curH == hCount) {
        curH = 1;
    } else
        curH++;
    $('headline'+curH).style.left = hX+'px';
    $('headline'+curH).setOpacity(0);
    new Effect.Fade('headline'+curH, {duration:0.6, from: 0, to: 1});
}

function setHead(val) {
    if(val == curH) return;
    cob['heads'].stop();
    hInt = 0;
    var hY = $('headline'+curH).offsetTop;
    $('headline'+curH).style.top = hY+'px';
    $('headline'+val).style.top = hY+'px';
    $('headline'+curH).style.left = hX+'px';
    new Effect.Move( 'headline'+curH, { duration:1, x: 10000, y: hY, mode: 'absolute' });
    new Effect.Move( 'headline'+val, { duration:1, x: hX, y: hY, mode: 'absolute' });
    setTimeout('$(\'headline'+curH+'\').style.left = \'-2000px\'',1050);
    curH = val;
}

function setMenu(care) {
    for(var i=0;i<mels.length;i++) {
        mels[i].className = '';
        if($('sub'+mels[i].id))
            $('sub'+mels[i].id).style.display = 'none';
    }
    $(care).className = 'mon';
    if($('sub'+care))
        $('sub'+care).style.display = 'block';
}
function initMenu() {
    if(!$('mainmenu')) return;
    mels = $('mainmenu').immediateDescendants();
    var mon = false;
    for(var i=0;i<mels.length;i++) {
        if(mels[i].className == 'mon')
            mon = true;
        mels[i].onmouseover = function() {
            setMenu(this.id);
        }
    }
    if(!mon)
        setMenu(mels[0].id);
    if(isie6)
        var menub = $$(".menub")[0].immediateDescendants().each(function(elu) {
            elu.immediateDescendants().each(function(el) {
                Event.observe(el, 'mouseover', function(event) {
                    this.addClassName('hover');
                });
                Event.observe(el, 'mouseout', function(event) {
                    this.removeClassName('hover');
                });
            });
        });
}

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].immediateDescendants();
        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();
}

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 submitform(n, submitf) {
    if(!n) {
        debug('select a form to submit');
        return false;
    }
    var theform = null;
    if(parseInt(n))
        n = parseInt(n);
    switch(typeof(n)) {
        case 'object':
            theform = n;
        break;
        case 'string':
            for(var i=0;i<d.forms.length;i++)
                if(d.forms[i].name == n) {
                    theform = d.forms[i];
                    break;
                }
        break;
        case 'number':
            theform = d.forms[n];
        break;
        default:
            return false;
    }
    if(!theform.tagName || theform.tagName != 'FORM') {
        debug('invalid form');
        return false;
    }
    if($('formerr'))
        $('formerr').hide();
    var err = false;
    var rads = new Array();
    var oldv = '';
    var ins = theform.elements;
    //radiouri
    for(var i=0;i<ins.length;i++) 
    if((ins[i].className.substring(0,4) == 'req ' || ins[i].className == 'req') && ins[i].tagName == 'INPUT' && ins[i].type == 'radio') {
        rads.push(ins[i]);
        ins[i].next().style.borderBottom = '0';
    }
    rads = rads.sortBy(function(el) { return el.name}, this);
    var radsok = new Array();
    var radsn = new Array();
    for(i=0;i<rads.length;i++) {
        radsn.push(rads[i].name);
        if(rads[i].checked)
            radsok.push(rads[i].name);
    }
    radsn = radsn.uniq();
    if(radsn.length != radsok.length) {
        err = true;
        for(var i=0;i<rads.length;i++)
            if(!radsok.include(rads[i].name))
                rads[i].next().style.borderBottom = '1px solid red';
    }
    var conti = false;
    //-radiouri
    for(var i=0;i<ins.length;i++) 
    if((ins[i].className.substring(0,4) == 'req ' || ins[i].className == 'req') && ins[i].name && ins[i].type != 'radio') {
        conti = false;
        for(var j=0;j<rads.length;j++)
            if(ins[i].name.substring(0,rads[j].value.length) == rads[j].value && !rads[j].checked) {
                conti = true;
                break;
            }
        if(conti) continue;
        oldv = ins[i].oldval;
        if(ins[i].tagName == 'TEXTAREA' || (ins[i].type && (ins[i].type == 'text' || ins[i].type == 'password'))) {
            if(ins[i].style.borderColor == 'red red red red') {
                ins[i].style.borderColor = ins[i].oldborderc;
                ins[i].style.backgroundColor = ins[i].oldback;
                ins[i].style.backgroundImage = ins[i].oldbacki;
            }
            if(!ins[i].value || ins[i].value == oldv || (ins[i].name.match('email') && !email_valid(ins[i].value))) {
                err = true;
                ins[i].oldborderc = $(ins[i]).getStyle('border-color');
                ins[i].style.borderColor = 'red';
                ins[i].oldback = $(ins[i]).getStyle('background-color');
                ins[i].oldbacki = $(ins[i]).getStyle('background-image');
                if(ins[i].getStyle('background-repeat') != 'no-repeat')
                    ins[i].style.backgroundImage = 'none';
                ins[i].style.backgroundColor = '#ffdddd';
            }
        }
        else if(ins[i].type && ins[i].type == 'checkbox') {
            if(!ins[i].checked) {
                err = true;
                $(ins[i]).next().oldcolor = $(ins[i]).next().getStyle('color');
                $(ins[i]).next().style.color = 'red';
            } else
                if($(ins[i]).next().oldcolor)
                    $(ins[i]).next().style.color = $(ins[i]).next().oldcolor;
        }
        else if(ins[i].tagName == 'SELECT') {
            if(ins[i].style.borderColor == 'red red red red') {
                ins[i].style.borderColor = ins[i].oldborderc;
                ins[i].style.backgroundColor = ins[i].oldback;
                ins[i].style.backgroundImage = ins[i].oldbacki;
            }
            if(!ins[i].value || ins[i].value == oldv || ins[i].value == '0') {
                err = true;
                ins[i].oldborderc = $(ins[i]).getStyle('border-color');
                ins[i].style.borderColor = 'red';
                ins[i].oldback = $(ins[i]).getStyle('background-color');
                ins[i].oldbacki = $(ins[i]).getStyle('background-image');
                if(ins[i].getStyle('background-repeat') != 'no-repeat')
                    ins[i].style.backgroundImage = 'none';
                ins[i].style.backgroundColor = '#ffdddd';
            }
        }
    }
    if(err) {
        var dim = d.viewport.getDimensions();
        if(!$('formerr')) {
            var deb = d.createElement('div');
            deb.id = 'formerr';
            deb.style.position = isie6 ? 'absolute' : 'fixed';
            deb.style.top = (isie6 ? d.viewport.getScrollOffsets().top+5 : 5)+'px';
            deb.style.backgroundColor = '#ffdddd';
            deb.style.font = '11px Arial';
            deb.style.padding = '7px';
            deb.style.border = '1px solid red';
            deb.style.zIndex = '200';
            deb.style.color = 'red';
            deb.style.fontSize = '13px';
            deb.style.fontWeight = 'bold';
            deb.innerHTML = formerrort;
            $(d.body).appendChild(deb);
            $('formerr').setOpacity(0.9);
        }
        $('formerr').show();
        $('formerr').style.left = parseInt(dim['width']/2 - $('formerr').getWidth()/2)+'px';
        return false;
    } else {
        for(var i=0;i<ins.length;i++) 
            if(ins[i].oldval && ins[i].oldval == ins[i].value)
                ins[i].value = '';
        if(submitf) 
            theform.submit();
        else
            return true;
    }
}

function getFunc(func) {
    if(!func) return '';
    func = func.toString();
    func = func.substring(func.indexOf(')')+3);
    return func.substring(0, func.length-2);
}

function initFlow() {
    if(!$('workflow')) return;
    witemwid = $('workflow').childElements()[0].getWidth();
    $('workflow').setStyle('width:'+(witemwid*$('workflow').childElements().length)+'px');
    workwid = $('wholder').getWidth();
    workwid = -($('workflow').childElements().length-Math.round(workwid/witemwid))*witemwid;
    cob['wflow'] = new PeriodicalExecuter(function(pe) { wmove();} , wtime);
}

function wmove(parte) {
    if(parte) {
        if(parte == 1) {
            if(slmove >= 0) 
                slmove = workwid;
            else 
                slmove += witemwid;
        } else {
            if(slmove <= workwid)
                slmove = 0; 
            else 
                slmove += -witemwid;
        }
        cob['wflow'].stop();
    } else {
        if(slmove <= workwid)
            slmove = 0; 
        else 
            slmove += -witemwid;
    }
    if(effects['movew']) effects['movew'].cancel();
    effects['movew'] = new Effect.Move( 'workflow', { x: slmove, y: 0, mode: 'absolute' });
}

function setInputs() {
    var i = 0;
    var ins = new Array();
    var temp;
    temp = d.getElementsByTagName('input');
    for(i=0;i<temp.length;i++)
        if((temp[i].type == 'text' || temp[i].type == 'password') && temp[i].oldborders == null) {
            if(isie6 && $(temp[i]).getWidth() == 146)
                temp[i].style.width = '220px';
            ins.push(temp[i]);
        }
    temp = d.getElementsByTagName('textarea');
    for(i=0;i<temp.length;i++)
        if(temp[i].oldborders == null)
            ins.push(temp[i]);
    temp = d.getElementsByTagName('select');
    for(i=0;i<temp.length;i++)
        if(temp[i].oldborders == null)
            ins.push(temp[i]);
    for(i=0;i<ins.length;i++) {
        ins[i].oldborders = $(ins[i]).getStyle('border-style');
        ins[i].oldborderc = $(ins[i]).getStyle('border-color');
        ins[i].oldback = $(ins[i]).getStyle('background-color');
        ins[i].oldbacki = $(ins[i]).getStyle('background-image');
        ins[i].oldcolor = $(ins[i]).getStyle('color');
        if(ins[i].onfocus)
            ins[i].ofocus = getFunc(ins[i].onfocus);
        if((ins[i].className.substring(0,4) == 'req ' || ins[i].className.substring(0,4) == 'def ') && ins[i].type != 'password') {
            ins[i].oldval = ins[i].className.substring(4);
            if(!ins[i].value)
                ins[i].value = ins[i].oldval;
            ins[i].onfocus = function() { 
                if(this.ofocus) {
                    if(this.ofocus.match('return'))
                        return;
                    else
                        eval(this.ofocus);
                }
                if(this.value == this.oldval)
                    this.value = '';
                this.focused = true; 
            }
        } else 
            ins[i].onfocus = function() {
                if(this.ofocus) {
                    if(this.ofocus.match('return'))
                        return;
                    else
                        eval(this.ofocus);
                }
                this.focused = true; 
            }
        if(ins[i].onmouseover)
            ins[i].omouseover = getFunc(ins[i].onmouseover);
        ins[i].onmouseover = function() {
            if(this.omouseover) {
                if(this.omouseover.match('return'))
                    return;
                else
                    eval(this.omouseover);
            }
            this.style.backgroundColor = '#ffffdd';
            this.style.borderStyle = 'solid';
            this.style.borderColor = '#ffee66';
            this.style.color = '#000';
            if(this.getStyle('background-repeat') != 'no-repeat')
                this.style.backgroundImage = 'none';
        }
        if(ins[i].onblur)
            ins[i].oblur = getFunc(ins[i].onblur);
        ins[i].onblur = function() {
            if(this.oblur) {
                if(this.oblur.match('return'))
                    return;
                else
                    eval(this.oblur);
            }
            if(this.oldval && !this.value)
                this.value = this.oldval;
            this.style.backgroundColor = this.oldback;
            this.style.backgroundImage = this.oldbacki;
            this.style.borderStyle = this.oldborders;
            this.style.borderColor = this.oldborderc;
            this.style.color = this.oldcolor;
            this.focused = false;
        }
        if(ins[i].onmouseout)
            ins[i].omouseout = getFunc(ins[i].onmouseout);
        ins[i].onmouseout = function() {
            if(this.omouseout) {
                if(this.omouseout.match('return'))
                    return;
                else
                    eval(this.omouseout);
            }
            if(!this.focused) {
                this.style.backgroundImage = this.oldbacki;
                this.style.backgroundColor = this.oldback;
                this.style.borderStyle = this.oldborders;
                this.style.borderColor = this.oldborderc;
                this.style.color = this.oldcolor;
            }
        }
    }
}

function setHeights() {
    if(!$('body')) {
        alert('Nu ai \'body\'!'); return;
    }
    $('body').setStyle('float:left;width:99%;');
    $('footer').setStyle('float:left;width:99%;margin-top:20px');
    window.onresize = function() {};
    var vdim = d.viewport.getDimensions();
    var wind = $(d.body).firstDescendant();
    vdim['width'] = Math.max(vdim['width'], $('body').getWidth()+20);
    wind.style.position = 'absolute';
    wind.style.overflow = 'hidden';
    wind.style.width = vdim['width']+'px';
    vdim['height'] += -$('footer').getHeight() - 20;
    vdim['height'] += -$('header').getHeight();
    if(vdim['height'] > $('body').getHeight())
        //vdim['height'] = Math.max(vdim['height'], $('body').getHeight());
        $('body').style.height = vdim['height']+'px';
    if($('headline1')) {
        hX = wind.firstDescendant().positionedOffset()['left'] - 100;
        //hX = parseInt(vdim.width/2 - ($('headline1').getWidth()/2));
        $('headline'+curH).style.position = 'absolute';
        $('headline'+curH).style.left = hX+'px';
    }
    if($('popload')) {
        var dim = d.viewport.getDimensions();
        $('popload').style.width = dim['width']+'px';
        $('popload').style.height = dim['height']+'px';
        var wid = $('popdiv').getWidth();
        var hei = $('popdiv').getHeight();
        $('popdiv').style.marginTop = parseInt(dim['height']/2 - hei/2)+'px';
        $('popdiv').style.marginLeft = parseInt(dim['width']/2 - wid/2)+'px';
        $('popclose').style.top = parseInt(dim['height']/2 - hei/2 + 4)+'px';
        $('popclose').style.left = parseInt(dim['width']/2 + wid/2 - $('popclose').getWidth() - 4)+'px';
    }
    setTimeout('window.onresize = setHeights',100);
}

function debug(el, func, infunc) {
    if(!$('debug')) {
        var deb = d.createElement('div');
        deb.id = 'debug';
        deb.style.left = '5px';
        deb.style.top = (isie6 ? d.viewport.getScrollOffsets().top+5 : 5)+'px';
        deb.style.overflow = 'auto';
        deb.style.backgroundColor = '#444444';
        deb.style.color = '#ffffff';
        deb.style.font = '11px Arial';
        deb.style.padding = '7px';
        deb.style.border = '2px solid #ffffff';
        deb.style.position = isie6 ? 'absolute' : 'fixed';
        if(isie6) {
            deb.style.width = '600px';
            deb.style.height = '200px';
        } else {
            deb.style.maxHeight = '200px';
            deb.style.minWidth = '250px';
            deb.style.maxWidth = '600px';
        }
        deb.style.zIndex = '10000';
        $(d.body).appendChild(deb);
        $('debug').setOpacity(0.9);
    }
    var type = typeof(el);
    var sel = '';
    switch(type) {
        case 'object':
            for (var i in el)
                if(i != 'channel' && el[i] && (typeof(el[i]) != 'function' || func)) {
                    sel += i;
                    if(infunc || typeof(el[i]) != 'function') sel += ' : '+el[i].toString().replace(/\n/g, '<br>');
                    sel += '<br>';
                }
        break;
        case 'undefined':
            sel = 'undefined';
        break;
        case 'boolean':
        case 'number':
        case 'string':
        case 'function':
        default:
            sel = el.toString().replace(/\n/g, '<br>')+'<br>';
        break;
    }
    if(!sel) sel = '&nbsp;';
    $('debug').innerHTML += ($('debug').innerHTML.length ? '<br>' : '')+sel;
    $('debug').scrollTop = $('debug').scrollHeight - $('debug').clientHeight;
}


function Preload() {
    if (!d.images) return;
    d.prArr=new Array();
    var a=Preload.arguments;
    for(var i=0; i<a.length; i++) {
        d.prArr[i]=new Image; 
        if(a[i].substring(0,4) != 'http') a[i] = im+'dyn/'+a[i];
        d.prArr[i].src = a[i];
    }
}

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 set(id, which, val) {
    if(typeof(val) == 'object') {
        var newval = '';
        for(var i=0;i<val.elements.length;i++)
            if(val.elements[i].name)
                switch(val.elements[i].type) {
                    case 'checkbox':
                        if(val.elements[i].checked)
                            newval += val.elements[i].name+'='+val.elements[i].value+'|';
                    break;
                    case 'select-one':
                    case 'text':
                    case 'textarea':
                        newval += val.elements[i].name+'='+val.elements[i].value+'|';
                    break;
            }
        val = newval.substring(0,newval.length-1);
    }
    if(val == '0' || val == '') return;
    var send = (val && which) ? which+'/'+val : '';
    phpSend(send, id);
}

function phpSend(getline, id, noSet) {
    if(!getline) {
        debug('Invalid Request');
        return;
    }
    getline = latin1(getline);
    if(getline.substring(0,4) != 'http')
        getline = root+'phpsend/'+getline;
    new Ajax.Request(getline, {
        method:'get',
        onSuccess: function(transport) {
            if(!id) return;
            $(id+'ajaxload').remove();
            if($(id).offsetHeight == 32) $(id).style.height = '';
            var response = transport.responseText;
            if(response.substring(0,5) == 'eval:')
                eval(response.substring(5));
            else if($(id).type == 'text') //input
                $(id).value = response.unescape();
            else {
                $(id).innerHTML = response;
                if(!acp && !noSet){
                    setInputs();
                    setHeights();
                }
            }
        },
        onLoading: function() {
            if(!id) return;
            if($(id).getStyle('display') == 'none')
                $(id).style.display = 'block';
            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+'default/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+'default/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 popImgClose() {
    if(!$('popload').visible()) 
        Event.stopObserving(window, 'keypress');
    won = false;
    $('popload').hide(); 
}

function popLoad() {
    //internal
    if($('popload')) return;
    var dim = d.viewport.getDimensions();
    var deb = d.createElement('div');
    deb.id = 'popload';
    deb.style.position = isie6 ? 'absolute' : 'fixed';
    if(isie6) {
        deb.style.backgroundColor = "#000000";
        deb.style.backgroundColor = "transparent";
        deb.style.backgroundImage = "url("+im+"default/blank.gif)";
        deb.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+im+"default/overlay_dark.png',sizingMethod='scale')";
    } else
        deb.style.backgroundImage = 'url('+im+'default/overlay_dark.png)';
    deb.innerHTML = '<div id="popdiv"></div><img src="'+im+'default/close.png" alt="Close" id="popclose">';
    $(d.body).appendChild(deb);
    $('popload').style.zIndex = '100';
    $('popload').style.left = '0px';
    $('popload').style.top = (isie6 ? d.viewport.getScrollOffsets().top : 0)+'px';
    $('popload').style.width = dim['width']+'px';
    $('popload').style.height = dim['height']+'px';
    $('popdiv').style.overflow = 'auto';
    $('popdiv').onclick = function() { won = true; };
    $('popclose').style.cursor = 'pointer';
    $('popclose').style.position = isie6 ? 'absolute' : 'fixed';
    $('popclose').onmouseover = function() {
        var deb = d.createElement('div');
        deb.id = 'popcloset';
        $(d.body).appendChild(deb);
        deb.setStyle('position:absolute;font:12px Arial;color:white;z-index:101;');
        deb.update(closet+'<div style="position:relative;top:-16px;left:-1px;color:black">'+closet+'</div>');
        deb.style.left = ($(this).positionedOffset().left - deb.getWidth() - 8)+'px';
        deb.style.top = ($(this).positionedOffset().top - 2)+'px';
    };
    $('popclose').onmouseout = function() { $('popcloset').remove(); };
}

function popImg(srcu) {
    var dim = d.viewport.getDimensions();
    popLoad();
    if(isie || ischrome) 
        $('popdiv').style.overflow = 'hidden';
    $('popload').onclick = function() {
        if(!won)
            popImgClose();
        else 
            won = false;
    };
    $('popclose').onclick = function() { popImgClose(); };
    $('popdiv').innerHTML = '<img id="popim" src="'+im+'default/loading_dark.gif" alt="please wait...">';
    $('popclose').hide();
    $('popload').show();
    $('popdiv').style.width = '32px';
    $('popdiv').style.height = '32px';
    $('popim').style.paddingTop = parseInt(32/2 - 16)+'px';
    $('popim').style.paddingLeft = parseInt(32/2 - 16)+'px';
    $('popdiv').style.marginTop = parseInt(dim['height']/2 - 32/2)+'px';
    $('popdiv').style.marginLeft = parseInt(dim['width']/2 - 32/2)+'px';
    Event.observe(window,'keypress',function(event) {
        if(event.keyCode == 27)
            popImgClose();
    }); 
    var imgu = new Image;
    imgu.onload = function() {
        $('popdiv').innerHTML = '';
        $('popdiv').appendChild(this);
        var wid = $(this).getWidth();
        var hei = $(this).getHeight();
        var scrols = false;
        if(wid > dim.width || hei > dim.height)
            scrols = true;
        wid = Math.min(wid, dim.width);
        hei = Math.min(hei, dim.height);
        $('popdiv').style.width = wid+'px';
        $('popdiv').style.height = hei+'px';
        $('popdiv').style.marginTop = parseInt(dim['height']/2 - hei/2)+'px';
        $('popdiv').style.marginLeft = parseInt(dim['width']/2 - wid/2)+'px';
        $('popclose').style.top = parseInt(dim['height']/2 - hei/2 + (scrols ? 8 : 4))+'px';
        $('popclose').style.left = parseInt(dim['width']/2 + wid/2 - $('popclose').getWidth() - (scrols ? 25 : (ischrome ? 15 : 4)))+'px';
        $('popclose').show();
    }
    if(srcu.substring(0,4) != 'http')
        srcu = im+'dyn/'+srcu;
    imgu.src = srcu;
}

function popClose() {
    won = false;
    $('popdiv').update('');
    $('popload').hide();
    if($('formerr'))
        $('formerr').hide();
}

function popPage(pag, wid, hei) {
    wid = parseInt(wid);
    hei = parseInt(hei);
    if(!wid || !hei || !pag) return;
    if(pag.substring(0,4) != 'http')
        pag = root+'phpsend/'+pag;
    new Ajax.Request(pag, {
        method:'get',
        onSuccess: function(transport) {
            var response = transport.responseText;
            $('popdiv').innerHTML = response;
            $('popclose').show();
            if(response.match(/<input|<select|<textarea/g))
                setInputs();
        },
        onLoading: function() {
            var dim = d.viewport.getDimensions();
            popLoad();
            $('popload').onclick = function() {
                if(!won)
                    popClose();
                else 
                    won = false;
            };
            $('popclose').onclick = function() { won = false; };
            $('popdiv').innerHTML = '<img id="popim" src="'+im+'default/loading_dark.gif" alt="please wait...">';
            $('popclose').hide();
            $('popload').show();
            $('popdiv').style.width = wid+'px';
            $('popdiv').style.height = hei+'px';
            $('popim').style.paddingTop = parseInt(hei/2 - 16)+'px';
            $('popim').style.paddingLeft = parseInt(wid/2 - 16)+'px';
            $('popdiv').style.marginTop = parseInt(dim['height']/2 - hei/2)+'px';
            $('popdiv').style.marginLeft = parseInt(dim['width']/2 - wid/2)+'px';
            $('popclose').style.top = parseInt(dim['height']/2 - hei/2 + 8)+'px';
            $('popclose').style.left = parseInt(dim['width']/2 + wid/2 - $('popclose').getWidth() - 7)+'px';
        }
    });
}

function correctPNG() {
    if(isie6)
        cob['pngc'] = new PeriodicalExecuter(function(pe) { setPNG();} , 0.1);
}

function setPNG() {
    pngI++;
    if(pngI == d.images.length) cob['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;
    }
}
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;
}

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

//acp
function acpinit() {
    acp = true;
    setInputs();
    swfUploadInit();
    acpres();
    if($('sorti'))
        Sortable.create('sorti',{tag:"div",delay:300,handle:"hand",
            onUpdate:function(element){
                var els = element.immediateDescendants();
                var ids = new Array();
                for(var i=0;i<els.length;i++)
                    ids.push(els[i].id.substring(4));
                var sen = '';
                var fid = els[0].id.substring(0,4);
                switch(fid) {
                    case 'art_':
                        sen = 'articles/artsort/';
                    break;
                    case 'prd_':
                        sen = 'products/prdsort/';
                    break;
                    default:
                        $('ajaxstatus').update(ero);
                        return;
                }
                phpSend(sen+ids.join('-'), 'ajaxstatus');
                ids = ids.sortBy(function(id) {return parseInt(id);});
                ids = ids.reverse();
                for(var i=0;i<els.length;i++)
                    els[i].id = fid+ids[i];
            }
        });
    if($('sortables')) {
        $('sortables').immediateDescendants().each(function(el) {
            el.down().next().immediateDescendants().each(function(eli) {
                Sortable.create(eli.down().next().id, {scroll:window, scrollSpeed: 50, 
                    onUpdate:function(element) {
                        phpSend('products/catsort/'+Sortable.sequence(element.id).join('-'), 'ajaxstatus');
                    }
                });
            });
            Sortable.create(el.down().next().id, {scroll:window, scrollSpeed: 50, 
                onUpdate:function(element) {
                    phpSend('products/catsort/'+Sortable.sequence(element.id).join('-'), 'ajaxstatus');
                }
            });
        });
        Sortable.create('sortables', {scroll:window, scrollSpeed: 50, 
            onUpdate:function(element) {
                phpSend('products/catsort/'+Sortable.sequence(element.id).join('-'), 'ajaxstatus');
            }
        });
    }
}
function acpres() {
    if(!$('body')) {
        alert('Nu ai \'body\'!'); return;
    }
    window.onresize = function() {};
    $('body').setStyle('float:left;width:100%;');
    $('footer').setStyle('float:left;width:100%;');
    var vdim = document.viewport.getDimensions();
    var wind = $(d.body).firstDescendant();
    vdim.width = Math.max(vdim.width, 999);
    wind.style.position = 'absolute';
    wind.style.overflow = 'hidden';
    wind.style.width = vdim.width+'px';
    vdim.height += -$('footer').getHeight();
    vdim.height += -$('header').getHeight();
    if(vdim['height'] > $('body').getHeight())
        $('body').style.height = vdim['height']+'px';
    setTimeout('window.onresize = acpres',100);
}
function acpset(set, val, phps) {
    location.href = root+'setacp-'+set+'-'+val;
    if(isie) event.returnValue=false;
}
function langedit(where, k, val) {
    //val = val.toPhp();
    k = k.toPhp();
    var phpline = root+'phpsend/langedit/'+k+'/';
    var getlen = 1900 - phpline.length;
    var i = 0;
    while(val.length > getlen) {
        phpSend('langedit/'+i+'/'+k+'/'+val.substring(0, getlen).toPhp(), where);
        val = val.substring(getlen);
        i++;
    }
    phpSend('langedit/fin/'+k+'/'+val.toPhp(), where);
}
function selart(all) {
    var ins = d.save.elements;
    for(var i=0;i<ins.length;i++)
        if(ins[i].name.substring(0,4) == 'art_')
            ins[i].checked = all ? true : false;
}
function apcartact(val) {
    var ins = d.save.elements;
    var ids = new Array();
    for(var i=0;i<ins.length;i++)
        if(ins[i].name.substring(0,4) == 'art_' && ins[i].checked)
            ids.push(ins[i].parentNode.parentNode.parentNode.id.substring(4));
    if(!ids.length) {
        d.save.actsel.selectedIndex = 0;
        return;
    }
    if(val == 'artdel') {
        if(confirm(areyousure)) 
            acpset(val, ids.join('-'));
        else
            d.save.actsel.selectedIndex = 0;
        return;
    }
    acpset(val, ids.join('-'));
}
function acptip(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 = '10px 12px 10px 12px';
        deb.style.zIndex = '100';
        $(d.body).appendChild(deb);
    }
    if(tex) {
        $('mshtip').style.left = (tempX+10)+'px';
        $('mshtip').style.top = tempY+'px';
        $('mshtip').innerHTML = tex;
        $('mshtip').show();
        $(d.body).onclick = function() {
            if(won) {
                mtip();
                $(d.body).onclick = function() {};
                won = false;
            } else
                won = true;
        };
    } else
        $('mshtip').hide();
}
function setDefImg(care) {
    var iid = care.up().up().id.substring(5);
    phpSend('products/setdef/'+iid);
    for(var i=0;i<imglen.length;i++)
        if(imglen[i] != iid)
            $('pimg_'+imglen[i]).down().next().innerHTML = '<a href="#" onclick="setDefImg(this);return false">'+setdefault+'</a>';
        else
            $('pimg_'+imglen[i]).down().next().innerHTML = defaultt;
}
function acpDelImg(care, tip) {
    if(!confirm(areyousure)) return;
    var unde = care.up().id;
    var iid = unde.substring(5);
    imglen = imglen.without(iid);
    phpSend(tip+'/delimg/'+iid, unde);
}
function swfUploadInit() {
    if(typeof(SWFUpload) == 'undefined' || typeof(swfu) == 'undefined') return;
    new SWFUpload({
        upload_url: root+"swfupload/"+swfu,
        post_params: {"PHPSESSID": PHPSESSID},
        file_size_limit : "5 MB",
        file_types : "*.jpg;*.jpeg;*.gif;*.png;*.bmp",
        file_types_description : "Image Files",
        file_upload_limit : "0",
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        button_image_url : im+"default/spyglass.png",	// Relative to the SWF file
        button_placeholder_id : "swfuButton",
        button_width: 200,
        button_height: 18,
        button_text : '<span class="button">'+selectimages+' <span class="buttonSmall">(5 MB Max)</span></span>',
        button_text_style : '.button {font-family: Helvetica, Arial, sans-serif;} .buttonSmall { font-size: 10px; }',
        button_text_top_padding: 0,
        button_text_left_padding: 18,
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        button_cursor: SWFUpload.CURSOR.HAND,
        flash_url : root+"templates/swfupload.swf",
        custom_settings : {
            upload_target : "sfwuProgress"
        },
        debug: false
    });
}
function addShopImage(sdata) {
    var iid = sdata.substring(0, sdata.indexOf(':'));
    var pthumb = sdata.substring(sdata.indexOf(':')+1);
    var pimg = pthumb.substring(pthumb.indexOf(':')+1);
    pthumb = pthumb.substring(0,pthumb.indexOf(':'));
    imglen.push(iid);
    var deb = d.createElement('div');
    deb.id = 'pimg_'+iid;
    deb.setStyle('height:100px;width:99%;');
    deb.innerHTML = '<div><img src="'+im+'dyn/'+pthumb+'" alt="" onmousemove="acptip(\'<img src=\\\''+im+'dyn/'+pimg+'\\\' width=\\\'500\\\'>\')" onmouseout="mtip()"></div>';
    deb.innerHTML += '<div><a href="#" onclick="setDefImg(this);return false">'+setdefault+'</a></div><br><br><a href="#" onclick="acpDelImg(this, \'products\');return false">'+deletet+'</a>';
    $('thumbnails').appendChild(deb);
    if(d.getElementsByClassName('opt')[0].getHeight() > $('body').getHeight()-$('footer').getHeight()-3)
        $('body').style.height = '100%';
}
function acpAddCDesc() {
    var deb = d.createElement('div');
    deb.setStyle('float:left;width:99%;height:50px;');
    deb.innerHTML = '<div style="width:15%;padding-left:7px;"><input type="text" class="text" onchange="acpSaveCDesc()" style="width:80%">:</div>';
    deb.innerHTML += '<div style="width:82%;"><a href="#" onclick="this.up().up().remove();acpSaveCDesc();return false" class="progressCancel"></a><input type="text" class="text" onchange="acpSaveCDesc()" style="width:94%;"></div>';
    $('customd').appendChild(deb);
    if(d.getElementsByClassName('artedit')[0].getHeight() > $('body').getHeight()-$('footer').getHeight()-3)
        $('body').style.height = '100%';
}
function acpAddSpec() {
    var deb = d.createElement('div');
    deb.setStyle('float:left;width:99%;');
    deb.innerHTML = '<div style="width:77%;padding-left:7px;"><input type="text" class="text" name="newdname[]"></div>';
    deb.innerHTML += '<div style="width:20%;padding-left:7px;"><a href="#" onclick="this.up().up().remove();return false" class="progressCancel"></a><select name="newisfront[]" style="width:80%"><option>'+hiddent+'</option><option>'+displayedt+'</option></select></div>';
    $('newspecs').appendChild(deb);
    if(d.getElementsByClassName('artedit')[0].getHeight() > $('body').getHeight()-$('footer').getHeight()-3)
        $('body').style.height = '100%';
}
function acpSaveCDesc() {
    var ins = $('customd').immediateDescendants();
    d.save.pdesc.value = '';
    var ke,va;
    for(var i=0;i<ins.length;i++) {
        ke = ins[i].down().down().value;
        va = ins[i].down().next().down().next().value;
        if(ke && va)
            d.save.pdesc.value += ke+'||'+va+'|||';
    }
    d.save.pdesc.value = d.save.pdesc.value.substring(0,d.save.pdesc.value.length-3);
}

// ]]>