<html>

<head>
<script language="javascript" src="<%=request.getContextPath()%>/js/cookieUtils.js" type="text/javascript"></script>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<fmt:setBundle basename="MessageResources"/>
   <link href="css/styles.css" rel="stylesheet" type="text/css" id ="stylelink">

   <script type="text/javascript">
   var stylesheet = getCookieValue("stylesheet");
   var stylelink = document.getElementById("stylelink");
   if(stylesheet != null || stylesheet != ""){
       stylelink.href = "css/" + stylesheet;
   }else{
       stylelink.href = "styles.css";
}
       
       //
       var contextPath = "<%=request.getContextPath()%>";

       //
       var meetingKey = "<%=request.getParameter("key")%>";
       
       //
       var operation = "<%=request.getParameter("operation")%>"; 

       //
       var isReloaded = "<%=request.getParameter("reload")%>";

       //
       var currentEMail = "<%=request.getParameter("email")%>";

       // In milliseconds - default 5 seconds
       var pollingPeriod = 5000;
       
       function getXMLHTTPRequest()
       {
           var xmlObject = null;
           if(document.all) 
           {
              if (window.XMLHttpRequest)
              { // check for IE7
                  xmlObject = new XMLHttpRequest();
              }
              else
              {
                  if(xmlObject == null) 
                  {
                      try 
                      {
                          xmlObject = new ActiveXObject('Msxml2.XMLHTTP');
                      } 
                      catch(e) {}
                  }
                  if(xmlObject == null) 
                  {
                      try 
                      {
                          xmlObject = new ActiveXObject('Microsoft.XMLHTTP');
                      } 
                      catch(e) 
                      {
                          throw new Exception('Browser does not support Ajax calls.  Please check your browser settings.');
                      }
                  }
              }
           } 
           else 
           {
               xmlObject = new XMLHttpRequest();
           }
           return xmlObject;
       }

       function sendAsyncAJAXRequest( type, urll , callbackFn)
       {
           try
           {
               var timeinms = (new Date()).getTime();
               var xmlhttp = getXMLHTTPRequest();
               xmlhttp.onreadystatechange = function(){ callbackFn(xmlhttp) };
               urll = urll+"&ttime="+timeinms;
               xmlhttp.open(type,urll,true);
               xmlhttp.send(null);
           }
           catch(e)
           {
               alert('<fmt:message key="unable.to.process"/>');
           }
       }

       function getMeetingDetails()
       {
           try
           {
               if(meetingKey)
               {
                   var urll = 
                      contextPath + "/zohomeeting.do?method=getMeetingDetails&key="
                                  +meetingKey ;

                   sendAsyncAJAXRequest('GET',urll,handleMeetingDetails);                   
               }

           }
           catch(e)
           {
               alert('<fmt:message key="error.sending.request.to.server"/>');
           }
       }

       function handleMeetingDetails(xmlhttp)
       {
           if(xmlhttp.readyState == 4)
           {
                var rsp = xmlhttp.responseText;
                //To handle request timed out situations.
                //Empty string will be returned at the
                //time of timedout
                if(rsp == null || trim(rsp) == "" )
                {
                    alert('<fmt:message key="unable.to.fetch.data"/>');
                    meetingStatusPolling();
                    return;
                }
                var evalRsp = eval("("+rsp+")");
                if(evalRsp.response.result)
                {
                    var meeting = evalRsp.response.result.meetings.meeting;
                    populateData(meeting);
                }
                else
                {
                    alert('<fmt:message key="unable.to.fetch.meeting.details"/>');
                }
                meetingStatusPolling();
           }
       }
       
       function populateData(rsp)
       {
           var topic = rsp.meeting_topic;
           var ddate = rsp.meeting_date;
           var presenter = rsp.meeting_presenter.emailid;
           var agenda = rsp.meeting_agenda;
           var mk = rsp.meeting_key;
           var status = rsp.meeting_status;

           document.getElementById("meetingTopic_span").innerHTML = topic;
           document.getElementById("meetingDateAndTime_span").innerHTML = ddate ; 
           document.getElementById("agenda_span").innerHTML = agenda;
           document.getElementById("presenter_span").innerHTML = presenter;
           document.getElementById("meetingStatus_span").innerHTML = status;
           document.getElementById("meetingKey_span").innerHTML = mk;
           document.getElementById("startMeetingButton").innerHTML = getButtonContent(status);
           if(operation == "join")
           {
               document.getElementById("meetingNameLabel_span").innerHTML = "Name/EMail Id:";
               if(currentEMail != null && currentEMail != "null" && trim(currentEMail) != "")
               {
                     document.getElementById("meetingName_span").innerHTML = 
                           "<input type=\"text\" id=\"meetingName_Text\" value=\"<%=request.getParameter("email")%>\">";
               }
               else
               {
                     document.getElementById("meetingName_span").innerHTML = 
                           "<input type=\"text\" id=\"meetingName_Text\" value=\"\">";
               }
           }
           else 
           {
               document.getElementById("meetingNameLabel_span").innerHTML = "";
               document.getElementById("meetingName_span").innerHTML = "";
           }
       }
       
       function isWindows()
       {
           var os = navigator.platform;
           if(os.indexOf('Win') != -1)
           {
               return true;
           }
           return false;
       }

       //********** Start and Linux - Remove Cancel **********
       function getButtonContent(sstatus)
       {
          
           document.getElementById("downloadAgentZip_icon").innerHTML = "";
           document.getElementById("downloadAgentZip_link").innerHTML = "";

           var buttonName;
           var innerContent;
           var urll = window.location.href+"&reload=true";
           if(operation == 'join')
           {
               if(sstatus == "Started")
               {
                   innerContent = "<input type=\"button\" value=\"<fmt:message key="join"/>\" onclick=\"javascript:popupJoinDiv()\">";
               }
               else 
               {
                    innerContent = "<input type=\"button\" value=\"<fmt:message key="join"/>\" disabled>";
               }
           }
           else if(operation == 'start')
           {
               if(sstatus == "Started")
               {
                    innerContent = "<input type=\"button\" value=\""+<fmt:message key="stop"/>+"\" onclick=\"javascript:stopMeeting()\">";
               }
               else
               {
                   if(isWindows())
                   {
                       innerContent = "<input type=\"button\" value=\""+<fmt:message key="start"/>+"\" onclick=\"javascript:openWindow('start')\">";
                       
                       document.getElementById("downloadAgentZip_icon").innerHTML = "<a href=\"javascript:downloadAgentZip()\"><img src=\"<%=request.getContextPath()%>/images/download_zip_button.gif\" style=\"padding-right:5px;\"/></a>";
                       document.getElementById("downloadAgentZip_link").innerHTML = "If START fails,<a href=\"javascript:downloadAgentZip()\"> download this zip</a>.. <br /> Unzip and start ZohoMeeting.exe";
                   }
                   else 
                   {
                       innerContent = "<span class=\"addheader\">"+'<fmt:message key="presenter.to.be.in.windows"/>'+"!</span>";
                   }
               }
           }
           return innerContent;
       }
       
       function downloadAgentZip()
       {
            try
            {
                 sendAsyncAJAXRequest('GET',
                    contextPath+"/zohomeeting.do?method=getDownloadZipURL&meetingKey="+meetingKey, 
                    handleDownloadAgentZip);
            }
            catch(e)
            {
                  alert('<fmt:message key="unable.to.send.request.to.server"/>');
            }
       }

       function handleDownloadAgentZip(xmlhttp)
       {
            if(xmlhttp.readyState == 4)
            {
                var rsp = xmlhttp.responseText;
                //To handle request timed out situations.
                //Empty string will be returned at the
                //time of timedout
                if(rsp == null || trim(rsp) == "" )
                {
                    alert('<fmt:message key="unable.to.download.zip"/>');
                    return;
                }
                var evalRsp = eval('('+rsp+')');
                if(evalRsp.response.result)
                {
                     var zipPath = evalRsp.response.result.meeting.zip_path;
                     location.href = zipPath;
                }
                else
                {
                     alert('<fmt:message key="unable.to.download.zip"/>');
                }
            }
       }

       function replaceStr(str,str1, str2)
       {
           var regx = new RegExp(str1,"g");
           var s = str.replace(regx,str2);
           return s;
       }


       function openWindow( axn , selectedViewer)
       {
           var urll = window.location.href;
           if(urll.match("reload=true"))
           {
               if(axn == "join")
               {
                   var currentViewer;
                   if(urll.match("=activex"))
                   {
                       currentViewer = "=activex";
                   }
                   else if(urll.match("=java"))
                   {
                       currentViewer = "=java";
                   }
                   else if(urll.match("=flash"))
                   {
                       currentViewer = "=flash";
                   }
                   selectedViewer = "="+selectedViewer;
                   urll = replaceStr(urll,currentViewer,selectedViewer);

                   var email = document.getElementById("meetingName_Text").value; 
                   if(urll.match("email="))
                   {
                       urll = replaceStr(urll,currentEMail,email);
                   }
               }
           }
           else
           {
               urll = urll+"&reload=true";
               if(axn == "join")
               {
                   var email = document.getElementById("meetingName_Text").value; 
                   urll = urll+"&viewerType="+selectedViewer+"&email="+email;
               }
           }
           window.open(urll , "_top");
       }

       function joinMeeting()
       {
            var options = document.joinOptionsForm.joinOptions;
            var selected = "";
            if(options.length == null || options.length == 0)
            {
                 selected = options.value;
            }
            else
            {
                for( var i = 0 ; i < options.length ; i++ )
                {
                    if(options[i].checked == true)
                    {
                        selected = options[i].value;
                    }
                }
            }
            //var urll = window.location.href+"&reload=true&viewerType="+selected;
            openWindow('join',selected);
       }

       function isJavaEnabled()
       {
           return navigator.javaEnabled();
       }

       function trim(s)
       {
           return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
       }

       function popupJoinDiv()
       {
           //checks EMailId
           var email = document.getElementById("meetingName_Text").value;
           if(!email || email == null || trim(email) == "")
           {
               alert('<fmt:message key="enter.valid.emailid"/>');
               return;
           }

           var divEle = document.getElementById("joinOptionsDiv");
           var innerHttml = "";
           var javaEnabled = "";
           if(isJavaEnabled())
           {
               javaEnabled = " <div><img src=\"images/spacer.gif\" width=\"20\" height=\"1\"/><input type=\"radio\" name=\"joinOptions\" id=\"joinOptions\" value=\"java\">Java</div>";
           }
           if(isWindows())
           {
               innerHttml = "<div><img src=\"images/spacer.gif\" width=\"20\" height=\"1\"/><input type=\"radio\" name=\"joinOptions\" id=\"joinOptions\" value=\"activex\" checked>ActiveX</div> "+javaEnabled+"<div><img src=\"images/spacer.gif\" width=\"20\" height=\"1\"/><input type=\"radio\" name=\"joinOptions\" id=\"joinOptions\" value=\"flash\">Flash</div> ";
           }
           else
           {
               if(isJavaEnabled())
               {
                   innerHttml = " <div><img src=\"images/spacer.gif\" width=\"20\" height=\"1\"/><input type=\"radio\" name=\"joinOptions\" id=\"joinOptions\" value=\"java\" checked>Java</div><div><img src=\"images/spacer.gif\" width=\"20\" height=\"1\"/><input type=\"radio\" name=\"joinOptions\" id=\"joinOptions\" value=\"flash\">Flash</div> ";
               }
               else
               {
                   innerHttml = " <div><img src=\"images/spacer.gif\" width=\"20\" height=\"1\"/><input type=\"radio\" name=\"joinOptions\" id=\"joinOptions\" value=\"flash\" checked>Flash</div> ";
               }
           }

           innerHttml = "<table width=\"100%\" class=\"formtext\">"+
               "<tr><td align=\"left\" valign=\"top\" class=\"addheader\">Choose Viewer<img src=\"images/spacer.gif\" width=\"30\" height=\"1\"/></td> <td align=\"left\" valign=\"top\"><a href=\"javascript:hideDiv('joinOptionsDiv')\"><img src=\"<%=request.getContextPath()%>/images/icon_cancel.gif\" border=\"0\" class=\"img\" title=\"<fmt:message key="close"/>\"/></a></td></tr>" + 
               "<tr><td align=\"left\" valign=\"top\">"+innerHttml+"</td></tr>"+
               "<tr><td align=\"center\" valign=\"bottom\" colspan=\"2\"><input type=\"button\" name=\"joinOptionsSubmit\" value=\"<fmt:message key="join"/>\" class=\"btnStyle\" onclick=\"javascript:joinMeeting()\"> </td></tr><tr><td colspan=\"2\">&nbsp;&nbsp;</td></tr>"+
               "</table>";


           divEle.innerHTML = innerHttml;
           //var pointXX = lastMouseClickX;
           //var pointYY = lastMouseClickY;
           divEle.classname = "tagmenu";
           divEle.style.right = "";
           //div.style.border = "1px solid black";
           //divEle.style.left = pointXX;
           //divEle.style.top = pointYY;
           divEle.style.position = "absolute";
           divEle.style.display = "block";
           divEle.style.backgroundColor = "#b8d4ec";
       }

       function hideDiv(divName)
       {
           var divEle = document.getElementById(divName);
           if(divEle)
           {
               divEle.style.display = "none"; 
           }
       }
      
       function stopMeeting()
       {
           try
           {
               if(!confirm('<fmt:message key="confirm.stop.meeting"/>'))
               {
                  return;
               }
               sendAsyncAJAXRequest('GET',
                  contextPath+"/zohomeeting.do?method=stopMeeting&key="+meetingKey , handleStopMeeting);
           }
           catch(e)
           {
               //alert("alert")
           }
       }

       function handleStopMeeting(xmlhttp)
       {
           if(xmlhttp.readyState == 4)
           {
               var rsp = xmlhttp.responseText;
               //To handle request timed out situations.
               //Empty string will be returned at the
               //time of timedout
               if(rsp == null || trim(rsp) == "" )
               {
                   alert('<fmt:message key="unable.to.stop.meeting"/>');
                   return;
               }
               var evalRsp = eval('('+rsp+')');
               if(evalRsp.response.result)
               {
                   var rspMssg = evalRsp.response.result.meeting.agent_response;
                   if(rspMssg == "received")
                   {
                   }
                   else
                   {
                      alert('<fmt:message key="unable.to.stop.meeting"/>');
                   }
               }
               else
               {
                    alert('<fmt:message key="unable.to.stop.meeting"/>');
               }
           }
       }
       
       function meetingStatusPolling()
       {
           try
           {
               sendAsyncAJAXRequest('GET',
                       contextPath+"/zohomeeting.do?method=getMeetingStatus&key="+meetingKey , handleMeetingStatus);
           }
           catch(e)
           {
               alert("meetngstatus"+e);
           }
       }

       function handleMeetingStatus(xmlhttp)
       {
           if(xmlhttp.readyState == 4)
           {
               var response = xmlhttp.responseText;
               //To handle request timed out situations.
               //Empty string will be returned at the
               //time of timedout
               if(response == null || trim(response) == "" )
               {
                   setTimeout("javascript:meetingStatusPolling()",pollingPeriod);
                   return;
               }
               var evalRsp = eval('('+response+')');
               if(evalRsp.response.result)
               {
                  var meetingStatus = evalRsp.response.result.meeting.meeting_status;
                  var statuss = "Started";
                  if(meetingStatus == "NOT_STARTED")
                  {
                      statuss = "Not Started";
                  }
                  document.getElementById("meetingStatus_span").innerHTML = statuss;
                  document.getElementById("startMeetingButton").innerHTML =  getButtonContent(statuss);
               }
               setTimeout("javascript:meetingStatusPolling()",pollingPeriod);
           }
       }
       
       function showInstructionImage()
       {
           
           if(operation == "start" && isReloaded == "true")
           {
               //IE
               if(document.all)
               {
               }
               //Mozilla Firefox
               else
               {
                   var divEle = document.getElementById("instructionDiv");
                   divEle.innerHTML = "<img src=\"/images/f_blocker.gif\">";
                   divEle.style.display = "block";
               }
           }
       }

   </script>

</head>

<body style="background-color:#b8d4ec">
 

<table align="center" cellpadding="5" cellspacing="0" border="0" width="100%" height="100%" style="background-color:#b8d4ec">
  <tr>
     <td align="center">
          <table align="center" height="100%" width="80%" cellpadding="0" cellspacing="0" border="0" class="mainbody"  style="background-color:#ffffff">
            <tr>
               <td>
                  <%
                       String operation = request.getParameter("operation");
                       String meetingKey = request.getParameter("key");
                       String reloaded = request.getParameter("reload");
                       if(operation.trim().equals("start") && reloaded != null && reloaded.trim().equals("true"))
                       {
                  %>
                          <iframe src="http://meeting.zoho.com/login/meeting_details.jsp?meetingKey=<%=request.getParameter("key")%>&startMeeting=true&reloaded=true&source=ZohoConnect&fb=no&live=no&inv=no" height="0" width="0" frameborder="0"></iframe>
                  <%
                       }
                       else if(operation.trim().equals("join") && reloaded != null && reloaded.trim().equals("true"))
                       {
                  %>
                  <%
                           String viewerType = request.getParameter("viewerType");
                           if(viewerType.equals("java"))
                           {
                  %>         
                              <iframe align="center" id="joinMeetingIframe" src="/jsp/javaviewer.jsp?key=<%=request.getParameter("key")%>&email=<%=request.getParameter("email")%>" height="40" width="415" frameborder="0" scrolling="no" style="background-color:#b8d4ec"></iframe>
                  <%       
                           }
                           else
                           {
                  %>
                              <iframe src="http://meeting.zoho.com/login/meeting_details.jsp?meetingKey=<%=request.getParameter("key")%>&joinMeeting=true&email=<%=request.getParameter("email")%>&viewer=<%=request.getParameter("viewerType")%>&source=ZohoConnect&fb=no&live=no&inv=no" height="0" width="0" frameborder="0"></iframe>
                  <%
                           }
                  %>
                  <%
                        }
                  %>
               </td>
            </tr>
            <tr>
               <td align="left">
                      <img src="images/spacer.gif" width="40" height="1"/><img src="<%=request.getContextPath()%>/images/CompanyLogo.gif" border="0" usemap="#Map" title="XYZ Inc"/>
               </td>
            </tr>
            <tr>
              <td valign="top" align="center">
                  <table align="center" width="100%" border="0" cellpadding="0" cellspacing="0" >
                      <tr>
                          <td align="center" valign="middle" style="color:#14377B;" class="BgColorDark"><fmt:message key="meeting.details"/></td>
                          <td align="right" valign="middle" class="formsheader"></td>
                      </tr>
                      <tr>
                           <td width="47%" align="center" valign="middle" class="formstop"><strong><fmt:message key="meeting.topic"/>:</strong></td>
                           <td align="left" valign="middle" class="formstop"><span id="meetingTopic_span"/></td>
                      </tr>
                      <tr>
                           <td align="center" valign="middle" class="formstyle"><strong><fmt:message key="meeting.dateandtime"/>:</strong></td>
                           <td align="left" valign="middle" class="formsinput" style="padding-top:5px;"><span id="meetingDateAndTime_span"/></td>
                      </tr>
                      <tr>
                           <td align="center" valign="middle" class="formstyle"><strong><fmt:message key="agenda"/>:</strong></td>
                                                       <td align="left" valign="top" class="formsinput"><span id="agenda_span"></td>
                      </tr>
                      <tr>
                           <td align="center" valign="middle" class="formstyle"><strong><fmt:message key="presenter"/>:</strong>&nbsp;</td>
                           <td align="left" valign="top" class="formsinput"><span id="presenter_span"></td>
                      </tr>
                      <tr>
                           <td align="center" valign="middle" class="formstyle"><strong><fmt:message key="meeting.key"/>:<span style="font-size:11px;">&nbsp;</span></strong>&nbsp;
                           <td align="left" valign="middle" class="formsinput"><span id="meetingKey_span"/></td>
                      </tr>
                      <tr>
                           <td align="center" valign="middle" class="formstyle"><strong><fmt:message key="meeting.status"/>:</strong></td>
                           <td align="left" valign="middle" class="formsinput"><span id="meetingStatus_span"/></td>
                      </tr>
                      <tr>
                           <td align="center" valign="middle" class="formstyle"><strong><span id="meetingNameLabel_span"></span></strong></td>
                           <td align="left" valign="middle" class="formsinput"><span id="meetingName_span"/></td>
                      </tr>
                      <tr>
                            <td align="center" valign="middle" class="formstyle">&nbsp;</td>
                            <td align="left" valign="middle" class="formsheader"> 
                               <span id="downloadAgentZip_icon"></span><span id="startMeetingButton"></span>
                               <input name="login2" class="btnStyle" value="<fmt:message key="cancel"/>" onClick="" type="submit" />
                            </td>
                      </tr>
                      <tr>
                            <td align="left" valign="middle">&nbsp;</td>
                            <td align="left" valign="middle" class="formstyle">
                              <form name="joinOptionsForm">
                                <div id="joinOptionsDiv" style="display:none;font-family:Verdana,sans-serif;font-size:12px;border:1px Solid black;width:200;height:115;top:320;left:350;">
                                </div>
                              </form>
                            </td>
                      </tr>
                      <tr>
                            <td colspan="2" align="center" valign="top"><span id="downloadAgentZip_link"></span></td>
                      </tr>
                  </table>
                  <div id="instructionDiv" style="display:none"></div>
                  <script>showInstructionImage();</script>
              </td>
            </tr>
          </table>
     </td>
  </tr>
</table>
<map name="Map" id="Map"><area shape="rect" coords="360,10,472,36" href="http://ad.doubleclick.net/clk;140592600;20645050;o?http://usa.visa.com/business/index.html?ep=a_cmp_akqa" target="_blank" alt="presented by VISA" />
<script>getMeetingDetails()</script>
</body>
</html>
