// Copyright (C) 1997-2000 Netopia, Inc.
// All rights reserved.
var DatePulldownsDone = false;
var UserDialog = false;
function GetNextHidden(k)
{
var i = k;
var el = document.nvoForm.elements[i];
while (el.type != "hidden" && (i < document.nvoForm.elements.length))
{
i++;
el = document.nvoForm.elements[i];
}
return i;
} // GetNextHidden
function reloadPage(init) //reloads the window if Nav4 is resized
{
if (init==true) with (navigator)
{
if ((appName=="Netscape")&&(parseInt(appVersion)==4))
{
document.pageWidth=innerWidth;
document.pageHeight=innerHeight;
onresize=reloadPage;
}
}
else if (innerWidth!=document.pageWidth || innerHeight!=document.pageHeight)
location.reload();
}
reloadPage(true);
var gRunOnce = 0;
function setCookie(name, value, expire)
{
document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}
function getCookie(Name)
{
var search = Name + "="
// if there are any cookies
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
{
end = document.cookie.length;
}
return unescape(document.cookie.substring(offset, end));
}
}
return "";
}
function FillInRadioGroups()
{
var i = 0;
var j = 0;
var choiceFound = false;
while (i < document.nvoForm.elements.length)
{
el = document.nvoForm.elements[i];
j = 0;
choiceFound = false;
// Find start of a radio group
if (el.type == "radio")
{
// Find form element that will store selected choice
var indexhf = document.nvoForm.elements[i - 2];
var choiceshf = document.nvoForm.elements[i - 1];
// Cycle through buttons in group, storing the index
// of the selected choice if found
while ((el.type == "radio") &&
(i < document.nvoForm.elements.length))
{
if (el.checked)
{
indexhf.value = j;
choiceFound = true;
}
i++;
j++;
el = document.nvoForm.elements[i];
}
if (!choiceFound)
choiceshf.value = "";
}
else
{
// For other element types, skip over and continue searching for radio
i++;
}
}
}
function FillInDateBoxes()
{
for (var i = 0; i < document.nvoForm.elements.length; i++)
{
if (document.nvoForm.elements[i].name == '.Data.F10065')
{
// copy the whole date to the hidden field
document.nvoForm.elements[i].value = document.nvoForm.year10065.options[document.nvoForm.year10065.selectedIndex].value + document.nvoForm.month10065.options[document.nvoForm.month10065.selectedIndex].value + document.nvoForm.day10065.options[document.nvoForm.day10065.selectedIndex].value;
document.nvoForm.elements[i].value += "0000";
}
}
}
function FillInCheckBoxes()
{
var i = 0;
var j = 0;
while (i < document.nvoForm.elements.length)
{
el = document.nvoForm.elements[i];
// Find start of checkbox group
if (el.type == "checkbox")
{
// Find form elements that will store selected choices
indexhf = document.nvoForm.elements[i - 2];
choiceshf = document.nvoForm.elements[i - 1];
// initilize values
indexhf.value = "";
choiceshf.value = "";
j = 0;
// Cycle through checkboxes in group to find and store all selected choices
while (el.type == "checkbox")
{
if(el.checked)
{
indexhf.value += (indexhf.value.length == 0 ? "" : ",") + j;
choiceshf.value += (choiceshf.value.length == 0 ? "" : "\n\r") + el.value;
}
i++;
j++;
el = document.nvoForm.elements[i];
}
}
else
{
// For other element types, skip over and continue searching for checkboxes
i++;
}
}
}
function FillInQuantityBoxes()
{
var i = 0;
var j = 0;
var val;
var namelist;
while (i < document.nvoForm.elements.length)
{
el = document.nvoForm.elements[i];
// Find start of quantity group
if (el.type == "text")
{
// Find form elements that will store selected choices
indexhf = document.nvoForm.elements[i - 2];
qtyhf = document.nvoForm.elements[i - 1];
if (qtyhf.value == "quantity")
{
// initilize values
var names = "";
qtyhf.value = "";
var k = GetNextHidden(i);
namelist = document.nvoForm.elements[k];
// Cycle through checkboxes in group to find and store all selected choices
while (el.type == "text")
{
val = parseInt(el.value);
if (val > 0)
{
indexhf.value += (indexhf.value.length == 0 ? "" : ",") + j;
qtyhf.value += (qtyhf.value.length == 0 ? "" : ",") + val;
names += (names.length == 0 ? "" : "\n\r") + GetFieldBySep(namelist.value,j,"\t");
}
i++;
j++;
el = document.nvoForm.elements[i];
}
namelist.value = names;
}
else
i++;
}
else
{
// For other element types, skip over and continue searching for checkboxes
i++;
}
}
}
function RequiredRadioFilledOut(radioGroupName)
{
var i = 0;
var choiceFound = false;
var el;
while ((i < document.nvoForm.elements.length) && !choiceFound)
{
el = document.nvoForm.elements[i];
// Find radio group buttons
if ((el.name == radioGroupName) && el.checked)
choiceFound = true;
i++;
}
return choiceFound;
}
function RequiredItemsFilledOut()
{
var gotOne = false;
var regExpression = /@/g;
el = FindElement(".Data.F10013");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10014");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10017");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10003");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10003");
if (el)
{
if (!el.value.match(regExpression) && !el.value == "")
{
alert("Valid e-mail addresses must contain an '@' sign.");
return false;
}
}
el = FindElement(".Data.F10042");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10043");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10044");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10061");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
el = FindElement(".Data.F10062");
if (el)
{
if (el.value == "")
{
alert("Please fill out all the items marked with a '*'.");
return false;
}
}
return true;
}
function DoOnLoad()
{
fillSelector();
}
function DoOnClose()
{
if (UserDialog)
UserDialog.close();
}
function setDates( item, day, month, year)
{
var dayItem = "day" + item;
var monthItem = "month" + item;
var yearItem = "year" + item;
var selIndex = 0;
selIndex = findCalendarItem(parent.opener.document.nvoForm, dayItem, day);
parent.opener.document.nvoForm[dayItem].selectedIndex = selIndex;
selIndex = findCalendarItem(parent.opener.document.nvoForm, monthItem, month);
parent.opener.document.nvoForm[monthItem].selectedIndex = selIndex;
selIndex = findCalendarItem(parent.opener.document.nvoForm, yearItem, year);
parent.opener.document.nvoForm[yearItem].selectedIndex = selIndex;
parent.opener.changeDaysInMonth(item);
parent.window.close();
}
function findCalendarItem(prefix, item, itemValue)
{
for (var i = 0; i <= prefix[item].length; i++)
{
if (prefix[item] && prefix[item].options[i] && (prefix[item].options[i].value == itemValue))
return i;
}
}
function showCalendar(item, weekend, theYear, theMonthNum)
{
var strOP = ""
var bMondayStart = false;
var bShowWeekend = (weekend == "on" ? true : false);
var bDone = false;
var bFirstRow = false;
var theDay = 1;
var theDate = new Date(theYear, theMonthNum-1, 1);
var theFirstDay = theDate.getDay();
var daysInMonth = getDaysInMonth( theDate );
var now = new Date();
var isToday = false;
strOP = "<html><head><title></title>"
+ "<link rel='stylesheet' href='calendar-eng.css' type='text/css'>"
+ "</head>"
+ "<body><center>"
+ "<table border=1 cellpadding=1 cellspacing=0 align=center width=100%>"
+ "<tr>";
if (bShowWeekend && !bMondayStart)
strOP += "<td width=14% class='header'>Sun</td>";
strOP  += "<td width=14% class='header'>Mon</td>"
+ "<td width=14% class='header'>Tue</td>"
+ "<td width=14% class='header'>Wed</td>"
+ "<td width=14% class='header'>Thu</td>"
+ "<td width=14% class='header'>Fri</td>";
if (bShowWeekend)
{
strOP +=  "<td width=14% class='header'>Sat</td>";
if (bMondayStart)
strOP +=  "<td width=14% class='header'>Sun</td>";
}
strOP += "</tr>";
if (bShowWeekend ||
(bMondayStart  && (theFirstDay != 6) && (theFirstDay != 0)) ||
(!bMondayStart && (theFirstDay != 6)))
{
strOP = strOP + "<tr>";
for ( var x = 0; x <= 6; x++ )
{
if (bShowWeekend ||
(bMondayStart  && (x < 5))   ||
(!bMondayStart && (x > 0) && (x < 6)))
{
if ((!bMondayStart && (x < theFirstDay)) ||
(bMondayStart && (((x + 1) < theFirstDay) || ((theFirstDay == 0) && (x < 6)))))
strOP += "<td class='date'>&nbsp;</td>";
else
{
if ((now.getFullYear() == theYear) && (now.getMonth() == (theMonthNum-1)) && (now.getDate() == theDay))
isToday = true;
else
isToday = false;
strOP += "<td class='date'>";
strOP += (isToday ? "<b>" : "");
strOP += "<a href='javascript:parent.cal_header.setDates("+item+","+theDay+",\""+((theMonthNum < 10) ? "0" + theMonthNum : theMonthNum)+"\","+theDate.getFullYear()+");'>" + theDay + "</a>"; 
strOP += (isToday ? "</b>" : "");
strOP += "</td>";
theDay++;
}
}
else
{
if ((bMondayStart && (x >= 5)) ||
(!bMondayStart && ((x == 6) || ((x == 0) && (theFirstDay == 0)))))
theDay++;
}
} // for ( var x = 0; x <= 6; x++ )
strOP += "</tr>";
}
else 
{
theDay++;
if (bMondayStart && (theFirstDay == 6))
theDay++;
}
for ( var y = 0; y <= 4 && !bDone; y++ )
{
strOP = strOP + "<tr>";
for ( var x = 0; x <= 6; x++ )
{
if (bShowWeekend ||
(bMondayStart  && (x < 5))   ||
(!bMondayStart && (x > 0) && (x < 6)))
{
if (!bDone)
strOP += "<td class='date'><a href='javascript:parent.cal_header.setDates("+item+","+theDay+",\""+((theMonthNum < 10) ? "0" + theMonthNum : theMonthNum)+"\","+theDate.getFullYear()+");'>" + theDay + "</a></td>";
else
strOP += "<td class='date'>&nbsp;</td>";
}
if (theDay >= daysInMonth)
bDone = true;
theDay++;
} // for ( var x = 0; x <= 6; x++ )
strOP += "</tr>";
if ((theDay == daysInMonth) && !bMondayStart && !bShowWeekend)
bDone = true;
} // for ( var y = 0; y <= 4; y++ )
strOP += "</table>"
+ "</center></body>"
+ "</html>";        
return strOP;
}
function getDaysInMonth( desiredDate )
{       
var retVal;
var now = new Date();
var millisecondsPerDay = 24 * 60 * 60 * 1000;
now.setMonth(desiredDate.getMonth()+1);
do          
{
now.setTime(now.getTime() - millisecondsPerDay);
retVal = now.getDate();
}                    
while ( desiredDate.getMonth() != now.getMonth() )
if ( ((desiredDate.getFullYear() % 4 ) == 0) && ((desiredDate.getFullYear() % 1000 ) != 0) && (desiredDate.getMonth() == 1) )
{
retVal++;
}
return retVal;
}
function getSelectedMonth(itemUID)
{
var selectedMonth = "";
if (document.nvoForm["month" + itemUID])
selectedMonth = document.nvoForm["month" + itemUID].selectedIndex;
return selectedMonth;
}
function getSelectedYear(itemUID)
{
var selectedYear = "";
var theSelect = document.nvoForm["year" + itemUID];
if (theSelect)
{
for ( var i = 0; i < theSelect.length; i++ )
{
if ( theSelect.options[i].selected == true )
selectedYear = theSelect.options[i].text;
}
}
return selectedYear;
}
function changeDaysInMonth(itemUID)
{
var selectedMonth = getSelectedMonth(itemUID);
var selectedYear  = getSelectedYear(itemUID);
var theDate       = new Date(selectedYear, selectedMonth, 1);
var daysInMonth   = getDaysInMonth(theDate);
var dayItemName   = "day" + itemUID;
var selectedDay   = document.nvoForm[dayItemName].selectedIndex;
if (selectedDay > (daysInMonth-1))
selectedDay = daysInMonth-1;
document.nvoForm[dayItemName].options.length = 0;
for (var i = 0; i < daysInMonth; i++)
{
var day = i+1;
if (selectedDay == i)
selectedDay = i;
document.nvoForm[dayItemName].options[i] = new Option(day,((day < 10) ? "0" + day : day));
}
document.nvoForm[dayItemName].selectedIndex = selectedDay;
}
function fillSelector(requestedDate)
{
var baseCalendarYear = 2001;
var maxCalendarYear = 2040;
var currDate = "";
if (requestedDate)
currDate = requestedDate;
else
currDate = "20091217133805";
var strMonth = new Array;
strMonth[0] = "Invalid Month"
strMonth[1] = "January"
strMonth[2] = "February"
strMonth[3] = "March"
strMonth[4] = "April"
strMonth[5] = "May"
strMonth[6] = "June"
strMonth[7] = "July"
strMonth[8] = "August"
strMonth[9] = "September"
strMonth[10] = "October"
strMonth[11] = "November"
strMonth[12] = "December"
var currYear = currDate.substring(0,4)
var currMonth= currDate.substring(4,6)
var currDay  = currDate.substring(6,8)
var firstDay = new Date(currYear, parseInt(currMonth)-1, 1);
var daysInMonth = getDaysInMonth(firstDay);
baseCalendarYear = parseInt("2002");
maxCalendarYear = parseInt("2040");
document.nvoForm.year10065.options.length = 0
document.nvoForm.month10065.options.length = 0
document.nvoForm.day10065.options.length = 0
var year = baseCalendarYear;
var month = 1;
var day = 1;
var initialYearIndex = 0;
var initialMonthIndex = 0;
var initialDayIndex = 0;
for (var i = 0; i < 12; i++)
{
if (month == currMonth)
initialMonthIndex = i;
document.nvoForm.month10065.options[i] = new Option(strMonth[i+1],((month < 10) ? "0" + month : month));
month++;
}
for (var i = 0; i < daysInMonth; i++)
{
if (day == currDay)
initialDayIndex = i;
document.nvoForm.day10065.options[i] = new Option(day,((day < 10) ? "0" + day : day));
day++;
}
for (var i = 0; i < ((maxCalendarYear - baseCalendarYear) + 1); i++)
{
if (year == currYear)
initialYearIndex = i;
document.nvoForm.year10065.options[i] = new Option(year,year);
year++;
}
document.nvoForm.month10065.selectedIndex = initialMonthIndex;
document.nvoForm.day10065.selectedIndex   = initialDayIndex;
document.nvoForm.year10065.selectedIndex  = initialYearIndex;
DatePulldownsDone = true;
}
function OpenUserDialog(url)
{
if (!UserDialog || UserDialog.closed)
{
UserDialog = window.open(url, "nsspopupcal", "menubar=no,toolbar=no,width=250,height=190,resizable=no,scrollbars=no");
if (!UserDialog.opener)
UserDialog.opener = self;
if (UserDialog.focus != null)
UserDialog.focus();
}
else
{
UserDialog.location.href = url;
UserDialog.focus();
}
}
function OpenCalendarDialog(url, itemUID)
{
if (DatePulldownsDone)
{
var selectedMonth = getSelectedMonth(itemUID) + 1;
var selectedYear = getSelectedYear(itemUID);
OpenUserDialog(url + "&selectedMonth=" + selectedMonth + "&selectedYear=" + selectedYear);
}
}
function DoSubmit()
{
if (!gRunOnce)
{
FillInDateBoxes();
if (!RequiredItemsFilledOut())
return;
var action = "";
// Store selected choices for checkboxes and radio groups in hidden form elements
FillInCheckBoxes();
FillInRadioGroups();
FillInQuantityBoxes();
var selections = new String();
action = "UseProfile(Name=customforms1);AddRecord(List=Data&Where=Bottom)";
el = FindElement(".Data.F10053SEL");
if (el)
{
el.value = document.nvoForm[".Data.F10053"].selectedIndex;
}
el = FindElement(".Data.F10066SEL");
if (el)
{
el.value = document.nvoForm[".Data.F10066"].selectedIndex;
}
var submitLimitThreshold = 1000 - (1000 * 0.1);
var submitModulus = 1000 * 0.025;
if (((26 >= submitLimitThreshold) && (1000 % submitModulus == 0)) ||
(1000 - 26 < 5))
{
action += ";UseProfile(Name=customforms1)";
action += ";SendMail(File=/pages/apps/form/warning.txt)";
}
action += ";UseProfile(Name=customforms1)";
action += ";SendMail(File=/pages/apps/form/message.txt)";
DoButton(action);
gRunOnce = 1;
} // not run once
}
