// JavaScript Document



function showImgGr(src) {
	_Elem('grImg').src=src;

	Show('grImgDv');
	_Elem('grImgDv').style.top = document.body.scrollTop+10;
	if (_Elem('grImgDv').style.top.replace(/px/,'') < 232) _Elem('grImgDv').style.top = 232;
}
var selectDefVal = new Array();
function doSelect(nom, optObj){
	strNew = '';
  aryOpt = getElementsByClass('opt'+nom, _Elem('opt'+nom));

	for (ii = 0 ; ii < aryOpt.length; ii++) {
			if (aryOpt[ii].checked == true) {
        	HTMLStr = aryOpt[ii].parentNode.innerHTML.split('&nbsp;') ;
					strNew += ', '+HTMLStr[1];
			}
		}
	_Elem('input'+nom).value=strNew.replace(/^, /,'');
  if (!_Elem('input'+nom).value) _Elem('input'+nom).value = selectDefVal[nom];
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
// insere du code html avant un element de la page..
function _InsertHtmlBefore( html, element ) {
    	if ( element.insertAdjacentHTML )	// IE
    	{
    		element.insertAdjacentHTML( 'beforeBegin', html ) ;
    	}
    	else								// Gecko
    	{
    		var oRange = document.createRange() ;
    		oRange.setStartBefore( element ) ;
    		var oFragment = oRange.createContextualFragment( html );
    		element.parentNode.insertBefore( oFragment, element ) ;
    	}
  }

// surcharge de la fonction getElementById pour simplifer le codage
function _Elem(id) {
  return document.getElementById(id);
}

// modifier simplement le style d'un id..
function _Style(id) {
  return _Elem(id).style ;
}

function activate() {
	for (var i = 0; i < arguments.length; ++i) {
		_Elem(arguments[i]).disabled = false;
	}
}

function desactivate() {
	for (var i = 0; i < arguments.length; ++i) {
		_Elem(arguments[i]).disabled = true;
	}
}

function Show() {
	for (var i = 0; i < arguments.length; ++i) {
		_Elem(arguments[i]).style.display = '';
		_Elem(arguments[i]).style.visibility = 'visible';
	}
}

function Hide() {
	for (var i = 0; i < arguments.length; ++i) {
		_Elem(arguments[i]).style.display = 'none';
		_Elem(arguments[i]).style.visibility = 'hidden';
	}
}

function showHide(id) {
	if (_Elem(id).style.display != 'none')
		Hide(id);
	else
		Show(id);
		
}

function bindDivs (id, idDst) {

		var sAgent = navigator.userAgent.toLowerCase() ;
       if (sAgent.indexOf("msie") == -1) {
          offsets = 1 ;
       } else {offsets = 0 }

       myTop = _Elem(idDst).offsetTop;
       myLeft = _Elem(idDst).offsetLeft;
       myHeight = Math.round(_Elem(idDst).clientHeight/10)*10;
       myWidth = Math.round(_Elem(idDst).clientWidth/10)*10;
       //showEditor(myTop, myLeft, myWidth, myHeight);
       _Elem(id).style.top = myTop+offsets ;
       _Elem(id).style.left = myLeft+offsets ;
       _Elem(id).style.width = myWidth ;
       _Elem(id).style.height = myHeight ;

       Show(id);
}

function ucFirst(str) {
   return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
}

function swapWidth(dvObj) {
	newWidth = dvObj.style.width;
	if (newWidth == '90%') dvObj.style.width = "10%";
	else dvObj.style.width = "90%";
}

function swapIDContents(id1,id2) {
	tmpid = id2 ;
	tmpidc = _Elem(id2).innerHTML;

	// swap du contenu
	_Elem(id2).innerHTML = _Elem(id1).innerHTML;
	_Elem(id1).innerHTML = tmpidc ;

	// swap des id
	_Elem(id2).id = id1;
	_Elem(id1).id = id2;
}

function selectAddOption(sId, oText, oVal, where) {
	sTmp = _Elem(sId);
	nbOptions = sTmp.options.length;
	
	if (where == 'top') {
		for(i=nbOptions; i >= 1  ; i--) {
			sTmp.options[i] = new Option (sTmp.options[i-1].innerHTML, sTmp.options[i-1].value);
		}
		sTmp.options[0] = new Option(oText, oVal);
	} else {
		sTmp.options[nbOptions] = new Option(oText, oVal);
	}
}

function checkMail(adresse){

var regEx = /([a-z0-9]+([-_]?[a-z0-9]+)*.)*[a-z0-9]+([-_]?[a-z0-9]+)*@([a-z0-9]+([-_]?[a-z0-9]+)*.)+[a-z]{1,4}/gi;  

if (adresse.match(regEx) != adresse ) {

 return false;

} else {

 return true;

}

}
