/*******************************************/
/* f_goPg(aPg) */
/*******************************************/
/* Lien vers une page produit du site
 * IN : aPg = pageid de la page à atteindre
 */

function f_goPg(aPg, aLg){
	var urlToGo = "/product.go?pg=" + aPg;

	if( !(aLg == null)){
		urlToGo += '&q_lg=' + aLg;
	}

	document.location.href = urlToGo;
}

/*******************************************/
/* f_goPgPopup(aPg) */
/*******************************************/
/* Lien vers une page produit du site dans un popup
 * IN : aPg = pageid de la page à atteindre
 */

function f_goPgPopup(aPg, aLg){
	var urlToGo = "/product.go?pg=" + aPg;

	if( !(aLg == null)){
		urlToGo += '&q_lg=' + aLg;
	}
	//alert("bing");
  window.open(urlToGo);
	//document.location.href = urlToGo;
}

/*******************************************/
/* f_goPgPopupNoMenu(aPg) */
/*******************************************/
/* Lien vers une page produit du site dans un popup sans les menu
 * IN : aPg = pageid de la page à atteindre
 */

function f_goPgPopupNoMenu(aPg, aLg){
	var urlToGo = "/productPop.go?pg=" + aPg;

	if( !(aLg == null)){
		urlToGo += '&q_lg=' + aLg;
	}
	//alert("bing");
  window.open(urlToGo);
	//document.location.href = urlToGo;
}


/*******************************************/
/* f_goStc(aPg) */
/*******************************************/
/* Lien vers une page statique du site
 * IN : aPg = pageid de la page à atteindre
 *			aParam = paramètre supplémentaires
 */

function f_goStc(aPg,aParam){
	loc =  "/stc/" + aPg + ".go?pg=" + aPg;

	if(aParam != null){
    	loc = loc + aParam;
    }
	document.location.href = loc;

}


/*************************************************************************/
/* f_buildMF(aPage, aRfsigna, aNoidscr, aCdoptrn, aUser, aLg, aPg, aStc) */
/*************************************************************************/
/* Lien vers une page mainframe du site
 * IN : aPage = imstran - cdemid à passer à la transac
 *			aRfsigna = signature de la dernière transac
 *			aNoidscr = numéro de scratch
 *			aCdoptrn = code opération de la transac à atteindre
 *			aUser = cookie identifiant de l'utilisateur
 *			aLg = langue
 *			aPg = pageid à passer en tant que param "PG" pour construction page si différent du cdoptrn
 *			aStc = spécifie si il faut rediriger sur une page statique après l'init
 *			aPrm = chaine contenant les paramètres supplémentaires
 */

function f_buildMF(aPage, aRfsigna, aNoidscr, aCdoptrn, aUser, aLg, aPg, aStc, aPrm, aBorne){
  
  // Indique si on a un cookie mon site ethias à la transac 
  var mse_id='';
  mse_id = getCookie("MSE_ID")>0?'Y':'N';
  
	loc = '';
	/* Si pas de numero de scratch, initialiser la SPA */
  if(aNoidscr == ''){
    loc = "/initMF.go?IMSTRAN=WSM328&CDEMID=1&CDOPTRN=SMINT&CLE=&CDMSETH=" + mse_id + "&CDLGTRN=" + aLg + "&NOIDUSR=" + aUser.substr(0,7) + "&NOSQUSR=" + aUser.substr(7,2);

    if(aPg != null){
    	loc = loc + "&aPg=" + aPg;
    }

    if(aStc > 0){
    	loc = loc + "&aStc=" + aStc;
    }

    if(aBorne != null){
    	loc = loc + "&BANNER=" + aBorne;
    }

    /* Toujours laisser cette instruction en dernier, elle permet de scinder l'url pour retourver les paramètres supplémentaires lors d'un initMF */
    loc = loc + "&aCDOPTRN=" + aCdoptrn;
	}else{
		if(aStc > 0){
			f_goStc(aCdoptrn);
			return;
		} else {
	    loc = "/mf.go?IMSTRAN=" + aPage.substr(0,6) + "&CDEMID=" + aPage.substr(7,1) + "&RFSIGNA=" + aRfsigna + "&NOIDSCR=" + aNoidscr + "&CLE=&CDLGPAG=" + aLg + "&NOIDUSR=" + aUser.substr(0,7) + "&NOSQUSR=" + aUser.substr(7,2) + "&CDOPTRN=" + aCdoptrn + "&CDLGTRN=" + aLg;

	    if(aPg != null){
	    	loc += "&pg=" + aPg;
		  }else{
		  	loc += "&pg=" + aCdoptrn;
		  }
  	}
	}

	if(aPrm != null){
  	loc = loc + aPrm;
  }

	document.location.href = loc;
}

/*************************************************************/
/* f_setCle(aCle) */
/*************************************************************/
/* Poste le formulaire mainframe avec une nouvelle clé
 * IN : aCle = clé à passer
 */

function f_setCle(aCle){
	document.form_mf.CDOPTRN.value = '';
  document.form_mf.CLE.value = aCle;
  document.form_mf.submit();
}

/*************************************************************/
/* f_setCode(aCode) */
/*************************************************************/
/* Poste le formulaire mainframe avec un nouveau code opération
 * IN : aCode = code à passer
 */

function f_setCode(aCode){
	document.form_mf.CDOPTRN.value = aCode;
  document.form_mf.CLE.value = '';
  document.form_mf.submit();
}

/*************************************************************/
/* f_warning(aMsg, aShow) */
/*************************************************************/
/* Affiche un message délivré par la transaction
 * IN : aMsg = message à afficher
 *			aShow = Spécifie si le message doit être affiché (0 = non, 1 = oui)
 */

function f_warning(aMsg, aShow){
	if(aShow > 0 && aMsg.length > 0){
	  alert(aMsg);
	}
}


/*************************************************************/
/* f_focus(LTRFCSR,NURFCSI,NURFCSJ,LTRFPOS,NURFPSI,NURFPSJ)  */
/*************************************************************/
/* Permet de placer le focus sur un champ commandé par la
 * transac lors d'un message d'erreur
 * IN : champs venant de la transaction
 */
function f_focus(LTRFCSR,NURFCSI,NURFCSJ,LTRFPOS,NURFPSI,NURFPSJ)
{ var zone;
  var estPositionne;
  var tmp;
  var i=0;

  // positionnement du curseur si erreur
  estPositionne=false;
  if (0 != LTRFCSR.length)
  {
    if (0 != NURFCSJ.length)
    {
      tmp="document.forms[0]."+LTRFCSR+NURFCSI+"_"+NURFCSJ;
    }
    else
    {
      tmp="document.forms[0]."+LTRFCSR+NURFCSI;
    }
    zone = eval(tmp);
    if (zone==null || zone.type==undefined) // pour les radio boutons
    {
  	  if (0 != NURFCSJ.length)
      {
        tmp="document.forms[0]."+LTRFCSR+NURFCSI+"["+(NURFCSJ-1)+"]";
      }
      else
      {
      	if (0 != NURFCSI.length){
        	tmp="document.forms[0]."+LTRFCSR+"["+(NURFCSI-1)+"]";
        }
        else
        {
        	tmp="document.forms[0]."+LTRFCSR+"[0]";
        }
      }
      zone = eval(tmp);
    }

    zone.select();
    estPositionne=true;
  }

  if (!estPositionne)
  {
  //positionnement du curseur par le mainframe
    if (0 != LTRFPOS.length)
    {
      if (0 != NURFPSJ.length)
      {
        tmp="document.forms[0]."+LTRFPOS+NURFPSI+"_"+NURFPSJ;
      }
      else
      {
        tmp="document.forms[0]."+LTRFPOS+NURFPSI;
      }
      zone = eval(tmp);
      if (zone==null || zone.type==undefined) // pour les radio boutons
      {
        if (0 != NURFPSJ.length)
        {
          tmp="document.forms[0]."+LTRFPOS+NURFPSI+"["+(NURFPSJ-1)+"]";
        }
        else
        {
        	if (0 != NURFPSI.length){
          	tmp="document.forms[0]."+LTRFPOS+"["+(NURFPSI-1)+"]";
          }
          else
          {
          	tmp="document.forms[0]."+LTRFPOS+"[0]";
          }
        }
        zone = eval(tmp);
      }
      zone.select();
    }
    else //positionnement du curseur par defaut sur le 1° element
    {
      for(i=0;i<document.forms[0].length;i++)
          {
            if ((document.forms[0].elements[i].type == "text")&& (!document.forms[0].elements[i].getAttribute("disabled")) && (!document.forms[0].elements[i].getAttribute("readonly"))&& (document.forms[0].elements[i].style.display!='none'))
            {
              document.forms[0].elements[i].focus();
              document.forms[0].elements[i].select();
              break;
            }
          }
    }
  }


}

/****************************************************************************/
/* f_chgLg(aLg) */
/****************************************************************************/
/* Change la langue de consultation du site tout en restant sur la même page
 * IN : aLg = Id Nouvelle langue du site
 * 			aCdoptrn = code operation de la transaction à rappeler
 */

function f_chgLg(aLg, aCdoptrn){
	if(document.location.pathname == '/mf.go'){
		document.location.href = '/index.go?q_lg=' + aLg;
		return;
	}else if(document.location.pathname == '/product.go'){
		f_goPg(getQueryStringVal('pg'), aLg);
		return;
	}else if(document.location.pathname == '/index.go'){
		document.location.href = '/index.go?q_lg=' + aLg;
		return;
	}else if(document.location.pathname == '/snd.go'){
		document.location.href = '/snd.go?pg=ETIF010&pageEnCours=0&q_lg=' + aLg;
		return;
	}else if(document.location.pathname == '/fr/hs/Particuliers/Epargner_et_investir/Aide_pour_choisir.htm'){
		document.location.href = '/nl/hs/Particulieren/Sparen_en_beleggen/Hulp_bij_uw_keuze.htm';
		return;
	}else if(document.location.pathname == '/fr/hs/Particuliers/Epargner_et_investir/Aide_pour_choisir.htm#'){
		document.location.href = '/nl/hs/Particulieren/Sparen_en_beleggen/Hulp_bij_uw_keuze.htm';
		return;
	}else if(document.location.pathname == '/nl/hs/Particulieren/Sparen_en_beleggen/Hulp_bij_uw_keuze.htm'){
		document.location.href = '/fr/hs/Particuliers/Epargner_et_investir/Aide_pour_choisir.htm';
		return;
	}else if(document.location.pathname == '/nl/hs/Particulieren/Sparen_en_beleggen/Hulp_bij_uw_keuze.htm#'){
		document.location.href = '/fr/hs/Particuliers/Epargner_et_investir/Aide_pour_choisir.htm';
		return;
	}else if(document.location.pathname == '/vsnd.go'){
		document.location.href = '/vsnd.go?pg=ETIF010&pageEnCours=0&q_lg=' + aLg;
		return;
	}else if(document.location.pathname == '/vsnd.go'){
		document.location.href = '/index.go?q_lg=' + aLg;
		return;
	}else if(document.location.pathname == '/vsnd2.go'){
		document.location.href = '/index.go?q_lg=' + aLg;
		return;

	}else{
		var urlToGo = document.location.href;

		if(urlToGo.indexOf('?') > 0){
			if(urlToGo.indexOf('q_lg=') > 0){
				urlToGo = urlToGo.substr(0, urlToGo.indexOf('q_lg=') + 5) + aLg + urlToGo.substr(urlToGo.indexOf('q_lg=') + 6);
			}else{
				if(urlToGo.indexOf('#') > 0){
					urlToGo = urlToGo.substr(0, urlToGo.indexOf('#')) + '&q_lg=' + aLg + urlToGo.substr(urlToGo.indexOf('#'));
				}else{
					urlToGo = urlToGo + '&q_lg=' + aLg;
				}
			}
		}else{
			urlToGo = urlToGo + '?q_lg=' + aLg;
		}
		document.location.href = urlToGo;
		return;
	}
}


/****************************************************************************/
/* f_popCall(respquest, origine, aLg, aUser, aSq) */
/****************************************************************************/
/* Ouvre une fenêtre de CallBack (Now or Later)
 * IN : respquest = badge du destinataire du message
 * 			origine = page d'origine du call
 *			aLg = langue de navigation
 *			aUser = id utilisateur
 *			aSq	= séquence de l'utilisateur
 */

function f_popCall(respquest, origine, aLg, aUser, aSq){
  var options="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes";
  var top=100;
  var left=150;

  if (origine.substring(0,3)=='CMN')
    {
      callCDOPTRN='S2ICN';
    }
  else
    {
      callCDOPTRN='S2ICL';
    }
  var loc = "/initMF.go?IMSTRAN=WSM328&CDEMID=1&CDOPTRN=SMINT&CLE=&CDLGTRN=" + aLg + "&aIMSTRAN=WS1096&aCDOPTRN="+callCDOPTRN+"&NOIDUSR=" + aUser + "&NOSQUSR=" + aSq + "&recall=Y&respquest=" + respquest + "&origine=" + origine + "&popCall=1";

  window.open(loc, "CallNow", "top="+top+",left="+left+",width=680,height=566,"+options);
}


/****************************************************************************/
/* f_search() */
/****************************************************************************/
/* Lance le moteur de recherche sauf si la valeur entrée est un kernel connu (goPg)
 */

function f_search(){
	knownKernels = new Array('A2', 'BQ', 'CP', 'CT', 'D5', 'EC', 'EE', 'ET', 'IB', 'IF', 'ME', 'PR', 'SC', 'T1', 'VI');
	var firstIsKnown = false;
	var secndIsKnown = false;
	var firstKrn;
	var secndKrn;

	if(document.form_search.topic.value.length == 7){
		firstKrn = document.form_search.topic.value.substr(0,2).toUpperCase();
		secndKrn = document.form_search.topic.value.substr(2,2).toUpperCase();

		for(i=0; i < knownKernels.length; i++){
			if(firstKrn == knownKernels[i]){
				firstIsKnown = true;
			}
			if(secndKrn == knownKernels[i]){
				secndIsKnown = true;
			}
		}
	}

	if(firstIsKnown && secndIsKnown){
		f_goPg(document.form_search.topic.value.toUpperCase());
	}else{
		document.form_search.action = '/search.go';
		document.form_search.submit();
	}
}

/****************************************************************************/
/* f_sofisk(aUrl) */
/****************************************************************************/
/* Ouvre la popup de calcul des impots
 */

 function f_sofisk(aUrl){
    var options="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes";
    var top=100;
    var left=100;
    xyz=window.open(aUrl,"Sofisk","top="+top+",left="+left+",width=830,height=528,"+options);
  }

/****************************************************************************/
/* f_myLogin(aLg) */
/****************************************************************************/
/* Ouvre la popup de demande de login myEthias
 */

 function f_myLogin(aLg){
    var options="width=600,height=350,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes";
    var top=100;
    var left=100;
    xyz=window.open("/mf.go?IMSTRAN=WS1098&CDEMID=1&CDOPTRN=S2VAF&CLE=&CDLGTRN="+aLg+"&CDLGPAG="+aLg+"&CDENTREE=N&pg=MEIF010","myLogin",options);
  }

/****************************************************************************/
/* f_myMdp(aLg) */
/****************************************************************************/
/* Ouvre la popup de demande de mot de passe myEthias
 */

 function f_myMdp(aLg,aNOIDAFF){
    var options="width=600,height=415,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes";
    var top=100;
    var left=100;
    xyz=window.open("/mf.go?IMSTRAN=WS1098&CDEMID=1&CDOPTRN=S2CPW&CLE=&CDLGTRN="+aLg+"&CDLGPAG="+aLg+"&CDENTREE=N&NOIDAFF="+aNOIDAFF+"&pg=MEIF010","myMdp",options);
  }

/****************************************************************************/
/* f_popDemoMyEt(aLg) */
/****************************************************************************/
/* Ouvre le popup de demo myEthias
 */

 function f_popDemoMyEt(aLg){
      	windowFeatures = 'width=800,height=600,top=150,left=200,screenX=0,screenY=0,scrollbars';
				windowName     = 'windowDemo';
				windowUrl      = 'http://www.ethias.be/upload/demo/demoFR.swf';
				if (aLg=='2'){ windowUrl      = 'http://www.ethias.be/upload/demo/demoNL.swf'; } 
				windowPreviewNWL = window.open(windowUrl, windowName, windowFeatures);
      }


/****************************************************************************/
/* f_open(aUrl, aOptions) */
/****************************************************************************/
/* Ouvre une popup avec options
 */

 function f_open(aUrl, aOptions){
 		var top=100;
    var left=100;
    xyz=window.open(aUrl,"newW",aOptions);
 	}

/****************************************************************************/
/* f_forgetMdp(aLg) */
/****************************************************************************/
/* Ouvre la popup d'oubli de mot de passe MyEthias
 */

 function f_forgetMdp(aLg){
    var options="width=600,height=415,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes";
    var top=100;
    var left=100;
    //xyz=window.open("/stc/MEIFFMP.go?pg=MEIFFMP&q_lg=" + aLg,"ForgetMdp2",options);
    switch (aLg) {
  		case '1' :
  			xyz=window.open("/mf.go?IMSTRAN=WS1098&CDEMID=1&CDOPTRN=S2OPW&CDLGTRN=F&pg=MEIFFMP&q_lg=" + aLg,"ForgetMdp",options);
  			break;
  		case '2' :
  			xyz=window.open("/mf.go?IMSTRAN=WS1098&CDEMID=1&CDOPTRN=S2OPW&CDLGTRN=N&pg=MEIFFMP&q_lg=" + aLg,"ForgetMdp",options);
  			break;
  		default :
  		  xyz=window.open("/mf.go?IMSTRAN=WS1098&CDEMID=1&CDOPTRN=S2OPW&CDLGTRN=F&pg=MEIFFMP&q_lg=1","ForgetMdp",options);
  			break;
  	}
  }