var envoyer = false;
var liensMenu = new Array(
new Array("Mot du directeur","motDG.html"),
new Array("Historique et mission","menu.php?p=17&c=0"),
new Array("Calendrier","Javascript: calendrier();"),
new Array("Horaire des cours","menu.php?p=18&c=0"),
new Array("Répertoire du personnel","menu.php?p=11&c=0"),
new Array("Info « grippe A(H1N1) »","menu.php?p=20&c=0"),
new Array("Rôle et intervention","menu.php?p=22&c=0"),
new Array("Soutien aux élèves","menu.php?p=14&c=0"),
new Array("Frais de scolarité","menu.php?p=15&c=0"),
new Array("Nos installations","menu.php?p=9&c=0"),
new Array("Nos services","menu.php?p=8&c=0"),
new Array("Menu","menu.php?p=13&c=0"),
new Array("Les anciens","menu.php?p=10&c=0"),
new Array("Centre de documents","menu.php?p=21&c=0"),
new Array("On parle de nous","menu.php?p=16&c=0"),
new Array("Surveillants","menu.php?p=12&c=0"),
new Array("Saviez-vous...","menu.php?p=7&c=0"));

var preload=new Array(),pl = new Array("images/menuacc_01o.gif","images/menuacc_02o.gif","images/menuacc_03o.gif","images/menuacc_04o.gif","images/menuacc_05o.gif","images/menuacc_06o.gif","images/menuacc_07o.gif","images/menuacc_08o.gif","images/menuacc_09o.gif");

if (preload.length < 1){
	for(var i=0;i<pl.length;i++ ){
		preload[i]=new Image;
		preload[i].src=pl[i];	
	}
}

// ********************************
// Insère le menu secondaire en bas de page
function menuBas(page) {
  var texte = '<center><font face="arial" size=2 color="#1E3964">';
  for (var i = 0; i < liensMenu.length; i++) {
    if (liensMenu[i][0] == page) {
      texte = texte + liensMenu[i][0];
    } // if
    else {
      texte = texte + '<A href="' + liensMenu[i][1];
      if (liensMenu[i][0] != 'Calendrier') {
        texte = texte + '" target="_top"';
      }  // if
      texte = texte + '">' + liensMenu[i][0] + '</A>';
    }
    if (i < liensMenu.length - 1) {
      if ((i+ 1) % 3   == 0) {
        texte = texte + '<br>';
      } // if
      else {
	texte = texte + '  |  ';
      } // else
    } // if
  }  // for
  
  texte = texte + '</font><br><br><a href="menu.php?p=5&c=0" target="_top">msa@college-mont-sainte-anne.qc.ca</a></center><br>';
  document.open();
  document.write(texte);
  document.close();
}

// ********************************
// permet d'imprimer une page à partir d'un bouton
function imprimer(page) {
  var win1 = open(page, "Fen1","menubar=no,statusbar=no,toolbar=no,scrollbars=yes,top=0,left=0,width=620");
  win1.print();
//  win1.close();
}

// ********************************
// Ouvre la fenêtre du calendrier 
function calendrier() {
  var win;
  win = window.open("calendrier.html","Fen2", "status=no,toolbar=no,menubar=no,locationbar=no,height=455, width=575, top=10, left=100");
}

// ********************************
// Ferme la fenêtre du calendrier
function fermeCal() {
window.close();
}

// ********************************
// vide
function stop() {
}

// ********************************
// Ajoute la page aux favoris
function favoris(p,t) {
  window.external.addFavorite('http://www.college-mont-sainte-anne.qc.ca/accueil.html','Collège du Mont-Sainte-Anne');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  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=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function cpValide(ctrl){
// Valide le code postal en passant le nom du champs
	with (ctrl) {
		if(ctrl.value != ''){
			var temp = value.replace(/ /g,"");
			var modele= /[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]/;
			if (!modele.test(temp) || temp.length > 6) {
				alert("Le code postal n'est pas pas valide !\nSVP, inscrivez-le de nouveau.");
				focus();
			}// if
			else { // Formate le code postal validé
				temp = temp.slice(0,3) + " " + temp.slice(3,6);	
				value = temp.toUpperCase();
			}// else
		}//if
	}// with
}// end cpValide

function telValide(ctrl){
// Valide le code postal en passant le nom du champs
	with (ctrl) {
		if(ctrl.value != ''){
			var temp = value.replace(/ /g,"");
			temp = temp.replace(/-/g,"");
			temp = temp.replace(/\(/g,"");
			temp = temp.replace(/\)/g,"");
			var modele = (temp.length == 7)?/[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/:/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/;			
			if(!modele.test(temp) || (temp.length != 7 && temp.length != 10)) {
				alert("Ce numéro n'est pas pas valide !\nSVP, inscrivez-le de nouveau.");
				focus();
				return false;
			}// if
			else {
				value = (temp.length == 7)?temp.slice(0,3) + "-" + temp.slice(3,7):temp.slice(0,3) + " " + temp.slice(3,6) + "-" + temp.slice(6,10);
				return true;
			}
		}// if
		else 
			return false;	
	}// with
}// end 

function emailCheck(form){
	//Pour vérifier si le champ contient bien une adresse courriel (contenant "@")
	with (form){
	var s = value.split(/@/);
		if((value)&&(value.search(/ /)!=-1||s.length!=2||!(s[0])||!(s[1])||s[1].search(/\.\w/)==-1)){
			focus();
			alert("Votre adresse courriel n'est pas valide !\n" +
							"Veuillez recommencer.");
			return false;
		}//if
		else {
			if (value == '') return false; else return true;
		}
	}//with
}//funct

function checkForm(ctrl){
// Vérifie que les champs
// requis soient bien remplis
var f,msg = "Les champs marqués d'un astérisque sont requis!";
with(ctrl){
			if(nom.value == '' || !telValide(telResidence) || !emailCheck(courriel) ) {
				if(nom.value=='') f=nom; else if (!telValide(telResidence)) f=telResidence; else if (!emailCheck(courriel)) f=courriel;
				f.focus();
				alert(msg); 
				return false;
			}//if
			else
				return true;
		}
}

function requis(form){
	if (envoyer==false){
		envoyer=true;
		var n,args=requis.arguments, l=args.length - 1;
		if(l > 0) {
			for(var i=1; i<args.length; i++){
				n=args[i];
				if(n.value == '' || n.value == 0) {
						alert("Les champs marqués d'un astérisque sont requis !"); 
						n.focus();
						envoyer=false;
						return false;
				}//if
			}//for
		}//if
		form.submit();
		return true;
	}
	else { return false; }
}

function openPictWindow(thePict,h,w){
 var txt, win = window.open("","Pict",'scrollbars=no,resizable=no,width=' + h + ',height=' + w);
  txt = "<html>";
  txt = txt  + "<head>";
  txt = txt + "<Title>Collège du Mont-Sainte-Anne</Title>";
  txt = txt + "</head>";
  txt = txt + "<Body leftmargin=0 topmargin=0 onBlur=self.close();>";
  txt = txt + "<img src=" + thePict + ">";
  txt = txt + "</Body>";
  txt = txt + "</html>";
  win.document.write(txt);
  win.document.close();
}

function popUp(page,w,h) {
  var win;
  win = window.open(page,"Fen2", "status=no,toolbar=no,menubar=no,locationbar=no,height="+h+", width="+w+", top=0, left=0");
}