// ----- Checkbox Check All
function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}



var formblock;
var forminputs;
 
function prepare() {
	if(document.getElementById('courrier')){
		formblock= document.getElementById('courrier');
		forminputs = formblock.getElementsByTagName('input');
	}
}
 
function select_all(name, value) {
  for (i = 0; i < forminputs.length; i++) {
    // regex here to check name attribute
    var regex = new RegExp(name, "i");
    if (regex.test(forminputs[i].getAttribute('name'))) {
      if (value == '1') {
		  if(forminputs[i].disabled == false){
        	forminputs[i].checked = true;
		  }
      } else {
        forminputs[i].checked = false;
  }
    }
  }
}
 
if (window.addEventListener) {
  window.addEventListener("load", prepare, false);
} else if (window.attachEvent) {
  window.attachEvent("onload", prepare)
} else if (document.getElementById) {
  window.onload = prepare;
}





// ----- Checkbox Check All



function afficherDiv(id){
	
	if(document.getElementById(id)){
		
		if(document.getElementById(id).style.display == 'block'){
			document.getElementById(id).style.display = 'none'
		}else{
			document.getElementById(id).style.display = 'block'
		}
		
	}
	
}

var timeOutMessage;
function afficherMessage(){
	
	if(afficherMessage.arguments[0] && afficherMessage.arguments[1]){
		clearTimeout(timeOutMessage);
		document.getElementById(afficherMessage.arguments[0]).innerHTML = afficherMessage.arguments[1];
		document.getElementById(afficherMessage.arguments[0]).style.display = 'block';
		timeOutMessage = setTimeout('afficherMessage('+afficherMessage.arguments[0]+')', 5000);
	}else{
		if(afficherMessage.arguments[0]){
			afficherMessage.arguments[0].style.display = 'none';
			afficherMessage.arguments[0].innerHTML = '';
		}else{
			document.getElementById('divMessage').style.display = 'none';
			document.getElementById('divMessage').innerHTML = '';
		}
	}
	
}

function enLigne(login){
	
	if(login!=0){
		
		var xhr; 
		try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
		catch (e) 
		{
			try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
			catch (e2) 
			{
			  try {  xhr = new XMLHttpRequest();     }
			  catch (e3) {  xhr = false;   }
			}
		 }
	  
	   xhr.open( "POST", "ajax/enligne.php",  true); 
	   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   xhr.send(); 	
			
	}
	
	window.setTimeout("enLigne("+login+")",120000);
	
}


function getElementLeft(Elem) {

	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;

}


function getElementTop(Elem) {

	if(document.getElementById) {	
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;

}


function menuPosition(id){
	
	document.getElementById('sm_'+id).style.top = getElementTop('m_'+id) + 21 + 'px';
	document.getElementById('sm_'+id).style.left = getElementLeft('m_'+id) - 1 + 'px';
	
}







// POPUP SPECIAL


var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "standard";
var w = "780";
var h = "580";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}


function findPopUps()
{
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
	{
	if(popups[i].rel){
		if (popups[i].rel.indexOf("popup")!=-1)
			{
			// attach popup behaviour
			popups[i].onclick = doPopUp;
			// add popup indicator
			/*if (popups[i].rel.indexOf("noicon")==-1)
				{
				popups[i].style.backgroundImage = "url(pop-up.gif)";
				popups[i].style.backgroundPosition = "0 center";
				popups[i].style.backgroundRepeat = "no-repeat";
				popups[i].style.paddingLeft = "15px";
				}*/
			// add info to title attribute to alert fact that it's a pop-up window
			//popups[i].title = popups[i].title + " [Opens in pop-up window]";
			}
		}
	}
}

if (window.addEventListener) {
  window.addEventListener("load", findPopUps, false);
} else if (window.attachEvent) {
  window.attachEvent("onload", findPopUps)
} else if (document.getElementById) {
  window.onload = findPopUps;
}

//addEvent(window, 'load', findPopUps, false);



document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}; 



flashTextEtat = 0;
function flashText(){
	
	if(flashTextEtat==0){ flashTextEtat=1; }else{ flashTextEtat=0; }
	
	elm = document.getElementsByClassName('flashText');
	
	for (i=0;i<elm.length;i++){
		if(elm[i].name){
			if(elm[i].name.length == 13){
				couleur = elm[i].name.split(':');
				elm[i].style.color = '#' + couleur[flashTextEtat];
			}
		}
	}
	
	
	
	setTimeout('flashText()', 1000);
	
}

if (window.addEventListener) {
  window.addEventListener("load", flashText, false);
} else if (window.attachEvent) {
  window.attachEvent("onload", flashText)
} else if (document.getElementById) {
  window.onload = flashText;
}

