// JavaScript Document
/*
Losque IE est en cache automatique PROBLEME dans REQUETES AJAX
*/
//-----------------------------------------------------------------------------------------------------------------
//utilisé sur la home 
function formatprix(prix) {
	//alert("prix : "+prix);
	var a = prix;
	var b = a.indexOf(".");
	 if (b == -1) return prix;
	var c= a.substring(b-3,b);
	var prix=a.substring(0,b-3)+" "+c+","+a.substring(b+1);
	if(b>6){
	var c= a.substring(b-3,b);
	var d= a.substring(b-6,b-3);
	var prix=a.substring(0,b-6)+" "+d+" "+c+","+a.substring(b+1);
	/*PATCH AV 270208*/
	//return prix;
	}
return (prix +"&euro;&nbsp;H.T.");	
}

//--------------------------------------AFFICHAGE DU PANIER (GD OCTOBRE 2008)------------------------------------

/*Affiche le panier dans la head */
function PanierGestion_head(){callAjax(8, "GET", "SO2/showPaniera18a.html?t="+(new Date()).getTime(), null);}
function fn8(id){
	var donnees = reponseAjax[id].trim();
	if( document.getElementById("panier") ) 
	{
    	document.getElementById("panier").innerHTML = donnees ;
 	}
}  

/* Verification de la necessite d'afficher le panier */
function checkIfPanier(){callAjax(2, "GET", "SO2/checkIfPaniera18a.html?t="+(new Date()).getTime(), null);}
function fn2(id){var rep = reponseAjax[id].toLowerCase() ; }  

/*maj quantité produit dans le panier*/
function updatePanier(idP){ callAjax(7, "GET", "home.htm?idp="+idP+"&op=m&t="+(new Date()).getTime(), null); }
function fn7(id){ 
PanierGestion_head();

}

function showPanier(){document.getElementById("panier").style.visibility = 'visible';}

/* Suppression de l'affichage du panier => Non utilisé à priori, vient de fortinet*/
function hidePanier(){ document.getElementById("panier").innerHTML="&nbsp;"; document.getElementById("panier").style.visibility = 'hidden';}

/* Change la quantité du panier dans la head */
function changeQte(idP,operation){callAjax(5, "GET", "home.htm?idp="+idP+"&op="+operation+"&t="+(new Date()).getTime(), null);}
function fn5(id){ 
	self.location.reload(); 
	//PATCH GD 081209 PanierGestion_head();
}

//-----------------------------------RECUPERATION DU PRIX----------------------------------------------------

function getThePrice(pdt){ 
callAjax(3, "GET", "SO2/getPrice16a8.html?pdt="+pdt+"&t="+(new Date()).getTime(), null);
}
function fn3(id){
	document.getElementById("PRIX").innerHTML = "<img src='/images/double_fleche_bleue.jpg' width='15' height='14' align='absbottom'>" + reponseAjax[id] + "&euro; H.T";
}  
//---------------------FONCTION D'AFFICHAGE DE LA POP UP (GD NOVEMBRE 2009)-------------------------------------

function window_onscroll() // déplace le div en fonction du scroll
{
    window.document.getElementById("boite_deplacable").style.top =  window.document.body.scrollTop+101+'px';
}
function none_popup() // fait disparaitre la pop up
{
		document.getElementById('boite_deplacable').style.display = 'none';

}
function block_popup() // fait apparaitre la pop up
{
		document.getElementById('boite_deplacable').style.display = 'block';
}

//-----------------------------AJOUT D'UNE OPTION AU PANIER (GD OCTOBRE 2008)---------------------------------
var timer;
function buyIt(modele){
	block_popup() ;
	var tab=new Array;
	tab[0]= 4 ; // id de la fonction Ajax qui va suivre
	tab[1]= modele ; // nom du modele concerné
	callAjaxTab(tab, "GET", "SO2/buyIt652a.html?md="+modele+"&t="+(new Date()).getTime(), null);
	}
	
function fn4(id,modele){ 
	PanierGestion_head();
	timer = setTimeout("none_popup();",10000);//disparait au bout de 10sec	
} 

//Arrete la minuterie de la popup a son survol
function stopMin(){	
	clearTimeout(timer);	
}
//Reprend la minuterie de la popup qd on la quitte
function startMin(){	
	timer = setTimeout("none_popup();",10000)//disparait au bout de 10sec
}

//---------------------------------AJOUT D'UN PRODUIT AU PANIER (GD OCTOBRE 2008)------------------------------
/*mise dans le panier du produit */
function buyProduct(modele){
	block_popup();
	var tab=new Array;
	tab[0]= 22 ; // id de la fonction Ajax qui va suivre
	tab[1]= modele ; // nom du modele concerné
	callAjaxTab(tab, "GET", "SO2/buyProduct652a.html?md="+modele+"&t="+(new Date()).getTime(), null); 
}

function fn22(id,modele){ 
	PanierGestion_head(); // mise à jour du panier dans la head
	timer = setTimeout("none_popup();",10000)//disparait au bout de 10sec
} 

//-------------------------------------ACHETER UN SERVICE : CHANGEMENT DU PANIER----------------------

/*mise dans le panier du service concerne*/
function buyService(id){
	callAjax(23, "GET", "SO2/buyService5445.html?id="+id+"&t="+(new Date()).getTime(), null)
	;}

function fn23(id){ PanierGestion_head(); } 

//-----------------------------------------------------------------------------------------------------

/* utilisé pour la page home le produit est mis dans le panier et on redirige l'utilisateur sur la page du produit concerne */
var uri = "";
function buyItAndGO(modele, url){ uri = url ; callAjax(6, "GET", "SO2/buyProduct652a.html?md="+modele+"&t="+(new Date()).getTime(), null); }
function fn6(id){ self.location.href=uri ;}

/*Gestion stock  //remplacé dans showproduit par une fonction jsp

function getStock(pdt){
var tab=new Array;
	tab[0]= 20 ; // id de la fonction Ajax qui va suivre
	tab[1]= pdt ; // nombre d'utilisateur pour l'option (50-100-250- ... )
	
	callAjaxTab(tab, "GET", "/SO2/getStock.jsp?pdt="+pdt+"&t="+(new Date()).getTime(), null);}


function fn20(id,pdt){
	
	var idhtml= "STK"+pdt;
	document.getElementById(idhtml).innerHTML = reponseAjax[id];
	}  
*/

function getAdnServicePrice1(pdt){callAjax(30, "GET", "SO2/getAdnServicePrice16a8.html?pdt="+pdt+"&t="+(new Date()).getTime(), null);}
function fn30(id){
	var donnees = reponseAjax[id].split("|");
 	donnees[0] = donnees[0].trim();
	if( document.getElementById(donnees[0]) ) 
	{
   		 var infos = donnees[1].trim();
   		 var dd = infos.split(" ");
		 document.getElementById(donnees[0]).innerHTML = "&euro;&nbsp;"+formatprix(dd[0]);
	}
}  

 //----------------------------AFFICHE LES OPTIONS -----------------------------------------------------------------
function getOptions(pdt){
	callAjax(33, "GET", "SO2/showOptions51ea.html?rp="+pdt+"&t="+(new Date()).getTime(), null);
}
	 
function fn33(id){
 var donnees = reponseAjax[id].trim();
if( document.getElementById("options") ) {
    document.getElementById("options").innerHTML = donnees ;
 }
}  

//---------------------------AFFICHE LES PRODUITS--------------------------------------------------------------------

function PanierGestion_getProduit(pdt){
callAjax(34, "GET", "SO2/showProduit51ea.html?rp="+pdt+"&t="+(new Date()).getTime(), null);
}
/*Affichage des options dans la balise contenant l'id produit. */
function fn34(id){
 var donnees = reponseAjax[id].trim();
if( document.getElementById("produit") ) {
    document.getElementById("produit").innerHTML = donnees ;
 }
} 
//PATCH GD 110311 Ajout fonction pour les bonnes affaires
function PanierGestion_getProduitBO(pdt){
callAjax(40, "GET", "SO2/showProduitBonneAffaire51ea.html?rp="+pdt+"&t="+(new Date()).getTime(), null);
}
/*Affichage des options dans la balise contenant l'id produit. */
function fn40(id){
 var donnees = reponseAjax[id].trim();
if( document.getElementById("produit") ) {
    document.getElementById("produit").innerHTML = donnees ;
 }
} 
 //---------------------AFFICHE LES OPTIONS POUR LE NOMBRE D'UTILISATEURS (GD FIN OCTOBRE 2008)-----------------------

function getOptionsMail(pdt,user){
	var tab=new Array;
	tab[0]= 35 ; // id de la fonction Ajax qui va suivre
	tab[1]= user ; // nombre d'utilisateur pour l'option (50-100-250- ... )
	
	callAjaxTab(tab,"GET", "SO2/showOptionsMail51ea.html?rp="+pdt+"&use="+user+"&t="+(new Date()).getTime(), null);
	// envoit le nombre d'users et le nom du produit (pour les ES le nom du produit est OPTES car ils s'appliquent à tous les ES)
}
	
function fn35(id,user){
 /*  renvoit dans le div du nombre d'user adequate le tableau formé dans la fonction getOptionsMail */
	var donnees = reponseAjax[id].trim();
	if( document.getElementById(user) ) 
	{
    	document.getElementById(user).innerHTML = donnees ;
 	}
}  

function getOptionsMail_maintenance(pdt,user){
	var tab=new Array;
	tab[0]= 355 ; // id de la fonction Ajax qui va suivre
	tab[1]= pdt ; // nombre d'utilisateur pour l'option (50-100-250- ... )
	var tabSplit=new Array;
	tabSplit = pdt.split("-");
	callAjaxTab(tab,"GET", "SO2/showOptionsMail51ea.html?rp="+tabSplit[1]+"&use="+user+"&t="+(new Date()).getTime(), null);
	// envoit le nombre d'users et le nom du produit (pour les ES le nom du produit est OPTES car ils s'appliquent à tous les ES)
}
	
function fn355(id,pdt){
 /*  renvoit dans le div du nombre d'user adequate le tableau formé dans la fonction getOptionsMail */
	var donnees = reponseAjax[id].trim();
	if( document.getElementById(pdt) ) 
	{
    	document.getElementById(pdt).innerHTML = donnees ;
 	}
} 

//-----------------------------------------------------------------------------------------------

/* voir getAdnServicePrice1*/
function getAdnServicePrice2(pdt){callAjax(31, "GET", "SO2/getAdnServicePrice16a8.html?pdt="+pdt+"&t="+(new Date()).getTime(), null);}
function fn31(id){
 /* retour =>  ref | prix */
 var donnees = reponseAjax[id].split("|");
 donnees[0] = donnees[0].trim();
if( document.getElementById(donnees[0]) ) {
  //var infos = trimALL(donnees[1]);
   var infos = donnees[1].trim();
   var dd = infos.split(" ");
 document.getElementById(donnees[0]).innerHTML = "&euro;&nbsp;"+formatprix(dd[0]);
 }
} 

/*
Enleve les espaces au debut et a la fin 
et les \r\n 
*/

String.prototype.trim = function(){
var val = this ;
 while (val.substring(0,1) == ' '){ val = val.substring(1);}
 while (val.substring(val.length-1, val.length) == ' '){val = val.substring(0,val.length-1);}
 while ( (val.charCodeAt(0,1) == 13) || (val.charCodeAt(0,1) == 10) ){ val = val.substring(1);}
 while ((val.charCodeAt(val.length-1, val.length) == 13) ||  (val.charCodeAt(val.length-1, val.length) == 10) ){val = val.substring(0,val.length-1);}
return val;
}

function showPrice(id){
 var rep = sync.getResponse(id).trim().split("|");
 
 for (var i= 0 ; i < rep.length -1 ; i+=3){
  ref = rep[i].trim() ; prix = rep[i+1].trim(); msgStock = rep[i+2]
  
  var pc = prix.indexOf("H.html"); 
     if (pc != -1) { prix = prix.substring(0,pc); prix = prix.trim();}
	
  if (document.getElementById(ref)) document.getElementById(ref).innerHTML += formatprix(prix) ;
  if (document.getElementById("STK"+ref)) document.getElementById("STK"+ref).innerHTML += msgStock;
 }// fin for
}//ff


/*
allref doit etre sous la forme : model1|model2.....|modelN
*/
function paniergestion_getShowAdnPrice(allref){
 sync.clear();
 sync.pusher(__AJAX__, 1, "GET", "SO2/getAdnServicesPrices16a8.html?pdt="+allref ,sync, null , showPrice);
 sync.caller();
}
/*
allref doit etre sous la forme : model1|model2.....|modelN
*/
function paniergestion_getShowAdnProductPrice(allref){
 sync.clear();
 sync.pusher(__AJAX__, 1, "GET", "SO2/getAdnProductPrices16a8.html?pdt="+allref ,sync, null , showPrice);
 sync.caller();
}


