jQuery(document).ready(function(){

	// Implement indexOf method for arrays
	if (!Array.prototype.indexOf) {
		Array.prototype.indexOf = function (obj, fromIndex) {
			if (fromIndex == null) {
				fromIndex = 0;
			} else if (fromIndex < 0) {
				fromIndex = Math.max(0, this.length + fromIndex);
			}
			for (var i = fromIndex, j = this.length; i < j; i++) {
				if (this[i] === obj) return i;
			}
			return -1;
		};
	}

	compubase.init();
		
	var params = $.parseQuery();
	if (params.checked=="false") {
		jQuery("#direct_access_favoriSub").removeAttr("checked");
	}
	
	if (params.prod){
		jQuery(".search-type .tabs li").removeClass("current");
		jQuery(".search-type .keywords").hide();		
		var keyWord = "PRODUCTNAME";	
				
		if(params.prod=="category"){
			jQuery(".search-type .tabs li a[name='searchByCategoryProduct']").parent().addClass("current");
			jQuery(".search-type #search-type-1-categorie2").val("searchByCategoryProduct");
			$('.search-zone').hide();
			$('.search-zone-fake').show();
			keyWord = "NOMENCLATURE";
			href = jQuery(".search-type .tabs li a[name='searchByCategoryProduct']").attr("href");
			var idToShow = href.split("#")[1];			
			jQuery("#" + idToShow).show();				
			jQuery(".search-type form").submit();
		}else{
			jQuery(".search-type .tabs li a[name='searchByProduct']").parent().addClass("current");
			jQuery(".search-type #search-type-1-categorie2").val("searchByProduct");
			href = jQuery(".search-type .tabs li a[name='searchByProduct']").attr("href");
			var idToShow = href.split("#")[1];
						
			if(params.prod=="keyword"){
				keyWord = "PRODUCTKEYWORD";
				jQuery(".search-type #" + idToShow +" a").removeClass("current");
				jQuery(".search-type .keywords a[name='PRODUCTKEYWORD']").addClass("current");
			}	
			jQuery("#" + idToShow).show();
		}				
		jQuery(".search-type #search-type-1-categorie").val(keyWord);	
	}
	
	//reset preffiled form field  by browser
	if(typeof jQuery(".ident-check-form  .password").val() != "undefined")
		jQuery(".ident-check-form .password").val("freee");
	
	if(typeof jQuery(".ident-check-form  .email-confirm").val() != "undefined")
		jQuery(".ident-check-form .email-confirm").val("");
	if(typeof jQuery(".ident-check-form  .password-confirm").val() != "undefined")
		jQuery(".ident-check-form .password-confirm").val("");
	
	if(typeof jQuery(".search-type #search-type-1-categorie2").val() != "undefined"){
		if(jQuery(".search-type #search-type-1-categorie2").val() == "searchByMap"){
			jQuery("#search-type-1 .search-zone").hide();
			jQuery("#search-type-1 .search-zone-map").show();
		}
	}	
});

jQuery(window).load(function() {
	compubase.datasheet.fixImageValign();
	//compubase.datasheet.hideCaProd();
	compubase.datasheet.handleCharts();
	$('#result-search-prmaison #load_').hide();
	compubase.datasheet.showDefaultTabs();
	compubase.datasheet.scrollToTab();
});

var errorsValue = 0;

var compubase = {
	init: function(){
		compubase.topMenu.init();
		compubase.loginBox.init(); // Scenario 1
		compubase.infosPersos.init(); // Scenario 1
		compubase.search.init(); // Scenario 2
		compubase.resultSearch.init(); // Scenario 3
		compubase.leftMenu.init(); // Left Menu
		compubase.datasheet.init(); // Scenario 4
		compubase.identification.init(); // Scenario 7
		compubase.activitiesFilter.init();
		compubase.common();
		compubase.infoRequester.init(); // Scenario 8
		compubase.aFiche.init(); // Scenario 7c
		compubase.studies.init() // Scenario 10
		compubase.zoomImages.init();
	},
	topMenu: {
		init: function () {
			this.handleMenu();
			this.handleVousEtesMenu();
			this.hintTopMenu();
		},
		hintTopMenu: function(){
			var timer = null;
						
			//jQuery(".topmenu-item #annuarylink, .topmenu-item  #easystocklink, .topmenu-item  #expolink, .topmenu-item  #bizrsslink, .topmenu-item1 #advertising,#logolink").hover(function(){
			jQuery(".topmenu-item a, .topmenu-item1 #advertising,#logolink").hover(function(){
				var info = jQuery(this).attr("name");				
				var currentId = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble2("#"+currentId, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		},

		handleMenu: function() {
			$('.topmenu-item').hover(
				function () {
					$('.topmenu-sub .b-c',this).css("width",Math.floor($('.topmenu-sub',this).outerWidth()-20)+"px");
					$(this).addClass("on");
				},
				function() {
					$(this).removeClass("on");
				}
			).click(function() {
				if ($('a',this).length) {
					location.href = $('a',this).attr("href");
				}
			});
		},
		handleVousEtesMenu: function() {
			$('.vousetes-tab').hover(
				function () {
					if (!$(this).hasClass("on")) { $(this).addClass("act"); }
				},
				function () {
					$(this).removeClass("act");
				}
			).click(function() {
				$(this).parent().children().removeClass("on");
				$(this).removeClass("act").addClass("on");

				$('#vousetes-tab-'+$('a',this).attr("rel")).parent().children().hide();
				$('#vousetes-tab-'+$('a',this).attr("rel")).show();
			});

			$('.vousetes-button').hover(
				function () {
					$(this).addClass("on");
				},
				function() {
					$(this).removeClass("on");
				}
			).click(function() {
				if ($('a',this).attr("href")) { location.href = $('a',this).attr("href"); }
			});
		}
	},
	loginBox: {
		currentLanguage: "",
		currentCountry: "",
		init: function(){
			this.handleLanguage();
			this.handleButton();
			this.handleReset();
			this.handleReset2();
			this.handleClose();
			//this.handleEnter();
			this.handleEnterForIE();
			this.hintSub();
			this.hintFavori();
			errors.loginBox("#zone-login-form form");
			
			if(jQuery(".zone-login-error").size() > 0){
				jQuery("#zone-login #button").click();
				jQuery("#zone-login.zone-login-error .content .case-error").show();
				jQuery("#zone-login.zone-login-error .content .case-open").hide();
			}
		},
		handleLanguage: function(){
			language = navigator.browserLanguage ? navigator.browserLanguage : navigator.language;
			jQuery("#language option[value='" + language + "'], #country option[value='" + language + "']").attr("selected", "selected");
			this.currentLanguage = jQuery("#zone-login-form #language :selected").val();
			this.currentCountry = jQuery("#zone-login-form #country :selected").val();
		},
		handleButton: function(){
			jQuery("#zone-login-form form, #zone-login-form .links, #zone-login .icons, #zone-login-form .submit").css({ opacity: 0 });
			jQuery(".zone-login-logged .icons").css({ opacity: 1 });
			
			jQuery("#zone-login #button").click(function(){
				tools.stateArrow(this);
				jQuery("#zone-login .content .case-close").hide();
				jQuery("#zone-login .content .case-open").fadeIn(1000);
				jQuery("#zone-login-form").animate({ height: "toggle" }, function(){
					jQuery("#zone-login-form form, #zone-login-form .links, #zone-login .icons, #zone-login-form .submit").animate({ opacity: 1 });
					jQuery(".zone-login-logged .icons").css({ opacity: 1 });
				});
								
				 if (jQuery("#search-type-3").is(":hidden"))
					 jQuery("#search-type-3").show();
				 else
					 jQuery("#search-type-3").hide();
				 
				return false;
			});
			
			var params = $.parseQuery();
			if (params.demo) {
				if(params.demo=="true"){
					jQuery("#zone-login .content .case-close").hide();
					jQuery("#zone-login .content .case-open").fadeIn(1000);
					jQuery("#zone-login-form").animate({ height: "toggle" }, function(){
						jQuery("#zone-login-form form, #zone-login-form .links, #zone-login .icons, #zone-login-form .submit").animate({ opacity: 1 });
						jQuery(".zone-login-logged .icons").css({ opacity: 1 });
					});
				}
			}
			
			jQuery(".cpb_not_implemented_functionnality").click(function(){
				var title 	= jQuery("#cpb_biz_popup_alert_info_title").html();
				var info 	= jQuery("#cpb_biz_functionnality_not_implemented_info").html();
				jAlert(info, title);
				return false;
			});
		},
		handleReset: function(){
			current = this;
			jQuery("#reset").click(function(){
				jQuery("#zone-login .content .case-error").hide();
				jQuery("#zone-login .content .case-open").show();
				jQuery("#zone-login").removeClass("zone-login-error");
				jQuery(".swap-value").toggleVal();
				//jQuery("#zone-login-form input[type='text']").val("").blur();
				jQuery("#zone-login-form #language option[value='" + current.currentLanguage + "']").attr("selected", "selected");
				jQuery("#zone-login-form #country option[value='" + current.currentCountry + "']").attr("selected", "selected");
				errors.resetError("#zone-login-form");
				jQuery("#email").val("Votre email");
				jQuery("#password").val("Votre Mot de passe");
				jQuery("#zone-login-form input[type='text']").val("").blur();
				return false;
			});
		},
		handleReset2: function(){
			current = this;
			jQuery("#reset2").click(function(){
				jQuery("#zone-login .content .case-error").show();
				jQuery("#zone-login .content .case-open").hide();
				//jQuery("#zone-login").addClass("zone-login-error");				
				jQuery(".swap-value").toggleVal();				
				errors.resetError("#zone-login-form");
				jQuery("#email").val("Votre email");
				jQuery("#infolostpsswd").show();
				jQuery("#zone-login-form input[type='text']").val("").blur();
				return false;
			});
		},
		handleClose: function(){
			jQuery("#close").click(function(){
				jQuery("#reset").click();
				jQuery("#zone-login .content .case-open, #zone-login .content .case-error").hide();
				jQuery("#zone-login .content .case-close").fadeIn(1000);
				jQuery("#zone-login-form .links, #zone-login .icons, #zone-login-form .submit").animate({ opacity: 0 });
				jQuery(".zone-login-logged .icons").css({ opacity: 1 });
				jQuery("#zone-login-form form").animate({ opacity: 0 }, function(){
					jQuery("#zone-login-form").animate({ height: "toggle" });
					jQuery("#zone-login").removeClass("zone-login-error");
				});
				
				return false;
			});
		},
		handleEnter: function(){
			if(jQuery("#zone-login #password").size() > 0){
				jQuery("#zone-login #email").keydown(function(e){
					if(e.keyCode == 13){
						jQuery("#password").focus();
						return false;
					}
				});
			}
		},
		handleEnterForIE: function(){
			jQuery("#password").keydown(function(e){
				if(navigator.appName == "Microsoft Internet Explorer") 
					if(e.keyCode == 13){
						jQuery("#loginform").submit();												
					}
			});
		},
		hintSub: function(){
			var timer = null;
			var desc = $('#descSub').text();
			jQuery(".info_bulle").hover(function(){
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(desc);
					tools.fixPosBubble(".info_bulle", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		},
		hintFavori: function(){
			var timer = null;
			var info = "Cliquez sur l'\u00E9toile pour faire de cet abonnement votre abonnement favori";
			jQuery(".star").hover(function(){
				var idStar = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble("#"+idStar, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		}
	},
	infosPersos: {
		init: function(){
			this.handleBoxes();
		},
		handleBoxes: function(){
			jQuery("#close-infos-persos-1").click(function(){
				tools.stateArrow(this);
				
				jQuery("#block-infos-1 .block-links").animate({ opacity: "toggle" });
				jQuery("#block-infos-1").animate({ height: "toggle" });
				
				return false;
			});
			
			jQuery("#close-infos-persos-2").click(function(){
				tools.stateArrow(this);
				
				if(jQuery("#block-infos-2 form").is(":visible")) jQuery("#block-infos-2 form").css({ visibility: "hidden" });
				
				if(jQuery("#block-infos-2").is(":visible")){
					jQuery("#block-infos-2").animate({ height: "toggle" });
				} else {
					jQuery("#block-infos-2").animate({ height: "toggle" }, function(){
						jQuery("#block-infos-2 form").css({ visibility: "visible" });
					});
				}
				
				return false;
			});
			
			jQuery("#close-infos-persos-all").click(function(){
				tools.stateArrow(this);
				
				jQuery("#block-infos-1 .block-links").animate({ opacity: "toggle" });
				jQuery("#block-infos-1").animate({ height: "toggle" });
				
				if(jQuery("#block-infos-2 form").is(":visible")) 
					jQuery("#block-infos-2 form").css({ visibility: "hidden" });
					
				if(jQuery("#block-infos-2").is(":visible")){
					jQuery("#block-infos-2").animate({ height: "toggle" });
				} else {
					jQuery("#block-infos-2").animate({ height: "toggle" }, function(){
						jQuery("#block-infos-2 form").css({ visibility: "visible" });
					});
				}
				
				return false;
			});
			
			jQuery("#direct_access_favoriSub").click(function(){				
				var val =jQuery("#direct_access_favoriSub").attr("checked");					
				var action = action ="/ict/updateDirectAccess.do?checked="+val;				
				$("#formSub").attr("action",action); 
				jQuery("#formSub").submit();				
				$('html, body').animate({scrollTop: $('#fullStar').offset().top-7}, 1000);
			});	
			
			jQuery(".go").click(function (e) {
				e.preventDefault();
				var info = jQuery(this).attr("name");
				var sub = jQuery(this).attr("title");
				info = info.replace("{0}", sub);
				var url = jQuery(this).attr("href");
				confirm(info, function () {
					window.location.href = url;
				});
			});
		}
	},
	search: {
		init: function(){
			this.keywords();
			this.tabs();
			this.fakeSelect();
			this.dropBox();
			this.searchRight();
			errors.search(".search-type form");
			this.hints();
			this.breadcrumbs();
			this.validFormKeyWords();
			this.validHomeForm();
			this.otherSearchType();
	},
	defaultValue: null,

		validFormKeyWords: function(){
			var message = jQuery("#htmlKeyError").html();
			if(message!=null && message!=""){
				jQuery("#msg-error p").html(message);
				current.showError(".search-type .input-text");
				tools.fixPosBubble(".search-type .input-text", "#msg-error");
				jQuery("#htmlKeyError").html("");
			}
		},
		validHomeForm: function(){
			var message = jQuery("#htmlHomeError").html();
			var error = jQuery(".case-error .show").html();
			if(message!=null && message!="" && message!="null" ){
				if(error==null){
					jQuery("#msg-error p").html(message);
					current.showError(".block-vouscherchez .text");
					tools.fixPosBubble2(".block-vouscherchez #search-type-4-input", "#msg-error");
					jQuery("#htmlHomeError").html("");
			
				}
			}
		},
		breadcrumbs: function(){
			var currentCategory = jQuery(".search-type .tabs li.current a").html();
			if(currentCategory !=null){			
				jQuery("#breadCrumbSearchCategory").html(currentCategory) ;
			}
		},
		keywords: function(){
			jQuery(".search-type .keywords a").click(function(){
				if(jQuery(this).hasClass(".inactif")) return false;
				
				jQuery(".search-type .keywords a").removeClass("current");
				
				jQuery(".search-type #search-type-1-categorie").val(jQuery(this).attr("name"));
				jQuery(this).addClass("current");
				if(this.id != "AREA")				
					jQuery(".search-type form").submit();
				
				return false;
			});			
			
		},
		otherSearchType: function(){
			jQuery("#no-results li a").click(function(){
				if(jQuery(this).hasClass(".inactif")) return false;				
				jQuery(".search-type #search-type-1-categorie").val(jQuery(this).attr("rel"));
				jQuery(".search-type #search-type-1-categorie2").val(jQuery(this).attr("name"));				
				jQuery(".search-type form").submit();
				
				return false;
			});
		},
		tabs: function(){
			var current = jQuery(".search-type .tabs li.current:eq(0)");
			var actionScroll = true;
			if( jQuery(current).size() > 0 ){
				errorsValueTmp = jQuery("a", current).attr("rel");
				errorsValue = errorsValueTmp.split("errorsValue")[1];
			}
			
			var index = jQuery(".search-type .tabs li").index(current);
			
			if( jQuery(".search-type .tabs").width() > 406 ){
				jQuery(".search-type .tabs").jcarousel({
					scroll: 1,
					initCallback: function(carousel){
					jQuery("#tabs-categories a, .search-type li a").bind("click", function() {
						var rel = jQuery(this).attr("rel");
						var totalLi = jQuery(".search-type .tabs li").size();
						var index = jQuery(".search-type .tabs li").index( jQuery(".search-type .tabs a[rel='" + rel + "']").parent("li") );
						
						if(actionScroll == false && index < 2){
							carousel.prev();
							actionScroll = true;
						}
						
						if(actionScroll){
							if(index != -1) carousel.scroll(jQuery.jcarousel.intval(index));
							
							if(index+1 == totalLi){
								setTimeout(function(){
									carousel.next();
								}, 500);
							}
						}
						
						return false;
					});
				},
				buttonNextCallback: function(carousel, button, enabled){
					actionScroll = enabled ? true : false;
				}
			});
		}
			
			jQuery(".search-type .jcarousel-prev").mouseover(function(){
				width = jQuery("#tabs-categories").width();
				jQuery("#tabs-categories").css({ left: "-" + (width-10) + "px" });
			});
			
			jQuery(".search-type .jcarousel-next").mouseover(function(){
				jQuery("#tabs-categories").css({ left: "485px" });
			});
			
			jQuery(".search-type .jcarousel-prev, .search-type .jcarousel-next, #tabs-categories").hover(function(){
				jQuery("#tabs-categories").show();
			}, function(){
				jQuery("#tabs-categories").hide();
			});
			
			/*jQuery(".search-type .jcarousel-next").click(function(){
				jQuery("#search-type-1 .jcarousel-clip").css({ marginLeft: 45 + "px", width: 406 + "px" });
			});*/
			
			jQuery(".search-type .tabs li a, #tabs-categories a").click(function(){
				if(jQuery(this).parent().hasClass(".inactif")) return false;
				
				jQuery("#msg-error, #msg-hints, #drop-box").hide();
				errors.resetError(".search-type form");
											
				href = jQuery(this).attr("href");
				var idToShow = href.split("#")[1];
				jQuery(".search-type .keywords").hide();
				jQuery("#" + idToShow).show();				
				var keyWord =jQuery("#" + idToShow ).children(".current").attr("name");
				jQuery(".search-type #search-type-1-categorie").val(keyWord);				
				errorsValueTmp = jQuery(this).attr("rel");
				errorsValue = errorsValueTmp.split("errorsValue")[1];
				
				jQuery(".search-type .tabs li").removeClass("current");
				jQuery(".search-type .tabs li a[rel='" + errorsValueTmp + "']").parent().addClass("current");
				jQuery(".search-type #search-type-1-categorie2").val(jQuery(this).attr("name"));
				jQuery(".search-type #search-type-1-searchTypeCode").val(jQuery(this).attr("id"));
				jQuery(".search-type #search-type-1-nodecodeField").val("");
				
				jQuery(".nomenclature-results").hide();
				compubase.activitiesFilter.tabActive = 0;
										
				if(jQuery(this).attr("name")!="searchByMap"){
					$('.search-zone').show();
					$('.search-zone-fake').hide();
					jQuery("#result-search").hide();
					jQuery("#search-type-1 .search-zone-map").hide();
					jQuery(".search-type form").submit();	
				}else{
					$('.search-zone').hide();
				}
						
				return false;
			});
			
			jQuery(".search-type #MAP, .search-type #AREA").click(function(){				
				geoOpen("http://online.compubase.net/cpbol/img/","frmDept","val",false);
				pos = {
					x: $(this).offset().left+Math.floor($(this).innerWidth()/2),
					y: $(this).offset().top-$('#geography-popup').innerWidth()+180
				}
				$('#geography-popup').css({top:pos.y+"px",left:pos.x+"px"}).show();
			});
			
			jQuery("#geography-popup .icon-close").click(function(){				
				jQuery("#geography-popup").hide();
				return false;
			});
			
			jQuery("#geography-popup .reloadLink").click(function(){
				$('#geography-popup').hide();
				geoOpen("http://online.compubase.net/cpbol/img/","frmDept","val",false);
				$('#geography-popup').show();
			});
			
			jQuery(".block-vouscherchez #cross-button").click(function(){
				jQuery(".block-vouscherchez input.text").val("");
			});
			jQuery(".block-vouscherchez #cross-button").mouseover(function(){
				jQuery(this).removeClass("crossButton");
				jQuery(this).addClass("crossButtonwWthRedBorder");
			});
			jQuery(".block-vouscherchez #cross-button").mouseleave(function(){
				jQuery(this).removeClass("crossButtonwWthRedBorder");
				jQuery(this).addClass("crossButton");
			});
		},
		fakeSelect: function(){
			var current = jQuery(".search-type #categories li.current:eq(0)");
			
			if( jQuery(current).size() > 0 ){
				errorsValueTmp = jQuery("a", current).attr("rel");
				errorsValue = errorsValueTmp.split("errorsValue")[1];
			}
			
			jQuery(".search-type .fake-select").click(function(){
				jQuery("#categories").toggle();
				
				return false;
			});
			
			jQuery("#categories").hover(function(){
				jQuery(this).show();
			},function(){
				jQuery(this).hide();
			});
			
			jQuery("#categories ul a").click(function(){
				errorsValueTmp = jQuery(this).attr("rel");
				errorsValue = errorsValueTmp.split("errorsValue")[1];
				
				jQuery("#msg-error, #msg-hints, #drop-box").hide();
				errors.resetError(".search-type form");
				
				var val = jQuery(this).html();
				var val2 = jQuery(this).attr("name");
				
				jQuery(".search-type .fake-select span").html(val);
				jQuery("#search-type-1-categorie").val(val2);
				jQuery("#categories").hide();
				
				return false;
			});
		},
		dropBox: function(){
			if(jQuery("#drop-box").size() < 1) return false;
			
			var height = jQuery(".search-type form").outerHeight();
			var posLeft = jQuery(".search-type .input-text").offset();
			var widthInput = jQuery(".search-type .input-text").innerWidth()-27;
			var posLeft = Math.round(jQuery(".search-type .input-text")[0].offsetLeft);
			jQuery("#drop-box").css({ top: height + "px", left: posLeft + "px", width: widthInput + "px" });
			
			jQuery("#drop-box").hover(function(){
				jQuery(this).show();
			}, function(){
				jQuery(this).hide();
			});
			
			jQuery("#drop-box a").click(function(){
				jQuery("#msg-error, #msg-hints, #drop-box").hide();
				errors.resetError(".search-type form");
				
				var val1 = jQuery(this).parent().children(".left").children("strong").html();
				var val2 = jQuery(this).parent().children(".left").attr("name");
				var val3 = jQuery(this).parent().children(".right").attr("name");
				
				jQuery(".search-type .input-text").val(val1);
				jQuery("#search-type-1-categorie").val(val2);
				jQuery("#search-type-1-categorie2").val(val3);
				jQuery("#drop-box").hide();
				jQuery(".search-type form").submit();
				
				return false;
			});
			
						
			jQuery(".search-type #infos-history").click(function(){
				if(jQuery("#drop-box").is(":visible")) 
					jQuery("#drop-box").hide();
				else
					jQuery("#drop-box").show();
			});
						
			/*var timer = null;			
			jQuery(".search-type .input-text").hover(function(){
				timer = setTimeout(function(){
					jQuery("#drop-box").show();
				}, 3000);
			}, function(){
				clearTimeout(timer);
			});*/
		},
		searchRight: function(){
			var current = jQuery(".search-type #categories-right li.current:eq(0)");
			
			if( jQuery(current).size() > 0 ){
				errorsValueTmp = jQuery("a", current).attr("rel");
				errorsValue = errorsValueTmp.split("errorsValue")[1];
			}
			
			jQuery("#search-type-3 label").click(function(){
				jQuery("#categories-right").show();
				
				return false;
			});
			
			jQuery("#categories-right").hover(function(){
				jQuery(this).show();
			},function(){
				jQuery(this).hide();
			});
			
			jQuery("#categories-right ul a").click(function(){
				errorsValueTmp = jQuery(this).attr("rel");
				errorsValue = errorsValueTmp.split("errorsValue")[1];
				
				jQuery("#msg-error, #msg-hints, #drop-box").hide();
				errors.resetError(".search-type form");
				
				var val = jQuery(this).html();
				var val2 = jQuery(this).attr("name");
				
				jQuery("#search-type-3-input").val(val);
				jQuery("#search-type-3-categorie").val(val2);
				jQuery("#categories-right").hide();
				
				jQuery(".swap-value").toggleVal();
				
				compubase.search.defaultValue = jQuery("#search-type-3-input").val();
				return false;
			});
		},
		hints: function(){
			var timer = null;
			
			jQuery(".search-type .input-text").hover(function(){
				if(jQuery(".search-type .input-text").val().length==0){
					if( jQuery("#errorsValue" + errorsValue).size() > 0 ){
						timer = setTimeout(function(){
							jQuery("#msg-hints p").html( jQuery("#errorsValue" + errorsValue).html() );
							tools.fixPosBubble(".search-type .input-text", "#msg-hints");
							jQuery("#msg-hints").show();
							jQuery("#msg-error").hide();
						}, 2000);
					}
				}
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		}
	},
	resultSearch: {
		init: function(){
			this.grid();
			this.handleViews();
			this.filters();
			this.hintSearchResultTools();
		},
		grid: function(){
			jQuery(".nb-pages select").change(function(){
				jQuery("#result-search table").setGridParam({rowNum:jQuery(this).val()}).trigger("reloadGrid");
			});
		},
		gridCallback: function(){			
			var pageSize = jQuery(".nb-pages select").val();
			if(typeof pageSize != "undefined")
				jQuery("#result-search table").setGridParam({rowNum:pageSize});
			
			var nbCompany = jQuery("#nbrecords").html();
			if(nbCompany!=null){
				jQuery("#nbFoundResult").html(nbCompany);
			}else{
				jQuery("#nbFoundResult").html("0");
			}
			table = jQuery("#table-results .grid_bdiv table:eq(0)");
			colspan = jQuery("tr:eq(0) td", table).size();
			
			jQuery("#table-results .grid_hdiv table:eq(0) th:eq(0)").addClass("first");
			
			jQuery("tr", table).each(function(){
				if( jQuery(this).parents(".popupGroupe").size() == 0 ){
					alt = jQuery(this).hasClass("alt") ? " class='minificheContainer alt'" : " class='minificheContainer'";
					jQuery(this).after("<tr" + alt + "><td colspan='" + colspan + "'></td></tr>");
					newMiniFiche = jQuery(".minifiche", this).clone().appendTo( jQuery(this).next("tr").children("td") );
					jQuery(".minifiche", this).remove();
					jQuery(".close-minifiche", newMiniFiche).click(function(){
						jQuery(this).parents(".minifiche").hide();
						jQuery(this).parents(".minifiche").next(".popupGroupe").hide();
						jQuery(this).parents("tr").prev("tr").show();

						jQuery(".grid_hdiv").show();
						
						return false;
					});
					
					newPopupGroupe = jQuery(".popupGroupe", this).clone().appendTo( jQuery(this).next("tr").children("td") );
					jQuery(".popupGroupe", this).remove();
				}
			});
			
			jQuery("td", table).each(function(){
				if(jQuery(this).attr("title") != "") jQuery(this).attr("title", "");
			});
			
			jQuery("#table-results .openMinifiche").click(function(){
				jQuery(this).parents("tr").hide();
				//jQuery(this).parents("tr").next("tr.subgrid").remove();
				jQuery(this).parents("tr").children("td.sgexpanded").children("img").click();
				jQuery(this).parents("tr").nextAll("tr.minificheContainer:eq(0)").children("td").children(".minifiche").toggle();

				if (!$(".minifiche:hidden").length) { jQuery(".grid_hdiv").hide(); }
				
				return false;
			});
			
						
			jQuery("#table-results .linkGroupe").click(function(){
				var current = this;			
				jQuery(".popupGroupe").hide();
				popupToShow = jQuery(current).parents(".minifiche").next(".popupGroupe");
				
				var idGroup = this.id;
				var currentGroup = idGroup;
				var oldvalue = jQuery("#table-results #"+currentGroup).html();		
				$("#table-results #"+currentGroup).ajaxStart(function(){
					$("#table-results #"+currentGroup).html("<img src='img/group-loader.gif' />");
				});
				$(popupToShow).ajaxStop(function(){
					$("#table-results #"+idGroup).html(oldvalue);
				});
				
				jQuery(popupToShow).load(this.href, function(){
					currentGroup =0;
					heightPopup = jQuery(popupToShow).height();
					posContainer = jQuery("#table-results").offset();
					pos = jQuery(current).offset();
					jQuery(popupToShow).css({ left: (pos.left-posContainer.left) + "px", top: (pos.top-posContainer.top)-(heightPopup/2) + "px" }).show();
	
					jQuery("#table-results .close-popup").click(function(){
						jQuery(this).parent().hide();
						
						return false;
					});
					
					jQuery("#table-results .popupGroupe .block-top .locations a").click(function(){
						id = jQuery(this).attr("rel");
						if(id) jQuery("#" + id).click();
						
						return false;
					});
					
					jQuery("#table-results .popupGroupe li a.close").click(function(){
						jQuery(this).next("ul").toggle();
						jQuery(this).parents("li").get(0).className = jQuery(this).next("ul").is(":visible") ? "open" : "close";
						
						//var valSpan = jQuery("#table-results .popupGroupe .block-top .locations").children("a").next().html();
						//alert(valSpan);
						return false;
					});
					
										
					var data = jQuery("#table-results .popupGroupe .linkMore").get(0);
					jQuery.data(data, "styleDisplay", "block");
					
					/*var srcImg = jQuery("#popuplogo_"+idGroup).attr("src");
					jQuery("#groupLogo_"+idGroup).attr("src",srcImg);
					jQuery("#groupLogo_"+idGroup).attr("width",64);
					jQuery("#groupLogo_"+idGroup).attr("height",51);*/
					
					jQuery("#table-results .popupGroupe .linkMore").click(function(){												
						toDisplay = jQuery.data(this, "styleDisplay");										
						
						if(typeof toDisplay == "undefined") toDisplay = "block";
						
						current = jQuery(this).parent(".block-bottom").children("ul");
						jQuery("ul", current).each(function(){
							jQuery(this).css("display", toDisplay);
							
							jQuery(this).parents("li").get(0).className = jQuery(this).is(":visible") ? "open" : "close";
						});
						
						if(toDisplay == "none"){
							jQuery.data(this, "styleDisplay", "block");
							
							if( jQuery("img", this).attr("src").indexOf("icon-minus.gif") > -1 )
								jQuery("img", this).attr({ src: "img/icon-plus.gif" });
						} else {
							jQuery.data(this, "styleDisplay", "none");
							
							if( jQuery("img", this).attr("src").indexOf("icon-plus.gif") > -1 )
								jQuery("img", this).attr({ src: "img/icon-minus.gif" });
						}						
						return false;
					});
				});
				currentGroup = idGroup;
				return false;
			});
			
			jQuery("#table-results .iconGmap").click(function(){
				var idCpy = this.id.split("_")[1];				
				var link = jQuery("#"+this.id).attr('href');
				window.open( link);
				return false;
			});
				
			jQuery("#table-results .iconloop").hover(function(){
				var idIcone = this.id;
				var loopInfo = jQuery("#"+idIcone).attr("name")
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(loopInfo);
					tools.fixPosBubble3("#"+idIcone, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
			
			jQuery("#table-results .info_country").hover(function(){
				var idcpy = this.id;
				var countryLabel = jQuery("#"+idcpy).attr("name")
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(countryLabel);
					tools.fixPosBubble("#"+idcpy, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
			
			jQuery("#table-results .certification").hover(function(){
				var id_agreement = this.id;
				var info =jQuery(".hide #certificationInfo").html();
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble3("#table-results #"+id_agreement, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});		
			
			jQuery(".productdefaultimage").hover(function(){
				var ref = this.id;
				var info =jQuery(this).attr("name");
					timer = setTimeout(function(){
						jQuery("#msg-hints p").html(info);
						tools.fixPosBubble3("#"+ref, "#msg-hints");
						jQuery("#msg-hints").show();
						jQuery("#msg-error").hide();
					}, 1000);
				}, function(){
					clearTimeout(timer);
					jQuery("#msg-hints").hide();
				});		
			
			jQuery("#table-results .iconloop, #table-results .datasheetlink").click(function(e) { 
				e.preventDefault();
				e.stopPropagation();
				var url = jQuery(this).attr("href");
				$.blockUI({ css: { 
					border: 'none', 
					padding: '15px', 
					backgroundColor: '#000', 
					'-webkit-border-radius': '10px', 
					'-moz-border-radius': '10px', 
					opacity: .5, 
					color: '#fff' 
				} });  
				setTimeout($.unblockUI, 3000); 
				window.location.href = url;
			}); 
						
			jQuery("#table-results .subscriptionlock").hover(function(){
				var currentid=this.id;
				var info =jQuery(this).attr("alt");
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble6("#table-results #"+currentid, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});		
			
			jQuery("#table-results .close-minifiche .close-arrow").hover(function(){
				var currentid=this.id;
				var info =jQuery(this).attr("alt");				
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble2("#table-results #"+currentid, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});	
			
			jQuery("#table-results .product_activity_type").click(function(){
				var rel = jQuery(this).attr("rel");
				var nodecode =/activity_(.*)/.exec(rel)[1];
				jQuery(".search-type #search-type-1-nodecodeField").val(nodecode);
				jQuery(".search-type #search-type-1-categorie2").val("searchByCategoryProduct");
				jQuery(".search-type form").submit();
			});
			
			jQuery('img[src$=.png]').ifixpng();

			compubase.zoomImages.init();
		},
		handleViews: function(){
			jQuery(".tools-container a.views").click(function(){
				jQuery(".tools-container a.views").removeClass("on");
				jQuery(this).addClass("on");
				
				switch(jQuery(this).attr("name")){
					case "view1":
						jQuery("#table-results table").removeClass("table-view-2 table-view-3");
						jQuery("#table-results table").addClass("table-view-1");
						jQuery("#table-results .minifiche").hide();
						jQuery(".grid_hdiv").show();
						jQuery(".minificheContainer").prev().show();

						jQuery("#table-results .jqgrow span.strong").css("font-weight","normal");
						jQuery("#table-results .jqgrow .view2").hide();
											
						break;
					case "view2":
						jQuery("#table-results table").removeClass("table-view-1 table-view-3");
						jQuery("#table-results table").addClass("table-view-2");
						jQuery("#table-results .minifiche").hide();
						jQuery(".grid_hdiv").show();
						jQuery(".minificheContainer").prev().show();

						jQuery("#table-results .jqgrow span.strong").css("font-weight","bold");
						jQuery("#table-results .jqgrow .view2").show();
						break;
					case "view3":
						jQuery("#table-results table").removeClass("table-view-1 table-view-2");
						jQuery("#table-results table").addClass("table-view-3");
						jQuery("#table-results .minifiche").show();
						jQuery(".grid_hdiv").hide();
						jQuery(".minificheContainer").prev().not("#_empty").hide();
						break;
				}
				
				return false;
			});
		},
		filters: function(){
			jQuery(".linkHideTable").click(function(){
				jQuery("#table-results").toggle();
				
				if( jQuery(this).prev("a").children("img").size() > 0 ){
					if( jQuery(this).prev("a").children("img").attr("src").indexOf("arrow-bottom-1.png") > -1 )
						jQuery(this).prev("a").children("img").attr({ src: "img/arrow-right-1.png" });
					else
						jQuery(this).prev("a").children("img").attr({ src: "img/arrow-bottom-1.png" });
				} else {
					if( jQuery("img", this).attr("src").indexOf("arrow-bottom-1.png") > -1 )
						jQuery("img", this).attr({ src: "img/arrow-right-1.png" });
					else
						jQuery("img", this).attr({ src: "img/arrow-bottom-1.png" });
				}				
				return false;
			});
			
			$("#close-result-search-top").click(function(e){
				e.preventDefault();
				$("#list-filters").toggle();
				
				if ($("img", this).attr("src").indexOf("icon-close.gif") > -1 )
					$("img", this).attr({ src: "img/icon-close-b.gif" });
				else
					$("img", this).attr({ src: "img/icon-close.gif" });
				
				return false;
			});

			var sendHttpRequest = function() {
				var typeOfSearch = jQuery("#search-type-1-categorie2").val();
				
				if (typeof typeOfSearch == "undefined") {
					finalUrl = "jsp/compubase/search/Ajax/searchCompanyResult.jsp?filters=\"";
				}
				
				switch(typeOfSearch){
					case "searchByCompany":
					 finalUrl = "jsp/compubase/search/Ajax/searchCompanyResult.jsp?filters=\"";
					 break;
					case "searchByProduct":
					 finalUrl = "jsp/compubase/search/Ajax/searchProductResult.jsp?filters=\"";
					 break;
					case "searchByCategoryProduct":
						 finalUrl = "jsp/compubase/search/Ajax/searchProductCategoryResult.jsp?filters=\"";
						 break;
					case "searchByGeography":
						 finalUrl = "jsp/compubase/search/Ajax/searchGeographyResult.jsp?filters=\"";
						 break;
					case "searchByMap":
						 finalUrl = "jsp/compubase/search/Ajax/searchCompanyResult.jsp?filters=\"";
						 break;
					case "searchByProductResold":
						 finalUrl = "jsp/compubase/search/Ajax/searchProductResoldResult.jsp?filters=\"";
						 break;
					case "searchByMarkets":
						 finalUrl = "jsp/compubase/search/Ajax/searchMarketResult.jsp?filters=\"";
						 break;
					case "searchByTechnicalField":
						 finalUrl = "jsp/compubase/search/Ajax/searchTechnicalFieldResult.jsp?filters=\"";
						 break;
						 
				}		
				
				 $('#filters-all span[id^=filter-]').filter(":visible").not("[class*=inactive]").each(function() {
					 if (!$(this).children('.filterq').hasClass("inactive")) {
						 finalUrl += /filter-(.*)-.*/.exec($(this).attr("id"))[1]+"="+/filter-.*-(.*)/.exec($(this).attr("id"))[1]+";";
				 }
				});
				
				 finalUrl += "\"";
				 jQuery("#result-search table").setGridParam({url:finalUrl}).trigger("reloadGrid");
			 
			
			 } 
			
			$('#filters-all .delete').hover(
				function() {               
					jQuery("img", this).attr({ src: "img/icon-close3.gif" });
				},
				function() {
					jQuery("img", this).attr({ src: "img/icon-close3-i.gif" });
				}
			);

			$('#filters-popup a.icon-close').click(function(e) {
				e.preventDefault();
				$('#filters-popup').hide();
			});

			$('#filters-all .delete').click(function(e) {
				e.preventDefault();

				$(this).parent().hide();
				$('#filter-row-'+/filter-(.*)-.*/.exec($(this).parent().attr("id"))[1]+' a[rel='+/filter-.*-(.*)/.exec($(this).parent().attr("id"))[1]+']').parent().hide();

				$('#filter-row-'+/filter-(.*)-.*/.exec($(this).parent().attr("id"))[1]+' .enlarge').show();
				$('#filter-row-'+/filter-(.*)-.*/.exec($(this).parent().attr("id"))[1]+' .reduce').hide();

				if (!$('#filters-all .filterq').parent().filter(":visible").length) {
					$('#filters-all .nofilters').show();
				}
				sendHttpRequest(); 
			});

			//$('#filters-detailed a.filter').parent().hide();
			$('#filters-all span[id^=filter-]').hide();
			$('#filters-detailed div[id^=filter-row-]').hide();
			$('#filters-detailed a').each(function() {
				if ($(this).hasClass("default")) {
					$(this).parent().show();
					$(this).parents("[id^=filter-row-]").show();
				}
			});
			$('#filters-detailed div.default').show();
			$('#filters-all span.default').show();

			if ($('#filters-all .default').length) {
				$('#filters-all .nofilters').hide();
			}

			$('#filters-all a.filterq').click(function(e) {
				e.preventDefault();

				filter1 = /filter-(.*)-.*/.exec($(this).parents("[id^=filter-]").attr("id"))[1];
				filter2 = /filter-.*-(.*)/.exec($(this).parents("[id^=filter-]").attr("id"))[1];
				if (!$('#filter-row-'+filter1).hasClass("all-inactive")) {
					$(this).toggleClass("inactive");
					$('#filter-row-'+filter1+' a[rel='+filter2+']').toggleClass("inactive");

					// Send http request
					sendHttpRequest(); 
				}
			});
			$('#filters-detailed a.filter').click(function(e) {
				e.preventDefault();

				if (!$(this).parents('[id^=filter-row-]').hasClass("all-inactive")) {
					$(this).toggleClass("inactive");

					$('#filters-all #filter-'+/filter-.*-(.*)/.exec($(this).parents('[id^=filter-]').attr("id"))[1]+'-'+$(this).attr("rel")+' .filterq').toggleClass("inactive");

					// Send http request
					sendHttpRequest(); 
				}
			});

			$('#filters-detailed a[class*=modify]').click(function(e) {
				e.preventDefault();

				$('#filters-popup strong.filter-name').html($(this).parent().children(".name").html());
				html = "";
				children = $('#filters-data ul[title='+/filter-row-(.*)/.exec($(this).parents("[id^=filter-row-]").attr("id"))[1]+']').children();
				for (i=0;i<children.length;i++) {
					html += '<tr><td><input type="checkbox" name="'+children.eq(i).attr("title")+'"';
					if (!$('a.filter[rel='+children.eq(i).attr("title")+']').hasClass("inactive") && $('a.filter[rel='+children.eq(i).attr("title")+']').is(":visible")) { html += ' checked="checked"'; }
					html += '/></td><td>'+children.eq(i).html()+'</td></tr>';
				}
				$('#filters-popup .content table').html(html);
				$('#filters-popup a.filter-name').attr("rel",/filter-row-(.*)/.exec($(this).parents("[id^=filter-row-]").attr("id"))[1]);

				if ($(this).parents("[id^=filter-row-]").hasClass("all-inactive")) {
					$('#filters-popup .make-active').removeClass("active");
					$('#filters-popup .make-inactive').addClass("active");
					$('#filters-popup input:checkbox').attr("disabled","disabled");
					$('#filters-popup td').addClass("inactive");
				} else {
					$('#filters-popup .make-active').addClass("active");
					$('#filters-popup .make-inactive').removeClass("active");
					$('#filters-popup input:checkbox').removeAttr("disabled");
					$('#filters-popup td').removeClass("inactive");
				}

				pos = {
					x: $(this).offset().left+Math.floor($(this).innerWidth()/2),
					y: $(this).offset().top-$('#filters-popup').outerHeight()+8
				}

				$('#filters-popup').css({top:pos.y+"px",left:pos.x+"px"}).show();
			});

			$('#filters-popup .save').click(function(e) {
				e.preventDefault();

				children = $('#filters-popup input:checkbox');

				for (i=0;i<children.length;i++) {
					if (children.eq(i).is(":checked")) {
						$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a[rel='+children.eq(i).attr("name")+']').removeClass("inactive");
						$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a[rel='+children.eq(i).attr("name")+']').parent().show();

						$('#filters-all #filter-'+$('#filters-popup a.filter-name').attr("rel")+'-'+children.eq(i).attr("name")+' .filterq').removeClass("inactive");
						$('#filters-all #filter-'+$('#filters-popup a.filter-name').attr("rel")+'-'+children.eq(i).attr("name")).show();
					} else {
						$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a[rel='+children.eq(i).attr("name")+']').parent().hide();
						$('#filters-all #filter-'+$('#filters-popup a.filter-name').attr("rel")+'-'+children.eq(i).attr("name")).hide();
					}
				}

				if (!$('#filters-all .filterq').parent().filter(":visible").length) {
					$('#filters-all .nofilters').show();
				} else {
					$('#filters-all .nofilters').hide();
				}

				if ($('#filters-popup .filters-button.make-inactive').hasClass("active")) {
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")).addClass("all-inactive");
					$('#filters-all span[id^=filter-'+$('#filters-popup a.filter-name').attr("rel")+']').addClass("inactive");
				} else {
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")).removeClass("all-inactive");
					$('#filters-all span[id^=filter-'+$('#filters-popup a.filter-name').attr("rel")+']').removeClass("inactive");
				}

				/*if (children.not(":checked").length) {
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a.enlarge').show();
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a.reduce').hide();
				}else*/
				if (children.filter(":checked").length > 0){
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a.reduce').show();
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a.enlarge').hide();
				}else {
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a.reduce').hide();
					$('#filter-row-'+$('#filters-popup a.filter-name').attr("rel")+' a.enlarge').show();
				}

				$('#filters-popup').hide();
				sendHttpRequest(); 
			});

			$('#filters-popup .filters-button').click(function() {
				$('#filters-popup .filters-button').removeClass("active");
				$(this).addClass("active");

				if ($(this).hasClass("make-active")) {
					$('#filters-popup input:checkbox').removeAttr("disabled");
					$('#filters-popup td').removeClass("inactive");
				} else {
					$('#filters-popup input:checkbox').attr("disabled","disabled");
					$('#filters-popup td').addClass("inactive");
				}
			});

			$('#filters-popup .toggle-checkboxes').click(function(e) {
				e.preventDefault();
				if ($('#filters-popup input:checkbox:not(:checked)').length) {
					$('#filters-popup input:checkbox:not(:disabled)').attr("checked","checked");
				} else {
					$('#filters-popup input:checkbox:not(:disabled)').removeAttr("checked");
				}
			});
		},

		hintSearchResultTools: function(){
			var timer = null;
						
			jQuery(".views").hover(function(){
				var val =null;
				switch(jQuery(this).attr("name")){
					case "view1":
						val = jQuery(".hide #view1").html();
						break;							
					case "view2":
						val = jQuery(".hide #view2").html();
						break;
					case "view3":
						val = jQuery(".hide #view3").html();
						break;
				}			
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(val);
					tools.fixPosBubble3(".views", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
			
			jQuery(".tools-container .link").hover(function(){
				var val =jQuery(".hide #actList").html();
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(val);
					tools.fixPosBubble3(".link", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
			
			jQuery(".tools-container .view-tools").hover(function(){
				var val =jQuery(".hide #tools").html();
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(val);
					tools.fixPosBubble(".view-tools", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});		
					
			jQuery("#searchInfoPicto").hover(function(){
				var val =jQuery(".hide #searchInfo").html();
				var currentCateg = jQuery(".title-search #currentCateg").html();
				var searchWord = jQuery("#search-type-1-input").val();
				if(searchWord=="")
					searchWord = jQuery("#search-type-1-nodecodeField").val();;
				val = val.replace("Terme", searchWord);
				val = val.replace("currentCateg", currentCateg);				
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(val);
					tools.fixPosBubble2("#searchInfoPicto", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});	
		}
	},

	datasheet: {
		init: function() {
			this.handleProdSheet();
			this.handleActions();
			this.handleDropDowns();
			this.handleTabsControl();
			this.handleBlockView();
			this.handleButtonTabs();
			this.handleCurrencies();
			this.handleCaTable();
			this.handleContacts();
			this.handleCaProd();
			this.handlePrMaison();
			this.handleMisc();
		},
		defaultTabs: ["certs","activite","motsclef","certprod","prix","plateform"],
		show2ClosedTabs: [],
		srollTo: null,
		charts: [],
		handleActions: function() {
			var timer = null;
			$('.datasheet-actions .datasheet-action').hover(
				function() {
					$(this).addClass("act");
					
					id = /datasheet-action-(.*)/.exec($(this).attr("id"))[1];
					val = $('#datasheet-action-hint-'+id).html();

					if (val) {
						timer = setTimeout(function(){
							tools.fixPosBubble4(id);
							jQuery("#datasheet-action-hint").html(val).show();
						}, 2000);
					}
				},
				function() {
					clearTimeout(timer);
					$(this).removeClass("act");
				}
			);
			$('#datasheet-action-hint').hover(
				function(){},
				function() {
					clearTimeout(timer);
					jQuery("#datasheet-action-hint").hide();
				}
			);
			$('.datasheet-actions .datasheet-action').each(function() {
				if ($('div:last',this).innerHeight()<=13) {
					$('div:last',this).css("margin-top","20px");
				}
			});

			var i = 0;
			$('.datasheet-actions').children().each(function() {
				if (!$(this).hasClass("extra")) {
					i++;
					if (i>7) { $(this).hide(); }
				}
			});
			if (i<=7) { $('.datasheet-actions .datasheet-action.extra').hide(); }

			$('.datasheet-actions .datasheet-action.extra').click(function() {
				var html = "<ul>\n";
				var len = $('.datasheet-actions .datasheet-action:hidden').length;
				var i = 0;
				$('.datasheet-actions .datasheet-action:hidden').each(function() {
					i++;
					html += "\t<li";
					if (i==len) { html += " class=\"last\""; }
					html += ">"+$('div:last',this).html().replace("<br>"," ").replace("<BR>"," ")+"</li>\n";
				});
				html += "</ul>";

				$('#datasheet-dropdown').html(html);
				tools.fixPosBubble5(this);
			});
			$('.datasheet-actions .datasheet-action.extra a').click(function(e) { e.preventDefault(); });

			$('.certificate a').click(function(e) {
				e.preventDefault();

				rel = $(this).attr("rel").split(" ");
				head = $('#datasheet-cert-popup-'+rel[0]+' .head').html();
				cont = $('#datasheet-cert-popup-'+rel[0]+' .content1').html();
				img = $('#datasheet-cert-popup-'+rel[0]+' .img').html();

				if (head && cont) {
					$('#datasheet-popup2 .head .text').html(head);
					if (img) { $('#datasheet-popup2 .head .img img').attr("src",img).show(); }
					else { $('#datasheet-popup2 .head .img img').hide(); }
					$('#datasheet-popup2 .content').html(cont);
					compubase.datasheet.fixPosPopup2($(this).parent().parent(),rel[0],rel[1],[20,20]);
					$('#datasheet-popup2').unbind("mouseleave");
				}
			});
			$('#datasheet-popup2 .icon-close').click(function(e) {
				e.preventDefault();

				$('#datasheet-popup2').hide();
			});
			
			jQuery(".chart, .list").hover(function(e) {
				e.preventDefault();
				var info = $(this).attr("name");				
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble2(".chart", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});			
			
		},

		handleProdSheet: function() {
			//$('.prodsheet-head .arr-l')
			//$('.prodsheet-head .arr-r')
			
			//$('.prodsheet-head .enlarge, .prodsheet-head .images .fleft a').click(function(e) {
			$('.prodsheet-head .enlarge').click(function(e) {
				e.preventDefault();

				$('#prodsheet-image-popup').css({left:$('.prodsheet-head .enlarge').offset().left-$('#prodsheet-image-popup').outerWidth()+80+"px",top:$('.prodsheet-head .enlarge').offset().top-Math.floor($('#prodsheet-image-popup').outerHeight()/2)+"px"}).show();
			});

			$('#prodsheet-image-popup .icon-close').click(function(e) {
				e.preventDefault();

				$('#prodsheet-image-popup').hide();
			});

			// Arrows

			$('#prodsheet-image-popup .arr-r, .prodsheet-head .arr-r').click(function(e) {
				e.preventDefault();

				act = $('#prodsheet-image-popup .images div.act');
				nextel = act.next();

				if (typeof nextel.attr("class") == "undefined") {
					nextel = $('#prodsheet-image-popup .images div:first');
				}

				act.removeClass("act");
				nextel.addClass("act");

				$('#prodsheet-image-popup .image img').attr("src",$('a',nextel).attr("rel"));
				$('.prodsheet-head .images .fleft img').attr("src",$('img',nextel).attr("src"));
			});

			$('#prodsheet-image-popup .arr-l, .prodsheet-head .arr-l').click(function(e) {
				e.preventDefault();

				act = $('#prodsheet-image-popup .images div.act');
				prevel = act.prev();

				if (typeof prevel.attr("class") == "undefined") {
					prevel = $('#prodsheet-image-popup .images div:last');
				}

				act.removeClass("act");
				prevel.addClass("act");

				$('#prodsheet-image-popup .image img').attr("src",$('a',prevel).attr("rel"));
				$('.prodsheet-head .images .fleft img').attr("src",$('img',prevel).attr("src"));
			});
		},

		fixPosPopup2: function(i,n,c,o) {
			if ($('#datasheet-popup2').is(":hidden")||n!=$('#datasheet-popup2 .current').html()) {
				pos = $(i).offset();
				pos.left = pos.left + $(i).outerWidth() - o[1];
				$('#datasheet-popup2').removeAttr("class").addClass(c);
				$('#datasheet-popup2').show();
				pos.top = pos.top - $('#datasheet-popup2').outerHeight() + o[0];
				$('#datasheet-popup2').css({"left":pos.left,"top":pos.top});
				$('#datasheet-popup2 .current').html(n);
			} else {
				if (n==$('#datasheet-popup2 .current').html()) { $('#datasheet-popup2').hide(); }
			}
		},
		handleDropDowns: function() {
			$('.dropdown-link').click(function(e) {
				e.preventDefault();

				val = $('#ds-dropdown-'+$(this).attr("rel")).html();
				$('#datasheet-dropdown').html(val);

				tools.fixPosBubble5(this);

				compubase.datasheet.handleContacts();
			});

			$('#datasheet-dropdown').hover(function() {},
				function() {
					$(this).hide();
				}
			);
		},
		showDefaultTabs: function() {
			$('.datasheet-tab').each(function() {
				if (!$(this).hasClass("main")) {
					var a = 0;
					for (i=0;i<compubase.datasheet.defaultTabs.length;i++) {
						if ("ds-tab-"+compubase.datasheet.defaultTabs[i]==$(this).attr("id")) { a = 1; }
					}
					
					var params = jQuery("#scrolltocpycatalog").html();
					if(params=="c"){
						if ($(this).attr("id")=="ds-tab-catalogue-tabs") { a = 1; }
					}
				
					if (a) {
						$('.btn-tab-show a.show[rel='+/ds-tab-(.*)/.exec($(this).attr("id"))[1]+']').parent().parent().parent().hide().attr("title","hide");
						$('.btn-tab-show3 a[rel='+/ds-tab-(.*)/.exec($(this).attr("id"))[1]+']').parent().addClass("on");
					} else {
						$(this).hide();
					}

					$('.btn-tab-show3.on').each(function() {
						$('#ds-tab-'+$('a',this).attr("rel")).show();
					});
				}
			});

			//$('.datasheet-buttontabs3').children(":eq(0)").addClass("on");
			$('.datasheet-buttontabs3').parent().children("[id^=blocklook-sub-]")/*filter(":gt(0)")*/.hide();
			//$('.datasheet-buttontabs3').parent().contents(".seealso .all").click();
		},
		scrollToTab: function() {
			var params = jQuery("#scrolltocpycatalog").html();
			if(params=="c"){		
				$('html, body').animate({scrollTop: $('#ds-tab-catalogue-tabs').offset().top-7}, 1000);
			}
		},
		handleTabsControl: function() {
			$('.btn-tab-close').click(function(e) {
				e.preventDefault();
				$(this).parent().parent().parent().animate({opacity:"0"},{queue:false,duration:200}).animate({height:"toggle"},200);

				if ($('#ds-tab-'+$(this).attr("rel")).is(":hidden")) {
					$('#ds-tab-'+$(this).attr("rel")).animate({opacity:1},{queue:false,duration:200})
						.animate({height:"toggle"},200);
				}
				id = /ds-tab-(.*)/.exec($(this).parent().parent().parent().attr("id"))[1];
				$('.btn-tab-show a.show[rel='+id+']').parent().parent().parent().animate({opacity:1},{queue:false,duration:200}).animate({width:"toggle"},200).removeAttr("title");
			});
			$('.btn-tab-close').hover(
				function() {
					$(this).addClass("on");
				},
				function() {
					$(this).removeClass("on");
				}
			);

			$('.btn-tab-toggle').click(function(e) {
				e.preventDefault();
				id = '#'+$(this).parent().parent().parent().attr("id");
				if ($(id+' .content').is(":visible")) {
					$(id+' .content').animate({height:"toggle"},300,function() {
						$(id+' .hidden').show(100);
					});
				} else {
					$(id+' .hidden').slideUp(100,function() {
						$(id+' .content').slideDown(300);//animate({height:"toggle"},300);
					});
				}
				$(this).toggleClass("off");
			});

			$('.btn-tab-show').click(function(e) {
				e.preventDefault();
				if ($('#ds-tab-'+$('a.show',this).attr("rel")).is(":hidden")) {
					$('#ds-tab-'+$('a.show',this).attr("rel")).animate({opacity:1},{queue:false,duration:200}).animate({height:"toggle"},200).removeClass("hide");
					if ($(this).parent().children(":visible").length>1) {
						$(this).animate({opacity:0},{queue:false,duration:200}).animate({width:"toggle"},200).attr("title","hide");
					} else {
						$(this).parent().parent().parent().animate({opacity:"0"},{queue:false,duration:200})
							.animate({height:"toggle"},200);
						$(this).hide().attr("title","hide");
					}
					$('html, body').animate({scrollTop: $('#ds-tab-'+$('a.show',this).attr("rel")).offset().top-7}, 1000);
				}
			});
			var timer = null;
			$('.btn-tab-show').hover(function() {
				c = $('a.popup',this).attr("rel");
				rel = $('a.show',this).attr("rel");
				head = $('#datasheet-button-popup-'+rel+' .head').html();
				cont = $('#datasheet-button-popup-'+rel+' .content').html();
				img = $('#datasheet-button-popup-'+rel+' .img').html();
				el = this;

				if (head && cont) {
					timer = setTimeout(function(){
						$('#datasheet-popup2 .head .text').html(head);
						if (img) { $('#datasheet-popup2 .head .img img').attr("src",img).show(); }
						else { $('#datasheet-popup2 .head .img img').hide(); }
						$('#datasheet-popup2 .content').html(cont);
						compubase.datasheet.fixPosPopup2($(el),rel,c,[20,20]);
						$('#datasheet-popup2').mouseleave(function() {
							$(this).hide();
						});
					}, 3000);
				}
			}, function(){
				clearTimeout(timer);
			});	

			$('.btn-tab-show2').click(function() {
				if($('.datasheet-tab.'+$('a.block-color',this).attr("rel")+':visible').length) {
					$('.datasheet-tab.'+$('a.block-color',this).attr("rel")+':visible').each(function() { compubase.datasheet.show2ClosedTabs.push(/ds-tab-(.*)/.exec($(this).attr("id"))[1]); });
					$('.datasheet-tab.'+$('a.block-color',this).attr("rel")+':visible').animate({opacity:0},{queue:false,duration:200}).animate({height:"toggle"},200);
					$('.btn-tab-show.'+$('a.block-color',this).attr("rel")).show().css("opacity",1).removeAttr("title");
					$('.cattabs-block.'+$('a.block-color',this).attr("rel")+' .btn-tab-show3').removeClass("on");
					$('.cattabs-block.'+$('a.block-color',this).attr("rel")+' .content').children().hide();
				} else {
					//$('#ds-tab-'+$('a.show',this).attr("rel")).animate({opacity:1},{queue:false,duration:200}).animate({height:"toggle"},200).removeClass("hide");
					//compubase.datasheet.show2ClosedTabs.splice(compubase.datasheet.show2ClosedTabs.indexOf($('a.show',this).attr("rel")), 1);
					for (i=0;i<compubase.datasheet.show2ClosedTabs.length;i++) {
						if ($('#ds-tab-'+compubase.datasheet.show2ClosedTabs[i]).hasClass($('a.block-color',this).attr("rel"))) {
							$('#ds-tab-'+compubase.datasheet.show2ClosedTabs[i]).animate({opacity:1},{queue:false,duration:200})
								.animate({height:"toggle"},200);
							$('.btn-tab-show a.show[rel='+compubase.datasheet.show2ClosedTabs[i]+']').parent().parent().parent().hide().attr("title","hide");
							$('.btn-tab-show3 a[rel='+compubase.datasheet.show2ClosedTabs[i]+']').parent().addClass("on");
							compubase.datasheet.show2ClosedTabs.splice(compubase.datasheet.show2ClosedTabs.indexOf(compubase.datasheet.show2ClosedTabs[i]), 1);
							i--;
						}
					}

					if (!$('.datasheet-tab.'+$('a.block-color',this).attr("rel")+':visible').length) {
						$('.datasheet-tab.'+$('a.block-color',this).attr("rel")+'.main').animate({opacity:1},{queue:false,duration:200}).animate({height:"toggle"},200);
					}
					//$('html, body').animate({scrollTop: $('#ds-tab-'+$('a.show',this).attr("rel")).offset().top-7}, 1000);
				}
			});

			$('.btn-tab-show3').click(function() {
				$('#ds-tab-'+$('a',this).attr("rel")).parent().children().hide();
				$('#ds-tab-'+$('a',this).attr("rel")).show();

				$(this).parent().children().removeClass("on");
				$(this).addClass("on");
			});

			$(".btn-tab-help").click(function(e) { e.preventDefault(); });
			$(".btn-tab-help").hover(function(){
				var val = jQuery(".hide #datasheet-certs-hint").html();
				var id = $(this).parent().parent().parent().attr("id");
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(val);
					tools.fixPosBubble6("#"+id+" .btn-tab-help", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});	
			
			$('#companyCatalog').click(function(e) {
				if ($('#ds-tab-catalogue-tabs').is(":hidden")) {
					$('#ds-tab-catalogue-tabs').animate({opacity:1},{queue:false,duration:200}).animate({height:"toggle"},200).removeClass("hide");					
					$('html, body').animate({scrollTop: $('#ds-tab-catalogue-tabs').offset().top-7}, 1000);
					$('.show[rel=catalogue-tabs]').parents(".btn-tab-show").hide().attr("title","hide");
				}
			});
			
			//begin popupGroup for datasheet
			jQuery(".datasheet-data-content #linkGroupe").click(function(){
				var current = this;			
				jQuery(".popupGroupe").hide();
				popupToShow = jQuery(".datasheet-data-content .popupGroupe");
				var idGroup = this.id;
				var currentGroup = idGroup;
				var oldvalue = jQuery(".datasheet-data-content #"+currentGroup).html();		
				$(".datasheet-data-content #"+currentGroup).ajaxStart(function(){
					$(".datasheet-data-content #"+currentGroup).html("<img src='img/group-loader.gif' />");
				});
				$(popupToShow).ajaxStop(function(){
					$(".datasheet-data-content #"+idGroup).html(oldvalue);
				});
				
				jQuery(popupToShow).load(this.href, function(){
					currentGroup =0;
					heightPopup = jQuery(popupToShow).height();
																		
					posContainer = jQuery("#table-results-datasheet .datasheet-data-content").offset();					
					pos = jQuery(current).offset();
										
					//jQuery(popupToShow).css({ left: (pos.left-posContainer.left) + "px", top: (pos.top-posContainer.top)-(heightPopup/2) + "px" }).show();
					jQuery(popupToShow).css({ left: pos.left+ "px", top: (pos.top - 100) + "px" }).show();
	
					jQuery(".datasheet-data-content .close-popup").click(function(){
						jQuery(this).parent().hide();
						
						return false;
					});
					
					jQuery(".datasheet-data-content .popupGroupe .block-top .locations a").click(function(){
						id = jQuery(this).attr("rel");
						if(id) jQuery("#" + id).click();
						
						return false;
					});
					
					jQuery(".datasheet-data-content .popupGroupe li a").click(function(){
						jQuery(this).next("ul").toggle();
						jQuery(this).parents("li").get(0).className = jQuery(this).next("ul").is(":visible") ? "open" : "close";
						return false;
					});
					
										
					var data = jQuery(".datasheet-data-content .popupGroupe .linkMore").get(0);
					jQuery.data(data, "styleDisplay", "block");
					
					var srcImg = jQuery("#popuplogo_"+idGroup).attr("src");
					jQuery("#groupLogo_"+idGroup).attr("src",srcImg);
					jQuery("#groupLogo_"+idGroup).attr("width",64);
					jQuery("#groupLogo_"+idGroup).attr("height",51);
					
					jQuery(".datasheet-data-content .popupGroupe .linkMore").click(function(){												
						toDisplay = jQuery.data(this, "styleDisplay");										
						
						if(typeof toDisplay == "undefined") toDisplay = "block";
						
						current = jQuery(this).parent(".block-bottom").children("ul");
						jQuery("ul", current).each(function(){
							jQuery(this).css("display", toDisplay);
							
							jQuery(this).parents("li").get(0).className = jQuery(this).is(":visible") ? "open" : "close";
						});
						
						if(toDisplay == "none"){
							jQuery.data(this, "styleDisplay", "block");
							
							if( jQuery("img", this).attr("src").indexOf("icon-minus.gif") > -1 )
								jQuery("img", this).attr({ src: "img/icon-plus.gif" });
						} else {
							jQuery.data(this, "styleDisplay", "none");
							
							if( jQuery("img", this).attr("src").indexOf("icon-plus.gif") > -1 )
								jQuery("img", this).attr({ src: "img/icon-minus.gif" });
						}						
						return false;
					});
				});
				currentGroup = idGroup;
				return false;
			});			
			//end popupGroup for datasheet
			
			// poupFunctions
			jQuery(".ident-blocks #linkFunctions").click(function(){
                var current = this;                                                          
                jQuery(".popupGroupe").hide();
                popupToShow = jQuery(".popupGroupe");     
                var oldvalue = jQuery(".ident-blocks #linkFunctions").html();
                
                $(".ident-blocks #linkFunctions").ajaxStart(function(){
                    $(".ident-blocks #linkFunctions").html("<img src='img/group-loader.gif' />");
                });
     
                $(popupToShow).ajaxStop(function(){
                    $(".ident-blocks #linkFunctions").html(oldvalue);
  				});
                
                jQuery(popupToShow).load(this.href, function(){
                	
                	heightPopup = jQuery(popupToShow).height();
                    posContainer = jQuery(".ident-blocks #linkFunctions").offset();
                    pos = jQuery(current).offset();
                    
                    jQuery(popupToShow).css({width:250 +"px",background:"#F6F6F6", left: (pos.left-(posContainer.left/2)) + "px", top: ((pos.top-posContainer.top)+(heightPopup/2) + 60)+ "px" }).show();
                    	//jQuery(".block-type-1 .img").css("display", "none");
                         jQuery("#checkchildren").checkboxTree({
                         	collapsedarrow: "images/checkboxtree/img-arrow-collapsed.gif",
                         	expandedarrow: "images/checkboxtree/img-arrow-expanded.gif",
                         	blankarrow: "images/checkboxtree/img-arrow-blank.gif",
                         	checkchildren: true
                         });
                	     
                	     jQuery(".ident-blocks .close-popup").click(function(){
         					jQuery(this).parent().hide();
         					return false;
         				 });
                	     
                	     jQuery(".ident-blocks .save").click(function(){
          					jQuery(this).parent().hide();
          					return false;
          				 });
                	     
           		});
                  return false;              
            });
			//added by mohand ferhi
			
			jQuery(".datasheet-data-content #popup_company_product").click(function(){
                var current = this;                                                          
                jQuery(".popupGroupe").hide();
                popupToShow = jQuery(".datasheet-data-content .popupGroupe");                                                  
                var company_productId = this.id;
                
                var oldvalue = jQuery(".datasheet-data-content #"+company_productId).html();
                
                $(".datasheet-data-content #"+company_productId).ajaxStart(function(){
                               $(".datasheet-data-content #"+company_productId).html("<img src='img/group-loader.gif' />");
                });
                
                $(popupToShow).ajaxStop(function(){
                               $(".datasheet-data-content #"+company_productId).html(oldvalue);
                });
                
                jQuery(popupToShow).load(this.href, function(){
                	
                   heightPopup = jQuery(popupToShow).height();
                   posContainer = jQuery("#table-results-datasheet .datasheet-data-content").offset();
                   
                   placement = { x: Math.floor($(current).offset().left+$(current).outerWidth()+$(current).outerWidth())-20 +"px", y: (Math.floor($(current).offset().top)/2) +80 +"px" }
                         
                   jQuery(popupToShow).css({background:"#F38F16", left:placement.x, top:placement.y }).show();
                                     
                  // jQuery(popupToShow).css({ width: 200 + "px" ,background:"#F38F16", left: ((pos.left+25)-(posContainer.left/12)) + "px", top: (70+ (pos.left-posContainer.top)) + "px" }).show();
                                                  
                   jQuery(".datasheet-data-content .close-popup").click(function(){
                      jQuery(this).parent().hide();
                       return false;
                   });
                   
                   jQuery(".datasheet-data-content .othersProductList").hover(function() {	                   				
                	   var info = jQuery(this).attr("name");
                	   var currentId = this.id;
                	   timer = setTimeout(function(){
       					jQuery("#msg-hints p").html(info);
       					tools.fixPosBubble2("#"+currentId, "#msg-hints");
       					jQuery("#msg-hints").show();
       					jQuery("#msg-error").hide();
       				}, 1);
       			}, function(){
       				clearTimeout(timer);
       				jQuery("#msg-hints").hide();
       			});
                               
                });
               
                return false;
			}); 
			
			jQuery(".datasheet-data-content  .product_activity_type").click(function(){
				var rel = jQuery(this).attr("rel");
				var nodecode =/activity_(.*)/.exec(rel)[1];
				jQuery(".search-type #search-type-1-nodecodeField").val(nodecode);
				jQuery(".search-type #search-type-1-categorie2").val("searchByCategoryProduct");
				jQuery(".search-type form").submit();
			});
			
			jQuery(".disbl, .disbl-red, .disbl-green").click(function(){
				var title =jQuery("#features_popup_alert_header_title").html();
				var content =jQuery("#features_popup_alert_content_text").html();
				var isConfirm = jQuery("#features_popup_alert_type_confirm").html();
				var href = "identification.do"
				var ok_Button_label = jQuery("#features_popup_alert_button_ok").html();
				
				if(isConfirm == "false"){
					jAlert(""+content, ""+title);
				}else{
					jConfirm(content, title,ok_Button_label,
						function (r) { 
							res = r; 
							if(res)
							location.href = href;});
				}
			});
			
		},
		handleMisc: function() {
			tmp = 0;

			$('.datasheet-data-line1 .border').each(function() {
				if ($(this).innerHeight()>tmp) { tmp = $(this).innerHeight(); }
			});
			$('.datasheet-data-line1 .border').each(function() {
				if (!$(this).parent().hasClass("first")) { $(this).css("height",tmp+"px"); }
			});

			$('.btn-tab-show .content- div.link').each(function() {
				$(this).css("padding-top",Math.floor(30-parseInt($(this).innerHeight())/2)+"px");
			});

		},
		fixImageValign: function() {
			$('.certificate img, .caprod-brand img').each(function() {
				$(this).parent().parent().css("padding-top",Math.floor(35-parseInt($(this).height())/2)+"px");
			});

			var i = 0;

			$('.btn-tab-show .content- div.img').each(function() {
				$(this).css("padding-top",Math.floor(29-parseInt($('img',this).height())/2)+"px");
			});
		},

		handleContacts: function() {
			$('.linkContactsHide').click(function(e) {
				e.preventDefault();
				$('#contacts-area').toggle();
				if (/bottom-1/.test($('.linkContactsHide img').attr("src"))) {
					$('.linkContactsHide img').attr("src","img/arrow-right-1.png");
				} else {
					$('.linkContactsHide img').attr("src","img/arrow-bottom-1.png");
				}
			});

			$('.contacts-table tr').each(function() {
				if (/contact-line-(.*)/.test($(this).attr("id"))) {
					$('td.contact-name',this).css("cursor","pointer");
					$('td.contact-name',this).click(function() {
						id = /contact-line-(.*)/.exec($(this).parent().attr("id"))[1];
						$('#contact-minifiche-'+id).show();
						$('#contact-line-'+id).hide();
						if ($('.contacts-table .line:visible').length<1) { $('.contacts-table .line-header').css("visibility","hidden"); }
					});
				}
			});

			$('.contacts-table .close-minifiche').click(function(e) {
				e.preventDefault();

				$('#contact-minifiche-'+$(this).attr("rel")).hide();
				$('#contact-line-'+$(this).attr("rel")).show();

				$('.contacts-table .line-header').css("visibility","visible");
			});

			$('.contacts-table .open-minifiche').click(function(e) {
				e.preventDefault();

				$('#contact-minifiche-'+$(this).attr("rel")).show();
				$('#contact-line-'+$(this).attr("rel")).hide();

				if ($('.contacts-table .line:visible').length<1) { $('.contacts-table .line-header').css("visibility","hidden"); }
			});

			$('.contacts-links .view1, .contacts-view.view1').click(function(e) {
				e.preventDefault();

				$('.contacts-table tr').each(function() {
					if (/contact-line-(.*)/.test($(this).attr("id"))) { $(this).show(); }
					if (/contact-minifiche-(.*)/.test($(this).attr("id"))) { $(this).hide(); }
				});

				$('.contacts-table .line-header').css("visibility","visible");
				$('.contacts-links .views').removeClass("on");
				$('.contacts-links .view1').addClass("on");
				$('#datasheet-dropdown').hide();
			});

			$('.contacts-links .view3').click(function(e) {
				e.preventDefault();

				$('.contacts-table tr').each(function() {
					if (/contact-line-(.*)/.test($(this).attr("id"))) { $(this).hide(); }
					if (/contact-minifiche-(.*)/.test($(this).attr("id"))) { $(this).show(); }
				});

				$('.contacts-table .line-header').css("visibility","hidden");
				$('.contacts-links .views').removeClass("on");
				$('.contacts-links .view3').addClass("on");
				$('#datasheet-dropdown').hide();
			});
			
			$('.contacts-view.view3').click(function(e) {
				e.preventDefault();			
				$('#contacts-area input:checkbox:checked').parents("tr").hide();
				$('#contacts-area input:checkbox:checked').parents("tr").next().show();
				
				if ($('#contacts-area input:checkbox:checked').length) {
				  $('.contacts-table .line-header').css("visibility","hidden");
				  $('.contacts-links .views').removeClass("on");
				  $('.contacts-links .view3').addClass("on");
				}
				$('#datasheet-dropdown').hide();
			});
			
			var timer=null;
			$('.contacts-links .view3, .contacts-view.view3').hover(function(e) {
				e.preventDefault();
				var info = $(this).attr("rel");
				var currentId = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble3("#"+currentId, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
			
			$('.contacts-links .view1, .contacts-view.view1').hover(function(e) {
				e.preventDefault();
				var info = $(this).attr("rel");
				var currentId = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble3("#"+currentId, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});		
			
			$('.social a').hover(function(e) {
				var currentId = this.id;
				var info = $(this).attr("name");
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble3(".social-icons #"+currentId, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		},
		handlePrMaison: function() {
			$('.prmaison-tabs div').click(function() {
				$(this).parent().children().removeClass("active");
				$(this).addClass("active");

				$('#'+$('a',this).attr("rel")).parent().children().hide();
				$('#'+$('a',this).attr("rel")).show();
			});
			
			/*jQuery("#result-search-prmaison .product_activity_type").click(function(){
				
				var rel = jQuery(this).attr("rel");
				var nodecode =/activity_(.*)/.exec(rel)[1];
				jQuery(".search-type #search-type-1-nodecodeField").val(nodecode);
				jQuery(".search-type #search-type-1-categorie2").val("searchByCategoryProduct");
				jQuery(".search-type form").submit();
			});*/
		},

		makeChart: function(id) {
			plot = compubase.datasheet.charts[id];

			if (plot.type=="default") {
				labels = new Array();
				data = new Array();
				for (i=0;i<plot.data.length;i++) {
					labels[labels.length] = plot.data[i][0];
					data[data.length] = plot.data[i][1];
				}

				title = (typeof plot.title != "undefined") ? plot.title : {text:"",size:0,color:"000"};

				max = 0;
				interval = 10;
				for (i=0;i<data.length;i++) {
					if (data[i]>max) { max = data[i]; }
				}
				max += max*0.2;
					if(max>500)	
						interval = 60;
				$('#'+id).gchart({
					type: "barVertGrouped",
					series: [$.gchart.series('',data,'4f80bb')],
					dataLabels: labels,
					barSpacing: 115,
					barWidth: "r",
					gridSize: [0, 0], gridLine: [3, 0],
					maxValue: max,
					axes: [
						$.gchart.axis('left',0,max,interval,'494949','right').ticks('4f81be',-500),
						$.gchart.axis('x',0,10,'4e82be')
					]
				});
			} else if (plot.type=="pie" || plot.type=="pie3D") {
				labels = new Array();
				data = new Array();
				for (i=0;i<plot.data.length;i++) {
					labels[labels.length] = plot.data[i][0];
					data[data.length] = plot.data[i][1];
				}

				title = (typeof plot.title != "undefined") ? plot.title : {text:"",size:0,color:"000"};

				$('#'+id).gchart({
					type: plot.type,
					series: [$.gchart.series('',data)],
					dataLabels: labels,
					title: title.text,
					titleColor: title.color,
					titleSize: title.size
				});
			}
		},
		handleCharts: function() {
			for (i in compubase.datasheet.charts) {
				compubase.datasheet.makeChart(i);
			}
		},

		gridCallback: function() {
			//$('.loadingui').hide();
		},

		handleBlockView: function() {
			$('.blockview a').click(function(e) {
				e.preventDefault();

				$(this).parent().children().removeClass("on");
				$(this).addClass("on");
				$('#blocklook-'+$(this).attr("rel")).parent().children().hide();
				$('#blocklook-'+$(this).attr("rel")).show();
			});
		},

		handleButtonTabs: function() {
			$('.datasheet-buttontab').click(function() {
				$(this).parent().children().removeClass("on");
				$(this).addClass("on");

				$('#blocklook-'+$('a',this).attr("rel")).parent().children().hide();
				$('#blocklook-'+$('a',this).attr("rel")).show();
			});

			$('.datasheet-buttontab2').click(function() {
				if (!$(this).hasClass("disbl")) {
					$(this).parent().children().removeClass("on");
					$(this).addClass("on");

					$('#blocklook-sub-'+$('a',this).attr("rel")).parent().children().each(function() {
						if (/^blocklook-sub-/.test($(this).attr("id"))) { $(this).hide(); }
					});
					$('#blocklook-sub-'+$('a',this).attr("rel")).show();
				}
			});

			$('.datasheet-buttontab3').click(function() {
				if (!$(this).hasClass("disbl")) {
					if ($(this).hasClass("on")) {
						$('#blocklook-sub-'+$('a',this).attr("rel")).hide();
						$(this).removeClass("on");
					} else {
						$(this).addClass("on");
						$('#blocklook-sub-'+$('a',this).attr("rel")).show();
						$('html, body').animate({scrollTop: $('#blocklook-sub-'+$('a',this).attr("rel")).offset().top-7}, 1000);
					}
				}
			});
		},

		handleCurrencies: function() {
			$('.currency-change .tab-rounded-item').click(function() {
				$('#currency-'+$('a',this).attr("rel")).parent().children().hide();
				$('#currency-'+$('a',this).attr("rel")).show();

				$(this).parent().children('.tab-rounded-item').removeClass("sel");
				$(this).addClass("sel");
				
				var currentmoney =$('a',this).attr("rel");
				$('.moneyChange').hide();
				$('#'+currentmoney).show();
				
			});
		},

		handleCaTable: function() {
			$('.ca-table-expand').click(function(e) {
				e.preventDefault();

				if (/blockview-icon-add\.gif$/.test($('img',this).attr("src"))) {
					$('.ca-table-sub-'+$(this).attr("rel")).show();
					$('img',this).attr("src","img/blockview-icon-minus.gif");
				} else {
					id = $(this).attr("rel");
					$('.ca-table-sub-'+id).hide();
					$('tr[class^=ca-table-sub-'+id+'-]').hide();
					$('.ca-table-sub-'+id+' .ca-table-expand img').attr("src","img/blockview-icon-add.gif");
					$('tr[class^=ca-table-sub-'+id+'-] .ca-table-expand img').attr("src","img/blockview-icon-add.gif");
					$('img',this).attr("src","img/blockview-icon-add.gif");
				}
			});
		},

		handleCaProd: function() {

			$('.caprod-close a').click(function(e) {
				e.preventDefault();

				$(this).parent().parent().parent().hide();
				id = /caprod-(.*)/.exec($(this).parent().parent().parent().attr("id"))[1];

				$('.seealso #link-'+id).show();

				if ($(this).parents('.caprod2').contents().find('.line:visible').length==1) { $(this).parents('table').contents().find('.caprod-close a').hide(); }

				$(this).parents('table').parent().children('.seealso').show();
			});

			$('.seealso a').click(function(e) {
				e.preventDefault();

				if ($(this).hasClass("all")) {
					$(this).parent().parent().contents().find('.line').show();
					$(this).parent().hide();
					$(this).parent().children('a[class!=all]').hide();
				} else {
					id = /link-(.*)/.exec($(this).attr("id"))[1];
					$(this).hide();
					$('#caprod-'+id).show();
					if ($(this).parent().children(":visible").length==1) { $(this).parent().hide(); }
				}

				$(this).parent().parent().contents().find('.caprod-close a').show();
			});

			$('.caprod-close a').hover(
				function() {
					$(this).addClass("on");
				},
				function() {
					$(this).removeClass("on");
				}
			);
		},
		hideCaProd: function() {
			$('.caprod2').each(function() {
				$('tr.line',this).filter(":gt(0)").hide();
			});
		}
	},

	leftMenu: {
		init: function() {
			this.handleTopLevel();
			this.handleSubLevel();
			this.handlePopupLevel();
		},

		showSub: function(sub,li) {
			li.addClass("opened");
			pos = li.position();
			posX = pos.left+li.outerWidth();
			posY = pos.top;
			
			sub.css({"left":posX,"top":posY+"px"}).show();
			sub.children('.b-c').css("width",Math.floor(sub.outerWidth()-12)+"px");
			sub.children('.r-c').css("height",Math.floor(sub.outerHeight()-25)+"px");

			max = 0;
			for (i=0;i<$('.subpopup-item',sub).length;i++) {
				if ($('.subpopup-item',sub).eq(i).width()>max) {
					max = $('.subpopup-item',sub).eq(i).width();
				}
			}
			$('.subpopup-item',sub).css("width",max+"px");
		},

		handleTopLevel: function() {
			var timer = null;
			$('.leftmenu .item').hover(
				function() {
					$(this).addClass("hover");
					html = $('#leftmenu-toolip-'+$('a',this).attr("rel")).html();
					li = $(this);
					if (html) {
						timer = setTimeout(function() {
							$('#leftmenu-toolip .content').html(html);
							$('#leftmenu-toolip').show();

							h = $('#leftmenu-toolip').outerHeight() - $('#leftmenu-toolip .top').outerHeight() - $('#leftmenu-toolip .bottom').outerHeight();
							$('#leftmenu-toolip .bg').css("height",h+"px");

							$('#leftmenu-toolip .content').css("margin-top","0");
							h = $('#leftmenu-toolip').height() - $('#leftmenu-toolip .content').height();
							h = Math.floor(h/2);
							$('#leftmenu-toolip .content').css("margin-top",h+"px");

							pos = li.offset();
							pos.left = pos.left + Math.round(li.width()/2) - 37;
							pos.top = pos.top - $('#leftmenu-toolip').outerHeight() + 3;
							$('#leftmenu-toolip').css("top",pos.top+"px").css("left",pos.left+"px");
						}, 1000);
					}
				},
				function() {
					$(this).removeClass("hover");
					$('#leftmenu-toolip').hide();
					clearTimeout(timer);
				}
			).click(function(e) {
				if ($(this).hasClass("has-sub")) {
					e.preventDefault();

					$('#leftmenu-sub-'+$('a',this).attr("rel")).toggle();
					$(this).toggleClass("on");
				} else {
					location.href = $('a',this).attr("href");
				}
			});
		},
		handleSubLevel: function() {
			var timer = null;

			$('.leftmenu .subitem').hover(
				function() {
					$(this).addClass("hover");
					if ($(this).children('a').attr("rel")) {
						sub = $('#leftmenu-subpopup-'+$(this).children('a').attr("rel"));
						li = $(this);
						timer = setTimeout(function() {
							compubase.leftMenu.showSub(sub,li);
							clearTimeout(timer);
						}, 1000);
					}
				},
				function() {
					$(this).removeClass("hover").removeClass("opened");
					$('.leftmenu-subpopup',this).hide();
					$('.subpopup-item',this).removeClass("opened");
					clearTimeout(timer);
				}
			).click(function(e) {
				if ($(this).children('a').attr("rel")) {
					e.preventDefault();
					clearTimeout(timer);
					sub = $('#leftmenu-subpopup-'+$(this).children('a').attr("rel"));
					li = $(this);
					if (sub.is(":visible")) {
						sub.hide();
						li.removeClass("opened");
					} else {
						compubase.leftMenu.showSub(sub,li);
					}
				} else {
					location.href = $(this).children('a').attr("href");
				}
			});
		},

		handlePopupLevel: function() {
			var timer = null;

			$('.leftmenu .subpopup-item').hover(
				function() {
					$(this).addClass("hover");
					if ($(this).children('a').attr("rel")) {
						sub = $('#leftmenu-subpopup-'+$(this).children('a').attr("rel"));
						li = $(this);
						timer = setTimeout(function() {
							compubase.leftMenu.showSub(sub,li);
							clearTimeout(timer);
						}, 1000);
					}
				},
				function() {
					$(this).removeClass("hover").removeClass("opened");
					$('.leftmenu-subpopup',this).hide();
					$('.subpopup-item',this).removeClass("opened");
					clearTimeout(timer);
				}
			).click(function(e) {
				e.stopPropagation();
				
				if ($(this).children('a').attr("rel")) {
					e.preventDefault();
					clearTimeout(timer);
					sub = $('#leftmenu-subpopup-'+$(this).children('a').attr("rel"));
					li = $(this);
					if (sub.is(":visible")) {
						sub.hide();
						li.removeClass("opened");
						$('.subpopup-item.has-sub').removeClass("opened");
					} else {
						compubase.leftMenu.showSub(sub,li);
					}
				} else {
					location.href = $(this).children('a').attr("href");
				}
			});
		}
	},

	identification: {
		init: function() {
			this.handleChangeStep();
			this.handleTabs();
			this.handleCheckForm();
			this.handleMisc();
			this.handleFakeSelect();
			this.handleActions();
		},

		handleChangeStep: function() {
			$('.ident-load-step').click(function(e) {
				e.preventDefault();

				step = $(this).val();

				compubase.identification.changeStep(step);
			});
		},

		changeStep: function(step) {
			location.href = "/step_"+step+".php"; // FIXME: set correct link here
		},

		handleTabs: function() {
			$('.ident-tabs td').click(function() {
				if (!$('.wrap',this).length||$('.wrap',this).is(":hidden")) { return false; }
				$(this).parent().children().removeClass("act");
				$(this).addClass("act");

				$('#ident-tab-'+$('a',this).attr("rel")).parent().children().hide();
				$('#ident-tab-'+$('a',this).attr("rel")).show();
			});

			if ($('.show-livraison').is(':checked')) {
				$('.ident-tabs a[rel=livraison]').parents(".wrap").show();
				$('#ident-tab-livraison input').removeAttr("disabled");
			}

			$('.show-livraison').click(function() {
				if ($('.show-livraison').is(':checked')) {
					$('.ident-tabs a[rel=livraison]').parents(".wrap").show();
					$('#ident-tab-livraison input').removeAttr("disabled");
				}else{
					$('.ident-tabs a[rel=facturation]').parents("td").addClass("act");
					$('.ident-tabs a[rel=livraison]').parents("td").removeClass("act");
					$('.ident-tabs a[rel=livraison]').parents(".wrap").hide();
					$('#ident-tab-livraison').hide();
					$('#ident-tab-facturation').show();
					$('#ident-tab-livraison input').attr("disabled","disabled");
				}
			});
			
			$('div[class*=copy-to-]').each(function() {
				to = /copy-to-(.*)($|\s){1,}/.exec($(this).attr("class"))[1];
				$('.ident-fake-select input[id='+to+']').val($(':hidden',this).val());
				$('.ident-fake-select input[id='+to+']').parent().children(".text").html($('.text',this).html());
			});
		},

		handleCheckForm: function() {
			$('.ident-check-form').submit(function() {
				var error = 0;
				var empty = 0;
				var form = $(this);

				$('.ident-check-field',this).removeClass("error-active");

				if (form.hasClass("ajax")) {
					error = 1;
					$.ajax({
						url: form.attr("action"),
						type: form.attr("method"),
						data: form.serialize(),
						success: function(data) {
							if (data=="1") {
								compubase.identification.raiseError($('input',form),1);
							} else {
								compubase.identification.changeStep('H');
							}
						}
					});
				} else {
					$('.ident-check-field',$(this)).each(function() {
						if ($(this).hasClass("radio")) {
							if (!$(this).parent().children(":radio:checked").length) { empty++; }
						} else {
							if ($(this).hasClass("ident-required") && $(this).is(":enabled") && !$(this).val()) { empty++; }
						}
					});
					error = compubase.identification.checkForm($(this));
				}
				
				$('.ident-toolip-red',this).addClass("hide");
				$('.ident-toolip-green',this).removeClass("hide");
				
				if (error) {
					if ($(this).hasClass("toolip")&&empty==$('.ident-check-field.ident-required:enabled',this).length) {
						$('.ident-toolip-green',this).addClass("hide");
						$('.ident-toolip-red',this).removeClass("hide");
					}
					compubase.identification.raiseError($('.ident-check-field.error-active',this).eq(0));
					return false;
				}
			});
			
			$('#button-quick-procedural').click(function(){				
				$('.ident-check-Demail-form').submit();
				return false;
			});
			
			$('.ident-check-Demail-form , .ident-check-Demail-form-login').submit(function() {
				$('.ident-check-field',this).removeClass("error-active");
				error = 0;
				$('.ident-check-Demail-form .ident-check-error').hide();

				$('.ident-check-field',this).each(function() {
					if (error) { return false; }

					if (!$(this).val()) {
						$(this).addClass("error-active");
						compubase.identification.raiseError($(this),0,1);
						error = 1;
					} else {
						if ($(this).hasClass("email")&&!/^[a-zA-Z0-9]([a-zA-Z0-9_.-])+[a-zA-Z0-9_-]@([a-zA-Z0-9-.])+\.([a-zA-Z]{2,4})$/.test($(this).val())) {
							$(this).addClass("error-active");
							compubase.identification.raiseError($(this),0,2);
							error = 1;
						} else if ($(this).hasClass("password")&&$(this).val().length<6) {
							$(this).addClass("error-active");
							compubase.identification.raiseError($(this),0,2);
							error = 1;
						}
					}
				});

				if (error) { return false; }
			});

			$('.ident-check-form .ident-check-field').focus(function() {
				$(this).parents("form").contents().find('.ident-toolip-green').removeClass("hide");
				$(this).parents("form").contents().find('.ident-toolip-red').addClass("hide");
				if (!$(this).hasClass("radio")) { compubase.identification.raiseError($(this)); }
			});
			$('.ident-check-form .ident-check-field').blur(function() {
				$(this).parents("form").contents().find('.ident-toolip-green').removeClass("hide");
				$(this).parents("form").contents().find('.ident-toolip-red').addClass("hide");
				if ($(this).hasClass("error-active")) { compubase.identification.hideError($(this)); }
				compubase.identification.checkField($(this),1);
			});
			$('.ident-check-form .ident-check-field').keydown(function(e) {
				if (e.keyCode==9) {
					if (compubase.identification.checkField($(this),1)) {
						e.preventDefault();
						compubase.identification.checkField($(this),1);
					} else {
						$(this).removeClass("error-active");
						compubase.identification.hideError($(this));
					}
						

					/*var empty = 0;
					$('.ident-check-field',$(this).parents("form")).each(function() {
						if ($(this).hasClass("radio")) {
							if (!$(this).parent().children(":radio:checked").length) { empty++; }
						} else {
							if ($(this).hasClass("ident-required") && $(this).is(":enabled") && !$(this).val()) { empty++; }
						}
					});
					if ($(this).parents("form").hasClass("toolip")&&empty==$('.ident-check-field.ident-required:enabled',$(this).parents("form")).length) {
						$('.ident-toolip-green',$(this).parents("form")).addClass("hide");
						$('.ident-toolip-red',$(this).parents("form")).removeClass("hide");
					}*/
				}
			});
			$('.ident-check-form .ident-check-field.radio').parent().children(":radio").click(function() {
				$(this).parent().children(".error-active").removeClass("error-active");
				$(this).parent().removeClass("error-active");
				compubase.identification.hideError($(this).parent().children(".radio"));
			});
			$('.ident-check-form .ident-check-field.radio').parent().hover(
				function() { compubase.identification.raiseError($('.radio',this)); },
				function() { compubase.identification.hideError($('.radio',this)); }
			);
		},

		checkForm: function(form) {
			var error = 0;

			$('.error-active',form).removeClass("error-active");

			$('.ident-check-field',form).each(function() {
				$(this).parents(".fieldset").children(".ident-check-error").hide();
				if (compubase.identification.checkField($(this))) { error = 1; }
			});

			return error;
		},

		checkField: function(input,separate) {
			var error = 0;

			if (input.attr("disabled")) { return 0; }
			if (separate) { input.removeClass("error-active"); }

			min = /min-(\d+)($|\s){1,}/.exec(input.attr("class")) ? /min-(\d+)($|\s){1,}/.exec(input.attr("class"))[1] : 0;
			if (input.hasClass("password")) { min = 6; }

			if ((input.hasClass("ident-required") && !input.val() && !separate)||(min && input.val().length && input.val().length<min)) {
				input.addClass("error-active");
				error = 1;
			}
			if (min && input.val().length && input.val().length<min) {
				input.addClass("error-active");
				error = 1;
			}
			var emailreg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			// /^[a-zA-Z0-9]([a-zA-Z0-9_.-])+[a-zA-Z0-9_-]@([a-zA-Z0-9-.])+\.([a-zA-Z]{2,4})$/
			if ((input.hasClass("email")&&!emailreg.test(input.val()))&&(input.hasClass("ident-required")||input.val())) {
				input.addClass("error-active");
				error = 1;
			}
			var webreg = new RegExp(/^(http:\/\/)?[a-zA-Z]([a-zA-Z0-9.-])+\.([a-zA-Z]{2,4})(\/(.*)?)?$/);
			if ((input.hasClass("web")&&!webreg.test(input.val()))&&(input.hasClass("ident-required")||input.val())) {
				input.addClass("error-active");
				error = 1;
			}
			if (input.hasClass("web")&&webreg.test(input.val())) {
				if (!/^http:\/\//.test(input.val())) { input.val("http://"+input.val()); }
			}
			if (input.hasClass("captcha")&&!/^.+\s.+$/.test(input.val())) {
				input.addClass("error-active");
				error = 1;
			}
			//var telreg = new RegExp(/^[0-9 \s \- \+](10,})$/);
			var telreg = new RegExp(/^(\+\d)*\s*(\(\d{10}\)\s*)*\d{10}(-{0,1})/);
			if (input.hasClass("tel")&&!telreg.test(input.val())) {
				input.addClass("error-active");
				error = 1;
			}
			if (input.hasClass("email-confirm")&&input.val()!=input.parents("div.fieldset").contents().find(".ident-check-field.email").val()&&input.parents("div.fieldset").contents().find(".ident-check-field.email").val()) {
				input.addClass("error-active");
				error = 1;
			}
			if (input.hasClass("password-confirm")&&input.val()!=input.parents("div.fieldset").contents().find(".ident-check-field.password").val()) {
				input.addClass("error-active");
				error = 1;
			}
			if (input.hasClass("radio")) {
				v = input.parent().children(":radio:checked").length?input.parent().children(":radio:checked").val():0;
				if (!v) {
					input.addClass("error-active");
					input.parent().addClass("error-active");
					error = 1;
				}
			}
			var tvareg = new RegExp(/^(RO\d{2,10}|GB\d{5}|(ATU|DK|FI|HU|LU|MT|CZ|SI)\d{8}|IE[A-Z\d]{8}|(DE|BG|EE|EL|LT|BE0|PT|CZ)\d{9}|CY\d{8}[A-Z]|(ES|GB)[A-Z\d]{9}|(BE0|PL|SK|CZ)\d{10}|(FR|IT|LV)\d{11}|(LT|SE)\d{12}|(NL|GB)[A-Z\d]{12})$/);
			if ((input.hasClass("tva")&&!tvareg.test(input.val()))&&(input.hasClass("ident-required")||input.val())) {
				input.addClass("error-active");
				error = 1;
			}

			if (separate) { compubase.identification.raiseError(input); }

			return error;
		},

		raiseError: function(input,ignore,fcase) {
			if (typeof ignore == "undefined") { ignore = 0; }
			if (typeof fcase == "undefined") { fcase = 0; }
			if (input.hasClass("error-active")||ignore) {
				fieldset = input.parents("div.fieldset");
				box = fieldset.children(".ident-check-error");
				if (fcase) { box = fieldset.children(".ident-check-error.case-"+fcase+"."+input.attr("id")); }
				text = input.parent().children(".ident-error-text").html();
				relto = input;
				if (input.hasClass("radio")) { relto = input.parent().eq(0); }
				notext = 0;

				if (box.hasClass("left")) {
					placement = { x: Math.floor(relto.offset().left+relto.outerWidth()-5)+"px", y: Math.floor(relto.offset().top-box.outerHeight()/2)+"px" }
				} else if (box.hasClass("right")) {
					placement = { x: Math.floor(relto.offset().left+relto.outerWidth()-10)+"px", y: Math.floor(relto.offset().top-box.outerHeight()/2+14)+"px" }
				}
				if (box.hasClass("external")) {
					placement = { x: Math.floor(box.outerWidth()*-1)+"px", y: Math.floor(fieldset.outerHeight()/2-box.outerHeight()/2)+"px" }
					notext = box.hasClass("notext") ? 1 : 0;
				}

				if (!notext) { $('.content',box).html(text); }
				box.css({left:placement.x,top:placement.y}).show();
			}
		},

		hideError: function(input) {
			input.parents(".fieldset").children(".ident-check-error").hide();
		},

		handleMisc: function() {
			$('select[class^=copy-to-]').change(function(e) {
				to = /copy-to-(.+)($|\s){1,}/.exec($(this).attr("class"))[1];
				$('#'+to).val($(this).val());
			});

			$('a.fonction-popup').click(function(e) {
				e.preventDefault();

				placement = { x: Math.floor($(this).offset().left+$(this).outerWidth()+10)+"px", y: Math.floor($(this).offset().top)+"px" }

				$('div.fonction-popup').css({"left":placement.x,"top":placement.y}).toggle();
			});

			$('div.fonction-popup .icon-close').click(function(e) {
				e.preventDefault();

				$('div.fonction-popup').hide();
			});

			$('div.fonction-popup input:checkbox').click(function() {
				$('div.fonction-popup input:checkbox').removeAttr("checked");
				$(this).attr("checked","checked");
			});

			$('div.fonction-popup a.save').click(function(e) {
				e.preventDefault();

				$('#position').val($('div.fonction-popup input:checkbox:checked').val());
				$('a.fonction-popup').html($('div.fonction-popup input:checkbox:checked').parent().children("span").html());

				$('div.fonction-popup').hide();
			});

			$('div.fonction-popup a.close').click(function(e) {
				e.preventDefault();

				$(this).parent().children("ul").toggle();
			});

			if ($('#email_confirmation').length) {
				$('#popup-prompt').css({"left":Math.floor($('#email_confirmation').offset().left+120)+"px","top":Math.floor($('#email_confirmation').offset().top-70)+"px"});
				$('#popup-prompt .non').click(function(e) { e.preventDefault(); $('#popup-prompt').hide(); });
			}
		},
		
		handleActions: function() {
			$('#reloadCapcha').click(function(e) {				
				e.preventDefault();
				location.reload();
			});
			
			
			$('.icon-help').hover(function(e) {				
				e.preventDefault();
				var help = $(this).attr("name");				
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(help);
					tools.fixPosBubble2(".icon-help", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
			
		},
	
		handleFakeSelect: function() {
			$('.ident-fake-select').click(function() {
				if (!$(this).hasClass("disabled")) {
					pos = {
						x: Math.floor($(this).offset().left)+"px",
						y: Math.floor($(this).offset().top+$(this).outerHeight())+"px",
						w: Math.floor($(this).outerWidth()-12)+"px"
					}
					$(this).parent().children('.ident-fakeselect-values').css({"top":pos.y,"left":pos.x,"width":pos.w}).toggle();
				}
			});
			
			$('.ident-fakeselect-values').mouseleave(function() {
				$(this).hide();
			});
			
			$('.ident-fakeselect-values li').click(function() {
				$('.ident-fakeselect-values').hide();
				$('.ident-fake-select input',$(this).parents('.ident-fakeselect-values').parent()).val($('a.value',this).attr("rel"));
				$('.ident-fake-select .text',$(this).parents('.ident-fakeselect-values').parent()).html($('.text',this).html());

				if ($('.ident-fake-select',$(this).parents('.ident-fakeselect-values').parent()).is("[class*=copy-to-]")) {
					to = /copy-to-(.*)($|\s){1,}/.exec($('.ident-fake-select',$(this).parents('.ident-fakeselect-values').parent()).attr("class"))[1];
					$('.ident-fake-select input[id='+to+']').val($('a.value',this).attr("rel"));
					$('.ident-fake-select input[id='+to+']').parent().children(".text").html($('.text',this).html());
				}
			});
			
			$('.ident-fakeselect-values li span').hover(function() {
				var help = $(this).html();	
				var current = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(help);
					tools.fixPosBubble2("#activity_form_list", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		}
	},
	
	infoRequester: {
		init: function() {
			this.handleRows();

			$('#info-requester tr').each(function() { $('td:last,th:last',this).addClass("last"); });
			$('#info-requester tr').each(function() { $('td:first',this).addClass("first"); });
			$('#info-requester tr').each(function() { $('td:eq(1)',this).addClass("width"); });

			$('#info-requester tr:not([th])').click(function() {
				if (!$(this).parents("#info-requester").hasClass("step2")) {
					if ($(this).is('.on')) {
						$(this).insertAfter($('#info-requester .sub').parent());
						$(this).removeClass('on');
						$('input',this).val("0");
						compubase.infoRequester.handleRows();
					} else {
						$(this).insertBefore($('#info-requester .sub').parent());
						$(this).addClass('on');
						$('input',this).val("1");
						compubase.infoRequester.handleRows();
					}
				}
			});

			$('.infor-show-all').click(function(e) {
				e.preventDefault();
				$('#info-requester .hide').show();
				$(this).hide();
				$('.infor-hide-all').show();
			});
			$('.infor-hide-all').click(function(e) {
				e.preventDefault();
				$('#info-requester .hide').not(".on").hide();
				$(this).hide();
				$('.infor-show-all').show();
			});

			$('#infor-step1-validate').submit(function() {
				//
			});
		},

		handleRows: function() {
			$('#info-requester tr:not([th])').removeClass("odd").removeClass("even");
			$('#info-requester tr:not([th]):odd').addClass("odd");
			$('#info-requester tr:not([th]):even').addClass("even");
		}
	},

	activitiesFilter: {
		init: function() {
			String.prototype.repeat = function(num) {
				return new Array(num+1).join(this);
			}
			String.prototype.trim = function () {
				return this.replace(/^\s*/, "").replace(/\s*$/, "");
			}

			this.handleSearchArea();
			if ($('.search-type .tabs a[name=searchByActivity]').parent().hasClass("current")) {
				$('#nomenclature-results-activity').show();
				compubase.activitiesFilter.tabActive = 1;
				compubase.activitiesFilter.keywordsId = $(this).attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-activity";

				$(compubase.activitiesFilter.keywordsId).parent().children(".keywords").hide();
				$(compubase.activitiesFilter.keywordsId).show();

				$(compubase.activitiesFilter.keywordsId).show();
				if ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") {
					compubase.activitiesFilter.setMode(2);
				} else if ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="MOTCLEF" || $(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="FILTER") {
					compubase.activitiesFilter.setMode(1);
				}
			}
			if ($('.search-type .tabs a[name=searchByCategoryProduct]').parent().hasClass("current")) {
				$('#nomenclature-results-categoryproduct').show();
				compubase.activitiesFilter.tabActive = 2;
				compubase.activitiesFilter.keywordsId = $('.search-type .tabs a[name=searchByCategoryProduct]').attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-categoryproduct";

				$(compubase.activitiesFilter.keywordsId).parent().children(".keywords").hide();
				$(compubase.activitiesFilter.keywordsId).show();

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			}
			
			if ($('.search-type .tabs a[name=searchByGeography]').parent().hasClass("current")) {
				$('#nomenclature-results-geography').show();
				compubase.activitiesFilter.tabActive = 1;
				compubase.activitiesFilter.keywordsId = $('.search-type .tabs a[name=searchByGeography]').attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-geography";

				$(compubase.activitiesFilter.keywordsId).parent().children(".keywords").hide();
				$(compubase.activitiesFilter.keywordsId).show();

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			}
			if ($('.search-type .tabs a[name=searchByProductResold]').parent().hasClass("current")) {
				$('#nomenclature-results-product-resold').show();
				compubase.activitiesFilter.tabActive = 1;
				compubase.activitiesFilter.keywordsId = $('.search-type .tabs a[name=searchByProductResold]').attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-product-resold";

				$(compubase.activitiesFilter.keywordsId).parent().children(".keywords").hide();
				$(compubase.activitiesFilter.keywordsId).show();

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			}
			if ($('.search-type .tabs a[name=searchByMarkets]').parent().hasClass("current")) {
				$('#nomenclature-results-markets').show();
				compubase.activitiesFilter.tabActive = 1;
				compubase.activitiesFilter.keywordsId = $('.search-type .tabs a[name=searchByMarkets]').attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-markets";

				$(compubase.activitiesFilter.keywordsId).parent().children(".keywords").hide();
				$(compubase.activitiesFilter.keywordsId).show();

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			}
			if ($('.search-type .tabs a[name=searchByTechnicalField]').parent().hasClass("current")) {
				$('#nomenclature-results-technical-field').show();
				compubase.activitiesFilter.tabActive = 1;
				compubase.activitiesFilter.keywordsId = $('.search-type .tabs a[name=searchByTechnicalField]').attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-technical-field";

				$(compubase.activitiesFilter.keywordsId).parent().children(".keywords").hide();
				$(compubase.activitiesFilter.keywordsId).show();

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			}
						
			this.handleMotClef();
			this.handleNomenclature();
		},

		tabActive: 0, // 0 - none, 1 - Activite, 2 - Categorie Produit
		mode: 2,		// 1 - mot clef, 2 - nomenclature
		keywordsId: '',
		nomenclResId: '',
		motclefFound: 0,
		mode1name: '',
		mode2name: '',

		setMode: function(mode) {
			this.mode = mode;
						
			$(this.nomenclResId+' .nomenclature-mode').hide();

			$(compubase.activitiesFilter.keywordsId+' a').removeClass("current");
			if (this.mode==1) {
				$(compubase.activitiesFilter.keywordsId+' a[name=MOTCLEF], '+compubase.activitiesFilter.keywordsId+' a[name=FILTER]').addClass("current");
				$(this.nomenclResId+' .mode-MOTCLEF, '+this.nomenclResId+' .mode-FILTER').show();
			} else if (this.mode==2) {
				$(compubase.activitiesFilter.keywordsId+' a[name=NOMENCLATURE]').addClass("current");
				$(this.nomenclResId+' .mode-NOMENCLATURE').show('slow');
				
				//added mohsaa
				/*setTimeout(function(){
					$('.nomenclature-results .mode-NOMENCLATURE').toggleClass("off");
					$('.nomenclature-results .mode-NOMENCLATURE').parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .list').slideToggle("2000");
					$('.nomenclature-results .mode-NOMENCLATURE a.hide-link').toggleClass("off");
				}, 5000);*/
			}

			if (this.mode==2) {
				$('.search-zone').hide();
				$('.search-zone-fake').show();
			}
			else {
				$('.search-zone').show();
				$('.search-zone-fake').hide();
			}
		},

		handleSearchArea: function() {
			$('.search-type .tabs a[name=searchByActivity]').click(function() {
				$('#nomenclature-results-activity').show();
				compubase.activitiesFilter.tabActive = 1;
				compubase.activitiesFilter.keywordsId = $(this).attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-activity";

				if ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") {
					compubase.activitiesFilter.setMode(2);
				} else if ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="MOTCLEF" || $(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="FILTER") {
					compubase.activitiesFilter.setMode(1);
				}
			});

			$('.search-type .tabs a[name=searchByCategoryProduct]').click(function() {
				$('#nomenclature-results-categoryproduct').show();
				compubase.activitiesFilter.tabActive = 2;
				compubase.activitiesFilter.keywordsId = $(this).attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-categoryproduct";

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			});

			$('.search-type .tabs a[name=searchByGeography]').click(function() {
				$('#nomenclature-results-geography').show();
				compubase.activitiesFilter.tabActive = 2;
				compubase.activitiesFilter.keywordsId = $(this).attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-geography";

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			});
			$('.search-type .tabs a[name=searchByProductResold]').click(function() {
				$('#nomenclature-results-product-resold').show();
				compubase.activitiesFilter.tabActive = 2;
				compubase.activitiesFilter.keywordsId = $(this).attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-product-resold";

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			});
			
			$('.search-type .tabs a[name=searchByMarkets]').click(function() {
				$('#nomenclature-results-markets').show();
				compubase.activitiesFilter.tabActive = 2;
				compubase.activitiesFilter.keywordsId = $(this).attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-markets";

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			});
			
			$('.search-type .tabs a[name=searchByTechnicalField]').click(function() {
				$('#nomenclature-results-technical-field').show();
				compubase.activitiesFilter.tabActive = 2;
				compubase.activitiesFilter.keywordsId = $(this).attr("href");
				compubase.activitiesFilter.nomenclResId = "#nomenclature-results-technical-field";

				var mode = ($(compubase.activitiesFilter.keywordsId+' a.current').attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			});

			
			$('.nomenclature-keywords a').unbind("click");
			$('.nomenclature-keywords a').click(function(e) {
				e.preventDefault();

				if(jQuery(this).hasClass(".inactif")) return false;
				
				jQuery(this).parent().children("a").removeClass("current");
				jQuery(".search-type #search-type-1-categorie").val(jQuery(this).attr("name"));
				jQuery(this).addClass("current");

				var mode = ($(this).attr("name")=="NOMENCLATURE") ? 2 : 1;
				compubase.activitiesFilter.setMode(mode);
			});

			$('form[name=searchForm]').submit(function() {
				if (compubase.activitiesFilter.tabActive>0 && compubase.activitiesFilter.mode==1) {
						compubase.activitiesFilter.startSearch($('#search-type-1-nodecodeField').val());
						
					return false;
				}
			});

		},

		handleMotClef: function() {
			$('.activities-tree').children("li").css("padding-left","0");

			$('.activities-tree li').click(function(e) {
				e.preventDefault();
				e.stopPropagation();

				compubase.activitiesFilter.listNomenclature($(this));
				compubase.activitiesFilter.setMode(2);
				$(this).parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .list').show();
				$(this).parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .close').removeClass("off");

				compubase.activitiesFilter.updateSearchResults($(this).children('a').attr("rel"));
			});

			$('.nomenclature-results .mode-MOTCLEF a.close, .nomenclature-results .mode-FILTER a.close').click(function(e) {
				e.preventDefault();

				$(this).toggleClass("off");
				$(this).parents('.nomenclature-results').contents().find('.activities-tree').toggle();
			});
			$('.nomenclature-results .mode-MOTCLEF a.close').parents("[class^=mode-]").each(function() {
				var timer = null;
				$(this).hover(
					function() {
						if (!$('.activities-tree',this).is(":animated")) {
							$('a.close',this).removeClass("off");
							$('.popup-detail',this).hide();
							$('.activities-tree',this).stop().slideDown();
							clearTimeout(timer);
						}
					},
					function() {
						that = $(this);
						var hh = function() {
							$('a.close',that).addClass("off");
							$('.popup-detail',that).show();
							$('.activities-tree',that).stop().slideUp();
						}
						timer = setTimeout(hh,2000);
					}
				);
			});
		},
		startSearch: function(keyword) {
			if (keyword.trim().length>=3) {
				$(this.nomenclResId+' .activities-tree li').hide();
				this.motclefFound = 0;
				$(this.nomenclResId+' .motclef-mode-notfound').hide();

				$(this.nomenclResId+' .mode-MOTCLEF .search-string span, '+this.nomenclResId+' .mode-FILTER .search-string span').html(keyword);

				this.searchTree($(this.nomenclResId+' .activities-tree'),keyword,0);

				if (this.motclefFound==0) { $(this.nomenclResId+' .motclef-mode-notfound').show(); }
			}
		},
		searchTree: function(tree,keyword,level) {
			var children = tree.children();

			for (var i=0;i<children.length;i++) {
				if (children.eq(i).children("ul").length) {
					this.searchTree(children.eq(i).children("ul"),keyword,level+1);
				}
			
				var text = children.eq(i).children("a").html();
				var found = (text.toLowerCase().indexOf(keyword.toLowerCase())!=-1) ? 1 : 0;
				if (found) {
					this.motclefFound++;
					this.returnParents(children.eq(i),level);
				}
			}
		},
		returnParents: function(element) {
			element.show();
			if (!element.parent().hasClass("activities-tree")) {
				this.returnParents(element.parent());
			}
		},

		handleNomenclature: function() {
			curitem1 = ($(".search-type #search-type-1-nodecodeField").val()&&$('#nomenclature-results-activity a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').length) ? $('#nomenclature-results-activity a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').parent() : $('#nomenclature-results-activity .activities-tree-root');
			curitem2 = ($(".search-type #search-type-1-nodecodeField").val()&&$('#nomenclature-results-categoryproduct a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').length) ? $('#nomenclature-results-categoryproduct a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').parent() : $('#nomenclature-results-categoryproduct .activities-tree-root');
			curitem3 = ($(".search-type #search-type-1-nodecodeField").val()&&$('#nomenclature-results-geography a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').length) ? $('#nomenclature-results-geography a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').parent() : $('#nomenclature-results-geography .activities-tree-root');
			curitem4 = ($(".search-type #search-type-1-nodecodeField").val()&&$('#nomenclature-results-product-resold a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').length) ? $('#nomenclature-results-product-resold a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').parent() : $('#nomenclature-results-product-resold .activities-tree-root');
			curitem5 = ($(".search-type #search-type-1-nodecodeField").val()&&$('#nomenclature-results-markets a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').length) ? $('#nomenclature-results-markets a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').parent() : $('#nomenclature-results-markets .activities-tree-root');
			curitem6 = ($(".search-type #search-type-1-nodecodeField").val()&&$('#nomenclature-results-technical-field a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').length) ? $('#nomenclature-results-technical-field a[rel=activity_'+$(".search-type #search-type-1-nodecodeField").val()+']').parent() : $('#nomenclature-results-technical-field .activities-tree-root');
			if ($('#nomenclature-results-activity .activities-tree-root').length) { this.listNomenclature(curitem1); }
			if ($('#nomenclature-results-categoryproduct .activities-tree-root').length) { this.listNomenclature(curitem2); }
			if ($('#nomenclature-results-geography .activities-tree-root').length) { this.listNomenclature(curitem3); }
			if ($('#nomenclature-results-product-resold .activities-tree-root').length) { this.listNomenclature(curitem4); }
			if ($('#nomenclature-results-markets .activities-tree-root').length) { this.listNomenclature(curitem5); }
			if ($('#nomenclature-results-technical-field .activities-tree-root').length) { this.listNomenclature(curitem6); }
			
			$('.nomenclature-results .mode-NOMENCLATURE a.hide-link').click(function(e) {
				e.preventDefault();

				$(this).toggleClass("off");
				$(this).parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .list').toggle();
			});
			$('.nomenclature-results .mode-NOMENCLATURE a.hide-link').parents(".mode-NOMENCLATURE").each(function() {
				var timer = null;
				$(this).hover(
					function() {
						if (!$('.list',this).is(":animated")) {
							$('a.hide-link',this).removeClass("off");
							$('.popup-detail',this).hide();
							$('.list',this).stop().slideDown();
							clearTimeout(timer);
						}
					},
					function() {
						that = $(this);
						var hh = function() {
							$('a.hide-link',that).addClass("off");
							$('.popup-detail',that).show();
							$('.list',that).stop().slideUp();
						}
						timer = setTimeout(hh,2000);
					}
				);
			});
		},
		listNomenclature: function(item) {
			col_number = 3;

			html = "<tr>";
			
			chldr = item.children("ul").children();

			len = chldr.length;
			j = 0;
			columns = new Array();
			count = len;
			per_column = Math.ceil(len/col_number);
			for (i=0;i<col_number;i++) {
				val = (count>=per_column) ? per_column : count;
				count = count - val;
				columns.push(val);
			}

			var c = 0;
			for (i=0;i<columns.length;i++) {
				html += "<td><table cellspacing=\"0\">";
				if (columns[i]) {
					for (j=0;j<columns[i];j++) {
						html += "<tr><td><a href=\"\" rel=\""+$('a',chldr.eq(c)).attr("rel")+"\">"+$('a',chldr.eq(c)).html()+"</a></td><td class=\"number\">"+$("div",chldr.eq(c)).html()+"</td></tr>";
						c++;
					}
				} else {
					html += "<tr><td></td></tr>";
				}
				html += "</table></td>";
			}

			html += "</tr>";

			$(item).parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .list').html(html);

			this.makeBreadcrumbs(item,0,"");
			this.handleNomenclatureLinks();
		},
		makeBreadcrumbs: function(li,level,breadcrumbs) {
			if (li.parent().attr("class")=="activities-tree-top") {
				if (level==0) { li.parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .breadcrumbs span.links').html(li.children('a').html()); }
				else { li.parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .breadcrumbs span.links').html('<a href="" rel="activity_root">'+li.children('a').html()+'</a> &gt; '+breadcrumbs); }
			}
			arr = (level>0) ? " &gt; " : "";
			b_tmp = li.children("a").html();
			if (level==0 && li.children("ul").length) {
				b_tmp = '<span>'+li.children("a").html()+'</span>';
			}
			if (level>0) {
				b_tmp = '<a href="" rel="'+li.children("a").attr("rel")+'">'+li.children("a").html()+'</a>';
			}

			breadcrumbs = b_tmp+arr+breadcrumbs;

			if (li.parent().attr("class")!=("activities-tree-top")) {
				this.makeBreadcrumbs(li.parents("li").eq(0),1,breadcrumbs);
			}
		},
		handleNomenclatureLinks: function() {
			$('.mode-NOMENCLATURE .breadcrumbs .links a, .mode-NOMENCLATURE .list a').click(function(e) {
				e.preventDefault();

				compubase.activitiesFilter.listNomenclature($(this).parents('.nomenclature-results').contents().find('.activities-tree-top a[rel='+$(this).attr("rel")+']').parent());
				$(this).parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .list').show();
				$(this).parents('.nomenclature-results').contents().find('.mode-NOMENCLATURE .close').removeClass("off");

				compubase.activitiesFilter.updateSearchResults($(this).attr("rel"));
			});
		},

		updateSearchResults: function(rel) {
			var nodecode =/activity_(.*)/.exec(rel)[1];
				jQuery(".search-type #search-type-1-nodecodeField").val(nodecode);
				jQuery(".search-type form").submit();
				//finalUrl="jsp/compubase/search/Ajax/searchProductCategoryResult.jsp?idnomeclature="+/activity_(.*)/.exec(rel)[1];
				//jQuery("#result-search table").setGridParam({url:finalUrl}).trigger("reloadGrid");
		}

	},
	
	aFiche: {
		init: function() {
			this.handleTabs();
			this.handleRadio();
			this.handleForms();
			this.handleHints();
		},

		handleTabs: function() {
			$('.afiche-tabs- > div').click(function() {
				$(this).parent().children().removeClass("act");
				$(this).addClass("act");

				$('.afiche-tabs-contents').hide();
				$('#afiche-tabs-'+$('a',this).attr("rel")).show();

				$('.afiche-subtotal .right dl').hide();
				$('#afiche-subtotal-'+$('a',this).attr("rel")).show();

				$('.afiche-subtotal .help').toggle();
			});

			$('.afiche-subtotal .lampe').click(function(e) {
				e.preventDefault();

				$('#afiche-tab1-popup').toggle();
			});
			$('#afiche-tab1-popup a').click(function(e) {
				e.preventDefault();

				$('#afiche-tab1-popup').hide();
				$('.afiche-tabs- a[rel=formule]').parent().click();
			});
		},
		handleRadio: function() {
			if ($('.afiche-checkbox-table .checkbox-cell input:checked').length) {
				$('.afiche-checkbox-table .checkbox-cell input:checked').each(function() {
					$("#"+$(this).parents(".afiche-tabs-contents").attr("id").replace("tabs","subtotal")+" dd.total span").html($(this).next().attr("rel"));
				});
			}

			$('.afiche-checkbox-table .checkbox-cell input').click(function() {
				$("#"+$(this).parents(".afiche-tabs-contents").attr("id").replace("tabs","subtotal")+" dd.total span").html($(this).next().attr("rel"));
				$("#depthPrice").val($(this).next().attr("rel"));
				$("#depthLabel").val($(this).next().attr("name"));
			});

			$('.afiche-payment-list input').click(function() {
				$('#afiche-payment').attr("src",$(this).parents("tr").eq(0).contents().find("img").attr("src"));
			});
			
			if ($("#payment-method-form input:radio:checked")) {
				$('#afiche-payment').attr("src",$("#payment-method-form input:radio:checked").parents("tr").eq(0).contents().find("img").attr("src"));
			}
			
			$('#payment-method-form input:radio').click(function() {
				$('#payment-error').hide();
			});
		},
		handleForms: function() {
			/*$('#command-submit').click(function(e) {
				e.preventDefault();
				$('#command-form').submit();
			});*/
			$('#command-submit').click(function(e) {
				if (!$('#command-form .form-element-accept').is(":checked")) {
					$('#command-form-error').show();
					return false;
				}
			});

			$('#command-form').submit(function() {
				if (!$('#command-form .form-element-accept').is(":checked")) {
					$('#command-form-error').show();
					return false;
				}
			});

			$('#afiche-add-to-cart').click(function(e) {
				e.preventDefault();
				$('.afiche-tabs-contents:visible form').submit();
			});
			
			$('#purchaseForm').submit(function() {
				if (!$('input:radio:checked',this).length) {
					$('div[class^=afiche-red-error]',this).show();
					$('html, body').animate({scrollTop: $('div[class^=afiche-red-error]',this).offset().top-30}, 1000);

					return false;
				}
			});
			
			$('.afiche-tabs-contents form').submit(function() {
				if ($(this).parents('.afiche-tabs-contents').eq(0).hasClass("payments")) {
					if (!$('input:radio:checked',this).length) {
						return false;
					} 
				}
				
				if (!$('input:radio:checked',this).length) {
					$('div[class^=afiche-red-error]',this).show();
					$('html, body').animate({scrollTop: $('div[class^=afiche-red-error]',this).offset().top-30}, 1000);

					return false;
				}
			});

			$('.order-datsheet-tabs form').submit(function() {
				if (!$('input:radio:checked',this).length) { $('div[class^=afiche-red-error]',this).show(); return false; }				
				if (typeof $('#currentCartLineItemIndex').attr("rel") != "undefined")
					$("#orderCartLineItemIndex").val($("#currentCartLineItemIndex").attr("rel"));
				//$("#orderCartLineItemIndex").val($("#currentCartLineItemIndex").attr("rel"));
			});
					
			$('.afiche-tabs-contents form').each(function() {
				if ($(this).parents('.afiche-tabs-contents').eq(0).hasClass("payments")) {
					if (!$('input:radio:checked',this).length) {
						return false;
					}
				}
				$(this).submit(function() {
					if (!$('input:radio:checked',this).length) {
						$('div[class^=afiche-red-error]',this).show();
						$('html, body').animate({scrollTop: $('div[class^=afiche-red-error]',this).offset().top-30}, 1000);

						return false;
					}
				});
			});
			
			$('.afiche-tabs-contents input:radio').click(function() {
				$(this).parents('.afiche-tabs-contents').eq(0).contents().find('div[class^=afiche-red-error]').hide();
			});

			$('#payment-method-form').submit(function() {
				if(!$('input:radio:checked',this).length) { 
					$('#payment-error').show();
					return false;
					}
				});
		},
		handleHints : function() {
			var timer = null;
			$('.afiche-icon-info').hover(function(e) {
				e.preventDefault();
				var info = jQuery(this).attr("name");				
				var currentId = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble7("#"+currentId, "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 1000);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		}
	},
	studies: {
		init: function() {
			this.handleTabs();
			this.handleList();
			this.handleInfo();
			this.handleOptions();
		},

		handleTabs: function() {
			$('.studies-tabs- > div').click(function() {
				$(this).parent().children().removeClass("act");
				$(this).addClass("act");

				$('.studies-tabs-contents').hide();
				$('#studies-tabs-'+$('a',this).attr("rel")).show();
				
				/*
				$('#studies-subtotal-'+$('a',this).attr("rel")).parent().children().hide();
				$('#studies-subtotal-'+$('a',this).attr("rel")).show();
				*/
			});
		},

		handleList: function() {
		/*	$('.studies-list tr:gt(0)').each(function() {
				$(this).click(function() {
					location.href = $(this).contents().find("a.info").attr("href");
				});

				$(this).contents().find("a.info").click(function(e) {
					e.preventDefault();
				});

				price = 0;
				$('.studies-list .act span.price').each(function() {
					price += parseInt($(this).html());
				});

				$('#studies-subtotal-list .total span').html(price);
			});*/

						
			var timer = null;
			$('.studies-list .remove a').hover(function(e) {
				e.preventDefault();
				var info = jQuery(this).attr("name");				
				var currentId = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble6("#icon-list-remove", "#msg-hints");
					jQuery("#msg-hints").show();
					jQuery("#msg-error").hide();
				}, 0);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
					
				
		},

		handleInfo: function() {
			$('.study-moreinfo-link a.more').click(function(e) {
				e.preventDefault();

				$('.study-moreinfo').show();
				$('.study-moreinfo-link a.less').show();
				$(this).hide();
			});

			$('.study-moreinfo-link a.less').click(function(e) {
				e.preventDefault();

				$('.study-moreinfo').hide();
				$('.study-moreinfo-link a.more').show();
				$(this).hide();
			});

			$('.study-list-more a.more').click(function(e) {
				e.preventDefault();

				$('.studies-list tr.less').show();
				$('.study-list-more a.less').show();
				$(this).hide();
			});

			$('.study-list-more a.less').click(function(e) {
				e.preventDefault();

				$('.studies-list tr.less').each(function() {
					if (!$(this).hasClass("act")) { $(this).hide(); }
				});
				$('.study-list-more a.more').show();
				$(this).hide();
			});
		},

		handleOptions: function() {
			compubase.studies.updatePrices();

			if ($('#study-options-check').is(":checked")) { $('.study-options-list input:radio').removeAttr("disabled"); }

			$('#study-options-check').click(function() {
				if ($(this).is(":checked")) {
					$('.study-options-list input:radio').removeAttr("disabled").removeClass("hide");
				} else {
					$('.study-options-list input:radio').attr("disabled","disabled").addClass("hide");
				}

				compubase.studies.updatePrices();
			});
			
			$('.study-options-list input:radio').click(function() {
				compubase.studies.updatePrices();
			});
		},

		updatePrices: function() {
			price = 0;
			priceOptions = 0;

			//$('.study-prices-box.first td span').each(function() {
			$('.study-prices-box.first .total-ht').each(function() {
				price += parseFloat($(this).html().replace(",", "."));
			});
			
			$('.study-options-list input:radio:checked').not(":disabled").each(function() {
				p = $(this).parents("tr").eq(0).contents().find(".price").attr("rel");
				priceOptions += parseFloat($(this).parents("tr").eq(0).contents().find(".price").attr("rel").replace(",", "."));
			});			
			
			$('.study-prices-box.final th:eq(0) span').html($('.study-options-list input:radio:checked').not(":disabled").length);
			$('.study-prices-box.final td:eq(0) span').html(priceOptions);
			$('.study-prices-box.final .total span').html((price+priceOptions).toFixed(2));
			$('#service-order-totalextax').val((price+priceOptions).toFixed(2));
		}
	},

	zoomImages: {
		init: function() {
			$('a.imagezoom').not('.applied').each(function() {
				var timer = null;
				var el = $(this);
				$(this).addClass('applied').hover(
					function() {
						timer = setTimeout(function() { el.click(); },3000);
					},
					function() {
						clearTimeout(timer);
					}
				).zoomimage({'controls':false});
			});
			
			var timer = null;
			$('.imagezoom').hover(function(e) {
				e.preventDefault();
				var info = jQuery("#cpb_biz_image_zoom_hint_message").html();
				var currentId = this.id;
				timer = setTimeout(function(){
					jQuery("#msg-hints p").html(info);
					tools.fixPosBubble6("#"+currentId , "#msg-hints");
					jQuery("#msg-hints").show();
				}, 0);
			}, function(){
				clearTimeout(timer);
				jQuery("#msg-hints").hide();
			});
		}
	},
	//end oleg js
	common: function(){
		if(jQuery(".zone-login-error-abo").size() > 0 || jQuery(".zone-login-logged").size() < 1) jQuery(".swap-value-login-box").toggleVal();
		jQuery(".swap-value").toggleVal();
		jQuery(".block-type-1").roundCorners({ corner1: '<span class="corner-l-b"><img src="img/corner-type-1-l-b.gif" alt="" /></span>', corner2: '<span class="corner-r-b"><img src="img/corner-type-1-r-b.gif" alt="" /></span>' });
		jQuery(".block-vouscherchez").each(function() {
			if (!$(this).hasClass("vousetes")) {
				$(this).roundCorners({ corner1: '<span class="corner-l-b"><img src="img/corner-type-1-l-b.gif" alt="" /></span>', corner2: '<span class="corner-r-b"><img src="img/corner-type-1-r-b.gif" alt="" /></span>' });
			} else {
				var altWholesallers = jQuery("#seo_wholesalers_resellers").html();
				var altCompuScience = jQuery("#seo_compu_sicence_platform").html();
				$(this).roundCorners({ corner1: '<span class="corner-l-b"><img src="img/plateforme_informatique.gif" alt="'+altCompuScience+'" /></span>', corner2: '<span class="corner-r-b"><img src="img/grossistes_revendeurs.gif" alt="'+altWholesallers+'" /></span>' });
			}
		});
		jQuery(".block-links").roundCorners({ corner1: '<span class="corner-l-t"><img src="img/corner-links-l-t.gif" alt="" /></span>', corner2: '<span class="corner-r-b"><img src="img/corner-links-r-b.gif" alt="" /></span>' });
		jQuery(".search-type form").roundCorners({ corner1: '<span class="corner-l-b"><img src="img/corner-search-l-b.gif" alt="" /></span>', corner2: '<span class="corner-r-b"><img src="img/corner-search-r-b.gif" alt="" /></span>' });
		
		jQuery.ifixpng('img/pix.gif');
		jQuery('img[src$=.png]').ifixpng();
	}
};

var errors = {
	error: false,
	errorElt: [],
	showError: function(elt){
		jQuery(elt).addClass("error");
		this.errorElt.push(elt.substr(1));
		this.error = true;
	},
	resetError: function(elt){
		jQuery(elt + " input, " + elt + " select").removeClass("error");
		jQuery("#zone-login .content .case-error p, #login-error-email-2").hide();
		for(i=0; i<this.errorElt.length; i++)
			jQuery("#login-error-" + current.errorElt[i]).hide();
		this.errorElt = [];
	},
	checkEmail: function(elt){
		var reg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		if( !reg.test(jQuery(elt).val()) ){ this.showError(elt); }
	},
	checkEmail2: function(elt){
		var reg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return ( !reg.test(jQuery(elt).val()) ) ? false : true;
	},
	checkTel: function(elt){
		var reg = new RegExp("^[0-9]{3}");
		if( !reg.test(jQuery(elt).val()) ){ this.showError(elt); }
	},
	checkLength: function(elt, lng){
		val = jQuery(elt).val();
		val = tools.trim(val);
		return ( val.length >= lng ) ? false : true;
	},
	checkWords: function(elt, words){
		val = jQuery(elt).val();
		val = tools.trim(val);
		nbWords = val.split(" ");
		return ( nbWords.length <= words ) ? false : true;
	},
	loginBox: function(elt){
		current = this;
		
		var defaultValues = {
			email: "Votre email",
			password: "Votre Mot de passe"
		}
		
		jQuery(elt).submit(function(){
			current.error = false;
			current.resetError(elt);
			
			jQuery("#email").val() == "" ? current.showError("#email") : current.checkEmail("#email");
			if( jQuery("#password").val() == "" || jQuery("#password").val() == defaultValues.password ){ current.showError("#password"); }
			
			if(current.error){
				jQuery("#zone-login .content .case-error ul").show();
				
				jQuery("#zone-login").addClass("zone-login-error");
				jQuery("#zone-login .content .case-open, #zone-login .content .case-close, #zone-login .content .case-error, #zone-login .content .case-error-2").hide();
				
				if(jQuery("#zone-login .content .case-error-2").size() > 0)
					jQuery("#zone-login .content .case-error-2").show();
				else
					jQuery("#zone-login .content .case-error").show();
				
				
				for(i=0; i<current.errorElt.length; i++){					
					if(jQuery("#password").val() == "" && jQuery("#email").val() == ""){
						jQuery("#login-error-email-2").show();
						jQuery("#login-error-" + current.errorElt[i]).show();
						jQuery("#login-error-email").hide();											
					}					
					if(jQuery("#email").val() != ""){
						if(!current.checkEmail2("#email")){
							jQuery("#login-error-title").hide();
							jQuery("#login-error-email").show();
						}else{								
							if(jQuery("#password").val() == ""){
								jQuery("#login-error-title").show();
								jQuery("#login-error-password").show();
							}
						}
					}					
				}
			}
			return current.error ? false : true;
		});
	},
	search: function(elt){
		var current = this;
		compubase.search.defaultValue = jQuery("#search-type-3 .input-text").val();
		
		jQuery(".search-type .input-text").bind("keypress", function(){
			jQuery("#msg-error").hide();
			jQuery(this).removeClass("error");
		});
		
		jQuery("#msg-error").click(function(){
			jQuery("#msg-error").hide();
			jQuery(".search-type .input-text").removeClass("error");			
		});
		
		////added by mohand
		jQuery(".block-vouscherchez .text").bind("keypress", function(){
			jQuery("#msg-error").hide();
			jQuery(this).removeClass("error");
		});
		////added by mohand
		jQuery(elt).submit(function(){
			current.error = false;
			current.resetError(elt);
			jQuery("#msg-error, #msg-hints").hide();
			
			//if(jQuery(".search-type .input-text").val() == ""){
				//current.showError(".search-type .input-text");
				//jQuery("#msg-error p").html(errorsMsg.error7());
			//}else
				if(jQuery(".search-type .input-text").val() == compubase.search.defaultValue) {
				current.showError(".search-type .input-text");
				jQuery("#msg-error p").html(errorsMsg.error8());
			}			
			else {
				//testLength = current.checkLength(".search-type .input-text", errorsValues[errorsValue][0]);
				//if(testLength){
					//jQuery("#msg-error p").html(errorsMsg.error2(errorsValues[errorsValue][0]));
					//current.showError(".search-type .input-text");
					//current.error = true;
				//}
				
				testWords = current.checkWords(".search-type .input-text", errorsValues[errorsValue][2]);
				if(testWords){
					jQuery("#msg-error p").html(errorsMsg.error1(errorsValues[errorsValue][2]));
					current.showError(".search-type .input-text");
					current.error = true;
				}
			}
			
			if(current.error){
				tools.fixPosBubble(".search-type .input-text", "#msg-error");
			}
			
			return current.error ? false : true;
		});
	
	}
};

var tools = {
	stateArrow: function(elt){
		src = jQuery("img", elt).attr("src");
		if(typeof src != "undefined"){
			if(src.indexOf("icon-close-b") != -1){
				src = src.replace("icon-close-b", "icon-close");
			} else {
				src = src.replace("icon-close", "icon-close-b");
			}
			jQuery("img", elt).attr({ src: src });
		}
	},
	trim: function(str){
		return str.replace(/^\s+/g,'').replace(/\s+$/g,'')
	},
	fixPosBubble: function(from, to){
		widthFrom = jQuery(from).outerWidth();
		jQuery(to).css({ width: widthFrom + "px" }).show();
		
		widthFromTable = jQuery(to + " table").outerWidth();
		jQuery(to).css({ width: widthFromTable+1 + "px" }).show();
		
		posFrom = jQuery(from).offset();
		heightTo = jQuery(to).outerHeight();
		
		if (posFrom) { jQuery(to).css({ top: (posFrom.top-heightTo-5) + "px", left: posFrom.left + "px" }).show(); }		
	},	
	fixPosBubble2: function(from, to){
		widthFrom = 115;
		jQuery(to).css({ width: widthFrom + "px" }).show();
		
		widthFromTable = 223;
		jQuery(to).css({ width: widthFromTable+1 + "px" }).show();
		
		posFrom = jQuery(from).offset();
		heightTo = jQuery(to).outerHeight();
		
		jQuery(to).css({ top: (posFrom.top-heightTo-5) + "px", left: posFrom.left + "px" }).show();
	},	
	fixPosBubble3: function(from, to){
		widthFrom = 115;
		jQuery(to).css({ width: widthFrom + "px" }).show();
		
		widthFromTable = 120;
		jQuery(to).css({ width: widthFromTable+1 + "px" }).show();
		
		posFrom = jQuery(from).offset();
		heightTo = jQuery(to).outerHeight();
		
		jQuery(to).css({ top: (posFrom.top-heightTo-5) + "px", left: posFrom.left + "px" }).show();
	},
	fixPosBubble4: function(from){
		from = '#datasheet-action-'+from;
		posFrom = jQuery(from).offset();
		posFrom.left = posFrom.left + Math.floor(jQuery(from).outerWidth()/2) - Math.floor($('#datasheet-action-hint').outerWidth()/2);
		posFrom.top = posFrom.top + Math.floor(jQuery(from).outerHeight()/2) - Math.floor($('#datasheet-action-hint').outerHeight()/2);

		jQuery('#datasheet-action-hint').css({ top: posFrom.top + "px", left: posFrom.left + "px" }).show();
	},
	fixPosBubble5: function(from){
		if ($('#datasheet-dropdown').is(":hidden")) {
			posFrom = jQuery(from).offset();
			posFrom.top = posFrom.top + $(from).innerHeight() + 5;

			jQuery('#datasheet-dropdown').css({ top: posFrom.top + "px", left: posFrom.left + "px" }).show();
		} else {
			$('#datasheet-dropdown').hide();
		}
	},	
	fixPosBubble6: function(from, to){
		widthFrom = 115;
		jQuery(to).css({ width: widthFrom + "px" }).show();
		
		widthFromTable = 100;
		jQuery(to).css({ width: widthFromTable+1 + "px" }).show();
		
		posFrom = jQuery(from).offset();
		heightTo = jQuery(to).outerHeight();
		
		jQuery(to).css({ top: (posFrom.top-heightTo-5) + "px", left: posFrom.left + "px" }).show();
	},
	fixPosBubble7: function(from, to){
		widthFrom = 115;
		jQuery(to).css({ width: widthFrom + "px" }).show();
		
		widthFromTable = 300;
		jQuery(to).css({ width: widthFromTable+1 + "px" }).show();
		
		posFrom = jQuery(from).offset();
		heightTo = jQuery(to).outerHeight();
		
		jQuery(to).css({ top: (posFrom.top-heightTo-5) + "px", left: (posFrom.left -300)+ "px"}).show();
	}
};

//added by mohsaa

function confirm(message, callback) {
	$('#confirm').modal({	
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'confirm-overlay',
		containerId:'confirm-container', 
		onShow: function (dialog) {
			$(".message", dialog.data[0]).append(message);

			// if the user clicks "yes"
			$(".yes", dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}

function displayView(view) {
	jQuery("#ds-dropdown-actList a.views").removeClass("on");
			jQuery(".tools-container a.views").removeClass("on");
			jQuery(".tools-container a."+view ).addClass("on");
			switch(view){
				case "view1":
					//jQuery("#table-results table").removeClass("table-view-2 table-view-3");
					jQuery("#table-results table .jqgrow input:checkbox:checked").parents("tr").contents().find(".view2").hide();
					jQuery("#table-results table .jqgrow input:checkbox:checked").parents("tr").contents().find("span.strong").css("font-weight","normal");
					//jQuery("#table-results table").addClass("table-view-1");
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").next().find(".minifiche").hide();
					//if (!jQuery("#table-results .jqgrow input:checkbox").not(":checked").length) {
					//	jQuery("#table-results table").removeClass("table-view-3");
					//}
					jQuery(".grid_hdiv").show();
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").show();


					/*jQuery("#table-results table").removeClass("table-view-2 table-view-3");
					jQuery("#table-results table").addClass("table-view-1");
					jQuery("#table-results .minifiche").hide();
					jQuery(".grid_hdiv").show();
					jQuery(".minificheContainer").prev().show();*/

					break;
				case "view2":
					//jQuery("#table-results table").removeClass("table-view-1 table-view-3");
					//jQuery("#table-results table").addClass("table-view-2");
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").next().find(".minifiche").hide();
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").show();
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").contents().find("span.strong").css("font-weight","bold");
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").contents().find(".view2").show();
					//jQuery("#table-results .minifiche").hide();
					jQuery(".grid_hdiv").show();
					//jQuery(".minificheContainer").prev().show();
					break;
				case "view3":
					//jQuery("#table-results table").removeClass("table-view-1 table-view-2");
					//jQuery("#table-results table").addClass("table-view-3");
					//jQuery("#table-results .minifiche").show();
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").next().find(".minifiche").show();
					jQuery("#table-results .jqgrow input:checkbox:checked").parents("tr").hide();
					if (!jQuery("#table-results .jqgrow:visible").length) {
						jQuery(".grid_hdiv").hide();
					}
					//jQuery(".minificheContainer").prev().hide();
					break;
			}
	
	};