var MonthFull = new Array(12);
var MonthShort = new Array(12);
MonthFull[0] = "January";
MonthFull[1] = "February";
MonthFull[2] = "March";
MonthFull[3] = "April";
MonthFull[4] = "May";
MonthFull[5] = "June";
MonthFull[6] = "July";
MonthFull[7] = "August";
MonthFull[8] = "September";
MonthFull[9] = "October";
MonthFull[10] = "November";
MonthFull[11] = "December";
MonthShort[0] = "JAN";
MonthShort[1] = "FEB";
MonthShort[2] = "MAR";
MonthShort[3] = "APR";
MonthShort[4] = "MAY";
MonthShort[5] = "JUN";
MonthShort[6] = "JUL";
MonthShort[7] = "AUG";
MonthShort[8] = "SEP";
MonthShort[9] = "AUG";
MonthShort[10] = "NOV";
MonthShort[11] = "DEC";

function FillDate(InDate, DateFormat, separator)
{
	if (InDate.value != DateFormat) 
	{
		return;
	}
	var curdate= new Date(); 
	var MonthOrder = 0;
	var DayOrder = 0;
	var YearOrder = 0;
	var Order = 0;

	var curyear = curdate.getYear() + "";
	
	var curmonth = curdate.getMonth()+1 + "";
	var curday = curdate.getDate() + "";
	var MonthLoc = -1, YearLoc = -1, DayLoc = -1;
	var newdate = "";
	var fourdigit = false;

	for (var i=0; i< DateFormat.length; i++)
	{
		if (DateFormat.substring(i,i+3) == "MMM" && MonthLoc == -1)
		{
			Order++;
			curmonth = MonthShort[curdate.getMonth()];
			MonthOrder = Order;
			MonthLoc = i;
		}
		else if (DateFormat.substring(i,i+2) == "MM" && MonthLoc == -1)
		{
			Order++;
			if (curmonth.length == 1)
			{	
				curmonth = "0" + curmonth;
			}
			MonthOrder = Order;
			MonthLoc = i;
		}
		else if (DateFormat.substring(i,i+4) == "YYYY" && YearLoc == -1)
		{
			Order++;
			YearOrder = Order;
			if (curyear < 1000) 
			{
				curyear += 1900;
			}
			YearLoc = i;
			fourdigit = true;
		}
		else if (DateFormat.substring(i,i+4) == "RRYY" && YearLoc == -1)
		{
			Order++;
			YearOrder = Order;
			YearLoc = i;
			fourdigit = true;
		}
		else if (DateFormat.substring(i,i+2) == "YY" && YearLoc == -1)
		{
			Order++;
			YearOrder = Order;
			YearLoc = i;
		}
		else if (DateFormat.substring(i,i+2) == "DD" && DayLoc == -1)
		{
			Order++;
			DayOrder = Order;
			if (curday.length == 1)
			{
				curday = "0" + curday;
			}
			DayLoc = i;
		}
	}
	
	for (x =1;x<=3;x++)
	{
		if (DayOrder == x)
		{
			newdate = newdate + "" +  curday;
		}
		if (MonthOrder == x)
		{
			newdate = newdate + "" + curmonth;
		}
		if (YearOrder == x)
		{
			if (fourdigit == false)
			{
		   		if (curyear.length == 4)
				{
					curyear = curyear.substring(2,4);
				}
			}
			newdate = newdate + "" + curyear;
		}
		if ((x == 1 || x == 2) && separator > "")
			newdate = newdate + separator;
	}
	InDate.value = newdate;
//	InDate.select();
}
function IsEmpty(InField)
{
	if (InField == null || InField.length ==0) 
	{
		return true;
	}

   var i;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < InField.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = InField.charAt(i);

        if (c!=" ") return false;
    }

    // All characters are whitespace.
    return true;
}

function IsNotEmpty(InField)
{
	if (IsEmpty(InField) == true) 
	{
		return false;
	}
	else
	{
		return true;
	}
}

function IsNumeric(InField)
{
	if (IsEmpty(InField)) 
		return true;

	var j=0;
	for (var i=0; i< InField.length; i++)
	{
		if (InField.charAt(i) != " ")
		{	
			j = i;
			break;
		}
	
	}
	
	for (var i=j; i< InField.length; i++)
	{
		var digit= InField.charAt(i);
		if ((digit >= "0" && digit <= "9") || (i == j && digit == "-")) 
			continue;	 
		else
		if (digit == " ")
			for (var h = i; h < InField.length; h++)
			{
				if (InField.charAt(h) != " ")
				{	
					return false;
				}	
			}	
		else 
			return false;
				
	}
	return true;		
}


function IsDecimal(InField)
{
	
    if (IsEmpty(InField))
		return true;
		
	var j=0;
	var f_str= null;
	var l_str= null;
	for (var i=0; i< InField.length; i++)
	{
		if (InField.charAt(i) != " ")
		{	
			j = i;
			break;
		}
	
	}

	var v_decimal = "N";
	
	for (i = j; i < InField.length; i++)
	{	
		if (InField.charAt(i) == ".")
		{
			f_str = InField.substr(j, i-j);
			l_str = InField.substr(i+1, InField.length-i-1);
			v_decimal ="Y";
			break;
		}	
		else
			continue;
	}

		
	if (v_decimal =="N" && IsNumeric(InField)) return true;
	
	if (f_str == null)	f_str = InField;

	
	if (IsNumeric(f_str) == false || (f_str.charAt(f_str.length-1) <"0" || f_str.charAt(f_str.length-1) > "9")) return false;
	
	if (IsNumeric(f_str) == false) return false;
	
	if (l_str != null && (l_str.charAt(0) < "0" ||l_str.charAt(0) > "9" || IsNumeric(l_str) == false)) return false;
	
	return true;		
						
}	


function IsReqDecimal(InField)
{
	if (IsEmpty(InField) == true || IsDecimal(InField) == false)
		return false;
	else	
		return true;		
}


function IsReqNumeric(InField)
{
	if (IsNumeric(InField) == false || IsEmpty(InField) == true)
	{
		return false;
	}
	else
	{
		return true;
	}
}
 function IsValidDate(DateString, DateFormat)
{
	var DayLoc = -1;
	var DayLen = 2;
	var MonthLoc = -1;
	var MonthLen = 0;
	var YearLoc = -1;
	var YearLen = 0;
	var DateLen = 0;

	for (var i=0; i< DateFormat.length; i++)
	{
		if (DateFormat.substring(i,i+1) == "/" || DateFormat.substring(i,i+1) == "-")
		{
			//return IsValidDate2(DateString, DateFormat);
			break;
		}
	}

	DateLen = DateFormat.length;

	if (IsEmpty(DateString) || DateFormat == DateString)
	{
		return true;
	}
	for (var i=0; i< DateFormat.length; i++)
	{
		if (DateFormat.substring(i,i+3) == "MMM" && MonthLoc == -1)
		{
			MonthLoc = i;
			MonthLen = 4;
		}
		else if (DateFormat.substring(i,i+2) == "MM" && MonthLoc == -1)
		{
			MonthLoc = i;
			MonthLen = 2;
		}
		else if (DateFormat.substring(i,i+4) == "YYYY" && YearLoc == -1)
		{
			YearLoc = i;
			YearLen = 4;
		}
		else if (DateFormat.substring(i,i+4) == "RRYY" && YearLoc == -1)
		{
			YearLoc = i;
			YearLen = 2;
			DateLen = DateLen-2;
		}
		else if (DateFormat.substring(i,i+2) == "YY" && YearLoc == -1)
		{
			YearLoc = i;
			YearLen = 2;
		}
		else if (DateFormat.substring(i,i+2) == "DD" && DayLoc == -1)
		{
			DayLoc = i;
			DayLen = 2;
		}
	}
	if (DateLen != DateString.length)
	{
		alert ("Date is Incorrect\nPlease use " + DateFormat + " Format");
		return false;
	}
	
	Day=DateString.substring(DayLoc,DayLoc + DayLen);
	Month=DateString.substring(MonthLoc,MonthLoc +  MonthLen);
	Year=DateString.substring(YearLoc,YearLoc + YearLen);

	if (IsNumeric(Day) == false || IsNumeric(Year) == false || (MonthLen == 2 && IsNumeric(Month) == false))
	{
		alert ("Day and year must be numeric\nPlease use " + DateFormat + " Format");
		 return false;
	}
	if (Day < "0" || Day > "31")
	{
		alert("Day is incorrect\nPlease use " + DateFormat + " Format");
		return false;
	}
	var foundvalid = false;
	if (MonthLen == 3)
		for (var i = 0; i <= 11; i++)
		{
			if (MonthShort[i] == Month.toUpperCase())
			{
				foundvalid=true;
				break;
			}
		}
	else if (MonthLen == 2)
	{
		if (Month > 0 && Month <= 12)
		{
			foundvalid = true;
		}
	}
	if (foundvalid == false)
	{
		alert("Month is incorrect\nPlease use " + DateFormat + " Format");
		return false;
	}
	if (Year.length != YearLen || (YearLen == 4 && (Year.substring(0,2) != 19 && Year.substring(0,2) != 20)))
	{
		alert("Year is incorrect\nPlease use " + DateFormat + " Format");
		return false;
	}
	return true;
}

function IsValidReqDate(inDateString, inDateFormat)
{
	if (IsValidDate(inDateString, inDateFormat) == true && IsEmpty(inDateString) == false && inDateString != inDateFormat)
	{
		return true;
	}
	else
	{
		if (IsEmpty(inDateString) == true)
		{
			alert("Date Field is required");
		}
		return false;
	}
}
function SearchForChar(InField, InChar)
{
	for (var i=0; i< InField.length; i++)
	{
		if (InField.substring(i,i+InChar.Length) == InChar)
		{
			return i;
		}
	}
	return -1;
}
function ReplaceChar(InField, InChar, newChar)
{
	
	var outReplaceChar = "";
	for (var i=0; i< InField.length; i++)
	{
		if (InField.substring(i,i+InChar.length) == InChar)
		{
			outReplaceChar = outReplaceChar + newChar;
			i = i+InChar.Length-1;
		}
		else
		{
			outReplaceChar = outReplaceChar + InField.substring(i,i+1);
		}
		
	}
	return outReplaceChar;
}
	
function IsRadioEmpty(radio_group)
{
	for (var i=0; i< radio_group.length; i++)
	{
		if (radio_group[i].checked == true)
		{
			return false;
		}
	}
	return true;
}

//This will handle checkboxes and radio buttons that do not have a value
function SubmitForm(formname)
{
    var sNewURL;
    var bFirstField = true;
    var prevRadio = " ";
    sNewURL = formname.action;
    bSkipField = false;
    bfound = false;
    for (var i =  0; i< formname.elements.length;i++)
    {
//	alert(formname.elements[i].name + " " + formname.elements[i].value);
	if (formname.elements[i].type != "submit" 
	 && formname.elements[i].type != "button" 
         && formname.elements[i].type != "reset")
	{
		if (bFirstField == true)
		{
		   sNewURL = sNewURL + "?";
		   bFirstField = false;
		}
		else if (bSkipField == false)
		{
		   sNewURL = sNewURL + "&";
		}
		else
		{
		   bSkipField = false;
		}
		if (formname.elements[i].type == "checkbox")
	        	sNewURL = sNewURL + formname.elements[i].name + "=" + formname.elements[i].checked;
		else if (formname.elements[i].type == "radio")
		{
			if (formname.elements[i].name != prevRadio)
			{  
			    bfound = false;
			    for (var x =  i; x< formname.elements.length;x++)
			    {
				if (formname.elements[x].name == formname.elements[i].name)
				{
				   if (formname.elements[x].checked == true)
				    {
 				    sNewURL = sNewURL + formname.elements[i].name + "=" + formname.elements[x].value;
				    bfound = true;
				    }
				}
			    }
			    if (bfound = false)
				{
 				    sNewURL = sNewURL + formname.elements[i].name + "=false";
				}
			}
			else
				bSkipField = true;
	        	prevRadio = formname.elements[i].name;
		}
		else
	        	sNewURL = sNewURL + formname.elements[i].name + "=" + escape(formname.elements[i].value);
	}
    }
//    alert(sNewURL);
    if (sNewURL.length < 1000)
       location =sNewURL;
    else
       alert("Sorry.. but your message is too long.  Please try Shortening the message and try again.\nSorry for the Inconvenience");
    return false;
}

   function checkdate ( vbl )
        {
          var err =0;         
          if (vbl.length !=6) 
               err=1;
          b = vbl.substring(0,2);          
          d = vbl.substring(2,4);          
          f = vbl.substring(4,6);  
     if (b<1 || b>12) 
         err = 1;       
     if (d<1 || d>31) 
         err = 1;
      if (b==4 || b==6 || b==9 || b==11)
        {
          if( d==31) 
            err =1;
        } 
       if (b==2)
     {       
       var g=parseInt(f/4)
        if (isNaN(g))
         { 
          err=1;
         }
        if (d>29)
            err = 1;
        if (d==29 && ((f/4) !=parseInt(f/4))) 
          err = 1;
     } 
        if (err==1)     
          return false;       
        return true
       }
       
   function isInteger ( vbl )
        {
         var ctr;
       vbl += ""; 
       for ( ctr=0; ctr < vbl.length; ++ctr )
        {
        if ( "1234567890".indexOf ( vbl.substring (ctr, ctr + 1)) == -1)
           {
            return false;
            }
         }        

        return true;
			
        }

function isInteger2 ( vbl )
        {
         var ctr;
       vbl += ""; 
       for ( ctr=0; ctr < vbl.length; ++ctr )
        {
        if ( "1234567890.-".indexOf ( vbl.substring (ctr, ctr + 1)) == -1)
           {
            return false;
            }
         }        

        return true;
			
        }

function isInteger3 ( vbl )
        {
         var ctr;
       vbl += ""; 
       for ( ctr=0; ctr < vbl.length; ++ctr )
        {
        if ( "1234567890-".indexOf ( vbl.substring (ctr, ctr + 1)) == -1)
           {
            return false;
            }
         }        

        return true;
			
        }
function fmtPrice(value)
              {
                result=Math.floor(value)+".";
                var cents=100*(value-Math.floor(value))+0.5;
                result += Math.floor(cents/10);
                result += Math.floor(cents%10);
               return result;
        }

function IsValidTime(sTime)
{
	var iHours = 0, iMinutes = 0;
	if (sTime.length != 4 && sTime.length > 0)
	{
		return false;
	}
	iHours = sTime.substring(0,2);
	iMinutes = sTime.substring(2,4);
	if (IsNumeric(sTime) == false)
	{
		return false;
	}
	if (iHours < 0)
	{
		return false;
	}
	if (iHours > 23)
	{
		return false;
	}
	if (iMinutes < 0)
	{
		return false;
	}
	if (iMinutes > 59)
	{
		return false;
	}
	return true;
}
function IsValidReqTime(sTime)
{
	if (IsValidTime(sTime) == false || IsEmpty(sTime) == true)
		return false;
	else
		return true;
}


function IsYear(s)
{
	if( IsEmpty(s) == true ) return false;
	if( IsNumeric(s) == false) return false;
	if( (s.length != 2) && (s.length != 4)) return false; 
	return true; 
}

function IsDay(s, mth, year)
{
var daysInMonth = Array(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;
	var intMonth = parseInt(mth);
	var intYear = parseInt(year);
	var intDay;
	var leap_year4 = (intYear%4);
	if( IsEmpty(s) == true ) {return false;}
	if( IsNumeric(s) == false) {return false;};
	if( s.length != 2 ) return false; 
	if( s.charAt(0) == "0" )
	{
		intDay = parseInt(s.charAt(1));
	}
	else
	{
		intDay = parseInt(s);
	}
	if( (intDay < 1 ) || (intDay > 31) ) {return false;} 
	if( intDay > parseInt(daysInMonth[intMonth]) ) {return false;} 
	if( intMonth == 2 ) 
	{
		if (leap_year4 == 0)
		{
			if(intDay > 29) return false;
		}
		else
		{
			if(intDay > 28) return false;
		}
	}
	return true; 
}
function IsMonth(s)
{
	if( IsEmpty(s) == true ) {return false;}
	if( IsNumeric(s) == false) {return false;};
	if( s.length != 2 ) return false; 
	var intMonth;
	if( s.charAt(0) == "0" )
	{
		intMonth = parseInt(s.charAt(1));
	}
	else
	{
		intMonth = parseInt(s);
	}
	if( (intMonth < parseInt("1") ) || (intMonth > parseInt("12")) ) {return false;}; 
	return true; 
}
//	Auto Print
function printPage()
	{
		if (window.print)
			{	agree = confirm("OK to print now?");
				if (agree) window.print(); 
			}
	} 
//	Disable Submit
function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
}
setTimeout('alert("Your form has been submitted.")', 2000);
return true;
}
else {
alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
return false;
   }
}
//	Field Explain
function explain(name, output, msg) {
newwin = window.open('','','top=150,left=150,width=325,height=300');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form>' + msg + '<br>');
write('<p>You may enter your ' + name + ' here and it will be copied into the form for you.');
write('<p><center>' + name + ':  <input type=text name=box size=10 onKeyUp=' + output + '=this.value>');
write('<p><input type=button value="Click to close when finished" onClick=window.close()>');
write('</center></form></body></html>');
close();
   }
}
//	Checkbox Text
function changeBox(cbox)
	{	box = eval(cbox);
		box.checked = !box.checked;	}
//	Auto Tab
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e)
	{	var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode))
			{	input.value = input.value.slice(0, len);
				input.form[(getIndex(input)+1) % input.form.length].focus();	}
function containsElement(arr, ele)
	{	var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;	}
function getIndex(input)
	{	var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	return true;	}		


<!-- Comment to allow old browsers to not interpret Javascript code

// Requires a date in month, day , year format, FormName, Fieldname, Field on screen description. 
// formats a message if date is invalid...
// You must declare the following global variables in your script to 
// for this to work.
//  var month;
//  var day;
//  var year;

 function ValidateDate(date, FormName, FieldName, FieldDesc)
{

  if (SplitDate(date) == false)
   {
    alert("The date is invalid in the " + FieldDesc + " field.");
    eval("document." + FormName + "." + FieldName + ".focus()");
	// 		document.requestform.beg_dt.focus();
	return false;
   }
  
 // alert("Month = " + month); 
 // alert("Day = " + day);
 // alert("Year = " + year);

  if (isMonth(month) == false)
   {
     alert("The month is invalid in the " + FieldDesc + " field.");
     eval("document." + FormName + "." + FieldName + ".focus()");
   	 return false;
   }// end of if
   
   if (isDay(day) == false)
   {
   	alert("The day is invalid in the " + FieldDesc + " field.");
    eval("document." + FormName + "." + FieldName + ".focus()");
   	return false;
   }// end of if
   
      
   if (isYear(year) == false)
   {
    alert("The year is invalid in the " + FieldDesc + " field.");
    eval("document." + FormName + "." + FieldName + ".focus()");
	return false;
   }// end of if
   
   if (isDate(year,	month,	day) == false)
   {
    alert("The date is invalid in the " + FieldDesc + " field.");
    eval("document." + FormName + "." + FieldName + ".focus()");
   	return false;
   }// end of if
   
    return true;
 }

		

// Returns true if date is in valid mm dd yy date format was passed
// You must declare the following global variables in your script to 
// for this to work.
//  var month;
//  var day;
//  var year;
//  var newDate;
// This function will split out any of the following formats:
//   mmddyy
//	 mmddyyyy
//	 m/d/yy
//	 m/d/yyyy
//	 mm/dd/yy
//	 mm/dd/yyyy
//	 m-d-yy
//	 m-d-yyyy
//	 mm-dd-yy
//	 mm-dd-yyyy
//	 m.d.yy
//	 m.d.yyyy
//	 mm.dd.yy
//	 mm.dd.yyyy
//	 m d yy
//	 m d yy
//	 mm dd yy
//	 mm dd yyyy
// loads the converted date into the global variable var newDate;

function SplitDate(date)
{
  var strSeparatorArray = new Array("-"," ","/",".");
  var strDateArray;
  var dateFound = false;
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (date.indexOf(strSeparatorArray[intElementNr]) != -1) 
			{
				strDateArray = date.split(strSeparatorArray[intElementNr]);
				if (strDateArray.length != 3) 
				{
					return false;
	  				
   				}// end of if
    			else {
						month = strDateArray[0];
						day = strDateArray[1];
						year = strDateArray[2];
				
						dateFound = true;
					 }
   			}
	}

  if (dateFound == false) 
  {
	if (Date.length > 5) 
	{
		month = date.substr(0, 2);
		day = date.substr(2, 2);
		year = date.substr(4);
   		dateFound = true;
   	}
  }
 
 if (month.length == 1) 
	{
      month = "0" + month;
	}
 if (day.length == 1) 
	{
      day = "0" + day;
	}
if (year.length == 2) 
	{
	 if (year > 49)
	 {
	    year = "19" + year;
	 }
	 else
	 {
	    year = "20" + year;
	 }
	}

  newDate = month + '/' + day + '/' + year;
  return true;
}

// Returns true 
// this function will create a beg date of the first day of the month
// and a ending date of current date.  This is for month-to-date reports
// You must declare the following global variables in your script to 
// for this to work.
//  var defBegDate;
//  var defEndDate;
// loads the converted date into the global variable var newDate;
