//Author : JAMKA Wojciech
var global;
specialKeys=Array();
specialKeys["enter"]=13;
specialKeys["tab"]=9;
specialKeys["shift"]=16;
specialKeys["alt"]=18;
specialKeys["downarrow"]=40;
specialKeys["space"]=32;
function getE(id){
	return new Obj(id);
}
function getKeyPressed(e){
	var code;
	if (!e){ 
		var e = window.event;
	}
	if (e.keyCode){
		code = e.keyCode;
	}else if(e.which) {
		 code = e.which;
	}
	return code;
}
function getXhr(){
	if (window.XMLHttpRequest)
        return new XMLHttpRequest();
 
    if (window.ActiveXObject)
    {
        var names = [
            "Msxml2.XMLHTTP.6.0",
            "Msxml2.XMLHTTP.3.0",
            "Msxml2.XMLHTTP",
            "Microsoft.XMLHTTP"
        ];
        for(var i in names)
        {
            try{ return new ActiveXObject(names[i]); }
            catch(e){}
        }
    }
    window.alert("Votre navigateur ne prend pas en charge l'objet XMLHTTPRequest.");
    return null; // non supporté
}
function searchE(text){
	var all = document.getElementsByTagName('*');
	for(var i=0; i<all.length; i++){
		if(all[i].firstChild){
			if(all[i].firstChild.nodeValue == text){
				return new Obj(all[i]);
	        }
		}
    }
	alert(text+' not found');
}
function getEs(className,idWhere,tag){
	var resultats = new Array();
	if(!idWhere || idWhere==''){
		var all = document.getElementsByTagName('*');
	}else{
		var all = document.getElementById(idWhere).elements;
	}
	if(!className || className==''){// pas de class demandée
		if(!tag || tag==''){//pas tag demandée pas de class
			for(var i=0; i<all.length; i++){
				  resultats.push(getE(all[i].id));
			}
		}else{ // tag demandée pas de class
			var reg=new RegExp("[,]+", "g");
        	var tags=tag.split(reg);
        	for(var i=0; i<all.length; i++){
	        	for(var j=0; j<tags.length; j++){
		        	 if(all[i].tagName==tags[j]){
		        		 resultats.push(getE(all[i].id));
		        	 }
		        }
        	}
		}
	}else{ //class demandée
		if(!tag || tag==''){//pas tag demandée et class demandée
			for(var i=0; i<all.length; i++){
				if(all[i].className == className){
		              resultats.push(getE(all[i].id));
		         }
			}
		}else{ //tag demandée et class demandée
			var reg=new RegExp("[,]+", "g");
        	var tags=tag.split(reg);
        	for(var i=0; i<all.length; i++){
	        	for(var j=0; j<tags.length; j++){
		        	 if(all[i].tagName==tags[j] && all[i].className == className){
		        		 resultats.push(getE(all[i].id));
		        	 }
		         }
        	}
		}
	}
    return resultats;
}
function loadWithAjax(fichier, donnees, loading, asynchrone,func){
	global="";
	var xhr_object=getXhr();
	if(asynchrone && asynchrone==true){
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4 && xhr_object.status == 200){
				//alert(func);
				eval(func);
				getE("result").inject(xhr_object.responseText);
			}
		}
		xhr_object.open("POST", fichier, true);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.setRequestHeader("Cache-Control", "no-cache; must-revalidate");
		xhr_object.send(donnees); 
	}else{
		xhr_object.open("POST", fichier, false);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.setRequestHeader("Cache-Control", "no-cache; must-revalidate");
		xhr_object.send(donnees); 
		if(xhr_object.readyState == 4){
			global=xhr_object.responseText;
		}
	}
	//xhr_object.setRequestHeader("Cache-Control", "no-cache; must-revalidate");
	//xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}

//////////////////////////////////////////////////////////////////////////
////////////////////////Classe OBJET//////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
function Obj(id) {
	/*if (!id)
	{
		alert("Erreur d'appel getE");
		return;
	}*/
	
	if(document.getElementById(id)!=null){
		this._el=document.getElementById(id);
	}else if(id && id.tagName!=""){
		this._el=id;
	}
	if(!this._el)
	{
		//alert(id+ "non construit avec getE");
	}
	else if(!this._el.id){
		//alert(id+ "non construit avec getE");
	}
}

Obj.prototype._el;

Obj.prototype.get = function(valeur) {
	switch(valeur){
		case 'id':return this._el.id;
		case 'name':return this._el.name;
		case 'type':return this._el.type;
		case 'tagName':return this._el.tagName;
		case 'class':return this._el.className;
		case 'value':return this._el.value;
		case 'checked':return this._el.checked;
		case 'title':return this._el.title;
		case 'text':return this._el.nodeValue;
		case 'src':return this._el.src;
		case 'height':return this._el.height;
		default : return this._el.getAttribute(valeur);
	}
	
}
Obj.prototype.remplir = function(valeur) {
	if(this.get('tagName')=="INPUT" || this.get('tagName')=="TEXTAREA"){
		 if(this.get('type')=="radio" || this.get('type')=="checkbox"){
			 this.set('checked',valeur);
		 }else{
			 this.set('value',valeur);
		 }
	 }else if(this.get('tagName')=="SELECT"){
		 for(i=0;i<this._el.options.length;i++){
			 if(this._el.options[i].value==valeur || this._el.options[i].text==valeur){
				 this._el.selectedIndex=i;
				 break;
			 }
		 }
	 }
}
Obj.prototype.focus = function() {
	try
	{
		this._el.focus();
	}
	catch (err)
	{
	}
}
Obj.prototype.set = function(valeur,value) {
	switch(valeur){
		case 'id':this._el.id=value;break;
		case 'name':this._el.name=value;break;
		case 'type':this._el.type=value;break;
		case 'tagName':this._el.tagName=value;break;
		case 'class':this._el.className=value;break;
		case 'value':this._el.value=value;break;
		case 'checked':
			if(value=="true"){
				this._el.checked=true;break;
			}else{
				this._el.checked=false;break;
			}
			break;
		case 'title':this._el.title=value;break;
		case 'text':this._el.firstChild.nodeValue=value;break;
		case 'src':this._el.src=value;break;
		case 'disabled':this._el.disabled=value;break;
		default : this._el.setAttribute(valeur,value);
	}
	
}
Obj.prototype.remove = function(valeur) {
	switch(valeur){
		case 'id':this._el.id='';break;
		case 'name':this._el.name='';break;
		case 'type':this._el.type='';break;
		case 'tagName':this._el.tagName='';break;
		case 'value':this._el.value='';break;
		case 'checked':this._el.checked='';break;
		case 'title':this._el.title='';break;
		case 'text':this._el.nodeValue='';break;
		default : this._el.removeAttribute(valeur);
	}
	
}
Obj.prototype.show = function(eff){
	if(this.getStyle('display')!=''){
		if(eff==true){
			var id= '#'+this.get('id');
			jQuery(id).stop(true, true).animate({opacity: "show"}, "slow");
		}else{
			this.setStyle('display', '');
		}
		
		if(window.location.pathname.indexOf('Accueil')==-1 && window.location.pathname!='/'){
			ResizeSiteHeight();
		}
	}
}
Obj.prototype.hide = function(eff){
	if(this.getStyle('display')!='none'){
		if(eff==true){
			var id= '#'+this.get('id');
			jQuery(id).stop(true, true).animate({opacity: "hide"}, "slow");
			this.setStyle('display', 'none');
		}else{
			this.setStyle('display', 'none');
		}
		if(window.location.pathname.indexOf('Accueil')==-1 && window.location.pathname!='/'){
			window.setTimeout('ResizeSiteHeight();', 100);
		}
		
	}
	
}
Obj.prototype.showHide = function(eff){
	if(this.getStyle('display')=='none'){
		this.show(eff);
	}else{
		this.hide(eff);
	}
}
Obj.prototype.setStyle = function(style,value){
	switch(style){
		case 'backgroundColor':this._el.style.backgroundColor=value;break;
		case 'color':this._el.style.color=value;break;
		case 'display':this._el.style.display=value;break;
		case 'selected':this._el.style.selected=value;break;
		case 'visibility':this._el.style.visibility=value;break;
		case 'top':return this._el.style.top=value;break;
		case 'left':return this._el.style.left=value;break;
		case 'border':return this._el.style.border=value;break;
		default : alert(style+" non connu dans setStyle");
	}

}
Obj.prototype.getStyle = function(style){
	switch(style){
		case 'backgroundColor':return this._el.style.backgroundColor;
		case 'color':return this._el.style.color;
		case 'display':return this._el.style.display;
		case 'top':return this._el.style.top;
		case 'left':return this._el.style.left;
		case 'height':return this._el.height;
		default : alert(style+" non connu dans setStyle");
	}

}

Obj.prototype.hasClass=function(cls) {
	return this._el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
Obj.prototype.addClass=function(cls) {
	this._el.className=cls;
}
Obj.prototype.removeClass=function(cls) {
	if (this.hasClass(cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		this._el.className=this._el.className.replace(reg,'');
	}
}
Obj.prototype.inject = function(donnee){
	this._el.innerHTML=donnee;
}
Obj.prototype.append = function(donnee){
	this._el.innerHTML+=donnee;
}
Obj.prototype.addEvent= function(event,func){
	switch(event){
		case 'onclick':this._el.onclick=func;break;
		case 'onkeyup':this._el.onkeyup=func;break;
		case 'onkeydown':this._el.onkeydown=func;break;
		case 'onchange':this._el.onchange=func;break;
		case 'onfocus':this._el.onfocus=func;break;
		case 'onblur':this._el.onblur=func;break;
		case 'ondblclick':this._el.ondblclick=func;break;
		default :alert(event+" non connu dans addEvent");
	}
}
Obj.prototype.loadPageFromAjax=function(fichier, donnees, asynchrone, loading, func){
	var xhr_object=getXhr(); 
	var elElement=this;
	imgLoading="<center><img src='/sites/module/img/ajax-loader.gif' /></center>";	
	
	if(asynchrone && asynchrone==true){
		xhr_object.onreadystatechange = function() {
			if((!loading && !loading==false) || loading==true){
				elElement.inject(imgLoading);
			}
			if(xhr_object.readyState == 4 && xhr_object.status == 200){
				elElement.inject(xhr_object.responseText);
				global=xhr_object.responseText;
				eval(func);
				ResizeSiteHeight();
			}else{
				global="error";
			}
		}
		xhr_object.open("POST", fichier, true);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.setRequestHeader("Cache-Control", "no-cache; must-revalidate");
		xhr_object.send(donnees); 
	}else{
		if((!loading && !loading==false) || loading==true){
			elElement.inject(imgLoading);
		}
		xhr_object.open("POST", fichier, false);
		xhr_object.setRequestHeader("Cache-Control", "no-cache; must-revalidate");
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send(donnees); 
		if(xhr_object.readyState == 4){
			elElement.inject(xhr_object.responseText);
			global=xhr_object.responseText;
			ResizeSiteHeight();
		}else{
			global="error";
		} 
		return(xhr_object.responseText);
	}
	
	
	// modif RS >> recalculer le bottom
	
	
	//xhr_object.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
	
	
}
Obj.prototype.addNewOption=function(text,value,selected,id,disabled){
	if(value){
		var txt = document.createTextNode(text);
		var opt = document.createElement('option');
		opt.setAttribute('value',value);
		opt.setAttribute('id',id);
		if(disabled==true){
			opt.setAttribute('disabled','disabled');
		}
		if(selected){
			opt.setStyle('selected','selected');
		}
		opt.appendChild(txt);
	}else{
		opt=text;
	}
	this._el.appendChild(opt);
}
Obj.prototype.loadOptionsFromAjax=function(fichier,donnees,valueToSelect,createOptionAll){
	var xhr_object=getXhr();
	var toSelect=0;
	var elSelect=this;
	elSelect.empty();
	
	
	elSelect.disabled=true;
	elSelect.addNewOption('chargement','chargement');
	
	xhr_object.onreadystatechange = function() {
		//alert(xhr_object.readyState);
		if(xhr_object.readyState == 4 && xhr_object.status == 200){
			elSelect.empty();
			if(createOptionAll){
				elSelect.addNewOption('Tous','all');
			}
			//elSelect.append(xhr_object.responseText);
			
			var test=xhr_object.responseText.split('value=');
			for (i=1;i<test.length;i++){
				var val=test[i].substring(1,test[i].length);
				to=val.indexOf("'>");
				if(to==-1){
					to=val.indexOf('">');
				}
				val=val.substring(0,to);
				
				var text=test[i].substring(test[i].indexOf('>')+1,test[i].length);
				text=text.substring(0,text.indexOf('<'));
				elSelect.addNewOption(text,val,false,elSelect.get('id')+val);
			}
			
			elSelect.setStyle('backgroundColor', 'white');
		}
	}
	xhr_object.open("POST", fichier, true);
	
	xhr_object.setRequestHeader("Cache-Control", "no-cache; must-revalidate");
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	xhr_object.send(donnees);
	
}

Obj.prototype.empty=function(tagName){
	if(tagName!=null && tagName=='text'){
		for (i=0;i<this._el.childNodes.length;i++){
			if(getE(this._el.childNodes[i]).get('tagName')=="span"){
				this._el.removeChild(this._el.childNodes[i]);
			 } 
		 }
	}else if(tagName!=null && tagName!=''){
		for (i=0;i<this._el.childNodes.length;i++){
			if(getE(this._el.childNodes[i]).get('tagName')==tagName){
				this._el.removeChild(this._el.childNodes[i]);
			 } 
		 }
	}else{
		while(this._el.hasChildNodes()){
			this._el.removeChild(this._el.firstChild);
		}
	}
}
Obj.prototype.getSelectedValue=function(){
	if(this._el.selectedIndex>-1){
		return this._el.options[this._el.selectedIndex].value;
	}else{
		return null;
	}
}
Obj.prototype.getSelectedIndex=function(){
	return this._el.selectedIndex;
}
Obj.prototype.getSelectedOption=function(){
	if(this._el.selectedIndex>-1){
		return this._el.options[this._el.selectedIndex];
	}else{
		return null;
	}
}





//fonction pour initialiser un formualire ou ds champs d'un formualire en leur ajoutant les evenement onclick, onchange et on keyup
Obj.prototype.initialize=function(){
	
	if(this.get('tagName')=="FORM"){
		var tab=getEs('',this.get('id'),'INPUT,TEXTAREA');
		for(var i=0; i<tab.length; i++){
			tab[i].initialize();
		}
	}else if(this.get('tagName')=="INPUT" || this.get('tagName')=="TEXTAREA"){
		thisEl=this;
		var id=thisEl.get('id');
		/*if(thisEl.get("validator")!="validatorLoginBd()" && thisEl.get("validator")!="validatorEmailBd()"){
			thisEl.addEvent('onkeyup', function(e) {
				//if(specialKeys.indexOf(getKeyPressed(e))==-1){
					getE(id).validate();
				//}
			});
		}
		thisEl.addEvent('onblur', function(e) {
			getE(id).validate();
		});*/
		if(thisEl.get('type')!='button' && thisEl.get('type')!='submit'){
			thisEl.addEvent('onclick', function(e) {
				getE(id).setValidStyle();
			});
		}
	}else{
		//alert(this._el+this.get('id')+'||'+this.get('name')+'||'+this.get('tagName')+' is not an element which can be initialized, initialize cannot be done');
	}
}
Obj.prototype.getToSubmit= function(event,func){
	var donnees="";
	if(this.get('tagName')=="FORM"){
		var tab=getEs('',this.get('id'),'INPUT,TEXTAREA,SELECT');
		for(var i=0; i<tab.length; i++){
			donnees+=tab[i].getToSubmit();
		}
	}else if(this.get('tagName')=="INPUT" || this.get('tagName')=="TEXTAREA" ){
		if(this.get('type')=='checkbox'){
			donnees+=this.get('name')+'='+this.get('checked')+"&";
		}else if(this.get('type')=='radio'){
			if(this.get('checked')){
				donnees+=this.get('name')+'='+this.get('value')+"&";
			}
		}else{
			donnees+=this.get('name')+'='+encodeURIComponent(this.get('value'))+"&";
		}
	}else if(this.get('tagName')=="SELECT"){
		//gerer le multi select
		if(this.get('name').indexOf("[]")!=-1){//c'est un multiselect
			var tab=this._el.options;
			if(this.get('submit')=='selected'){
				for(i=0;i<tab.length;i++){
					if(tab[i].selected){
						donnees+=this.get('name')+'='+tab[i].value+"&";
					}
				}
			}else{
				for(i=0;i<tab.length;i++){
					donnees+=this.get('name')+'='+tab[i].value+"&";
				}
			}
		}else{
			donnees+=this.get('name')+'='+this.getSelectedValue()+"&";
		}
	}else{
		//alert(this._el+' is not an form element');
		return false;
	}
	return donnees;
}

Obj.prototype.setValidStyle=function(){
	if(this.get('bulle2')){
		getE(this.get('bulle2')).hide(true);
	}
	/*getE(this._el.parentNode).empty('IMG');
	if(this.get('value').length>0 && this.get('validator')!='validatorCodeSecurite()'){
		var img = document.createElement("img");
		img.setAttribute("src","/sites/module/img/field_valid.gif");
		img.setAttribute("height","16");
		img.setAttribute("style", "padding-left: 3px");
		this._el.parentNode.appendChild(img);
		this.addClass('valid_form_element');
	}*/
}
Obj.prototype.setNotValidStyle=function(){
	if(this.get('bulle2')){
		getE(this.get('bulle2')).show(true);
	}
	/*var img = document.createElement("img");
	img.setAttribute("src","/sites/module/img/field_invalid.gif");
	img.setAttribute("title",this.get('title'));
	img.setAttribute("height","16");
	img.setAttribute("style", "padding-left: 3px");
	getE(this._el.parentNode).empty('IMG');
	this._el.parentNode.appendChild(img);
	this.addClass('not_valid_form_element');*/
}
Obj.prototype.setNotValidStylePresent=function(){
	if(this.get('bulle')){
		getE(this.get('bulle')).show(true);
	}
}
Obj.prototype.setValidStylePresent=function(){
	if(this.get('bulle')){
		getE(this.get('bulle')).hide(true);
	}
}
//fonction qui permet de valider un formulaire ou un champ du formulaire en changeant sont style en fonction de la validit� des donn�e
Obj.prototype.validate=function(){
	if(this.get('tagName')=="FORM"){
		var tab=getEs('',this.get('id'),'INPUT,TEXTAREA');
		var valid=true;
		for(var i=0; i<tab.length; i++){
			var res=tab[i].validate();
			if(res==false){
				//alert(tab[i].get('id'));
				valid=false;
			}
		}
		return valid;
	}else if(this.get('tagName')=="INPUT" || this.get('tagName')=="TEXTAREA"){
		
		var txt=this.get('validator');
		
		if(txt!=null && txt!=undefined && txt!="" && txt!=" "){
			if(txt.indexOf('(')==-1){
				txt+="()";
			}
			if(eval("this."+txt)){
				this.setValidStyle();
				return true;
			}else{
				this.setNotValidStyle();
				return false;
			}
		}else{
			return true;
		}
	}else{
		//alert(this._el+'is not an element which can be validated, validation cannot be done');
	}
}
//LES VALIDATOR//
Obj.prototype.validatorRequired = function() {
	if(this.get('type')=='checkbox'){
		return (this.get('checked'));
	}else{
		return ((this.get('value') != null) && (this.get('value').length != 0));
	}
}
Obj.prototype.validatorNumeric = function(){
	return this.validatorRequired() && (/^-?(?:0$0(?=\d*\.)|[1-9]|0)\d*(\.\d+)?$/).test(this.get('value'));
}
Obj.prototype.validatorLength = function(longeur,comparateur,type){
	if(!type || type==""){
		type="validatorRequired()";
	}
	switch(comparateur){
		case '>' : return eval("this."+type) && this.get('value').length > longeur;
		case '<' : return eval("this."+type) && this.get('value').length < longeur;
		case '=' : return eval("this."+type) && this.get('value').length == longeur;
		default : alert('"'+type+'" non connu dans les comparateur du validatorLength');
	}
}
Obj.prototype.validatorLengthNr = function(longeur,comparateur,type){
	switch(comparateur){
		case '>' : return (eval("this."+type) && this.get('value').length > longeur) || !this.validatorRequired();
		case '<' : return (eval("this."+type) && this.get('value').length < longeur) || !this.validatorRequired();
		case '=' : return (eval("this."+type) && this.get('value').length == longeur) || !this.validatorRequired();
		default : alert('"'+type+'" non connu dans les comparateur du validatorLengthNr');
	}
}
Obj.prototype.validatorAlpha = function(){
	return this.validatorRequired() &&  (/^[a-zA-Z-ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ ]+$/).test(this.get('value'));
}
Obj.prototype.validatorTel = function(){
	return this.validatorRequired() &&  (/^[0-9+ ]+$/).test(this.get('value'));
}
Obj.prototype.validatorDate = function(){
	return this.validatorRequired();
}
Obj.prototype.validatorDateNR=function(){
	return !this.validatorRequired() || this.validatorDate;
}
Obj.prototype.validatorEmail = function(){
	return this.validatorRequired() && (/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).test(this.get('value'));
}
Obj.prototype.validatorPassword = function(){
	return this.validatorRequired() &&  (/^[0-9a-zA-Z-ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ!?.:;,_*()]+$/).test(this.get('value'));
}
Obj.prototype.validatorSiret = function(){
	return EstSiretValide(this.get('value'));
}
Obj.prototype.validatorCodeSecurite = function(){
	return this.validatorLength(0,'>');
}
Obj.prototype.validatorEmailBd = function(table){
	if(this.validatorEmail()){
		loadWithAjax(urlGlobals,"table="+table+"&type=mail&mail="+this.get('value'),false);
		if(global!="1"){
			this.setValidStylePresent();
			return true;
		}else{
			this.setNotValidStylePresent();
			return false;
		}
	}else{
		this.setValidStylePresent();
		return false;
	}
}
Obj.prototype.validatorLoginBd = function(){
	if(this.validatorLength(2,'>')){
		id=this.get('id');
		loadWithAjax(urlGlobals,"type=login&login="+this.get('value'));
		if(global!="1"){
			getE(id).setValidStylePresent();
			return true;
		}else{
			getE(id).setNotValidStylePresent();
			return false;
		}
		
	}else{
		this.setValidStylePresent();
		return false;
	}
}
Obj.prototype.validatorConfirmPass = function(){
	//alert(this.get('value')+"=="+getE('pwd').get('value')+"=="+document.getElementById('pwd').id);
	if(this.get('value').indexOf('●')!=-1){
		this.set('value','');
	}
	return this.get('value')==getE('pwd').get('value');
}


//FIN DES VALIDATORS//


//////////////////////////////////////////////////////////////////////////
////////////////////////FIN Classe OBJET//////////////////////////////////
//////////////////////////////////////////////////////////////////////////


Array.prototype.indexOf = function(elt /*, from*/)
{
  var len = this.length;

  var from = Number(arguments[1]) || 0;
  from = (from < 0)
       ? Math.ceil(from)
       : Math.floor(from);
  if (from < 0)
    from += len;

  for (; from < len; from++)
  {
    if (from in this &&
        this[from] === elt)
      return from;
  }
  return -1;
};
//////////////////////////////////////////////////////////////////////////
////////////////////////Classe SPECIAL FOR SITE//////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
function ResizeSiteHeight()
{
    // handle bottom div
    var hauteur_max = Math.max(jQuery("#leftColumn").outerHeight(), jQuery("#content").outerHeight());            
    hauteur_max += 190;            
    jQuery("#footer").css("top", hauteur_max);        
    jQuery("#page").css("visibility", "visible");    
}
function EstSiretValide(siret) {
    var estValide;
    if ( (siret.length != 14) || (isNaN(siret)) )
      estValide = false;
    else {
       // Donc le SIRET est un numérique à 14 chiffres
       // Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants
       // correspondent au numéro d'établissement
       // et enfin le dernier chiffre est une clef de LUHN. 
      var somme = 0;
      var tmp;
      for (var cpt = 0; cpt<siret.length; cpt++) {
        if ((cpt % 2) == 0) { // Les positions impaires : 1er, 3è, 5è, etc... 
          tmp = siret.charAt(cpt) * 2; // On le multiplie par 2
          if (tmp > 9) 
            tmp -= 9;	// Si le résultat est supérieur à 9, on lui soustrait 9
        }
       else
         tmp = siret.charAt(cpt);
         somme += parseInt(tmp);
      }
      if ((somme % 10) == 0)
        estValide = true; // Si la somme est un multiple de 10 alors le SIRET est valide 
      else
        estValide = false;
    }
    return estValide;
  }
