var nomRepServeur = 'http://www.promoalert.com';

//affichage du menu déroulant et placement de ce dernier
function etend(id)
{
	var d = document.getElementById(id);
	//si on quitte un élément du menu
	if (d && (d.style.display=='block'))
	{
		d.style.display='none'; //on l'efface
		var c=d.parentNode; //son parent
		if (c.parentNode.parentNode.parentNode.tagName!='DIV')  //si c'est un sous-menu, on rend à son parent les couleurs d'origine
		{
			c.firstChild.style.color='#ea661d';
			c.firstChild.style.background='#fff';
		}
	}
	//sinon si on se mets sur un élément du menu
	else if (d && (d.style.display=='none'))
	{ 
		d.style.display='block'; //on l'affiche
		var c=d.parentNode; //son parent
		if (c.parentNode.parentNode.parentNode.tagName!='DIV') //si c'est un sous-menu, on donne à son parent les couleurs de survol
		{
			c.firstChild.style.color='#fff';
			c.firstChild.style.background='#ea661d';
		}
	}
}

/**
 * Renvoie la taille de la page courante ainsi que la taille de la zone cliente du navigateur
 */
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;
	return {'pageWidth': pageWidth, 'pageHeight': pageHeight, 'windowWidth': windowWidth, 'windowHeight': windowHeight};
}

function ouverture(url,id) {
 
   var xhr_object = null;
   var position = id;
   
   if(window.XMLHttpRequest) { 
      xhr_object = new XMLHttpRequest(); 
      }
   else 
      if(window.ActiveXObject) { 
         xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
          }
      else  { 
         alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
      }
  
   // On ouvre la requete vers la page désirée
   xhr_object.open("GET", url, true);
   xhr_object.onreadystatechange = function() {
         if ( xhr_object.readyState == 4 ) {
             if(xhr_object.status != 200) {
               document.getElementById(position).innerHTML ="Erreur " + xhr_object.status;
                } 
             else {
                 // on affiche ou cache dans la DIV spécifiées le contenu retourné par le fichier                
                 if (document.getElementById) {
                     if (document.getElementById(position).style.display == "block") {                    
                           document.getElementById('filter_masque').style.display='none'; 
                           document.getElementById(position).style.display='none';                     
                       }
                     else 
                        if (document.getElementById(position).style.display == "none") {                            
                            var pageSize = getPageSize();            
                                                                             
                            //document.getElementById('filter_masque').style.width = pageSize.pageWidth + "px";
                            document.getElementById('filter_masque').style.height = pageSize.pageHeight + "px";
                                                           
                             document.getElementById('filter_masque').style.display='block'; 
                             document.getElementById(position).style.display='block';
                          }
                        else { 
                               document.getElementById('filter_masque').style.display='none'; 
                               document.getElementById(position).style.display='none';
                        }
                 }
                 document.getElementById(position).innerHTML = xhr_object.responseText;
             }
           } 
         else { 
            document.getElementById(position).innerHTML = '<p style="text-align:center">Chargement des données en cours...</p>'; 
         }
   }
   // dans le cas du get
   xhr_object.send(null);
}

function changeVille() {

   var xhr_object = null;
   
   if(window.XMLHttpRequest) { 
      xhr_object = new XMLHttpRequest(); 
      }
   else 
      if(window.ActiveXObject) { 
         xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
          }
      else  { 
         alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
      }
  
   // On ouvre la requete vers la page désirée
   var url = nomRepServeur + '/services/changeVille.php?idVilleNew='+document.getElementById('idVille').value;
 
   xhr_object.open("GET", url, true);
   xhr_object.onreadystatechange = function() {
         if ( xhr_object.readyState == 4 ) {
             if(xhr_object.status != 200) {
               //document.getElementById(position).innerHTML ="Erreur " + xhr_object.status;
                } 
             else {
                 //document.getElementById(position).innerHTML = xhr_object.responseText;
                    document.getElementById('filter_masque').style.display='none'; 
                    document.getElementById('popupmessage').style.display='none';                    
                    document.getElementById('maville').innerHTML = xhr_object.responseText; 
             }
           } 
         else { 
            document.getElementById(position).innerHTML = '<p style="text-align:center">Chargement des données en cours...</p>'; 
         }
   }
   // dans le cas du get
   xhr_object.send(null);
   
   location.href= nomRepServeur;	
}


function filtre(chaine) {
  temp = chaine.replace(/[ÀÁÂÃÄÅàáâãäå]/gi,"a")
  temp = temp.replace(/[ÈÉÊËèéêë]/gi,"e")
  temp = temp.replace(/[ÌÍÎÏìíîï]/gi,"i")
  temp = temp.replace(/[ÒÓÔÕÖðòóôõö]/gi,"o")
  temp = temp.replace(/[ÙÚÛÜùúûü]/gi,"u")
  temp = temp.replace(/[Ýýÿ]/gi,"y")
  temp = temp.replace(/[Çç]/gi,"c")
  temp = temp.replace(/[Ññ]/gi,"n")

  return temp
}

function rechercheVille(nomEnseigne){
		var magasin;
		var idVille;
		magasin = document.formRequestVille.idEnseigne.value;
		idVille = document.formRequestVille.idVille.value;
    nomVille = document.formRequestVille.nomVille.value;
    
    var positionCodePostal = nomVille.indexOf(" \(");
    
    ville =  nomVille.substring(0, positionCodePostal);
    ville = ville.toLowerCase();
    ville = ville.replace('/[^a-z0-9_-\s]/', '');
    ville = ville.replace('/[\s]+/', ' ');
    ville = ville.replace(' ', '-');    
    ville = filtre(ville);    
 
    if (idVille!=0) {
  		  location.href= nomRepServeur+ "/magasin/"+nomEnseigne+"-"+ville+"-horaires-adresse-"+magasin+"-"+idVille+"-0-0-0-0.html";	
    }    		
}
 