<html>
<%@page info="AvailabilityDataFrame" language="java" pageEncoding="utf-8" contentType="text/html; charset=UTF-8"%> 
<%@taglib uri="/WEB-INF/jato.tld" prefix="jato"%>
<%@include file="../../uwc/js/resourceBundleUtils.js"%>
<script src="../uwc/js/uwcUtils.js" type="text/javascript"> </script><noscript></noscript>

<%  String path = request.getContextPath();  
   if( path.equals("/") )
     path="";
%>
<jato:useViewBean className="com.sun.uwc.calclient.AvailabilityDataFrameViewBean" fireChildDisplayEvents="true">

<head>
<title><%= getLocalizedLabel(session, "uwc-calclient-availabilityview-windowititle","Check Availability") %></title>
<SCRIPT language="JavaScript" src="../uwc/js/scripts.js"></SCRIPT>
<SCRIPT src="../uwc/js/browserVersion.js" type="text/javascript"></SCRIPT>
<SCRIPT type="text/javascript">
<!--
  if (is_ie5up) // IE5
  {
   document.write("<LINK href=<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="skinModel" lookInSession="true" name="Style-Sheet-IE" defaultValue="../uwc/css/css_ie5win.css"/> type=text/css rel=stylesheet>") 
  }
  else if (is_gecko) // Netscape 6/7 or Mozilla
  {
  document.write("<LINK href=<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="skinModel" lookInSession="true" name="Style-Sheet-NN" defaultValue="../uwc/css/css_ns6up.css"/> type=text/css rel=stylesheet>") 
  }
  else  // All others
  {
  document.write("<LINK href=<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="skinModel" lookInSession="true" name="Style-Sheet-NN" defaultValue="../uwc/css/css_ns6up.css"/> type=text/css rel=stylesheet>") 
  }
//-->
</script>
<script language=JavaScript type=text/javascript>
<!--

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//-->
</script>
<script src="../uwc/js/date_utils.js"></script>
<script src="../uwc/js/uwcUtils.js" type="text/javascript"> </script>
<script src="../uwc/js/browserVersion.js" type="text/javascript"></script>
<script language=JavaScript type=text/javascript >
<!--


// This theAddressBookUrl can be written by view bean in fresh page request as
// hidden and can be maintianed by form/model cycles

var weekends = [1,1,0,0,0,1,1];
var weekstart = 0;


function openWinAutoHeight(theURL,winName,features) { //v2.0
  winHeight = screen.availHeight * .85;
  window.open(theURL,winName,features + ', height=' + winHeight);
}


function getWeekStart() {
  return weekstart;
}

function getWeekEnds() {
  return weekends;
}

function openSearchPopup() {

  var theUrl = "<%=path%>/abs/select-popup-main.xml?";
  theUrl = theUrl + "wcfg_col1=dnnolink" + "&";
  theUrl = theUrl + "wcfg_col2=primemailnolink" + "&";
  theUrl = theUrl + "wcfg_ablist=1" + "&";
  theUrl = theUrl + "wcfg_abtype=2" + "&";
  theUrl = theUrl + "wcfg_buttonlabel=AddInvitees" + "&";
  openWinAutoHeight(theUrl, 'search','scrollbars=yes,resizable=yes,width=700');
}

function GetSharedObject() {
  sharedObj = new Object();
  sharedObj.expandselectedgroup = "0";
  sharedObj.expandonmissing = "";
  sharedObj.fieldsToReturn = new Array("displayname", "email_1");
  sharedObj.nid = new Array("");
  sharedObj.sid = new Array("");
  return sharedObj;
}

function AcceptData(inputArray) {
  if(null == inputArray) {
    UWCAlert("<%= getLocalizedLabel(session, "uwc-calclient-event-EditEvent-AddFromAddressBook-NoInvitees", "No invitees selected to add") %>");
  }

  if(inputArray.length < 2) {
    UWCAlert("<%= getLocalizedLabel(session, "uwc-calclient-event-EditEvent-AddFromAddressBook-NoData", "Cannot add invitees - No data available from search window") %>");
  }

  if(inputArray[0].length > 0) {
    var theEmails = "";
    var theLength = inputArray[0].length;
    for(i=0; i < theLength; i++) {
      var emailId = ((null == inputArray[1][i])? "" : trim(inputArray[1][i])); 
      var userCN = ((null == inputArray[0][i])? "" : trim(inputArray[0][i])); 
      theEmails = theEmails + emailId;
      if(i < (theLength - 1)) {
        theEmails = theEmails + "!!SEPARATOR!!"; 
      }
    }
    document.forms[0].elements["AvailabilityDataFrame.emailsSelectedFromAB"].value = theEmails;
    document.forms[0].elements["AvailabilityDataFrame.action"].value = "abadd";
    document.forms[0].submitType.value = "AvailabilityDataFrame.addinviteesfromab";
    document.forms[0].submit();
  } 
  else {
    UWCAlert("<%= getLocalizedLabel(session, "uwc-calclient-event-EditEvent-AddFromAddressBook-NoData", "Cannot add invitees - No data available from search window") %>");
  }
}


function loaddisplayframe() {
	availframe = parent.frames[1]
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startday"].value = document.forms[0].elements["date"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startmonth"].value = document.forms[0].elements["month"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startyear"].value = document.forms[0].elements["year"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.starthours"].value = document.forms[0].elements["hours"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startminutes"].value = document.forms[0].elements["minutes"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.durationhours"].value = document.forms[0].elements["durationhours"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.durationminutes"].value = document.forms[0].elements["durationminutes"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.calidslist"].value = document.forms[0].elements["AvailabilityDataFrame.calidslist"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.submitType"].value= "checkavailability";
	availframe.document.forms[0].submit();	
}

function validateData(){
	  var year=document.forms[0].elements["year"].value
      var month=document.forms[0].elements["month"].value - 1;
      var day=document.forms[0].elements["date"].value
            
      var valid = isValidDate(day ,month ,year);
      
      if(valid == false){
      	UWCAlert("<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true" escape="false" name="uwc-mail-error-invalid-date" defaultValue="Invalid Date Selection !"/>");
      	return valid;
      }
      var hours = document.forms[0].elements["durationhours"].value;
      var minutes = document.forms[0].elements["durationminutes"].value;
      
      if((hours == '0') && (minutes == '00')) {
      	valid = false;
      	UWCAlert("<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-zeroduration" defaultValue="Duration Cannot be Zero"/>");
      }       
      else if(document.forms[0].elements["inviteelist"].length == 0 ){
         valid = false;
         UWCAlert("<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-noinvitees" defaultValue="Add atleast one invitee"/>");
      }
      
      return valid;
}

function getDelimitedString(theArray, theDelimiter) {
    var delimitedString = "";
    if(null == theArray) { 
      return delimitedString;
    }
    for(var i=0; i < theArray.length; i++) {
      if((null == delimitedString) || ("" == delimitedString)) {
        delimitedString = theArray[i]; 
      }
      else {
        delimitedString = delimitedString + theDelimiter + theArray[i];
      }
    }
    return delimitedString;
}

function transferdata() {
	var vaild = validateData();
	if(vaild == false) return;
	availframe = parent.frames[1]
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startday"].value = document.forms[0].elements["date"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startmonth"].value = document.forms[0].elements["month"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startyear"].value = document.forms[0].elements["year"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.starthours"].value = document.forms[0].elements["hours"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.startminutes"].value = document.forms[0].elements["minutes"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.durationhours"].value = document.forms[0].elements["durationhours"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.durationminutes"].value = document.forms[0].elements["durationminutes"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.calidslist"].value = document.forms[0].elements["AvailabilityDataFrame.calidslist"].value;
	availframe.document.forms[0].elements["AvailabilityDisplayFrame.submitType"].value= "checkavailability";
	availframe.document.forms[0].submit();
}

function openMiniCalendar(){
	var dt = new Date();
	dt.setDate(document.forms[0].elements["date"].value);
	dt.setMonth(document.forms[0].elements["month"].value - 1);
	dt.setYear(document.forms[0].elements["year"].value);
	var dtstr = dt.toUTCString();
	dtstr = escape(dtstr)
	MM_openBrWindow('../uwc/js/minicalendarpopup.jsp?date='+ dtstr,'minical','scrollbars=yes,resizable=yes,width=250,height=225');
	return false;	
}

function acceptSelectedDate(str) {
   var dt = new Date(str)	
   document.forms[0].elements["date"].value = dt.getDate();
   document.forms[0].elements["month"].value = dt.getMonth() + 1;
   document.forms[0].elements["year"].value = dt.getFullYear();
}

//-->
</script>

</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="Popup">
<jato:form name="AvailabilityDataFrameForm" method="post" defaultCommandChild="/addinvitee">
<input type="hidden" name="submitType" value="">
<jato:hidden name="emailsSelectedFromAB" defaultValue=""/>
<jato:hidden name="action" defaultValue="add"/>
<jato:hidden name="calidslist" defaultValue=""/>
<jato:hidden name="cnlist" defaultValue=""/>
<jato:hidden name="neweventcalid" defaultValue=""/>

<script>
weekstart = <jato:getDisplayFieldValue name="weekstart"/>
weekends = [<jato:getDisplayFieldValue name="weekends" />];
</script>

<!--Popup Title block -->

<table width="100%" border="0" cellspacing="0" cellpadding="0" title="">
  <tr>
    <td class="PopupTitle"><span class="PopupTitleText"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-windowititle" defaultValue="Check Availability"/></span></td>
  </tr>
</table>
<!-- Form Input table that contains start date/time and Invitee List -->
  <table class="FormInputTable" width="100%" border="0" cellspacing="0" cellpadding="0" title="">
    <tr> 
      <td colspan="2">
        <!-- Error pagelet -->
           <jato:containerView name="errorPlugin">
             <%@include file="/uwc/common/popuperror.jsp"%>
           </jato:containerView>
       </td>
    </tr>

    <tr> 
      <td class="PropLabel"><span class="Lbl2"><label for="month"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-startdate" defaultValue="Start Date:"/></label></span></td>
      <td class="PropInput" width="100%" nowrap valign="middle"> 
        <jato:combobox name="month" elementId="month" />
         <label for="date"></label>
        <jato:combobox name="date" elementId="date" />
        <label for="year"></label>
        <jato:combobox name="year" elementId="year" />
        <a href="javascript:;" accesskey="C" title="<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-mcpopuptitle" defaultValue="Select Date from Calendar"/>" onClick="openMiniCalendar()" onKeyPress="openMiniCalendar()"><img src="<%= getLocalizedLabel(session, "skinModel", "uwc-calclient-availability-minicalendar-image", "../uwc/images/CalendarLink_wo.gi") %>" width="20" height="20" align="baseline" border="0" title="<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-mcpopuptitle" defaultValue="Select Date from Calendar"/>" alt="<jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-mcpopuptitle" defaultValue="Select Date from Calendar"/>" tabindex="4"></a> 
      </td>
    </tr>
    <tr> 
      <td class="PropLabel"><span class="Lbl2"><label for="hours"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-starttime" defaultValue="Start Time:"/></label></span></td>
      <td class="PropInput"> 
        <jato:combobox name="hours" elementId="hours" />
        <label for="minutes"></label>
        <jato:combobox name="minutes" elementId="minutes" />
         <jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-for" defaultValue="for"/>
        <jato:combobox name="durationhours" elementId="durationhours" />
        <label for="durationhours"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-hours" defaultValue="hour (s)"/></label> 
        <jato:combobox name="durationminutes" elementId="durationminutes" />
        <label for="durationminutes"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-minutes" defaultValue="minutes"/></label></td>
    </tr>
    <tr> 
      <td class="PropLabel" nowrap><span class="Lbl2"><label for="invitee"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-inviteename" defaultValue="Invitee Name:"/></label></span></td>
      <td class="PropInputWHelp" width="100%"> 
        <jato:textField name="invitee" size="40" maxLength="120" elementId="invitee"/> 
        <jato:button styleClass="Btn1" name="addinvitee" elementId="addinviteebutton" defaultValue="<jato:getModelFieldValue modelClass='com.sun.uwc.common.model.UWCResourceBundleModel' modelName='i18nModel' lookInSession='true'  escape='false' name='uwc-calclient-availabilityview-add' defaultValue='Add'/>" onMouseOver="if (this.disabled==0) this.className='Btn1Hov'" onFocus="if (this.disabled==0) this.className='Btn1Hov'" onMouseOut="if (this.disabled==0) this.className='Btn1'" onBlur="if (this.disabled==0) this.className='Btn1'"  extraHtml='<%= getTitleForExtraHtml(session,"uwc-calclient-event-EditEvent-Add-title","Add Invitee") %>'/>
        <jato:button styleClass="Btn2" name="addinviteesfromab" elementId="addAddressBook" defaultValue='<%= getLocalizedLabel(session,"uwc-calclient-availabilityview-addfromaddressBook","Add from Address Book") %>' onClick="openSearchPopup(); return false;" onMouseOver="if (this.disabled==0) this.className='Btn2Hov'" onFocus="if (this.disabled==0) this.className='Btn2Hov'" onMouseOut="if (this.disabled==0) this.className='Btn2'" onBlur="if (this.disabled==0) this.className='Btn2'" extraHtml='<%= getTitleForExtraHtml(session,"uwc-calclient-event-EditEvent-AddFromAddressBook-title","Add Invitee from Address Book") %>' tabIndex="9"/>
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><span class="inlineHelpText"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-inviteehelp" defaultValue=""/></span></td>

    </tr>
    <tr> 
      <td colspan="2"><img src="../uwc/images/spacer.gif" width="1" height="4" alt=""></td>
    </tr>
    <tr> 
      <td class="PropLabel" valign="top"><label for="inviteelist"><span class="Lbl2"><jato:getModelFieldValue modelClass="com.sun.uwc.common.model.UWCResourceBundleModel" modelName="i18nModel" lookInSession="true"  escape="false" name="uwc-calclient-availabilityview-inviteelist" defaultValue="Invitee List:"/></span></label></td>
      <td class="PropInput"> 
        <table border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td valign="top"> 
            <jato:listbox name="inviteelist" elementId="inviteelist" size="5" multiple="true"/>
            </td>
            <td> 
              <table class="AddRmvBtnTbl" border="0" cellspacing="0" cellpadding="0" title="">
                <tbody> 
                <tr> 
                  <td align="center"><img src="../uwc/images/spacer.gif" width="10" height="1" alt=""></td>

                  <td class="PropInput" align="center" valign="middle"> 
                    <div class="AddRmvHrzWin"> 
                      <input class="Btn1" type="button" name="checkAvailability" id="checkAvailability" tabindex="24" value='<%= getLocalizedLabel(session, "uwc-calclient-availabilityview-windowititle","Check Availability") %>' onMouseOver="if (this.disabled==0) this.className='Btn1Hov'" onMouseOut="if (this.disabled==0) this.className='Btn1'"  onClick="transferdata()" title='<%= getLocalizedLabel(session, "uwc-calclient-event-EditEvent-CheckAvailability-title", "Check Availability of Invitees") %>'>
                    </div>
                    <div class="AddRmvHrzWin"> 
                      <jato:button styleClass="Btn2" name="removeinvitee" elementId="removeinviteebutton" defaultValue='<%= getLocalizedLabel(session, "uwc-calclient-availabilityview-remove","Remove") %>' onMouseOver="if (this.disabled==0) this.className='Btn2Hov'" onMouseOut="if (this.disabled==0) this.className='Btn2'" onBlur="if (this.disabled==0) this.className='Btn1'"  extraHtml='<%= getTitleForExtraHtml(session,"uwc-calclient-event-EditEvent-Remove-title"," Remove Selected Invitees") %>'/>
                    </div>
                  </td>
                </tr>
                </tbody> 
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</jato:form>
</jato:useViewBean>
</body>
</html>
