function $(id)
{
 return document.getElementById(id);
}

function change_to_full_desc()
{
 jQuery("#fiche-produit-accroche").hide();
 jQuery("#fiche-produit-description").show();
}

function change_to_partial_desc()
{
 jQuery("#fiche-produit-description").hide();
 jQuery("#fiche-produit-accroche").show();
}

function display_send_friend_form()
{
 jQuery("#fiche-produit-content").hide();
 jQuery("#fiche-produit-send-friend").show();
}

function return_from_send_friend()
{
 jQuery("#fiche-produit-send-friend").hide();
 jQuery("#fiche-produit-content").show();
}

function open_tri_mark()
{
 jQuery("#tri-par-marque").toggle();
}

function open_tri_price()
{
 jQuery("#tri-par-prix").toggle();
}

function open_tri_stock()
{
 jQuery("#tri-par-stock").toggle();
}

function Liste_Change_Page(t)
{
 query = urlsearch+"&tri="+document.listeproduit.tri.options[document.listeproduit.tri.selectedIndex].value;
 if (!all) query+= "&page="+t.value;
 document.location.href = query;
}

function Liste_Change_Tri(t)
{
 query = urlsearch+"&tri="+t.value;
 if (!all && nbpages>1) query+= "&page="+document.listeproduit.num_page.options[document.listeproduit.num_page.selectedIndex].value;
 document.location.href = query;
}

function Liste_Change_mark(t)
{
 if (t.value)
 	{
	 query = urlsearch+"&f_mark="+t.value;
	 document.location.href = query;
	}
}

function Marque_change_mark(t)
{
 if (t.value)
 	{
	 query = urlsearch+"docid="+t.value;
	 document.location.href = query;
	}
}

function Marque_change_onglet(code)
{
 listeonglet = ["selection", "entreprise", "savoirfaire"];
 for (i=0; i<listeonglet.length; i++)
 	{
 	 $(listeonglet[i]).css("display","none");
 	 $(listeonglet[i]+"_onglet").className = "";
	}
 $(code).css("display","block");
 $(code+"_onglet").className = "selec";
}

function Fiche_change_onglet(code)
{
 listeonglet = ["descriptionv2", "infoMarque"];
 var ongletId = 0 ;
 for (i=0; i<listeonglet.length; i++)
 	{
 		if (document.getElementById(listeonglet[i]))
 	 	{
 	  		document.getElementById(listeonglet[i]).style.display = "none";
 	  		ongletId = i+1;
 	  		$(listeonglet[i]+"_onglet").className = "onglet o"+ongletId+" notcurrent";
 	  		if (code == listeonglet[i]) {
 	 	 		var select = i+1 ;
 	  		}
	 	}
	}
 $(code).css("display","block");
 $(code+"_onglet").className = "onglet o"+select+" current";
}

function FicheCrossMerch_change_onglet(code)
{
 if (code=="avisShopzilla")
 	{
 	 select_prod_tab('avis_clients', true);
	}
	else
	{
	 listeonglet = ["nos-pack", "aimerez", "similaires", "marque", "avisShopzilla"];
	 for (i=0; i<listeonglet.length; i++)
 		{
 		 if ($(listeonglet[i]))
 	 		{
 			 $(listeonglet[i]).css("display", "none");
 			 $(listeonglet[i]+"-onglet").className = "onglet-cross-merch onglet-"+listeonglet[i];
			}
		}
	 $(code).css("display","block");
	 $(code+"-onglet").className = "onglet-cross-merch onglet-"+code+" selec";
	}
}


function zoom_popup(id)
{
 zoom_pp = window.open('/prod/zoom.php?docid='+id,'zoom','left=100,top=100,width=550,height=550,resizable=yes,dependent=no,menubar=no,location=no,titlebar=yes,toolbar=no,scrollbars=yes,statusbar=yes');
 zoom_pp.focus();
}

function process_order()
{
 document.panier.nextstep.value="1";
 document.panier.submit()
}

field_mark=new Array();
function mark_change(fieldname)
{
 field_mark[fieldname] = 1;
}

function duplicate_value(fieldname)
{
 if (document.addr.same_address[0].checked==true)
 	{
	 eval("f1 = document.addr."+fieldname+";");
	 eval("f2 = document.addr.s_"+fieldname+";");
	 if (!field_mark[fieldname]) f2.value = f1.value;
	}
}

function duplicate_value_select(fieldname)
{
 if (document.addr.same_address[0].checked==true)
 	{
	 eval("f1 = document.addr."+fieldname+";");
	 eval("f2 = document.addr.s_"+fieldname+";");
	 if (!field_mark[fieldname]) f2.selectedIndex = f1.selectedIndex;
	}
}

function duplicate_value_radio(fieldname)
{
 if (document.addr.same_address.checked==true)
 	{
	 eval("f1 = document.addr."+fieldname+";");
	 eval("f2 = document.addr.s_"+fieldname+";");
	 if (!field_mark[fieldname])
	 	{
		 for (i=0;i<f1.length;i++) 
		 	{
			 eval("f1_bis = document.addr."+fieldname+"["+i+"];");
			 eval("f2_bis = document.addr.s_"+fieldname+"["+i+"];");
			 f2_bis.checked = f1_bis.checked;
			}
		}
	}
}

check_text_started = 0;

function check_text_length(id, len)
{
 check_text_started = 1;
 setTimeout("check_text_length_exec('"+id+"', "+len+")", 1000);
}

function check_text_length_exec(id, len)
{
/*
 restlen = (len-$(id).value.length);
 if (restlen<0) restlen=0;
 $("text_reste_length").innerHTML = restlen+"/"+len;
 if ($(id).value.length>len)
 	{
	 $(id).value = $(id).value.substr(0,len);
	}
 setTimeout("check_text_length_exec('"+id+"', "+len+")", 1000);
 */
 restlen = (len-jQuery('#'+id).val().length);
 if (restlen<0) restlen=0;
 jQuery('#text_reste_length').html(restlen+"/"+len);
 if (jQuery('#'+id).val().length>len)
 	{
	 jQuery('#'+id).val(jQuery('#'+id).val().substr(0,len));
	}
 setTimeout("check_text_length_exec('"+id+"', "+len+")", 1000);
}


function change_livraison_kdo(way)
{
 if (way)
 	{
 	 $("livraison_label_kdo_on").style.display="inline";
 	 $("livraison_label_kdo_off").style.display="none";
	}
	else
 	{
 	 $("livraison_label_kdo_on").style.display="none";
 	 $("livraison_label_kdo_off").style.display="inline";
	}
 
}

function change_label(on,off)
{
 if (on) $(on).style.display="inline";
 if (off) $(off).style.display="none";
}

function select_shipping_method(id)
{
 switch (id)
 	{
	 case 1: $('kiala_box').style.display='block'; break;
	 default: $('kiala_box').style.display='none'; break;
 	}
}

/*	Search
---------------------------------------------------------------------- */
function search_active()
{
 if(jQuery('#digiSuggSearch').val()=='Saisissez ici votre recherche')
	{
	 jQuery('#digiSuggSearch').val('');
	 jQuery('#digiSuggSearch').toggleClass('search-tbx-active','search-tbx');
	}
}

/*	Basket
---------------------------------------------------------------------- */
function basket_show() { jQuery('#header_basket').slideDown('slow'); }
function basket_hide() { jQuery('#header_basket').slideUp('fast'); }

/*	Menu
---------------------------------------------------------------------- */
function menu1_show()
{
	jQuery(this).children('ul').fadeIn("fast").show();
}
function menu1_hide()
{
	jQuery(this).children('ul').hide();
}
function menu2_show()
{
	jQuery('#sub'+jQuery(this).attr('id')).fadeIn("fast").show();
	//jQuery('#sub'+jQuery(this).attr('id')).parent('li').children('span.on').fadeIn("fast").show();
}
function menu2_hide()
{
	jQuery('#sub'+jQuery(this).attr('id')).hide();
	//jQuery('#sub'+jQuery(this).attr('id')).parent('li').children('span.on').hide();
}

/*	Prod list
---------------------------------------------------------------------- */
function change_prod_list(list)
{
 if (list=='block')
 	{
	 jQuery('#list-line').hide();
	 jQuery('#list-block').show();
 	}
 else
 	{
	 jQuery('#list-block').hide();
	 jQuery('#list-line').show();
 	}
}

/*	layer
---------------------------------------------------------------------- */
function layer_show(id) { jQuery('#'+id).show(); }
function layer_hide(id) { jQuery('#'+id).hide(); }

/*	Fiche prod
---------------------------------------------------------------------- */
function view_prod_gallery(medium, maxi)
{
 jQuery('a#zoom1').attr('href',maxi);
 jQuery('a#zoom1 img').attr('src',medium);
 // init digizoom
 jQuery('div#zoom1-zoom').html('');
 jQuery('a#zoom1 div').remove();
 setTimeout(DigiZoom.init, 300);
}

function view_prod_pop_in(img)
{
 //jQuery('.fiche-produit-photo img').attr('src',img);
 jQuery('img#img-prod_zoom').attr('src',img);
 layer_show('layer-prod_zoom');
}

function select_prod_tab(id, scroll)
{
 if (scroll) jQuery('html,body').animate({scrollTop:jQuery('#niv_3').offset().top},1000,'swing');
 jQuery('.fiche-produit-contenu-onglet').hide();
 jQuery('#'+id).show();
 jQuery('.fiche-produit-onglets li').removeClass('on');
 jQuery('.fiche-produit-onglets img').hide();
 jQuery('#tab_'+id).addClass('on');
 jQuery('#tab_'+id+' span').show();
}

function scroll_declinaisons(id)
{
 jQuery('html,body').animate({scrollTop:jQuery('#'+id).offset().top},1000,'swing');
}

/*	Order Shipping
---------------------------------------------------------------------- */
var ajax_page = '../lib/ajax.php';

function shipping_address(action)
{
 if (action=='show')
	{
	 jQuery('#ship_address').show('fast');
	 // activation de la validation des champs
	 $('#prenom-fact-tbx').addClass('validationFF');
	 $('#nom-fact-tbx').addClass('validationFF');
	 $('#adr1-fact-tbx').addClass('validationFF');
	 $('#cp-fact-tbx').addClass('validationFF');
	 $('#ville-fact-tbx').addClass('validationFF');
	 $('#tel-fact-tbx').addClass('validationFF');
	}
 else
	{
	 jQuery('#ship_address').hide('fast');
	 // desactivation de la validation des champs
	 $('#prenom-fact-tbx').removeClass('validationFF');
	 $('#nom-fact-tbx').removeClass('validationFF');
	 $('#adr1-fact-tbx').removeClass('validationFF');
	 $('#cp-fact-tbx').removeClass('validationFF');
	 $('#ville-fact-tbx').removeClass('validationFF');
	 $('#tel-fact-tbx').removeClass('validationFF');
	}
}

function order_shipping_methode(id)
{
 var sa = jQuery('input[name=same_address]:checked').val();
 var shipm = jQuery('input[name=livraison_mode]:checked').val();
 //alert (sa+' '+shipm);
 jQuery.ajax({
	type: 'POST',
	async: true,
	url: ajax_page+'?action=order_shipping_methode',
	data: 'shipm='+shipm+'&sa='+sa,
	success: function(data){
		//alert(data);
	}
 });
}

function order_country_shipping(cid)
{
 jQuery.ajax({
	type: 'POST',
	async: true,
	dataType: 'json',
	url: ajax_page+'?action=order_country_shipping',
	data: 'cid='+cid,
	success: function(data){
		$.each(data.ship_methodes, function(i,ship_methode){
			var ship_li = jQuery('input#ship'+ship_methode.nr+'_rad').parent('li');
			if (ship_methode.display) ship_li.show('fast');
			else ship_li.hide('fast');
			ship_li.children('span.prix').html(ship_methode.prix);
			ship_li.children('span.help').html(ship_methode.help);
		});
	}
 });
}

/*	Select Box CSS
---------------------------------------------------------------------- */
function sb_toggle(id)
{
 $('#'+id).slideToggle('fast');
}

/*	Marque
---------------------------------------------------------------------- */
function select_marque_tab(id)
{
 jQuery('.boxs_content .box_content').hide();
 jQuery('#'+id).show();
 jQuery('.tabs_marque li').removeClass('on');
 //jQuery('.tabs_marque img').hide();
 jQuery('#tab_'+id).addClass('on');
 jQuery('#tab_'+id+' span').show();
}

/*	Kookit
---------------------------------------------------------------------- */
menu_color_0 = "#7b043e";
menu_color_1 = "#bb005d";

function showMenu(idToShow)
{
	//Affichage du block
	if (document.getElementById('sousmenu'+idToShow)) document.getElementById('sousmenu'+idToShow).style.display = 'block';
	if (idToShow<30) switchCss(idToShow,0);
}

function hideMenu(idToShow)
{
	if (document.getElementById('sousmenu'+idToShow)) document.getElementById('sousmenu'+idToShow).style.display = 'none';
	switchCss(idToShow,1);
}

function switchCss(idToShow,ini)
{
	var element = document.getElementById('lienmenu'+idToShow);
	//Si on veut lui redonner le style initial
	if (ini == 1)
		{
		 element.className=element.className.substr(0,element.className.length-3);
		}
		else
		{
		 element.className=element.className + "off";
		}
}

function switchNumCmdInput(pIdValue)
{
	document.getElementById('li-num-cmd').style.display = (pIdValue<=4?'block':'none');
}


