/******************************************************************************
* ixlufFonctions.js 
******************************************************************************/


function inputFocus(inputValue, inputId){
	if(inputValue == "Recherchez" && inputId == "fulltextField"){
		document.getElementById(inputId).value="";
	}else if(inputValue == "" && inputId == "fulltextField"){
		document.getElementById(inputId).value="Recherchez";
	}
}

ixLufMenuPrincipalHover=function() {
	Event.observe('nav1', 'mouseover', function(event) {
		var element = Event.element(event);
		if (('A' == element.tagName) && ('selected' != element.className)) {
			element.setStyle(
				'color:#5B8A9B;background:transparent url(iso_icons/ixLuf_bgMenuOnRight.png) right 0% no-repeat;'
			)
			if (('LI' == element.up().tagName) && ('selected' != element.up().className)) {
				element.up().setStyle(
					'background:transparent url(iso_icons/ixLuf_bgMenuOnLeft.png) left 0% no-repeat;'
				)			
			}
		}
	});

	Event.observe('nav1', 'mouseout', function(event) {
	var element = Event.element(event);
		if (('A' == element.tagName) && ('selected' != element.className)) {
			element.setStyle(
				'color:#ffffff;background:none;'
			)
			if (('LI' == element.up().tagName) && ('selected' != element.up().className)) {
				element.up().setStyle(
					'background:none;'
				)				
			}
		}
	});
}
addLoadAction(ixLufMenuPrincipalHover);




ixLufBorderShopItems = function() {
	var nbColumns = 5;
	var allItems = $$('div.gshpCategoryListItem');
	
	for (i=0; i < allItems.length; i++) {
		
		/* ?? */
		if (i > (allItems.length - (allItems.length % nbColumns) - 1)) {
			$(allItems[i]).setStyle(
				'border-bottom:none;'
			);
		}

		/* ?? */
		if ((i + nbColumns + 1) % nbColumns == 0) {
			$(allItems[i]).setStyle(
				'border-right:none;'
			);
		}

		/* ?? */
		if ((allItems.length % nbColumns == 0) && (i >= allItems.length - 4)) {
			$(allItems[i]).setStyle(
				'border-bottom:none;'
			);
		}
	}
}
addLoadAction(ixLufBorderShopItems);


ixLufCollapseBasket=function() {
	if (document.getElementById("ixlufEncartHaut") != null) {
		Event.observe('ixlufBasketDown', 'click', function(event) {
			$("ixLufBasketItems").setStyle({
			  height: '210px'
			});
			
			$("ixLufBasket").setStyle({
			  height: 'auto'
			});	
			$("ixlufEncartHautMiddle").setStyle({
			  height: 'auto'
			});	
			$("ixlufBasketDown").setStyle({
			  display: 'none'
			});		
			$("ixlufBasketUp").setStyle({
			  display: 'block'
			});	
		});
		
		Event.observe('ixlufBasketUp', 'click', function(event) {
			$("ixLufBasketItems").setStyle({
			  height: 'auto'
			});
			$("ixLufBasket").setStyle({
			  height: '46px'
			});	
			$("ixlufEncartHautMiddle").setStyle({
			  height: '51px'
			});	
			$("ixlufBasketUp").setStyle({
			  display: 'none'
			});		
			$("ixlufBasketDown").setStyle({
			  display: 'block'
			});	
		});
	}
}
addLoadAction(ixLufCollapseBasket);



function ixLufRefCollapse(oid) {
	if (oid != null) {
		
		if ($("ixlufproductRef"+oid).getStyle('display') == 'none') {
			$("ixlufproductRef"+oid).setStyle({
			  display: 'block'
			});
			$("ixlufproductRefCollapse"+oid).innerHTML ="Masquer les références";
			$("ixlufproductRefCollapse"+oid).setStyle({
			  background:'transparent url(iso_icons/ixLuf_refMoins.png) 0 0 no-repeat'
			});			
			
		} else {
			$("ixlufproductRef"+oid).setStyle({
			  display: 'none'
			});		
			$("ixlufproductRefCollapse"+oid).innerHTML ="Voir les références";
			$("ixlufproductRefCollapse"+oid).setStyle({
			  background:'transparent url(iso_icons/ixLuf_refPlus.png) 0 0 no-repeat'
			});	
		}
	}
}


function nbProductManager(oid,byHowMuch,type) {
	var inputValue = Number(document.getElementById("gshpBasketQuantityInputId"+oid).value);
	var byHowMuchNum =  Number(byHowMuch);
    switch (type) {
        case 'more':
            inputValue = inputValue + byHowMuchNum;
            break;
        case 'less':
            if (inputValue > byHowMuchNum)
                inputValue = inputValue - byHowMuchNum;
            break;
        default:
            break;
    }
    document.getElementById("gshpBasketQuantityInputId"+oid).value = inputValue;
}


function verifyNb(oid,byHowMuch){
	var inputValue = Number(document.getElementById("gshpBasketQuantityInputId"+oid).value);
	var byHowMuchNum =  Number(byHowMuch);

	while(inputValue % byHowMuchNum != 0){
		inputValue++;
	}

	if(inputValue < byHowMuchNum)
		inputValue = byHowMuchNum;

	document.getElementById("gshpBasketQuantityInputId"+oid).value = inputValue;
}
