package org.apache.jsp.js;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import com.edeal.frontline.*;
import java.util.*;
import com.edeal.frontline.navigation.FlRequest;

public final class format_005ftel_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  static {
    _jspx_dependants = new java.util.ArrayList(1);
    _jspx_dependants.add("/WEB-INF/taglib.tld");
  }

  private org.apache.jasper.runtime.TagHandlerPool _005fjspx_005ftagPool_005ffl_005fcacheControl_0026_005fdelay_005fnobody;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _005fjspx_005ftagPool_005ffl_005fcacheControl_0026_005fdelay_005fnobody = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
    _005fjspx_005ftagPool_005ffl_005fcacheControl_0026_005fdelay_005fnobody.release();
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;


/******************************************************************************
 * Copyright (c) 2000-2004 e-Deal
 *
 * e-Deal S.A.
 * 55 rue Brillat Savarin
 * 75013 Paris
 * France
 *
 * T: +33 (0)1 53 80 80 30
 * F: +33 (0)1 73 01 69 77
 * http://www.e-deal.com
 * 
 * La diffusion de ce code source sous quelque forme que ce soit sans
 * l'autorisation de E-DEAL est interdite.
 *
 * Vous êtes autorisés à modifier ce code source uniquement pour votre usage
 * propre et sous réserve que les mentions de copyright demeurent intactes.
 *
 * Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou
 * implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour
 * responsable des dommages pouvant résulter de l'utilisation de ce code
 * source.
 *
 ******************************************************************************/

      out.write('\n');
 response.setContentType("application/x-javascript");
      out.write('\n');
      if (_jspx_meth_fl_005fcacheControl_005f0(_jspx_page_context))
        return;
      out.write('\n');

final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
FlRequest flRequest = new FlRequest(request);
FlContext context = flRequest.getContext();
DataDictionary dico = context.getDataDictionary();
String paysID="";
String formatTel="";
//le vecteur qui contient les id des pays
Vector vectid = dico.getRefList(session, "Ctr", "Te1", true);
//vecteur contient les id des pays et le format de tel dont ce dernier n'est pas nul
Vector vect = dico.getRefList(session, "Ctr","Te3");

for (int i=0;i < vect.size(); i++) {
	Vector curCtr = (Vector) vect.elementAt(i);
	String id = (String) curCtr.elementAt(0);
	String fTel = (String) curCtr.elementAt(1);
	paysID += (i > 0? ", " : "") + "\"" + id +"\"";
	formatTel += (i > 0? ", " : "") + "\"" + fTel +"\"";
}
for (int i=0;i < vectid.size(); i++)
     {  Vector curPays = (Vector) vectid.elementAt(i);
        String idP = (String) curPays.elementAt(0);
        //logger.debug("PAYS="+curPays);
        if (vectid.contains(idP)) {paysID = paysID;}
        else
        {

     	if(!"".equals(paysID)){
     		paysID += "," + "\"" + idP +"\"";
     		formatTel += "," + "\""+"\"";
     	}else {
     		paysID += "\"" + idP +"\"";
     		formatTel += "\""+"\"";
     	}
        }
     }

      out.write("\n");
      out.write("var lesPays = new Array(");
      out.print( paysID );
      out.write(");\n");
      out.write("var lesFormatsTel = new Array(");
      out.print( formatTel);
      out.write(");\n");
      out.write("var leTelOrigOuverture = '';\n");
      out.write("var lePaysOuverture = '';\n");
      out.write("\n");
      out.write("function doEpurePhone(phone) {\n");
      out.write("\tepure = \"\";\n");
      out.write("\tfor (i=0 ; i<phone.length ; i++) {\n");
      out.write("\t\tif (phone.substring(i,i+1) >= \"0\" && phone.substring(i,i+1) <= \"9\") {\n");
      out.write("\t\t\tepure += phone.substring(i,i+1);\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\treturn epure;\n");
      out.write("}\n");
      out.write("\n");
      out.write("function doEpurePhone2(phone) {\n");
      out.write("\tepure = \"\";\n");
      out.write("\tfor (i=0 ; i<phone.length ; i++) {\n");
      out.write("\t\tif (phone.substring(i,i+1) >= \"0\" && phone.substring(i,i+1) <= \"9\") {\n");
      out.write("\t\t\tepure += phone.substring(i,i+1);\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\t\n");
      out.write("\tif (epure.length > 10) {\n");
      out.write("\t\tepure = '0' + epure.substring(epure.length - 9,epure.length);\n");
      out.write("\t}\n");
      out.write("\t\n");
      out.write("\treturn epure;\n");
      out.write("}\n");
      out.write("\n");
      out.write("function formatMasque(masque, entree) {\n");
      out.write("\t// si pas de masque ou entree vide on rend ce qui est rentre\n");
      out.write("\tif (masque == \"\" || entree == \"\") {\n");
      out.write("\t\treturn entree;\n");
      out.write("\t}\n");
      out.write("\t// Si conforme au masque en rend l'entree\n");
      out.write("\tif (masque.length == entree.length) {\n");
      out.write("\t\tk=i=0;\n");
      out.write("\t\twhile (k==0 && i < masque.length) {\n");
      out.write("\t\t\tif ((masque.substring(i,i+1) != entree.substring(i,i+1)) && (masque.substring(i,i+1) != \"?\")) {\n");
      out.write("\t\t\t\tk=1;\n");
      out.write("\t\t\t} else {\n");
      out.write("\t\t\t\ti++;\n");
      out.write("\t\t\t}\n");
      out.write("\t\t}\n");
      out.write("\t\tif (k==0) {\n");
      out.write("\t\t\treturn entree;\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\t// on compte le nbr de ? dans le masque\n");
      out.write("\tfor (cpt=i=0 ; i < masque.length ; i++) {\n");
      out.write("\t\tif (masque.substring(i,i+1) == \"?\") {\n");
      out.write("\t\t\tcpt++;\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\t// on extrait les chiffres de la saisie\n");
      out.write("\tepure = \"\";\n");
      out.write("\tfor (i=0 ; i < entree.length ; i++) {\n");
      out.write("\t\tif (entree.substring(i,i+1) >= \"0\" && entree.substring(i,i+1) <= \"9\") {\n");
      out.write("\t\t\tepure += entree.substring(i,i+1);\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\t\n");
      out.write("\t// Si le nbr de ? different du nbr de chiffres dans l'entree en rend null\n");
      out.write("\tif (epure.length != cpt) {\n");
      out.write("\t\tres = \"Erreur:\" + cpt.toString();\n");
      out.write("\t\treturn res;\n");
      out.write("\t}\n");
      out.write("\t//on recupere le resultat\n");
      out.write("\tresult = \"\";\n");
      out.write("\tj = 0;\n");
      out.write("\tfor (i=0 ; i < masque.length ; i++) {\n");
      out.write("\t\tif (masque.substring(i,i+1) == \"?\") {\n");
      out.write("\t\t\tresult += epure.substring(j,j+1);\n");
      out.write("\t\t\tj++;\n");
      out.write("\t\t} else {\n");
      out.write("\t\t\tresult += masque.substring(i,i+1);\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\treturn result;\n");
      out.write("}\n");
      out.write("\n");
      out.write("function doFormatTel(leChamp , leMsg, leChampPays) {\n");
      out.write("\tif (!leChampPays) {\n");
      out.write("\t\treturn;\n");
      out.write("\t}\n");
      out.write("\tif (leChampPays.options) {\n");
      out.write("\t\tnomPays = leChampPays.options[leChampPays.selectedIndex].value;\n");
      out.write("\t} else {\n");
      out.write("\t\tnomPays = leChampPays.value;\n");
      out.write("\t}\n");
      out.write("\tif (!nomPays || nomPays == '') {\n");
      out.write("\t\treturn;\n");
      out.write("\t}\n");
      out.write("\tvar posPays = 0;\n");
      out.write("\t\n");
      out.write("\t//alert('nomPays ' + nomPays);\n");
      out.write("\t\n");
      out.write("\twhile ((posPays < lesPays.length) && (lesPays[posPays] != nomPays)) {\n");
      out.write("\t\tposPays++;\n");
      out.write("\t}\n");
      out.write("\tif(posPays < lesPays.length) {\n");
      out.write("\t\tmasque = lesFormatsTel[posPays];\n");
      out.write("\t\t//alert('masque ' + masque);\n");
      out.write("\t\t//alert('leChamp.value ' + leChamp.value);\n");
      out.write("\t\tres = formatMasque(masque , leChamp.value);\n");
      out.write("\t\t//alert('res ' + res);\n");
      out.write("\t\tif (res.indexOf(\"Erreur:\") != -1) {\n");
      out.write("\t\t\twindow.status = leMsg + \" Vous devez entrer \" + res.substring(7, res.length) + \" chiffres.\";\n");
      out.write("\t\t\talert(leMsg + \" Vous devez entrer \" + res.substring(7, res.length) + \" chiffres.\");\n");
      out.write("\t\t\treturn false;\n");
      out.write("\t\t} else {\n");
      out.write("\t\t\tleChamp.value = res;\n");
      out.write("\t\t\twindow.status = \"\";\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("}\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("function doFormatTel_(leChamp , leMsg, leChampPaysVal) {\n");
      out.write("debugger;\n");
      out.write("\tif (!leChampPaysVal) {\n");
      out.write("\t\treturn;\n");
      out.write("\t}\n");
      out.write("\tnomPays = leChampPaysVal;\n");
      out.write("\tif (!nomPays || nomPays == '') {\n");
      out.write("\t\treturn;\n");
      out.write("\t}\n");
      out.write("\tvar posPays = 0;\n");
      out.write("\t\n");
      out.write("\t\n");
      out.write("\twhile ((posPays < lesPays.length) && (lesPays[posPays] != nomPays)) {\n");
      out.write("\t\tposPays++;\n");
      out.write("\t}\n");
      out.write("\tif(posPays < lesPays.length) {\n");
      out.write("\t\tmasque = lesFormatsTel[posPays];\n");
      out.write("\t\tres = formatMasque(masque , leChamp.value);\n");
      out.write("\t\tif (res.indexOf(\"Erreur:\") != -1) {\n");
      out.write("\t\t\twindow.status = leMsg + \" Vous devez entrer \" + res.substring(7, res.length) + \" chiffres.\";\n");
      out.write("\t\t\talert(leMsg + \" Vous devez entrer \" + res.substring(7, res.length) + \" chiffres.\");\n");
      out.write("\t\t\tleChamp.style = \"background-color: #FDCBCC;\"\n");
      out.write("\t\t\tleChamp.value = '';\n");
      out.write("\t\t\treturn false;\n");
      out.write("\t\t} else {\n");
      out.write("\t\t\tleChamp.style.backgroundColor = \"\"\n");
      out.write("\t\t\tleChamp.value = res;\n");
      out.write("\t\t\twindow.status = \"\";\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("}\n");
      out.write("\n");
      out.write("function getTelEpure(masque , entree) {\n");
      out.write("\t// on extrait les chiffres de la saisie\n");
      out.write("\tvar epure = \"\";\n");
      out.write("\tfor (i=0 ; i < entree.length ; i++) {\n");
      out.write("\t\tvar digit = entree.substring(i, i+1);\n");
      out.write("\t\tif (digit >= \"0\" && digit <= \"9\") {\n");
      out.write("\t\t\tepure += digit;\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\t// si pas de masque on rend le tel epure\n");
      out.write("\tif (masque == \"\") {\n");
      out.write("\t\treturn epure;\n");
      out.write("\t}\n");
      out.write("\t// Si non conforme au masque en rend le tel epure\n");
      out.write("\tif (masque.length == entree.length) {\n");
      out.write("\t\tk = i = 0;\n");
      out.write("\t\twhile (k == 0 && i < masque.length) {\n");
      out.write("\t\t\tif ((masque.substring(i,i+1) != entree.substring(i,i+1)) && (masque.substring(i,i+1) != \"?\")) {\n");
      out.write("\t\t\t\tk=1;\n");
      out.write("\t\t\t} else {\n");
      out.write("\t\t\t\ti++;\n");
      out.write("\t\t\t}\n");
      out.write("\t\t}\n");
      out.write("\t\tif (k != 0) {\n");
      out.write("\t\t\treturn epure;\n");
      out.write("\t\t}\n");
      out.write("\t} else {\n");
      out.write("\t\treturn epure;\n");
      out.write("\t}\n");
      out.write("\t// tel conforme au masque :\n");
      out.write("\tvar res = \"\";\n");
      out.write("\tfor (i = 0 ; i < masque.length ; i++) {\n");
      out.write("\t\tif (masque.substring(i,i+1) == \"?\") {\n");
      out.write("\t\t\tres += entree.substring(i,i+1);\n");
      out.write("\t\t}\n");
      out.write("\t}\n");
      out.write("\treturn res;\n");
      out.write("}\n");
      out.write("\n");
      out.write("function doEpureTel(leChamp , leChampOrig, leChampPays) {\n");
      out.write("\tif (!leChampPays) {\n");
      out.write("\t\treturn;\n");
      out.write("\t}\n");
      out.write("\tif (leChampPays.options) {\n");
      out.write("\t\tnomPays = leChampPays.options[leChampPays.selectedIndex].value;\n");
      out.write("\t} else {\n");
      out.write("\t\tnomPays = leChampPays.value;\n");
      out.write("\t}\n");
      out.write("\tif (!nomPays || nomPays == '') {\n");
      out.write("\t\treturn;\n");
      out.write("\t}\n");
      out.write("\tvar posPays = 0;\n");
      out.write("\tif (nomPays != \"\" ) {\n");
      out.write("\t\twhile ((posPays < lesPays.length) && (lesPays[posPays] != nomPays)) {\n");
      out.write("\t\t\tposPays++;\n");
      out.write("\t\t}\n");
      out.write("\t\tmasque = lesFormatsTel[posPays];\n");
      out.write("\t\tleChampOrig.value = getTelEpure(masque , leChamp.value);\n");
      out.write("\t}\n");
      out.write("}\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }

  private boolean _jspx_meth_fl_005fcacheControl_005f0(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  fl:cacheControl
    com.edeal.frontline.navigation.CacheControlTag _jspx_th_fl_005fcacheControl_005f0 = (com.edeal.frontline.navigation.CacheControlTag) _005fjspx_005ftagPool_005ffl_005fcacheControl_0026_005fdelay_005fnobody.get(com.edeal.frontline.navigation.CacheControlTag.class);
    _jspx_th_fl_005fcacheControl_005f0.setPageContext(_jspx_page_context);
    _jspx_th_fl_005fcacheControl_005f0.setParent(null);
    // /js/format_tel.jsp(28,0) name = delay type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_fl_005fcacheControl_005f0.setDelay("0");
    int _jspx_eval_fl_005fcacheControl_005f0 = _jspx_th_fl_005fcacheControl_005f0.doStartTag();
    if (_jspx_th_fl_005fcacheControl_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      _005fjspx_005ftagPool_005ffl_005fcacheControl_0026_005fdelay_005fnobody.reuse(_jspx_th_fl_005fcacheControl_005f0);
      return true;
    }
    _005fjspx_005ftagPool_005ffl_005fcacheControl_0026_005fdelay_005fnobody.reuse(_jspx_th_fl_005fcacheControl_005f0);
    return false;
  }
}
