// Such that openeing a div should close the other divs
var divArray = new Array("createMeetingsDiv" , "myMeetingsDiv" , "invitedMeetingsDiv", "startMeetingDiv" , "joinMeetingDiv", "joinOptionsDiv" , "viewParticipantsDiv" , "configureTimeZoneDiv" , "inviteParitcipantsDiv","instructionDiv");

//
var monthArr_Shot = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

// In milliseconds - default 5 seconds
var pollingPeriod = 5000;

//
var userMailId = ""; 
userMailId = getCookieValue(readCookie('EMAILID'));

//
var configuredTimezone = "";

//
var isSearchEnabled = false;

//
var userName = getCookieValue(readCookie('USERNAME'));

//
var isInvitedMeetingFirstTime = true;

//
var isMyMeetingFirstTime = true;

//
var doStatusPollingForKey = "";
//
var statusPollingKeyTopic = "";
//
var statusPollingKeyType = "";
//
var statusPollingKeyRole = "";

//Used in finding out the time in millis corresponding 
//to the configured timezone.
// GMT offset + configured Time zone off set in millis
var offSetWithRespectToSystemTime = "";

//Stores My Meetings
var MyMeetingsDB = new Array();

//Object format for My Meeting
function MyMeeting(ttopic , kkey , sstatus , ttime , timezone , agenda , role , participants , presenter , ct)
{
    this.meetingTopic = ttopic;
    this.meetingKey = kkey;
    if(sstatus == "Started")
    {
        this.meetingStatus = "STARTED";
    }
    else
    {
        this.meetingStatus = "NOTSTARTED";
    }
    this.meetingTime = ttime;
    this.timezone = timezone;
    if(agenda === true)
    {
        agenda = "";
    }
    this.agenda = agenda;
    this.role = role;
    this.participantsList = participants;
    this.controlTransfer = ct;
    this.presenter = presenter;
}

//Stores Invited Meetings
var InvitedMeetingsDB = new Array();

//Object format for Invited Meeting
function InvitedMeeting(ttopic , kkey , sstatus, role , ddate , agenda , presenter , timezone)
{
    this.meetingTopic = ttopic;
    this.meetingKey = kkey;
    if(sstatus == "Started")
    {
        this.meetingStatus = "STARTED";
    }
    else
    {
        this.meetingStatus = "NOTSTARTED";
    }
    this.meetingTime = ddate;
    this.timezone = timezone;
    this.agenda = agenda;
    this.role = role;
    this.presenter = presenter;
}

//Stores the recent meeting key to be deleted
var recentMKToBeDeleted = "";

//Loading image
var loadingImg = "<img src=\"" + contextPath +"/images/loading.gif\">";

//
var currentlySelectedMeetingType = "myMeetings";

//Used while changing the status of the start/stop button, 
//when user lands on starting url
var isMeetingStoppedOnce = false;

//
function getAllMyMeetings()
{
    try
    {
        showLoadingDiv(document.getElementById("loading").innerHTML+"...");
        sendAsyncAJAXRequest('GET',
                contextPath + '/zohomeeting.do?method=getMyMeetingsList', handleMyMeetings);
    }
    catch(e)
    {
        alert("getAllMyMeetings::"+e);
    }
}

//
function handleMyMeetings(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(document.getElementById("unable.to.fetch.data").innerHTML);
            hideLoadingDiv();
            return;
        }
        var evalRsp = eval('('+rsp+')');
        var rslt = evalRsp.response.result;
        if(rslt)
        {
            MyMeetingsDB = new Array();
            var meetings = rslt.meetings.meeting;
            if(meetings && meetings.length)
            {
                var ln = meetings.length;
                for(var i = 0 ; i < ln ; i++ )
                {
                    parseAndAddMyMeetings(meetings[i]);
                }
            }
            else if(meetings.length == null || meetings.length == 0)
            {
                parseAndAddMyMeetings(meetings);
            }
            isMyMeetingFirstTime = false;
            formMeetingsTable("myMeetings",false);
        }
        else
        {
            //If no meeting is available for the user,
            //response is error with the message "There are no meetings.".
            //As a temporary solution, handling such exception as follows.
            if(evalRsp.response.error)
            {
                var mssg = evalRsp.response.error.message;
                if(mssg == "There are no meetings.")
                {
                    isMyMeetingFirstTime = false;
                    formMeetingsTable("myMeetings",false);
                }
            }
            else
            {
                alert(document.getElementById("unable.to.fetch.data").innerHTML);
            }
        }
        hideLoadingDiv();
    }
}


//
function parseAndAddMyMeetings(meeting)
{
    var mtopic = meeting.meeting_topic;
    var mkey = meeting.meeting_key;
    var mstatus = meeting.meeting_status;
    var mdate = meeting.meeting_date;
    var mtimezone = "dummy_timezone";
    var magenda = meeting.meeting_agenda;
    var mrole = meeting.meeting_role;
    var participants = new Array();
    
    //
    var participantsList = meeting.meeting_participants;
    if(participantsList && participantsList.meeting_participant)
    {
        participantsList = participantsList.meeting_participant;
        //only one participant
        if(participantsList.length == null || participantsList.length == 0)
        {
            participants[0] = participantsList.emailid;
        }
        //participants in array - object
        else
        {
            var ln = participantsList.length ;
            for(var i = 0 ; i< ln ; i++ )
            {
                participants[participants.length] = participantsList[i].emailid;
            }
        }
    }
    //

    var ct = meeting.agent_type;
    var presenter = meeting.meeting_presenter.emailid;

    MyMeetingsDB[MyMeetingsDB.length] = new MyMeeting(mtopic,mkey,mstatus,
                       mdate,mtimezone,magenda,mrole,participants,presenter,ct);
}


function getAllInvitedMeetings()
{
    try
    {
        showLoadingDiv(document.getElementById("loading").innerHTML+"...");
        sendAsyncAJAXRequest('GET',
                contextPath + '/zohomeeting.do?method=getInvitedMeetingsList', handleInvitedMeetings);
    }
    catch(e)
    {
        alert(document.getElementById("error.sending.request.to.server").innerHTML);
    }
}

function handleInvitedMeetings(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(document.getElementById("unable.to.fetch.data").innerHTML);
            hideLoadingDiv();
            return;
        }
        var evalRsp = eval('('+rsp+')');
        var rslt = evalRsp.response.result;
        if(rslt)
        {
            InvitedMeetingsDB = new Array();
            var meetings = rslt.meetings.meeting;
            if(meetings && meetings.length)
            {
               var ln = meetings.length;
               for(var i = 0 ; i < ln ; i++ )
               {
                  parseAndAddInvitedMeetings(meetings[i]);
               }
            }
            else if(meetings.length == null || meetings.length == 0)
            {
                parseAndAddInvitedMeetings(meetings);
            }
            isInvitedMeetingFirstTime = false;
            formMeetingsTable("invitedMeetings",false);
        }
        else
        {
            //If no meeting is available for the user,
            //response is error with the message "There are no meetings.".
            //As a temporary solution, handling such exception as follows.
            if(evalRsp.response.error)
            {
                var mssg = evalRsp.response.error.message;
                if(mssg == "There are no meetings.")
                {
                    isInvitedMeetingFirstTime = false;
                    formMeetingsTable("invitedMeetings",false);
                }
            }
            else
            {
                alert(document.getElementById("unable.to.fetch.data").innerHTML);
            }
        }
        hideLoadingDiv();
    }
}

//
function parseAndAddInvitedMeetings(meeting)
{
    var ttopic = meeting.meeting_topic;
    var sstatus = meeting.meeting_status;
    var kkey = meeting.meeting_key;
    var role = meeting.meeting_role;
    var ddate = meeting.meeting_date;
    var agenda = meeting.meeting_agenda;
    var presenter = meeting.meeting_presenter;
    var timezone = "dummy_timezone";
    InvitedMeetingsDB[InvitedMeetingsDB.length] = new InvitedMeeting(ttopic,kkey,sstatus,role,ddate,agenda,presenter,timezone);
}

function formMeetingsTable(meetingType , isDateFilterOn )
{
    var tableHeaderLabelMssg = document.getElementById("list.of.all.meetings").innerHTML;
    //*** This selectedDate should be at top ***
    //Because the complete div is cleared at the time of rendering
    //table view which also clears the selected Date field.
    //
    var dateToCompare;
    //
    if(isDateFilterOn)
    {
        var dddate = document.getElementById("selectedDate_TF").value;
        if(dddate && trim(dddate) != "")
        {
            var arr = dddate.split("-");
            dateToCompare = monthArr_Shot[(arr[1]-1)]+" "+arr[2]+", "+arr[0];
            tableHeaderLabelMssg = document.getElementById("meeting.scheduled.for.date").innerHTML+" : "+dateToCompare;
        }
    }
    
    if(isSearchEnabled)
    {
        tableHeaderLabelMssg = document.getElementById("search.result").innerHTML;
    }

    //
    var meetingArr = new Array();

    //
    var meetingsDiv;
    if(meetingType == "myMeetings")
    {
        if(isMyMeetingFirstTime)
        {
           getAllMyMeetings();
           return;
        }
        meetingArr = MyMeetingsDB;
        meetingsDiv = "myMeetingsDiv";
    }
    else if(meetingType == "invitedMeetings")
    {
        if(isInvitedMeetingFirstTime)
        {
            getAllInvitedMeetings();
            return;
        }
        meetingArr = InvitedMeetingsDB;
        meetingsDiv = "invitedMeetingsDiv";
    }

    var ln = meetingArr.length;
    
    //Clearing meetingsDiv
    var divEle = document.getElementById(meetingsDiv);
    divEle.innerHTML = "";
    showDiv(meetingsDiv,true);

    var tbl = document.createElement("table");
    tbl.style.width = "100%";
    tbl.style.border = "2";
    tbl.cellPadding = "0";
    tbl.cellSpacing = "0";
 //   tbl.className = "formtext";
    tbl.align="center";
		var tbdym = document.createElement("tbody");
    tbdym.id = "mTBody";
    tbl.appendChild(tbdym);
    divEle.appendChild(tbl);

    addOptionsHeader(tbdym,tableHeaderLabelMssg);
    var ttr = document.createElement("tr");
    tbdym.appendChild(ttr);
    var ttcol = document.createElement("td");
    ttcol.colSpan="3";
    ttr.appendChild(ttcol);
	
	
	var tblinner = document.createElement("table");
	tblinner.style.width = "100%";
    tblinner.cellPadding = "0";
    tblinner.cellSpacing = "0";
 //   tbl.className = "formtext";
   // tblinner.style.border="1px solid #74C6ED;"
    ttcol.appendChild(tblinner);
    var tbdy = document.createElement("tbody");
//	tbdy.style.height="300px";
//	tbdy.style.overflow="auto";
    tbdy.id = "meetingsTBody";
	
	/*
	var meetingInnerTableDiv = document.createElement("div");
	meetingInnerTableDiv.id="meetingInnerTableDiv";
	meetingInnerTableDiv.style.height="200px";
	meetingInnerTableDiv.style.overflow="auto";
	tbdy.appendChild(meetingInnerTableDiv);*/
	
    addColumnHeader(tbdy ,meetingType);
   

    if(ln > 0)
    {
        var isMatchFound = false;
        for(var ij = 0 ; ij < ln ; ij++ )
        {
            var meeting = meetingArr[ij];
            var islastrow = false;
            //adding style border for all the rows except last row
            if(ij == ln-1 )
            {
                islastrow = true;
            }
            //Date filter
            if(isDateFilterOn)
            {
                if(dateToCompare)
                {
                    var meetingDate = meeting.meetingTime;
                    if(meetingDate.indexOf(dateToCompare) != -1)
                    {
                        isMatchFound = true;
                        addRowInMeetingsTable(meeting,tbdy,islastrow,meetingType);
                    }
                }
            }
            //Search filter
            else if(isSearchEnabled)
            {
                var searchValue = document.getElementById("searchField").value;
                var topicc = meeting.meetingTopic;
                if(topicc.match(searchValue))
                {
                     isMatchFound = true;
                     addRowInMeetingsTable(meeting,tbdy,islastrow,meetingType);
                }
            }
            //Generic
            else
            {
                addRowInMeetingsTable(meeting,tbdy,islastrow,meetingType);
            }
        }

        //If no match found for this date filter or search result
        if((isDateFilterOn && !isMatchFound) || (isSearchEnabled && !isMatchFound))
        {
            var ttr = document.createElement("tr");
            tbdy.appendChild(ttr);

            var cn = "meetingcontent";
        var sstylename = new Array("borderBottom","className");
       var  sstyleval = new Array("dotted 1px #CCCCCC","Linktxtsmall");
            var aalign = "left";
            var vvalign = "middle";

            var message = document.getElementById("no.meeting.scheduled.for.date").innerHTML+" : "+dateToCompare;
            if(isSearchEnabled)
            {
                message = document.getElementById("no.matches.found").innerHTML;
            }
            
            createAndAddCell(ttr , message , cn , sstylename , sstyleval , "left" , vvalign , null , "9");

            var ttr1 = document.createElement("tr");
            tbdy.appendChild(ttr1);
            createAndAddCell(ttr1 , "&nbsp" , cn , null , null , "center" , vvalign , null , "9");
        }

        //If search is enabled, making it to disable after the table is rendered
        if(isSearchEnabled)
        {
             //Making search enabled to false
             isSearchEnabled = false;
        }
    }
    else
    {
        var ttr = document.createElement("tr");
        tbdy.appendChild(ttr);

        var cn = "meetingcontent";
        var sstylename = new Array("borderBottom","className");
       var  sstyleval = new Array("dotted 1px #CCCCCC","Linktxtsmall");
        var aalign = "left";
        var vvalign = "middle";
        
        var message;
        if(meetingType == "myMeetings")
        {
            message = document.getElementById("you.have.not.created.any.meetings").innerHTML;
        }
        else if(meetingType == "invitedMeetings")
        {
            message = document.getElementById("you.are.not.invited.for.any.meetings").innerHTML;
        }
        createAndAddCell(ttr , message , cn , sstylename , sstyleval , "left" , vvalign , null , "9");
        
        var ttr1 = document.createElement("tr");
        tbdy.appendChild(ttr1);
        createAndAddCell(ttr1 , "&nbsp" , cn , null , null , "center" , vvalign , null , "9");
    }
    tblinner.appendChild(tbdy);
	
	
}

function addRowInMeetingsTable(meeting , ttbody , islastrow , meetingType )
{
    var ttr = document.createElement("tr");
    ttbody.appendChild(ttr);
     
    var cn = "meetingcontent";
    var sstylename;
    var sstyleval;
    if(!islastrow)
    {
        sstylename = new Array("borderBottom","className");
        sstyleval = new Array("dotted 1px #CCCCCC","Linktxtsmall");
    }else
    {
        sstylename = new Array("className");
        sstyleval = new Array("Linktxtsmall");
    }    
    var aalign = "left";
    var vvalign = "middle";

    var meetingTopic = meeting.meetingTopic;
    var meetingKey = meeting.meetingKey;
    var meetingStatus = meeting.meetingStatus;
    var meetingTime = meeting.meetingTime;
    var role = meeting.role ;
    
    var meetingTopicHtml = meetingTopic ;
    if(meetingType == "myMeetings")
    {
        meetingTopicHtml = "<a href=\"javascript:startMeetingDetails('"+meetingTopic+"','"+meetingKey+"','"+meetingStatus+"','"+role+"','"+meetingType+"',null)\">"+meetingTopic+"</a>";
    }
    else if(meetingType == "invitedMeetings")
    {
        meetingTopicHtml = "<a href=\"javascript:joinMeetingDetails('"+meetingTopic+"','"+meetingKey+"','"+meetingStatus+"','"+role+"','"+meetingType+"',null)\">"+meetingTopic+"</a>";
    }
    createAndAddCell(ttr , meetingTopicHtml , cn , sstylename , sstyleval , aalign , vvalign );
    //createAndAddCell(ttr , meetingTime , cn , sstylename , sstyleval , aalign , vvalign );
    //createAndAddCell(ttr , meetingKey , cn , sstylename , sstyleval , aalign , vvalign );
    createAndAddCell(ttr , meetingTime , cn , sstylename , sstyleval , aalign , vvalign ,null,"2");
    createAndAddCell(ttr , role , cn , sstylename , sstyleval , aalign , vvalign );
    createAndAddCell(ttr , meetingStatus , cn ,sstylename , sstyleval , aalign , vvalign);

    if(meetingType == "myMeetings")
    {
        var startInnHtml = getStartJoinIconHtml(role,meetingStatus,meetingKey,meetingTopic,meetingType);
        createAndAddCell(ttr , startInnHtml , cn , sstylename , sstyleval , aalign , vvalign , "3%");

        var joinInnHtml;
        if(meetingStatus == "STARTED")
        {
            joinInnHtml = "<a href=\"javascript:popupJoinDiv('"+meetingKey+"','"+meetingType+"',null)\"><img src=\"images/joinicon.gif\" class=\"img\" border=\"0\" title=\""+document.getElementById("connected").innerHTML+"\"/></a>"
        }
        else if(meetingStatus == "NOTSTARTED")
        {
            joinInnHtml = "<img src=\"images/join_disabled.gif\" border=\"0\" title=\""+document.getElementById("not.connected").innerHTML+"\"/>";
        }
        createAndAddCell(ttr , joinInnHtml , cn , sstylename , sstyleval , aalign , vvalign , "4%");

        var editInnHtml = "<a href=\"javascript:displayEditView('"+meetingKey+"')\"><img src=\"images/edit.gif\" border=\"0\" title=\""+document.getElementById("edit.meeting").innerHTML+"\"/>";
        createAndAddCell(ttr , editInnHtml , cn , sstylename , sstyleval , aalign , vvalign , "3%");

        var dltInnHtml = "<a href=\"javascript:deleteMeeting('"+meetingKey+"')\"><img src=\"images/delete.gif\" border=\"0\" title=\""+document.getElementById("delete").innerHTML+"\"/></a> ";
        createAndAddCell(ttr , dltInnHtml , cn , sstylename , sstyleval , aalign , vvalign , "5%");
    }
    else if(meetingType == "invitedMeetings")
    {
        var startInnHtml = getStartJoinIconHtml(role,meetingStatus,meetingKey,meetingTopic,meetingType);
        createAndAddCell(ttr , startInnHtml , cn , sstylename , sstyleval , "center" , vvalign , null , "4");
    }
}

function getStartJoinIconHtml( role , meetingStatus , meetingKey , meetingTopic , meetingType )
{
    var innerHtmll ;
    if(role == "Presenter")
    {
        if(meetingStatus == "STARTED")
        {
             innerHtmll = "<img src=\"images/stop.gif\" border=\"0\" title=\""+document.getElementById("stop").innerHTML+"\" onclick=\"javascript:stopMeeting('"+meetingKey+"','tableView')\"/>";
        }
        else if(meetingStatus == "NOTSTARTED")
        {
            if(isWindows())
            {
                innerHtmll = "<a href=\"javascript:startMeeting('"+meetingKey+"','"+meetingTopic+"','"+meetingType+"')\"><img src=\"images/start.gif\" border=\"0\" title=\""+document.getElementById("start").innerHTML+"\"/>";
            }
            else
            {
                innerHtmll = "<img src=\"images/start.gif\" border=\"0\" title=\""+document.getElementById("need.windows.to.start.meeting").innerHTML+"\"/>";
            }
        }
    }
    else if(role == "Participant")
    {
        if(meetingType == "myMeetings")
        {
            innerHtmll = "<img src=\"images/start.gif\" border=\"0\" title=\""+document.getElementById("only.presenter.can.start.meeting").innerHTML+"\"/>";
            if(meetingStatus == "STARTED")
            {
                innerHtmll = "<img src=\"images/stop.gif\" border=\"0\" title=\""+document.getElementById("stop").innerHTML+"\" onclick=\"javascript:stopMeeting('"+meetingKey+"','tableView')\"/>";
            }
        }
        else
        {
            if(meetingStatus == "STARTED")
            {
                innerHtmll = "<a href=\"javascript:popupJoinDiv('"+meetingKey+"','"+meetingType+"',null)\"><img src=\"images/joinicon.gif\" border=\"0\" title=\""+document.getElementById("connected").innerHTML+"\"/>";
            }
            else if(meetingStatus == "NOTSTARTED")
            {
                innerHtmll = "<img src=\"images/join_disabled.gif\" border=\"0\" title=\""+document.getElementById("not.connected").innerHTML+"\"/>" ;
            }
        }
    }
    return innerHtmll;
}

function createAndAddCell( ttrow , innerContent , cclassName , sstylename , sstyleval ,  aalign , vvalign , width ,ccolspan)
{
    var cell1 = document.createElement("td");
    cell1.innerHTML = innerContent;
    if(cclassName)
    {
        cell1.className = cclassName;
    }
    if(sstylename && sstyleval)
    {
        var ln = sstylename.length;
        for(var i = 0 ; i < ln ; i++ )
        {
            var prop = sstylename[i];
            if(prop == "borderBottom")
            {
                cell1.style.borderBottom = sstyleval[i];
            }
            else if(prop == "borderTop")
            {
                cell1.style.borderTop = sstyleval[i];
            }
            else if(prop == "paddingBottom")
            {
                cell1.style.paddingBottom = sstyleval[i];
            }else if(prop=="className" )
            {
                cell1.className=sstyleval[i];
            }    
        }
    }
    if(aalign)
    {
        cell1.align = aalign;
    }
    if(vvalign)
    {
        cell1.verticalAlign = vvalign;
    }
    if(width)
    {
        cell1.width = width;
    }
    if(ccolspan)
    {
        cell1.colSpan = ccolspan;
    }
    ttrow.appendChild(cell1);
}

function addColumnHeader( ttbody , type ,tableHeaderLabelMssg)
{
    if(type == "myMeetings" || type == "invitedMeetings")
    {
        var ttr = document.createElement("tr");
        ttbody.appendChild(ttr);

        var cn = "meetinginfo";
        var sstylename = new Array("borderBottom","borderTop","className");
        var sstyleval = new Array("1px solid #74C6ED","1px solid #74C6ED","ColumnHeader");
        var aalign = "left";
        var vvalign = "middle";

        createAndAddCell(ttr , document.getElementById("topic").innerHTML , cn , sstylename , sstyleval , aalign , vvalign , "30%");
        //createAndAddCell(ttr , "Time" , cn , sstylename , sstyleval , aalign , vvalign , "17%");
        //createAndAddCell(ttr , "Meeting Key" , cn , sstylename , sstyleval , aalign , vvalign );
        createAndAddCell(ttr , document.getElementById("time").innerHTML , cn , sstylename , sstyleval , aalign , vvalign , "20%" , "2");
        createAndAddCell(ttr , document.getElementById("role").innerHTML , cn , sstylename , sstyleval , aalign , vvalign , "15%");
        createAndAddCell(ttr , document.getElementById("status").innerHTML , cn , sstylename , sstyleval , aalign , vvalign , "15%");
        createAndAddCell(ttr , "<a href=\"javascript:refreshMeetings('"+type+"')\"><img src=\"images/refresh.gif\" border=\"0\" title=\""+document.getElementById("refresh").innerHTML+"\"/></a>" , cn , sstylename , sstyleval , "center" , vvalign , "20%" , "4");
            
    }
}

function addOptionsHeader(ttbody,tableHeaderLabelMssg)
{
    var ttr = document.createElement("tr");
    ttbody.appendChild(ttr);

    var cn = "meetingcontent";
    var sstylename = new Array("paddingBottom");
    var sstyleval = new Array("10px");
    var aalign = "left";
    var vvalign = "middle";

    var divEle = "<div class=\"BoldTextsmall\" id=\"tableHeaderLabel\">"+tableHeaderLabelMssg+"</div>";
    createAndAddCell(ttr , divEle , cn , sstylename , sstyleval , aalign , vvalign , null  );

    var calendarInnHtml = "<input type=\"hidden\" id=\"selectedDate_TF\"><span class=\"Linktxtsmall\"><a href=\"javascript:callCalendar('selectedDate_TF','calender','tableView')\"><img src=\"images/icon_sched.gif\" align=\"absmiddle\" id=\"calender\" alt=\"Date Chooser\" class=\"img\" title=\""+document.getElementById("select.date").innerHTML+"\" /> "+document.getElementById("select.date").innerHTML +"</span></a>";
    createAndAddCell(ttr , calendarInnHtml , cn , sstylename, sstyleval , "right" , vvalign );
    var optionInHtml = " <span class=\"Linktxtsmall\"><a href=\"javascript:formMeetingsTable('"+currentlySelectedMeetingType+"',false)\"><img src=\"images/icon_back.gif\" class=\"img\" align=\"absmiddle\"/> &nbsp; "+document.getElementById("all").innerHTML+"</a> | <a href=\"javascript:showTodayMeetings()\">"+document.getElementById("today").innerHTML+"&nbsp; <img class=\"img\" src=\"images/icon_next.gif\" align=\"absmiddle\"/></a> </span>";
    createAndAddCell(ttr , optionInHtml , cn , sstylename, sstyleval , "right" , vvalign , null );
        
}

function createMeeting(action , meetingKey , existingParticipants , existingPresenter , existingTopic , existingTime)
{
    var ttopic = getElementValue("topic_create_TF", "text" , true);
    if(!validateUserInput(ttopic))
    {
        alert(document.getElementById("provide.meeting.topic").innerHTML);
        setFocus(document.getElementById("topic_create_TF"));
        return false;
    }
    var ttime = getCreateTime(true);
    var mailTime = getCreateTime(false);
    var agenda = getElementValue("agenda_create_TF" , "text" , true);
    var presenterMailId = getElementValue("presenter_mailid_create_TF" , "text" , false);
    if(!validateUserInput(presenterMailId))
    {
        alert(document.getElementById("presenter.emailid.mandatory").innerHTML);
        setFocus(document.getElementById("presenter_mailid_create_TF"));
        return false;
    }
    if(!checkEMail(presenterMailId))
    {
        alert(document.getElementById("enter.valid.presenter.emailid").innerHTML);
        setFocus(document.getElementById("presenter_mailid_create_TF"));
        return false;
    }
    var participantsMailId = getCreateParticipantsId('string');
    if(!checkMultipleEMailIds(participantsMailId))
    {
        alert(document.getElementById("enter.valid.participant.emailid").innerHTML);
        return false;
    }
    var controlTransfer = getCreateControlTransfer();
    var timeZone = tzVsShortForm[configuredTimezone];
    //alert("Topic::"+ttopic+"::Time::"+ttime+"::agda::"+agenda+"::prMailId::"+presenterMailId+"::CT::"+controlTransfer);
    //alert("participantMailID::"+participantsMailId);

    try
    {
        disableEnableButton("createMeetingButton", true);
        var urll = "";
        if(action == "create")
        {
            showLoadingDiv(document.getElementById("creating").innerHTML+"...");
            urll = contextPath + '/zohomeeting.do?method=createMeeting';
            urll = urll + "&ttopic=" + ttopic +" &ttime="+ttime+"&agenda="+agenda+"&presenter="+presenterMailId+"&participants="+participantsMailId+"&ct="+controlTransfer+"&timeZone="+timeZone+"&userName="+userName+"&mailTime="+mailTime;
            sendAsyncAJAXRequest('GET', urll , handleCreateMeeting);
        }
        else if(action == "edit")
        {
            showLoadingDiv(document.getElementById("saving").innerHTML+"...");
            urll = contextPath + '/zohomeeting.do?method=editMeeting';
            urll = urll + "&ttopic=" + ttopic +" &ttime="+ttime+"&agenda="+agenda+"&presenter="+presenterMailId+"&participants="+participantsMailId+"&ct="+controlTransfer+"&timeZone="+timeZone+"&userName="+userName+"&mailTime="+mailTime+"&meetingKey="+meetingKey+"&existingParticipants="+existingParticipants+"&extPresenter="+existingPresenter+"&extTopic="+existingTopic+"&extTime="+existingTime;
            sendAsyncAJAXRequest('GET', urll , handleEditMeeting);
        }
    }
    catch(e)
    {
        alert(e);
    }
}


function handleCreateMeeting(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(document.getElementById("unable.to.create.meeting").innerHTML);
            disableEnableButton("createMeetingButton", false);
            hideLoadingDiv();
            return;
        }
        var evalRsp = eval('('+rsp+')');
        var result = evalRsp.response.result;
        if(result)
        {
            var kkey = result.meeting.meetingKey;
            var ttopic = getElementValue("topic_create_TF", "text" , false);
            var ttime = getCreateTime(false);
            var agenda = getElementValue("agenda_create_TF" , "text" , false);
            var presenterMailId = getElementValue("presenter_mailid_create_TF" , "text" , false);
            var participants = getCreateParticipantsId('array');
            var ct = getCreateControlTransfer();
            var timezone = "";
            var sstatus = "NOTSTARTED";
            var role = "Participant";
            if(trim(presenterMailId) == trim(userMailId))
            {
                role = "Presenter";
            }

            MyMeetingsDB[MyMeetingsDB.length] = new MyMeeting(ttopic,kkey,sstatus,
                       ttime,timezone,agenda,role,participants,presenterMailId,ct);
            formMeetingsTable("myMeetings",false);
        }
        else
        {
            alert(document.getElementById("unable.to.create.meeting").innerHTML);
        }
        disableEnableButton("createMeetingButton", false);
        hideLoadingDiv();
    }
}

function handleEditMeeting(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(document.getElementById("unable.to.edit.meeting").innerHTML);
            disableEnableButton("createMeetingButton", false);
            hideLoadingDiv();
            return;
        }
        var evalRsp = eval('('+rsp+')');
        var result = evalRsp.response.result;
        if(result)
        {
            var message = result.meeting;
            if(message == "Updated successfully")
            {
                var kkey = getElementValue("meetingKey_edit_span","text",false);
                var ttopic = getElementValue("topic_create_TF", "text" , false);
                var ttime = getCreateTime(false);
                var agenda = getElementValue("agenda_create_TF" , "text" , false);
                var presenterMailId = getElementValue("presenter_mailid_create_TF" , "text" , false);
                var participants = getCreateParticipantsId('array');
                var ct = getCreateControlTransfer();
                var timezone = "";
                var sstatus = "NOTSTARTED";
                var role = "Participant";
                if(trim(presenterMailId) == trim(userMailId))
                {
                    role = "Presenter";
                }
                
                var meetingObj = getMeetingObjectFromClient(kkey,"myMeetings");
                //If the client data is stored at the client end at this stage
                if(meetingObj != null)
                {
                    meetingObj.meetingTopic = ttopic;
                    meetingObj.presenter = presenterMailId;
                    meetingObj.agenda = agenda;
                    meetingObj.role = role;
                    meetingObj.meetingTime = ttime;
                    meetingObj.participantsList = participants;
                    meetingObj.controlTransfer = ct;
                }
                //else, the user lands on directly on the start meeting view and performing edit
                formMeetingsTable("myMeetings",false);
            }
            else
            {
                alert(document.getElementById("unable.to.edit.meeting").innerHTML);
            }
        }
        else
        {
            alert(document.getElementById("unable.to.edit.meeting").innerHTML);
        }
        disableEnableButton("createMeetingButton", false);
        hideLoadingDiv();
    }
}

function getCreateTime(inMillis)
{
    var ddate = getElementValue("date_create_TF" , "text" , true);
    var hhours = getElementValue("hoursCombo_create_TF", "combo" , true);
    var mminutes = getElementValue("minutesCombo_Create_TF" , "combo" , true);

    var mdform = document.meridiemForm.meridiem_create_radio;
    for(var i = 0 ; i < mdform.length ; i++ )
    {
        if(mdform[i].checked == true)
        {
            var val = mdform[i].value;
            if(val == "PM")
            {
                if(hhours != "12")
                {
                    hhours = 1*(hhours) + 12;
                }
            }
            else if(val == "AM")
            {
                if(hhours == "12")
                {
                    hhours = "00";
                }
            }
        }
    }
    var ttime =  ddate+" "+hhours+":"+mminutes;


    if(inMillis)
    {
        var darr = ddate.split("-");
        ttime = darr[0] + "-"+darr[1] + "-"+darr[2] + " "+hhours+":"+mminutes;
    }
    //returning in the format of "Month date, year hh:min"
    else
    {

        var darr = ddate.split("-");
        var mnth = monthArr_Shot[((darr[1] - 1))];
		var ddtt = darr[2];
		if(ddtt.length == 1)
		{
			ddtt = "0" + ddtt;
		}
        ttime = mnth+" "+ddtt+", "+darr[0]+" "+hhours+":"+mminutes; 
    }
    return ttime;
}

function getCreateParticipantsId(returnType)
{
    var ln = document.getElementById('ParticipantEmailBody').childNodes.length;
    if(returnType == "array")
    {
        var arr = new Array();
        for(var i = 1 ; i <= ln ; i++ )
        {
            var idd = "participant_"+i+"_create_TF";
            var idVal = getElementValue(idd, "text" , false);
            if(idVal && trim(idVal) != "" && trim(idVal) != "Enter Email ID")
            {
                arr[arr.length] = idVal;
            }
        }
        return arr;
    }
    else
    {
        var str = "";
        for(var i = 1 ; i <= ln ; i++ )
        {
            var idd = "participant_"+i+"_create_TF";
            var idVal = getElementValue(idd, "text" , false);
            if(idVal && trim(idVal) != "" && trim(idVal) != "Enter Email ID")
            {
                if(trim(str) != "")
                {
                    str = str+","+idVal;
                }
                else
                {
                    str = idVal;
                }
            }
        }
        return str;
    }
}

function getCreateControlTransfer()
{
    var ct = "";
    var ctForm = document.createControlTransferForm.agentType_create_TF;
    for( var i = 0 ; i < ctForm.length ; i++ )
    {
        if(ctForm[i].checked == true )
        {
           ct = ctForm[i].value;
        }
    }
    return ct;
}

function deleteMeeting(meetingKey)
{
    try
    {
        if(!confirm(document.getElementById("confirm.delete.meeting").innerHTML))
        {
            return;
        }
        showLoadingDiv(document.getElementById("deleting.please.wait").innerHTML+"...");
        var urll = contextPath + '/zohomeeting.do?method=deleteMeeting' ;
        urll = urll + "&kkey="+meetingKey;
        recentMKToBeDeleted = meetingKey ; 
        sendAsyncAJAXRequest('GET', urll , handleDeleteMeeting);
    }
    catch(e)
    {
        alert("deleteMeeting::"+e);
    }
}

function handleDeleteMeeting(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(document.getElementById("unable.to.delete.meeting").innerHTML);
            hideLoadingDiv();
            return;
        }
        var evalRsp = eval('('+rsp+')');
        var rslt = evalRsp.response.result;
        if(rslt)
        {
            var isDeleted = rslt.meeting.is_deleted;
            
            //Deletes the meeting from DB and view
            removeMeetingRef(recentMKToBeDeleted);

            //Making the recentMKToBeDeleted  to ""
            recentMKToBeDeleted = "";
        }
        else
        {
            alert(document.getElementBuId("unable.to.delete.meeting").innerHTML);
        }
        hideLoadingDiv();
    }
}

function removeMeetingRef(kkey)
{
    var ln = MyMeetingsDB.length;
    for(var ij = 0 ; ij < ln ; ij++ )
    {
         var meetingKey = MyMeetingsDB[ij].meetingKey;
         if(meetingKey == kkey)
         {
             MyMeetingsDB.splice(ij,1);
             break;
         }
    }
    formMeetingsTable("myMeetings",false);
}


function joinMeetingDetails(ttopic , kkey , sstatus , role , meetingType , axn)
{
    document.getElementById("join_meetingTopic_span").innerHTML = ttopic;
    document.getElementById("join_meetingKey_span").innerHTML = kkey;
    document.getElementById("join_meetingStatus_span").innerHTML = sstatus;
    var ttime = "";
    var agenda = "";
    var presenter = "";
    if(axn != "join")
    {
        var meetingObj = getMeetingObjectFromClient( kkey ,"invitedMeetings");
        ttime = meetingObj.meetingTime;
        agenda = meetingObj.agenda;
        presenter = meetingObj.presenter;
       document.getElementById("joinMeetingButton").innerHTML = getStartJoinDetailsHtml( role , sstatus , kkey , ttopic , meetingType);
    }
    else
    {
        //fetching details from server
        try
        {
            var rsp = getMeetingDetails(kkey);
            ttime = rsp.meeting_date;
            agenda = rsp.meeting_agenda;
            presenter = rsp.meeting_presenter;
        }
        catch(e)
        {
            alert(document.getElementById("unable.to.fetch.meeting.details").innerHTML);
        }
        document.getElementById("join_downloadAgentIcon_span").innerHTML = "<span><a href=\"javascript:downloadAgentZip('"+kkey+"')\"><img src=\""+contextPath+"/images/download_zip_button.gif\" style=\"padding-right:5px;\"/></a></span>";
        document.getElementById("join_downloadAgentLink_span").innerHTML = "<span>If START fails,<a href=\"javascript:downloadAgentZip('"+kkey+"')\"> download this zip</a>.. <br /> Unzip and start ZohoMeeting.exe </span>";

        document.getElementById("joinMeetingButton").innerHTML = "<input name=\"login2\" class=\"btn\" value=\""+document.getElementById("start").innerHTML+"\" type=\"submit\" disabled/>"; 
    }
    
    //
    document.getElementById("join_meetingDateAndTime_span").innerHTML = ttime ;
    document.getElementById("join_agenda_span").innerHTML = agenda;
    document.getElementById("join_presenter_span").innerHTML = presenter;


    showDiv("joinMeetingDiv",true);
    if(axn == "join")
    {
        showInstructionImage();
    }
    performStatusPolling(kkey,"invitedMeetings",ttopic,role);
}


function startMeetingDetails(ttopic , kkey , sstatus , role , meetingType ,axn )
{
    document.getElementById("meetingTopic_span").innerHTML = ttopic;
    document.getElementById("meetingKey_span").innerHTML = kkey;
    document.getElementById("meetingStatus_span").innerHTML = sstatus;
    var ttime = "" ;
    var agenda = "" ;
    var presenter = "";
    var participants = new Array();
    //Fetching data internally from the MyMeetingsDB
    if(axn != "start" && axn != "view")
    {
       var meetingObj = getMeetingObjectFromClient( kkey , 'myMeetings');
       ttime = meetingObj.meetingTime;
       agenda = meetingObj.agenda;
       presenter = meetingObj.presenter;
       participants = meetingObj.participantsList.toString();

       document.getElementById("startMeetingButton").innerHTML = getStartJoinDetailsHtml( role , sstatus , kkey , ttopic , meetingType);
    }
    else
    {
        //fetching details from server
        try
        {
            var rsp = getMeetingDetails(kkey);
            ttime = rsp.meeting_date;
            agenda = rsp.meeting_agenda;
            presenter = rsp.meeting_presenter;
            participants = rsp.meeting_participants.toString();
        }
        catch(e)
        {
            alert(document.getElementById("unable.to.fetch.meeting.details").innerHTML);
        }
        if(axn == "view")
        {
            document.getElementById("startMeetingButton").innerHTML = getStartJoinDetailsHtml( role , sstatus , kkey , ttopic , meetingType);
        }
        else
        {
            document.getElementById("downloadAgentIcon_span").innerHTML = "<span><a href=\"javascript:downloadAgentZip('"+kkey+"')\"><img src=\""+contextPath+"/images/download_zip_button.gif\" style=\"padding-right:5px;\"/></a></span>";
            document.getElementById("downloadAgentLink_span").innerHTML = "<span>If START fails,<a href=\"javascript:downloadAgentZip('"+kkey+"')\"> download this zip</a>.. <br /> Unzip and start ZohoMeeting.exe </span>";

            document.getElementById("startMeetingButton").innerHTML = "<input name=\"login2\" class=\"btn\" value=\""+document.getElementById("start").innerHTML+"\" onclick=\"#\" type=\"submit\" disabled/>";
        }
    }

    document.getElementById("meetingDateAndTime_span").innerHTML = ttime;
    document.getElementById("agenda_span").innerHTML = agenda;
    document.getElementById("presenter_span").innerHTML = presenter;
    document.getElementById("viewLink").href = "javascript:showViewParticipant('"+participants+"')";
    document.getElementById("inviteLink").href = "javascript:showInviteMeeting('"+kkey+"')";
    document.getElementById("editMeetingLink").href = "javascript:displayEditView('"+kkey+"')";
    showDiv("startMeetingDiv",true);
    if(axn == "start")
    {
       showInstructionImage();
    }
    performStatusPolling(kkey,meetingType,ttopic,role);
}

function getMeetingObjectFromClient(meetingKey , meetingType)
{
    var meetingArr = new Array();
    if(meetingType == "myMeetings")
    {
        meetingArr = MyMeetingsDB;
    }
    else if(meetingType == "invitedMeetings")
    {
        meetingArr = InvitedMeetingsDB;
    }

    var ln = meetingArr.length;
    if(ln > 0)
    {
        for(var i = 0 ; i < ln ; i++ )
        {
            if(meetingKey == meetingArr[i].meetingKey)
            {
                return meetingArr[i];
            }
        }
    }
    return null;
}

function startMeeting(meetingKey,topic,meetingType)
{
    //window.open(contextPath+"/jsp/startmeeting.jsp?meetingKey="+meetingKey,"_blank");
    window.open(contextPath+"/zohomeeting.do?operation=start&key="+meetingKey+"&topic="+topic+"&meetingType="+meetingType,"_top");
}

function removeFrame()
{
    var divEle = document.getElementById("startMeetingIframe");
    document.body.removeChild(divEle);
}

function showAgendaTA()
{
    hideDiv("AddLink");
    showDiv("AgendaTA",false);
}

function showDiv(divName , hideOthers)
{
    if(hideOthers)
    {
        var ln = divArray.length;
        for(var i = 0 ; i < ln ; i++ )
        {
            var divvvName = divArray[i];
            if(divvvName != divName)
            {
                hideDiv(divvvName);
            }
        }
    }
    //Making the particular tab selected and placing arrow. And content change.
    if(divName == "createMeetingsDiv")
    {
        currentlySelectedMeetingType = "createMeeting";
       // document.getElementById("txtheaderContentDiv").style.display = "none";
        //document.getElementById("createMeatingsHeader").style.display = "block";
        document.getElementById("createMeetingTab").className="topmenuOffBg";
        document.getElementById("myMeetingsTab").className="topmenuOnBg";
        document.getElementById("invitedMeetingsTab").className="topmenuOnBg";
        document.getElementById("createMeetingArrow").className="arrow";
        document.getElementById("myMeetingArrow").className="arrowoff";
        document.getElementById("invitedMeetingArrow").className="arrowoff";
       document.getElementById("presenter_mailid_create_TF").value=userMailId;
        // to disable status polling
        performStatusPolling("","","","");
    }
    else if(divName == "startMeetingDiv" || divName == "myMeetingsDiv")
    {
        currentlySelectedMeetingType = "myMeetings";
        //document.getElementById("createMeatingsHeader").style.display = "none";
        document.getElementById("headerContentDiv").style.display = "block";
        if(divName == "startMeetingDiv")
        {
            document.getElementById("headerContentDiv").innerHTML=document.getElementById("meeting.details").innerHTML; 
        }
        else
        {
            document.getElementById("headerContentDiv").innerHTML=document.getElementById("my.meetings").innerHTML; 
        }
        document.getElementById("createMeetingTab").className="topmenuOnBg";
        document.getElementById("myMeetingsTab").className="topmenuOffBg";
        document.getElementById("invitedMeetingsTab").className="topmenuOnBg";
        document.getElementById("createMeetingArrow").className="arrowoff";
        document.getElementById("myMeetingArrow").className="arrow";
        document.getElementById("invitedMeetingArrow").className="arrowoff";
        // to disable status polling
        performStatusPolling("","","","");
    }
    else if(divName == "invitedMeetingsDiv")
    {
        currentlySelectedMeetingType = "invitedMeetings";
        document.getElementById("headerContentDiv").style.display = "block";
        //document.getElementById("createMeatingsHeader").style.display = "none";
        document.getElementById("headerContentDiv").innerHTML=document.getElementById("invited.meetings").innerHTML; 
        document.getElementById("createMeetingTab").className="topmenuOnBg";
        document.getElementById("myMeetingsTab").className="topmenuOnBg";
        document.getElementById("invitedMeetingsTab").className="topmenuOffBg";
        document.getElementById("createMeetingArrow").className="arrowoff";
        document.getElementById("myMeetingArrow").className="arrowoff";
        document.getElementById("invitedMeetingArrow").className="arrow";
        // to disable status polling
        performStatusPolling("","","","");
    }
    var divEle = document.getElementById(divName);
    if(divEle)
    {
        divEle.style.display = "block";
    }
}

function hideDiv(divName )
{
    var divEle = document.getElementById(divName);
    if(divName == "createMeetingsDiv")
    {
    }
    if(divEle)
    {
        divEle.style.display = "none";
    }
}

function callCalendar(inpField, but , fromView)
{
    //used while select meeting with the selected date functionality form table views
    if(fromView == "tableView")
    {
        var obj = document.getElementById("myMeetingsTab");
        posX = findPosX(obj)-180;
        posY = findPosY(obj)-120;
        Calendar.setup({ 
            inputField     :    inpField,                // id of the input field
            ifFormat       :    "%Y-%m-%d",       // format of the input field
            button         :    but,         // trigger for the calendar (button ID)
            align          :    "Tl",           // alignment (defaults to "Bl")
            position       :    [posX,posY], 
            onClose        :    onChangeInSelectedDate
         });
    }
    //used while creating a meeting
    else
    {
        Calendar.setup({ 
            inputField     :    inpField,                // id of the input field
            ifFormat       :    "%Y-%m-%d",       // format of the input field
            button         :    but,         // trigger for the calendar (button ID)
            align          :    "Tl"           // alignment (defaults to "Bl")
         });
    }
}

function onChangeInSelectedDate()
{
    window.calendar.hide();
    var dddate = document.getElementById("selectedDate_TF").value;
    if(dddate)
    {
       formMeetingsTable(currentlySelectedMeetingType,true); 
    }
}

function joinMeeting(meetingKey,meetingType)
{
    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;
            }
        }
    }
    
    window.open(contextPath+"/zohomeeting.do?operation=join&viewerType="+selected+"&key="+meetingKey+"&meetingType="+meetingType+"&email="+userMailId,"_top");
}

function popupJoinDiv(meetingKey , meetingType , objectName )
{
     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=\"images/icon_cancel.gif\" border=\"0\" class=\"imgcancel\" title=\""+document.getElementById("close").innerHTML+"\"/></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=\""+document.getElementById("join").innerHTML+"\" onclick=\"javascript:joinMeeting('"+meetingKey+"','"+meetingType+"')\"> </td></tr><tr><td colspan=\"2\">&nbsp;&nbsp;</td></tr>"+
                   "</table>";

     divEle.innerHTML = innerHttml;
     var pointXX = lastMouseClickX - 80;
     var pointYY = lastMouseClickY;
     if(objectName && objectName != null)
     {
         var objectEle = document.getElementById(objectName);
         pointXX = findPosX(objectEle)-200;
         pointYY = findPosY(objectEle)-115;
     }
     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 getStartJoinDetailsHtml( role , meetingStatus , meetingKey , meetingTopic , meetingType)
{
    var link1_name ;
    var link2_name ;
    if(meetingType == "myMeetings")
    {
        link1_name = "downloadAgentIcon_span";
        link2_name = "downloadAgentLink_span";
    }
    else if(meetingType == "invitedMeetings")
    {
        link1_name = "join_downloadAgentIcon_span";
        link2_name = "join_downloadAgentLink_span";
    }
        
    document.getElementById(link1_name).innerHTML = "";
    document.getElementById(link2_name).innerHTML = "";

    var inHHtml = "";
    if(role == "Presenter")
    {
         if( meetingStatus == "STARTED")
         {
             inHHtml = "<input name=\"login2\" class=\"btn\" value=\""+document.getElementById("stop").innerHTML+"\" type=\"submit\" onclick=\"javascript:stopMeeting('"+meetingKey+"','detailsView')\"/>";
         }
         else if(meetingStatus == "NOTSTARTED")
         {
             if(isWindows())
             {
                 inHHtml = "<input name=\"login2\" class=\"btn\" value=\""+document.getElementById("start").innerHTML+"\" onclick=\"javascript:startMeeting('"+meetingKey+"','"+meetingTopic+"','"+meetingType+"')\" type=\"submit\"/>";
                 document.getElementById(link1_name).innerHTML = "<span><a href=\"javascript:downloadAgentZip('"+meetingKey+"')\"><img src=\""+contextPath+"/images/download_zip_button.gif\" style=\"padding-right:5px;\"/></a></span>";
                 document.getElementById(link2_name).innerHTML = "<span>If START fails,<a href=\"javascript:downloadAgentZip('"+meetingKey+"')\"> download this zip</a>.. <br /> Unzip and start ZohoMeeting.exe </span>";
             }
             else
             {
                 inHHtml = "<span class=\"addheader\">"+document.getElementById("presenter.to.be.in.windows").innerHTML+"!</span>";
             }
         }
    }
    else if(role == "Participant")
    {
         if( meetingStatus == "STARTED")
         {
             inHHtml = "<input name=\"login2\" id=\"joinButtonId\" class=\"btn\" value=\""+document.getElementById("join").innerHTML+"\" type=\"submit\" onclick=\"javascript:popupJoinDiv('"+meetingKey+"','"+meetingType+"','joinButtonId')\"/>";
         }
         else if(meetingStatus == "NOTSTARTED")
         {
             inHHtml = "<input name=\"login2\" class=\"btn\" value=\""+document.getElementById("join").innerHTML+"\" type=\"submit\" disabled/>";
         }
    }
    return inHHtml;
}

function refreshMeetings(meetingType)
{
    if(meetingType == "myMeetings")
    {
         isMyMeetingFirstTime = true;
         formMeetingsTable(meetingType,false);
    }
    else if(meetingType == "invitedMeetings")
    {
       isInvitedMeetingFirstTime = true;
       formMeetingsTable(meetingType,false);
    }
}

function getElementValue(eleId , type , encode )
{
    var ele = document.getElementById(eleId);
    var val ;
    if(type == "text")
    {
       val = ele.value;
    }
    else if(type == "combo")
    {
        val = ele.options[ele.selectedIndex].value;
    }

    if(val && encode)
    {
       return encodeURIComponent(val);
    }
    return val;
}

function validateUserInput( str )
{
    if(str && trim(str) != "" )
    {
        return true;
    }
    return false;
}

function showViewParticipant(participants)
{
    var innHtml = "";
    if(participants && trim(participants) != "")
    {
        var arr = participants.split(",");
        for(var i = 0 ; i < arr.length ; i++ )
        {
            if(trim(innHtml) == "")
            {
                innHtml = arr[i];
            }
            else
            {
               innHtml = innHtml + "<br>"+arr[i];
            }
        }
    }
    var divEle = document.getElementById("viewParticipantsDiv");
    divEle.innerHTML = innHtml;
    var pointXX = lastMouseClickX;
    var pointYY = lastMouseClickY;
    divEle.classname = "tagmenu";
    divEle.style.right = "";
    divEle.style.left = pointXX;
    divEle.style.top = pointYY;
    divEle.style.width = "200";
    divEle.style.height = "100";
    divEle.style.position = "absolute";
    divEle.style.display = "block";
    divEle.style.backgroundColor = "#b8d4ec";
}

function fetchMailId()
{
    var userid = getCookieValue(readCookie('USERID'));
    if(userid)
    {
        try
        {
            sendAsyncAJAXRequest('GET' , 
               contextPath+"/zohomeeting.do?method=getEMailId&userId="+userid , handleMailId );
        }
        catch(e)
        {
        }
    }
}

function handleMailId(xmlhttp)
{
    if(xmlhttp.readyState == 4)
    {
        var rsp = xmlhttp.responseText;
        userMailId = trim(rsp);
    }
}

function displayCreateView()
{
    showDiv('createMeetingsDiv',true);
    setDataInCreateMeetingView(null, 'create' );
}

function displayEditView(meetingKey)
{
   showDiv('createMeetingsDiv',true);
   setDataInCreateMeetingView(meetingKey, 'edit' );
}

function setDataInCreateMeetingView( meetingKey , viewType )
{
    var ttopic = "Meeting Topic";
    var agenda = "";
    var ttime = "";
    var presenterMailId = userMailId;
    var controlTrnsfr = "prompt";
    var participant = new Array();
    if(viewType == "edit")
    {
        var meetingObj = getMeetingObjectFromClient(meetingKey , "myMeetings");
        //If the meeting data is stored at client end 
        if(meetingObj != null)
        {
            ttopic = meetingObj.meetingTopic;
            agenda = meetingObj.agenda;
            ttime =  meetingObj.meetingTime;
            presenterMailId = meetingObj.presenter;
            controlTrnsfr = meetingObj.controlTransfer;
            participant = meetingObj.participantsList;
        }
        //If the user lands directly on start meeting view 
        //and performing the edit operation
        else
        {
            try
            {
                var rsp = getMeetingDetails(meetingKey);
                ttopic = rsp.meeting_topic;
                ttime = rsp.meeting_date;
                agenda = rsp.meeting_agenda;
                presenterMailId = rsp.meeting_presenter;
                participant = rsp.meeting_participants;
                controlTransfer = rsp.agent_type;
            }
            catch(e)
            {
                alert(document.getElementById("unable.to.fetch.meeting.details").innerHTML+e);
            }

        }
    }

        document.getElementById("topic_create_TF").value = ttopic;

        //Time
        setCreateTime(viewType , ttime )

        //Agenda
        document.getElementById("agenda_create_TF").value = agenda;
        if(trim(agenda) == "")
        {
           showDiv('AddLink',false);
           hideDiv('AgendaTA');
        }
        else
        {
            showDiv('AgendaTA',false);
            hideDiv('AddLink');
        }

        //Presenter mail id
        document.getElementById("presenter_mailid_create_TF").value = presenterMailId;

        //
        setParticipantTable(participant);

        //control transfer
        setControlTransfer(controlTrnsfr);
        
        //
        disableEnableButton("createMeetingButton", false);
            var divEle = document.getElementById("createButton_span");
        
        if(viewType == "edit")
        {
           divEle.innerHTML = "<input name=\"Create\" type=\"submit\" class=\"btnStyle\" onclick=\"javascript:createMeeting('edit','"+meetingKey+"','"+participant.toString()+"','"+presenterMailId+"','"+ttopic+"','"+ttime+"')\" id=\"createMeetingButton\" class=\"btn\" value=\""+document.getElementById("save").innerHTML+"\" title=\""+document.getElementById("host.meeting").innerHTML+"\"/><input type=\"hidden\" id=\"meetingKey_edit_span\" value=\""+meetingKey+"\">";
        }
        else
        {
           divEle.innerHTML = "<input name=\"Create\" type=\"submit\" class=\"btnStyle\" onclick=\"javascript:createMeeting('create',null,null,null,null,null)\" id=\"createMeetingButton\"  value=\""+document.getElementById("create").innerHTML+"\" title=\""+document.getElementById("host.meeting").innerHTML+"\"/>";
        }
}

function setCreateTime(viewType , ttime )
{
    var dd = new Date();
    
    //Getting the equivalent time with respect to the configured
    //timezone
    var temp_set = dd.getTime();
    temp_set = temp_set + offSetWithRespectToSystemTime;
    dd.setTime(temp_set);
    //

    var yr = dd.getFullYear();
    var mn = dd.getMonth() + 1 ;
    var dt = dd.getDate();
    var hr = dd.getHours();
    var min = dd.getMinutes();



    var meridiem = "AM";

    if(viewType == 'edit')
    {
        var ttimeArr = ttime.split(" ");
        var mnthth = ttimeArr[0];
        for(var ij = 0 ; ij < monthArr_Shot.length ; ij++ )
        {
            if(mnthth == monthArr_Shot[ij])
            {
                mn = ij+1;
                break;
            }
        }
        yr = ttimeArr[2];
        dt = (ttimeArr[1].split(","))[0];
        hr = (ttimeArr[3].split(":"))[0];
        min = (ttimeArr[3].split(":"))[1];
    }

    var ddate = yr+"-"+mn+"-"+dt;
    document.getElementById("date_create_TF").value = ddate;

    if(hr >= 12)
    {
        hr = 1*(hr)-12;
        meridiem = "PM";
    }

    if( hr == 00)
    {
        hr = 11;
    }
    else 
    {
        hr = hr-1;
    }

    min = min/5;

    //
    var ele = document.getElementById("hoursCombo_create_TF");
    //ele.options[ele.selectedIndex].text = hr;
    ele.selectedIndex = hr;
    var minele = document.getElementById("minutesCombo_Create_TF");
    minele.selectedIndex = min;

    var mdform = document.meridiemForm.meridiem_create_radio;
    for(var i = 0 ; i < mdform.length ; i++ )
    {
        if(mdform[i].value == meridiem)
        {
            mdform[i].checked = "true";
        }
    }
}

function setControlTransfer(val)
{
    var ctform = document.createControlTransferForm.agentType_create_TF;
    for(var i = 0 ; i < ctform.length ; i++ )
    {
        if(ctform[i].value == val)
        {
            ctform[i].checked = "true";
        }
    }
}

function getMeetingDetails(meetingKey)
{
    try
    {
        var urll = contextPath+"/zohomeeting.do?method=getMeetingDetails&key="+meetingKey;
        var mainResponse = sendSyncAJAXRequest('GET',urll,'Text');
        var resp = eval('('+mainResponse+')');
        if(resp.response.result)
        {
            var meeting = resp.response.result.meetings.meeting;
            var agenda = meeting.meeting_agenda;
            if(agenda === true)
            {
                meeting.meeting_agenda = "";
            }

            var participants = new Array();

            //
            var participantsList = meeting.meeting_participants;
            if(participantsList && participantsList.meeting_participant)
            {
                participantsList = participantsList.meeting_participant;
                //only one participant
                if(participantsList.length == null || participantsList.length == 0)
                {
                    participants[0] = participantsList.emailid;
                }
                //participants in array - object
                else
                {
                    var ln = participantsList.length ;
                    for(var i = 0 ; i< ln ; i++ )
                    {
                        participants[participants.length] = participantsList[i].emailid;
                    }
                }
            }
            //
            meeting.meeting_participants = participants;
            meeting.meeting_presenter = meeting.meeting_presenter.emailid;

            return meeting;
        }
        else
        {
            throw new Exception();
        }
    }
    catch(e)
    {
        alert("exception:::"+e);
        throw e;
        
    }
}

function showLoadingDiv(message)
{
    var divEle = document.getElementById("loadingDiv");
    divEle.innerHTML = "&nbsp;"+message+"&nbsp; "+loadingImg+" &nbsp;";
    divEle.style.top = lastMouseClickY;
    divEle.style.left = lastMouseClickX;
    divEle.classname = "tagmenu";
    divEle.style.display = "block";
}

function hideLoadingDiv()
{
    hideDiv("loadingDiv");
}

function disableEnableButton(buttonName , disable)
{
    var but = document.getElementById(buttonName);
    if(but)
    {
        but.disabled = disable;
    }
}

function startStatusPolling()
{
    if(trim(doStatusPollingForKey) != "")
    {
        //In case of user landing on start meeting view
        //meetingkey and meetingType values are set in the meeting.jsp 
        //when this method is getting triggered.
        getStatusFromServer(doStatusPollingForKey);
    }
}

function getStatusFromServer(meetingKey)
{
    try
    {
        sendAsyncAJAXRequest('GET', 
              contextPath+"/zohomeeting.do?method=getMeetingStatus&key="+meetingKey , handleMeetingStatus);
    }
    catch(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:startStatusPolling()", pollingPeriod);
            return;
        }
        var evalRsp = eval('('+response+')');
        if(evalRsp.response.result)
        {
            var meetingStatus = evalRsp.response.result.meeting.meeting_status;
            var buttonEle ;
            var statusEle ; 
            
            if(statusPollingKeyType == "invitedMeetings")
            {
                buttonEle = document.getElementById("joinMeetingButton");
                statusEle = document.getElementById("join_meetingStatus_span");
            }
            else
            {
                buttonEle = document.getElementById("startMeetingButton");
                statusEle = document.getElementById("meetingStatus_span");
            }


            if(meetingStatus == "NOT_STARTED")
            {
                if(!isMeetingStoppedOnce)
                {
                    //showLoadingDiv("Starting...");
                }
                else
                {
                     buttonEle.innerHTML = getStartJoinDetailsHtml( statusPollingKeyRole , "NOTSTARTED" , doStatusPollingForKey , statusPollingKeyTopic , statusPollingKeyType);
                }
                updateMeetingStatusOnPolling( statusPollingKeyType , doStatusPollingForKey , "NOTSTARTED");
                statusEle.innerHTML = "NOT STARTED";
            }
            else
            {
                isMeetingStoppedOnce = true;
                //hideLoadingDiv();
                statusEle.innerHTML = "STARTED";
                buttonEle.innerHTML = getStartJoinDetailsHtml( statusPollingKeyRole , "STARTED" , doStatusPollingForKey , statusPollingKeyTopic , statusPollingKeyType);

                updateMeetingStatusOnPolling( statusPollingKeyType , doStatusPollingForKey , "STARTED");
            }
            setTimeout("javascript:startStatusPolling()", pollingPeriod);
        }
        else
        {
            setTimeout("javascript:startStatusPolling()", pollingPeriod);
        }
    }
}

function updateMeetingStatusOnPolling( meetingType , kkey , sstatus)
{
    var meetingObj = getMeetingObjectFromClient(kkey,meetingType);
    if(meetingObj != null)
    {
       meetingObj.meetingStatus = sstatus;
    }
}


function stopMeeting(meetingKey , from )
{
    try
    {
        if(!confirm(document.getElementById("confirm.stop.meeting").innerHTML))
        {
            return;
        }
        if(from == "tableView")
        {
             sendAsyncAJAXRequest('GET',
                contextPath+"/zohomeeting.do?method=stopMeeting&key="+meetingKey , handleStopMeetingFromTable);
        }
        //From details view
        else
        {
             sendAsyncAJAXRequest('GET',
                contextPath+"/zohomeeting.do?method=stopMeeting&key="+meetingKey , handleStopMeetingFromDetails);
        }
    }
    catch(e)
    {
        alert(document.getElementById("error.sending.request.to.server").innerHTML);
    }
}

function handleStopMeetingFromTable(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(document.getElementById("unable.to.stop.meeting").innerHTML);
            hideLoadingDiv();
            return;
        }
        var evalRsp = eval('('+rsp+')');
        if(evalRsp.response.result)
        {
            var rspMssg = evalRsp.response.result.meeting.agent_response;
            if(rspMssg == "received")
            {
                showLoadingDiv(document.getElementById("loading").innerHTML+"...");
                //Performing stop operation from (my/invited) meeting table views
                // ** Refreshing the complete data from server ***
                setTimeout("javascript:refreshMeetings('"+currentlySelectedMeetingType+"')",2000);
            }
            else
            {
                alert(document.getElementById("unable.to.stop.meeting").innerHTML);
            }
        }
        else
        {
            alert(document.getElementById("unable.to.stop.meeting").innerHTML);
        }
    }
}

function handleStopMeetingFromDetails(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(document.getElementById("unable.to.stop.meeting").innerHTML);
            hideLoadingDiv();
            return;
        }
        var evalRsp = eval('('+rsp+')');
        if(evalRsp.response.result)
        {
            var rspMssg = evalRsp.response.result.meeting.agent_response;
            if(rspMssg == "received")
            {
                //startStatusPolling() & follow up methods will take 
                //care of updating the status and button changes
            }
            else
            {
                alert(document.getElementById("unable.to.stop.meeting").innerHTML);
            }
        }
        else
        {
            alert(document.getElementById("unable.to.stop.meeting").innerHTML);
        }
    }
}

function showTodayMeetings()
{
    var ddate = new Date();
    //Set offset
    ddate.setTime( ddate.getTime()+offSetWithRespectToSystemTime ); 
    //
    var dt = ddate.getDate();
    if(dt <= 9)
    {
        dt = "0"+dt;
    }
    var today = ddate.getFullYear()+"-"+(ddate.getMonth()+1)+"-"+dt;
    document.getElementById("selectedDate_TF").value = today;
    formMeetingsTable(currentlySelectedMeetingType,true);
}

function showTimeZoneComp()
{
    setTimezoneInCombo();
    var divEle = document.getElementById('configureTimeZoneDiv');
     var pointXX = lastMouseClickX;
     var pointYY = lastMouseClickY;
     divEle.classname = "tagmenu";
     divEle.style.right = "";
     //div.style.border = "1px solid black";
     divEle.style.left = pointXX-600;
     divEle.style.top = pointYY+50;
     divEle.style.position = "absolute";
     divEle.style.display = "block";
     divEle.style.backgroundColor = "#b8d4ec";
}

function setTimezoneInCombo()
{
    showDiv('timezoneLoadingDiv',false);
    //Fetch timezone from server and store it in client end.
    if(configuredTimezone == "")
    {
        try
        {
            var broffset =  - ( (new Date()).getTimezoneOffset ( ) / 60 ) ;
            sendAsyncAJAXRequest('GET', 
                contextPath+"/zohomeeting.do?method=getTimezone&offsetHr="+broffset,handleGetTimezone);
        }
        catch(e)
        {
            alert(document.getElementById("unable.to.send.request.to.server").innerHTML);
        }
    }
    //
    else
    {
        setTimeZone(configuredTimezone);
    }
    hideDiv('timezoneLoadingDiv');
}

function handleGetTimezone(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) == "" )
        {
            return;
        }
        var evalRsp = eval('('+rsp+')');
        if(evalRsp.response.result)
        {
            configuredTimezone = evalRsp.response.result.meeting.timezone;
            setTimezoneInCombo();
            var timezoneText = getSelectedTimeZone('intext');
            setOffset(timezoneText);
            displayCurrentTime();
        }
    }
}

function setOffset(timezoneText)
{
   var arr = timezoneText.split("GMT");
   var stArr = arr[1].split(")");
   var oper = "add";
   var offStArr ;
   //Ahead of GMT time
   if(stArr[0].indexOf("-") == 0 )
   {
       oper = "sub";
       offStArr = stArr[0].split("-");
   }
   else if(stArr[0].indexOf("+") == 0)
   {
       offStArr = stArr[0].split("+");
   }
   //GMT time 
   else 
   {
       offStArr = new Array("0","0:0");
   }
   var offStTime = offStArr[1];

   var oneHourValue = 1*60*60*1000;
   var oneMinuteValue = 1*60*1000;
   var systemOffset = (new Date()).getTimezoneOffset()*oneMinuteValue;
   var timeArr = offStTime.split(":");
   var offSetConfInMillis = ((1*timeArr[0])*oneHourValue)+((1*timeArr[1])*oneMinuteValue);
   
   if(oper == "add")
   {
       offSetWithRespectToSystemTime = systemOffset + offSetConfInMillis;
   }
   else
   {
       offSetWithRespectToSystemTime = systemOffset - offSetConfInMillis;
   }
}

function configureTimezone()
{
    showDiv('timezoneLoadingDiv',false);
    try
    {
        var timezone = getSelectedTimeZone('invalue');
        sendAsyncAJAXRequest('GET', 
                contextPath+"/zohomeeting.do?method=setTimezone&timezone="+timezone,handleSetTimezone);
    }
    catch(e)
    {
        alert(document.getElementById("unable.to.send.request.to.server").innerHTML);
    }
}

function handleSetTimezone(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(document.getElementById("unable.to.configure.timezone").innerHTML);
            hideDiv('configureTimeZoneDiv');
            return;
        }
        var evalRs = eval('('+rsp+')');
        if(evalRs.response.result)
        {
             configuredTimezone = getSelectedTimeZone('invalue');
             var timezoneText = getSelectedTimeZone('intext');
             setOffset(timezoneText);
             hideDiv('configureTimeZoneDiv');
             alert(document.getElementById("timezone.set.successfully").innerHTML);

             //Making the my meetings and invited meetings to fetch
             //on next table rendering operation
             isMyMeetingFirstTime = true;
             isInvitedMeetingFirstTime = true;
             if(currentlySelectedMeetingType == "createMeeting")
             {
                 displayCreateView();
             }
             else
             {
                 formMeetingsTable(currentlySelectedMeetingType,false);
             }
             displayCurrentTime();
        }
        else
        {
            alert(document.getElementById("unable.to.configure.timezone").innerHTML);
            hideDiv('configureTimeZoneDiv');
        }
        //alert(rsp);
        //hideDiv('configureTimeZoneDiv');
    }
}

function displayCurrentTime()
{
    var d = new Date();

    //Getting the equivalent time with respect to the configured
    //timezone
    var temp_set = d.getTime();
    temp_set = temp_set + offSetWithRespectToSystemTime;
    d.setTime(temp_set);
    //
    var hrs = d.getHours();
    var meridian = "am";
    if(hrs >= 12)
    {
        meridian = "pm";
        if(hrs > 12)
        {
            hrs = hrs - 12;
        }
    }

    var dispTime = monthArr_Shot[d.getMonth()] +" "+
                    getNumbersInTwoDigits(d.getDate())+", "+
                    d.getFullYear()+" "+
                    getNumbersInTwoDigits(hrs)+":"+
                    getNumbersInTwoDigits(d.getMinutes()) + " "+meridian+" "+
                    "<a href=\"javascript:showTimeZoneComp()\">"+tzVsShortForm[configuredTimezone]+"</a>";
    document.getElementById("currentTime_span").innerHTML = dispTime;
}

//Appends "0" infront of single digit number
function getNumbersInTwoDigits(num)
{
     if(num <= 9)
     {
         return "0"+num;
     }
     return num;
}

function showInviteMeeting(meetingkey)
{
     var pointXX = lastMouseClickX;
     var pointYY = lastMouseClickY;
     var divEle = document.getElementById("inviteParitcipantsDiv");
     divEle.style.top = pointYY;
     divEle.style.left = pointXX-100;
     showDiv("inviteParitcipantsDiv",false);
     document.getElementById("inviteParticipants_Text").value = "";
     var pathVar=document.location.toString();
     var pathArr=pathVar.lastIndexOf("/");
     var formJoinURL = pathVar.substring(0,pathArr)+"/jsp/meetingview.jsp?operation=join&key="+meetingkey;
     document.getElementById("sendEmailSection").innerHTML = document.getElementById("simply.send.this.link").innerHTML+"<br>"+ formJoinURL;
     document.getElementById("inviteMeetingButton").innerHTML = "<input id=\"inviteJoinButton\" type=\"button\" name=\"Invite\" value=\""+document.getElementById("invite").innerHTML+"\" onclick=\"javascript:inviteMeeting('"+meetingkey+"')\">";
}

function inviteMeeting(kkey)
{
    var emails = document.getElementById("inviteParticipants_Text").value;
    if(trim(emails) == "")
    {
        alert(document.getElementByID("provide.participant.emailid.to.invite").innerHTML);
        return;
    }
    if(emails.indexOf("\n") != -1)
    {
        emails = replaceStr(emails, "\n" , ",");
    }
    //Removing control+M characters
    emails = removeControlMChars(emails);
    var decode_emails = decodeURIComponent(emails);
    if(!checkMultipleEMailIds(decode_emails))
    {
        alert(document.getElementById("enter.valid.emailid").innerHTML);
        return;
    }

    var presenter = document.getElementById("presenter_span").innerHTML;
    var ttime = document.getElementById("meetingDateAndTime_span").innerHTML;
    var topic = document.getElementById("meetingTopic_span").innerHTML;
    var agenda = document.getElementById("agenda_span").innerHTML;
    var timezone = tzVsShortForm[configuredTimezone];

    try
    {
        disableEnableButton("inviteJoinButton",true);
        showDiv("processingInviteDiv",false);
        var urll = contextPath + "/zohomeeting.do?method=inviteMeeting&key="
                   +kkey+"&emails="+emails+"&presenter="+presenter+"&ttime="+ttime+
                   "&topic="+topic+"&agenda="+agenda+"&timezone="+timezone+"&userName="+userName;
        sendAsyncAJAXRequest('GET', urll , handleInviteMeeting);
    }
    catch(e)
    {
        alert(document.getElementById("unable.to.send.request.to.server").innerHTML);
    }
}

function handleInviteMeeting(xmlhttp)
{
    if(xmlhttp.readyState == 4)
    {
        var rsp = xmlhttp.responseText;
        var evalRsp = eval('('+rsp+')');
        if(evalRsp)
        {
            var meetingKey = document.getElementById("meetingKey_span").innerHTML;
            meetingKey = trim(meetingKey);
            var meetingObj = getMeetingObjectFromClient(meetingKey , "myMeetings");
            var participants = new Array();
            //If the client view contains the meeting details in client DB.
            if(meetingObj != null)
            {
                participants = meetingObj.participantsList;
            }
            var emailsList = evalRsp.emails;
            var zohoresponse = evalRsp.zohoResp;
            //To handle request timed out situations.
            //Empty string will be returned at the
            //time of timedout
            if(zohoresponse.response == null || zohoresponse.response == "" )
            {
                alert(document.getElementById("unable.to.invite.participants").innerHTML);
                hideDiv("processingInviteDiv");
                disableEnableButton("inviteJoinButton",false);
                return;
            }

            if(zohoresponse.response.result)
            {
                var message = zohoresponse.response.result.meeting.invite_participant;
                if(message == "Participant Invited")
                {
                    var emailArr = emailsList.split(",");
                    var eLn = emailArr.length;
                    if(eLn > 0)
                    {
                        for( var cn = 0 ; cn < eLn ; cn++)
                        {
                            participants[participants.length] = emailArr[cn];
                        }
                        hideDiv("inviteParitcipantsDiv");
                        alert(document.getElementById("participants.invited.successfully").innerHTML);
                        //If the meeting data is stored at the client end
                        if(meetingObj != null)
                        {
                            document.getElementById("viewLink").href = 
                                "javascript:showViewParticipant('"+participants+"')";
                        }
                        //If the user directly landed on the start view on starting the meeting
                        else
                        {
                            var ddiv = document.getElementById("viewParticipantsDiv");
                            participants = participants.toString();
                            var extParticipants = ddiv.innerHTML; 
                            if(  extParticipants != "")
                            {
                                extParticipants = replaceStr(extParticipants,"<br>",",");
                                participants = extParticipants + "," + participants;
                            }
                            document.getElementById("viewLink").href = 
                                "javascript:showViewParticipant('"+participants+"')";
                        }
                    }
                }
                else
                {
                    alert(document.getElementById("unable.to.invite.participants").innerHTML);
                }
            }
            else
            {
                alert(document.getElementById("unable.to.invite.participants").innerHTML);
            }
        }
        hideDiv("processingInviteDiv");
        disableEnableButton("inviteJoinButton",false);
    }
}

function setFocus(obj)
{
    if(obj)
    {
        obj.focus();
    }
}

//check comma separated email ids.
function checkMultipleEMailIds(str)
{
    var result = true;
    if(str != null && trim(str) != "")
    {
        var emailArr = str.split(",");
        var ln = emailArr.length;
        for(var i = 0 ; i < ln ; i++ )
        {
            var email = emailArr[i];
            if(email != null && trim(email) != "")
            {
                var individualRslt = checkEMail(email);
                if(!individualRslt)
                {
                    return false;
                }
            }
        }
    }
    return result;
}

function setFocusOnNextParticipantField(tbdy, textFieldName , ev)
{
    var objArr = textFieldName.split("_");
    var tbbody = document.getElementById(tbdy);
    var keyCode = ev.keyCode;
    if(keyCode == 13)
    {
        //Next field name
        var nextFieldName = "participant_"+(1*(objArr[1])+1)+"_create_TF";
        //Next field
        var nextObj = document.getElementById(nextFieldName);
        //If next field exists , set focus to it
        if(nextObj)
        {
            setFocus(nextObj);
        }
        else
        {
            addAParticipantRow(tbdy , nextFieldName , "");
        }
    }
    return true;
}

function addAParticipantRow(tbdy , nextFieldName , val)
{
        var tbbody = document.getElementById(tbdy);
        var rowCnt = tbbody.childNodes.length;
        var trr = document.createElement("tr"); 
        tbbody.appendChild(trr);
        var tcl = document.createElement("td");
        var idd = nextFieldName;//"participant_"+rowCnt+"_create_TF";
        tcl.innerHTML = "<input type=\"text\" name=\""+idd+"\" id=\""+idd+"\" maxlength=\"100\" size=\"22\" value=\""+val+"\" class=\"txtField\" style=\"border:1px solid #74C6ED;\" onkeydown=\"javascript:setFocusOnNextParticipantField('"+tbdy+"','"+idd+"',event)\" onfocus=\"javascript:makeFieldEmpty('"+idd+"')\"/>";
        trr.appendChild(tcl);
}

function makeFieldEmpty(tfName)
{
    var ele = document.getElementById(tfName);
    if(ele.value == "Enter Email ID")
    {
        ele.value = "";
    }
}

function setParticipantTable(participants)
{
    var ttbody = document.getElementById('ParticipantEmailBody');
    //Removing all the rows from tbody
    var ln = ttbody.childNodes.length;
    for(var j = 0 ; j < ln ; j++ )
    {
        ttbody.removeChild(ttbody.childNodes[0]);
    }

    var arrLn = participants.length;
    if(arrLn < 4)
    {
        countArrLn = 4;
    }
    else
    {
        countArrLn = arrLn;
    }
    for(var i = 1 ; i <= countArrLn ; i++ )
    {
        var val = "";
        if(i == 1 && arrLn == 0 )
        {
            val = "Enter Email ID";
        }
        else
        {
            if(arrLn >= i)
            {
                val = participants[i-1];
            }
        }
        var textFieldName = "participant_"+i+"_create_TF";
        addAParticipantRow('ParticipantEmailBody',textFieldName,val);
    }
}

function searchMeeting()
{
    isSearchEnabled = true;
    formMeetingsTable(currentlySelectedMeetingType,false);
}

function downloadAgentZip(meetingKey)
{
    try
    {
        sendAsyncAJAXRequest('GET',
            contextPath+"/zohomeeting.do?method=getDownloadZipURL&meetingKey="+meetingKey, 
            handleDownloadAgentZip);
    }
    catch(e)
    {
        alert(document.getElementById("unable.to.send.request.to.server").innerHTML);
    }
}

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(document.getElementById("unable.to.download.zip").innerHTML);
            return;
        }
        var evalRsp = eval('('+rsp+')');
        if(evalRsp.response.result)
        {
            var zipPath = evalRsp.response.result.meeting.zip_path;
            location.href = zipPath;
        }
        else
        {
            alert(document.getElementById("unable.to.download.zip").innerHTML);
        }
    }
}

function showInstructionImage()
{
    //IE
    if(document.all)
    {
    }
    //Mozilla Firefox
    else
    {
        var divEle = document.getElementById("instructionDiv");
        divEle.innerHTML = "<img src=\"images/f_blocker.gif\">";
        divEle.style.display = "block";
    }
}

function performStatusPolling(mkey , mType, mTopic , mRole)
{
    statusPollingKeyTopic = mTopic;
    doStatusPollingForKey = mkey;
    statusPollingKeyType = mType;
    statusPollingKeyRole = mRole;
    startStatusPolling();
}
