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;
import com.edeal.frontline.services.cti.CTIServiceClient;
import com.edeal.frontline.services.FlServiceClient;
import com.edeal.frontline.services.FlServiceException;

public final class cti_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_005fwebapp_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_005fwebapp_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_005fwebapp_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;

final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
	response.setContentType("application/x-javascript");
	FlRequest flRequest = new FlRequest(request);
	FlContext context = flRequest.getContext();
	DataDictionary dico = context.getDataDictionary();

	String strActID = (String)session.getAttribute("actorID");
	boolean actHasLic;
	try {
		actHasLic = ((Boolean)session.getAttribute("actorHasCTI")).booleanValue();
	} catch (Exception e) {
		actHasLic = context.getLicenceManager().actorHasSoftware(strActID, CTIServiceClient.CTI_LIC_CODE, LicenceManager.LicenceType.PermanentLicence, null);
	}	
	
	//if CTI is activated, the CTI window will pop up.
	//if not, it is hidden in the main frameset and the ActiveX control should not be loaded.
	boolean activateCTI = false;
	CTIServiceClient cti = null;
	try {
		cti = (CTIServiceClient)context.getServiceManager().getServiceClient(session, "CTI");
		activateCTI = (cti != null);
	} catch (final FlServiceException flse) {
	}
	
	boolean isDoCTIWindow = false;
	if (activateCTI) {
		try {
			isDoCTIWindow = !cti.useHideFrame();
		} catch(Exception e) {
		}
	}
      out.write("\n");
      out.write("\n");
      out.write("var useCtiWindow = ");
      out.print( isDoCTIWindow );
      out.write(";\n");
      out.write("function doCtiOnLoad() {\n");
      out.write("\t");
 if (activateCTI && actHasLic) { 
      out.write("\n");
      out.write("\t\tif (useCtiWindow) {\n");
      out.write("\t\t\tvar ctiWindow = window.open('','CTI');\n");
      out.write("\t\t\ttry { ctiWindow.doOnLoadCTI(true); } catch (error) {}\n");
      out.write("\t\t} else {\n");
      out.write("\t\t\tdoOnLoadCTI();\n");
      out.write("\t\t}\n");
      out.write("\t");
 } 
      out.write("\n");
      out.write("}\n");
      out.write("\n");
      out.write("function addInteraction(pPhone,pObj, pID){\t\n");
      out.write("\t\tvar strQuery = '&';\n");
      out.write("\t\n");
      out.write("\t\tif('Actor' == pObj) {\n");
      out.write("\t\t\tif(pID == '");
      out.print( strActID );
      out.write("') {\n");
      out.write("\t\t\t\tstrQuery += 'initIntActID=' + pID;\n");
      out.write("\t\t\t} else {\n");
      out.write("\t\t\t\tstrQuery += 'initIntActID=");
      out.print( strActID );
      out.write(";' + pID;\n");
      out.write("\t\t\t}\n");
      out.write("\t\t} else if('Person' == pObj) {\n");
      out.write("\t\t\tstrQuery += 'initIntPerID=' + pID;\n");
      out.write("\t\t\t\n");
      out.write("\t\t} \n");
      out.write("\t\telse if('Enterprise' == pObj) {\n");
      out.write("\t\t\tstrQuery += 'initIntEntID=' + pID;\n");
      out.write("\t\t} else if('Journalist' == pObj) {\n");
      out.write("\t\t\tstrQuery += 'initIntJouID=' + pID;\n");
      out.write("\t\t} else if('Support' == pObj) {\n");
      out.write("\t\t\tstrQuery += 'initIntSupID=' + pID;\n");
      out.write("\t\t} else if('Location' == pObj) {\n");
      out.write("\t\t\tstrQuery += 'initIntLocID=' + pID;\n");
      out.write("\t\t}else\n");
      out.write("\t\t{\n");
      out.write("\t\t\treturn;\n");
      out.write("\t\t}\n");
      out.write("\t\n");
      out.write("\t\tvar dt = new Date();\n");
      out.write("\n");
      out.write("\t\tstrQuery += '&initIntDate=' + flEscape((dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate()) + '/' + ((dt.getMonth() + 1) < 10 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1)) + '/' + dt.getFullYear());\n");
      out.write("\t\tstrQuery += '&initIntTimeBeg=' + flEscape((dt.getHours() < 10 ? '0' + dt.getHours() : dt.getHours()) + ':' + (dt.getMinutes() < 10 ? '0' + dt.getMinutes() : dt.getMinutes()));\n");
      out.write("\t\tstrQuery += '&initIntTimeEnd=';\n");
      out.write("\t\tstrQuery += '&initIntStiID=");
      out.print( dico.getRefIdByCode("IntStiID", "DONE") );
      out.write("';\n");
      out.write("\t\tstrQuery += '&initIntAtvID=");
      out.print( dico.getRefIdByCode("IntAtvID", "OUTPHONE") );
      out.write("';\n");
      out.write("\t\twindow.open('");
      if (_jspx_meth_fl_005fwebapp_005f0(_jspx_page_context))
        return;
      out.write("/create_interaction.fl?phone=' + flEscape(pPhone) + strQuery + '&done=1', 'InteractionFrom', 'menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=1024,height=768');\n");
      out.write("}\n");
      out.write("\n");
      out.write("function doCall(pPhone, pObj, pID) {\n");
      out.write("\tvar urlRandomizer = (new Date()).getTime();\n");
      out.write("\tdoAjax('");
      if (_jspx_meth_fl_005fwebapp_005f1(_jspx_page_context))
        return;
      out.write("/doCallCTI_ajax.fl?rand=' + urlRandomizer + '&arg0=' + flEscape(pPhone) + '&arg1=' + flEscape(pObj) + '&arg2=' + flEscape(pID));\n");
      out.write("}\n");
      out.write("\n");
      out.write("function doAnswer(pRef) {\n");
      out.write("\t");
 if (activateCTI && actHasLic) { 
      out.write("\n");
      out.write("\t\tif (useCtiWindow) {\n");
      out.write("\t\t\tvar ctiWindow = window.open('','CTI');\n");
      out.write("\t\t\ttry { ctiWindow.doAnswerCTI(pRef); } catch (error) {}\n");
      out.write("\t\t} else {\n");
      out.write("\t\t\tdoAnswerCTI(pRef);\n");
      out.write("\t\t}\n");
      out.write("\t");
 } 
      out.write("\n");
      out.write("}\n");
      out.write("\n");
      out.write("function doTransfer(pRef, pPhone) {\n");
      out.write("\tvar urlRandomizer = (new Date()).getTime();\n");
      out.write("\tdoAjax('");
      if (_jspx_meth_fl_005fwebapp_005f2(_jspx_page_context))
        return;
      out.write("/doTransferCTI_ajax.fl?rand=' + urlRandomizer + '&arg0=' + flEscape(pRef) + '&arg1=' + flEscape(pPhone));\n");
      out.write("}\n");
      out.write("function doChangeStatus(newState) {\n");
      out.write("\tvar urlRandomizer = (new Date()).getTime();\n");
      out.write("\tdoAjax('");
      if (_jspx_meth_fl_005fwebapp_005f3(_jspx_page_context))
        return;
      out.write("/doCTIChangeStatus_ajax.fl?rand=' + urlRandomizer + '&newState=' + newState);\n");
      out.write("}\n");
      out.write("\n");
      out.write("// Form transfer\n");
      out.write("//\tpRef : tel reference\n");
      out.write("//\tpPhone : someone to call\n");
      out.write("//\tpobjID : object id to associate\n");
      out.write("//\tpType : object type to associate\n");
      out.write("//\tpIsGroup : is this a group ? (escalation group team)\n");
      out.write("//\tpCallerPhone : the first caller phone number (the client).\n");
      out.write("function doTransferForm(pRef, pPhone, pobjID, pType, pIsGroup, pCallerPhone) {\n");
      out.write("\t//alert('doTransferForm : pobjID : '+pobjID);\n");
      out.write("\t//alert('doTransferForm : pType : '+pType);\n");
      out.write("\tvar urlRandomizer = (new Date()).getTime();\n");
      out.write("\t//alert('avant url ');\n");
      out.write("\tvar url = '");
      if (_jspx_meth_fl_005fwebapp_005f4(_jspx_page_context))
        return;
      out.write("/doTransferFormCTI_ajax.fl?rand=' +urlRandomizer + '&arg0=' + escape(pRef) + '&arg1=' + escape(pPhone);\n");
      out.write("\t//alert('url1 : '+url);\n");
      out.write("\turl += '&pType='+escape(pType)+'&pobjID='+escape(pobjID)+'&isGroup='+escape(pIsGroup)+'&callerPhone='+escape(pCallerPhone);\n");
      out.write("\t//alert('url : '+url);\n");
      out.write("\tdoAjax(url);\n");
      out.write("}");
    } 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_005fwebapp_005f0(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  fl:webapp
    com.edeal.frontline.WebappTag _jspx_th_fl_005fwebapp_005f0 = (com.edeal.frontline.WebappTag) _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.get(com.edeal.frontline.WebappTag.class);
    _jspx_th_fl_005fwebapp_005f0.setPageContext(_jspx_page_context);
    _jspx_th_fl_005fwebapp_005f0.setParent(null);
    int _jspx_eval_fl_005fwebapp_005f0 = _jspx_th_fl_005fwebapp_005f0.doStartTag();
    if (_jspx_th_fl_005fwebapp_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f0);
      return true;
    }
    _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f0);
    return false;
  }

  private boolean _jspx_meth_fl_005fwebapp_005f1(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  fl:webapp
    com.edeal.frontline.WebappTag _jspx_th_fl_005fwebapp_005f1 = (com.edeal.frontline.WebappTag) _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.get(com.edeal.frontline.WebappTag.class);
    _jspx_th_fl_005fwebapp_005f1.setPageContext(_jspx_page_context);
    _jspx_th_fl_005fwebapp_005f1.setParent(null);
    int _jspx_eval_fl_005fwebapp_005f1 = _jspx_th_fl_005fwebapp_005f1.doStartTag();
    if (_jspx_th_fl_005fwebapp_005f1.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f1);
      return true;
    }
    _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f1);
    return false;
  }

  private boolean _jspx_meth_fl_005fwebapp_005f2(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  fl:webapp
    com.edeal.frontline.WebappTag _jspx_th_fl_005fwebapp_005f2 = (com.edeal.frontline.WebappTag) _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.get(com.edeal.frontline.WebappTag.class);
    _jspx_th_fl_005fwebapp_005f2.setPageContext(_jspx_page_context);
    _jspx_th_fl_005fwebapp_005f2.setParent(null);
    int _jspx_eval_fl_005fwebapp_005f2 = _jspx_th_fl_005fwebapp_005f2.doStartTag();
    if (_jspx_th_fl_005fwebapp_005f2.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f2);
      return true;
    }
    _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f2);
    return false;
  }

  private boolean _jspx_meth_fl_005fwebapp_005f3(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  fl:webapp
    com.edeal.frontline.WebappTag _jspx_th_fl_005fwebapp_005f3 = (com.edeal.frontline.WebappTag) _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.get(com.edeal.frontline.WebappTag.class);
    _jspx_th_fl_005fwebapp_005f3.setPageContext(_jspx_page_context);
    _jspx_th_fl_005fwebapp_005f3.setParent(null);
    int _jspx_eval_fl_005fwebapp_005f3 = _jspx_th_fl_005fwebapp_005f3.doStartTag();
    if (_jspx_th_fl_005fwebapp_005f3.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f3);
      return true;
    }
    _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f3);
    return false;
  }

  private boolean _jspx_meth_fl_005fwebapp_005f4(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  fl:webapp
    com.edeal.frontline.WebappTag _jspx_th_fl_005fwebapp_005f4 = (com.edeal.frontline.WebappTag) _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.get(com.edeal.frontline.WebappTag.class);
    _jspx_th_fl_005fwebapp_005f4.setPageContext(_jspx_page_context);
    _jspx_th_fl_005fwebapp_005f4.setParent(null);
    int _jspx_eval_fl_005fwebapp_005f4 = _jspx_th_fl_005fwebapp_005f4.doStartTag();
    if (_jspx_th_fl_005fwebapp_005f4.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f4);
      return true;
    }
    _005fjspx_005ftagPool_005ffl_005fwebapp_005fnobody.reuse(_jspx_th_fl_005fwebapp_005f4);
    return false;
  }
}
