// JavaScript Document

// GetElementByID PERSO
/*
if(!document.getElementById){
  if(document.all){
    document.getElementById=function(){
if(typeof document.all[arguments[0]]!="undefined"){return document.all[arguments[0]]}else{return null}
    }
  }else if(document.layers){
    document.getElementById=function(){
if(typeof document[arguments[0]]!="undefined"){return document[arguments[0]]}else{return null}
    }
  }
}

// pour ie5
Array.prototype.push = ArrayPush;
function ArrayPush(value){
    this[this.length] = value;
}
*/
function getVar(urlVarName) {
   var urlHalves = String(document.location).toLowerCase().split('?');
   var urlVarValue = '';
   if(urlHalves[1]){
      var urlVars = urlHalves[1].split('&');
      for(var i=0; i<=(urlVars.length); i++){
         if(urlVars[i]){
            var urlVarPair = urlVars[i].split('=');
            if (urlVarPair[0] && urlVarPair[0] == urlVarName.toLowerCase()) {
               urlVarValue = urlVarPair[1];
            }
         }
      }
   }
   return urlVarValue;
} 


function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function HideAllSmenu()
{
	SMenus = getElementsByClassName(document, "div", "SMenu"); 
	for (var j = 0; j < SMenus.length; ++j) { 
		SMenus[j].style.display="none";			
		}
	SMenus = getElementsByClassName(document, "a", "navBtnActive"); 
	for (var j = 0; j < SMenus.length; ++j) { 
			SMenus[j].className="navBtn";
		}
}
	
function showSMenu(a, idmenu){
		HideAllSmenu();
		var smenu=document.getElementById("sMenu"+idmenu);
		smenu.style.display="block";
		a.className="navBtnActive";
		}

function mailpage()
{
	var eaccent="%E9"; 
	if(navigator.appVersion.indexOf("Mac",0)>0)
	{eaccent="%8E";}
	var avant = location.href;
 	var url_propre = avant.replace(/\?/,"%3F");

	mail_str = "mailto:?subject=Article de l'AVFT ";
	mail_str += "&body=Sur le site de Association europ"+eaccent+"enne contre les Violences faites aux Femmes au Travail ";
	mail_str += "(http://www.avft.org/), un article int"+eaccent+"ressant : " + url_propre;
	location.href = mail_str;
}


// XMLHTTPREQUEST + MESSAGEBOX
	
// Afficher/Masquer les messages

function ShowMessage(Message)
{
	// prep objects
	var MBox = document.getElementById('MBox');
	var MBoxContent   =  document.getElementById("MBoxContent");

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	MBoxContent.innerHTML=Message;
	
	MBox.style.left =  (  ( (arrayPageSize[0]/2) - 150 ) + 'px'  );
	MBox.style.top =  ( (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - MBox.style.height) / 2)) + 'px');
	//alert(arrayPageSize[0]+"-----"+MBox.style.width);
	MBox.style.display = 'block';
	MBox.style.visibility = 'visible';
}

function HideMessage()
{
	var Container = document.getElementById("MBox");
	var Content   =  document.getElementById("MBoxContent");
	Container.style.visibility="hidden";
	Container.style.display="none";
	Content.innerHTML = "";
}
			
var xhr = null;

function getXhr(){
	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 { // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   xhr = false;
	}
}

/**
* Méthode qui sera appelée sur le click du bouton
*/
function RegisterMail(){
			
	//ShowMessage("inscription en cours...");
	getXhr();
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
										reponse="";
										// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
										if(xhr.readyState == 4 && xhr.status == 200){
											reponse = xhr.responseText;
											ShowMessage(reponse);
											}										
										}

	// Ici on va voir comment faire du post
	xhr.open("POST","register_newsletter.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	// ne pas oublier de poster les arguments
	adresse = document.getElementById('Mail').value;
	xhr.send("adresse="+adresse);
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
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;
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Redirection select
function GoTo(select) {
	var index=select.selectedIndex
	if (select.options[index].value != "0") {
	location=select.options[index].value;
	}
}

function focusSearch(searchField) {
	if(searchField) {
		searchField.onfocus = function() {searchField.className = "focus"; if(searchField.value == "rechercher") {searchField.value = '';} }
		searchField.onblur = function() {searchField.className = "";}
	}
}



