var sBase = "http://admin.segec.be/GestionEcoles/"

//var url = document.location.href;
//var s=url.substring(0,url.lastIndexOf("/")) + "/";
//alert(s);

var sAnnee = 2002
var sLogoutConfirm = "Etes-vous sûr de vouloir quitter ?"
var Relocate

function ShowWindow(WindowName, URL, Actualiser, Width, Height) {
  var wnd = window.open("", WindowName, "height=" + Height + ",width=" + Width + ",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes,top=0,left=0")
  if (Actualiser || wnd.defaultStatus != "Fpe") {
    if (Relocate)
      wnd.location.replace(sBase + URL)
	else
      wnd.location = sBase + URL
  }
  wnd.focus()
}
function OpenNewWindow(URL) {
  var wnd = window.open(sBase + URL, "_blank", "height=400,width=600,status=no,toolbar=no,menubar=no,resizable=yes,top=0,left=0")
  wnd.focus()
}

//fonctions pour les menus principaux
function MenuprincGestion(CloseWindow) {
  if (top.name != "MenuGest" && CloseWindow) top.close()
  ShowWindow("MenuGest", "Cgi/gestion/menuprinc.cfm", 1, 780, 300)
}

function MenuprincConsultation(CloseWindow) {
  if (top.name != "MenuConsult" && CloseWindow) top.close()
  ShowWindow("Menuconsult", "cgi/consultation/menuprinc.htm", 1, 850, 150)
}

// fonctions pour listes de sélection
function ShowFormationsListe() {
  ShowWindow("ForListe", "cgi/gestion/Formations/index.htm", 0, 800, 600)
}

function ConsultFormationsListe() {
  ShowWindow("ForListe", "cgi/Consultation/Formations/index.htm", 0, 800, 600)
}

function ShowPersonnesListe() {
  ShowWindow("PerListe", "cgi/gestion/Personnes/index.htm", 0, 800, 600)
}

function ShowLieuxListe() {
  ShowWindow("LieuxListe", "cgi/gestion/Lieux/index.htm", 0, 800, 600)
}

function ShowEcolesListe() {
  ShowWindow("EcoListe", "cgi/gestion/Ecoles/index.htm", 0, 800, 600)
}

function ShowFormateursListe() {
  ShowWindow("ProfListe", "cgi/gestion/Formateurs/index.htm", 0, 800, 600)
}

function ShowOperateursListe() {
  ShowWindow("OpeListe", "cgi/gestion/Operateurs/index.htm", 0, 800, 600)
}

function ShowPromoteursListe() {
  ShowWindow("ProListe", "cgi/gestion/Promoteurs/index.htm", 0, 800, 600)
}

function ShowRapportsListe() {
  ShowWindow("Rapports", "cgi/gestion/Rapports/index.htm", 0, 800, 600)
}

function ShowDivers() {
  ShowWindow("Divers", "cgi/gestion/Divers/index.htm", 0, 800, 600)
}

function ShowLocalitesListe() {
  ShowWindow("Localites", "cgi/gestion/Localites/index.htm", 0, 800, 600)
}

function ShowTelecharger() {
  ShowWindow("Telecharger", "cgi/gestion/Telecharger/index.htm", 0, 800, 600)
}

// Consultation et édition formations
function FormationGest(CloseWindow, Key) {
  if (top.name != "ForGest" && CloseWindow) top.close()
  ShowWindow("ForGest", "cgi/gestion/Formations/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function FormationConsult(CloseWindow, Key) {
  if (top.name != "ForCons" && CloseWindow) top.close()
  ShowWindow("ForCons", "cgi/Consultation/Formations/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function FormationsEdit(CloseWindow, Key) {
  if (top.name != "ForEdit" && CloseWindow) top.close()
  ShowWindow("ForEdit", "cgi/gestion/Formations/ModifierFormation.cfm" + Key, 1, 800, 600)
}


function FormationsCopier(CloseWindow, Key) {
  if (top.name != "ForCopier" && CloseWindow) top.close()
  ShowWindow("ForEdit", "cgi/gestion/Formations/CopierFormation.cfm" + Key, 1, 800, 600)
}

function FormationsAjout(CloseWindow) {
  if (top.name != "ForAjout" && CloseWindow) top.close()
  ShowWindow("ForAjout", "cgi/gestion/Formations/AjouterFormation.cfm", 1, 800, 600)
}

function FormationSupp(CloseWindow, Key) {
  if (top.name != "ForSupp" && CloseWindow) top.close()
  ShowWindow("ForSupp", "cgi/gestion/Formations/SupprimerFormation.cfm" + Key, 1, 400, 300)
}

function FormationsProgrammes(CloseWindow, Key) {
  if (top.name != "ForPrg" && CloseWindow) top.close()
  ShowWindow("ForPrg", "Documents/FormationsProgrammes.rpt" + Key, 1, 800, 600)
}

function FormationsAnnexe4(CloseWindow, Key) {
  if (top.name != "ForPres" && CloseWindow) top.close()
  ShowWindow("ForPres", "Documents/FormationsPresences.rpt" + Key, 1, 800, 600)
}

function FormationsPresences(CloseWindow, Key) {
  if (top.name != "ForPres" && CloseWindow) top.close()
  ShowWindow("ForPres", "Documents/FormationsPresencesPortrait.rpt" + Key, 1, 800, 600)
}

function FormationsInscrits(CloseWindow, Key) {
  if (top.name != "ForIns" && CloseWindow) top.close()
  ShowWindow("ForIns", "Documents/FormationsInscrits.rpt" + Key, 1, 800, 600)
}

function EtFormationsInscritsFormateurs(CloseWindow, Key) {
  if (top.name != "ForEti" && CloseWindow) top.close()
  ShowWindow("ForEti", "Documents/EtFormationsInscritsFormateurs.rpt" + Key, 1, 800, 600)
}

function FormationsCertificats(CloseWindow, Key) {
  if (top.name != "ForCertif" && CloseWindow) top.close()
  ShowWindow("ForCertif", "Documents/RpCertificatsInscrits.rpt" + Key, 1, 800, 600)
}

// Consultation et édition personnes
function PersonneGest(CloseWindow, Key) {
  if (top.name != "PerGest" && CloseWindow) top.close()
  ShowWindow("PerGest", "cgi/gestion/Personnes/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function PersonneEdit(CloseWindow, Key) {
  if (top.name != "PerEdit" && CloseWindow) top.close()
  ShowWindow("PerEdit", "cgi/gestion/Personnes/FicheModifications.cfm" + Key, 1, 800, 600)
}

function PersonneAjout(CloseWindow) {
  if (top.name != "PerAjout" && CloseWindow) top.close()
  ShowWindow("PerAjout", "cgi/gestion/Personnes/Ajouter.cfm", 1, 800, 600)
}

function PersonneSupp(CloseWindow, Key) {
  if (top.name != "PerSupp" && CloseWindow) top.close()
  ShowWindow("PerSupp", "cgi/gestion/Personnes/Supprimer.cfm" + Key, 1, 400, 300)
}

// Consultation et édition localités
function LocaliteGest(CloseWindow, Key) {
  if (top.name != "LocGest" && CloseWindow) top.close()
  ShowWindow("LocGest", "cgi/gestion/Localites/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function LocaliteEdit(CloseWindow, Key) {
  if (top.name != "LocEdit" && CloseWindow) top.close()
  ShowWindow("LocEdit", "cgi/gestion/Localites/FicheModifications.cfm" + Key, 1, 800, 600)
}

function LocaliteAjout(CloseWindow) {
  if (top.name != "LocAjout" && CloseWindow) top.close()
  ShowWindow("LocAjout", "cgi/gestion/Localites/Ajouter.cfm", 1, 800, 600)
}

function LocaliteSupp(CloseWindow, Key) {
  if (top.name != "LocSupp" && CloseWindow) top.close()
  ShowWindow("LocSupp", "cgi/gestion/Localites/Supprimer.cfm" + Key, 1, 400, 300)
}

// Consultation et édition lieux
function LieuxGest(CloseWindow, Key) {
  if (top.name != "LieuxGest" && CloseWindow) top.close()
  ShowWindow("LieuxGest", "cgi/gestion/Lieux/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function LieuxEdit(CloseWindow, Key) {
  if (top.name != "LieuxEdit" && CloseWindow) top.close()
  ShowWindow("LieuxEdit", "cgi/gestion/Lieux/FicheModifications.cfm" + Key, 1, 800, 600)
}

function LieuxAjout(CloseWindow) {
  if (top.name != "LieuxAjout" && CloseWindow) top.close()
  ShowWindow("LieuxAjout", "cgi/gestion/Lieux/Ajouter.cfm", 1, 800, 600)
}

function LieuxSupp(CloseWindow, Key) {
  if (top.name != "LieuxSupp" && CloseWindow) top.close()
  ShowWindow("LieuxSupp", "cgi/gestion/Lieux/Supprimer.cfm" + Key, 1, 400, 300)
}

// Consultation et édition écoles
function EcoleGest(CloseWindow, Key) {
  if (top.name != "EcoGest" && CloseWindow) top.close()
  ShowWindow("EcoGest", "cgi/gestion/Ecoles/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function EcoleEdit(CloseWindow, Key) {
  if (top.name != "EcoEdit" && CloseWindow) top.close()
  ShowWindow("EcoEdit", "cgi/gestion/Ecoles/FicheModifications.cfm" + Key, 1, 800, 600)
}

function EcoleAjout(CloseWindow) {
  if (top.name != "EcoAjout" && CloseWindow) top.close()
  ShowWindow("EcoAjout", "cgi/gestion/Ecoles/Ajouter.cfm", 1, 800, 600)
}

function EcoleSupp(CloseWindow, Key) {
  if (top.name != "EcoSupp" && CloseWindow) top.close()
  ShowWindow("EcoSupp", "cgi/gestion/Ecoles/Supprimer.cfm" + Key, 1, 400, 300)
}


function OffresEdit(CloseWindow, Key) {
  if (top.name != "OffreEdit" && CloseWindow) top.close()
  ShowWindow("OffreEdit", "cgi/gestion/Ecoles/FicheOffres.cfm" + Key, 1, 800, 600)
}

function MailBiEdit(CloseWindow, Key) {
  if (top.name != "MailBiEdit" && CloseWindow) top.close()
  ShowWindow("MailBiEdit", "cgi/gestion/Ecoles/FicheMailBi.cfm" + Key, 1, 800, 600)
}




// Consultation et édition formateurs
function FormateurGest(CloseWindow, Key) {
  if (top.name != "ProfGest" && CloseWindow) top.close()
  ShowWindow("ProfGest", "cgi/gestion/Formateurs/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function FormateurEdit(CloseWindow, Key) {
  if (top.name != "ProfEdit" && CloseWindow) top.close()
  ShowWindow("ProfEdit", "cgi/gestion/Formateurs/FicheModifications.cfm" + Key, 1, 800, 600)
}

function FormateurAjout(CloseWindow) {
  if (top.name != "ProfAjout" && CloseWindow) top.close()
  ShowWindow("ProfAjout", "cgi/gestion/Formateurs/Ajouter.cfm", 1, 800, 600)
}

function FormateurRech(CloseWindow) {
  if (top.name != "ProfRech" && CloseWindow) top.close()
  ShowWindow("ProfRech", "cgi/gestion/Formateurs/Rechercher.cfm", 1, 800, 600)
}

function FormateurSupp(CloseWindow, Key) {
  if (top.name != "ProfSupp" && CloseWindow) top.close()
  ShowWindow("ProfSupp", "cgi/gestion/Formateurs/Supprimer.cfm" + Key, 1, 400, 300)
}

// Consultation et édition opérateurs
function OperateurGest(CloseWindow, Key) {
  if (top.name != "OpeGest" && CloseWindow) top.close()
  ShowWindow("OpeGest", "cgi/gestion/Operateurs/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function OperateurEdit(CloseWindow, Key) {
  if (top.name != "OpeEdit" && CloseWindow) top.close()
  ShowWindow("OpeEdit", "cgi/gestion/Operateurs/FicheModifications.cfm" + Key, 1, 800, 600)
}

function OperateurAjout(CloseWindow) {
  if (top.name != "OperAjout" && CloseWindow) top.close()
  ShowWindow("OperAjout", "cgi/gestion/Operateurs/Ajouter.cfm", 1, 800, 600)
}

function OperateurSupp(CloseWindow, Key) {
  if (top.name != "OperSupp" && CloseWindow) top.close()
  ShowWindow("OperSupp", "cgi/gestion/Operateurs/Supprimer.cfm" + Key, 1, 400, 300)
}

// Consultation et édition promoteurs
function PromoteurGest(CloseWindow, Key) {
  if (top.name != "PromGest" && CloseWindow) top.close()
  ShowWindow("PromGest", "cgi/gestion/Promoteurs/IndexUnRecord.cfm" + Key, 1, 800, 600)
}

function PromoteurEdit(CloseWindow, Key) {
  if (top.name != "PromEdit" && CloseWindow) top.close()
  ShowWindow("PromEdit", "cgi/gestion/Promoteurs/FicheModifications.cfm" + Key, 1, 800, 600)
}

function PromoteurAjout(CloseWindow) {
  if (top.name != "PromAjout" && CloseWindow) top.close()
  ShowWindow("PromAjout", "cgi/gestion/Promoteurs/Ajouter.cfm", 1, 800, 600)
}

function PromoteurSupp(CloseWindow, Key) {
  if (top.name != "PromSupp" && CloseWindow) top.close()
  ShowWindow("PromSupp", "cgi/gestion/Promoteurs/Supprimer.cfm" + Key, 1, 400, 300)
}

function PromoteurBudget(CloseWindow, Key) {
  if (top.name != "ProBudget" && CloseWindow) top.close()
  ShowWindow("ProBudget", "Documents/RpBudgetsTableaux.rpt" + Key, 1, 800, 600)
}


//Fonctions de dialogues
function FermerFenetre(Message){
alert(Message);
window.close()
}

function Logout() {
  if (confirm(sLogoutConfirm)) location = sBase + "elink.dll/logout?PAGE=Logout.htm"
}

//Fonctions de navigation
function rafraichir(cadre){
parent.frames(cadre).document.location.reload(true)
}

function rafraichirdoc(){
parent.document.location.reload(true)
}




//Fonctions de validation des entrées

function validerform(which) {

var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,6)=="requis") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(6,30).toUpperCase();
alert("Vérifiez que "+shortFieldName+" a été complèté");
tempobj.focus();
return false;
}
else
return true;
}

function ValiderDate(Chaine)
{
var jours;
var mois;
var datejour;
var datemois;
var dateannee;
var j;
var a;
var b;
var m;
var y;
var q;
var r;
var ok;

jours = new Array(7);
mois = new Array(12);

jours[ 0 ] = "Dimanche";
jours[ 1 ] = "Lundi";
jours[ 2 ] = "Mardi";
jours[ 3 ] = "Mercredi";
jours[ 4 ] = "Jeudi";
jours[ 5 ] = "Vendredi";
jours[ 6 ] = "Samedi";

mois[ 1 ] = "janvier";
mois[ 2 ] = "février";
mois[ 3 ] = "mars";
mois[ 4 ] = "avril";
mois[ 5 ] = "mai";
mois[ 6 ] = "juin";
mois[ 7 ] = "juillet";
mois[ 8 ] = "aout";
mois[ 9 ] = "septembre";
mois[ 10 ] = "octobre";
mois[ 11 ] = "novembre";
mois[ 12 ] = "décembre";

ok=true;
datejour=parseInt(Chaine.substr(0,2),10);
datemois=parseInt(Chaine.substr(3,2),10);
dateannee=parseInt(Chaine.substr(6,4),10);

a1=parseInt(Chaine.substr(6,2),10);
a2=parseInt(Chaine.substr(8,2),10);
b = false;
if (a2 != 0 && Math.floor( a2/4 )== a2/4 ) b = true;
if (a2==0 && floor( a1/4 ) == a1/4) b = true;

a=Math.floor((14-datemois)/12);
y=dateannee-a;
m=datemois+12*a-2;
j=datejour+y+Math.floor(y/4)-Math.floor(y/100)+Math.floor(y/400)+Math.floor((31*m)/12);
j=j%7;
}

function EstChiffre(x)
{

}

// création des classes d'objets

// classe validateur

// déclaration d'une méthode pour la classe validateur
// avant, si utilisée dans la déclaration de classe
// après, avant si associée par prototype

function methvalider()
{
	var expratio = new RegExp("^[0123]\\d\\/[01]\\d\\/\\d{4}$");
	var datejour;
	var datemois;
	var dateannee;
	var bissextile;
	var a1;
	var a2;
	var nbjours;
	var valeurobj = this.elem.value;
	var valide = true;
	var suitemessage = "";
	nbjours = new Array(12);
//if ((valeurobj==null || valeurobj=="") && (this.requis==1)) {valide=false;suitemessage="ne peut être vide";}
		if (!(valeurobj==null || valeurobj==""))
			{
			if (this.typedonnee!=null)
			{
			switch (this.typedonnee)
				{
				case "alpha":
				{valide=isNaN(valeurobj) ;
				break;}
				case "num":
				{valide=!isNaN(valeurobj);
				break;}
				case "date":
				if(!expratio.test(valeurobj)) {valide = false;break;}
				{
				nbjours[1]=31;
				nbjours[2]=28;
				nbjours[3]=31;
				nbjours[4]=30;
				nbjours[5]=31;
				nbjours[6]=30;
				nbjours[7]=31;
				nbjours[8]=31;
				nbjours[9]=30;
				nbjours[10]=31;
				nbjours[11]=30;
				nbjours[12]=31;
				datejour=parseInt(valeurobj.substr(0,2),10);
				datemois=parseInt(valeurobj.substr(3,2),10);
				dateannee=parseInt(valeurobj.substr(6,4),10);
				if (datejour < 1) {valide = false;break};
				if (datemois < 1) {valide = false;break};
				if (datemois > 12) {valide = false;break};
				if (dateannee < 2000) {valide = false;break};
				a1=parseInt(valeurobj.substr(6,2),10);
				a2=parseInt(valeurobj.substr(8,2),10);
				bissextile = false;
				if (a2 != 0 && Math.floor( a2/4 )== a2/4 ) {bissextile = true;}
				if (a2==0 && floor( a1/4 ) == a1/4) {bissextile = true;}
				if (bissextile) {nbjours[2]=29;}
				if (datejour > nbjours[datemois]) {valide = false;break}
				}
				}
			}
		if (this.objexpreg)
		{
		var valreg = new RegExp(this.objexpreg,this.intreg);
		valide = valreg.test(valeurobj)
		}
	suitemessage="non valide";
}

if (!valide)
	{
	alert(this.elem.name + " ("+ this.txtmessage+") "+suitemessage+"\ncorrigez svp");
	this.elem.value= "";
	this.elem.focus()
	}

}

// déclaration de classe par la fonction constructrice (technique javascript)

function validateur(obj, txtmessage, typedonnee, requis,objexpreg, intreg)
{
this.elem = obj;
this.txtmessage = txtmessage;
this.requis = requis;
this.typedonnee = typedonnee;
this.objexpreg = objexpreg;
this.intreg = intreg;
this.valider = methvalider;
}


// affectation de la méthode valider à la classe validateur
// fsa validateur.prototype.valider=methvalider

