function printUSES(uses,usesdate1,usesdate2) {
	$('newuses').value = "0";
	new Ajax.Updater('usesDIV', '/system_modules/webshop_v1/includes/admin_usesprint.php?uses='+uses+'&usesdate1='+usesdate1+'&usesdate2='+usesdate2, { method: 'get' });
}

function SEARCHprintUSES(uses,usesdate1,usesdate2,date) {
	new Ajax.Updater('usesDIV', '/system_modules/webshop_v1/includes/search_usesprint.php?uses='+uses+'&usesdate1='+usesdate1+'&usesdate2='+usesdate2+'&date='+date, { method: 'get' });
}

function printATTR(attr) {
	obj = $('newattr');
	obj.value = "0";
	new Ajax.Updater('attrDIV', '/system_modules/webshop_v1/includes/admin_attrprint.php?attr='+attr , { method: 'get' });
}

function adminATTRremove(id) {
	var attrSTR = $F('attributs');
	var CHKattrARRAY = attrSTR.split(",");
	CHKattrARRAY.reverse();
	key = 0;
	while (value = CHKattrARRAY.pop()) {
		if (value == id) delkey = key;
		key++;
	}
	var OA = attrSTR.split(",");
	OA.splice(delkey,1);
	var NEWattrSTR = OA.toString();
	$('attributs').value = NEWattrSTR;
	printATTR($F('attributs'));
}

function resetDATES() {	
	obj = $('year1');
	obj.value = "0";
	obj = $('year2');
	obj.value = "0";
}

function resetSELECTS() {
	obj = $('year1');
	obj.value = "0";
	obj = $('year2');
	obj.value = "0";
	obj = $('newuses');
	obj.value = "0";
	obj = $('newattr');
	obj.value = "0";
}

function checkcikkszam(cikkszamNUM) {
	new Ajax.Updater('cikkszamCHKDIV', '/system_modules/webshop_v1/includes/cikkszamCHK.php?cikkszam='+cikkszamNUM , { method: 'get' });
}

// ------------------------
function sumbitkeres() {
	USESobj = $('USES');
	USESparentsobj = $('USESlevel');
	// alert (USESparentsobj.value + ' ' + DATEobj.value);

	if ($F('date') > 0 && USESparentsobj.value < 2) {
		alert ("Error");
		// DATEobj.value = 0;
	} else {
	document.shopsearch.submit();
	}
}

// ------------------------

function OCimageCHANGE(imgID)																		// hide TOOLTIP
    {
			obj = $(imgID);
			imgsrc = obj.src;
			if (imgsrc.match("-.gif")) {
				obj.src="/webshop/images/list_+.gif";
			} else {
				obj.src="/webshop/images/list_-.gif";
			}
	}
	
// ------------------------

function order_and_pay() {
	if ($F('accept') == 'accepted') $('chkout').submit();
	else systemFLOATmessage_show(you_must_accept_terms_and_conditions);
	}
	
function cart_add_button() {
	$('product_admin_form').action = '/system_modules/webshop_v1/cart_run.php';
	$('product_admin_form').submit();
}

function multi_pic_slider(div,picnum,picwidth,direction) {
	if ($(div).picnow == undefined) var pic = 0;
	else var pic = $(div).picnow;
	var nextpic = Number(pic) + Number(direction);
	if (nextpic < 0) nextpic = Number(0);
	if (nextpic > picnum) nextpic = Number(picnum);
	var to = Number(nextpic) * Number(picwidth) * Number(-1);
	$(div).picnow = nextpic;
	clearTimeout($(div).slide);
	multi_pic_slider_move(div,to);
}

function multi_pic_slider_move(div,to) {
	var len = $(div).style.left.length;
	var from = $(div).style.left.substr(0,len-2);
	if (from == to) return false;
	var maxspeed = 7;
	var tolerance = 20;
	if (Number(from) < Number(to)) {
		var step = 1;
		var offset1 = Number(to) - Number(from);
	} else {
		var step = -1;
		var offset1 = Number(from) - Number(to);
	}
	
	if (offset1 > tolerance) var step = step * maxspeed;
	
	// $('debug').update('step: ' + step);

	now = Number(from)+Number(step);
	$(div).style.left = now+'px';
	if (step > 0) {
		if (now < to) $(div).slide = setTimeout('multi_pic_slider_move(\''+div+'\',\''+to+'\')', 20);
	} else {
		if (now > to) $(div).slide = setTimeout('multi_pic_slider_move(\''+div+'\',\''+to+'\')', 20);
	}
}


function openlogin() {
	updateSUBpage('/system/boxx/boxx-login.php?');
}





Zoomer = Class.create({
    initialize: function (element, zoomer,  options, preload) {
		
        this.element    = $(element);
        this.zoomer    	= $(zoomer);
        this.posgrab    = this.element.up('#picshow');
		this.image      = this.element.down('img');
        this.zoomimage  = this.zoomer.down('img');
        this.source     = {
            small: this.image.src,
            large: this.element.href
        }

		this.zoomer.style.display = "none";

        // Restart when small image fully loaded
        if (!preload) {
            var image    = new Image();
            image.src    = this.source.small;
            image.onload = this.initialize.bind(this).curry(element, zoomer, options, true);
            return;
        }

        this.selected   = this.source.small;

        this.options = Object.extend({
            trigger:        null,
            afterZoomIn:    null,
            afterZoomOut:   null
        }, options || {});

        this.position = this.posgrab.cumulativeOffset();

        this.dimensions = {
            small: {
                width:  this.image.getWidth(),
                height: this.image.getHeight()
            }
        }

        this.scaleReport = 1;

        // Large image preloading
        this.preload        = new Image();
        this.preload.src    = this.source.large;
        this.preload.onload = this.loaded.bind(this);

        // Wrappers
        this.scroller = (new Element('div')).setStyle({
            overflow: 'auto',
            width: this.dimensions.small.width + 20 + 'px',
            height: this.dimensions.small.height + 20 + 'px'
        });

        this.element.wrap(this.scroller);

        this.wrapper = (new Element('div').setStyle({
            overflow: 'hidden',
            width: this.dimensions.small.width + 'px',
            height: this.dimensions.small.height + 'px'
        }));

        this.scroller.wrap(this.wrapper);


        // Zoom onover on additional trigger
        if (this.options.trigger) {
            $(this.options.trigger).observe('over', this.over.bindAsEventListener(this));
        }
        
        this.element.observe('mouseover',       this.in.bindAsEventListener(this));
		this.element.observe('click',       this.click.bindAsEventListener(this));
		this.element.observe('mouseout',       this.out.bindAsEventListener(this));
        this.element.observe('mousemove',   this.move.bindAsEventListener(this));
  },


    over: function (event) {
        event.stop();
		this.zoomer.style.display = "block"; 
        switch (this.selected) {
            case this.source.small:
                if (this.element.loaded) {
                    this.zoomimage.src = this.selected = this.source.large;
                    this.element.show();                    
                    this.move(event);
                    if (this.options.afterZoomIn) {
                        this.options.afterZoomIn();
                    }
                } else {                    
                    this.element.hide();
                    // Periodically check if target image has loaded
                    this.over.bind(this).delay(0.5, event);
                }
            break;
            case this.source.large:
                this.zoomimage.src = this.selected = this.source.large;
                if (this.options.afterZoomOut) {
                    this.options.afterZoomOut();
                }
            break;
        }
    },

    in: function (event) {
        event.stop();
		this.zoomimage.src = this.source.large;
		this.zoomer.style.display = "block"; 
	},


    out: function (event) {
        event.stop();
		this.zoomimage.src = this.source.large;
		this.zoomer.style.display = "none";
	},
	
    click: function (event) {
        event.stop();
		false;
	},	


    move: function (event) {
        var x = event.pointerX() - this.position.left;
        var y = event.pointerY() - this.position.top;

        // this.scroller.scrollLeft = x * this.scaleReport - x;
        // this.scroller.scrollTop  = y * this.scaleReport - y;

//        this.zoomimage.style.marginLeft = -this.scaleReport * x + x + "px";
//       this.zoomimage.style.marginTop = -this.scaleReport * y + y + "px";

        this.zoomimage.style.marginLeft = -4.4 * x  + 50 + "px";
        this.zoomimage.style.marginTop = -4.4 * y + 5 + "px";
 
    },


    loaded: function () {
        this.element.loaded = true;
        this.dimensions.large = {
            width:  this.preload.width,
            height: this.preload.height
        };

        this.scaleReport = this.dimensions.large.width / this.dimensions.small.width;
    }
});
