// -------------------------------------------------
// Ouvre une fenêtre
// -------------------------------------------------

function gf_PopUpWindow(URL, WindowName, WindowWidth, WindowHeight) {
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open(URL,WindowName,"scrollbars=yes,resizable=yes,directories=no,menubar=no,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth )
    popupwin.focus();
    return(popupwin);
	}

function gf_PopUpModalWindow(URL,WindowWidth, WindowHeight) {	
	sReturnValue = window.showModalDialog(URL,'',"help:no;scroll:no;resizable:yes;center:yes;status:no;dialogHeight:" + WindowHeight + "px;dialogWidth:" + WindowWidth + "px")
    	return(sReturnValue);
}

	
// -------------------------------------------------
// Affichage des boîtes d'édition
// -------------------------------------------------

function gf_UsagerForm(PK){
	gf_PopUpWindow("Usager_e.asp?PK=" + PK,"UsagerForm",500,335)
}
function gf_UsagerIntranetForm(PK){
	gf_PopUpWindow("UsagerIntranet_e.asp?PK=" + PK,"UsagerIntranetForm",500,310)
}
function gf_QuoiDeNeufForm(PK){
	gf_PopUpWindow("QuoiDeNeuf_e.asp?PK=" + PK,"QuoiDeNeufForm",550,425)
}
function gf_NouvelleForm(PK){
	gf_PopUpWindow("Nouvelle_e.asp?PK=" + PK,"NouvelleForm",550,350)
}
function gf_FAQsForm(PK){
	gf_PopUpWindow("Faqs_e.asp?PK=" + PK,"FAQsForm",550,400)
}
function gf_FaqProgrammeForm(PK){
	gf_PopUpWindow("FaqProgramme_e.asp?PK=" + PK,"FAQProgrammeForm",550,400)
}
function gf_FaqRessourceForm(PK){
	gf_PopUpWindow("FaqRessource_e.asp?PK=" + PK,"FAQRessourceForm",550,400)
}
function gf_FAQsResForm(PK,ResId){
	gf_PopUpWindow("FaqRes_e.asp?PK=" + PK+"&ResId="+ResId,"FAQsResForm",550,360)
}
function gf_RepertoireForm(PK){
	gf_PopUpWindow("Repertoire_e.asp?PK=" + PK,"RepertoireForm",550,385)
}
function gf_RessourceForm(PK){
	gf_PopUpWindow("Ressource_e.asp?PK=" + PK,"RessourceForm",550,355)
}
function gf_RessourceArchForm(PK){
	gf_PopUpWindow("RessourceA_e.asp?PK=" + PK,"RessourceArchForm",550,355)
}
function gf_RealisationForm(PK){
	gf_PopUpWindow("Realisation_e.asp?PK=" + PK,"RealisationForm",550,220)
}
function gf_CoursForm(PK){
	gf_PopUpWindow("Cours_e.asp?PK=" + PK,"CoursForm",550,465)
}
function gf_ProgCoursForm(PK){
	gf_PopUpWindow("CoursProg_e.asp?PK=" + PK,"CoursProgForm",550,465)
}
function gf_ProgDescForm(PK, iProg) {
    gf_PopUpWindow("ProgDesc_e.asp?PK=" + PK + "&iProg=" + iProg, "ProgDescForm", 550, 465)
}
function gf_FCDescForm(PK, iProg) {
    gf_PopUpWindow("FCDesc_e.asp?PK=" + PK + "&iFC=" + iProg, "FCDescForm", 550, 465)
}
function gf_ProgrammeForm(PK) {
	gf_PopUpWindow("Programme_e.asp?PK=" + PK,"ProgrammeForm",740,340)
}
function gf_FormationForm(PK){
	gf_PopUpWindow("Formation_e.asp?PK=" + PK,"FormationForm",740,440)
}
function gf_ProfilForm(){
	gf_ShowEditionWindow("profile_e.asp?PK=" + PK,"Édition du profil","win_ProfileFrm",550,330)
}
function gf_RechCoursForm(PK, iSession){
	gf_PopUpWindow("./RechCours.asp?PK=" + PK + "&iSession=" + iSession,"RechCoursFrm",460,330)
}
function gf_CreateurHTMLForm(PK){
	gf_PopUpWindow("./webapp/htmlcreator/default.asp","CreateurHTMLForm",800,560)
}
function gf_CoursFC(PK){
	gf_PopUpWindow("CoursFC.asp?PK=" + PK,"CoursFCForm",550,340)
}
function gf_LienForm(PK){
	gf_PopUpWindow("Liens_e.asp?PK=" + PK,"LiensForm",550,355)
}
function gf_SatelliteForm(PK){
	gf_PopUpWindow("Satellite_e.asp?PK=" + PK,"SatelliteForm",550,220)
}
function gf_FichierForm(PK){
	gf_PopUpWindow("Fichier_e.asp?PK=" + PK,"FichierForm",550,220)
}
function gf_AjoutFichierForm(PK){
	gf_PopUpWindow("Fichier_a.asp?PK=" + PK,"AjoutFichierForm",550,220)
}
function gf_OffreEmploiForm(PK){
	gf_PopUpWindow("OffreEmploi_e.asp?PK=" + PK,"OffreEmploiForm",840,340)
}
function gf_CandidaturesForm(PK) {
    gf_PopUpWindow("Candidatures_e.asp?PK=" + PK, "CandidaturesForm", 740, 440)
}

function gf_SondageForm(iQ, PK){
	gf_PopUpWindow("Sondage_e.asp?iQ=" + iQ +"&PK=" + PK,"SondageForm",740,535)
}

function gf_ProgrammeCrsOrdreForm(PK,iSession){
	gf_PopUpWindow("Programme_CrsOrdre.asp?PK=" + PK + "&iSession=" + iSession,"ProgrammeCrsOrdreForm",740,340)
}


//--------------------------
// BIBLIOTHÈQUE
function gf_BLienForm(PK){
	gf_PopUpWindow("B_Lien_e.asp?PK=" + PK,"BLiensForm",550,355)
}
function gf_BIndexForm(PK){
	gf_PopUpWindow("B_Index_e.asp?PK=" + PK,"BIndexForm",550,355)
}
function gf_BHoraireForm(PK) {
	gf_PopUpWindow("B_Horaires_e.asp?PK=" + PK,"BHoraireForm",550,355)
}
function gf_BPeriodiqueForm(PK){
	gf_PopUpWindow("B_Periodique_e.asp?PK=" + PK,"BPeriodiqueForm",550,355)
}
function gf_BJournauxForm(PK){
	gf_PopUpWindow("B_Journaux_e.asp?PK=" + PK,"BJournauxForm",550,355)
}
function gf_BQuoiDeNeufForm(PK){
	gf_PopUpWindow("B_QuoiDeNeuf_e.asp?PK=" + PK,"BQuoiDeNeufForm",550,355)
}
function gf_BFAQsForm(PK){
	gf_PopUpWindow("B_Faq_e.asp?PK=" + PK,"BFAQsForm",550,350)
}
function gf_BFAQsProForm(PK,ProId){
	gf_PopUpWindow("B_FaqPro_e.asp?PK=" + PK+"&ProId="+ProId,"BFAQsProForm",550,360)
}
function gf_BServiceForm(PK){
	gf_PopUpWindow("B_Service_e.asp?PK=" + PK,"BServiceForm",550,385)
}
function gf_BCollectionForm(PK){
	gf_PopUpWindow("B_Collection_e.asp?PK=" + PK,"BCollectionForm",550,355)
}
function gf_BRepertoireForm(PK){
	gf_PopUpWindow("B_Repertoire_e.asp?PK=" + PK,"BRepertoireForm",550,385)
}
function gf_BFormulaireTypeForm(PK){
	gf_PopUpWindow("B_FormulaireType_e.asp?PK=" + PK,"BFormulaireTypeForm",550,385)
}

//--------------------------
// PUBLIC
function gf_Repertoire() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/inc/Repertoire.asp?Lieu=<%=L_SITE_COURANT%>","RepertoireForm",620,340);
}
function gf_CarteEtude() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/Car_Etude.asp","CarEtudeForm",620,340);
}
function gf_CarteEtudiant() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/Car_Etudiant.asp","CarEtudiantForm",620,340);
}
function gf_CartePartenaire() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/Car_Partenaire.asp","CarPartenaireForm",620,340);
}
function gf_CarteTravail() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/Car_Travail.asp","CarTravailForm",620,340);
}
function gf_ComTravail() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/Com_Travail.asp","ComTravailForm",620,340);
}
function gf_ComEtude() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/Com_Etude.asp","ComEtudeForm",620,340);
}
function gf_ComPartenaire() {
	gf_PopUpWindow("<%=G_APP_BASE_URL%>/Com_Partenaire.asp","ComPartenaireForm",620,340);
}
//=======================================================


// -------------------------------------------------
// Ouvre une boite d'assitant de création de code HTML
// -------------------------------------------------

function gf_Id3HtmlEdit(FieldName) {

	var popupwin
	var PosX
	var PosY
	var WindowWidth
	var WindowHeight

	WindowWidth = 485
	WindowHeight = 315
	
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open("./Webapp/Id3HtmlEdit/HtmlEditor.asp?FieldName="+FieldName,"ID3HtmlEdit","scrollbars=no,resizable=no,directories=no,menubar=no,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth )
    popupwin.focus();
}
	
// -------------------------------------------------
// S'assure qu'un champ n'est pas vide
// -------------------------------------------------

function gf_CheckIfEmpty( sData, sDescription ) {
	if (sData.length < 1) {
		gf_WUI_ShowMessageBox("Champ vide non-valide","Le champ «" + sDescription + "» est obligatoire.");
		return(false);
		}
	return(true);
	}

// -------------------------------------------------
// S'assure qu'une liste n'est pas vide
// -------------------------------------------------

function gf_CheckListIfEmpty( sData, sDescription ) {
	if (sData == "#NULL#") {
		alert("Le champ «" + sDescription + "» est obligatoire.")
		return(false)
		}
	return(true)
	}

// -------------------------------------------------
// S'assure qu'un champ n'est pas vide
// -------------------------------------------------

function gf_CheckIfSitesSatellites( sData ) {
	if ((sData.toLowerCase() == "sites satellites") || (sData.toLowerCase() == "site satellite")) {
		gf_WUI_ShowMessageBox("Catégorie interdite","Cette catégorie ne peut être créé car elle est déjà utlisé par le système!");
		return(false);
		}
	return(true);
	}

// -------------------------------------------------
// Validation d'une date
// -------------------------------------------------
function gf_ValideDate ( FormObj,fieldName,Description )
	{
	var jour = 0
	var mois = 0
	var annee = 0
	var dateOK = false

	annee = parseInt( eval("FormObj." + fieldName + "Y.value") )
	mois = parseInt( eval("FormObj." + fieldName + "M.value") )
	jour = parseInt( eval("FormObj." + fieldName + "D.value") )

	dateOK = !( jour < 1 || jour > 32 || mois < 1 || mois > 12 ) &&
			 !( ( (annee % 4 == 0 && annee % 100 != 0 || annee % 400 == 0) && mois == 2 && jour > 29 ) ||
				( !(annee % 4 == 0 && annee % 100 != 0 || annee % 400 == 0) && mois == 2 && jour > 28 ) ) &&
			 !( ( mois==4 || mois==6 || mois==9 || mois==11 ) && jour > 30 ) &&
			 !( annee < 1900 ) &&
			 !( isNaN(annee) ) &&
			 !( isNaN(mois) ) &&
			 !( isNaN(jour) )

	if (!dateOK)
		{
		alert("Le format de date du champ «" + Description + "» est invalide.")
		return(false)
		}
	return(true)
	}

// -------------------------------------------------
// Validation d'un URL
// -------------------------------------------------
function gf_AsURL( oText ) {
	// Make shure the first characters of the URL is "http://"
	if (oText.value.substr(0,7) != "http://") {
		oText.value = "http://" + oText.value;
		}
	}
	
// -------------------------------------------------
// Trouve une référence sur un objet de la page
// -------------------------------------------------
function ID3_findObj(n, d) {
	var p,i,x;  
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
		
	if(!(x=d[n])&&d.all) x=d.all[n]; 
		
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=ID3_findObj(n,d.layers[i].document);
			
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
		
	return x;
}
