// Support Script (663)
function Validate(stopOnFailure)
{
	var ErrorMsg = "";
	var i
	var msg
	var tofocus = true;
	var ErrorMsg = "";
	
	// Go through the Validate Array that may or may not exist
	// and call the Validate function for all elements that have one.
	if (document.ValidateArray)
	{
		for (i = 0; i < document.ValidateArray.length; i ++)
		{
			msg = eval( document.ValidateArray[i] + ".Validate()")
			if (msg != "")
			{
				ErrorMsg += "\n\n" + document.ValidateArray[i] + ":  " + msg;
				if (tofocus) 
				{
					eval(document.ValidateArray[i] + ".focus()")
					tofocus = false;
				}
				
				if (stopOnFailure == "1") return ErrorMsg;
			}
  	}
  }
	return ErrorMsg;
}

// Support Script (669)
function AddToValidateArray(strElementName)
{
    var strName = strElementName

    if (!document.ValidateArray) 
    {
        document.ValidateArray = new Array
    }

    document.ValidateArray[document.ValidateArray.length] = strName
}

// Support Script (665)
// These date functions work for Nav 3 and above.

function getDayName(d)
{   
   var theDay = d.getDay()

   if (theDay == 0) 
            return "Sunday"
   if (theDay == 1) 
            return "Monday"
   if (theDay == 2) 
            return "Tuesday"
   if (theDay == 3) 
            return "Wednesday"
   if (theDay == 4) 
            return "Thursday"
   if (theDay == 5) 
            return "Friday"
   if (theDay == 6) 
            return "Saturday"
}

function getFullYear(d)
{
   var y = d.getYear();

   if (y < 2000) 
   {
        y += 1900
   }

   return y
}

function getMonthName(d)
{
   var theMonth = d.getMonth()
   
   if (theMonth == 0) 
            return "January"
   if (theMonth == 1) 
            return "February"
   if (theMonth == 2) 
            return "March"
   if (theMonth == 3) 
            return "April"
   if (theMonth == 4) 
            return "May"
   if (theMonth == 5) 
            return "June"
   if (theMonth == 6) 
            return "July"
   if (theMonth == 7) 
            return "August"
   if (theMonth == 8) 
            return "September"
   if (theMonth == 9) 
            return "October"
   if (theMonth == 10) 
            return "November"
   if (theMonth == 11) 
            return "December"
}

// A helper function for the other functions in this
// support script

function DateSupportReplaceAwithBinC(aa,bb,cc)
{
 var a = aa + ""
 var b = bb + ""
 var c = cc + ""
	var i = c.indexOf(a);
	var l = b.length;
	while (i != -1)	
 {
		c = c.substring(0,i) + b + c.substring(i + a.length,c.length);
  i += l
		i = c.indexOf(a,i);
	}
	return c;
}


function ReplaceTokensWithTimeDate(strIn, leadingZeroes, zoneDiff)
{
    var strOut = strIn
    var now = new Date()
    var d = new Date(now.getTime() + zoneDiff)

    var theTime = ""
    var theHours
    var theMinutes
    var theSeconds
    var ampm = "am"

    theHours = d.getHours()
    if (theHours >= 12)
    {
        ampm = "pm"
    }
    if (theHours > 12)
    {
         theHours -= 12   
    }

    theMinutes = d.getMinutes()
    if (leadingZeroes, theMinutes < 10)
    {
        theMinutes = "0" + theMinutes
    }
    
    theTime = theHours + ":" + theMinutes + ampm

    theSeconds = d.getSeconds()
    if (leadingZeroes && theSeconds < 10)
    {
        theSeconds = "0" + theSeconds
    }

    strOut = DateSupportReplaceAwithBinC("[monthname]", getMonthName(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[monthnumber]", d.getMonth(d) + 1, strOut)
    strOut = DateSupportReplaceAwithBinC("[dayname]", getDayName(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[daynumber]", d.getDate(), strOut)
    strOut = DateSupportReplaceAwithBinC("[year]", getFullYear(d), strOut)
    strOut = DateSupportReplaceAwithBinC("[time]", theTime, strOut)
    strOut = DateSupportReplaceAwithBinC("[hours]", theHours, strOut)
    strOut = DateSupportReplaceAwithBinC("[minutes]", theMinutes, strOut)
    strOut = DateSupportReplaceAwithBinC("[seconds]", theSeconds, strOut)
    strOut = DateSupportReplaceAwithBinC("[ampm]", ampm, strOut)

    return strOut
}


// This function takes the name of an edit box and a 
// flag that says whether or not to pad single digit 
// minutes and seconds with a zero.  It provides a 
// real time clock in an edit box.
//
function SetTimeText(strElementName, blnLeadingZeroes, zoneDiff)
{
  var theObj = eval(strElementName)

  theObj.setText(ReplaceTokensWithTimeDate(theObj.ContentString,blnLeadingZeroes, zoneDiff))
  setTimeout("SetTimeText('" + strElementName + "'," + blnLeadingZeroes + "," + zoneDiff + ")",1000)
}

// Returns a JavaScript Date object
// Expected format of date is 8/17/1998
// Expected format of time is 12:02am or 1:09pm
// Gives an error message if format is wrong.
//
function MakeDate(strDate, strTime)
{

 var tempDate = new Date(strDate)
 var strFormatted = getMonthName(tempDate) + " " + tempDate.getDate() + ", " + getFullYear(tempDate)

	var colonPos = strTime.indexOf(":")
	var ampmPos = strTime.indexOf("am")
	if (ampmPos == -1)
		ampmPos = strTime.indexOf("AM")
    if (ampmPos == -1)
		ampmPos = strTime.indexOf("pm")
	if (ampmPos == -1)
		ampmPos = strTime.indexOf("PM")

	// assume format of time is okay
	var theHours = strTime.substring(0,colonPos)
	var theMinutes = strTime.substring(colonPos + 1, ampmPos)
	var ampm = strTime.substring(ampmPos, strTime.length)
	ampm = ampm.toUpperCase()

	if (ampm == "PM")
	{
		if (theHours != "12")
		{
			theHours += 12
		}
	}
	else
	{
		if (theHours == "12")
		{
			theHours = "0"
		}
	}

	var outDate = new Date(strFormatted + " " + theHours + ":" + theMinutes)
	return outDate
}

// Support Script (690)
function dbi_ValidateDate() {
 var msg = "";
 var fullYear = ""
 var fullYear2 = ""
 var bFourYear = ""
 var theString = this.getText()
 var dateVar = new Date(theString);
 var Today = new Date();
 var peavd = "Please enter a valid "
 peavd += (this.FourYear==1) ? " 4 year digit " : ""
 peavd += "date. \n(for example "
 peavd += (Today.getMonth()+1) + "/" + Today.getDate() + "/" + Today.getFullYear();
 peavd += " or "
 peavd +=  getMonthName(Today) + " " + Today.getDate() + ", " + Today.getFullYear();
 peavd += " or "
 peavd += Today.getDate() + " " + getMonthName(Today) + ", " + Today.getFullYear();
 peavd += ")";

	var theLen = StripChars(" ",theString).length
	if (theLen == 0)
	{
		if (!this.Required) return "";
		else return "Required field.  " + peavd;
	}

	if (isNaN(dateVar.valueOf()) || (dateVar.valueOf() == 0))
		return peavd;

	// Check for correct range.
	if (this.when == "Past")
	{
		if (dateVar >= Today)
		return "Please enter a date in the past (Today is " + Today.toLocaleString() +")";
	}
	if (this.when == "Future")
	{
		if (dateVar <= Today)
		return "Please enter a date in the future (Today is " + Today.toLocaleString() +")";
	}

	// We have a valid date. Reformat it and write it back to the control
	var style = this.Reformat;
	var d = dateVar;
	fullYear = d.getYear();
	fullYear2 = d.getFullYear();
	bFourYear = dbi_isFourYear(theString)

	if(bFourYear){
		fullYear = fullYear2
	}
	else if (String(this.FourYear)=="1" && (bFourYear==false)) {
 		return peavd;
	}
	else if (bFourYear==false){
 		fullYear = fullYear2
	}
 
 if (style == "MM/DD/YYYY") {
	  var date_string = (d.getMonth()+1) + "/" + d.getDate() + "/" + fullYear;
	}
	else if (style == "MM-DD-YYYY") {
	  var date_string = (d.getMonth()+1) + "-" + d.getDate() + "-" + fullYear;
	}
	else if (style == "DD/MM/YYYY") {
	  var date_string = d.getDate() + "/" + (d.getMonth()+1) + "/" + fullYear;
	}
 else if (style == "Month Day, Year") {
	  var date_string = getMonthName(d) + " " + d.getDate() + ", " + fullYear;
	}
 else if (style == "Day Month, Year") {
	  var date_string = d.getDate() + " " + getMonthName(d) + ", " + fullYear;
	}
	else if (style == "Day of week, Month Day, Year") {
	  var date_string = getDayName(d) + " " + getMonthName(d) + " " + d.getDate() + ", " + fullYear;
	}
	else if (style == "Locale") {
	  var date_string = d.toLocaleString();
	}
	else if (style == "Don't reformat") {
	  var date_string = theString;
	}
	else {
	  var date_string = d.toGMTString();
 }

	this.setText(date_string);

	return msg;
}

// Test if four year date was entered
function dbi_isFourYear(x) {
	var len = ""

	if (x.indexOf(", ")!=-1) {
		x = x.split(", ")
		len = (x.length >= 2) ? x[1].length : 0
	}
	else if (x.indexOf("/")!=-1) {
		x = x.split("/")
		len = (x.length >= 3) ? x[2].length : 0
	}
	else if (x.indexOf("-")!=-1) {
		x = x.split("-")
		len = (x.length >= 3) ? x[2].length : 0
	}
	if (len == 4) {
		return true
	}
	else {
		return false
	}
}
// Support Script (670)
function StripChars(theFilter,theString)
{
	var strOut,i,curChar

	strOut = ""
	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}

function AllInRange(x,y,theString)
{
	var i, curChar
	
	for (i=0; i < theString.length; i++)
	{
		curChar = theString.charAt(i)
		if (curChar < x || curChar > y) //the char is not in range
			return false
	}
	return true
}


function reformat (s)
{
    var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) 
           resultString += arg;
       else 
       {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function Trim(theString)
{
 var i,firstNonWhite

 if (StripChars(" \n\r\t",theString).length == 0 ) return ""

	i = -1
	while (1)
	{
		i++
		if (theString.charAt(i) != " ")
			break	
	}
	firstNonWhite = i
	//Count the spaces at the end
	i = theString.length
	while (1)
	{
		i--
		if (theString.charAt(i) != " ")
			break	
	}	

	return theString.substring(firstNonWhite,i + 1)

}
// Support Script (587)
function ValidateDropDown()
{
  msg = "";
  var iPos = this.getSelectedPosition();
  if (iPos<=0)
  {
    msg = "Please make a selection."
  }

  return msg;
}
function document_onLoad() {
dte.Validate = dbi_ValidateDate;
dte.when = "Future";
dte.Required = Number("1");
dte.Reformat = "MM/DD/YYYY";
dte.FourYear = "1"
AddToValidateArray("dte")
vehicle.Validate = ValidateDropDown;
AddToValidateArray("vehicle")
service.Validate = ValidateDropDown;
AddToValidateArray("service")
 }
function Setup_onSubmit() {
errorMsg = Validate("0"); // don't stop on first error

if (errorMsg != "")
    alert("The form could not be submitted:" + errorMsg);

return (errorMsg == ""); // false prevents form submission
 }
function _Setup_onSubmit() { if (Setup) return Setup.onSubmit(); }
function Image10_onClick() {
var options="";
options+="status="+(("0"=="1")?"yes":"no")
options+=",directories="+(("0"=="1")?"yes":"no")
options+=",location="+(("0"=="1")?"yes":"no")
options+=",toolbar="+(("0"=="1")?"yes":"no")
options+=",menubar="+(("0"=="1")?"yes":"no")
options+=",scrollbars="+(("0"=="1")?"yes":"no")
options+=",resizable="+(("0"=="1")?"yes":"no")

if (parseInt("270")  > 0) options+=",width="+"270"
if (parseInt("160") > 0) options+=",height="+"160"

if (parseInt("-1") >= 0)
{
	options+=",top="+"-1"
	options+=",screenY="+"-1"
}
if (parseInt("-1") >= 0)
{
	options+=",left="+"-1"
	options+=",screenX="+"-1"
}

page = "cal_pop.htm";

window.open(page,"NewWindow",options);
 }
function _Image10_onClick() { if (Image10) return Image10.onClick(); }
function help2_onClick() {
helpWin("help_services.asp")
 }
function _help2_onClick() { if (help2) return help2.onClick(); }
function help1_onClick() {
helpWin("help_vehicles.asp")
 }
function _help1_onClick() { if (help1) return help1.onClick(); }
function help3_onClick() {
helpWin("help_area.asp")
 }
function _help3_onClick() { if (help3) return help3.onClick(); }
function help4_onClick() {
helpWin("help_date.asp")
 }
function _help4_onClick() { if (help4) return help4.onClick(); }
function Text7_Inline(html) {
document.write(ReplaceTokensWithTimeDate(html,parseInt("1"),0))
 }
function _Text7_Inline(html) { if (Text7) return Text7.Inline(html); }
function FormButton1__onClick() {
return ckForm();
 }
function _FormButton1__onClick() { if (FormButton1) return FormButton1.onClick(); }


