

function alphaOk() {
 try {
  var ie =(window.navigator.appName.indexOf('Microsoft')!=-1);
  var version = parseFloat(window.navigator.appVersion);
  if (ie) {
   var idx = window.navigator.appVersion.indexOf('MSIE');
   var vers = window.navigator.appVersion.substr(idx+5, 3);
   version = parseFloat(vers);
  }
  
  return !(ie && version<7);
 } catch (e) {
  return false;
 } 
}








function setImgOpacity(obj) {
 var imgs = null;
 if (obj.tagName=='IMG')
  imgs = new Array(obj);
 else 
  imgs = obj.getElementsByTagName('IMG');
 if (imgs.length>0) {
  
  if (document.all) {
   if (obj == imgs[0]) {
    imgs[0].className='btn_opacityon';
   } 
   imgs[0].onmouseover = function (e) {
    this.className='btn_opacityon';
    
   }
   imgs[0].onmouseout = function (e) {
    this.className='';
   }
   
  } else {
   imgs[0].className='btn_opacity';
   obj.setAttribute("onmouseover","");
  }
 } 
 
  
}

function getURLParams(byindex) {
 urlvar = new Array();
 urlvarnum = new Array();
 if (window.location.search != "") {
  longueur = window.location.search.length - 1;
  data = window.location.search.substr(1,longueur);
  donnees = data.split("&");
  
  for (var i=0; i < donnees.length; i++) {
   position = donnees[i].indexOf("=");
   variable = donnees[i].substr(0,position);
   pos = position + 1;
   valeur = decodeURI(donnees[i].substr(pos,donnees[i].length));
   while (valeur.search(/\+/) != -1)
    valeur = valeur.replace(/\+/," ");
   urlvar[variable] = valeur;
   urlvarnum[i] = valeur;
  }
 }
 if (byindex)
  return urlvarnum;
 else
  return urlvar; 
} 

function loaded(){
 $('loaderImg').hide();
 $('page').show();
}


function getLeftAbsolute(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
	 if (el==document.body)
	  return tmp;
		tmp += el.offsetLeft;
		
		el = el.offsetParent;
	}
	return tmp;
}

function getRightAbsolute(el) {
	var tmp = el.offsetLeft;
	var w = el.offsetWidth;
	el = el.offsetParent
	while(el) {
	 if (el==document.body)
	  return tmp + w;
		tmp += el.offsetLeft;
		
		el = el.offsetParent;
	}
	return tmp + w;
}

function getTopAbsolute(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
	 if (el==document.body)
	  return tmp;
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}

function getParent(el) {
 if (el.parentNode) 
  return el.parentNode;
 else
  return el.parentElement; 
}

function getTarget(e) {
 if (window.event) e = window.event;
 return e.target ? e.target : e.srcElement;
}

function afficheAscenseur() {
 //if (alphaOk()) {
  if (!asc)
   asc = new Ascenseur($('epage'));
  asc.show(); 
 //} //else afficheBadAscenseur();
}

function afficheBadAscenseur() {
 if (!alphaOk()){
  if ($('epage'))
   var doc = $('epage').contentWindow.document; 
  else
   var doc = document; 
  //doc.write('<style type="text/css">');
  //doc.writeln('html { overflow:auto; }');
  //doc.write('body { overflow:visible; }');
  //doc.write('</style>');
  doc.body.style.overflow = "auto";
  
 } 
}

function cacheAscenseur() {
 if (asc) 
  asc.hide();
  
}



//drag & drop
var ie=document.all;
var x,y;
var lift = null;
var dragapproved=false;
var nDrag = 0;

function move(e){
if (window.event) e = window.event;
var target = e.target ? e.target : e.srcElement;
if((e.button==1 || e.which==1)&&dragapproved)
	{
	if (lift) {
	 lift.style.left="0px";
	 
	 if (lift.offsetTop>=0 && lift.offsetTop<=(getParent(lift).offsetHeight-lift.offsetHeight))
	  lift.style.top=(temp2+e.clientY-y)+"px";
	} else { 
	 $("msg-box").style.left=(temp1+e.clientX-x)+"px";
	 $("msg-box").style.top=(temp2+e.clientY-y)+"px";
	} 
	return false
	}
}

function drags(e){
if (window.event) e = window.event;
var target = e.target ? e.target : e.srcElement;
evclass=target.className
//alert(evclass);
if(evclass=="win-header" || evclass=="win-tl" || evclass=="win-tc" || evclass=="win-tr" || evclass=="win-header-text" || evclass=="lift")
	{
	if (evclass=="lift")
	 lift = target;
	else
	 lift = null; 
	dragapproved=true;
	nDrag++;
	if (lift) {
	 lift.onmouseup = stopDrags;
	 temp1=0;
	 temp2=target.offsetTop;
	 x=e.clientX;
	 y=e.clientY;
	} else {
	 temp1=$("msg-box").offsetLeft;
	 temp2=$("msg-box").offsetTop;
	 x=e.clientX;
	 y=e.clientY;
	}
	
	document.onmousemove=move}
}

function stopDrags(e) {
  dragapproved=false;
  if (lift) {
   if (lift.offsetTop<0) lift.style.top = "0px";
   if (lift.offsetTop>(getParent(lift).offsetHeight-lift.offsetHeight)) lift.style.top = (getParent(lift).offsetHeight-lift.offsetHeight) + "px";
  }
   
  lift = null;
  nDrag--;
 }; 


document.onmousedown=drags;
document.onmouseup=stopDrags;



// End Drag & Drop //

function createPlan(fichier,width,height,bgcolor) {
 if (window.parent == window)
  return new Plan(fichier,width,height,bgcolor);
 else
  return new window.parent.Plan(fichier,width,height,bgcolor); 
}

function Plan(fichier,width,height,bgcolor) {
 
 if (window.parent == window) {
  this.element = document.createElement('div');
  document.body.appendChild(this.element);
 } else {
  this.element = window.parent.document.createElement('div');
  window.parent.document.body.appendChild(this.element); 
 } 
 if (bgcolor)
  this.element.style.backgroundColor = bgcolor;
 this.element.style.height = height + "px";
 this.element.style.width = width + "px";
 
 this.image = new Image();
 this.image.src = fichier;
 this.image.alt = "Cliquez pour fermer";
 this.image.title = "Cliquez pour fermer";
 this.image.style.cursor= "pointer";
 this.element.appendChild(this.image);
 
 
 this.element.style.top = "50%";
 this.element.style.left = "50%";
 try {
  this.element.style.marginLeft = (-width/2) + "px";
  this.element.style.marginTop = (-height/2) + "px";
 } catch(e) {
 } 
 
 
 this.element.style.position = "absolute";
 this.element.style.border = "2px solid Black";
 this.element.style.textAlign = "right";
 this.element.style.verticalAlign = "top";
 this.image.fPlan = this;
 this.image.onmousedown = function (e) {
  setImgOpacity(getTarget(e));
 }
 this.image.onclick = function(e) {
  var t = getTarget(e);
  t.fPlan.close();
 }
 this.close = function() {
  if (window.parent == window)
  document.body.removeChild(this.element);
 else
  window.parent.document.body.removeChild(this.element);
 }
}

function controlForm() {
	if ($('ed_mail').value =='')
		return 'Vous devez saisir votre email.';
	else if ($('ed_mail').value.indexOf('@')==-1 || $('ed_mail').value.indexOf('.')==-1)
		return 'Email non valide.' 
}

var XHRmel;

function Mel(atype) {
	this.typeMel = atype;
	this.expediteur = '';
	this.nom = '';
	this.company = '';
	this.corps = '';
	
	this.envoi = function() {
		XHRmel = creationXHR();
		if (XHRmel==null) return null;
		XHRmel.mel = this;
		var parametres = "typeMel="+this.typeMel;
		parametres += "&expediteur="+this.expediteur; 
		parametres += "&nom="+this.nom;
		parametres += "&company="+this.company;
		parametres += "&message="+this.corps;
		
		XHRmel.onreadystatechange = function()  { 
		  if(XHRmel.readyState == 4) {
		   if(XHRmel.status == 200) {
			   if (XHRmel.responseText=='ok'){
			    alert('Mail envoyé');
			   } else {
				alert('Erreur durant envoi mail.');
			   }
		   }
		  }
		}

		
		XHRmel.open("POST",'/requests/db_envoimel.php',true);
		XHRmel.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		XHRmel.send(parametres);
		 
		 
	}
}

function melFromForm() {
	var m = new Mel($('cb_typecontact').value);
	m.expediteur = $('ed_mail').value;
	m.nom = $('ed_nom').value;
	m.company = $('ed_entreprise').value;
	m.corps = $('ed_message').value;
	return m;
}

function formEnvoi() {
 var err = '';
 err = controlForm();
 if (err) {alert(err);return;}
 
 var m = melFromForm();
 m.envoi();

}
