// JavaScript Document
posXmenu = "50px";
posYmenu = "50px";
var xhr = null;
mouse_y = 0;
var div = "";
var clicEnCours = false;
var position_x = 0;
var position_y = 0;
var origineDiv_x = 0;
var iExplorer = false;

// fonction appellee quand le doc est pret (avant le premier rendu)
function onDocReady() {
	taille();

	if (typeof(window.activateMenu)!="undefined" && document.getElementById("selectLoc"))
	{
		activateMenu('selectLoc');
	}
	if (typeof(window.activateMenu)!="undefined" && document.getElementById("selectRub"))
	{
		activateMenu('selectRub');
	}
}

//alert('screen.availHeight '+screen.availHeight+' | screen.availTop '+screen.availTop+' | screen.height '+screen.height);

if (document.all){
  iExplorer = true;
} 

function taille() {
	// definir la taille a appliquer
	var test = navigator.appName;
	if(test != "Netscape") 
	{
		var w=document.documentElement.clientWidth;
		if (w==0)
		{
			w=document.body.offsetWidth;
		}

		if(w > 983) {
			 mode='1024';
		}
		else  {
			 mode='800';
		}
	}
	else {
		if(window.innerWidth > 1002) {
			 mode='1024';
			 } 
			else {
				 mode='800';
			}
	}

	// appliquer la classe correspondant au mode, sur le body
	document.body.className='dim_'+mode;
}

function taille_old() {
var test = navigator.appName;
if(test != "Netscape") {
	if(document.body.offsetWidth > 983) {
		 document.getElementById("page").width = "1003px";
	}
	else  {
		 document.getElementById("page").width = "100%";
	}
		}
else {
	if(window.innerWidth > 1024) {
		 document.getElementById("page").width = "1003px";
		 } 
		else {
		 document.getElementById("page").width = "100%";
		}
	}

}

function changer() {
	return;

	if(document.body.offsetWidth > 983) {
		 document.getElementById("td_qui").className = "dim_1024";
		 document.getElementById("td_ou").className = "dim_1024";
	}
}

function getXhr() { 
if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
	else 
		if(window.ActiveXObject) { 
			try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } 
			catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
		} 
		else { 
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest,veuillez le mettre à jour");
			xhr = false;
		 }
}  

function popup(url) {
	url='http://'+url
	w=open(url,'popup','width=400,height=400,directories=yes,location=yes,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes');
}



function getXhr2(){
	var xhr = null;
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
	else if(window.ActiveXObject){ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else { 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		xhr = false;
	}
	return xhr;
}



function affiche(id,url,div) {
fermer('carte');
fermer('infos');
fermer('envoie');
getXhr(); 
xhr.onreadystatechange = function() { 
	if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById(div).innerHTML = "" + xhr.responseText;
			document.getElementById(div).style.left = Mouse_X+"px";
			document.getElementById(div).style.top = Mouse_Y+"px";
			document.getElementById(div).style.visibility = 'visible';		
	} 
} 
xhr.open("POST",url,true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send("code="+id); 
} 



function fermer(div){
document.getElementById(div).style.visibility = 'hidden';	
}

// ============= Affinage ===================
function stripslashes(ch) {
   return ch.replace(/(\\)([\\\'\"])/g,"$2")
}


function affinage_activ(quoiqui1,form,ou1,geo,activ)
{
	activ = stripslashes(activ)
	document.location.href='?nxo=moteur&nxs=process&pge=0&string='+quoiqui1+'&activ_form='+form+'&ou='+ou1+'&geo='+geo+'&activ='+activ;
	
}
function affinage_activ_tourisme(quoiqui1,form,ou1,geo,activ)
{
	
	document.location.href='?nxo=moteur_tourisme&nxs=process&pge=0&string='+quoiqui1+'&activ_form='+form+'&ou='+ou1+'&geo='+geo+'&activ='+activ;
	
}
function affinage_geo(quoiqui1,form,ou1,activ,geo)
{
			
	document.location.href='?nxo=moteur&nxs=process&pge=0&string='+quoiqui1+'&activ_form='+form+'&ou='+ou1+'&activ='+activ+'&geo='+geo;
	
}
function affinage_geo_tourisme(quoiqui1,form,ou1,activ,geo)
{
			
	document.location.href='?nxo=moteur_tourisme&nxs=process&pge=0&string='+quoiqui1+'&activ_form='+form+'&ou='+ou1+'&activ='+activ+'&geo='+geo;
	
}

function check_form(mailsociete,url,div)
{
	var message=document.getElementById('message').value;
	var email=document.getElementById('email').value;
	var nom=document.getElementById('nom').value;
	var sujet=document.getElementById('sujet').value;
	
	
	if(email==""){
		alert("Veuillez remplir le Champ Votre E-mail");
		email.focus();
		return false;
	}	 

	if (email.search(/^[_a-z0-9-]+(.[_a-z0-9-]+)*[^._-]@[a-z0-9-]+(.[a-z0-9]{2,4})*$/) == -1){ 
		alert ("entrez une adresse Email valide");
		email.focus(); 
		return false;
	} 
	
	if(message ==0)
	{
		alert("Veuillez remplir le Champ Sujet ");
		formulaire.message.focus();
		return false;
	}
	
	getXhr(); 
	
	xhr.onreadystatechange = function() { 
		if(xhr.readyState == 4 && xhr.status == 200) {
				alert(posYmenu);
			document.getElementById(div).innerHTML = "<img src=\"/base/image/fermer.jpg\" style=\"cursor:pointer\" onClick=\"fermer('"+div+"')\" align=\"right\"/>"+xhr.responseText;
			document.getElementById(div).style.left = posXmenu;
//			document.getElementById(div).style.top = posYmenu;
		
			document.getElementById(div).style.top = 250;
			alert(document.getElementById(div).style.top);
			document.getElementById(div).style.visibility = 'visible';
			
		} 
	} 
	xhr.open("POST",url,true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send('mailsociete='+mailsociete+'&mailexpediteur='+email+'&sujet='+sujet+'&message='+message+'&nom='+nom); 		

}	

function Envoyer_tel(){
var tel = document.getElementById('tel').value;
var anum=/^[0-9]{2,3}[\/ \.\-]?[0-9]{2}[\/ \.\-]?[0-9]{2}[\/ \.\-]?[0-9]{2}$/;
var anum1=/^[0-9]{2,3}[\/ \.\-]?[0-9]{3}[\/ \.\-]?[0-9]{3}$/;
if (!anum.test(tel) && !anum1.test(tel)){
	document.getElementById('error').style.visibility = 'visible';
	document.getElementById('tel').value = "";
	return false;
 	}
	else
		return true;
}

function Envoyer_tel_info(){
var tel = document.getElementById('tel').value;
var anum=/^[0-9]{2,3}[\/ \.\-]?[0-9]{2}[\/ \.\-]?[0-9]{2}[\/ \.\-]?[0-9]{2}$/;
var anum1=/^[0-9]{2,3}[\/ \.\-]?[0-9]{3}[\/ \.\-]?[0-9]{3}$/;
if (!anum.test(tel) && !anum1.test(tel)){
	alert('Numéro de téléphone invalide');
	document.getElementById('tel').value = '';
	return false;
 	}
	else
		return true;
}

function nouv_tel(){
document.getElementById('error').style.visibility = 'hidden';	
}

//window.onresize = rafraichir;

function rafraichir() {
document.location.reload();

}


/*--------Statistique----------------------*/

function sgpc(_serial, _group, _page, _class) 
{ 
        document.write('<IMG src="http://prof.estat.com/cgi-bin/ft/'+ 
        _serial+ '?'+ 
        '&n='+ Math.round (Math.random () * 1000000000000000)+ 
        '&group='+ _group+ 
        '&page='+ _page+ 
        '&class='+ _class+ 
        '&referer='+ escape(document.referrer)+'" border=0>' ); 

} 



/*---------------  Ajouter aux favoris --------------------*/

function favoris() {
      if ( navigator.appName != 'Microsoft Internet Explorer' ){
          window.sidebar.addPanel("Télécontact","http://www.telecontact.ma","");
      }
      else {
          window.external.AddFavorite("http://www.telecontact.ma","Télécontact");
      }
}

