//=============================================================================
//				S U I V I  D E S  M O D I F I C A T I O N S 
//============================================================================= 
//Date		: 04/06/04		Auteur(e)	: Josée Gaudreault
//
//Chercher	: §JG-0604a
//
// 	- OuvrirBrowserFPT : Ajuster fonctionnement de l'ouverture du browser FPT.
//=============================================================================
//Date		: 07/07/23		Auteur(e)	: Sébastien Brie
//Liv. ACMT1071.25
//
//DDS 9007031901
//Chercher	§SB-0723a:
//
//  - ValiderPage : Dans la recherche par l'option 1, retirer les espaces en 
//					double dans le mot clé avant de le passer en paramètre à 
//					l'URL du site Inforoute FPT.
//=============================================================================

//<script language=javascript>

var gobjWindow;

function InitPage() {

	//si on revient de la page de recherche avancée on donne le focus au lien 
	//"Domaines et disciplines de niveau universitaire"
	if (strTypeRechrForm == "AVAN")
	{
		document.getElementById("lnkNivUniv").focus();
	}
}

function ValiderPage(pstrIdCtrl) {
	var blnValid = true;
	var strURL;
	var arrLocation;
	var strCorr; //§SB-0723a
	switch(pstrIdCtrl) {
		case 'all':
			//RC-1124 enlevé switch
			//switch(document.MAIN_FORM.posted.value) {
			//	case 'btnrechrmotcle':
					if(document.MAIN_FORM.radsec[0].checked == true)
					{
						blnValid = ValiderRechMotCle();
						if (blnValid)
						{
							//§SB-0723a debut
							strCorr = document.MAIN_FORM.txtmotcle.value
							while (strCorr.indexOf("  ",1) > -1)
							{
								strCorr = strCorr.replace("  "," ");
							}
							strURL = strLienFPTRechr + "?txtmotcle=" + strCorr + "&QPROV=SIMTEQ";
							//§SB-0723a fin
							arrLocation = window.top.location.href.split("#");
							
							blnValid = OuvrirBrowserFPT(strURL, 1);
						}
						//break;
					}
					else
					{
						blnValid = ValiderRechMotCle();
						//break;
					}
			//}
			//on ne fait rien ici
			break;
			
		case "btnnouvrechr":
			go(URLNOUVRECH);
			//EffacerChamps();
			blnValid = false;
			break;
	}
	return blnValid;
}

function EffacerChamps() {
	
	with (document.MAIN_FORM)
	{
		txtmotcle.value = "";
		radsec[0].checked = true;
		txtmotcle.focus();
	}
}

function ValiderRechMotCle() {
	
	var i;
	var c;
	var strInfo;
	var blnRetour = true;
	var intCmptChar = 0;
	var strACorr;
	var intLongChamp;
	var intLongMot = 0;
	
	//Verifie si le champ est vide
	if (document.MAIN_FORM.txtmotcle.value == "")
	{
		ShowAlert(DC956276, '', "txtmotcle")
		blnRetour = false;
	}
	
	//Verifie la presence de caracteres illegaux
	if (blnRetour)
	{
		intLongChamp = document.MAIN_FORM.txtmotcle.value.length;
		strACorr = document.MAIN_FORM.txtmotcle.value;
		strInfo = fgCorrText(strACorr);
		for (i = 0; i < intLongChamp; i++)
		{
            c = strInfo.charAt(i);
			if (!((c >= 'A' && c <= 'Z') ||
			   (c >= 'a' && c <= 'z')	||
			   (c == " ") ||
			   (c == "")))
			{
				ShowAlert(DC956277, '', "txtmotcle")
				blnRetour = false;
				break;
			}	
		}
	}	
	
	//Vérifie que l'info contient des mots d'au moins 4 lettres
	if (blnRetour) {
		var blnMotSaisi;
		strACorr = document.MAIN_FORM.txtmotcle.value;
		strInfo = fgCorrText(strACorr);
		intLongChamp = strInfo.length;
		blnMotSaisi = false;
		for (i = 0; i < intLongChamp; i++)
		{
            c = strInfo.charAt(i);
            if (c == " ")
            {
				if (intLongMot < 4 && intLongMot > 0)
				{
					ShowAlert(DC956278, '', "txtmotcle")
					blnRetour = false;
					break;
				}
				else
				{
					intLongMot = 0;
				}	
            }
            else
            {
				blnMotSaisi = true;
				intLongMot++;
            }
		}
		if (blnRetour && (intLongMot < 4 && intLongMot > 0))
		{
			ShowAlert(DC956278, '', "txtmotcle");
			blnRetour = false;
		}
		else if (!blnMotSaisi)
		{
			ShowAlert(DC956278, '', "txtmotcle");
			blnRetour = false;
		}
	}
    return blnRetour;
}

function OuvrirBrowserFPT(strURL, intSection)
{
	if(intSection == 2)
	{
		EffacerChamps();
	}
	//§JG-0604a: Ouvrir une seule fois un browser pour FTP
	//gobjWindow = window.open(strURL, "BrowserFPT", "height=300,width=790,top=0,left=0,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
	//gobjWindow.close();
	
	gobjWindow = window.open(strURL, "BrowserFPT", "height=300,width=790,top=0,left=0,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
	
	//§JG-0604a: Retourner false pour annuler le "href"
	return false;
	
}


//</script>