About This Code
Brief Description:
R5 Web Mail Event Javascript Code
Contributor:
Andrew Jones
Last Modified:
17 Jun 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
function isEmpty(s)
{
return ((s == null) || (s.length == 0))
}
function isDigit (c)
{
return ((c >= "0") && (c <= "9"))
}
function isInteger (s)
{
var i;
if (isEmpty(s)) return false;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (!isDigit(c)) return false;
}
return true;
}
function isNonnegativeInteger (s)
{
// The next line is a bit byzantine. What it means is:
// a) s must be a signed integer, AND
// b) one of the following must be true:
// i) s is empty and we are supposed to return true for
// empty strings
// ii) this is a number >= 0
return (isSignedInteger(s) && (isEmpty(s) || (parseInt (s) >= 0) ) );
}
function isSignedInteger (s)
{
if (isEmpty(s)) return false;
else {
var startPos = 0;
// skip leading + or -
if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
startPos = 1;
return (isInteger(s.substring(startPos, s.length)))
}
}
function makeArray(n)
{
for (var i = 1; i <= n; i++) {
this[i] = 0
}
return this
}
var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29; // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
function isIntegerInRange (s, a, b)
{
if (isEmpty(s)) return false;
if (!isInteger(s)) return false;
var num = parseInt (s);
return ((num >= a) && (num <= b));
}
function isMonth (s)
{
if (isEmpty(s)) return false;
// Format may yield "05 Wed" or "Wed 05" so look for substring of 2 chars.
if (s.length > 2) {
var space = s.indexOf(" ");
if (space >2) s = s.slice( space + 1, s.length);
else s = s.slice( 0, space );
}
// now strip out leading 0 because parseInt() will not!
s = stripLeadingCharsInBag (s, "0")
return isIntegerInRange (s, 1, 12);
}
function isDay (s)
{
if (isEmpty(s)) return false;
// Format may yield "05 Wed" or "Wed 05" so look for substring of 2 chars.
if (s.length > 2) {
var space = s.indexOf(" ");
if (space >2) s = s.slice( space + 1, s.length);
else s = s.slice( 0, space );
}
// now strip out leading 0 because parseInt() will not!
s = stripLeadingCharsInBag (s, "0")
return isIntegerInRange (s, 1, 31);
}
function stripLeadingCharsInBag (s, bag)
{
var i;
var returnString = "";
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (bag.indexOf(c) == -1) {
returnString = s.substring( i, s.length);
break;
}
}
return returnString;
}
function daysInFebruary (year)
{
return ( ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}
function isYear (s)
{
if (isEmpty(s)) return false;
if (!isNonnegativeInteger(s)) return false;
return ((s.length == 2) || (s.length == 4));
}
// isDate (STRING year, STRING month, STRING day)
function isDate (year, month, day)
{
if (! (isYear(year) && isMonth(month) && isDay(day))) return false;
var intYear = parseInt(year);
var intMonth = parseInt(month);
var intDay = parseInt(day);
// catch invalid days, except for February
if (intDay > daysInMonth[intMonth]) return false;
if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
return true;
}
function isWhitespace (s)
{
var i;
var whitespace = " \t\n\r";
if (isEmpty(s)) return true;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1) return false;
}
return true;
}
function stripCharsInBag (s, bag)
{
var i;
var returnString = "";
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
function stripWhitespace (s)
{
var whitespace = " \t\n\r";
return stripCharsInBag (s, whitespace)
}
function addDuration(time, duration)
{
var thisform = document.forms[0];
var meridian = "";
var amstring = thisform.tmpMeridian.value.slice( 0, thisform.tmpMeridian.value.indexOf(";"));
var pmstring = thisform.tmpMeridian.value.slice( thisform.tmpMeridian.value.indexOf(";") + 1, thisform.tmpMeridian.value.length);
var returnstring = "";
var newstart = new Date( translateDate(thisform.StartDate.value) + " " + time);
if (newstart.toString() == "Invalid Date" || newstart.toString() == "NaN") return "NaN";
strTimeFormat = thisform.tmpDateTimeFormat.value.slice(thisform.tmpDateTimeFormat.value.indexOf(";") + 1, thisform.tmpDateTimeFormat.value.length)
strTimeFormat = stripWhitespace(strTimeFormat)
var num = parseInt(duration); // convert string to integer
var hours = newstart.getHours(); // 0 - 23
var minutes = newstart.getMinutes(); // 0 - 59
hours += num / 60;
if (hours > 23) // we have spanned days
{
var xxNoMidnight = 'Meetings can not span midnight';
alert( xxNoMidnight );
return "NaN";
}
if (strTimeFormat == "12")
{
if (hours > 12)
{
hours -= 12;
meridian = pmstring;
}
else if (hours < 12)
{
meridian = amstring;
} else {
meridian = pmstring;
}
}
if (hours < 9) hours = "0" + hours;
minutes += num % 60;
if (minutes < 9) minutes = "0" + minutes;
if (meridian.length > 0)
{
returnstring = hours + ":" + minutes + " " + meridian;
}
else
{
returnstring = hours + ":" + minutes;
}
return returnstring;
}
//Displays participant status.
function openStatusWin()
{
thisform = window.document.forms[0]
var value = "/"+ thisform.path.value + "/(wViewParticipantStatus)?OpenAgent&UNID=" + thisform.statusUNID.value;
var nav = navigator.appVersion.charAt(0);
var nap = navigator.appName;
if (nap.indexOf('Netscape') >=0 && (nav == 3))
{
window.open(value,'wViewStatus','resizable=yes,width=570,height=490,status=no,location=no,toolbar=no,menubar=no,scrollbars=yes');
}
else
{
window.open(value,'wViewStatus','resizable=yes,width=550,height=464,status=no,location=no,toolbar=no,menubar=no,scrollbars=yes');
}
}
function displayDialog(strFormName, strActionType, strArgs, strTitle, nWidth, nHeight)
{
thisform = window.document.forms[0]
strLocation = window.location.protocol + "//" + window.location.host + "/" + thisform.tmpDB.value + "/(wDlgBox)?OpenForm&Subform=" + strFormName
if (strActionType)
strLocation += "&ActionType=" + strActionType
if (strArgs)
strLocation += strArgs
if (strTitle)
strLocation += "&Title=" + strTitle +"&Form="+thisform.Form.value
return window.open(strLocation,"Dlg","resizable=yes,width="+nWidth+",height="+nHeight)
}
function isUserOwner()
{
thisform = document.forms[0]
if (thisform.tmpOwner.value == thisform.Chair.value)
{
return true
}
else
return false
}
function translateDate( datevalue )
{
strDateFormat = thisform.tmpDateTimeFormat.value.substring(0,thisform.tmpDateTimeFormat.value.indexOf(";"))
strDateSep = thisform.tmpDateTimeSep.value.substring(0, thisform.tmpDateTimeSep.value.indexOf(";"))
if (strDateFormat == "0") //DMY
{
iIndex = datevalue.indexOf(strDateSep)
day = datevalue.substring(0, iIndex)
datevalue = datevalue.substring(iIndex+1, datevalue.length)
iIndex = datevalue.indexOf(strDateSep)
month = datevalue.substring(0, iIndex)
year = datevalue.substring(iIndex+1, datevalue.length)
}
else if (strDateFormat == "1") // YMD
{
iIndex = datevalue.indexOf(strDateSep)
year = datevalue.substring(0, iIndex)
datevalue = datevalue.substring(iIndex+1, datevalue.length)
iIndex = datevalue.indexOf(strDateSep)
month = datevalue.substring(0, iIndex)
day = datevalue.substring(iIndex+1, datevalue.length)
}
else // MDY
{
iIndex = datevalue.indexOf(strDateSep)
month = datevalue.substring(0, iIndex)
datevalue = datevalue.substring(iIndex+1, datevalue.length)
iIndex = datevalue.indexOf(strDateSep)
day = datevalue.substring(0, iIndex)
year = datevalue.substring(iIndex+1, datevalue.length)
}
if (year.length == 2 && year.substring(0,1) < 5) year = '20' + year;
if (isDate(year, month, day)) {
return month + "/" + day + "/" + year;
} else {
return "NaN";
}
}
function isDateTimeValuesModified()
{
thisform = document.forms[0]
if (thisform.Form.value!="Task")
{
newstart = new Date(translateDate(thisform.StartDate.value) + " " + thisform.StartTime.value);
newend = new Date(translateDate(thisform.EndDate.value) + " " + thisform.EndTime.value);
} else
{
newstart = new Date(translateDate(thisform.StartDate.value) + " 12:00 AM" );
newend = new Date(translateDate(thisform.DueDate.value) + " 11:59 PM" );
}
oldstart = new Date(thisform.tmpWebStartDateTime.value);
oldend = new Date(thisform.tmpWebEndDateTime.value);
if (newstart.getTime() != oldstart.getTime())
{
return true
}
else if (newend.getTime() != oldend.getTime())
{
return true
}
else
return false
}
function isActionInProgress(dAction)
{
thisform = document.forms[0]
aip = new Number(thisform.tmpAction.value)
if (aip & dAction)
{
return true
}
else
return false
}
function updateActionInProgress(dAction, bAdd)
{
thisform = document.forms[0]
csactions = new Number(thisform.tmpAction.value)
if (bAdd)
csactions |= dAction
else
csactions &= ~dAction
thisform.tmpAction.value = csactions.toString()
}
function fixRepeats()
{
var urlString = new String(document.location);
//if we are creating a new appointment and have unchecked the repeat checkbox, we need to reset repeat values
if (urlString.search(/document/i) == -1) {
if (((thisform.Repeats.type == "hidden" && thisform.Repeats.value == "") ||
(thisform.Repeats.type == "checkbox" && !thisform.Repeats.checked))
&& thisform.OrgRepeat.value == "1") {
thisform.RepeatStartDate.value = "";
thisform.RepeatUnit.value = "";
thisform.RepeatInterval.value = "";
thisform.RepeatAdjust.value = "";
thisform.RepeatCustom.value = "";
thisform.RepeatHow.value = "";
thisform.RepeatFor.value = "";
thisform.RepeatForUnit.value = "";
thisform.RepeatUntil.value = "";
thisform.RepeatFromEnd.value = "";
thisform.RepeatWeekends.value = "";
thisform.OrgRepeat.value = "";
thisform.tmpRepeatCheck.value = "";
}
}
}
function submitDocument()
{
thisform = document.forms[0]
fixRepeats();
if (thisform.tmpAction.value != 2048) {
// see if we are changing the date/time and we are the owner
if (isUserOwner() && (thisform.tmpWasMailed.value == "1") && isDateTimeValuesModified() && !isActionInProgress(512))
{
if ( !isActionInProgress(256) )
{
if (!self.confirm("You have changed the date/time of this entry. All participants will be notified. Are you sure this is what you want to do?"))
{
updateActionInProgress(512, false)
return
}
updateActionInProgress(512, true)
}
}
}
// see if we are modifying repeating instance -> THIS MUST BE DONE LAST, since
// the window opened is treated as a modal dialog and is responsible for submitting
// this document. We don't modify if we are just confirming.
if (thisform.OrgRepeat.value == "1" && thisform.tmpResponse.value == "1" && thisform.tmpChangeWhich.value == "" )
{
strLocation = window.location.protocol + "//" + window.location.host + "/" + thisform.tmpDB.value + "/(wDlgBox)?OpenForm&Subform=(ChangeRepeat)"
strLocation += "&Title=Change"
if (self.open(strLocation,"Other","width=450,height=300"))
{
return
}
}
thisform.submit()
}
function openV5RepeatInstance()
{
thisform = document.forms[0]
if (!thisform.OrgRepeat)
{
return
}
if ((thisform.OrgRepeat.value.length > 0) && (thisform.$CSVersion.value.length >0) && (thisform.tmpCalInstanceDate.value.length <= 2) && (thisform.tmpRepeatCheck.value > 1))
{
displayDialog("(RepeatOpenList)", "", "&Prompt=Select%20the%20repeat%20instance%20you%20wish%20to%20edit.", "Open", "300","250")
}
}
Usage / Example