var w3c=document.getElementById && !document.all;
var ie=document.all;

if (ie||w3c) {
 // déclaration des variables uniquement pour IE vive microsoft ?!!
 var my_overlay;
 var my_window;
}


function affiche_overlay_window(image_fond_overlay,adresse_page){
	// creation de l'overlay et affichage de l'image
	montreoverlay("<table class='image_calque' valign='center' border='0' align='center'><tr><td><img src='transparent.gif' alt='' /></td></tr></table>");
	// creation de la fenêtre
	montrefenetre(adresse_page);
}


function montreoverlay(text) {
  if (w3c||ie){
    my_overlay = document.all ? document.all["overlay"] : document.getElementById ? document.getElementById("overlay") : ""
	my_overlay.innerHTML = text; // fixe le code HTML dans l'overlay balise (div)
    my_overlay.style.visibility = "visible"; // modification du style
  }
}

function montrefenetre(html) {
  if (w3c||ie){
    //affichage de la fenetre
	my_window = document.all ? document.all['window'] : document.getElementById ? document.getElementById('window') : ""
    my_window.style.visibility = "visible";

	// affichage du corps de la fenêtre (balise iframe)
    my_window = document.getElementById('contempwindow');
    my_window.style.visibility = "visible";
    frames['contempwindow'].location.href= html ;
  }
}


function cachetout() {
	if (w3c||ie){

	// masque la fenetre (balise div [window] )
	my_window = parent.document.getElementById('window');
	my_window.style.visibility = "hidden";

	// masque le contenu (balise iframe [contempwindow])
	my_window = parent.document.getElementById('contempwindow');
	my_window.style.visibility = "hidden";

	// masque l'overlay (balise div [overlay])
	my_window = document.all ? parent.document.all['overlay'] : parent.document.getElementById ? parent.document.getElementById('overlay') : ""
	my_window.style.visibility = "hidden";
	}
}
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}

function check_autre(lid){
var obj=document.getElementById(lid).disabled;
alert (obj);
if(obj == "true")
{
	obj="false";
}else{
	obj="true";
}
}
function blink_newApp()
{
	if(document.getElementById('newApp').style.visibility = 'hidden')
   	 {
   	 	setTimeout("document.getElementById('newApp').style.visibility = 'visible';",500);
   	 } else {
   	 	setTimeout("document.getElementById('newApp').style.visibility = 'hidden';",500);
   	 }
}
  function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
  }
  function add_radio()
  {
  	document.form_radio.submit();
  }
  function add_chbx()
  {
  	document.form_chkbx.submit();
  }
  function add_list()
  {
 	var nbelem = document.getElementById("nbelem").value;
   	document.form_list.submit();
  }
  function add_champ()
  {
   	document.form_champ.submit();
  }
  function add_file()
  {
  	document.form_file.submit();
  }
function aff(objet){
	if(document.getElementById(objet).style.display == "block") {
	document.getElementById(objet).style.display = "none"; } else {
	document.getElementById(objet).style.display = "block"; }
}
function aff2(objet){
	if(document.getElementById(objet).style.display == "none") {
	document.getElementById(objet).style.display = "block"; } else {
	document.getElementById(objet).style.display = "none"; }
}
function Ajout_Produit(){
	var err=0;
	for(count1=0; count1<document.form_prodinf.elements.length; count1++)
	{
	  theelement = document.form_prodinf.elements[count1];
	  theelementtype = theelement.type;
	  theelementname = theelement.name;
		switch (theelementtype)
		{
		case 'text':
			// if(theelement.value == ""){alert("Champs TEXT "+theelementname+" Vide");}
			break;
		case 'radio':
			//if(theelement.checked == ""){alert("Champs RADIO "+theelementname+" Vide");err+=1;}
			break;
		case 'select':
			//if(theelement.value == ""){alert("Champs SELECT "+theelementname+" Vide");}
			break;
		case 'checkbox':
			//if(theelement.value == ""){alert("Champs RADIO "+theelementname+" Vide");}
			break;
		case 'textarea':
			//if(theelement.value == ""){alert("Champs RADIO "+theelementname+" Vide");}
			break;
		case 'file':
			//if(theelement.value == ""){alert("Champs RADIO "+theelementname+" Vide");}
			break;
		default:
		}
	 }
	document.form_prodinf.submit();
}
function Produits_Simplus(info_produit,mod,limit) {
var nbboucle= parseInt($('#nb_boucle').text());
var nbproduits= parseInt($('#nb_produits').text());
nbboucle = nbboucle+6;
if (nbboucle < nbproduits-6) { 
$('#img_liste_droite').css('display','block');
} else {
$('#img_liste_droite').css('display','none');
}
if (nbboucle > 0) { 
$('#img_liste_gauche').css('display','block');
}
$('#nb_boucle').html(nbboucle);
	// le $ est l'objet Jquery. Ici, on applique la fonction sur le div qui contient la liste des produits similaires à savoir id="img_liste_mid". En fait ici, on change son css en le cachant
	$('#img_liste_mid').css('display','none');
	// on envoie en méthode POST à un ficher PHP avec les paramètre $_POST['info_produit'] = info_produit (passé en paramètre de la fonction) et ainsi dessuite et on traite le retour
	$.post("select_produit.php",{"info_produit":info_produit,"mod":mod,"limit":nbboucle},function(html) {
		// Si le PHP renvoit rien, c'est qu'on a pas d'objet, on affiche donc.
		if (html == 'NA') {
			$('#img_liste_mid').html('Pas d-objet').fadeIn();
		} 
		// Si le PHP renvoit autre chose que NA, c'est qu'on a des objets, on les affiche en fade.
		else {
			$('#img_liste_mid').html(html).fadeIn();
		}
	});
}
function Produits_Simmoins(info_produit,mod,limit) {
var nbboucle= parseInt($('#nb_boucle').text());
var nbproduits= parseInt($('#nb_produits').text());
nbboucle = nbboucle-6;
if (nbboucle <1) { 
$('#img_liste_gauche').css('display','none');
}
if (nbboucle < nbproduits-6) { 
$('#img_liste_droite').css('display','block');
}
$('#nb_boucle').html(nbboucle);
	// le $ est l'objet Jquery. Ici, on applique la fonction sur le div qui contient la liste des produits similaires à savoir id="img_liste_mid". En fait ici, on change son css en le cachant
	$('#img_liste_mid').css('display','none');
	// on envoie en méthode POST à un ficher PHP avec les paramètre $_POST['info_produit'] = info_produit (passé en paramètre de la fonction) et ainsi dessuite et on traite le retour
	$.post("select_produit.php",{"info_produit":info_produit,"mod":mod,"limit":nbboucle},function(html) {
		// Si le PHP renvoit rien, c'est qu'on a pas d'objet, on affiche donc.
		if (html == 'NA') {
			$('#img_liste_mid').html('Pas d-objet').fadeIn();
		} 
		// Si le PHP renvoit autre chose que NA, c'est qu'on a des objets, on les affiche en fade.
		else {
			$('#img_liste_mid').html(html).fadeIn();
		}
	});
}
function zone(id_pays,bkt,idc)
{
	zoneHttp=getXMLHTTP();
	if (zoneHttp==null)
 	 {
 	 	alert ("Votre explorateur ne supporte pas AJAX!");
 		return;
 	 }
	zoneHttp.onreadystatechange=function()
	{
	  if (zoneHttp.readyState == 4) { // only if "OK"
		if (zoneHttp.status == 200) {
			reponse=zoneHttp.responseText;
			var crea=reponse.split('[]');
			var nbElems	= crea.length;
			var nbElem	= nbElems - 1;
			var newdate	= 0;
			var declistfin = crea[nbElem].split('__');
				for (var i=0; i<nbElem; i++)
				{
				  var elem = crea[i].split('|');
				  var Ch_Livr	="";
				  var id_bkt	="";
				  Ch_Livr		= "Ch_Livr_" + elem[0];
				  id_bkt		= "id_bkt_"  + elem[0];
				  iport			= "iport_"  + elem[0];
				  var txt		= "Livraison prévue entre le "+elem[7]+" et le "+elem[8]+".<br /> Expédié par <b>"+elem[10]+"</b> de "+elem[9]+" en "+elem[6]+" ("+elem[5]+" €).";
				  var txt2	= "Livraison prévue entre le "+elem[7]+" et le "+elem[8]+". Expédié par <b>"+elem[10]+"</b> de "+elem[9]+" en "+elem[6]+" ("+elem[5]+" €).";
				  var txt3	= elem[7]+"|"+elem[8]+"|"+elem[6]+"|"+elem[5];
  				  if(elem[6] =="format numerique")
				  {
					txt		= "Envoi par e-mail ou téléchargement<br /> prévu le "+elem[7];
					txt2	= "Envoi par e-mail ou téléchargement prévu le "+elem[7];
				  }
				  document.getElementById(Ch_Livr).innerHTML	=	txt;
				  document.getElementById(id_bkt).value	=	txt2;
				  document.getElementById(iport).value	=	txt3;
				}
				var LePxTot	= declistfin[0]*1;
				var fdp_tot	= declistfin[1]*1;
				var PxTot	= declistfin[2]*1;
				LePxTot	= LePxTot.toFixed(2);
				AFF_fdp_tot = fdp_tot.toFixed(2);
				PxTot	= PxTot.toFixed(2);
				LePxTot	= LePxTot.replace(".",",");
				AFF_fdp_tot	= AFF_fdp_tot.replace(".",",");
				PxTot	= PxTot.replace(".",",");
				document.getElementById("LePxTot").innerHTML	=	LePxTot+" €";
				document.getElementById("FDP").innerHTML		=	AFF_fdp_tot+" €";
				document.getElementById("PxTot").innerHTML		=	PxTot+" €";
				document.getElementById("hid_ship").value		=	fdp_tot;
		} else {
			alert("There was a problem while using XMLHTTP:\n" + catHttp.statusText);
				}
		}
	}
	var zoneString = "?pays=" + id_pays + "&bkt=" + bkt + "&idc=" + idc;
	zoneHttp.open("GET","ajax_zone.php"+zoneString,true);
	zoneHttp.send(null);
}
function personnaliser() {
    var select = "html,body";
    if ((jQuery.browser.msie && jQuery.browser.version <= 7)) {
        select = "html";
    }
	offset = $('#index_main_cexnter').height();
	offset = offset - 190;
	//alert(offset);
    jQuery(select).animate({ "scrollTop": offset + "px" }, 1000);
}

