/***********************************************************************************************
 *
 * IFC common JS library
 *
 * Auteur : Novalet renaud (juillet 2003)
 *
 * modifications :
 *
 ***********************************************************************************************/


function viewform(codef,ksess)
{

	window.open('viewform05.asp?id='+ codef+'&sess='+ ksess,'viewFormation','toolbar=no,scrollbars=yes,width=660,height=560');
	return false;
}
function viewform1(codef)
{

	window.open('viewform05.asp?id='+ codef,'viewFormation','toolbar=no,scrollbars=yes,width=660,height=560');
	return false;
}
function promptEmail()
{
	var emailadd="";

	while(emailadd.indexOf ('@',0) == -1){
		emailadd=prompt('Inscrivez votre adresse email');
	}

	return emailadd;
}

function ValidateMailForm(thisForm)
{
	if (szreplace(thisForm.emailadd.value,' ','')==''){
		alert ("veuillez intoduire votre adresse email !");
		return false;
	}

	if (thisForm.emailadd.value.indexOf ('@',0) == -1){
		alert("L\'adresse email spécifiée est incorrecte !");
		return false;
	}
	if (thisForm.emailadd.value.indexOf ('.',0) == -1){
		alert("L\'adresse email spécifiée est incorrecte !");
		return false;
	}
	return true;
}

function checkCode(thisValue)
{
	if (isNaN(thisValue)){
		alert('Le code école doit avoir une valeur numérique !');
		return false;
	}

	if (thisValue.length<10){
		alert('Le code école spécifié est incorrect!');
		return false;
	}
return true;
}

function checkCodeCIF(thisValue)
{
	if (isNaN(thisValue)){
		alert('Le code CIF doit avoir une valeur numérique !');
		return false;
	}

	if (thisValue.length!=8)
	{
		alert('Le code CIF spécifié est incorrect !');
		return false;
	}
	if (thisValue.substring(0,6)%91!=thisValue.substring(6,8)){
		alert('Le code CIF spécifié est incorrect !');
		return false;
	}
	
return true;
}
function checkCF(thisValue)
{
	if (isNaN(thisValue)){
		alert('Le code formation doit avoir une valeur numérique !');
		return false;
	}

	if (thisValue.length!=7){
		alert('Le code formation spécifié est incorrect !');
		return false;
	}
return true;
}

function submitThisMenu(thisForm,option)
{
	if (option==1){
		thisForm.submit();
	}

	return false;
}


function ValidateLoginForm(thisForm)
{
	if (thisForm.CodeEcole.value=='')
	{
		alert("Veuillez introduire le code C.I.F.")
		return false;
	}
	return true
}

function countChecked(thisForm,chkname)
{
  var retval=0
  for (var i=0;i<thisForm.elements.length;i++){
    var e = thisForm.elements[i];
    if (e.name == chkname){
		 if(e.checked)
		 	retval++;
	}
   };
   return retval;
}

function isoneChecked(thisForm,chkname)
{
var retval=0
  for (var i=0;i<thisForm.elements.length;i++){
    var e = thisForm.elements[i];
    if (e.name == chkname){
		 if(e.checked){
		 		return 1;
		 }
	  }
	};
	return retval;
}


function checkMat(thisMat)
{
	var sdate="";
	if (thisMat.length==7){
		return true;
	}
	if (szreplace(thisMat," ","")==""){
		alert('Veuillez compléter le matricule');
		return false;
	}

	if (thisMat.length<11){
		alert('le matricule spécifié est incorrect !');
		return false;
	}
	if(parseInt(thisMat.charAt(0))>2 || parseInt(thisMat.charAt(0))<1){
		alert('le matricule spécifié est incorrect !');
		return false;
	}

	sdate=thisMat.substr(1,6);


	if(parseInt(sdate.substr(2,2))>12 || parseInt(sdate.substr(2,2))<0){
		alert('le matricule spécifié est incorrect !');
		return false;
	}
	if(parseInt(sdate.substr(4,2))>31 || parseInt(sdate.substr(4,2))<0){
			alert('le matricule spécifié est incorrect !');
			return false;
	}
	if(parseInt(sdate.substr(0,2))<30 || parseInt(sdate.substr(0,2))>90){
			alert('le matricule spécifié est incorrect !');
			return false;
	}
	if(isNaN(thisMat.substr(7,2))){
		alert('le matricule spécifié est incorrect !' );
		return false;
	}

	if(!checkNiss(thisMat)){
		alert('le matricule spécifié est incorrect !' );
		return false;
	}

	return true;
}


function ValidateAdd1Form(thisForm)
{

var tab =new Array(9);
for (var u=0;u<9;u++)
	tab[u]=0;

if (thisForm.level.value=="save" ){
	for (var i=0;i<thisForm.elements.length;i++){
	    var e = thisForm.elements[i];

	    if (e.name.indexOf("pref-") >= 0 ){
			if (tab[parseInt(e.options[e.selectedIndex].value)]){
				alert("la sélection de vos préférence est incorrecte !");
				return false;
			}
			else
				tab[parseInt(e.options[e.selectedIndex].value)]=1;
		}

	}
	return true;

} else {
	if (thisForm.level.value=="1b" || thisForm.level.value=="1b2") {
		if (!checkMat(thisForm.matens.value))
		return false;
		if (szreplace(thisForm.nomens.value," ","")==""){
				alert('Veuillez compléter le nom');
				return false;
		}

		if (szreplace(thisForm.prenomens.value," ","")==""){
				alert('Veuillez compléter le prénom');
				return false;
		}
		if (szreplace(thisForm.adresse.value," ","")==""){
				alert('Veuillez compléter l\'adresse');
				return false;
		}
		if (szreplace(thisForm.cp.value," ","")==""){
				alert('Veuillez compléter le code postal');
				return false;
		}		
		if (szreplace(thisForm.ville.value," ","")==""){
				alert('Veuillez compléter la localité');
				return false;
		}
		var testme;
		testme=szreplace(thisForm.telp.value,"-","")
		testme=szreplace(testme,"/","")
		testme=szreplace(testme,"(","")
		testme=szreplace(testme,")","")
		testme=szreplace(testme," ","")
		testme=szreplace(testme,".","")
		
		if(testme!="")
		{
		if(isNaN(testme))
		{
				alert('Numéro de Téléphone incorrect');
				return false;
		}
		}
		else
		{
			thisForm.telp.value="";
		}
		
		testme=szreplace(thisForm.faxp.value,"-","")
		testme=szreplace(testme,"/","")
		testme=szreplace(testme,"(","")
		testme=szreplace(testme,")","")
		testme=szreplace(testme," ","")
		testme=szreplace(testme,".","")
		
		if(testme!="")
		{
			if(isNaN(testme))
			{	
				alert('Numéro de Fax incorrect');
				return false;
			}
		}
		else
		{
			thisForm.faxp.value="";
		}
		

		
	
		/*if(thisForm.inter.selectedIndex==0)
		{
				alert('Veuillez séléctionner la fonction');
				return false;
		}
		if(thisForm.niv1.selectedIndex==0)
		{
				alert('Veuillez séléctionner le niveau d\'enseignement');
				return false;
		}		
		if(thisForm.niv2.selectedIndex==0)
		{
				alert('Veuillez séléctionner le type');
				return false;
		}*/		
		if (szreplace(thisForm.formselected1.value," ","")==""){
		alert('Veuillez compléter le code de la formation');
		return false;
		}	

		if(thisForm.accept.checked==false)
		{
				alert('Votre engagement est indispensable afin de pouvoir finaliser la procédure d\'inscription');
				return false;
		}
		if(thisForm.accept2.checked==false)
		{
				alert('Vous devez confirmer que l\'enseignant répond bien au public cible de la formation');
				return false;
		}
		
	} else { //end if level==""
		var szlistofform="";

		if (thisForm.level.value=="2" ) { // choix des sessions
			if(!isoneChecked(thisForm,"formselected")){
				alert('Confirmez votre choix de formation en cochant la petite case, ou modifiez votre choix en revenant sur << Préc.');
				return false;
			}

			for (var u=0;u<thisForm.elements.length;u++){
			    var el = thisForm.elements[u];
			    if (el.name == "formselected"){
					if(el.checked){
						var pos=0;
						var iFormCount=0;
						var szformid="#"+el.value.substr(0,el.value.indexOf("@"))+"#"

						pos=szlistofform.indexOf(szformid);
						while (pos>=0){
							iFormCount++;
							pos=szlistofform.indexOf(szformid,(++pos));
						}
						if (iFormCount<=0)
							szlistofform+=szformid;
						else {
							alert("Vous ne pouvez sélectionner qu'une seule session !");
							return false;
						}
					}
				}
			};


		}

	} //end if level==""

}

return true;
}
function ValidateAdd2Form(thisForm)
{

var tab =new Array(9);
	if (thisForm.level.value=="1b" || thisForm.level.value=="1b2") {
		if (!checkMat(thisForm.matens.value))
		return false;
		if (szreplace(thisForm.nomens.value," ","")==""){
				alert('Veuillez compléter le nom');
				return false;
		}

		if (szreplace(thisForm.prenomens.value," ","")==""){
				alert('Veuillez compléter le prénom');
				return false;
		}
		if (szreplace(thisForm.adresse.value," ","")==""){
				alert('Veuillez compléter l\'adresse');
				return false;
		}
		if (szreplace(thisForm.cp.value," ","")==""){
				alert('Veuillez compléter le code postal');
				return false;
		}		
		if (szreplace(thisForm.ville.value," ","")==""){
				alert('Veuillez compléter la localité');
				return false;
		}
		var testme;
		testme=szreplace(thisForm.telp.value,"-","")
		testme=szreplace(testme,"/","")
		testme=szreplace(testme,"(","")
		testme=szreplace(testme,")","")
		testme=szreplace(testme," ","")
		testme=szreplace(testme,".","")
		
		if(testme!="")
		{
		if(isNaN(testme))
		{
				alert('Numéro de Téléphone incorrect');
				return false;
		}
		}
		else
		{
			thisForm.telp.value="";
		}
		
		testme=szreplace(thisForm.faxp.value,"-","")
		testme=szreplace(testme,"/","")
		testme=szreplace(testme,"(","")
		testme=szreplace(testme,")","")
		testme=szreplace(testme," ","")
		testme=szreplace(testme,".","")
		
		if(testme!="")
		{
			if(isNaN(testme))
			{	
				alert('Numéro de Fax incorrect');
				return false;
			}
		}
		else
		{
			thisForm.faxp.value="";
		}
		

		
	
		if(thisForm.inter.selectedIndex==0)
		{
				alert('Veuillez séléctionner la fonction');
				return false;
		}
		if(thisForm.niv1.selectedIndex==0)
		{
				alert('Veuillez séléctionner le niveau d\'enseignement');
				return false;
		}		
		if(thisForm.niv2.selectedIndex==0)
		{
				alert('Veuillez séléctionner le type');
				return false;
		}		


}

return true;
}

function ValidateAdd1Form05(thisForm)
{

var tab =new Array(9);
for (var u=0;u<9;u++)
	tab[u]=0;

if (thisForm.level.value=="save" ){
	for (var i=0;i<thisForm.elements.length;i++){
	    var e = thisForm.elements[i];

	    if (e.name.indexOf("pref-") >= 0 ){
			if (tab[parseInt(e.options[e.selectedIndex].value)]){
				alert("la sélection de vos préférence est incorrecte !");
				return false;
			}
			else
				tab[parseInt(e.options[e.selectedIndex].value)]=1;
		}

	}
	return true;

} else {
	if (thisForm.level.value=="1b" || thisForm.level.value=="1b2") {
		if (!checkMat(thisForm.matens.value))
		return false;
		if (szreplace(thisForm.nomens.value," ","")==""){
				alert('Veuillez compléter le nom');
				return false;
		}

		if (szreplace(thisForm.prenomens.value," ","")==""){
				alert('Veuillez compléter le prénom');
				return false;
		}
		var testme;
		testme=szreplace(thisForm.telp.value,"-","")
		testme=szreplace(testme,"/","")
		testme=szreplace(testme,"(","")
		testme=szreplace(testme,")","")
		testme=szreplace(testme," ","")
		testme=szreplace(testme,".","")
		
		if(testme!="")
		{
			if(isNaN(testme))
			{
				alert('Numéro de Téléphone incorrect');
				return false;
			}
		}
		if(testme=="")
		{
			alert('Veuillez Compléter le numéro de téléphone');
			return false;
		}
		var cff;
		var ctrlcff;
		cff=szreplace(thisForm.formselected1.value," ","");
		
		if (cff=="")
		{
			alert('Veuillez compléter le code de la formation');
			return false;
		}	
		if(cff.length<10)
		{
			alert('Le code formation doit avoir le format "9 chiffres/de 1 à 4 chiffres');
			return false;
		}
		if(cff.length>14)
		{
			alert('Le code formation doit avoir le format "9 chiffres/de 1 à 4 chiffres');
			return false;
		}
				ctrlcff = cff.indexOf("/");
		if (ctrlcff == -1) 
		{
			alert('Le code formation doit avoir le format "9 chiffres/de 1 à 4 chiffres');
			return false;
		}
		
		
		if(thisForm.accept.checked==false)
		{
				alert('Votre engagement est indispensable afin de pouvoir finaliser la procédure d\'inscription');
				return false;
		}
		if(thisForm.accept2.checked==false)
		{
				alert('Vous devez confirmer que l\'enseignant répond bien au public cible de la formation');
				return false;
		}
		
	} else { //end if level==""
		var szlistofform="";

		if (thisForm.level.value=="2" ) { // choix des sessions
			if(!isoneChecked(thisForm,"formselected")){
				alert('Confirmez votre choix de formation en cochant la petite case, ou modifiez votre choix en revenant sur << Préc.');
				return false;
			}
			if((thisForm.at1.selectedIndex==0)&&(thisForm.at1.value!=0))
			{
				alert('Veuillez faire un choix');
				return false;
							
			}
			if((thisForm.at2.selectedIndex==0)&&(thisForm.at2.value!=0))
			{
				alert('Veuillez faire un choix');
				return false;
							
			}
			if((thisForm.at3.selectedIndex==0)&&(thisForm.at3.value!=0))
			{
				alert('Veuillez faire un choix');
				return false;
							
			}
			if((thisForm.at4.selectedIndex==0)&&(thisForm.at4.value!=0))
			{
				alert('Veuillez faire un choix');
				return false;
							
			}
			if((thisForm.at4.selectedIndex==0)&&(thisForm.at3.selectedIndex==0)&&(thisForm.at2.selectedIndex==0)&&(thisForm.at1.selectedIndex==0))
			{
				alert('Veuillez sélectionner au moins un atelier');
				return false;
							
			}
			/*if(thisForm.at2.selectedIndex==thisForm.at1.selectedIndex)
			{
				alert('Veuillez sélectionner des ateliers différents');
				return false;
			}*/
			for (var u=0;u<thisForm.elements.length;u++){
			    var el = thisForm.elements[u];
			    if (el.name == "formselected"){
					if(el.checked){
						var pos=0;
						var iFormCount=0;
						var szformid="#"+el.value.substr(0,el.value.indexOf("@"))+"#"

						pos=szlistofform.indexOf(szformid);
						while (pos>=0){
							iFormCount++;
							pos=szlistofform.indexOf(szformid,(++pos));
						}
						if (iFormCount<=0)
							szlistofform+=szformid;
						else {
							alert("Vous ne pouvez sélectionner qu'une seule session !");
							return false;
						}
					}
				}
			};


		}

	} //end if level==""

}

return true;
}





function ShowNum()
{
   	document.all.cache.style.visibility = 'visible';
   	document.all.cache.style.width = '590px';
   	document.all.cache.style.overflowX= 'visible'
   	document.all.cache.style.position= 'relative'
}
function CacheNum()
{
	document.all.cache.style.visibility = 'hidden';
	document.all.cache.style.height = '1px';
	document.all.cache.style.overflowX= 'hidden'
	document.all.cache.style.position= 'absolute'
}
function ShowNew()
{
   	document.all.cache2.style.visibility = 'visible';
   	document.all.cache2.style.width = '590px';
   	document.all.cache2.style.overflowX= 'visible'
   	document.all.cache2.style.position= 'relative'
}
function CacheNew()
{
	document.all.cache2.style.visibility = 'hidden';
	document.all.cache2.style.height = '1px';
	document.all.cache2.style.overflowX= 'hidden'
	document.all.cache2.style.position= 'absolute'
}

var selectedSess='';
var selectedForms=0;
var initi=0;

function initvar(sess,iforms)
{
	if (initi!=0 )
	    return true

	selectedSess=sess;
	selectedForms=parseInt(iforms);

	initi=true;

}

function checkthisSess(checkBox,forms)
{

var pos = selectedSess.indexOf("#"+forms+"#");
var count=0;

while ( pos != -1 ) {
		count++;
		pos = selectedSess.indexOf("#"+forms+"#",pos+1);
}

if (checkBox.checked){
	if (count==0) {
		if(selectedForms<3)
			selectedForms++;
		else {
			alert('Vous ne pouvez sélectionner que 3 formations');
			checkBox.checked=false;
			return false;
		}

	}

	if (count<3){
		selectedSess=selectedSess + "#" +forms + "#";
		return true;
	}
	else {
		alert('vous pouvez sélectionner au maximum 3 sessions par formation');
		checkBox.checked=false;
		return 0;
	}
} else {
 var tmpstring1,tmpstring2
 	if (count!=-1) {

 		var pos = selectedSess.indexOf("#"+forms+"#");

 		tmpstring1=selectedSess.substr(0,pos);
 		tmpstring2=selectedSess.substr(pos+("#"+forms+"#").length);
 		selectedSess=tmpstring1+tmpstring2

 		if (count==1)
 			selectedForms--;


 		return true;
 	}

}

}






	var DisplayStatus="IFC";
	self.status=DisplayStatus;

	CSInit = new Array;

	/********************************************************
	 *
	 * CSSScriptInit()
	 *
	 *******************************************************/
	function CSScriptInit()
	{
		if(typeof(skipPage) != "undefined") {
			if(skipPage) return;
		}

		idxArray = new Array;

		for(var i=0;i<CSInit.length;i++)
			idxArray[i] = i;

		CSAction2(CSInit, idxArray);
	}

	CSAg = window.navigator.userAgent;
	CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);

	/********************************************************
	 *
	 * isIE()
	 *
	 *******************************************************/

	function IsIE() {
		return CSAg.indexOf("MSIE") > 0;
	}

	/********************************************************
	 *
	 * CSIEStyl()
	 *
	 *******************************************************/

	function CSIEStyl(s) {
		return document.all.tags("div")[s].style;
	}

	/********************************************************
	 *
	 * CSNSStyl()
	 *
	 *******************************************************/

	function CSNSStyl(s) {
		return CSFindElement(s,0);
	}


	/********************************************************
	 *
	 * CSFindElement()
	 *
	 *******************************************************/

	function CSFindElement(n,ly)
	{
		if (CSBVers < 4)
			return document[n];

		var curDoc = ly ? ly.document : document;
		var elem = curDoc[n];

		if (!elem) {
			for (var i=0;i<curDoc.layers.length;i++) {
				elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem;
			}
		}
		return elem;
	}


	/********************************************************
	 *
	 * CSClickReturn()
	 *
	 *******************************************************/

	function CSClickReturn ()
	{
		var bAgent = window.navigator.userAgent;
		var bAppName = window.navigator.appName;
		if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
			return true; // dont follow link
		else
			return false; // dont follow link
	}

	/********************************************************
	 *
	 * CSButtonReturn()
	 *
	 *******************************************************/

	function CSButtonReturn ()
	{
		var bAgent = window.navigator.userAgent;
		var bAppName = window.navigator.appName;

		if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
			return false; // follow link
		else
			return true; // follow link
	}


	/********************************************************
	 *
	 * CSIShow()
	 *
	 *******************************************************/

	CSIm = new Object();

	function CSIShow(n,i)
	{
		if (document.images) {
			if (CSIm[n]) {
				var img = (!IsIE()) ? CSFindElement(n,0) : document[n];
				if (img && typeof(CSIm[n][i].src) != "undefined")
					img.src = CSIm[n][i].src;

				if(i != 0)
					self.status = CSIm[n][3];
				else
					self.status = DisplayStatus;
				return true;
			}
		}
		return false;
	}

	/********************************************************
	 *
	 * CSILoad()
	 *
	 *******************************************************/

	function CSILoad(action)
	{
		im = action[1];

		if (document.images) {
			CSIm[im] = new Object();
			for (var i=2;i<5;i++) {
				if (action[i] != '') {
					CSIm[im][i-2] = new Image();
					CSIm[im][i-2].src = action[i];
				} else
					CSIm[im][i-2] = 0;
			}
			CSIm[im][3] = action[5];
		}
	}


	/********************************************************
	 *
	 * CSAction() && CSAction2()
	 *
	 *******************************************************/

	CSStopExecution = false;

	function CSAction(array)
	{
		return CSAction2(CSAct, array);
	}

	function CSAction2(fct, array)
	{
		var result;

		for (var i=0;i<array.length;i++) {
			if(CSStopExecution) return false;
			var actArray = fct[array[i]];

			if(actArray == null)
				return false;
			var tempArray = new Array;

			for(var j=1;j<actArray.length;j++) {
				if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {
					if(actArray[j][0] == "VAR")
						tempArray[j] = CSStateArray[actArray[j][1]];

					else {
						if(actArray[j][0] == "ACT")
							tempArray[j] = CSAction(new Array(new String(actArray[j][1])));
						else
							tempArray[j] = actArray[j];
					}
				} else
					tempArray[j] = actArray[j];
			} // end for

			result = actArray[0](tempArray);
		} // end for

		return result;
	}

	CSAct = new Object;



	CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button',/*URL*/'imgs/NEW3bandeaucomfr1_02.gif',/*URL*/'imgs/NEWbandeaucomfr1on_02.gif',/*URL*/'','portail d\'accès à tous les services de la Communauté');
	CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button3',/*URL*/'imgs/NEW3bandeaucomfr1_03.gif',/*URL*/'imgs/NEWbandeaucomfr1on_03.gif',/*URL*/'','Vos démarches, formulaires et services pratiques en ligne');
	CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button2',/*URL*/'imgs/NEW3bandeaucomfr1_04.gif',/*URL*/'imgs/NEWbandeaucomfr1on_04.gif',/*URL*/'','Rechercher une information sur le site de la Communauté');
	CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button4',/*URL*/'imgs/NEW3bandeaucomfr1_05.gif',/*URL*/'imgs/NEWbandeaucomfr1on_05.gif',/*URL*/'','Les informations récentes de la Communauté Wallonie-Bruxelles');

