// JavaScript Document
//Fait par Teofanovic Stefan

function FocusFirstChamp(){
	
	//Le scrpt parcour tout les éléments du formulaire a la recherche d'un champ text. 
	//Sur ce site il trouve toujours le champ "q" en premier il va stocker sa position et il continu de chercher. Si il trouve un deuxieme champ text il focus dessus si non il focus sur la position du champ q.
	
	var iElementNumber = 0;
	var iFormNumber = document.forms.length;
	var sElementType = "";
	var sElementName = "";
	var iSearchBarFormID;
	var iSearchBarChampID;
	var bFound = false;
	var sSearchBarName = "q";
	var sFormToIgnoreName = "inscriptionMailPro";
	
	for (i=0;i<=iFormNumber&&!bFound;i=i+1){
		
		if (typeof(document.forms[i]) != "undefined"){
			if (document.forms[i].name != sFormToIgnoreName){
				iElementNumber = document.forms[i].elements.length;
				for (n=0;n<=iElementNumber&&!bFound;n=n+1){
					if (typeof(document.forms[i].elements[n]) != "undefined"){
						sElementType = document.forms[i].elements[n].type;
						sElementName = document.forms[i].elements[n].name;
						if(sElementType=='text'||sElementType=='textarea'){
							if(sElementName==sSearchBarName){
								iSearchBarFormID = i;
								iSearchBarChampID = n;
							}else{
								bFound = true;
								document.forms[i].elements[n].focus();
							}
						}
					}
				}
			}
		}
	}
	if(!bFound && typeof(iSearchBarFormID) != "undefined" && typeof(iSearchBarChampID) != "undefined" ){
		document.forms[iSearchBarFormID].elements[iSearchBarChampID].focus();
	}
}

function addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
	window.onload = func; 
  } else { 
	window.onload = function() { 
	  if (oldonload) { 
		oldonload(); 
	} 
	  func(); 
	} 
  } 
} 
addLoadEvent(FocusFirstChamp); 