package zr.zrpower.analyseengine.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import zr.zrpower.entity.sys.SessionUser;
import zr.zrpower.analyseengine.service.StatisticsControl;
import zr.zrpower.analyseengine.mode.ANALYSE_STATISTICS_MAIN;
import zr.zrpower.ejb.sys.UIService;
import zr.zrpower.analyseengine.Request;

public class StatisticsEngine
    extends HttpServlet {


  //Initialize global variables
  public void init() throws ServletException {
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
      response.setContentType("text/html; charset=GBK");
      request.setCharacterEncoding("GBK");

      Request rq = null;
      try {
         rq = new Request();
         rq.fullItem(request);
      }
      catch (Exception ex) {
         response.getWriter().print(
          "<p>rq = new Request()发生异常！</p><p>详细错误信息:</p><p>" +
          ex.toString() + "</p>");
      }

      String strResult = "";
      String ID = request.getParameter("ID");
      if (ID == null) {
          ID = "";
      }
      String SHOWTITLE = request.getParameter("SHOWTITLE");
      if (SHOWTITLE == null) {SHOWTITLE = "";}

      String P1 = request.getParameter("P1");
      if (P1 == null) {
          P1 ="";
      }
      String P2 = request.getParameter("P2");
      if (P2 == null) {
          P1 ="";
      }
      String P3 = request.getParameter("P3");
      if (P3 == null) {
          P3 ="";
      }
      String P4 = request.getParameter("P4");
      if (P4 == null) {
          P4 ="";
      }
      String P5 = request.getParameter("P5");
      if (P5 == null) {
          P5 ="";
      }
      String TYPE = request.getParameter("TYPE");
      if (TYPE == null) {
          TYPE ="";
      }
      //调用报表的用户类别 0 按用户的行政区划权限 1 部门领导 2 普通员工
      String USERTYPE = request.getParameter("USERTYPE");
      if (USERTYPE == null) {
          USERTYPE ="2";
      }

      try {
           StatisticsControl SControl = new StatisticsControl();
           HttpSession session = request.getSession(true);
           SessionUser user = (SessionUser) session.getAttribute("userinfo");

           ANALYSE_STATISTICS_MAIN Smain = null;
           Smain = SControl.GetSmain(ID);



           //生成页面------------------
           strResult = GetTemplateStr(ID,P1,P2,P3,P4,P5,SControl,user,Smain,rq,TYPE,USERTYPE,SHOWTITLE);

           if (strResult.equals("SINPUTPAGE"))
           {
               //转到自定义页面-------------
               response.sendRedirect(Smain.getSINPUTPAGE()+"?ID="+ID+"&P1="+P1+"&P2="+P2+"&P3="+P3+"&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE);
           }else
           {
               //显示页面
               response.getWriter().print(strResult);
           }
           SControl = null;
           user = null;
           Smain = null;
      }
      catch (Exception ex) {
          response.getWriter().print("<p>发生异常！</p><p>详细错误信息:</p><p>" + ex.toString() + "</p>");
      }
  }

  //Process the HTTP Post request
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
    doGet(request, response);
  }

  //Clean up resources
  public void destroy() {
  }

  private String GetTemplateStr(String ID,String P1,String P2,String P3,String P4,String P5,StatisticsControl SControl,SessionUser user,ANALYSE_STATISTICS_MAIN Smain,Request rq,String TYPE,String USERTYPE,String SHOWTITLE) {
  StringBuffer sb = new StringBuffer();
  String strConn ="";
  try {
       UIService  userUI = new UIService();
       String sTMP = "";
       sb.append("<HTML>");
       sb.append("<HEAD>");
       sb.append("<TITLE></TITLE>");
       sb.append("<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">");
       sb.append("<META http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\">");
       sb.append("<LINK type=\"text/css\" rel=\"stylesheet\" href=\"zrsysmanage/css/" + user.getUserCSS() + "\">");
       if("html5.css".equals(user.getUserCSS())){//class="bordered"
    	   sb.append("<LINK type=\"text/css\" rel=\"stylesheet\" href=\"zrsysmanage/html5/css/style_tables.css\">");
       }
       sb.append("<LINK type=\"text/css\" rel=\"stylesheet\" href=\"ZrAnalyseEngine/js/calendar-win2k-cold-1.css\">");
       sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"zrsysmanage/script/Public.js\"  type=\"text/jscript\" ></SCRIPT>");
       sb.append("<SCRIPT LANGUAGE=Javascript TYPE=\"text/javascript\" src=\"ZrAnalyseEngine/js/coll.js\"></SCRIPT>");
       sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"ZrAnalyseEngine/js/calendar.js\"  type=\"text/jscript\" ></SCRIPT>");
       sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"ZrAnalyseEngine/js/calendar-zh.js\"  type=\"text/jscript\" ></SCRIPT>");
       sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"ZrAnalyseEngine/js/calendar-setup.js\"  type=\"text/jscript\" ></SCRIPT>");
       sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"ZrAnalyseEngine/js/QueryEngine.js\"  type=\"text/jscript\" ></SCRIPT>");
       sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"ZrAnalyseEngine/js/PrintFuncs.js\"  type=\"text/jscript\" ></SCRIPT>");

     //04-25======================================================================
       if("html5.css".equals(user.getUserCSS())){
    	   sb.append("<script type=\"text/javascript\" src=\"zrsysmanage/html5/script/jquery-2.0.3.min.js\"></script>");
           sb.append("<script type=\"text/javascript\" src=\"zrsysmanage/html5/layer/layer.js\"></script>");
           sb.append("<script type=\"text/javascript\" src=\"ZrCollEngine/Datehtml5/laydate.dev.js\"></script>");
           sb.append("<script type=\"text/javascript\" src=\"zrsysmanage/html5/script/systype.js\"></script>");
       }



       sb.append("</HEAD>");
       sb.append("<BODY class=\"BodyMain\">");
       sb.append("<FORM name=\"recordfrm\" method=\"post\" Action=\"statisticsengine.do?ID="+ID+"&SHOWTITLE="+SHOWTITLE+"&TYPE=1\">");
       sb.append("<input type='hidden' name='isexp' value='0'>");

       //页面传递的参数
       if (ID != null) {
           sb.append("<input type=\"hidden\" name=\"ID\" value=\"" + ID + "\">");
       }
       if (P1 == null) {
           P1="";
       }
       if (P2 == null) {
           P2="";
       }
       if (P3 == null) {
           P3="";
       }
       if (P4 == null) {
           P4="";
       }
       if (P5 == null) {
           P5="";
       }
       if (USERTYPE == null) {
           USERTYPE="";
       }
       sb.append("<input type=\"hidden\" name=\"P1\" value=\"" + P1 + "\">");
       sb.append("<input type=\"hidden\" name=\"P2\" value=\"" + P2 + "\">");
       sb.append("<input type=\"hidden\" name=\"P3\" value=\"" + P3 + "\">");
       sb.append("<input type=\"hidden\" name=\"P4\" value=\"" + P4 + "\">");
       sb.append("<input type=\"hidden\" name=\"P5\" value=\"" + P5 + "\">");
       sb.append("<input type=\"hidden\" name=\"USERTYPE\" value=\"" + USERTYPE + "\">");

       //得到报表统计的自定义条件类型
       String strSINPUTTYPE = Smain.getSINPUTTYPE();
       //得到报表的显示类型(1一般报表 2 嵌入式报表)
       String strISSHOWTYPE = Smain.getISSHOWTYPE();
       //在网页上显示的表格模板
       String strTIMETEMPLATE = Smain.getTIMETEMPLATE();
       if (strTIMETEMPLATE==null){strTIMETEMPLATE="";}


       String strTbutton = "";
       strTbutton = Smain.getTBUTTON();
       if (strTbutton==null)
       {strTbutton="";}
       if (strTbutton.length()==0){strTbutton="统计";}

       //字典设置
       String CodeHtml = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\r\n";
       String CODETABLE = Smain.getCODETABLE();
       if (CODETABLE==null){CODETABLE="";}
       //生成下拉字典
       if (CODETABLE.length()>2)
       {CodeHtml = SControl.GetCodeHtml(CODETABLE);}

       sb.append("<input type=\"hidden\" name=\"SINPUTTYPE\" value=\"" + strSINPUTTYPE + "\">");

       if (!strISSHOWTYPE.equals("2")  && !SHOWTITLE.equals("0")){
         sb.append("<!--HTML Head表单头显示[显示内容,图标文件,用户肤色的图片文件夹]-->");
         sb.append(userUI.ShowHeadHtml(Smain.getSTATISTICSNAME(), "IcoTitle.gif",user.getUserImage()));
         sb.append("<!--HTML Body Start显示表单开始部分-->");
         sb.append(userUI.ShowBodyStartHtml());
       }
       sb.append(" <TABLE height=\"100%\" width=\"100%\" cellSpacing='0' >");

       //非嵌入式报表时加载按钮
       if (!strISSHOWTYPE.equals("2")){

       //报表统计的自定义条件类型
       if (!strSINPUTTYPE.equals("2") && !strSINPUTTYPE.equals("3") && !strSINPUTTYPE.equals("4") && !strSINPUTTYPE.equals("5") && !strSINPUTTYPE.equals("6") && !strSINPUTTYPE.equals("7") && !strSINPUTTYPE.equals("8") && !strSINPUTTYPE.equals("9") && !strSINPUTTYPE.equals("A")  && !strSINPUTTYPE.equals("B") && !strSINPUTTYPE.equals("C"))
       {
             sb.append("<TR Height=30><TD align='left'>");
             sb.append("<table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr>");
       }
       if (strSINPUTTYPE.equals("2"))//年、月、周、日、固定格式条件
       {
             sb.append("<TR><TD  valign=TOP>");
             sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
             sb.append("<legend>项目</legend>");
             sb.append(" <DIV   style='width:100%;height:40px;overflow:auto;'>");
             sb.append("<TABLE border='0' width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" valign=center>");
             sb.append("<TR><TD width=20%></TD><TD width=30%></TD><TD width=20%></TD><TD width=30%></TD></TR>");
             //加固定日期统计条件
             sb.append(SControl.GetDateHtml());
             sb.append("</TABLE>");
             sb.append("</DIV>");
             sb.append("</fieldset>");
             sb.append("</TD></TR>");

             sb.append("<TR Height=30><TD align='center'>");
             sb.append("<table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr align=\"center\">");
             sb.append(userUI.ClickButton1(strTbutton,"Statistics();","IcoStatistics.gif", user.getUserImage()));
       }
       if (strSINPUTTYPE.equals("3") || strSINPUTTYPE.equals("B"))//日报固定格式条件
       {
             sb.append("<TR><TD  valign=TOP>");
             sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
             sb.append("<legend>项目</legend>");
             sb.append(" <DIV   style='width:100%;height:40px;overflow:auto;'>");
             //加固定日期统计条件
             sTMP = SControl.GetDateDayHtml();
             if (CODETABLE.length()>2)
             {
                 sTMP = sTMP.replaceAll("width=\"750\"","width=\"850\"");
             }
             sb.append(sTMP);

             sb.append("<td>"+CodeHtml+"</td>");

             sb.append(userUI.ClickButton1(strTbutton,"Statistics1();","IcoStatistics.gif", user.getUserImage()));


             sb.append(userUI.ClickButton1("导出Excel", "expexcel()","buttonExcel.gif",user.getUserImage()));
             sb.append(userUI.ClickButton1("打印", "ExportPrint();","IcoPrint.gif", user.getUserImage()));



             sb.append("<td width='80'></td>\r\n");
             sb.append("</tr></table><br></DIV>");
             sb.append("</fieldset></tr>");


       }

       if (strSINPUTTYPE.equals("9"))//年报固定格式条件
       {
             sb.append("<TR><TD  valign=TOP>");
             sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
             sb.append("<legend>项目</legend>");
             sb.append(" <DIV   style='width:100%;height:40px;overflow:auto;'>");
             //加固定日期统计条件
             sTMP = SControl.GetYearHtml();
             if (CODETABLE.length()>2)
             {
                 sTMP = sTMP.replaceAll("width=\"700\"","width=\"800\"");
             }

             sb.append(sTMP);
             sb.append("<td>"+CodeHtml+"</td>");

             sb.append(userUI.ClickButton1(strTbutton,"Statistics5();","IcoStatistics.gif", user.getUserImage()));

             sb.append(userUI.ClickButton1("导出Excel", "expexcel()","buttonExcel.gif",user.getUserImage()));
             sb.append(userUI.ClickButton1("打印", "ExportPrint();","IcoPrint.gif", user.getUserImage()));


             sb.append("<td width='80'></td>\r\n");
             sb.append("</tr></table><br></DIV>");
             sb.append("</fieldset></tr>");


       }

       if (strSINPUTTYPE.equals("A")  || strSINPUTTYPE.equals("C"))//月报固定格式条件
       {
             sb.append("<TR><TD  valign=TOP>");
             sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
             sb.append("<legend>项目</legend>");
             sb.append(" <DIV   style='width:100%;height:40px;overflow:auto;'>");
             //加固定日期统计条件
             sTMP = SControl.GetMonthHtml();
             if (CODETABLE.length()>2)
             {
                 sTMP = sTMP.replaceAll("width=\"700\"","width=\"800\"");
             }

             sb.append(sTMP);

             sb.append("<td>"+CodeHtml+"</td>");

             sb.append(userUI.ClickButton1(strTbutton,"Statistics6();","IcoStatistics.gif", user.getUserImage()));

             sb.append(userUI.ClickButton1("导出Excel", "expexcel()","buttonExcel.gif",user.getUserImage()));
             sb.append(userUI.ClickButton1("打印", "ExportPrint();","IcoPrint.gif", user.getUserImage()));


             sb.append("<td width='50'></td>\r\n");
             sb.append("</tr></table><br></DIV>");
             sb.append("</fieldset></tr>");


       }


       if (strSINPUTTYPE.equals("4"))//自定义条件
       {
             String SItem[] = SControl.CreateStatisticsItem(ID,rq,user);
             strConn = SControl.GetStatisticsItemConn(ID,rq,P1,P2,P3,P4,P5,user);

             String strSItem = SItem[0];
             int intItemNum = Integer.parseInt(SItem[1]);
             int height=60;
             if (intItemNum < 7) {
                  height = intItemNum * 23 + 7;
             }
             else {
                  height = 6 * 23 + 7;
             }

             sb.append("<TR><TD  valign=TOP>");
             sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
             sb.append("<legend>项目</legend>");
             sb.append(" <DIV   style='width:800;height:" + String.valueOf(height) +"px;overflow:auto;'>");
             sb.append("<TABLE border='0' width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" valign=center>");
             sb.append("<TR><TD width=20%></TD><TD width=30%></TD><TD width=20%></TD><TD width=30%></TD></TR>");
             //加统计条件

             sb.append(strSItem);
             sb.append("</TABLE>");
             sb.append("</DIV>");
             sb.append("</fieldset>");
             sb.append("</TD></TR>");

             sb.append("<TR Height=30><TD align='center'>");
             sb.append("<table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr align=\"center\">");
             sb.append(userUI.ClickButton1(strTbutton,"document.recordfrm.submit();","IcoStatistics.gif", user.getUserImage()));

       }
       if (strSINPUTTYPE.equals("5"))//自定义条件录入页面
       {
           return "SINPUTPAGE";
       }
       if (strSINPUTTYPE.equals("6"))//年份比较条件(统计年份比较时使用)
       {
           sb.append("<TR><TD  valign=TOP>");
           sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
           sb.append("<legend>项目</legend>");
           sb.append(" <DIV   style='width:100%;height:40px;overflow:auto;'>");
           //加年份比较条件
           sb.append(SControl.GetYearComHtml());
           sb.append("</DIV>");
           sb.append("</fieldset>");
           sb.append("</TD></TR>");

           sb.append("<TR Height=30><TD align='center'>");
           sb.append("<table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr align=\"center\">");
           sb.append(userUI.ClickButton1(strTbutton,"Statistics2();","IcoStatistics.gif", user.getUserImage()));

       }
       if (strSINPUTTYPE.equals("7"))//年份月份比较条件(统计年份月份比较时使用)
       {
           sb.append("<TR><TD  valign=TOP>");
           sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
           sb.append("<legend>项目</legend>");
           sb.append(" <DIV   style='width:100%;height:40px;overflow:auto;'>");
           //加年份月份比较条件
           sb.append(SControl.GetYearMonthComHtml());
           sb.append("</DIV>");
           sb.append("</fieldset>");
           sb.append("</TD></TR>");

           sb.append("<TR Height=30><TD align='center'>");
           sb.append("<table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr align=\"center\">");
           sb.append(userUI.ClickButton1(strTbutton,"Statistics3();","IcoStatistics.gif", user.getUserImage()));
       }
       if (strSINPUTTYPE.equals("8"))//年份季度比较条件(统计年份季度比较时使用)
       {
           sb.append("<TR><TD  valign=TOP>");
           sb.append("<fieldset style=\"width: 100%;display:''\" id=queryItem name=queryItem>");
           sb.append("<legend>项目</legend>");
           sb.append(" <DIV   style='width:100%;height:40px;overflow:auto;'>");
           //加年份季度比较条件
           sb.append(SControl.GetYearQuarterComHtml());
           sb.append("</DIV>");
           sb.append("</fieldset>");
           sb.append("</TD></TR>");

           sb.append("<TR Height=30><TD align='center'>");
           sb.append("<table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr align=\"center\">");
           sb.append(userUI.ClickButton1(strTbutton,"Statistics4();","IcoStatistics.gif", user.getUserImage()));
       }


        if (!strSINPUTTYPE.equals("3") && !strSINPUTTYPE.equals("9") && !strSINPUTTYPE.equals("A")  && !strSINPUTTYPE.equals("B") && !strSINPUTTYPE.equals("C")){

       sb.append(userUI.ClickButton1("导出Excel", "expexcel()","buttonExcel.gif",user.getUserImage()));
       sb.append(userUI.ClickButton1("打印", "ExportPrint();","IcoPrint.gif", user.getUserImage()));



       if (strSINPUTTYPE.equals("2") || strSINPUTTYPE.equals("3") || strSINPUTTYPE.equals("4") || strSINPUTTYPE.equals("6") || strSINPUTTYPE.equals("7") || strSINPUTTYPE.equals("8") || strSINPUTTYPE.equals("B") || strSINPUTTYPE.equals("C"))
       {
           if("html5.css".equals(user.getUserCSS())){

           }else{
        	   sb.append(userUI.ClickButton1("显示/隐藏", "document.all.queryItem.style.display=document.all.queryItem.style.display=='none'?'':'none';","buttonCancel.gif",user.getUserImage()));
           }
       }
       sb.append(" </tr></table>");
       sb.append("<br></TD></TR>");

       }else
       {
         sb.append("</TD></TR>");
       }



     }

       sb.append("<TR><TD height=\"100%\" valign=\"top\">");
       sb.append("<DIV style='width:0px;height:0px;display:none;'>");
       sb.append("<iframe id=computer name=computer src=\"statisticssubmitcompute.do\" border=0 frameborder=0 width=1 height=1></iframe>");
       sb.append("</DIV>");

       if (!strSINPUTTYPE.equals("2") && !strSINPUTTYPE.equals("3") && !strSINPUTTYPE.equals("4") && !strSINPUTTYPE.equals("5") && !strSINPUTTYPE.equals("6") && !strSINPUTTYPE.equals("7") && !strSINPUTTYPE.equals("8") && !strSINPUTTYPE.equals("9") && !strSINPUTTYPE.equals("A") && !strSINPUTTYPE.equals("B") && !strSINPUTTYPE.equals("C"))
       {
           if (strISSHOWTYPE.equals("2"))
           {
              sb.append("<iframe id=data name=data src=\"ZrAnalyseEngine/StatisticsShow/message2.jsp\" border=0 frameborder=0 width=100% height=100%></iframe>");
           }else
           {
        	  //var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
              sb.append("<iframe id=data name=data src=\"ZrAnalyseEngine/StatisticsShow/message1.jsp\" border=0 frameborder=0 width=100% height=100%></iframe>");
           }

       }else
       {
          sb.append("<iframe id=data name=data src=\"ZrAnalyseEngine/StatisticsShow/message.jsp\" border=0 frameborder=0 width=100% height=100%></iframe>");
       }

       sb.append("</TD></TR>");
       sb.append("</TABLE>");
       if (!strISSHOWTYPE.equals("2") && !strISSHOWTYPE.equals("3") && !strISSHOWTYPE.equals("6") && !strISSHOWTYPE.equals("7")){
         //表单结束部分
         sb.append(userUI.ShowFootHtml());
       }
       sb.append("</FORM>");
       //JS函数
       sb.append("<script language=\"javascript\">");
       if (!strSINPUTTYPE.equals("2") && !strSINPUTTYPE.equals("3") && !strSINPUTTYPE.equals("4") && !strSINPUTTYPE.equals("5") && !strSINPUTTYPE.equals("6") && !strSINPUTTYPE.equals("7") && !strSINPUTTYPE.equals("8") && !strSINPUTTYPE.equals("9") && !strSINPUTTYPE.equals("A") && !strSINPUTTYPE.equals("B") && !strSINPUTTYPE.equals("C"))
       {
           sb.append("setTimeout('computer();',300);");
       }
       if (strSINPUTTYPE.equals("4") && TYPE.equals("1"))
       {
           sb.append("setTimeout('computer1();',300);");
       }

       if (strSINPUTTYPE.equals("B"))
       {
           sb.append("setTimeout('timesub();',300);");
       }
       if (strSINPUTTYPE.equals("C"))
       {
           sb.append("setTimeout('timesub1();',300);");
       }


     //04-25========================================================
       if("html5.css".equals(user.getUserCSS())){
    	   //showCalendar
    	   sb.append("function showCalendar(fileid, DictTable){\r\n");
    	   sb.append("laydate({elem:'#'+fileid});\r\n");
    	   sb.append("}\r\n");
       }


       sb.append("function SetSelectValue(SelectId, DictTable){\r\n");
       //网页形式字典选择----------------
            sb.append("var mFileUrl =\"ZrCollEngine/selectDictPage.jsp?DictTable=\"+DictTable+\"&SelectId=\"+SelectId;\r\n");
            sb.append("var strValue=showModalDialog(mFileUrl,window,'status:no;help:no;dialogHeight:312px;dialogWidth:382px');\r\n");
            sb.append("if (strValue!=null){var arrTmp = strValue.split('/');\r\n");
            sb.append("document.getElementById(SelectId).options.length = 0;\r\n");
            sb.append("document.getElementById(SelectId).options[0] = new Option(arrTmp[1],arrTmp[0]);\r\n");
            sb.append("document.getElementById(SelectId).options[0].selected = true;\r\n");
            sb.append("document.getElementById(SelectId).options[0].className = 'selectlist';}\r\n");
        //网页形式-----------------

       sb.append("}\r\n");
       sb.append("function computer(){\r\n");
       sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1="+P1+"&P2="+P2+"&P3="+P3+"&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");
       sb.append("}\r\n");

       sb.append("function timesub(){\r\n");
       sb.append("var date1 = document.all('date1').value;\r\n");
       sb.append("date1 = date1.replace('-','/');\r\n");
       sb.append("var  a  =  new  Date(date1);\r\n");
       sb.append("a = a.valueOf();\r\n");
       sb.append("a = a - 1*24*60*60*1000;\r\n");
       sb.append("a = new Date(a);\r\n");
       sb.append("sm=a.getMonth()+1;\r\n");
       sb.append("sd=a.getDate();\r\n");

       sb.append("if ((a.getMonth()+1)<10){\r\n");
       sb.append("sm='0'+sm;\r\n");
       sb.append("}\r\n");

       sb.append("if (a.getDate()<10){\r\n");
       sb.append("sd='0'+sd;\r\n");
       sb.append("}\r\n");

       sb.append("var v1 =a.getFullYear()+'-'+sm+'-'+sd;\r\n");
       sb.append("document.all('date1').value = v1;\r\n");
       sb.append("}\r\n");



       sb.append("function timesub1(){\r\n");
       sb.append("var year = document.all('year1').value;\r\n");
       sb.append("var month = document.all('Month').value;\r\n");

       sb.append("var tdate = year+'/'+month+'/01';\r\n");
       sb.append("var  d  =  new  Date(tdate);\r\n");
       sb.append("var y = d.getYear();\r\n");
       sb.append("var m = d.getMonth()+1;\r\n");

       sb.append("if (m==1){\r\n");
       sb.append("y = y -1;\r\n");
       sb.append("m = 12;\r\n");
       sb.append("}else{\r\n");
       sb.append("m = m-1;\r\n");
       sb.append("}\r\n");

       sb.append("if (m<10){\r\n");
       sb.append("m = '0'+m;\r\n");
       sb.append("}\r\n");

       sb.append("document.all('year1').value=y;\r\n");
       sb.append("document.all('Month').value=m;\r\n");

       sb.append("}\r\n");



       sb.append("function computer1(){\r\n");
       if (strISSHOWTYPE.equals("2"))
       {
          sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message2.jsp';\r\n");
       }else
       {
          sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");
       }
       sb.append("document.computer.document.all('ID').value=\""+ID+"\";\r\n");
       sb.append("document.computer.document.all('P1').value=\""+P1+"\";\r\n");
       sb.append("document.computer.document.all('P2').value=\""+P2+"\";\r\n");
       sb.append("document.computer.document.all('P3').value=\""+P3+"\";\r\n");
       sb.append("document.computer.document.all('P4').value=\""+P4+"\";\r\n");
       sb.append("document.computer.document.all('P5').value=\""+P5+"\";\r\n");
       sb.append("document.computer.document.all('USERTYPE').value=\""+USERTYPE+"\";\r\n");
       sb.append("document.computer.document.all('CONN').value=\""+strConn+"\";\r\n");
       sb.append("document.computer.document.recordfrm.submit();\r\n");
       sb.append("}\r\n");

       //打印
       sb.append("function ExportPrint(){\r\n");
       sb.append("var isexp = document.all('isexp').value;\r\n");
       sb.append("if (isexp=='1'){\r\n");
       sb.append("if (document.data.location.href.indexOf('datashowtable.jsp')>-1){\r\n");
       sb.append("ZRPRINT=getZrprint();\r\n");
       sb.append("ZRPRINT.PRINT_INIT(\"报表打印\");\r\n");

       sb.append("var strBodyStyle='<style>table,td { border: 1 solid #000000;border-collapse:collapse;text-align: center }</style>';\r\n");
       sb.append("var strFormHtml=strBodyStyle+'<body>'+document.data.document.body.innerHTML+'</body>';\r\n");
       sb.append("ZRPRINT.ADD_PRINT_HTM(50,50,'96%','96%',strFormHtml);\r\n");

       sb.append("ZRPRINT.SET_PRINT_STYLEA(0,\"HOrient\",3);\r\n");
       sb.append("ZRPRINT.SET_PRINT_STYLEA(0,\"VOrient\",3);\r\n");
       sb.append("ZRPRINT.SET_SHOW_MODE(\"HIDE_PAPER_BOARD\",1);\r\n");
       sb.append("ZRPRINT.SET_SHOW_MODE(\"LANDSCAPE_DEFROTATED\",1);\r\n");
       sb.append("ZRPRINT.SET_SHOW_MODE(\"SHOW_SCALEBAR\",true);\r\n");

       sb.append("ZRPRINT.PREVIEW();\r\n");

       sb.append("}else{\r\n");
       sb.append("alert('请先生成报表！');}\r\n");
       sb.append("}else{\r\n");
       sb.append("alert('请先生成报表！');}\r\n");
       sb.append("}\r\n");

       //导出excel
       sb.append("function expexcel(){\r\n");
       sb.append("var isexp = document.all('isexp').value;");
       sb.append("if (isexp=='1'){");
       sb.append("var url='ZrAnalyseEngine/StatisticsShow/Excel.jsp?ID="+ID+"';\r\n");
       sb.append("var name='PopWindow';\r\n");
       sb.append("var ShowPopWindow = null;");
       sb.append("var status='toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=250';");
       sb.append("ShowPopWindow = window.open(url,name,status);");
       sb.append("ShowPopWindow.moveTo(280,200);");
       sb.append("ShowPopWindow.focus();");
       sb.append("}else{");
       sb.append("alert('请先生成报表！');}");
       sb.append("}\r\n");



       //生成统计报表
       sb.append("function Statistics(){\r\n");
       //得到报表类别
       sb.append("var type = '';\r\n");
       sb.append("radio1 = document.all(\"type\");\r\n");
       sb.append("for (i=0; i<radio1.length; i++){\r\n");
       sb.append("if (radio1.item(i).checked){\r\n");
       sb.append("type = radio1.item(i).value;\r\n");
       sb.append("break;}}\r\n");

       sb.append("var sdate = '';\r\n");
       sb.append("var edate = '';\r\n");
       sb.append("var year1 = document.all('year1').value;\r\n");
       sb.append("var Quarter = document.all('Quarter').value;\r\n");
       sb.append("var Month = document.all('Month').value;\r\n");
       sb.append("var Week = document.all('Week').value;\r\n");
       sb.append("var date1 = document.all('date1').value;\r\n");
       sb.append("var date2 = document.all('date2').value;\r\n");
       sb.append("var date3 = document.all('date3').value;\r\n");

       //年报
       sb.append("if (type=='1'){\r\n");
       sb.append("sdate = year1+'-01-01';\r\n");
       sb.append("edate = year1+'-12-31';\r\n");
       sb.append("}\r\n");
       //季度报
       sb.append("if (type=='2'){\r\n");
       sb.append("if (Quarter=='1'){\r\n");
       sb.append("sdate = year1+'-01-01';\r\n");
       sb.append("edate = year1+'-03-31';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter=='2'){\r\n");
       sb.append("sdate = year1+'-04-01';\r\n");
       sb.append("edate = year1+'-06-30';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter=='3'){\r\n");
       sb.append("sdate = year1+'-07-01';\r\n");
       sb.append("edate = year1+'-09-30';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter=='4'){\r\n");
       sb.append("sdate = year1+'-10-01';\r\n");
       sb.append("edate = year1+'-12-31';\r\n");
       sb.append("}\r\n");
       sb.append("}\r\n");
       //月报
       sb.append("if (type=='3'){\r\n");
       sb.append("if(Month=='01' || Month=='03' || Month=='05' || Month=='07' || Month=='08' || Month=='10' || Month=='12'){\r\n");
       sb.append("sdate = year1+'-'+Month+'-01';\r\n");
       sb.append("edate = year1+'-'+Month+'-31';\r\n");
       sb.append("}\r\n");
       sb.append("if(Month=='04' || Month=='06' || Month=='09' || Month=='11'){\r\n");
       sb.append("sdate = year1+'-'+Month+'-01';\r\n");
       sb.append("edate = year1+'-'+Month+'-30';\r\n");
       sb.append("}\r\n");
       sb.append("if(Month=='02' && RunNian(year1)==true){\r\n");
       sb.append("sdate = year1+'-'+Month+'-02';\r\n");
       sb.append("edate = year1+'-'+Month+'-29';\r\n");
       sb.append("}\r\n");
       sb.append("if(Month=='02' && RunNian(year1)==false){\r\n");
       sb.append("sdate = year1+'-'+Month+'-02';\r\n");
       sb.append("edate = year1+'-'+Month+'-28';\r\n");
       sb.append("}\r\n");

       sb.append("}\r\n");
       //周报
       sb.append("if (type=='4'){\r\n");
       sb.append("var d = new   Date(year1,0,1);\r\n");
       sb.append("d.setDate(parseInt('1065432'.charAt(d.getDay())) + Week * 7);\r\n");
       sb.append("var fe = getFirstAndEnd(d);\r\n");
       sb.append("sdate = fe.first.format('yyyy-MM-dd');\r\n");
       sb.append("edate = fe.end.format('yyyy-MM-dd');\r\n");
       sb.append("}\r\n");
       //日报
       sb.append("if (type=='5'){\r\n");
       sb.append("sdate = date1;\r\n");
       sb.append("edate = date1;\r\n");
       sb.append("}\r\n");
       //自定义日期
       sb.append("if (type=='6'){\r\n");
       sb.append("sdate = date2;\r\n");
       sb.append("edate = date3;\r\n");
       sb.append("}\r\n");

       //计算报表
       sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");
       sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+sdate+'&P2='+edate+'&P3="+P3+"&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");

       sb.append("document.all('P1').value=sdate;\r\n");
       sb.append("document.all('P2').value=edate;\r\n");

       sb.append("}\r\n");

       //生成统计报表(日报)
       sb.append("function Statistics1(){\r\n");
       sb.append("var date1 = document.all('date1').value;\r\n");
       if (CODETABLE.length()>0)
       {
          sb.append("var code = document.all('code').value;\r\n");
          sb.append("var name = \"\";\r\n");
          sb.append("var strs= new Array();\r\n");
          sb.append("var strs= code.split(\"/\");\r\n");
          sb.append("if (strs.length==2){");
          sb.append("code = strs[0];\r\n");
          sb.append("name = strs[1];\r\n");
          sb.append(";\r\n");
          sb.append("}");
       }
       //计算报表
       sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");
       if (CODETABLE.length()>0)
       {
          sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+date1+'&P2='+code+'&P3='+name+'&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");
       }else
       {

         sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+date1+'&P2="+P2+"&P3="+P3+"&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");

       }
       sb.append("document.all('P1').value=date1;\r\n");
       if (CODETABLE.length()>0)
       {
           sb.append("document.all('P2').value=code;\r\n");
           sb.append("document.all('P3').value=name;\r\n");
       }
       sb.append("}\r\n");

       //生成统计报表(年报)
       sb.append("function Statistics5(){\r\n");
       sb.append("var date1 = document.all('year1').value;\r\n");

       if (CODETABLE.length()>0)
       {
          sb.append("var code = document.all('code').value;\r\n");
          sb.append("var name = \"\";\r\n");
          sb.append("var strs= new Array();\r\n");
          sb.append("var strs= code.split(\"/\");\r\n");
          sb.append("if (strs.length==2){");
          sb.append("code = strs[0];\r\n");
          sb.append("name = strs[1];\r\n");
          sb.append(";\r\n");
          sb.append("}");
       }


       //计算报表
       sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");

       if (CODETABLE.length()>0)
       {
         sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+date1+'&P2='+code+'&P3='+name+'&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");

       }else
       {
         sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+date1+'&P2="+P2+"&P3="+P3+"&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");

       }


       sb.append("document.all('P1').value=date1;\r\n");
       if (CODETABLE.length()>0)
       {
           sb.append("document.all('P2').value=code;\r\n");
           sb.append("document.all('P3').value=name;\r\n");
       }

       sb.append("}\r\n");

       //生成统计报表(月报)
       sb.append("function Statistics6(){\r\n");
       sb.append("var date1 = document.all('year1').value;\r\n");
       sb.append("var Month = document.all('Month').value;\r\n");
       if (CODETABLE.length()>0)
       {
          sb.append("var code = document.all('code').value;\r\n");
          sb.append("var name = \"\";\r\n");
          sb.append("var strs= new Array();\r\n");
          sb.append("var strs= code.split(\"/\");\r\n");
          sb.append("if (strs.length==2){");
          sb.append("code = strs[0];\r\n");
          sb.append("name = strs[1];\r\n");
          sb.append(";\r\n");
          sb.append("}");
       }

       //计算报表
       sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");
       if (CODETABLE.length()>0)
       {
          sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+date1+'&P2='+Month+'&P3='+code+'&P4='+name+'&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");
       }else
       {
          sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+date1+'&P2='+Month+'&P3="+P3+"&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");
       }
       sb.append("document.all('P1').value=date1;\r\n");
       sb.append("document.all('P2').value=Month;\r\n");


       if (CODETABLE.length()>0)
       {
           sb.append("document.all('P3').value=code;\r\n");
           sb.append("document.all('P4').value=name;\r\n");
       }

       sb.append("}\r\n");



       //生成统计报表(年份比较)
       sb.append("function Statistics2(){\r\n");
       sb.append("var date1 = document.all('date1').value;\r\n");
       sb.append("var date2 = document.all('date2').value;\r\n");
       //计算报表
       sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");
       sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+date1+'&P2='+date2+'&P3="+P3+"&P4="+P4+"&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");
       sb.append("document.all('P1').value=date1;\r\n");
       sb.append("document.all('P2').value=date2;\r\n");
       sb.append("}\r\n");

       //生成统计报表(年月比较)
       sb.append("function Statistics3(){\r\n");
       sb.append("var year1 = document.all('date1').value;\r\n");
       sb.append("var year2 = document.all('date2').value;\r\n");
       sb.append("var month1 = document.all('Month1').value;\r\n");
       sb.append("var month2 = document.all('Month2').value;\r\n");
       sb.append("var dateS1 = '';\r\n");
       sb.append("var dateE1 = '';\r\n");
       sb.append("var dateS2 = '';\r\n");
       sb.append("var dateE2 = '';\r\n");
       sb.append("if(month1=='01' || month1=='03' || month1=='05' || month1=='07' || month1=='08' || month1=='10' || month1=='12'){\r\n");
       sb.append("dateS1 = year1+'-'+month1+'-01';\r\n");
       sb.append("dateE1 = year1+'-'+month1+'-31';\r\n");
       sb.append("}\r\n");
       sb.append("if(month1=='04' || month1=='06' || month1=='09' || month1=='11'){\r\n");
       sb.append("dateS1 = year1+'-'+month1+'-01';\r\n");
       sb.append("dateE1 = year1+'-'+month1+'-30';\r\n");
       sb.append("}\r\n");
       sb.append("if(month1=='02' && RunNian(year1)==true){\r\n");
       sb.append("dateS1 = year1+'-'+month1+'-02';\r\n");
       sb.append("dateE1 = year1+'-'+month1+'-29';\r\n");
       sb.append("}\r\n");
       sb.append("if(month1=='02' && RunNian(year1)==false){\r\n");
       sb.append("dateS1 = year1+'-'+month1+'-02';\r\n");
       sb.append("dateE1 = year1+'-'+month1+'-28';\r\n");
       sb.append("}\r\n");
       sb.append("if(month2=='01' || month2=='03' || month2=='05' || month2=='07' || month2=='08' || month2=='10' || month2=='12'){\r\n");
       sb.append("dateS2 = year2+'-'+month2+'-01';\r\n");
       sb.append("dateE2 = year2+'-'+month2+'-31';\r\n");
       sb.append("}\r\n");
       sb.append("if(month2=='04' || month2=='06' || month2=='09' || month2=='11'){\r\n");
       sb.append("dateS2 = year2+'-'+month2+'-01';\r\n");
       sb.append("dateE2 = year2+'-'+month2+'-30';\r\n");
       sb.append("}\r\n");
       sb.append("if(month2=='02' && RunNian(year2)==true){\r\n");
       sb.append("dateS2 = year2+'-'+month2+'-02';\r\n");
       sb.append("dateE2 = year2+'-'+month2+'-29';\r\n");
       sb.append("}\r\n");
       sb.append("if(month2=='02' && RunNian(year2)==false){\r\n");
       sb.append("dateS2 = year2+'-'+month2+'-02';\r\n");
       sb.append("dateE2 = year2+'-'+month2+'-28';\r\n");
       sb.append("}\r\n");

       //计算报表
       sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");
       sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+dateS1+'&P2='+dateE1+'&P3='+dateS2+'&P4='+dateE2+'&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");
       sb.append("document.all('P1').value=dateS1;\r\n");
       sb.append("document.all('P2').value=dateE1;\r\n");
       sb.append("document.all('P3').value=dateS2;\r\n");
       sb.append("document.all('P4').value=dateE2;\r\n");

       sb.append("}\r\n");


       //生成统计报表(年季度比较)
       sb.append("function Statistics4(){\r\n");
       sb.append("var year1 = document.all('date1').value;\r\n");
       sb.append("var year2 = document.all('date2').value;\r\n");
       sb.append("var Quarter1 = document.all('Quarter1').value;\r\n");
       sb.append("var Quarter2 = document.all('Quarter2').value;\r\n");
       sb.append("var dateS1 = '';\r\n");
       sb.append("var dateE1 = '';\r\n");
       sb.append("var dateS2 = '';\r\n");
       sb.append("var dateE2 = '';\r\n");
       sb.append("if (Quarter1=='1'){\r\n");
       sb.append("dateS1 = year1+'-01-01';\r\n");
       sb.append("dateE1 = year1+'-03-31';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter1=='2'){\r\n");
       sb.append("dateS1 = year1+'-04-01';\r\n");
       sb.append("dateE1 = year1+'-06-30';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter1=='3'){\r\n");
       sb.append("dateS1 = year1+'-07-01';\r\n");
       sb.append("dateE1 = year1+'-09-30';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter1=='4'){\r\n");
       sb.append("dateS1 = year1+'-10-01';\r\n");
       sb.append("dateE1 = year1+'-12-31';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter2=='1'){\r\n");
       sb.append("dateS2 = year2+'-01-01';\r\n");
       sb.append("dateE2 = year2+'-03-31';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter2=='2'){\r\n");
       sb.append("dateS2 = year2+'-04-01';\r\n");
       sb.append("dateE2 = year2+'-06-30';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter2=='3'){\r\n");
       sb.append("dateS2 = year2+'-07-01';\r\n");
       sb.append("dateE2 = year2+'-09-30';\r\n");
       sb.append("}\r\n");
       sb.append("if (Quarter2=='4'){\r\n");
       sb.append("dateS2 = year2+'-10-01';\r\n");
       sb.append("dateE2 = year2+'-12-31';\r\n");
       sb.append("}\r\n");

       //计算报表
       sb.append("document.data.location.href='ZrAnalyseEngine/StatisticsShow/message1.jsp';\r\n");
       sb.append("document.computer.location.href='statisticscompute.do?ID="+ID+"&P1='+dateS1+'&P2='+dateE1+'&P3='+dateS2+'&P4='+dateE2+'&P5="+P5+"&USERTYPE="+USERTYPE+"';\r\n");
       sb.append("document.all('P1').value=dateS1;\r\n");
       sb.append("document.all('P2').value=dateE1;\r\n");
       sb.append("document.all('P3').value=dateS2;\r\n");
       sb.append("document.all('P4').value=dateE2;\r\n");

       sb.append("}\r\n");


       //检查输入年份的有效性JS
       sb.append("function CheckYear(){\r\n");
       sb.append("var objSrc = event.srcElement;\r\n");
       sb.append("if (objSrc.tagName == 'INPUT'){\r\n");
       sb.append("if(event.keyCode >= 48 && event.keyCode <= 57){return true;}else{return false;}}\r\n");
       sb.append("return false;}\r\n");
       //取得是否为润年
       sb.append("function RunNian(The_Year){\r\n");
       sb.append("if ((The_Year%400==0) || ((The_Year%4==0) && (The_Year%100!=0)))\r\n");
       sb.append("return true;\r\n");
       sb.append("else\r\n");
       sb.append("return false;\r\n");
       sb.append("}\r\n");
       //根据年和周得到开始时间和结束时间相关-----------------
       sb.append("Date.prototype.getWeek = function(flag)\r\n");
       sb.append("{\r\n");
       sb.append("var first=new Date(this.getFullYear(),0,1);\r\n");
       sb.append("var n=parseInt('1065432'.charAt(first.getDay()));\r\n");
       sb.append("n=this.getTime()-first.getTime()-n*24*60*60*1000;\r\n");
       sb.append("n=Math.ceil(n/(7*24*60*60*1000));\r\n");
       sb.append("return (flag==true&&first.getDay()!=1)?(n+1):n;\r\n");
       sb.append("}\r\n");
       sb.append("Date.prototype.format = function(format)\r\n");
       sb.append("{\r\n");
       sb.append("var o = {");
       sb.append("'M+':this.getMonth()+1,");
       sb.append("'d+':this.getDate(),");
       sb.append("'h+':this.getHours(),");
       sb.append("'m+':this.getMinutes(),");
       sb.append("'s+':this.getSeconds(),");
       sb.append("'q+':Math.floor((this.getMonth()+3)/3),");
       sb.append("'S':this.getMilliseconds()");
       sb.append("}\r\n");
       sb.append("if(/(y+)/.test(format))  format=format.replace(RegExp.$1,");
       sb.append("(this.getFullYear()+'').substr(4  - RegExp.$1.length));");
       sb.append("for(var k in o)if(new  RegExp('('+ k +')').test(format))");
       sb.append("format = format.replace(RegExp.$1,");
       sb.append("RegExp.$1.length==1 ? o[k]:");
       sb.append("('00'+ o[k]).substr((''+ o[k]).length));\r\n");
       sb.append("return format;\r\n");
       sb.append("}\r\n");
       sb.append("function getFirstAndEnd(d)\r\n");
       sb.append("{\r\n");
       sb.append("var w=d.getDay(),n = 24*60*60*1000;\r\n");
       sb.append("var first = new Date(d.getTime() - parseInt('6012345'.charAt(w))*n);\r\n");
       sb.append("var end = new Date(d.getTime() + parseInt('0654321'.charAt(w))*n);\r\n");
       sb.append("return {first:first,end:end};\r\n");
       sb.append("}\r\n");
       //根据年和周得到开始时间和结束时间相关结束-----------
       sb.append(" </script>");
       sb.append("</BODY>");
       sb.append("</HTML>");

        userUI = null;
        SControl =null;
        user = null;
        Smain = null;

  }
  catch (Exception ex) {
      return "";
  }
  return sb.toString();
}

}
