function getElementsByClass(classe, tag) {   
	var divs = document.getElementsByTagName(tag);   
	var resultats = new Array();   
	for(var i=0; i<divs.length; i++){   
		if(divs[i].className == classe){
			resultats.push(divs[i]);
		}
	}
	return resultats;   
}

function displayWarning(){	

      var elems = getElementsByClass("congest_fond_warning warning", "div");        
      if(elems.length == 0){
	if(document.getElementById('global')){
        	document.getElementById('global').style.display = "none";
        }
        return;
      }
   	
      var content = '';
      for(var i = 0 ; i < elems.length ; i++){
        elems[i].style.display = 'none';
        content += elems[i].innerHTML + '<br/>';			

      }
      document.getElementById('global').style.display = "block";
      document.getElementById('messagePopin').innerHTML = content + document.getElementById('messagePopin').innerHTML;
}

function close(){	  
	document.getElementById('global').style.display = "none";
}

function SetCookie(c_name,value){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+30);
	document.cookie = c_name+ "=" +escape(value)+ ";expires="+exdate.toGMTString()+";path=/";
}

function profileEvents(){
	if (document.profil_login_form && document.profil_login_form.profil_login_profil){
		document.profil_login_form.profil_login_profil.onchange = function(){
			SetCookie('comgest_profil', document.profil_login_form.profil_login_profil.options[document.profil_login_form.profil_login_profil.selectedIndex].value );
			reload('language','profil','profil')
		}
	}
	if (document.profil_login_form && document.profil_login_form.profil_login_language){
		document.profil_login_form.profil_login_language.onchange = function(){
			SetCookie('comgest_language', document.profil_login_form.profil_login_language.options[document.profil_login_form.profil_login_language.selectedIndex].value);
			reload('language','profil','language')
		}
	}	
}

function filterProfile(){
	if(!document.profil_login_form) return;
	var profil = document.profil_login_form.profil.options[document.profil_login_form.profil.selectedIndex].value;
	if(profil.indexOf('4hongkong') != -1 ||  profil.indexOf('united_states') != -1 || profil.indexOf('japan') != -1){
		document.profil_login_form.language.length = 0;
		var o = new Option('English', '/sites/en/');
		document.profil_login_form.language.options[0] = o;
	}
}

if (window.addEventListener){ 
	window.addEventListener("load", displayWarning, false); 
	window.addEventListener("load", profileEvents, false);    
	window.addEventListener("load", filterProfile, false);       
 } else if (window.attachEvent){ 
	window.attachEvent("onload", displayWarning); 
	window.attachEvent("onload", profileEvents); 	
	window.attachEvent("onload", filterProfile); 		
}

