/*tab_sous_menus = new Array('Accueil', 'Architecture', 'Permis', 'Loisirs', 'Jeux', 'Enfants', 'Utilitaires', 'Papiers', 'Accessoires');*/
function affichage_popup(nom_de_la_page, nom_interne_de_la_fenetre, width, height){
window.open (nom_de_la_page, nom_interne_de_la_fenetre, config='height=' + height + ', width=' + width + ', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
}


function trim(string){
return string.replace(/(^\s*)|(\s*$)/g,'');
} 

function requete2div (mode, div){
	$.get("data/jquery.php", 
	{ mode: mode },
	function(data){
		$(div).html(data);
	});
}

function Show_ficheproduit(input){
	tab_ficheproduit = new Array('descriptif', 'config', 'screenshots', 'videos', 'presse', 'support', 'partenaires', 'sitesdedies', 'concours', 'envoiami', 'packs');
	//on masques tous les div pour commecner
	for (var i=0;i<tab_ficheproduit.length;i++){
		$('div[@id=\'fiche_'+tab_ficheproduit[i]+'\']').hide();
	}
	//on affiche celui sélectionné
	$('div[@id=\'fiche_'+input+'\']').show();
}

function checkform_support(){
  var ok=1;
  if(document.contact.mail.value == -1){alert("Veuillez choisir un sujet dans le menu"); ok=0;}
  if(document.contact.texte.value.length < 5 && ok==1){alert("Veuillez saisir votre texte"); ok=0;}
  /*if(document.contact.mail.value == 'support@anuman-interactive.com' && document.contact.ref.value.length != 13 && ok == 1){alert("Pour mieux répondre à vos attentes merci de précisier le code barre du logiciel (13 chiffres sans espace)"); ok=0;}*/
  if((document.contact.reponse.value.lenth < 5 || document.contact.reponse.value.indexOf('@',0) == -1) && ok==1){alert("Veuillez donner un email valide pour la réponse"); ok=0;}
  if(ok == 1){	document.contact.submit();  }
}

function windowCenter(myId) {
        //result=returnSize();
		result=getPageSize();
        var myWidth=result[2]; 
        var myHeight=result[3];
        var elementWidth=$("div[@id="+myId+"]").width();
        //alert(elementWidth);
        var elementHeight=$("div[@id="+myId+"]").height();
        var myScrollLeft=document.body.scrollLeft;
        var myScrollTop= document.body.scrollTop;
		var my_scroll =getPageScroll()
		var myScrollTop = my_scroll[1];
        var posX=myScrollLeft+myWidth-myWidth/2-elementWidth/2
        var posY=myScrollTop+myHeight-myHeight/2-elementHeight/2;
        $("div[@id="+myId+"]").css({ 'left': posX+'px',  'top': posY+'px'}); 
}

function getPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight+window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
    pageHeight = windowHeight;
    } else {
    pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
    pageWidth = windowWidth;
    } else {
    pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}

// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
// Code by Lokesh Dhakar
function getPageScroll(){
  var yScroll;
  if (self.pageYOffset) {
  yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
  yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
  yScroll = document.body.scrollTop;
  }
  arrayPageScroll = new Array('',yScroll)
  return arrayPageScroll;
}

function checkInput(input, msg_error){
	if (trim($("input[@name="+input+"]").val()) != ""){
		return true;
	}else{
		alert(msg_error);
		return false;
	}
}

function rechercheAvancee(){
	$("p[@class=\"recherche_avancee\"]").html('');
	var recherche = "";
	var elements = new Array();
	//thematique
	if (trim($('#rech_thematique').children("[@selected]").text())!=""){
		elements.push("de la thématique <span class='gras'>" + $('#rech_thematique').children("[@selected]").text()+"</span>");
		//alert($('#rech_thematique').children("[@selected]").text().length);
	}
	//thematique2
	if (trim($('#rech_thematique2').children("[@selected]").text())!=""){
		elements.push("de la sous-thématique <span class='gras'>" + $('#rech_thematique2').children("[@selected]").text()+"</span>");
		//alert($('#rech_thematique').children("[@selected]").text().length);
	}
	//prix
	if (trim($('#rech_prix').children("[@selected]").text()) != ""){
	 elements.push("qui coûte <span class='gras'>" + $('#rech_prix').children("[@selected]").text().toLowerCase()+"</span>");
	}
	//date
	if (trim($('#rech_date').children("[@selected]").text()) != ""){
	 elements.push("sorti il y a <span class='gras'>" + $('#rech_date').children("[@selected]").text().toLowerCase()+"</span>");
	}
	//plateforme
	if (trim($('#rech_plateforme').children("[@selected]").text()) != ""){
	 elements.push("sur <span class='gras'>" + $('#rech_plateforme').children("[@selected]").text()+"</span>");
	}
	//obtention
	if (trim($('#rech_obtention').children("[@selected]").text()) != ""){
	 elements.push("disponible en <span class='gras'>" + $('#rech_obtention').children("[@selected]").text()+"</span>");
	}
	
	if (elements.length > 0){
	    recherche += "Vous recherchez un produit ";
		for(i=0;i<elements.length;i++){
			if(i>0 && i<(elements.length-1)){recherche += ", ";}
			else if(i==(elements.length-1) && i>0){recherche += " et ";}
			recherche += elements[i];
		}
		$("p[@class=\"recherche_avancee\"]").html(recherche);
	}
	
}

function rechthematiques2(){
	$.get(_Racine+'data/jquery.php',
   { info: 'thematique2', thematique: $('#rech_thematique').children("[@selected]").text()},
   function(data){
	 var options = data.split(",");
	 var contenu = '<option selected="selected" value="" />';
	 for(var i=0;i<options.length;i++){
		contenu+="<option value='"+options[i]+"' >"+options[i]+"</option>";
	 }
	 $('#rech_thematique2').html(contenu);
	 //BUG FF//
	 $('#rech_thematique2').children('[@value=""]').attr({selected:"selected"});
	 //une fois contenu chargé, on lance la recherche avancée//
	 rechercheAvancee();
	 //alert('Data Loaded: '+  $('#rech_thematique2').children("[@selected]").text());
   })
 };
 
function findPos(obj) {
    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 showselect_thematique(){
	var pos = findPos(document.getElementById("champ_theme"));
	$('#select_theme').css({ position: 'absolute', top: (pos.y)+"px", left:pos.x});
	$('#select_theme').show();
	$('#select_theme').focus();
}

function ajoutPanierAjax(ref, id)
{
  var date=new Date;	
  $.ajax({
    type: "GET",
    url: _Racine+"ajaxpanier.php?action=ajout&ref="+ref+"&t="+date.getTime(),
    dataType: "html",
    success: function(retour)
    {
      var res = retour.split("|");
      
      $("#articlesapercupanier").empty();
      $("#articlesapercupanier").append(res[1]);
      $("#totalapercupanier").empty();
      $("#totalapercupanier").append(res[2]);
      $("#popupajoutpanier > .bloc").empty();
      $("#popupajoutpanier > .bloc").append("Le produit <span style='font-weight: bold'>"+res[0]+"</span> a été ajouté a votre panier.<br />");
      $("#popupajoutpanier > .bloc").append("Votre panier contient <span style='font-weight: bold'>"+res[1]+"</span>");
      $("#popupajoutpanier > .bloc").append("<br />Total de vos achats: <span style='font-weight: bold'>"+res[2]+"</span><br /><br />");
      $("#popupajoutpanier > .bloc").append("<span class='left'><a href='#' onclick='return cachePanierAjax();'><img src='"+_Racine+"data/images/boutonretour.png'><br />Retour</a></span> <span class='right'><a href='#' onclick='return voirPanier();'><img src='"+_Racine+"data/images/boutonpanier.png'><br />Voir le panier</a></span>");
      //$("#popuppanier").focus();
    }
  });
  deplaceVersPanier("span"+id);
  return false;
}

function cachePanierAjax()
{// taille finale x=90 y=20
  $("#popupajoutpanier").hide("slow");
  return false;
}

function deplaceVersPanier(id)
{
  var hfin = 20;
  var lfin = 90;
  var posfin = findPos(document.getElementById("monpaniertop"));
  var gfin = posfin.x;
  var tfin = posfin.y;
  
  var posdeb = findPos(document.getElementById(id));
  var gdeb = posdeb.x;
  var tdeb = posdeb.y;
  //alert(gdeb+" "+tdeb);
  
  var hdeb = $("#"+id).height();
  var ldeb = $("#"+id).width();
  $("#popuppointpanier").css("height", hdeb+"px");
  $("#popuppointpanier").css("width", ldeb+"px");
  $("#popuppointpanier").css("left", gdeb+"px");
  $("#popuppointpanier").css("top", tdeb+"px");

  $("#popuppointpanier").show();
  
  var ecarth, ecartw, ecartg, ecartt;
  ecarth= $("#popuppointpanier").css("height");
  ecarth= ecarth.substring(0, ecarth.length-2).valueOf();
  ecarth = ecarth - hfin;
  
  ecartw= $("#popuppointpanier").css("width");
  ecartw= ecartw.substring(0, ecartw.length-2).valueOf();
  ecartw= ecartw - lfin;
  
  ecartg= $("#popuppointpanier").css("left");
  ecartg= ecartg.substring(0, ecartg.length-2).valueOf();
  ecartg= ecartg - gfin;
  
  ecartt= $("#popuppointpanier").css("top");
  ecartt= ecartt.substring(0, ecartt.length-2).valueOf();
  ecartt= ecartt - tfin;


  i = 90;
  reduire(i, hfin, lfin, ecarth, ecartw, gfin, tfin, ecartg, ecartt);
  return false;
}

function reduire(i, hfin, lfin, ecarth, ecartw, gfin, tfin, ecartg, ecartt)
{
  var timer = 25;
  
  var pourcent = i/100;
  var temph = hfin + (pourcent * ecarth);
  var tempw = lfin + (pourcent * ecartw);
  var tempg = gfin + (pourcent * ecartg);
  var tempt = tfin + (pourcent * ecartt);
  $("#popuppointpanier").css("height", temph.toString()+"px");
  $("#popuppointpanier").css("width", tempw.toString()+"px");
  $("#popuppointpanier").css("left", tempg.toString()+"px");
  $("#popuppointpanier").css("top", tempt.toString()+"px");
  i = i-5;
  if(i>=0)
    setTimeout("reduire("+i+", "+hfin+", "+lfin+", "+ecarth+", "+ecartw+", "+gfin+", "+tfin+", "+ecartg+", "+ecartt+")", timer);
  else
  {
    $("#popuppointpanier").css("display", "none");
    windowCenter($("#popupajoutpanier").attr("id"));
    $("#popupajoutpanier").css("z-index", "5000");
    $("#popupajoutpanier").show("slow");
  }
}

function voirPanier()
{
  location.href=_Racine+"macommande.html";
  return false;
}

function verif_mail()
{
	$("img[@name=change]").attr({ src: "img/load.gif", alt: "NON" });
	$("img[@class=change]").css({visibility : "visible"});
	email = $("input[@name=0_mail]").val();
	
	//récupération de la validité du mail via la page jquery.php//
	$.get('jquery.php', { mail : email },
  	function(data){
  		if (data==1){
  		//MAIL VALIDE//
  			$("input[@name=0_mail]").removeClass("error");
  			$("input[@value=Je participe]").attr({ disabled: false});
  			$("img[@name=change]").attr({ src: "img/on.gif", alt: "NON" });
  			$("img[@class=change]").css({visibility : "visible"});
  			$("input[@name=Valider]").fadeIn("slow");
  		}
  		else
  		{
  		//MAIL INCORRECT//
  			$("input[@name=0_mail]").addClass("error");
  			$("input[@value=Je participe]").attr({ disabled: true});
  			$("img[@name=change]").attr({ src: "img/off.gif", alt: "NON" });
  			$("img[@class=change]").css({visibility : "visible"});
  			$("input[@name=Valider]").fadeOut("slow");
  		}
  	}
  );
}

function envoiMailAmi(email, nom, ami1, ami2, ami3, commentaire, ref)
{
  var ok = true;
  var aretour = "0";
  if(((email != "") && (email != null) && (email != "undefined")) && ok)
    ok=verif_mail_generique(email);
  else ok = false;
  if(((ami1 != "") && (ami1 != null) && (ami1 != "undefined")) && ok)
    ok=verif_mail_generique(ami1);
  else ok = false;
  if(((ami2 != "") && (ami2 != null) && (ami2 != "undefined")) && ok)
    ok=verif_mail_generique(ami2);

  if(((ami3 != "") && (ami3 != null) && (ami3 != "undefined")) && ok)
    ok=verif_mail_generique(ami3);
  
  if(ok)
  {
    $.ajax({
      type: "POST",
      url: _Racine+"envoimailami.php",
      dataType: "html",
      async: false,
      data: "email="+email+"&nom="+nom+"&ami1="+ami1+"&ami2="+ami2+"&ami3="+ami3+"&commentaire="+commentaire+"&ref="+ref,
      success: function(retour)
      {
        if(retour != "0")
          aretour = "1";
        else aretour = "0";
      },
      error: function()
      {
        aretour = "0";
      }
    }
    );
  }
  else aretour = "0";
  return aretour;
}

function verif_mail_generique(email)
{
	email = email.toLowerCase();
	if(email.length < 6)
	 return "0";
	if(email.length > 255)
	 return "0";
	if(email.search("@") == -1)
	 return "0";
	else return "1";
}

function show_rentabiliweb(ref) {
    windowCenter($("#popuprentabiliweb").attr("id"));
    $("#popuprentabiliweb").css("z-index", "5000");
    $("#popuprentabiliweb").show("slow");
	
	$.ajax({
    type: "GET",
    url: _Racine+"rentabiliweb.php?action=clic&ref="+ref,
    dataType: "html",
    success: function(retour) {}
	});
	return false;
}


function cache_rentabiliweb() {
  $("#popuprentabiliweb").hide("slow");
  
  $.ajax({
    type: "GET",
    url: _Racine+"rentabiliweb.php?action=fermer",
    dataType: "html",
    success: function(retour) {}
	})
  return false;
}

function check_cgv()
{
	if(!document.getElementById("cgv").check_cgv.checked)
	{
		alert("Pour valider votre commande, merci de cocher la case concernant l'acception des conditions générales de vente.");
		return false;
	}
	else
		return true;
}


