function revendeurs(departement){
	window.frames['carte'].location.href = "/float/revendeurs.php?dep="+departement;
}

function dsb_field(th_slt,opt_val,formulaire,champ){
	if(th_slt.value == 	opt_val){
		disabledMod	=	false;
	}else{
		disabledMod	=	true;
	}
	document.forms[formulaire].elements[champ].disabled =	disabledMod
}

function dsp_tr(tr_id){
	if(navigator.appName.indexOf("Internet Explorer") != -1){
		dsp_block 	= "block";
	}else{
		dsp_block 	= "table-row";
	}	
	
	tr_dsp			=	document.getElementById(tr_id).style.display
	if(tr_dsp		== 	'none' || tr_dsp		== 	''){
		dsp_mod		=	dsp_block
	}else{
		dsp_mod		=	'none';
	}
	document.getElementById(tr_id).style.display = dsp_mod
}

function basename(path, suffix) {
	var b = path.replace(/^.*[\/\\]/g, '');
	if (typeof(suffix) == 'string' && b.substr(-suffix.length) == suffix) {
   	    b = b.substr(0, b.length-suffix.length);
   	}
   	return b;
}
	
function chg_btn(btn_id,newBtn_src){
	all_btn = zone_sommaire.getElementsByTagName('IMG')
	for(i=0;i<all_btn.length;i++){
		btn_src 	= basename(all_btn[i].src, '.jpg');
		dec_bName 	= btn_src.split('.');
		baseName 	= dec_bName[0];
		dec_udsc	= baseName.split('_');
		if(dec_udsc.length > 2){
			all_btn[i].src = '<?=SITE_ROOT?>img/'+dec_udsc[0]+'_'+dec_udsc[1]+'.'+dec_bName[1]
		}
	}
	document.getElementById(btn_id).src = newBtn_src
}

function dsp_prod(TR_class,TR_id,img_id,mg2_src){
	
	if(navigator.appName.indexOf("Internet Explorer") != -1){
		dsp_block = "block";
	}else{
		dsp_block = "table-row";
	}	
	
	TR_all = zone_sommaire.getElementsByTagName('TR')
	for(i=0;i<TR_all.length;i++){
		if(TR_all[i].className == TR_class){
			TR_all[i].style.display = 'none'
		}
	}
	document.getElementById(TR_id).style.display 		= dsp_block;
	document.getElementById(img_id).src 				= mg2_src;
}

function cell_roll(cell_g,cell_c,cell_d,img_g,img_c,img_d,fontW){
	document.getElementById(cell_g).innerHTML = '<img src="'+img_g+'" width="4">'
	document.getElementById(cell_c).style.backgroundImage = 'url('+img_c+')'
	//document.getElementById(cell_c).style.fontWeight = fontW
	document.getElementById(cell_d).innerHTML = '<img src="'+img_d+'" width="4">'
}

function check_item(formulaire,fld,tr_dsp){
	if(navigator.appName.indexOf("Internet Explorer") != -1){
		dsp_block = "block";
	}else{
		dsp_block = "table-row";
	}			
	oForm = document.forms[formulaire]
	idx_slt = oForm.elements[fld].selectedIndex;
	if(idx_slt == oForm.elements[fld].options.length-1){
		TR_display = dsp_block
	}else{
		TR_display = "none";
	}
	document.getElementById(tr_dsp).style.display = TR_display
}

function mailing_act(){
	oForm = document.forms['mailing']
	window.open("<?=SITE_ROOT?>float/wait.php", "popup");
	oForm.target = "popup";
	oForm.submit();
}

function goSearch(pageR){
	document.forms['search'].pageR.value = pageR
	document.forms['search'].submit();
}

function roll_cellule(cell,class_to,color_to){
	cell.className 					= class_to;
	cell.style.backgroundColor 		= color_to
}


function check_all(formulaire,checkBName,ctrl_checkB){
	ctrl_check = document.forms[formulaire].elements[ctrl_checkB]
	check_box = document.forms[formulaire].elements[checkBName]
	switch(ctrl_check.checked){
		case true:
			checked_all = false
		break;
		case false:
			checked_all = true
		break;
	}
	for(chb=0;chb<check_box.length;chb++){
		check_box[chb].checked = checked_all
	}
	ctrl_check.checked = checked_all
}

function opn_window(page,nom,proprietes){
	window.open(page,nom,proprietes)
}


$(fixPNG)

function fixPNG(){
	if(!jQuery.browser.msie)return
	
	rePng 		= /\.png/gi
	imgBlank 	= '/img/space.gif';
	
	$('*',$('body')).each(
		
		function (i){
			// Traitement des backgrounds avec PNG
			if($(this).attr('background')){
				var bg = $(this).attr('background')
				if(bg.match(rePng)!=null){
					$(this).attr('background','')
					$(this).css('backgroundImage','none')
					$(this).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+bg+"', sizingMethod='scale');")
					return;
				}
			}	
			
			if($(this).css('backgroundImage')){
				var bg = $(this).css('backgroundImage')
				if(bg.match(rePng)!=null){
					$(this).css('backgroundImage','none')
					$(this).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+bg+"', sizingMethod='scale');")
					return;
				}
			}
			
			if(this.tagName=='IMG'){
				var source = $(this).attr('src')
				if(source.match(rePng)!=null){
					$(this).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+source+"', sizingMethod='scale');");
					return;
				}
			}
		}
		
	)
}


jQuery.fn.extend({
   findPos : function() {
       obj = $(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});

function close_zoom(icone,pos_x,pos_y,icone_width){
	$('.zoom_picture').animate({'width':icone_width,'left':pos_x,'top':pos_y},250,function(){$('.zoom_picture').remove()});
	
}
		
$(document).ready(function(){
	$('.zoomBox').click(function(){
		pos 						= 		$(this).findPos();
		icone_width					=		$(this).children('img').width();
		icone_height				=		$(this).children('img').height();
		explodeParam				=		$(this).attr('href').split('?');
		if(explodeParam.length	>	1){
			explodeWidth			=		explodeParam[1].split('=');
			newWidth				=		explodeWidth[1];
		}else{
			newWidth				=		500;
		}
		
		if($.browser.mozilla){
			pos.x = pos.x -4
			pos.y = pos.y -94
		}
		
		newHeight					=		Math.floor(icone_height*(newWidth/icone_width));
		leftPos						=		pos.x-(newWidth/2)+(icone_width/2);
		topPos						=		pos.y-(newHeight/2)+(icone_height/2);
		icone						=		$(this).parent().attr('class')
		$('body').append("<div class=\"zoom_picture\"><a onclick=\"javascript:close_zoom(icone,pos.x,pos.y,icone_width)\"><img src=\""+$(this).attr('href')+"\" border=\"0\"></a></div>");
		$('img',$('.zoom_picture')).css('width','100%');
		$('.zoom_picture').css({'top':pos.y,'left':pos.x,'height':newWidth});
		$('.zoom_picture').animate({'width':newWidth,'left':leftPos,'top':topPos},250);
		return false
	});
});
