/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition License
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magentocommerce.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://www.magentocommerce.com/license/enterprise-edition
 */

// Add validation hints
Validation.defaultOptions.immediate = true;
Validation.defaultOptions.addClassNameToContainer = true;

Event.observe(document, 'dom:loaded', function() {
    var inputs = $$('ul.options-list input');
    for (var i = 0, l = inputs.length; i < l; i ++) {
        inputs[i].addClassName('change-container-classname');
    }
})

if (!window.Enterprise) {
    window.Enterprise = {};
}
Enterprise.templatesPattern =  /(^|.|\r|\n)(\{\{(.*?)\}\})/;

Enterprise.TopCart= {
    initialize: function (container) {
        this.container = $(container);
        this.element = this.container.up(0);
        this.elementHeader = this.container.up(1);
        this.intervalDuration = 4000;
        this.interval = null;
        this.onElementMouseOut = this.handleMouseOut.bindAsEventListener(this);
        //this.onElementMouseOver = this.handleMouseOver.bindAsEventListener(this);
        this.onElementMouseOver = this.handleMouseOver.bindAsEventListener(this);

        //this.element.observe('mouseout', this.onElementMouseOut);
        this.elementHeader.observe('mouseout', this.onElementMouseOut);
        this.element.observe('mouseover', this.onElementMouseOver);
        this.elementHeader.observe('mouseover', this.onElementMouseOver);

    },

    handleMouseOut: function (evt) {
       if($(this.elementHeader).hasClassName('expanded')) {
            this.interval = setTimeout(this.hideCart.bind(this), this.intervalDuration);
        }
    },

    /*handleMouseOver: function (evt) {
        if (this.interval !== null) {
             clearTimeout(this.interval);
             this.interval = null;
        }
    },*/

    handleMouseOver: function (evt) {
        if (!$(this.elementHeader).hasClassName('expanded') && !$(this.container.id).hasClassName('process') )  {
            this.showCart();
        }
        if (this.interval !== null) {
             clearTimeout(this.interval);
             this.interval = null;
        }
        /*else {
            this.hideCart();
        }*/
    },

    showCart: function (timePeriod) {
    	 $(this.elementHeader).addClassName('expanded');
        this.container.up(1).style.zIndex=992;
        new Effect.SlideDown(this.container.id, { duration: 0.5,
            beforeStart: function(effect) {$( effect.element.id ).addClassName('process');},
            afterFinish: function(effect) {$( effect.element.id ).removeClassName('process'); }
            });
        $(this.elementHeader).addClassName('expanded');
        if(timePeriod) {
            this.timePeriod = timePeriod*1000;
            this.interval = setTimeout(this.hideCart.bind(this), this.timePeriod);
        }
    },

    hideCart: function () {

        if (!$(this.container.id).hasClassName('process') && $(this.elementHeader).hasClassName('expanded')) {
            new Effect.SlideUp(this.container.id, { duration: 0.5,
                beforeStart: function(effect) {$( effect.element.id ).addClassName('process');},
                afterFinish: function(effect) {
                    $( effect.element.id ).removeClassName('process');
                    effect.element.parentNode.style.zIndex=1;
                    }
                });
        }
        if (this.interval !== null) {
            clearTimeout(this.interval);
            this.interval = null;
        }
        $(this.elementHeader).removeClassName('expanded');
    }
};


Enterprise.Bundle = {
     oldReloadPrice: false,
     initialize: function () {
        this.slider = $('bundleProduct');
        this.xOffset = $('bundle-product-wrapper').getDimensions().width;
     },
     swapReloadPrice: function () {
         Enterprise.Bundle.oldReloadPrice = Product.Bundle.prototype.reloadPrice;
         Product.Bundle.prototype.reloadPrice = Enterprise.Bundle.reloadPrice;
         Product.Bundle.prototype.selection = Enterprise.Bundle.selection;
     },
     reloadPrice: function () {
         var result = Enterprise.Bundle.oldReloadPrice.bind(this)();
         var priceContainer, duplicateContainer = null
         if (priceContainer = $('bundle-product-wrapper').down('.price-box .price-as-configured')) {
            if (duplicateContainer = $('bundle-product-wrapper').down('.duplicate-price-box .price-as-configured')) {
                duplicateContainer.down('.price').update(
                    priceContainer.down('.price').innerHTML
                );
            }
         }
         if (!this.summaryTemplate && $('bundle-summary-template')) {
             this.summaryTemplate = new Template($('bundle-summary-template').innerHTML, Enterprise.templatesPattern);
             this.optionTemplate = new Template($('bundle-summary-option-template').innerHTML, Enterprise.templatesPattern);
             this.optionMultiTemplate = new Template($('bundle-summary-option-multi-template').innerHTML, Enterprise.templatesPattern);
         }

         if (this.summaryTemplate && $('bundle-summary')) {
             var summaryHTML = '';
             for (var option in this.config.options) {
                if (typeof (this.config.selected[option]) !== 'undefined') {
                    var optionHTML = '';
                    for (var i = 0, l = this.config.selected[option].length; i < l; i ++) {
                        var selection = this.selection(option, this.config.selected[option][i]);
                        if (selection && this.config.options[option].isMulti) {
                            optionHTML += this.optionMultiTemplate.evaluate(selection);
                        } else if (selection) {
                            optionHTML += this.optionTemplate.evaluate(selection);
                        }
                    }

                    if (optionHTML.length > 0) {
                        summaryHTML += this.summaryTemplate.evaluate({label:this.config.options[option].title.escapeHTML(), options: optionHTML});
                    }
                }
             }

             $('bundle-summary').update(summaryHTML).childElements().last().addClassName('last');
         }
         return result;
     },
     selection: function(optionId, selectionId) {
        if (selectionId == '' || selectionId == 'none') {
            return false;
        }
        var qty = null;
        if (this.config.options[optionId].selections[selectionId].customQty == 1 && !this.config['options'][optionId].isMulti) {
            if ($('bundle-option-' + optionId + '-qty-input')) {
                qty = $('bundle-option-' + optionId + '-qty-input').value;
            } else {
                qty = 1;
            }
        } else {
            qty = this.config.options[optionId].selections[selectionId].qty;
        }

        return {qty: qty, name: this.config.options[optionId].selections[selectionId].name.escapeHTML()};
     },
     start: function () {
        if (!$('bundle-product-wrapper').hasClassName('moving-now')) {
            new Effect.Move(this.slider, {
                x: -this.xOffset, y: 0, mode: 'relative', duration: 1.5,
                beforeStart: function (effect) {
                    $('bundle-product-wrapper').setStyle({height: $('productView').getHeight() + 'px'});
                    $('options-container').show();
                    Enterprise.BundleSummary.initialize();
                    $('bundle-product-wrapper').addClassName('moving-now');
                },
                afterFinish: function (effect) {
                    $('bundle-product-wrapper').setStyle({height: 'auto'});
                    $('productView').hide();
                    $('bundle-product-wrapper').removeClassName('moving-now');
                }
            });
         }
     },
     end: function () {
        if (!$('bundle-product-wrapper').hasClassName('moving-now')) {
            new Effect.Move(this.slider, {
                    x: this.xOffset, y: 0, mode: 'relative', duration: 1.5,
                    beforeStart: function (effect) {
                        $('bundle-product-wrapper').setStyle({height: $('options-container').getHeight() + 'px'});
                        $('productView').show();
                        $('bundle-product-wrapper').addClassName('moving-now');
                    },
                    afterFinish: function (effect) {
                        $('bundle-product-wrapper').setStyle({height: 'auto'});
                        $('options-container').hide();
                        Enterprise.BundleSummary.exitSummary();
                        $('bundle-product-wrapper').removeClassName('moving-now');
                    }
                });
        }
     }
};

Enterprise.BundleSummary = {
    initialize: function () {
        this.summary = $('bundleSummary');
        this.summaryOffsetTop = $('customizeTitle').getDimensions().height;
        this.summary.setStyle({top:this.summaryOffsetTop + "px"});
        this.summaryContainer = this.summary.up(0);
        this.doNotCheck = false;
        this.summaryStartY = this.summary.positionedOffset().top;
        this.summaryStartY = this.summaryOffsetTop;
        this.summaryStartX = this.summary.positionedOffset().left;
        this.onDocScroll = this.handleDocScroll.bindAsEventListener(this);
        this.GetScroll = setInterval(this.onDocScroll, 50);
        this.onEffectEnds = this.effectEnds.bind(this);
    },

    handleDocScroll: function () {
        if (this.currentOffsetTop == document.viewport.getScrollOffsets().top
            && (this.checkOffset(null) == null)) {
            return;
        } else {
            if (this.currentOffsetTop == document.viewport.getScrollOffsets().top) {
                this.doNotCheck = true;
            }
            this.currentOffsetTop = document.viewport.getScrollOffsets().top;
        }

        if (this.currentEffect) {
            this.currentEffect.cancel();
            var topOffset = 0;
            if (this.summaryContainer.viewportOffset().top < -60) {
               topOffset =  -(this.summaryContainer.viewportOffset().top);
            } else {
               topOffset = this.summaryStartY;
            }
            
            topOffset = this.checkOffset(topOffset);
            if (topOffset === null) {
                this.currentEffect = false;
                return;
            }
            
            this.currentEffect.start({
                x: this.summaryStartX,
                y: topOffset,
                mode: 'absolute',
                duration: 0.3,
                afterFinish: this.onEffectEnds
            });
            
            
            
            return;
        }

        
        this.currentEffect = new Effect.Move(this.summary);
    },
    
    effectEnds: function () {
        if (this.doNotCheck == true) {
            this.doNotCheck = false;
        }
    },
    
    checkOffset: function (offset) {
        if (this.doNotCheck && offset === null) {
            return null;
        }
        var dimensions = this.summary.getDimensions();
        var parentDimensions = this.summary.up().getDimensions();
        if ((offset !== null ? offset : this.summary.offsetTop) + dimensions.height >= parentDimensions.height) {
            offset = parentDimensions.height - dimensions.height;
        } else if (offset === null &&
            this.currentOffsetTop > (this.summaryContainer.viewportOffset().top) &&
            (this.currentOffsetTop - this.summaryContainer.viewportOffset().top) > this.summary.offsetTop) {
            offset = this.currentOffsetTop - this.summaryContainer.viewportOffset().top;
        }
        
        
        return offset;
    },

    exitSummary: function () {
        clearInterval(this.GetScroll);
    }
};

Enterprise.Tabs = Class.create();
Object.extend(Enterprise.Tabs.prototype, {
    initialize: function (container) {
        this.container = $(container);
        this.container.addClassName('tab-list');
        this.tabs = this.container.select('dt.tab');
        this.activeTab = this.tabs.first();
        this.tabs.first().addClassName('first');
        this.tabs.last().addClassName('last');
        this.onTabClick = this.handleTabClick.bindAsEventListener(this);
        for (var i = 0, l = this.tabs.length; i < l; i ++) {
            this.tabs[i].observe('click', this.onTabClick);
        }
        this.select();
    },
    handleTabClick: function (evt) {
        this.activeTab = Event.findElement(evt, 'dt');
        this.select();
    },
    select: function () {
        for (var i = 0, l = this.tabs.length; i < l; i ++) {
            if (this.tabs[i] == this.activeTab) {
                this.tabs[i].addClassName('active');
                this.tabs[i].style.zIndex = this.tabs.length + 2;
                /*this.tabs[i].next('dd').show();*/
                new Effect.Appear (this.tabs[i].next('dd'), { duration:0.5 });
                this.tabs[i].parentNode.style.height=this.tabs[i].next('dd').getHeight() + 15 + 'px';
            } else {
                this.tabs[i].removeClassName('active');
                this.tabs[i].style.zIndex = this.tabs.length + 1 - i;
                this.tabs[i].next('dd').hide();
            }
        }
    }
});


Enterprise.Slider = Class.create();

Object.extend(Enterprise.Slider.prototype, {
    initialize: function (container, config) {
        this.container = $(container);
        this.config = {
            panelCss: 'slider-panel',
            sliderCss: 'slider',
            itemCss: 'slider-item',
            slideButtonCss: 'slide-button',
            slideButtonInactiveCss: 'inactive',
            forwardButtonCss: 'forward',
            backwardButtonCss: 'backward',
            pageSize: 6,
            scrollSize: 2,
            slideDuration: 1.0,
            slideDirection: 'horizontal',
            fadeEffect: true
        };

        Object.extend(this.config, config || {});

        this.items = this.container.select('.' + this.config.itemCss);
        this.isPlaying = false;
        this.isAbsolutized = false;
        this.offset = 0;
        this.onClick = this.handleClick.bindAsEventListener(this);
        this.sliderPanel = this.container.down('.' + this.config.panelCss);
        this.slider =  this.sliderPanel.down('.' + this.config.sliderCss);
        this.container.select('.' + this.config.slideButtonCss).each(
            this.initializeHandlers.bind(this)
        );
        this.updateButtons();
        
        Event.observe(window, 'load', this.initializeDimensions.bind(this));
    },
    initializeHandlers: function (element) {
        if (element.hasClassName(this.config.forwardButtonCss) ||
            element.hasClassName(this.config.backwardButtonCss)) {
            element.observe('click', this.onClick);
        }
    },
    handleClick: function (evt) {
        var element = Event.element(evt);
        if (!element.hasClassName(this.config.slideButtonCss)) {
            element = element.up('.' + this.config.slideButtonCss);
        }

        if (!element.hasClassName(this.config.slideButtonInactiveCss)) {
           element.hasClassName(this.config.forwardButtonCss) || this.backward();
           element.hasClassName(this.config.backwardButtonCss) || this.forward();
        }
        Event.stop(evt);
    },
    updateButtons: function () {
        var buttons = this.container.select('.' + this.config.slideButtonCss);
        for (var i = 0, l = buttons.length; i < l; i++) {
            if (buttons[i].hasClassName(this.config.backwardButtonCss)) {
                if (this.offset <= 0) {
                    buttons[i].addClassName(this.config.slideButtonInactiveCss);
                }
                else {
                    buttons[i].removeClassName(this.config.slideButtonInactiveCss);
                }
            } else if (buttons[i].hasClassName(this.config.forwardButtonCss)) {
                if (this.offset >= this.items.length - this.config.pageSize) {
                    buttons[i].addClassName(this.config.slideButtonInactiveCss);
                }
                else {
                    buttons[i].removeClassName(this.config.slideButtonInactiveCss);
                }
            }
        }
    },
    initializeDimensions: function () {
        if ((this.config.slideDirection == 'horizontal' && this.sliderPanel.style.width) ||
            (this.config.slideDirection != 'horizontal' && this.sliderPanel.style.height)) {
            return this;
        }
        var firstItem = this.items.first();
        var offset = 0;
        if (this.config.slideDirection == 'horizontal') {
            offset = (parseInt(firstItem.getStyle('margin-left')) + parseInt(firstItem.getStyle('margin-right'))) * (this.config.pageSize - 1);
            this.sliderPanel.setStyle({width: (firstItem.getDimensions().width * this.config.pageSize + offset) + 'px'});
        } else {
            offset = (parseInt(firstItem.getStyle('margin-bottom')) + parseInt(firstItem.getStyle('margin-top'))) * (this.config.pageSize - 1);
            this.sliderPanel.setStyle({height: (firstItem.getDimensions().height * this.config.pageSize + offset) + 'px'});
        }
        
        var dimensions = this.sliderPanel.getDimensions();
        
        var sliderParent = this.sliderPanel.up();
        /*
        dimensions.height += parseInt(sliderParent.getStyle('padding-top'));
        dimensions.height += parseInt(sliderParent.getStyle('padding-bottom'));
        dimensions.width += parseInt(sliderParent.getStyle('padding-left'));
        dimensions.width += parseInt(sliderParent.getStyle('padding-right'));
    
        if (sliderParent.down('.slide-button')) {
            var buttonDimensions = sliderParent.down('.slide-button').getDimensions();
            if (this.config.slideDirection == 'horizontal') {
                dimensions.width += 2 * buttonDimensions.width;
            } else {
                dimensions.height += 2 * buttonDimensions.height;
            }
        }
        */
        sliderParent.setStyle({
            width: dimensions.width + 'px',
            height: dimensions.height + 'px'
        });
        return this;
    },
    absolutize: function () {
        if (!this.isAbsolutized) {
            this.isAbsolutized = true;
            var dimensions = this.sliderPanel.getDimensions();
            this.sliderPanel.setStyle({
                height: dimensions.height + 'px',
                width: dimensions.width + 'px'
            });
            
            this.slider.absolutize();
        }
    },
    
    forward: function () {
        if (this.offset + this.config.pageSize <= this.items.length - 1) {
            this.slide(true);
        }
    },
    backward: function () {
        if (this.offset > 0) {
            this.slide(false);
        }
    },
    slide: function (isForward) {

        if (this.isPlaying) {
            return;
        }
        this.absolutize();
        this.effectConfig = {
            duration: this.config.slideDuration
        };
        if (this.config.slideDirection == 'horizontal') {
            this.effectConfig.x = this.getSlidePosition(isForward).left;
        } else {
            this.effectConfig.y = this.getSlidePosition(isForward).top;
        }
        this.start();

    },
    start: function ()
    {
        if (this.config.fadeEffect) {
            this.fadeIn();
        } else {
            this.move();
        }
    },
    fadeIn: function ()
    {
        new Effect.Fade(this.slider.up('div.slider-panel'), {
            from: 1.0,
            to:0.5,
            afterFinish: this.move.bind(this),
            beforeStart: this.effectStarts.bind(this),
            duration: 0.3
        });
    },
    fadeOut: function ()
    {
        new Effect.Fade(this.slider.up('div.slider-panel'), {
                from: 0.5,
                to:1.0,
                afterFinish: this.effectEnds.bind(this),
                duration: 0.3
        });
    },
    move: function ()
    {
        if (this.config.fadeEffect) {
            this.effectConfig.afterFinish = this.fadeOut.bind(this);
        } else {
            this.effectConfig.afterFinish = this.effectEnds.bind(this);
            this.effectConfig.beforeStart = this.effectStarts.bind(this);
        }

        new Effect.Move(this.slider, this.effectConfig);
    },
    effectStarts: function () {
        this.isPlaying = true;
    },
    effectEnds: function () {
        this.isPlaying = false;
        this.updateButtons();
    },
    getSlidePosition: function (isForward) {
        var targetOffset;
        if (isForward) {
            targetOffset = Math.min(this.items.length - this.config.pageSize, this.offset + this.config.scrollSize)
        }
        else {
            targetOffset = Math.max(this.offset - this.config.scrollSize, 0);
        }
        this.offset = targetOffset;
        var item = this.items[targetOffset];
        var itemOffset = {left:0, top:0};

        itemOffset.left = -(item.cumulativeOffset().left
                       -  this.slider.cumulativeOffset().left + this.slider.offsetLeft);
        itemOffset.top = -(item.cumulativeOffset().top
                       -  this.slider.cumulativeOffset().top + this.slider.offsetTop);
        return itemOffset;
    }
});

Enterprise.PopUpMenu = {
    currentPopUp: null,
    documentHandlerInitialized: false,
    popUpZIndex: 994,
    hideDelay: 2000,
    hideOnClick: true,
    hideInterval: null,
    //
    initializeDocumentHandler: function () {
        if (!this.documentHandlerInitialized) {
            this.documentHandlerInitialized = true;
            Event.observe(
                document.body,
                'click',
                this.handleDocumentClick.bindAsEventListener(this)
            );
        }
    },
    handleDocumentClick: function (evt) {
        if (this.currentPopUp !== null) {
            var element = Event.element(evt);
            if (!this.currentPopUp.onlyShowed && this.hideOnClick) {
                this.hide();
            } else {
                this.currentPopUp.onlyShowed = false;
            }
        }
    },
    handlePopUpOver: function (evt) {
        if (this.currentPopUp !== null) {
            this.currentPopUp.removeClassName('faded');
            this.resetTimeout(0);
        }
    },
    handlePopUpOut: function (evt) {
        if (this.currentPopUp !== null) {
            this.currentPopUp.addClassName('faded');
            this.resetTimeout(1);
        }
    },
    show: function (trigger) {
        this.initializeDocumentHandler();

        var container = $(trigger).up('.switch-wrapper');
        if (!$('popId-' + container.id)) {
            return;
        }

        if (this.currentPopUp !== null && $('popId-' + container.id) !== this.currentPopUp) {
            this.hide(true);
        } else if (this.currentPopUp !== null && this.currentPopUp === $('popId-' + container.id)) {
            this.hide();
            return;
        }

        this.currentPopUp = $('popId-' + container.id);
        this.currentPopUp.container = container;
        this.currentPopUp.container.oldZIndex = this.currentPopUp.container.style.zIndex;
        this.currentPopUp.container.style.zIndex = this.popUpZIndex;
        new Effect.Appear(this.currentPopUp, { duration:0.3 });


        if (!this.currentPopUp.isHandled) {
            this.currentPopUp.observe('mouseover', this.handlePopUpOver.bindAsEventListener(this));
            this.currentPopUp.observe('mouseout', this.handlePopUpOut.bindAsEventListener(this));
            this.currentPopUp.isHandled = true;
        }
        this.currentPopUp.onlyShowed = true;
        this.currentPopUp.container.down('.switcher').addClassName('list-opened');
        this.resetTimeout(2);
    },
    hide: function () {
        if (this.currentPopUp !== null) {
            if (arguments.length == 0) {
                new Effect.Fade(this.currentPopUp, {duration: 0.3});
            } else {
                this.currentPopUp.hide();
            }
            this.currentPopUp.container.style.zIndex = this.currentPopUp.container.oldZIndex;
            this.resetTimeout(0);
            this.currentPopUp.container.down('.switcher').removeClassName('list-opened');
            this.currentPopUp = null;
        }
    },
    resetTimeout: function (delay) {
        if (this.hideTimeout !== null) {
            clearTimeout(this.hideTimeout);
            this.hideTimeout = null;
        }
        if (delay) {
            this.hideTimeout = setTimeout(
                this.hide.bind(this),
                this.hideDelay * delay
            );
        }
    }
};


function popUpMenu(element) {
   Enterprise.PopUpMenu.show(element);
}

function refplus(lenom)
{
	var num = document.getElementById(lenom).value;
	if (!isNaN(num)){
		if(document.getElementById(lenom).value < 99){
			document.getElementById(lenom).value=parseInt(num,10) + 1;
		}
	}
}

function refpluswarranty(lenom, qty, url, item_id, warrantyId){
		if(isNaN(qty)){
			var item_count = $(qty).value;
		}
		else{
			var item_count = qty;
		}
		var warranty_num = $(lenom).value;
		if(!isNaN(item_count)){
			if(((parseInt(warranty_num ,10) + 1) <= item_count) && (warranty_num != 0)){
				var tab_param = new Array();
				tab_param['item_id'] = item_id;
				tab_param['warranty_id'] = warrantyId;
				tab_param['qty'] = qty;
				var opt = 
				{
		            method:'post',
		            parameters:tab_param,
		            onSuccess: function(t){
						$(lenom).removeAttribute("readonly");
						$(lenom).value=parseInt(warranty_num,10) + 1;
						$(lenom).setAttribute("readonly", "readonly");
						var response = eval('(' + t.responseText + ')');
						
						
						var row_total = response.row_total.toString();
						var base_grand_total = response.base_grand_total.toString();
						var grand_total = response.grand_total.toString();
						$("cart"+item_id).innerHTML = row_total;
						$("resamag_basegrandtotal").innerHTML = base_grand_total;
						$("resamag_grandtotal").innerHTML = grand_total;
						
//						var row_total = response.row_total.toString();
//						var array_row_total = row_total.split('.');
//						if(!array_row_total[1]) array_row_total[1] = '00';
//						$("cart"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//						
//						var base_grand_total = response.base_grand_total.toString();
//	        			var array_base_grand_total = base_grand_total.split('.');
//	        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//	        			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//	        				
//	        			var grand_total = response.grand_total.toString();
//	        			var array_grand_total = grand_total.split('.');
//	        			if(!array_grand_total[1]) array_grand_total[1] = '00';
//	        			$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
					},
					on404: function(t) {
	    	        	alert(t.responseText);
	    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
	    	    	},
	    	    	onComplete:function(t) {
	    	       		$('reviewretrait-wait_changing_warranties').style.display = "none";
	    	    	},
	    	    	onFailure: function(t) {
	    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
	    	    	},
	    	    	onLoading: function(t) {
	    	       		$('reviewretrait-wait_changing_warranties').style.display = "";
	    	    	}  	
				}
				var ajaxreq = new Ajax.Request(url, opt);
			}
		}
}

function refpluswarrantyinRecap(lenom, qty, url, item_id, warrantyId, from){
		if(isNaN(qty)){
			var item_count = $(qty).value;
		}
		else{
			var item_count = qty;
		}
		var warranty_num = $(lenom).value;
		if(!isNaN(item_count)){
			if(((parseInt(warranty_num ,10) + 1) <= item_count) && (warranty_num != 0)){
				var tab_param = new Array();
				tab_param['item_id'] = item_id;
				tab_param['warranty_id'] = warrantyId;
				tab_param['qty'] = qty;
				var opt = 
				{
		            method:'post',
		            parameters:tab_param,
		            onSuccess: function(t){
						$(lenom).removeAttribute("readonly");
						$(lenom).value=parseInt(warranty_num,10) + 1;
						$(lenom).setAttribute("readonly", "readonly");
						var response = eval('(' + t.responseText + ')');
						
						var row_total = response.row_total.toString();
						var base_grand_total = response.base_grand_total.toString();
						var grand_total = response.grand_total.toString();
						if(from == 2){
							$("cart"+item_id).innerHTML = row_total;
							$("cartrecap"+item_id).innerHTML = row_total;
							$("resamag_basegrandtotal").innerHTML = base_grand_total;
							$("recapmag_basegrandtotal").innerHTML = base_grand_total;
							$("resamag_grandtotal").innerHTML = grand_total;
							$("recapmag_grandtotal").innerHTML = grand_total;
						}
						else if(from == 3){
							$("cartlivrecap"+item_id).innerHTML = row_total;
							$("recapliv_basegrandtotal").innerHTML = base_grand_total
							$("recapliv_grandtotal").innerHTML = grand_total;
							$("price_cb").innerHTML = grand_total;
						}
												
						
//						var array_row_total = row_total.split('.');
//						if(!array_row_total[1]) array_row_total[1] = '00';
//						if(from == 2){
//							$("cart"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//							$("cartrecap"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//						}
//						else if(from == 3){
//							$("cartlivrecap"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//						}
//						var base_grand_total = response.base_grand_total.toString();
//	        			var array_base_grand_total = base_grand_total.split('.');
//	        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//						if(array_base_grand_total[1].length == 1) array_base_grand_total[1] = array_base_grand_total[1]+'0';
//
//	        			if(from == 2){
//		        			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//		        			$("recapmag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//	        			}
//	        			else if(from == 3){
//		        			$("recapliv_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//	        			}
//	        			var grand_total = response.grand_total.toString();
//	        			var array_grand_total = grand_total.split('.');
//	        			if(!array_grand_total[1]) array_grand_total[1] = '00';
//	        			if(array_grand_total[1].length == 1) array_grand_total[1] = array_grand_total[1] + '0';
//	        			if(from == 2){
//		        			$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//		        			$("recapmag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//	        			}
//	        			else if(from == 3){
//		        			$("recapliv_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//	        			}
					},
					on404: function(t) {
	    	        	alert(t.responseText);
	    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
	    	    	},
	    	    	onComplete:function(t) {
	    	    		$('reviewrecap-wait_changing_warranties').style.display = "none";
	    	    	},
	    	    	onFailure: function(t) {
	    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
	    	    	},
	    	    	onLoading: function(t) {
	    	       		$('reviewrecap-wait_changing_warranties').style.display = "";
	    	    	}  	
				}
				var ajaxreq = new Ajax.Request(url, opt);

			}
		}
}

function refmoins(lenom)
{
	var num = document.getElementById(lenom).value;
	if (!isNaN(num))
	{
		if((num != 0) && (num != 1))
		{
			document.getElementById(lenom).value=parseInt(num,10) - 1;
		}
	}
} 

function refmoinswarranty(lenom, item, url, item_id, warrantyId){
	var num = $(lenom).value;
	if (!isNaN(num))
	{
		if((num != 0) && (num != 1))
		{
			var tab_param = new Array();
			tab_param['item_id'] = item_id;
			tab_param['warranty_id'] = warrantyId;
			tab_param['qty'] = $(lenom).value - 1;
			var opt = 
			{
	            method:'post',
	            parameters:tab_param,
	            onSuccess: function(t){
					$(lenom).removeAttribute("readonly");
					$(lenom).value=parseInt(num,10) - 1;
					$(lenom).setAttribute("readonly", "readonly");
					var response = eval('(' + t.responseText + ')');
					
					var row_total = response.row_total.toString();
					var base_grand_total = response.base_grand_total.toString();
					var grand_total = response.grand_total.toString();
					$("cart"+item_id).innerHTML = row_total;
					$("resamag_basegrandtotal").innerHTML = base_grand_total;
					$("resamag_grandtotal").innerHTML = grand_total;
					
//					var row_total = response.row_total.toString();
//					var array_row_total = row_total.split('.');
//					if(!array_row_total[1]) array_row_total[1] = '00';
//					$("cart"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//        			
//					var base_grand_total = response.base_grand_total.toString();
//        			var array_base_grand_total = base_grand_total.split('.');
//        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//        			if(array_base_grand_total[1].length == 1) array_base_grand_total[1] = array_base_grand_total[1]+'0';
//        			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//        				
//        			var grand_total = response.grand_total.toString();
//        			var array_grand_total = grand_total.split('.');
//        			if(!array_grand_total[1])array_grand_total[1] = '00';
//        			if(array_grand_total[1].length == 1) array_grand_total[1] = array_grand_total[1]+'0';
//        			$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
				},
				on404: function(t) {
    	        	alert(t.responseText);
    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
    	    	},
    	    	onComplete:function(t) {
    	       		$('reviewretrait-wait_changing_warranties').style.display = "none";
    	    	},
    	    	onFailure: function(t) {
    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
    	    	},
    	    	onLoading: function(t) {
    	       		$('reviewretrait-wait_changing_warranties').style.display = "";
    	    	}  				
			}
			var ajaxreq = new Ajax.Request(url, opt);

		}	
	}
}

function refmoinswarrantyinRecap(lenom, item, url, item_id, warrantyId, from){
	var num = $(lenom).value;
	if (!isNaN(num))
	{
		if((num != 0) && (num != 1))
		{
			var tab_param = new Array();
			tab_param['item_id'] = item_id;
			tab_param['warranty_id'] = warrantyId;
			tab_param['qty'] = $(lenom).value - 1;
			var opt = 
			{
	            method:'post',
	            parameters:tab_param,
	            onSuccess: function(t){
					$(lenom).removeAttribute("readonly");
					$(lenom).value=parseInt(num,10) - 1;
					$(lenom).setAttribute("readonly", "readonly");

					var response = eval('(' + t.responseText + ')');
					
					var row_total = response.row_total.toString();
					var base_grand_total = response.base_grand_total.toString();
					var grand_total = response.grand_total.toString();
					
					if(from == 2){
						$("cart"+item_id).innerHTML = row_total;
						$("cartrecap"+item_id).innerHTML = row_total;
						$("resamag_basegrandtotal").innerHTML = base_grand_total;
						$("recapmag_basegrandtotal").innerHTML = base_grand_total;
						$("resamag_grandtotal").innerHTML = grand_total;
						$("recapmag_grandtotal").innerHTML = grand_total;
					}
					else if(from == 3){
						$("cartlivrecap"+item_id).innerHTML = row_total;
						$("recapliv_basegrandtotal").innerHTML = base_grand_total;
						$("recapliv_grandtotal").innerHTML = grand_total;
						$("price_cb").innerHTML = grand_total;
					}
					
        			        			
					
//					var row_total = response.row_total.toString();
//					var array_row_total = row_total.split('.');
//					if(!array_row_total[1]) array_row_total[1] = '00';
//					if(array_row_total[1].length == 1) array_row_total[1] = array_row_total[1] + '0';
//					if(from == 2){
//						$("cart"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//						$("cartrecap"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//					}
//					else if(from == 3){
//						$("cartlivrecap"+item_id).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//					}
//        			
//
//					var base_grand_total = response.base_grand_total.toString();
//        			var array_base_grand_total = base_grand_total.split('.');
//        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//        			if(array_base_grand_total[1] < 10) array_base_grand_total[1] = array_base_grand_total[1] * 10;
//        			if(from == 2){
//		    			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//		    			$("recapmag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//        			}
//        			else if(from == 3){
//		    			$("recapliv_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//        			}
//        			var grand_total = response.grand_total.toString();
//        			var array_grand_total = grand_total.split('.');
//        			if(!array_grand_total[1]) array_grand_total[1] = '00';
//        			if(array_grand_total[1].length == 1) array_grand_total[1] = array_grand_total[1]+'0';
//        			if(from == 2){
//		    			$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//		    			$("recapmag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//        			}
//        			else if(from == 3){
//		    			$("recapliv_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//        			}
				},
				on404: function(t) {
    	        	alert(t.responseText);
    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
    	    	},
    	    	onComplete:function(t) {
    	       		$('reviewrecap-wait_changing_warranties').style.display = "none";
    	    	},
    	    	onFailure: function(t) {
    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
    	    	},
    	    	onLoading: function(t) {
    	       		$('reviewrecap-wait_changing_warranties').style.display = "";
    	    	}  				
			}
			var ajaxreq = new Ajax.Request(url, opt);

		}	
	}
	
}

function checkOrUncheck(item, divtext, from, urluncheck, urlcheck, warrantyId, item_qty){
	var id = item.split('-');
	var div = $(item);
	var etat = '';
	
	// On determine l'état
	if(div.hasClassName("box-unchecked")){
		etat = 'unckeck';
	}else{
		etat = 'ckeck';
	}
	
	// On coche ou décoche visuellement
	if(etat == 'unckeck'){
		div.setAttribute("class", "box-checked active");
		$(divtext).removeAttribute("readonly");
		$(divtext).value = item_qty;
//		$(divtext).setAttribute("readonly", "readonly");
	}else{
		div.setAttribute("class", "box-unchecked active");
//		$(divtext).removeAttribute("readonly");
		$(divtext).value = "0";
		$(divtext).setAttribute("readonly", "readonly");
	}
	
	
//	if(div.getAttribute("class") == "box-unchecked"){
//		div.setAttribute("class", "box-checked");
		if(from == 1){
			var tab_param = new Array();
			tab_param['item_id'] = id[1];
			tab_param['warranty_id'] = warrantyId;
			tab_param['ajax'] = true;
			var opt = 
			{	
	            method:'post',
	            parameters:tab_param,
                onSuccess:function(t){
					var response = eval('(' + t.responseText + ')');
					var row_total = response.row_total.toString();
					$("cart"+id[1]).innerHTML = row_total;
					
        			var base_grand_total = response.base_grand_total.toString();
        			$("resamag_basegrandtotal").innerHTML = base_grand_total;
					
        			var grand_total = response.grand_total.toString();
        			$("resamag_grandtotal").innerHTML = grand_total;
					
//					var row_total = response.row_total.toString();
//					var array_row_total = row_total.split('.');
//					if(!array_row_total[1]) array_row_total[1] = '00';
//					if(array_row_total[1].length == 1) array_row_total[1] = array_row_total[1] + '0';
//					$("cart"+id[1]).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//					
//        			var base_grand_total = response.base_grand_total.toString();
//        			var array_base_grand_total = base_grand_total.split('.');
//        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//        			if(array_base_grand_total[1].length == 1) array_base_grand_total[1] = array_base_grand_total[1]+'0';
//        			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//        				
//        			var grand_total = response.grand_total.toString();
//        			var array_grand_total = grand_total.split('.');
//        			if(!array_grand_total[1]) array_grand_total[1] = '00';
//        			if(array_grand_total[1].length == 1) array_grand_total[1] = array_grand_total[1]+'0';
//        			$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//        			$(divtext).removeAttribute("readonly");
//        			$(divtext).value = item_qty;
//        			$(divtext).setAttribute("readonly", "readonly");

				},
				on404: function(t) {
    	        	alert(t.responseText);
    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
    	    	},
    	    	onComplete:function(t) {
    	       		$('reviewretrait-wait_changing_warranties').style.display = "none";
    	    	},
    	    	onFailure: function(t) {
    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
    	    	},
    	    	onLoading: function(t) {
    	       		$('reviewretrait-wait_changing_warranties').style.display = "";
    	    	}  
			}
//			var ajaxreq = new Ajax.Request(urlcheck, opt);
//		}
		
			// On envoi la requete
			if(etat == 'unckeck'){
				var ajaxreq = new Ajax.Request(urlcheck, opt);
			}else{
				var ajaxreq = new Ajax.Request(urluncheck, opt);
			}
			
		}
//	}
//	else{
//		div.setAttribute("class", "box-unchecked");
//		$(divtext).setAttribute("readonly", "readonly");
//		if(from == 1){
//			var tab_param = new Array();
//			tab_param['item_id'] = id[1];
//			tab_param['ajax'] = true;
//			var opt = 
//			{	
//	             	method:'post',
//	             	parameters:tab_param,
//	                onSuccess:function(t)
//	            	{
//						var response = eval('(' + t.responseText + ')');
//
//	        			$("cart"+id[1]).innerHTML = "0<sup>€00</sup>";
//	        			var base_grand_total = response.base_grand_total.toString();
//	        			var array_base_grand_total = base_grand_total.split('.');
//	        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//	        			if(array_base_grand_total[1].length == 1) array_base_grand_total[1] = array_base_grand_total[1]+'0';
//	        			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//	        				
//	        			var grand_total = response.grand_total.toString();
//	        			var array_grand_total = grand_total.split('.');
//	        			if(!array_grand_total[1]) array_grand_total[1] = '00';
//	        			if(array_grand_total[1].length == 1) array_grand_total[1] = array_grand_total[1] + '0';
//	        			$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//	        			$(divtext).removeAttribute("readonly");
//	        			$(divtext).value = "0";
//	        			$(divtext).setAttribute("readonly", "readonly");
//
//	    	        },
//	                on404: function(t) {
//	    	        	alert(t.responseText);
//	    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
//	    	    	},
//	    	    	onComplete:function(t) {
//	    	       		$('reviewretrait-wait_changing_warranties').style.display = "none";
//	    	    	},
//	    	    	onFailure: function(t) {
//	    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
//	    	    	},
//	    	    	onLoading: function(t) {
//	    	       		$('reviewretrait-wait_changing_warranties').style.display = "";
//	    	    	}  
//			}
//			var ajaxreq = new Ajax.Request(urluncheck, opt);
//		}
//	}
}

function checkOrUncheckinRecap(item, divtext, from, urluncheck, urlcheck, warrantyId, item_qty){
	var id = item.split('-');
	var div = $(item);
	var etat = '';
	
	// On determine l'état
	if(div.hasClassName("box-unchecked")){
		etat = 'unckeck';
	}else{
		etat = 'ckeck';
	}
	
	// On coche ou décoche visuellement
	if(etat == 'unckeck'){
		div.setAttribute("class", "box-checked active");
		$(divtext).removeAttribute("readonly");
		$(divtext).value = item_qty;
//		$(divtext).setAttribute("readonly", "readonly");
	}else{
		div.setAttribute("class", "box-unchecked active");
//		$(divtext).removeAttribute("readonly");
		$(divtext).value = "0";
		$(divtext).setAttribute("readonly", "readonly");
	}
		
			var tab_param = new Array();
			tab_param['item_id'] = id[1];
			tab_param['warranty_id'] = warrantyId;
			tab_param['ajax'] = true;
			var opt = 
			{	
	            method:'post',
	            parameters:tab_param,
                onSuccess:function(t){
					var response = eval('(' + t.responseText + ')');
					
					var row_total = response.row_total.toString();
					if(from == 2){
						$("cart"+id[1]).innerHTML = row_total;
						$("cartrecap"+id[1]).innerHTML = row_total;
					}
					else if(from == 3){
						$("cartlivrecap"+id[1]).innerHTML = row_total;
					}
					
					var base_grand_total = response.base_grand_total.toString();
					if(from == 2){
	        			$("resamag_basegrandtotal").innerHTML = base_grand_total;
	        			$("recapmag_basegrandtotal").innerHTML = base_grand_total;
        			}
        			else if(from == 3){
        				$("recapliv_basegrandtotal").innerHTML = base_grand_total;
        			}
					
					var grand_total = response.grand_total.toString();
					if(from == 2){
        				$("resamag_grandtotal").innerHTML = grand_total;
        				$("recapmag_grandtotal").innerHTML = grand_total;
        			}
        			else if(from == 3){
        				$("recapliv_grandtotal").innerHTML = grand_total;
    					$("price_cb").innerHTML = grand_total;
        			}
					
					
//					var row_total = response.row_total.toString();
//					var array_row_total = row_total.split('.');
//					if(!array_row_total[1]) array_row_total[1] = '00';
//					if(array_row_total[1].length == 1) array_row_total[1] = array_row_total[1] + '0';
//					if(from == 2){
//						$("cart"+id[1]).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//						$("cartrecap"+id[1]).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//					}
//					else if(from == 3){
//						$("cartlivrecap"+id[1]).innerHTML = array_row_total[0]+'<sup>€'+array_row_total[1]+'</sup>';
//					}
//        			var base_grand_total = response.base_grand_total.toString();
//        			var array_base_grand_total = base_grand_total.split('.');
//        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//        			if(array_base_grand_total[1].length == 1) array_base_grand_total[1] = array_base_grand_total[1]+'0';
//        			if(from == 2){
//	        			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//	        			$("recapmag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//        			}
//        			else if(from == 3){
//        				$("recapliv_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//        			}
//        			var grand_total = response.grand_total.toString();
//        			var array_grand_total = grand_total.split('.');
//        			if(!array_grand_total[1]) array_grand_total[1] = '00';
//        			///if(array_grand_total[1].length = 1) array_grand_total[1] = array_grand_total[1]+'0';
//        			if(from == 2){
//        				$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//        				$("recapmag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//        			}
//        			else if(from == 3){
//        				$("recapliv_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//        			}
//        			$(divtext).removeAttribute("readonly");
//        			$(divtext).value = item_qty;
//        			$(divtext).setAttribute("readonly", "readonly");
				},
				on404: function(t) {
    	        	alert(t.responseText);
    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
    	    	},
    	    	onComplete:function(t) {
    	       		$('reviewrecap-wait_changing_warranties').style.display = "none";
    	    	},
    	    	onFailure: function(t) {
    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
    	    	},
    	    	onLoading: function(t) {
    	       		$('reviewrecap-wait_changing_warranties').style.display = "";
    	    	}  
			}
//			var ajaxreq = new Ajax.Request(urlcheck, opt);
		
			// On envoi la requete
			if(etat == 'unckeck'){
				var ajaxreq = new Ajax.Request(urlcheck, opt);
			}else{
				var ajaxreq = new Ajax.Request(urluncheck, opt);
			}
			
//	}
//	else{
//		
//			var tab_param = new Array();
//			tab_param['item_id'] = id[1];
//			tab_param['ajax'] = true;
//			var opt = 
//			{	
//	             	method:'post',
//	             	parameters:tab_param,
//	                onSuccess:function(t)
//	            	{
//						var response = eval('(' + t.responseText + ')');
//						if(from == 2){
//		        			$("cart"+id[1]).innerHTML = "0<sup>€00</sup>";
//		        			$("cartrecap"+id[1]).innerHTML = "0<sup>€00</sup>";
//						}
//						else if(from == 3){
//							$("cartlivrecap"+id[1]).innerHTML = "0<sup>€00</sup>";
//						}
//	        			var base_grand_total = response.base_grand_total.toString();
//	        			var array_base_grand_total = base_grand_total.split('.');
//	        			if(!array_base_grand_total[1]) array_base_grand_total[1] = '00';
//	        			if(array_base_grand_total[1].length == 1) array_base_grand_total[1] = array_base_grand_total[1]+'0';
//	        			if(from == 2){
//		        			$("resamag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//		        			$("recapmag_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//	        			}
//	        			else if(from == 3){
//	        				$("recapliv_basegrandtotal").innerHTML = array_base_grand_total[0]+"<sup>€"+array_base_grand_total[1]+"</sup>";
//	        			}
//	        			var grand_total = response.grand_total.toString();
//	        			var array_grand_total = grand_total.split('.');
//	        			if(!array_grand_total[1]) array_grand_total[1] = '00';
//	        			//if(array_grand_total[1].length = 1) array_grand_total[1] = array_grand_total[1]+'0';
//	        			if(from == 2){
//		        			$("resamag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//		        			$("recapmag_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//	        			}
//	        			else if(from == 3){
//	        				$("recapliv_grandtotal").innerHTML = array_grand_total[0]+"<sup>€"+array_grand_total[1]+"</sup>";
//	        			}
//	        			$(divtext).removeAttribute("readonly");
//	        			$(divtext).value = "0";
//	        			$(divtext).setAttribute("readonly", "readonly");
//	    	        },
//	                on404: function(t) {
//	    	        	alert(t.responseText);
//	    	        	alert('3: Error 404: location "' + t.statusText + '" was not found.');
//	    	    	},
//	    	    	onComplete:function(t) {
//	    	       		$('reviewrecap-wait_changing_warranties').style.display = "none";
//	    	    	},
//	    	    	onFailure: function(t) {
//	    	      	 	alert('4: Error ' + t.status + ' -- ' + t.statusText);
//	    	    	},
//	    	    	onLoading: function(t) {
//	    	       		$('reviewrecap-wait_changing_warranties').style.display = "";
//	    	    	}  
//			}
//			var ajaxreq = new Ajax.Request(urluncheck, opt);
//		}
}
/*
function popUpMenu(element,trigger) {
        var iDelay = 2000;
        var new_popup = 0;
        var sTempId = 'popUped';
        if (document.getElementById(sTempId)) {
            var eTemp = document.getElementById(sTempId);
            $(sTempId).previous(0).down('.switcher').removeClassName('list-opened');
            new Effect.Fade (eTemp, { duration:0.3 });
            eTemp.id = sNativeId;
            clearTimeout(tId);
            document.onclick = null;
        }

        sNativeId = 'popId-'+$(element).up(1).id;
        var el = $(sNativeId);
        el.id = sTempId;

        if (eTemp && el == eTemp) {
            hideElement();
        } else {
            $(element).addClassName('list-opened');
            $(sTempId).getOffsetParent().style.zIndex = 994;
            new Effect.Appear (el, { duration:0.3 });
            tId=setTimeout("hideElement()",2*iDelay);
        }
        new_popup = 1;
        document.onclick = function() {
            if (!new_popup) {
                hideElement();
                document.onclick = null;
            }
            new_popup = 0;
        }

        el.onmouseout = function() {
            if ($(sTempId)) {
                $(sTempId).addClassName('faded');
                tId=setTimeout("hideElement()",iDelay);
            }
        }

        el.onmouseover = function() {
            if ($(sTempId)) {
                $(sTempId).removeClassName('faded');
                clearTimeout(tId);
            }
        }

        hideElement = function() {
            //el.hide();
            new Effect.Fade (el, { duration:0.3 });
            $(element).removeClassName('list-opened');
            el.getOffsetParent().style.zIndex = 1;
            el.id = sNativeId;
            if (tId) {clearTimeout(tId);}
        }
} */


function gcookie(Name)
{
	  var search = Name + "="
	  var returnvalue = "";
	  if (document.cookie.length > 0) {
	    offset = document.cookie.indexOf(search)
	    // if cookie exists
	    if (offset != -1) { 
	      offset += search.length
	      // set index of beginning of value
	      end = document.cookie.indexOf(";", offset);
	      // set index of end of cookie value
	      if (end == -1) end = document.cookie.length;
	      returnvalue=unescape(document.cookie.substring(offset, end))
	      }
	   }
	  return returnvalue;

}


