// JavaScript Document

//favories

function calcul_imc()

{

msg="";

taille = document.stp.taille.value;

poids = document.stp.poids.value;

age = document.stp.age.value;

sexe = document.stp.sexe.value;

perdre = document.stp.perdre.value;

if ((taille < 20) || (taille > 300)){msg=msg+"\nIl y a un problème sur la taille"}

if ((poids < 20) || (poids > 300)){msg=msg+"\nIl y a un problème sur le poids";}

if(sexe==="0"){msg=msg+"\nIl y a un problème sur le sexe"}

if(age==="0"){msg=msg+"\nIl y a un problème sur l'age"}

if(perdre==="0"){msg=msg+"\nIl y a un problème sur le poids à perdre"}

if (msg > "")

{

alert(msg+".");

return(0);

}

tmp=poids*10000 / (taille*taille)*100;

resimc = Math.round(tmp)/100;

document.getElementById("varimc").value=resimc;

document.stp.submit();

}

$(document).ready(function() {



	//When page loads...

	$(".tab_content").hide(); //Hide all content

	$("ul.tabs li:first").addClass("active").show(); //Activate first tab

	$(".tab_content:first").show(); //Show first tab content



	//On Click Event

	$("ul.tabs li").click(function() {



		$("ul.tabs li").removeClass("active"); //Remove any "active" class

		$(this).addClass("active"); //Add "active" class to selected tab

		$(".tab_content").hide(); //Hide all tab content



		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content

		$(activeTab).fadeIn(); //Fade in the active ID content

		return false;

	});



});

function hidemenu(menu)

	{

		document.getElementById(menu).style.visibility='hidden';

		document.getElementById("h_"+menu).style.backgroundColor="#333333";		

	}

function showmenu(menu,decalage)

	{		

	    if ( !decalage ) {decalage=0}

		var p=$("#menuhorizontal");var offset=p.offset();var top=offset.top;		

	    var p=$("#h_"+menu);var offset=p.offset();var left=(offset.left)-decalage;		

		p.css({"background-color":$("#"+menu).css("borderTopColor")});	

		document.getElementById(menu).style.top=top+24+"px";		

		document.getElementById(menu).style.left=left+"px";			

		document.getElementById(menu).style.visibility='visible';

	}	

function favoris() 

{

if ( navigator.appName != 'Microsoft Internet Explorer' )

{ window.sidebar.addPanel("KOT.fr : produits minceur","http://www.kot.fr",""); }

else { window.external.AddFavorite("http://www.kot.fr","KOT.fr : produits minceur"); } 

}

// PANIER

var ttcpanier = 0;

var htpanier = 0;

var tvapanier = 0;

var contenupanier= "Votre panier est vide";

function supprimelivraison()

{

	if (confirm("Si vous supprimez l'adresse de livraison, celle-ci se fera à l'adresse de facturation."))

	{

		$.ajax({

   		type: "POST",

   		url: "actions/actions_panier.php?action=supprimelivraison",

   		data: "supprimelivraison",

   		success: function(html){

			alert("L'adresse a été supprimée.");

			location.reload() ; 

   }

 });

	}

}

function surgeles_on()

{

$.ajax({

   type: "POST",

   url: "actions/actions_panier.php?action=surgeles_on",

   data: "action=surgeles_on",

   success: function(html){



   }

 });

}

function affichemessage(txt){

	document.getElementById("messagetexte").innerHTML=txt;

	document.getElementById("masque").style.visibility="visible";	

	document.getElementById("message").style.visibility="visible";

}

function masquemessage(){

	document.getElementById("masque").style.visibility="hidden";	

	document.getElementById("message").style.visibility="hidden";

}

function getWindowHeight() {

	var windowHeight = 0;

	if (typeof(window.innerHeight) == 'number') {

		windowHeight = window.innerHeight;

	} else {

		if (document.documentElement && document.documentElement.clientHeight) {

			windowHeight = document.documentElement.clientHeight;

		} else {

			if (document.body && document.body.clientHeight) {

				windowHeight = document.body.clientHeight;

			}

		}

	}

	return windowHeight;

}

function getWindowWidth() {

	var windowWidth = 0;

	if (typeof(window.innerWidth) == 'number') {

		windowWidth = window.innerWidth;

	} else {

		if (document.documentElement && document.documentElement.clientWidth) {

			windowWidth = document.documentElement.clientWidth;

		} else {

			if (document.body && document.body.clientWidth) {

				windowWidth = document.body.clientWidth;

			}

		}

	}

	return windowWidth;

}

function resize() {

	headerHauteur=parseInt(document.getElementById("header").style.height);

	menuLargeur= parseInt(document.getElementById("maindroite").style.width)+ parseInt(document.getElementById("maingauche").style.width);	

	var loaded = getWindowHeight();

	if (loaded)

	{

		document.getElementById("global").style.height = (getWindowHeight() - (headerHauteur-156))+"px";

		document.getElementById("maincentre").style.height=(parseInt(document.getElementById("global").style.height)-160)+"px";

		a=parseInt(document.getElementById("maingauche").style.height);

		b=parseInt(document.getElementById("maincentre").style.height);

		document.getElementById("maingauche").style.height=Math.max(a,b)+"px";	

		if (typeof(window.innerWidth) == 'number') {document.getElementById("maincentre").style.width = (getWindowWidth()-(menuLargeur+20))+"px";}else

		{if (document.documentElement && document.documentElement.clientWidth){document.getElementById("maincentre").style.width = "auto";	}	}}

		if (document.getElementById("panier")) {

			a=parseInt(document.getElementById("panier").style.height);

			if (a<135) {alert(a);document.getElementById("panier").style.height="135px";}

		}

	}

function ajout_panier(form)

{

var f = document.getElementById(form); 

data = "";

for( var i = 0; i < f.elements.length; i++ )  {  data+= "&"+f.elements[i].name+"="+f.elements[i].value;  } 

$.ajax({

   type: "POST",

   url: "actions/actions_panier.php?action=ajout_panier",

   data: "action=ajout_panier"+data,

   success: function(html){

	 distribue_panier(html,0);	 

   }

 });

}

function envoiverspanier(id,form)

{

html = $("#"+id).html();	

var produit_width=$("#"+id).width();

var produit_height=$("#"+id).height();

var position_produit = $("#"+id).offset();

var produit_left=position_produit.left;

var produit_top=position_produit.top;

var position_panier = $("#panier").offset();

var panier_left = position_panier.left;

var panier_top = position_panier.top;

var move_h = position_panier.left-position_produit.left;

var move_v = position_panier.top-position_produit.top;

if (panier_top > produit_top) {$signe="+="}else{$signe="+="}



$("#"+id).html('<div id="move" style="background-color:#fff;z-index:600;border:solid thin #000; width:'+produit_width+'px;height:'+produit_height+'px;position:absolute;left:'+produit_left+'px;top:'+produit_top+'px;">'+html+'</div>'+$("#"+id).html()) ;

$("#move").animate({"left": "+="+move_h+"px","top": ""+$signe+move_v+"px","opacity" : "0.1","width" :"180px","height" : "145px"}, 700,function() {$("#move").fadeTo(100,0.5);$("#"+id).html(html);	ajout_panier(form)});

}

function lit_minipanierjq()

{

$.ajax({

   type: "POST",

   url: "actions/actions_panier.php",

   data: "action=lit_minipanierjq",

   success: function(html){

   }

 });

}

function poubelle_panier(idx,bigpanier)

{

$.ajax({

   type: "POST",

   url: "actions/actions_panier.php",

   data: "action=poubelle_panier&idx="+idx+"&big="+bigpanier,

   success: function(html){

	 distribue_panier(html,bigpanier);	 

   }

 });

}

function moins_panier(idx,bigpanier)

{	   

$.ajax({

   type: "POST",

   url: "actions/actions_panier.php",

   data: "action=moins_panier&idx="+idx+"&big="+bigpanier,

   success: function(html){

	 distribue_panier(html,bigpanier);	 

   }

 });

}

function plus_panier(idx,bigpanier)

{

$.ajax({

   type: "POST",

   url: "actions/actions_panier.php",

   data: "action=plus_panier&idx="+idx+"&big="+bigpanier,

   success: function(html){

	 distribue_panier(html,bigpanier);

   }

 });

}

function distribue_panier(html,bigpanier)

{

	apanier = html.split("||");

	if (bigpanier==0)

	{

		document.getElementById("panier").innerHTML=apanier[0];

		if (document.getElementById("totalttc"))

		{	

		var contenu="Nombre d'article(s) : "+apanier[2]+"<br />Montant T.T.C. : "+apanier[1]+".";

		document.getElementById("totalttc").innerHTML=contenu;

		}

	}

	else

	{

		document.getElementById("bigpanier").innerHTML=apanier[0];

		document.getElementById("bigst1").innerHTML=apanier[1]+" &euro;";

		if (document.getElementById("bigpor"))

		{

		if (apanier[5]>0)

		{

			document.getElementById("bigrem").innerHTML=apanier[5]+" &euro;";	

			document.getElementById("bigsoustot").innerHTML=apanier[6]+" &euro;";		

		}		

		document.getElementById("bigpor").innerHTML=apanier[4]+" &euro;";			

		document.getElementById("bigtot").innerHTML=apanier[7]+" &euro;";



		document.getElementById("bight").innerHTML=apanier[8]+" &euro;";	

		document.getElementById("bigtva").innerHTML=apanier[9]+" &euro;";			

		tauxtvaport = apanier[3];

		port = apanier[4];

		}

	}	

}

function parse_panier(html,secteur)

{

	apanier = html.split("||");

	pos = html.indexOf("||");

	var contenupanier = apanier[0];

	var ttcpanier = apanier[1]+" &euro;";

	if (secteur == "contenu")

	{

		return(contenupanier);

	}

	else

	{

		return(ttcpanier);

	}

}

// FIN PANIER

// LOGIN

function infocus(champ)

{

var defaut;

if (champ=="recherche"){defaut="Recherche";}

if (champ=="login"){defaut="Votre-email";}

if (champ=="passe"){defaut="motdepasse";}

valeur = document.getElementById(champ);

if (valeur.value == defaut){valeur.value="";}

return(0)

}

function outfocus(champ)

{

var defaut;

if (champ=="recherche"){defaut="Recherche";}

if (champ=="login"){defaut="Votre-email";}

if (champ=="passe"){defaut="motdepasse";}

valeur = document.getElementById(champ);

if (valeur.value===defaut){return(0)}

if (champ=="login")

{

	if (valeur.value >"")

	{

	if ( ((strpos(valeur.value,"@")==false) || (strpos(valeur.value,".")==false)) )

		{

			alert("mail invalide !");

			valeur.value=defaut;

			return(0);

		}

	}

}

if (valeur.value == ""){valeur.value=defaut;}

}

function strpos (haystack, needle, offset) {

    var i = (haystack+'').indexOf(needle, (offset || 0));

    return i === -1 ? false : i;

}

// FIN LOGIN

function show_teaser(id)

	{

		document.getElementById("teaser").style.visibility="hidden";	

		offset = $("#bloc"+id).offset();

		posleft=offset.left+110;

		postop=offset.top;

		newPos=new Object();

    	newPos.left=posleft;

    	newPos.top=postop;

		document.getElementById("teaser").innerHTML=document.getElementById("cache"+id).value;

		document.getElementById("teaser").style.visibility="visible";			

		$("#teaser").offset(newPos);	

		$("#teaser").offset(newPos);				

	}

function hide_teaser()

	{

		document.getElementById("teaser").style.visibility="hidden";	

	}	

function show_photo(id)

	{

		offset = $("#bloc"+id).offset();

		posleft=offset.left+160;

		postop=offset.top;

		newPos=new Object();

    	newPos.left=posleft;

    	newPos.top=postop;

		document.getElementById("photo").innerHTML=document.getElementById("cache"+id).value;

		document.getElementById("photo").style.visibility="visible";			

		$("#photo").offset(newPos);	

		$("#photo").offset(newPos);		

	}

function hide_photo()

	{

		document.getElementById("photo").style.visibility="hidden";	

	}	
