var browser = new Browser();

if (browser.ie4 || browser.ie5){
	document.write("<iframe id='spCal' name='spCal' STYLE='display:none; border:ridge;position:absolute;width:200;height:160;z-index=105' MARGINHEIGHT='0' MARGINWIDTH='0' width:156 SCROLLING='NO' src='/common/tiles/blank.jsp'></iframe>");
}

if (browser.ns6 || browser.ns4){
	document.write("<div id='spCal' name='spCal' class='content' STYLE='display:none; border:ridge;position:absolute;width:200;height:160;z-index=4' MARGINHEIGHT='0' MARGINWIDTH='0' width:156 SCROLLING='NO'></div>");
}

/*
================================================================================================
 Matthew Payne 04/1/2001
 Extended and updated by Mark Jacobsen

 Functionality presents an interactive calendar for a use to pick a date from.
 The current supported date format is 'mm/dd/yyyy'. Originally, the calendar was drawn in 
 a popup window(some of that code is left commented out.  I decided to create a calendar drop-down with similiar functionality to the 
 date picker used by expedia.com ie the calendar automatically is positioned below the object it is called from.
 
 To utilize this functionality for a text box, a call would look something like ->
 <INPUT id=cmdDisplayCalEnd  onclick="javascript:buildCal(frmDateSelect.txtEndDate);" name=cmdDisplayCalEnd type=button style="HEIGHT: 22px; WIDTH: 19px" value=...>

Extended usage:
To get a text box and the control simply wrap the following code w/ script tags...
document.write( getControlCode('date', '/common/images/show-calendar.gif') );
where the first parameter to getControlCode is the name of the field and the
second parameter is the location of the image to use.

Updates
03/08/2005 	Mark Jacobsen	Fixed next/previous year "buttons"
11/11/2005 	Mark Jacobsen 	Increased height of the calendar so all items fit
11/14/2005 	Mark Jacobsen 	Added src to iframe so we don't get the "show secure and unsecure items" message when on https
================================================================================================
*/

//var newformat = {date:{m:0,d:1,y:2},time:{h:0,m:1}};

/*  
	Functions for validating dates
	var newformat = {date:{d:0,m:1,y:2},time:{h:0,m:1}}; is the format = dd/mm/yyyy
	var newformat = {date:{m:0,d:1,y:2},time:{h:0,m:1}}; is the format = mm/dd/yyyy
*/

var displayFormat = "MM/dd/yyyy";
var newformat = displayFormat;
var workingDate = new Date();

function getControlCode(fieldName, imageSrc){
	var sHTML = new String();
	sHTML = "<input type='text' name='" + fieldName + "' value='" + getCurDate() + "' size='9'>";
	sHTML = sHTML + "<a href='javascript:buildCal(document.getElementById(\"" + fieldName + "\"));' onmouseout='return true;' onmouseover='return true;'><img height='15' id='IMG1' src='" + imageSrc + "' width='24'></a>";
	return sHTML;
}

function buildCal()
{
	var calDate = new Date();
	calDateField = arguments[0];
		
	/* This section is IE 5+ specific.  
	   In order to run this in lower browsers, a span tag called 
	   "spCal" needs to be defined in the HTML document.  
	 */  

	CalFrame = document.getElementById("spCal");
	 
	if (CalFrame== undefined)
	{
		
		//CalFrame =document.createElement("<span id='spCal' STYLE='display:none; border:ridge;position:absolute;width:200;height:160;z-index=100' MARGINHEIGHT='0' MARGINWIDTH='0' NORESIZE FRAMEBORDER='0' width:156 SCROLLING='NO'></span>"); 
    	document.write("<span id='spCal' STYLE='display:none; border:ridge;position:fixed;width:200;height:160;z-index=100' MARGINHEIGHT='0' MARGINWIDTH='0' NORESIZE FRAMEBORDER='0' width:156 SCROLLING='NO'></span>");
	    CalFrame = document.getElementById("spCal");
	
	    //document.body.insertBefore(CalFrame);
	}
	
	CalFrame.style.left=getLeftPos(calDateField) + "px";
	CalFrame.style.top=getTopPos(calDateField) + "px";
		
    switch (isValidDate(calDateField.value))
    {
		case 0:
			// no date supplied, use current date
			calDate = new Date();
			break;
			
		case -1:
    		// invalid date supplied
    		if (arguments.length == 2)
    		{
    			altDateField = arguments[1];
    			if (isValidDate(altDateField.value) == 1)
    			{
    				calDate = altDateField.value.toDateTime(newformat);
    			}
    		}
    		break;
    		
    	case 1:
			calDate = calDateField.value.toDateTime(newformat);
			break;
    }
    
	if (CalFrame.style.display == "")
	{
		CalFrame.style.display = "none";
		return;
	}
	// First call to the calendar gets set to the current date
 	drawCal(calDate);
		
	CalFrame.style.display = "";
}

function getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue;
}

function getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue;
}


function getCurDate(){
	return formatDate(new Date(), displayFormat);
}

function getDisplayDate(date) {	
	return formatDate(date, displayFormat);	
}

function drawCal (dateObj)
{
	var sHTML = new String();
	var objPop;
		
	//font-family : Arial,Helvetica,Sans-serif;
	//font-size : 11px;
	//color : #ffffff;
	
	//setup styles to define the look of the calendar
	sHTML += '<html><style>';
	sHTML += '.calBody {background-color: white;}';
	sHTML += '.calHeading {background-color : Silver; border-top-style: outset; font: 8px Verdana;}';
	sHTML += '.calRegularDay {background-color : #007f9b;}';
	sHTML += 'A.calRegularDay.HOVER {background-color : #FFFACD;}';
	sHTML += '.calOtherDay {background-color : #eeeeee; font-family: Arial,Helvetica,Sans-serif; font-size: 11px;}';
	sHTML += '.calToday { font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff;background-color : #ffffcc;}';
	sHTML += '.calReg, TD.calReg:ACTIVE, TD.calReg:FOCUS, TD.calReg:HOVER, TD.calReg:VISITED {font-family : Arial,Helvetica,Sans-serif;font-size : 11px;}' ;
	sHTML += 'TD.calReg:HOVER {background-color : #eeeeee }';
	sHTML += 'background-color : #D5D7C3; cursor: hand; display : block;}';
	sHTML += ' select.month{ font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : blue; width : 75px;}';
	sHTML += 'TD.calReg:VISITED {	background-color : Blue;} </style>';
	sHTML += '<body>';
	
	//start grid	
	sHTML += '<table cellspacing="0" border="0" cellpadding="0" height="100%">';
	sHTML += '<tr class="calHeading">';
	sHTML +=   '<td width="1"></td>';
	sHTML +=   '<td width="200"></td>';
	sHTML +=   '<td width="1"></td>';
	sHTML += '</tr>';
	sHTML += '<tr class="heading"><td width=1></td>';
	sHTML +=   '<td width="200" class="calBody">';
	sHTML +=   DrawCalendarMonth(dateObj);
	sHTML +=   '</td>';
	sHTML += '</tr>'
	sHTML += '<tr><td colspan="7" align="center" class="calBody" valign="top" height="100%"><font face="verdana, arial" size="1"><a href="javascript:parent.HideCal();">Cancel</a></font></td></tr>';
	sHTML += '</table></body></html>';
    
	var calobj = document.getElementById("spCal");
	//calobj.write(sHTML);
     
     
	if (browser.ie4 || browser.ie5)
	{
		self.spCal.document.open();
		self.spCal.document.write(sHTML);
		self.spCal.document.close();
		//calobj.innerHTML=sHTML;  
	}
	
	if (browser.ns6 || browser.ns4)
	{
		//calobj.document.body.innerHTML=sHTML;
		// calobj.insertAdjacentHTML('beforeEnd', sHTML); 
		calobj.innerHTML=sHTML;
		// calobj.document.body.appendChild(sHTML);
		//calobj.outerHTML=sHTML;
	}
}


function DrawCalendarMonth(dateObj)
{
	var sCal = new String();
	var sMonthPicker = new String();
	var lDay = dateObj.getDay(); 
	var lMonth = dateObj.getUTCMonth() + 1;
	var lControlMonth = lMonth - 1;
	var lYear = dateObj.getFullYear();
	var lNextYear = lYear + 1;
	var lPrevYear = lYear - 1;
	var dcurrDate = dateObj;
	var l_iDayMonthEnded;
	var l_iNextMonthDay = 0;
   
	monthArray = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    weekdayList = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    weekdayArray = new Array('Su','Mo','Tu','We','Th','Fr','Sa');
    
    var lDaysInMonth = GetDaysInMonth(dcurrDate.getMonth()+1, dcurrDate.getYear());
    var thisMonthFirstDay = new Date(dcurrDate.getFullYear(), dcurrDate.getMonth(), 1);
	
    var nextYear = new Date(dcurrDate.getFullYear() +1, dcurrDate.getMonth(), 1);
    var prevYear = new Date(dcurrDate.getFullYear() -1, dcurrDate.getMonth(), 1);
    
    var nextMonth = new Date(dcurrDate.getFullYear(), dcurrDate.getMonth() + 1, 1);
    var prevMonth = new Date(dcurrDate.getFullYear(), dcurrDate.getMonth() - 1, 1);
   
    
    var sNextYear = (thisMonthFirstDay.getUTCMonth()+ 1) + '/' + 1 + '/' + (thisMonthFirstDay.getFullYear() +1);
    var sPrevYear = ( 1 + '/' + (thisMonthFirstDay.getUTCMonth()+ 1) + '/' + (thisMonthFirstDay.getFullYear() -1));
    
    var sNextMonth = ( 1 + '/' + (thisMonthFirstDay.getUTCMonth()+ 2) + '/' + (thisMonthFirstDay.getFullYear()));
    var sPrevMonth = ( 1 + '/' + (thisMonthFirstDay.getUTCMonth()+ 0) + '/' + (thisMonthFirstDay.getFullYear()));
	
	window.status = dateObj;
	
	// Build select box for month selection
	sMonthPicker += '<select class="month" name="month" id="month" onchange="javascript:var selectedDate=new Date(' + dcurrDate.getFullYear() + ',this.selectedIndex, 01);parent.drawCal(selectedDate);">';
		for (var y=0; y < 12;y++)
		{
	    	sMonthPicker += '<option value="' + y + '"';
			if (y == lMonth -1) sMonthPicker += ' selected';
			sMonthPicker += '>' + monthArray[y] + '</option>';
	    }
	sMonthPicker += '</select>';

	// Control strip (prev year, month, next year)
	sCal = '<table width="200" border="1" style="background-color:while;border-collapse:collapse">' + '<tr class="heading" bgcolor="beige">';
	sCal += '<td style="cursor:hand;" onmouseover="this.style.backgroundColor=\'white\';" onmouseout="this.style.backgroundColor=\'\';" onclick="javascript:var selectedDate=new Date(' + lPrevYear + ',' + lControlMonth + ',01);parent.drawCal(selectedDate);" align="center"><font face="verdana, arial" size="2">&lt;&lt;</font></td>';
	sCal += '<td colspan=5 align=center><font face="verdana, arial" size=1>' + sMonthPicker + dcurrDate.getFullYear() + '</font></td>';
	sCal += '<td style="cursor:hand;" onmouseover="this.style.backgroundColor=\'white\';" onmouseout="this.style.backgroundColor=\'\';" onclick="javascript:var selectedDate=new Date(' + lNextYear + ',' + lControlMonth + ',01);parent.drawCal(selectedDate);" align="center"><font face="verdana, arial" size="2">&gt;&gt;</font></td>';
	sCal += '</tr>';
	
	// Weekday strip
	weekdays = '<tr bgcolor="#aaaaaa">';
		for (i in weekdayArray) {
			weekdays += '<td align=center><font face="verdana, arial" size=1>' + weekdayArray[i] +'</font></td>';
		}
	weekdays += '</TR><TR>';
	sCal += weekdays;  
   	
   	// Days (in previous month)
	for (i=0; i < thisMonthFirstDay.getDay(); i++)  
	{
		sCal += DrawOtherDay(thisMonthFirstDay.getDay() - i, dcurrDate);
	}
  
  	// Days (in this month)
	for (i=1; i < lDaysInMonth+1; i++)  
	{
		dcurrDate.setDate(i);
		sCal += DrawNormalDay(i, dcurrDate);
		
		if (dcurrDate.getDay() ==6) //start a new week if we are at the end
		{ 
			sCal +='</tr><tr>';      
		}
		l_iDayMonthEnded = dcurrDate.getDay();
	}
	
	// Days (in next month)
	for (i=l_iDayMonthEnded; i < 6; i++)  
	{
		sCal += DrawOtherDay(l_iNextMonthDay * -1, dcurrDate);
		l_iNextMonthDay++;
	}
	
	sCal += '</table>';
  
	return sCal;
}

function DrawOtherDay(lDayOffset, dDate)
{
	var DayNumber;
	var dWorkingDate = new Date(dDate.getYear(), dDate.getMonth(), (- lDayOffset) + 1) 
	var sTemp = new String(); 
	 
	DayNumber = dWorkingDate.getDate();
	 
	//' Draws a day cell - date is in previous or next month
	//' The response.write's are separate lines for clarity only
	sTemp = '<td class="calOtherDay" align="center" width="29">';
	sTemp += '';
	sTemp += DayNumber + '</td>';
	return sTemp;
}

function DrawNormalDay(DayNumber, dDate)
{
	//' Draws a day cell - date is in current month
	//' The response.write's are separate lines for clarity only
	var sDayDate = new String();
	var sTemp = new String(); 
	var dToday = new Date();
	var sClassName = 'calReg';
	  
	sDayDate = (dDate.getMonth() + 1) + '/' + DayNumber + '/' + dDate.getFullYear();
	
	if (sDayDate == ((dToday.getMonth() + 1) + '/' + dToday.getDate() + '/' + dToday.getFullYear()))
	{
		sClassName='calToday';
	}
	  
	sTemp += '<td class="' + sClassName +'"  width="29" ';
	sTemp += 'onclick="javascript:parent.calDateField.value=(\'' + getDisplayDate(dDate) + '\'); parent.HideCal();"';
	sTemp += ' align=center>';
	sTemp += '<a href="javascript:{}" onclick="void(\'' + sDayDate + '\');">' + DayNumber + '</a></td>';
	
	return sTemp;
}

function HideCal()
{
	CalFrame.style.display = "none"
}


function GetNextMonth(dCurrentDate)
{
	var lbmonth;
	var lbyear;
	
	// IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
	if (dCurrentDate.getMonth == 11) {
		dCurrentDate.setMonth(0);
		dCurrentDate.setYear(dCurrentDate.getYear() + 1);
	}else {
		dCurrentDate.setMonth(dCurrentDate.getMonth() + 1);
	}
	return dCurrentDate;
}


function GetDaysInMonth(iMonth, iYear) 
{
	//Returns the number of days in a month
	/*
		In: iMonth: Number of the Month -not zero based ie 3=March
		    iYear: four digit year
	*/
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}

String.prototype.getDateStr = function (dateformat) 
{
 re = {d:"\\d(\\d|)",m:"([\\d]|)\\d",y:"\\d\\d([\\d]|)([\\d]|)" };
 tempobj = {};
 for(var i=0; i<3; i++)
  for(var j in dateformat)
   if(dateformat[j]==i) {
    dateformat[i]=j;
    break;
   }
 var re_str = "\\b" + re[dateformat[0]] + "([\\.]|[\\/])" + re[dateformat[1]] + "([\.]|[\/])" + re[dateformat[2]] + "\\b";
 var date = this.match(new RegExp(re_str,"gmi"));
 return  (date==null ? null : date[0].indexOf(".")!=-1 && date[0].indexOf("/")!=-1? null : date[0]);
}

String.prototype.getTimeStr = function (timeformat) {
 var time = this.match(/\b(\d|)\d\:\d\d\b/);
 return (time==null ? null : time[0]);
}


function Browser()
{
	this.dom = document.getElementById?1:0;
	this.ie4 = (document.all && !this.dom)?1:0;
	this.ns4 = (document.layers && !this.dom)?1:0;
	this.ns6 = (this.dom && !document.all)?1:0;
	this.ie5 = (this.dom && document.all)?1:0;
	this.ok = this.dom || this.ie4 || this.ns4;
	this.platform = navigator.platform;
}
	

function isValidDate (sDateIn) {
	switch(true)
	{
		case (Date.UTC(new Date(1970,0,1,0,0,0))==Date.UTC(sDateIn.toDateTime(newformat))):
 			//alert('nothing entered here');
 			return 0;
 			break;
 		case ((sDateIn.toDateTime(newformat)) != null): 
 			//alert('valid date/time');
 			return 1;
 			break;
 		case true: 
 			//same as case else or default (ie result must have been null)
 			//alert('invalid date');
 			return -1;
 			break;
	}
}

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"


// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
String.prototype.toDateTime = function (val) {
	val = this;
	var preferEuro=(arguments.length==1)?arguments[0]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
	}

// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat (date_string,format) {
	val=date_string;
	format=displayFormat+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}

function LZ(x) {return(x<0||x>9?"":"0")+x} 

// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}

//-->







