//<script language=javascript>

function InitPage() {
	
	var blnFocus = false;
	var arrURL;
			
	GererRegionListeSectActv();
		
		//window.top.location.href.split("#");
		//§ML-0803a - Option 4 a été enlevée...
		//if (document.MAIN_FORM.radopt[3].checked == true) {
		//	//pour l'ancre, on vérifie s'il est déja la car avec MAC et IE
		//	//dans javascript cela cause la page de toujours se recharger
		//	if (window.top.location.hash != "#ancre1") {
		//		document.MAIN_FORM.FICHE_INTERNET.value = "ancre1";
		//		arrURL = window.top.location.href = "#" + document.MAIN_FORM.FICHE_INTERNET.value;
		//		document.MAIN_FORM.FICHE_INTERNET.action = arrURL[0];
		//	}
		//	blnFocus = true;
		//}
		if (!(blnFocus) &&
			(document.MAIN_FORM.txtmotclesect.value != "")) {
			document.MAIN_FORM.txtmotclesect.focus();
			document.MAIN_FORM.btnrechrmotcle.disabled = false;
			blnFocus = true;
		}
		if (!(blnFocus) &&
			(document.MAIN_FORM.txtmotclesect.value == "") &&
			(document.MAIN_FORM.cbolistesect.selectedIndex > 0)) {
			document.MAIN_FORM.cboregionsectactv.focus();
			document.MAIN_FORM.btnrechrlistesect.disabled = false;
			blnFocus = true;
		}
		if (!(blnFocus) &&
			(document.MAIN_FORM.txtmotclesect.value == "") &&
			(document.MAIN_FORM.cbolistesect.selectedIndex == 0) &&
			(document.MAIN_FORM.cbosectprofdemnd.selectedIndex > 0)) {
			document.MAIN_FORM.cbosectprofdemnd.focus();
			document.MAIN_FORM.btnrechrsectprof.disabled = false;
			blnFocus = true;
		}
		if (blnFocus == false) {	
			document.MAIN_FORM.txtmotclesect.focus();
			document.MAIN_FORM.radopt[0].checked = true;
			document.MAIN_FORM.btnrechrmotcle.disabled = false;
		}
}

function ValiderPage(pstrIdCtrl) {
	
	var blnValid = true;

		switch(pstrIdCtrl) {
			case 'all':
				//RC-1124
				//Un des boutons de recherche a été cliqué (boutons submit).
				//Maintenant on se fie au bouton radio plutôt que la propriété "posted". Cette 
				//dernière contient toujours la valeur "submit" peu importe le bouton utilisé.
				if (document.MAIN_FORM.radopt[0].checked == true)
				{
					blnValid = ValiderRechMotCle();
				}
				else if (document.MAIN_FORM.radopt[1].checked == true)
					 {
						blnValid = ValiderRechV2();
					 }
					 else if (document.MAIN_FORM.radopt[2].checked == true)
							{
								blnValid = ValiderRechV3();
							}
/*
				switch(document.MAIN_FORM.posted.value) {
					case 'btnrechrmotcle':
						blnValid = ValiderRechMotCle();
						break;
						
					case 'btnrechrlistesect':
						blnValid = ValiderRechV2();
						break;
					
					case 'btnrechrsectprof':
						blnValid = ValiderRechV3();
						break;
				}
*/				
				//on ne fait rien ici
				break;
							
			case "btnnouvrechr":
				go(URLNOUVRECH);
				//EffacerChamps('all');
				//document.MAIN_FORM.txtmotclesect.focus();
				//document.MAIN_FORM.radopt[0].checked = true;
				//Annule l'hyperlien
				blnValid = false;
				break;
				
			case "V1":
			case "txtmotclesect":
				GererSectionActive('V1');
				break;
			
			case "V2":
			case "cbolistesect":
			case "cboregionsectactv":
				GererSectionActive('V2');
				break;
			
			case "V3":
			case "cbosectprofdemnd":
				GererSectionActive('V3');
				break;

			//§ML-0803a - Option 4 a été enlevée case "V4":
			//	GererSectionActive('V4');
			//	break;

			//case "URLCOMSECT":
			//	GererSectionActive('V4');
			//	InitPage();
			//	//ouvFen(URLCOMSECT, 'Sectoriel', strSettings);
			//	break;
				
			//case "URLSITEINT":
			//	GererSectionActive('V4');
			//	InitPage();
			//	//ouvFen(URLSITEINT, 'Programme', strSettings);
			//	break;
		}
	return blnValid;
}

//RC-1124 Changer le nom de la fonction et le nom du paramètre.
//		  Ajouter le traitement pour désactiver les boutons Submit. 
//		  Seul le bouton de la section active demeure actif
//function EffacerChampsOPT(strBouton)
function GererSectionActive(pstrOptSection) {

	EffacerChamps(pstrOptSection);

	document.MAIN_FORM.radopt[0].checked = false;
	document.MAIN_FORM.radopt[1].checked = false;
	document.MAIN_FORM.radopt[2].checked = false;
	//§ML-0803a document.MAIN_FORM.radopt[3].checked = false;
	document.MAIN_FORM.btnrechrmotcle.disabled = true;
	document.MAIN_FORM.btnrechrlistesect.disabled = true;
	document.MAIN_FORM.btnrechrsectprof.disabled = true;

	if (pstrOptSection == "V1") {
		document.MAIN_FORM.radopt[0].checked = true;
		document.MAIN_FORM.txtmotclesect.focus();
		document.MAIN_FORM.btnrechrmotcle.disabled = false;
	}
	if (pstrOptSection == "V2") {
		document.MAIN_FORM.radopt[1].checked = true;
		document.MAIN_FORM.btnrechrlistesect.disabled = false;
	}
	if (pstrOptSection == "V3") {
		document.MAIN_FORM.radopt[2].checked = true;
		document.MAIN_FORM.btnrechrsectprof.disabled = false;
	}
	//§ML-0803a - Enlever Option 4
	//if (pstrOptSection == "V4") {
	//	document.MAIN_FORM.radopt[3].checked = true;
	//}
}

function EffacerChamps(strVal) {
	if (strVal != "V1") {
		document.MAIN_FORM.txtmotclesect.value = "";
	}
	if (strVal != "V2") {
		document.MAIN_FORM.cbolistesect.selectedIndex = 0;
		document.MAIN_FORM.cboregionsectactv.selectedIndex = 0;
		
	}
	if (strVal != "V3") {
		document.MAIN_FORM.cbosectprofdemnd.selectedIndex = 0;
	}
	if (strVal != "V4") {
		//rien à faire
	}
}

function ValiderRechMotCle() {
	
	var i;
	var c;
	var strInfo;
	var blnRetour = true;
	var intCmptSpace = 0;
	var intCmptChar = 0;
	var intCmptNbr = 0;
	var strACorr;
	var intLongChamp;
	var blnchar = false;
	var intPos = 0;
	
	strACorr = document.MAIN_FORM.txtmotclesect.value;
	strInfo = Trim(strACorr);
	strInfo = fgCorrText(strInfo);
	intLongChamp = strInfo.length;
	
	//Vérifie que le champs n'est pas vide
	if (strInfo == "") {
		ShowAlert(DC956301, '', "txtmotclesect");
		blnRetour = false;
	}
	//Vérifie que les mots contiennent tous 4 lettres min.
	else
	{
		for (i = 0; i < intLongChamp; i++) {
			c = strInfo.charAt(i);
			if ((c >= 'A' && c <= 'Z') ||
			   (c >= 'a' && c <= 'z')	||
			   (c >= '0' && c <= '9') ||
			   (c == " ") ||
			   (c == "")) {
			   // C'est bon
			}	
			else
			{
				ShowAlert(DC956302, '', "txtmotclesect");
				blnRetour = false;
				break;
			}
			if (isNaN(c)) {
				intCmptChar = intCmptChar + 1;
			}
			else if	((c == "") || (c == " ")) {
				intCmptSpace = intCmptSpace + 1;
			}
			else
			{
				intCmptNbr = intCmptNbr + 1;
			}
		}
		//Vérifie si l'info dans le champs contient au moins 4 lettres
		if (blnRetour && (intCmptChar < 4) && (intCmptNbr == 0)) {
			ShowAlert(DC956303, '', "txtmotclesect");
			blnRetour = false;
		}
		if (blnRetour && (intCmptChar > 0) && (intCmptNbr > 0)) {
			ShowAlert(DC956302, '', "txtmotclesect");
			blnRetour = false;	
		}
		if ((blnRetour && (intCmptChar == 0)) && ((intCmptNbr < 2) || (intCmptNbr > 4))) {
			ShowAlert(DC956325, '', "txtmotclesect");
			blnRetour = false;
		}
		if (blnRetour && (intCmptSpace > 0) && (intCmptNbr > 0)) {
			ShowAlert(DC956325, '', "txtmotclesect");
			blnRetour = false;
		}
		if (blnRetour && isNaN(strInfo)) {
			blnRetour = ValdNbCarcMinmParMot(strInfo,4);
			if (blnRetour == false) {
				ShowAlert(DC956303, '', "txtmotclesect");
			}
		}
	}
	return blnRetour;
}

function ValiderRechV2() {
	
	var blnRetour = true;
	
	if ((document.MAIN_FORM.cbolistesect.selectedIndex <= 0) &&
		(document.MAIN_FORM.cboregionsectactv.selectedIndex <= 0)) {
		ShowAlert(DC956305, '', "cbolistesect");
		blnRetour = false;
	}
	if ((document.MAIN_FORM.cbolistesect.selectedIndex > 0) &&
		(document.MAIN_FORM.cboregionsectactv.selectedIndex <= 0)) {
		ShowAlert(DC956306, '', "cboregionsectactv");
		blnRetour = false;
	}
	if ((document.MAIN_FORM.cbolistesect.selectedIndex <= 0) &&
		(document.MAIN_FORM.cboregionsectactv.selectedIndex > 0)) {
		ShowAlert(DC956307, '', "cbolistesect");
		blnRetour = false;
	}
	return blnRetour;
}

function ValiderRechV3() {
	
	var blnRetour = true;
	
	if (document.MAIN_FORM.cbosectprofdemnd.selectedIndex <= 0) {
		ShowAlert(DC956304, '', "cbosectprofdemnd");
		blnRetour = false;
	}
	return blnRetour;
}

function ValdNbCarcMinmParMot(pstrText,plngNbCarcMinm)
{
	var blnVald = true;

	var arrMots = pstrText.split(" ");
	var i = 0;
	while (i < arrMots.length && blnVald)
	{
		if (arrMots[i].length < plngNbCarcMinm)
		{
			blnVald = false;
		}
		else
		{
			i++;
		}
	}
	return blnVald;
}

function GererRegionListeSectActv() {
	
    var element;
	var blnAdd;
	var i;
	var strKey;
	var strOldValue;
	
		strKey = document.MAIN_FORM.cbolistesect.options[document.MAIN_FORM.cbolistesect.selectedIndex].value;	
		
		//Conserver l'ancienne valeur
		if (document.MAIN_FORM.cboregionsectactv.selectedIndex >= 0) {
			strOldValue = document.MAIN_FORM.cboregionsectactv.options[document.MAIN_FORM.cboregionsectactv.selectedIndex].value;
		}
		else {
			strOldValue = "";
		}
	
		//Vider Combo région liste sect actv
		//On vide le combo mais on garde la ligne blanche au début
		for (i=document.MAIN_FORM.cboregionsectactv.options.length-1; i>0; i--) {
			document.MAIN_FORM.cboregionsectactv.options[i] = null;
		}

		for (i=0; i<=arrKeysRegSect.length - 1; i++) {

			if (((strKey != 3) && (strKey != 4)) || (arrKeysRegSect[i] == "QC")) {
				element = new Option(arrLiblRegSect[i], arrKeysRegSect[i]);
				//Patch Netscape
				if (arrKeysRegSect[i]==strOldValue) {
					if(!(navigator.userAgent.indexOf("Gecko") > 0)) {
						element.defaultSelected = true;
					}
				}
				document.MAIN_FORM.cboregionsectactv.options[document.MAIN_FORM.cboregionsectactv.options.length] = element;
			 }
		}
				
		//Si l'ancienne valeur existe toujours on la sélectionne
		if ((strKey != "3") && (strKey != "4")) {
			SelOldValue(document.MAIN_FORM.cboregionsectactv, strOldValue);
		}

		if ((strKey == "3") || (strKey == "4")) {
			document.MAIN_FORM.cboregionsectactv.selectedIndex = 1;
		}
}

function SelOldValue(objCbo, strOldValue) {
		//Si l'ancienne valeur existe toujours on la sélectionne
		var intLength = objCbo.options.length;
		var i;
		for (i=0; i<intLength; i++) {
			if (strOldValue == objCbo.options[i].value) {
				objCbo.selectedIndex = i;
				break;
			}
		}
}

//</script>