var clic = 0, dclic = null;
var tel_obl;

function eventPointCarte() { 
  if (document.getElementById) { 
        if (document.getElementById('pos_image')) { 
			d = document.getElementById('pos_image');
			d = d.getElementsByTagName('img');
			for(i=0;i!=d.length;i++){
				d[i].onmouseover = function() { 
					this.src="/images/pointg.jpg";
					document.getElementById("div_detail_pdv").innerHTML = "<span class=\"bleuGras\">"+this.getAttribute("rsoc")+"</span>"+"<br/>";
					document.getElementById("div_detail_pdv").innerHTML  += "<span class=\"texte_bleu\">"+this.getAttribute("ville")+"</span><br/>";
					
					if (this.getAttribute("tel")!="")
						document.getElementById("div_detail_pdv").innerHTML  += "<span class=\"texte_bleu\">"+"Tél : "+this.getAttribute("tel")+"</span><br/>";
					if (this.getAttribute("fax")!="")
						document.getElementById("div_detail_pdv").innerHTML  += "<span class=\"texte_bleu\">"+"Fax : "+this.getAttribute("fax")+"</span><br/>";
					
					if (this.getAttribute("specialite_on")=="1")
						document.getElementById("div_detail_pdv").innerHTML  += "<span class=\"rougegras\">Spécialité(s)<br/></span><span class=\"texte_rouge\">" + this.getAttribute("specialite").replace(/\\n/,"<br/>") + "</span>";

				} 
				d[i].onmouseout = function() { 
					this.src="/images/point.gif";
					document.getElementById("div_detail_pdv").innerHTML = "<span class=\"bleuGras\">Survoler un point de la carte <br/>pour faire apparaître dans ce cadre <br/>les informations correspondantes.</span>";
				} 
				d[i].onclick = function() { 
					document.location = "pdv.asp?id="+this.getAttribute("id_ville");
				}
				
			}
        } else 
        if (document.getElementById('cg_pos_image')) { 
			d = document.getElementById('cg_pos_image');
			d = d.getElementsByTagName('img');
			for(i=0;i!=d.length;i++){
				d[i].onmouseover = function() { 
					if (clic)
						dclic.src = "/images/point.gif";
					dclic = null;
					this.src="/images/pointg.jpg";
					document.getElementById("div_detail_pdv").innerHTML = "<br/>";
					if (this.getAttribute("photo")!="")
						document.getElementById("div_detail_pdv").innerHTML += "<img src=\""+this.getAttribute("photo")+"\" border=\"0\">"+"<br/>";
					document.getElementById("div_detail_pdv").innerHTML += "<br/>"+"<span class=\"bleuGras\">"+this.getAttribute("rsoc")+"</span>"+"<br/>"
					document.getElementById("div_detail_pdv").innerHTML += "<span class=\"rougegras\">"+this.getAttribute("ville")+"</span><br/>";
					document.getElementById("div_detail_pdv").innerHTML += "<br/>";
					if (this.getAttribute("tel")!="")
						document.getElementById("div_detail_pdv").innerHTML += "<span class=\"texte_bleu\">"+"Tél : "+this.getAttribute("tel")+"<br/>"+"</span>";
					if (this.getAttribute("fax")!="")
						document.getElementById("div_detail_pdv").innerHTML += "<span class=\"texte_bleu\">"+"Fax : "+this.getAttribute("fax")+"<br/>"+"</span>";
					document.getElementById("div_detail_pdv").innerHTML += "<br/>";
						
					if (this.getAttribute("specialite_on")=="1")	
					{
						document.getElementById("div_detail_pdv").innerHTML  += "<span class=\"rougegras\">Spécialité(s)<br/></span><span class=\"texte_rouge\">" + this.getAttribute("specialite").replace(/\\n/,"<br/>") + "</span>";
						document.getElementById("div_detail_pdv").innerHTML += "<br/><br/>";
					}

					if (this.getAttribute("responsable")!="")
						document.getElementById("div_detail_pdv").innerHTML += "<span class=\"bleugras\">Responsable : "+this.getAttribute("responsable")+"<br/></span>";
						
					clic = 0;
				} 
				d[i].onmouseout = function() { 
					if (!clic)
					{
						this.src="/images/point.gif";
						document.getElementById("div_detail_pdv").innerHTML = "<br class=\"br\"/><br class=\"br\"/><br class=\"br\"/><br class=\"br\"/><br class=\"br\"/><br class=\"br\"/><br class=\"br\"/><br class=\"br\"/><span class=\"bleuGras\"><span class=\"rougegras\">Survoler un point de la carte</span> <br class=\"br\"/><br class=\"br\"/>La photo et les infos pratiques du point de vente apparaissent<br class=\"br\"/><br class=\"br\"/><br class=\"br\"/><span class=\"rougegras\">Cliquez sur un point de la carte</span><br class=\"br\"/><br class=\"br\"/>Vous serez redirigé vers une<br class=\"br\"/>description détaillée du point de vente.</span>";
					}
				} 

				d[i].onclick = function() { 
					//if (clic==1)
						document.location = "pdv.asp?id="+this.getAttribute("id_ville");
						/*
					this.src="/images/pointg.jpg";
					document.getElementById("div_detail_pdv").innerHTML = "<br/>"+"<img src=\""+this.getAttribute("photo")+"\" border=\"0\">"+"<br/>";
					document.getElementById("div_detail_pdv").innerHTML += "<br/>"+"<span class=\"bleuGras\">"+this.getAttribute("rsoc")+"</span>"+"<br/>"
					document.getElementById("div_detail_pdv").innerHTML += "<span class=\"rougegras\">"+this.getAttribute("ville")+"</span><br/>";
					document.getElementById("div_detail_pdv").innerHTML += "<br/>";
					if (this.getAttribute("tel")!="")
						document.getElementById("div_detail_pdv").innerHTML += "<span class=\"texte_bleu\">"+"Tél : "+this.getAttribute("tel")+"<br/>"+"</span>";
					if (this.getAttribute("fax")!="")
						document.getElementById("div_detail_pdv").innerHTML += "<span class=\"texte_bleu\">"+"Fax : "+this.getAttribute("fax")+"<br/>"+"</span>";
					document.getElementById("div_detail_pdv").innerHTML += "<br/>";
					if (this.getAttribute("responsable")!="")
						document.getElementById("div_detail_pdv").innerHTML += "<span class=\"bleugras\">Responsable : "+this.getAttribute("responsable")+"<br/></span>";
					clic = 1;
					dclic = this;
					*/
				} 

			}
		
        } 		
    } 
} 


 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
 
addLoadEvent(eventPointCarte); 

function ouvrir_fenetre(adresse) {
	window.open(adresse,'instantcustompopup', 'width=800,height=860,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,location=yes,directories=yes');
	return;
}	


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function save_pj(fic) {
    location.href = "/includes/lib_asp/download.asp?f="+fic;
}


function verify_form() {

	var reg = new RegExp("-","g");
	if (document.form_form.id_type_user[document.form_form.id_type_user.selectedIndex].text.replace(reg,"")=="")
	{
		alert("Veuillez sélectionner votre métier.");
		return false;
	}
	
	if (document.form_form.nom.value.length<4) {
		return warnInvalid(document.form_form.nom,"Veuillez saisir le nom");
	}

	if (document.form_form.prenom.value.length<4) {
		return warnInvalid(document.form_form.prenom,"Veuillez saisir le prénom");
	}

	vider_adr();
	
	if (document.form_form.adresse.value.length<4) 
		return warnInvalid(document.form_form.adresse,"Veuillez saisir l'adresse");	

	if (document.form_form.adresse.value.length>256) {
		alert("L'adresse ne doit pas dépasser 256 caractères");
		document.form_form.adresse.focus();
		return false;
	}
	
	if (document.form_form.cp.value.length<5) {
		return warnInvalid(document.form_form.cp,"Veuillez saisir le code postal");
	}

	if (document.form_form.ville.value=="") {
		return warnInvalid(document.form_form.ville,"Veuillez saisir la ville");
	}
	
	if (document.form_form.email.value!="")
		if (!verifierMail(document.form_form.email.value)) {
			return warnInvalid (document.form_form.email, "Veuillez vérifier l'adresse email");
    }
	
	if (tel_obl==1)
	{
		if (document.form_form.tel.value=="")
			return warnInvalid (document.form_form.tel, "Veuillez renseigner le numéro de télephone");
	}
	
	if (document.form_form.adresse2.value.length>256) {
		alert("L'adresse ne doit pas dépasser 256 caractères");
		document.form_form.adresse2.focus();
		return false;
	}
	
	if (document.form_form.cp2.value!="" && document.form_form.cp2.value.length<5) {
		return warnInvalid(document.form_form.cp2,"Veuillez saisir le code postal");
	}

	if (document.form_form.texte_descriptif.value.length>2500) {
		alert("Le texte descriptif ne doit pas dépasser 2500 caractères");
		document.form_form.adresse.focus();
		return false;
	}
	document.form_form.submit();
}


function vider_adr() {
	if (estVide(document.form_form.adresse.value)) 
		document.form_form.adresse.value = "";
}

function vider_adr2() {
	if (estVide(document.form_form.adresse2.value)) 
		document.form_form.adresse2.value = "";
}

function vider_descr() {
	if (estVide(document.form_form.texte_descriptif.value)) 
		document.form_form.texte_descriptif.value = "";
}

function estVide(s) {
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charCodeAt(i);
		if (c!=32 && c!=160 && c!=9) return false;
	}
	return true;
}

function warnInvalid (theField, s){
    theField.focus();
    theField.select();
    alert(s);
    return false;
}

function verifierMail(chaine) {
  if (chaine.indexOf("@") >0) {
     var a = chaine.split("@");
     if (a.length>=2) {
		if (a[0]=="" || !charValid(a[0]) || a[0].substr(a[0].length-1)=="." || a[0].substring(0,1)==".")
		   return false;
		if (a[1]=="" || !domainValid(a[1]))   
		   return false;
     }
     else
		return false;
  } else
     return false;
  return true;     
}

function charValid(chaine) {
   for (i=0; i<chaine.length; i++) {
     if (!isAlpha(chaine.charAt(i)) && !isDigit(chaine.charAt(i)) && chaine.charAt(i)!='.' && chaine.charAt(i)!='_' && chaine.charAt(i)!='-')
        return false;
   }     
   return true;  
}

function domainValid(chaine) {
	var p=chaine.indexOf(".");
	if (p>0) {
		d1 = chaine.substring(0,p);
		d2 = chaine.substr(p+1);
		if (!charValid(d1) || d1.substr(d1.length-1)=="." || d1.substring(0,1)==".")
		{
		   return false;
		}   
		if (d2=="")   
			return false;
					
		if (!charValid(d2) || d2.substr(d2.length-1)=="." || d2.substring(0,1)==".") {
		   return false;
		}   
   } else {
		if (!charValid(chaine))
			return false;
	}
   return true;  
}

function isAlpha(x) {
  if ((x.toUpperCase()>='A' && x.toUpperCase()<='Z') || x=="é" || x=="à" || x=="ê" || x=="è" || x=="ç" || x=="ù" || x=="-" || x=="'") 
     return true;
  else
     return false;   
  return true;   
}

function isEmpty(s){
	return ((s == null) || (s.length == 0));
}
			
function isDigit (c) { 
	return ((c >= "0") && (c <= "9"));
}

function check_tel(numtel){
	var ret = true;
	var i = 0;
	var ch;
	var ret;
	for (i = 0; i < eval(numtel.length); i++){
		ch = numtel.charAt(i);
		if (!isDigit(ch) && ch!='.' && ch!=' ')
			return false;
	}
	return true;
}

function verify_form_rec() {
	document.form_form.submit();
}

function MM_openBrWindow1(theURL,winName,features,titre) { //v2.0
  ow = window.open("",winName,features);
  ow.document.write("<html>"+"\n");
  ow.document.write("<title>"+titre+"</title>"+"\n");
  ow.document.write("<body>"+"\n");
  ow.document.write("<img src=\""+theURL+"\" border=\"0\">"+"\n");
  ow.document.write("</body>"+"\n");
  ow.document.write("</html>"+"\n");
  return true;
}


function go1_article1(i) {
	var x;
	x = document.formul_article1["lien_article"+i][document.formul_article1["lien_article"+i].selectedIndex].value;
	arr = x.split(",");
	document.location="doss.asp?id="+arr[0]+"&pageno="+arr[1]+"&i="+arr[2]+"#art"+arr[2];	
};

