var newlaunchfromflash;
function flashed(url)
{
  newlaunchfromflash = window.open(url,'name');
  if(window.focus)
  {
    newlaunchfromflash.focus();
  }
}

function ClickButtonByDefault(objectId)
{
  if (event.keyCode == 13)
  {
    event.returnValue=false;
    event.cancel = true;
    o = document.getElementById(objectId);
    if (o != null)
    {
      o.click();
    }
  }
}

function GetAbsoluteLeft(objectId)
{
		// Get an object left position from the upper left viewport corner
		// Tested with relative and nested objects
		o = document.getElementById(objectId)
		oLeft = o.offsetLeft            // Get left position from the parent object
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
		}
		// Return left postion
		return oLeft
	}
	
function GetAbsoluteTop(objectId)
{
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId);
	oTop = o.offsetTop;         // Get top position from the parent object
	while(o.offsetParent!=null) 
	{ // Parse the parent hierarchy up to the document element
	  oParent = o.offsetParent  // Get parent object reference
	  oTop += oParent.offsetTop // Add parent top position
	  o = oParent
	}
	// Return top position
	return oTop
}

function PopupDatePicker(ctlDate, ctlMinDate, defaultMinDate, width, height)
{
  var leftPosition = GetAbsoluteLeft(ctlDate);
  var topPosition = GetAbsoluteTop(ctlDate);
  
  var dateValue = document.getElementById(ctlDate).value;
  
  var dateMinValue = defaultMinDate;
  if (ctlMinDate != '')
  {
    dateMinValue = document.getElementById(ctlMinDate).value;
  }
  
  var settings='width='+ width + ',height='+ height + ',left=' + leftPosition + ',top=' + topPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=yes';
 
  var PopupWindow =  window.open('/Controls/DatePicker.aspx?Ctl=' + ctlDate + "&MinDate=" + dateMinValue + "&SelectedDate=" + dateValue, 'DatePicker', settings);
  PopupWindow.focus();
}

function goPage(pageNum, fieldName)
{
    o = document.getElementById(fieldName);
    o.value = pageNum;
    document.MainForm.submit();
}

function viewImage(imgUrl, caption, country, controlId)
{
    o1 = document.getElementById('captionSection');
    o2 = document.getElementById('imgSection');
    
    o2.src = imgUrl;
    o1.innerHTML = caption + "<br/>" + country;
    
    if (controlId != '')
    {
      if (document.getElementById(controlId) != null)
      {
        document.getElementById(controlId).value = imgUrl;
        if (document.getElementById('hidSelectedPicCaption') != null)
        {
          document.getElementById('hidSelectedPicCaption').value = caption + "<br/>" + country;
        }
      }
    }
}

function deletePicture(picId, fieldName)
{
    o = document.getElementById(fieldName);
    o.value = picId;
    document.Form1.submit();
}

function OpenUrlInNewWindow(Url)
{
  var newWindow = null;
  // Try to open.
  newWindow = window.open(Url);
  // Wait and check if it exists.
  var t = setTimeout('DoNothing()', 2000);
  // Check if the window exists.
  if (newWindow == null)
  {
    alert("Your browser pop-up blockers prevent access to the booking search engine.\nFor best experience, please always allow pop-ups on this site.");
  }
}

function DoNothing()
{
  ;
}

function CheckForPopUpBlocker(newWindow)
{
  if (newWindow == null)
  {
    alert("It looks like your browser's pop-up blocker may be preventing access to the booking engine. \nPlease disable all pop-up blockers and submit your request again.");
  }
}

function NavigateBack()
{
  window.navigate(-1);
}

function validateTravelocityPackage()
{
  var returnValue = '';
  
  if(document.getElementById(ctrPackageTo).value == '')
  {
    returnValue = returnValue + '\n * To';
  }
  if(document.getElementById(ctrPackageFrom).value == '')
  {
    returnValue = returnValue + '\n * From';
  }
  if(isDate(document.getElementById(ctrPackageDepart).value, 'M/d/yyyy') == false)
  {
    returnValue = returnValue + '\n * Depart Date';
  }
  if(isDate(document.getElementById(ctrPackageReturn).value, 'M/d/yyyy') == false)
  {
    returnValue = returnValue + '\n * Return Date';
  }
  if(parseInt(document.getElementById(ctrPackageNumAdults).value) + parseInt(document.getElementById(ctrPackageNumSeniors).value) == 0)
  {
    returnValue = returnValue + '\n * Must be at least one adult';
  }
  
  return returnValue;
}

function TravelocityPackage(checkKeystroke)
{
  if (checkKeystroke)
  {
    // See if the event keystroke is Enter and skip if not.
    if (event.keyCode == 13)
    {
      event.returnValue = false;
      event.cancel = true;
    }
    else
    {
      return;
    }
  }

  var msg = '';
  msg = validateTravelocityPackage();
  
  if (msg == '')
  {
    var departDate = new Date(document.getElementById(ctrPackageDepart).value);
    var returnDate = new Date(document.getElementById(ctrPackageReturn).value);
    
    var departYear = departDate.getFullYear();
    var departMonth = departDate.getMonth() +1;
    var departDay = departDate.getDate();
    var returnYear = returnDate.getFullYear();
    var returnMonth = returnDate.getMonth() +1;
    var returnDay = returnDate.getDate();
    
    var url = '';
    url = url + 'http://www.res99.com/nexres/start-pages/gateway.cgi?';
    url = url + 'engine=customtrip&src=10017101&action=search&stops=1&';
    url = url + 'dateLeavingTime=Anytime&dateReturningTime=Anytime&';
    url = url + 'goingTo=' + document.getElementById(ctrPackageTo).value + '&';
    url = url + 'leavingFrom=' + document.getElementById(ctrPackageFrom).value + '&';
    url = url + 'adults=' + document.getElementById(ctrPackageNumAdults).value + '&';
    url = url + 'children=' + document.getElementById(ctrPackageNumChildren).value + '&';
    url = url + 'seniors=' + document.getElementById(ctrPackageNumSeniors).value + '&';
    url = url + 'dateLeavingMonth=' + departMonth + '&';
    url = url + 'dateLeavingDay=' + departDay + '&';
    url = url + 'dateReturningMonth=' + returnMonth + '&';
    url = url + 'dateReturningDay=' + returnDay;
    
    window.open(url);
  }
  else
  {
    var errorMsg = 'The following fields have missing or invalid data';
    errorMsg = errorMsg + msg;
    alert(errorMsg);
  }
  
  return false;
}

function validateTravelocityFlight()
{
  var returnValue = '';
  
  if(document.getElementById(ctrFlightTo).value == '')
  {
    returnValue = returnValue + '\n * To';
  }
  if(document.getElementById(ctrFlightFrom).value == '')
  {
    returnValue = returnValue + '\n * From';
  }
  if(isDate(document.getElementById(ctrFlightDepart).value, 'M/d/yyyy') == false)
  {
    returnValue = returnValue + '\n * Depart Date';
  }
  if(isDate(document.getElementById(ctrFlightReturn).value, 'M/d/yyyy') == false)
  {
    returnValue = returnValue + '\n * Return Date';
  }
  if(parseInt(document.getElementById(ctrFlightNumAdults).value) + parseInt(document.getElementById(ctrFlightNumSeniors).value) == 0)
  {
    returnValue = returnValue + '\n * Must be at least one adult';
  }
  
  return returnValue;
}

function TravelocityFlight(checkKeystroke)
{
  if (checkKeystroke)
  {
    // See if the event keystroke is Enter and skip if not.
    if (event.keyCode == 13)
    {
      event.returnValue = false;
      event.cancel = true;
    }
    else
    {
      return;
    }
  }
  
  var msg = '';
  msg = validateTravelocityFlight();
  
  if (msg == '')
  {
    var departDate = new Date(document.getElementById(ctrFlightDepart).value);
    var returnDate = new Date(document.getElementById(ctrFlightReturn).value);
    
    var departYear = departDate.getFullYear();
    var departMonth = departDate.getMonth() +1;
    var departDay = departDate.getDate();
    var returnYear = returnDate.getFullYear();
    var returnMonth = returnDate.getMonth() +1;
    var returnDay = returnDate.getDate();
    
    var url = '';
    url = url + 'http://go.travelpn.com/flights/InitialSearch.do?';
    url = url + 'Service=TPN&affiliateId=10017101&subAffiliateId=&';
    url = url + 'aspHeader=air&aspFooter=air&flightType=roundtrip&';
    url = url + 'pref_aln=exclude&nearbyAirports=off&dateLeavingTime=Anytime&';
    url = url + 'dateReturningTime=Anytime&departDateFlexibility=0&returnDateFlexibility=0&';
    url = url + 'leavingDate=mm/dd/yyyy&returningDate=mm/dd/yyyy&';
    url = url + 'leavingFrom=' + document.getElementById(ctrFlightFrom).value + '&';
    url = url + 'goingTo=' + document.getElementById(ctrFlightTo).value + '&';
    url = url + 'adults=' + document.getElementById(ctrFlightNumAdults).value + '&';
    url = url + 'children=' + document.getElementById(ctrFlightNumChildren).value + '&';
    url = url + 'seniors=' + document.getElementById(ctrFlightNumSeniors).value + '&';
    url = url + 'dateLeavingMonth=' + departMonth + '&';
    url = url + 'dateLeavingDay=' + departDay + '&';
    url = url + 'dateReturningMonth=' + returnMonth + '&';
    url = url + 'dateReturningDay=' + returnDay;

    window.open(url);
  }
  else
  {
    var errorMsg = 'The following fields have missing or invalid data';
    errorMsg = errorMsg + msg;
    alert(errorMsg);
  }

  return false;
}

function validateTravelocityHotel()
{
  var returnValue = '';
  
  if((document.getElementById(ctrHotelCity).value == '') && (document.getElementById(ctrHotelCountry).value == ''))
  {
    returnValue = returnValue + '\n * Destinations';
  }
  if(isDate(document.getElementById(ctrHotelCheckIn).value, 'M/d/yyyy') == false)
  {
    returnValue = returnValue + '\n * Check-In Date';
  }
  if(isDate(document.getElementById(ctrHotelCheckOut).value, 'M/d/yyyy') == false)
  {
    returnValue = returnValue + '\n * Check-Out Date';
  }
  if(parseInt(document.getElementById(ctrHotelNumRooms).value) == 0)
  {
    returnValue = returnValue + '\n * Must be at least for one room';
  }
  if(parseInt(document.getElementById(ctrHotelNumAdults).value) == 0)
  {
    returnValue = returnValue + '\n * Must be at least one adult';
  }
  
  return returnValue;
}

function TravelocityHotel(checkKeystroke)
{
  if (checkKeystroke)
  {
    // See if the event keystroke is Enter and skip if not.
    if (event.keyCode == 13)
    {
      event.returnValue = false;
      event.cancel = true;
    }
    else
    {
      return;
    }
  }
  
  var msg = '';
  msg = validateTravelocityHotel();
  
  if (msg == '')
  {
    var checkInDate = new Date(document.getElementById(ctrHotelCheckIn).value);
    var checkOutDate = new Date(document.getElementById(ctrHotelCheckOut).value);
    
    var checkInYear = checkInDate.getFullYear();
    var checkInMonth = checkInDate.getMonth() + 1;
    var checkInDay = checkInDate.getDate();
    var checkOutYear = checkOutDate.getFullYear();
    var checkOutMonth = checkOutDate.getMonth()+ 1;
    var checkOutDay = checkOutDate.getDate();
    
    var city = document.getElementById(ctrHotelCity).value;
    if(city == "Destination...")
    {
      city = "";
    }
   
    
    var url = '';
    url = url + 'http://www.res99.com/nexres/search/search_results.cgi?avail=Y&';
    url = url + 'num_rooms=' + document.getElementById(ctrHotelNumRooms).value + '&';
    url = url + 'num_adults=' + document.getElementById(ctrHotelNumAdults).value + '&';
    url = url + 'num_children=' + document.getElementById(ctrHotelNumChildren).value + '&';
    url = url + 'smoking_pref=NP&bed_type=NP&src=10017101&currency_id=USD&tab=tab0&Go=Search+For+Hotels&';
    url = url + 'doa_mm=' + checkInMonth + '&';
    url = url + 'doa_yy=' + checkInYear + '&';
    url = url + 'doa_dd=' + checkInDay + '&';
    url = url + 'dod_mm=' + checkOutMonth + '&';
    url = url + 'dod_yy=' + checkOutYear + '&';
    url = url + 'dod_dd=' + checkOutDay + '&';
    url = url + 'city=' + city + '&' ;
    url = url + 'country=' + document.getElementById(ctrHotelCountry).value;
    
    window.open(url);
  }
  else
  {
    var errorMsg = 'The following fields have missing or invalid data';
    errorMsg = errorMsg + msg;
    alert(errorMsg);
  }
  
  return false;
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// May 17, 2003: Fixed bug in parseDate() for dates <1970
// March 11, 2003: Added parseDate() function
// March 11, 2003: Added "NNN" formatting option. Doesn't match up
//                 perfectly with SimpleDateFormat formats, but 
//                 backwards-compatability was required.

// ------------------------------------------------------------------
// 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"
// ------------------------------------------------------------------

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');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// 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;
	}
	
// ------------------------------------------------------------------
// 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;
	}
	
// ------------------------------------------------------------------
// 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(val,format) {
	val=val+"";
	format=format+"";
	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();
	}

// ------------------------------------------------------------------
// 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.
// ------------------------------------------------------------------
function parseDate(val)
{
	var preferEuro=(arguments.length==2)?arguments[1]: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;
}




//  ---------------------------------------------------------
//  Scroll arrow scripts
//  ---------------------------------------------------------

function OnLoadScripts()
{
	try
	{
		var ScrollboxTop = findPosY(document.getElementById("scrollbox"));
		var ScrollboxLeft = findPosX(document.getElementById("scrollbox"));
		var ScrollboxWidth = document.getElementById("scrollbox").clientWidth;
	}
	catch(e){}
}

function findPosX(obj)
{
	var curleft = 0;
	
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curleft = curleft + obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curtop = curtop + obj.offsetTop;
			
			obj = obj.offsetParent;
		}
	}
	
	return curtop;
}

var mousePress = "up";
		
function reset_mousePress()
{
	mousePress = "up";
}

function clickDivDown()
{
	mousePress = "down";
	moveDivDown();
}

function clickDivUp()
{
	mousePress = "down";
	moveDivUp();
}


function moveDivDown()
{
	var pos, posLength, pagePos;
	var scrollboxHeight, parentHeight;

	scrollboxHeight = document.getElementById("scrollbox").clientHeight;
	parentHeight = document.getElementById("parent").clientHeight;
	
	pos = document.getElementById("scrollbox").style.top;
	posLength = pos.length;
	pos = pos.substring(0, posLength - 2);
	
	pagePos = parseInt(scrollboxHeight) - parseInt(parentHeight) + parseInt(pos);
	
	if (pagePos > 0)
	{
		pos = pos - 14; // Scroll amount
		document.getElementById("scrollbox").style.top = pos + "px";
		if (mousePress == "down")
		{
			setTimeout('moveDivDown()', 50); // Speed
		}
		document.getElementById("ScrollImageUp").src = '/images/scroll_buttons_light_up.gif';
	}
	else
	{
		mousePress = "up";
		document.getElementById("ScrollImageDown").src = '/images/scroll_buttons_dark_dn.gif';
		//alert("HERE");
	}
}

function moveDivUp()
{
	var pos, posLength, pagePos;
	var scrollboxHeight, parentHeight;

	scrollboxHeight = document.getElementById("scrollbox").clientHeight;
	parentHeight = document.getElementById("parent").clientHeight;
	
	pos = document.getElementById("scrollbox").style.top;
	pos = pos.substring(0, pos.length - 2);
	
	pagePos = parseInt(pos);
	
	
	if (pagePos < 0)
	{
		pos = parseInt(pos) + 14; // Scroll amount
		document.getElementById("scrollbox").style.top = pos + "px";
		if (mousePress == "down")
		{
			setTimeout('moveDivUp()', 50); // Speed
		}
		document.getElementById("ScrollImageUp").src = '/images/scroll_buttons_light_up.gif';
		document.getElementById("ScrollImageDown").src = '/images/scroll_buttons_light_dn.gif';
	}
	else
	{
		mousePress = "up";
		document.getElementById("ScrollImageDown").src = '/images/scroll_buttons_light_dn.gif';
		document.getElementById("ScrollImageUp").src = '/images/scroll_buttons_dark_up.gif';
		//alert("HERE");
	}
}

//  ---------------------------------------------------------
//  End of scroll arrow scripts
//  ---------------------------------------------------------

//  ---------------------------------------------------------
//  Start of dropdown script
//  ---------------------------------------------------------

var disappeardelay = 550  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink = 0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick = 1 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed

var ie5 = document.all;
var ns6 = document.getElementById && !document.all;

function getposOffset(what, offsettype) {
  var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
  var parentEl = what.offsetParent;
  while (parentEl != null) {
    totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
    parentEl = parentEl.offsetParent;
  }
  return totaloffset;
}

function showhide(obj, e, visible, hidden) {
  if (ie5 || ns6) {
    //    dropmenuobj.style.left = dropmenuobj.style.top = -500;
  }
  if (e.type == "click" && obj.display == none || e.type == "mouseover") {
    setTimeout("dropmenuobj.style.display='inline'", 100);
  }
  else if (e.type == "click") {
    obj.display = nonw;
  }
}

function iecompattest() {
  return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge) {
  var edgeoffset = 0;
  if (whichedge == "rightedge") {
    var windowedge = ie5 && !window.opera ? iecompattest().scrollLeft + iecompattest().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15;
    dropmenuobj.contentmeasure = dropmenuobj.offsetWidth;
    if (windowedge - dropmenuobj.x < dropmenuobj.contentmeasure) {
      edgeoffset = dropmenuobj.contentmeasure - obj.offsetWidth;
    }
  }
  else {
    var topedge = ie5 && !window.opera ? iecompattest().scrollTop : window.pageYOffset;
    var windowedge = ie5 && !window.opera ? iecompattest().scrollTop + iecompattest().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18;
    dropmenuobj.contentmeasure = dropmenuobj.offsetHeight;
    if (windowedge - dropmenuobj.y < dropmenuobj.contentmeasure) { //move up?
      edgeoffset = dropmenuobj.contentmeasure + obj.offsetHeight;
      if ((dropmenuobj.y - topedge) < dropmenuobj.contentmeasure) { //up no good either?
        edgeoffset = dropmenuobj.y + obj.offsetHeight - topedge;
      }
    }
  }
  return edgeoffset;
}

function dropdownmenu(obj, e, dropmenuID) {
  if (window.event) {
    event.cancelBubble = true;
  }
  else if (e.stopPropagation) {
    e.stopPropagation();
  }

  if (typeof dropmenuobj != "undefined") {
    if (dropmenuobj) {
      //hide previous menu
      dropmenuobj.style.display = "none";
    }
  }

  clearhidemenu();

  if (ie5 || ns6) {
    obj.onmouseout = delayhidemenu;
    dropmenuobj = document.getElementById(dropmenuID);

    if (dropmenuobj) {
      if (hidemenu_onclick) dropmenuobj.onclick = function() { dropmenuobj.style.display = 'none' }
      dropmenuobj.onmouseover = clearhidemenu;
      dropmenuobj.onmouseout = ie5 ? function() { dynamichide(event) } : function(event) { dynamichide(event) }
      showhide(dropmenuobj.style, e, "visible", "hidden");
      dropmenuobj.x = getposOffset(obj, "left");
      dropmenuobj.y = getposOffset(obj, "top");
      dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + "px";
      dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + "px";
      removeselect("hidden");
    }
  }

  return clickreturnvalue();
}

function removeselect(hide) {
  if (navigator.appVersion.indexOf("MSIE") != -1) {
    temp = navigator.appVersion.split("MSIE");
    version = parseFloat(temp[1]);

    if (version < 7.0) {
      for (var begin = 0; begin < document.forms.length; begin++) {
        for (var next = 0; next < document.forms[begin].length; next++) {
          if (document.forms[begin].elements[next].options) {
            document.forms[begin].elements[next].style.visibility = hide;
          }
        }
      }
    }
  }
}

function clickreturnvalue() {
  if ((ie5 || ns6) && !enableanchorlink) {
    return false;
  }
  else {
    return true;
  }
}

function contains_ns6(a, b) {
  while (b.parentNode) {
    if ((b = b.parentNode) == a) {
      return true;
    }
  }
  return false;
}

function dynamichide(e) {
  if (ie5 && !dropmenuobj.contains(e.toElement)) {
    delayhidemenu();
  }
  else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget)) {
    delayhidemenu();
  }
}

function delayhidemenu() {
  if (typeof dropmenuobj != "undefined") {
    if (dropmenuobj) {
      delayhide = setTimeout("dropmenuobj.style.display='none';removeselect('visible')", disappeardelay);
    }
  }
}

function clearhidemenu() {
  if (typeof delayhide != "undefined") {
    clearTimeout(delayhide);
  }
}

//  ---------------------------------------------------------
//  End of dropdown script
//  ---------------------------------------------------------

//  ---------------------------------------------------------
//  Start Calendar Code
//  ---------------------------------------------------------

/*
The calendar is activated by clicking on a button.
In order for this to work, a Text field must be associated to the calendar "control"
by placing the button immediately after (to the right) of the text field.
For example:
   
<input type='text' value='3/12/2003'>
<input type='button' value='...' onclick='cal_showCalendar(this,'EN');'>
*/

//===== Start of Global Values ========
var cal_dteToday = new Date(); //if blank, will show today's date
var cal_intDD = cal_dteToday.getDate(); 	//Integer day value
var cal_intMM = cal_dteToday.getMonth() + 1; //Integer Month value
var cal_intYYYY = cal_dteToday.getYear(); //Integer Year value
if (cal_intYYYY < 2000)    //// Correct the year for Mozilla
{
  cal_intYYYY = cal_intYYYY + 1900;
}
var cal_intDDSelected;
var cal_intMMSelected;
var cal_intYYYYSelected;
var cal_nMaxYears = 4; // number of years to list in the dropdown
var nWeekDays = 7;
var cal_targetEl; 					// our target textbox
var calendarUI;
var calendarIF;
var calendarUIArea;
var cal_arrYears;
var cal_LangId = "en";
var blnSelectPast = false;
var blnRollPast = true;
var blnRollFuture = false;
var cal_dayInitialBorder = "1px solid #f5f5f5";
var cal_dayMouseOverBorder = "1px solid gray";
var cal_dayMouseOutBorder = "1px solid whitesmoke";
var cal_weekendBGColor = "#ebebeb";
var cal_weekendSelectedBGColor = "#ffff00";
var cal_todayBorderColor = "#990033";
var cal_SelectMouseOutBorder = "1px solid white ";
var cal_monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var cal_monthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
//var cal_monthNames_fr = new Array("Jan","Fév","Mar","Avr","Pou","Jui","Juil","Aoû","Sep","Oct","Nov","Déc");
var cal_monthNames_fr = new Array("Jan", "F&eacute;v", "Mar", "Apr", "May", "Jun", "Jul", "Ao&ucirc;", "Sep", "Oct", "Nov", "D&eacute;c");
var cal_weekdayNames = new Array("S", "M", "T", "W", "T", "F", "S");
var cal_weekdayNames_fr = new Array("D", "L", "M", "M", "J", "V", "S");
var calSelectList;
var cal_useCalSelect = false; //either show in browser drop down, or in span tag mimicking drop down
var nyearsBack = cal_intYYYY - 2002; //the data collection started in 2002	
var blnShowDefaultEndDate = false; //show 9999 as the last year if true

//======= End of Global Values =============
function cal_genYearList(selYear) {
  cal_arrYears = new Array();
  var intLength = 0;
  var current = new Date();
  var curYear = cal_getYear(current);
  if (selYear < curYear) {
    cal_arrYears[0] = selYear;
  }
  intLength = cal_arrYears.length;
  for (i = intLength; i < cal_nMaxYears; i++) {
    cal_arrYears[i] = curYear;
    curYear++;
  }
  if (blnShowDefaultEndDate == true) {
    cal_arrYears[cal_arrYears.length] = 9999;
  }
}

function cal_getDateString(intMM, intDD, intYYYY) {
  var strMonth = cal_monthNames[intMM - 1];
  var strDateString = strMonth + " " + intDD + ", " + intYYYY;
  return (strDateString);
}

function cal_getTimeString(intHH, intMIN, strAMPM) {
  var strTimeString;
  var strHourString;
  var strMinuteString;
  strHourString = "00" + intHH;
  strMinuteString = "00" + intMIN;
  strTimeString = strHourString.slice(-2) + ":" + strMinuteString.slice(-2) + " " + strAMPM;
  return (strTimeString);
}

function cal_getSelectList(y) {
  var strTempString = "";
  var strSelected;
  var i;
  if (cal_useCalSelect == true) {
    strTempString = strTempString + "<span id=\"cal_Select\" class=\"calselect2\" style=\"width:10px;\"><span id=\"cal_SelectValue\">" + y + "</span></span></TH><TH><img class='calimage' src=\"/images/cal_down.gif\" onclick=\"cal_showSelectlist()\"></TH>";
    strTempString2 = "<table id=\"cal_SelectDropDown\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    var strSelected = "";
    for (i = 0; i < cal_arrYears.length; i++) {
      if (cal_arrYears[i] == y) {
        strSelected = " class=\"calselected\"";
      }
      else {
        strSelected = "";
      }
      strTempString2 = strTempString2 + "<tr><td" + strSelected + " onmouseover=\"cal_Selectmouseover(this);\" onmouseout=\"cal_Selectmouseout(this);\" onclick=\"cal_SelectValue(" + cal_arrYears[i] + ");\">" + cal_arrYears[i] + "</td></tr>";
    }
    strTempString2 = strTempString2 + "</table>";
    // calSelectList.innerHTML = strTempString2;
    return strTempString2;
  }
  else {
    strTempString = strTempString + "<select class='calselect' onchange='cal_refreshCal(this.options[this.selectedIndex].value);' id='CalYearSelect' name='CalYearSelect'>";
    var strSelected = "";
    for (i = 0; i < cal_arrYears.length; i++) {
      if (cal_arrYears[i] == y) {
        strSelected = " selected";
      }
      else {
        strSelected = "";
      }
      strTempString = strTempString + "<option value='" + cal_arrYears[i] + "'" + strSelected + ">" + cal_arrYears[i] + "</option>";
    }
    strTempString = strTempString + "</select>";
    return strTempString;
  }

}

function cal_calendar(mydate) {
  var curYear = cal_getYear(cal_dteToday);
  var curDay = cal_dteToday.getDate();
  var curMonth = cal_dteToday.getMonth() + 1;
  var strCalendarString = "";
  var today = mydate;
  var thisDay;
  var pastStartDay;
  var strCSSCLass = "";
  var i;
  year = cal_getYear(today);
  thisDay = today.getDate();
  cal_monthDays[1] = cal_getFebDays(year);
  nDays = cal_monthDays[today.getMonth()];
  firstDay = today;
  firstDay.setDate(1);
  //testMe = firstDay.getDate();
  //if (testMe == 2)
  //	{ alert(mydate + " : " +mydate.getDay());
  //	firstDay.setDate(0);    
  //	}
  startDay = firstDay.getDay();
  if (today.getMonth() == 0)
    pastStartDay = cal_monthDays[11] - startDay + 1;
  else
    pastStartDay = cal_monthDays[today.getMonth() - 1] - startDay + 1;
  strCalendarString = strCalendarString + "<TABLE id='myTable' class='Calendar' border='0' cellspacing='0' width='169px'>";
  strCalendarString = strCalendarString + "<TR><TH><img src='/images/cal_left.gif' onclick='cal_back();' class='calimage'></TH>";
  if (cal_useCalSelect == true)
    strCalendarString = strCalendarString + "<TH style=\"text-align: right\" nowrap COLSPAN='3'>";
  else
    strCalendarString = strCalendarString + "<TH style=\"text-align: right\" nowrap COLSPAN='4'>";
  if (cal_LangId == "fr")
    strCalendarString = strCalendarString + cal_monthNames_fr[today.getMonth()];
  else
    strCalendarString = strCalendarString + cal_monthNames[today.getMonth()];
  strCalendarString = strCalendarString + " " + cal_getSelectList(year);
  strCalendarString = strCalendarString + "</TH><TH><img src='/images/cal_right.gif' onclick='cal_forward();' class='calimage'></TH><TH style=\"text-align:right; vertical-align:top\"><img src='/images/cal_close.gif' onclick='cal_close()' class='calimage'></TH></TR>";
  strCalendarString = strCalendarString + "<TR>";
  for (i = 0; i < nWeekDays; i++) {
    if (cal_LangId == "fr")
      strCalendarString = strCalendarString + "<TH class=\"Calweekdayheader\" width='24px'>" + cal_weekdayNames_fr[i] + "</TH>";
    else
      strCalendarString = strCalendarString + "<TH class=\"Calweekdayheader\" width='24px'>" + cal_weekdayNames[i] + "</TH>";
  }
  strCalendarString = strCalendarString + "<TR>";
  column = 0;
  for (i = 0; i < startDay; i++) {
    if ((column == 0) || (column == 6))
      strCalendarString = strCalendarString + "<TD style=\"background-color:" + cal_weekendBGColor + ";border:1px solid" + cal_weekendBGColor + "\" class=\"CalUnavailable\">" + (pastStartDay + i) + "</TD>";
    else
      strCalendarString = strCalendarString + "<TD class=\"CalUnavailable\">" + (pastStartDay + i) + "</TD>";
    column++;
  }

  for (i = 1; i <= nDays; i++) {
    strCSSCLass = "CalSelectable";
    if (blnSelectPast == true) {
      if (document.all) {
        strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDay(this.innerText);\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
      } else {
        strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDay(this.textContent);\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
      }


      if (cal_isSelectedDate(cal_intDDSelected, cal_intMMSelected, cal_intYYYYSelected, i) == true) {
        if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
          strCSSCLass = "CalSelectedToday";
        else
          strCSSCLass = "CalSelectedday";
      }
      else {
        if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
          strCSSCLass = "CalToday";
      }
    }
    else {
      if (cal_isPastDate(curDay, curMonth, curYear, i) == true) {
        strCalendarString = strCalendarString + "<TD";
        strCSSCLass = "CalInvalidday";
      }
      else {
        if (document.all) {
          strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDay(this.innerText);\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
        } else {
          strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDay(this.textContent);\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
        }


        if (cal_isSelectedDate(cal_intDDSelected, cal_intMMSelected, cal_intYYYYSelected, i) == true) {
          if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
            strCSSCLass = "CalSelectedToday";
          else
            strCSSCLass = "CalSelectedday";
        }
        else {
          if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
            strCSSCLass = "CalToday";
        }  // thisDay
      }  // isPastDate
    }  //SelectPast
    if ((column == 0) || (column == 6)) {
      switch (strCSSCLass) {
        case "CalSelectedToday":
          strCalendarString = strCalendarString + " style=\"background-color:" + cal_weekendSelectedBGColor + ";border:  1px solid" + cal_weekendBGColor + "\" class=\"" + strCSSCLass + "\">" + i + "</TD>";
          break;
        case "CalSelectedday":
          strCalendarString = strCalendarString + " style=\"background-color:" + cal_weekendSelectedBGColor + ";border:  1px solid" + cal_weekendBGColor + "\" class=\"" + strCSSCLass + "\">" + i + "</TD>";
          break;
        default:
          strCalendarString = strCalendarString + " style=\"background-color:" + cal_weekendBGColor + ";border: 1px solid" + cal_weekendBGColor + " \" class=\"" + strCSSCLass + "\">" + i + "</TD>";

      }
    }
    else {
      strCalendarString = strCalendarString + " class=\"" + strCSSCLass + "\">" + i + "</TD>";
    }
    column++;

    if (column == 7) {
      strCalendarString = strCalendarString + "</TR><TR>";
      column = 0;
    }
  }
  if ((column < 7) && (column > 0)) {
    for (i = 1; i <= (7 - column); i++) {
      if ((column + i) == 7)
        strCalendarString = strCalendarString + "<TD style=\"background-color:" + cal_weekendBGColor + ";border: 1px solid" + cal_weekendBGColor + "\" class=\"CalUnavailable\">" + i + "</TD>";
      else
        strCalendarString = strCalendarString + "<TD class=\"CalUnavailable\">" + i + "</TD>";
    }
    strCalendarString = strCalendarString + "</TR><TR>";
  }
  if (cal_LangId == "fr")
    strCalendarString = strCalendarString + "</tr><tr><td class='Calgototoday' colspan='7' onclick=\"cal_setToday();\">(f)Go to today</td></tr>";
  else
    strCalendarString = strCalendarString + "</tr><tr><td class='Calgototoday' colspan='7' onclick=\"cal_setToday();\">Go to today</td></tr>";
  strCalendarString = strCalendarString + "</TABLE>";
  calendarUI.innerHTML = strCalendarString;

  //cal_targetEl.value = cal_intMM + "/" + cal_intDD + "/" + cal_intYYYY;

  calendarIF.style.width = 1;
  calendarIF.style.height = 1;

  //	calendarUIArea = calendarUI.getBoundingClientRect();

  //	calendarIF.style.width=calendarUIArea.right - calendarUIArea.left;
  //	calendarIF.style.height=calendarUIArea.bottom - calendarUIArea.top;

  calendarUI.focus();
}

function cal_calendarUpdate(mydate, futureDate) {
  var curYear = cal_getYear(cal_dteToday);
  var curDay = cal_dteToday.getDate();
  var curMonth = cal_dteToday.getMonth() + 1;
  var strCalendarString = "";
  var today = mydate;
  var thisDay;
  var pastStartDay;
  var strCSSCLass = "";
  var i;

  //alert(futureDate);
  futureObj = document.getElementById(futureDate);
  year = cal_getYear(today);
  thisDay = today.getDate();
  cal_monthDays[1] = cal_getFebDays(year);
  nDays = cal_monthDays[today.getMonth()];
  firstDay = today;
  firstDay.setDate(1);
  //testMe = firstDay.getDate();
  //if (testMe == 2)
  //	{ alert(mydate + " : " +mydate.getDay());
  //	firstDay.setDate(0);    
  //	}
  startDay = firstDay.getDay();
  if (today.getMonth() == 0)
    pastStartDay = cal_monthDays[11] - startDay + 1;
  else
    pastStartDay = cal_monthDays[today.getMonth() - 1] - startDay + 1;
  strCalendarString = strCalendarString + "<TABLE id='myTable' class='Calendar' border='0' cellspacing='0' width='168px'>";
  strCalendarString = strCalendarString + "<TR><TH><img src='/images/cal_left.gif' onclick=\"cal_backUpdate('" + futureObj.id + "')\" class='calimage' /></TH>";
  if (cal_useCalSelect == true)
    strCalendarString = strCalendarString + "<TH style=\"text-align: right\" nowrap COLSPAN='3'>";
  else
    strCalendarString = strCalendarString + "<TH style=\"text-align: right\" nowrap COLSPAN='4'>";
  if (cal_LangId == "fr")
    strCalendarString = strCalendarString + cal_monthNames_fr[today.getMonth()];
  else
    strCalendarString = strCalendarString + cal_monthNames[today.getMonth()];
  strCalendarString = strCalendarString + " " + cal_getSelectList(year);
  strCalendarString = strCalendarString + "</TH><TH><img src='/images/cal_right.gif' onclick=\"cal_forwardUpdate('" + futureObj.id + "')\" class='calimage' /></TH><TH style=\"text-align:right; vertical-align:top\"><img src='/images/cal_close.gif' onclick='cal_close()' class='calimage'></TH></TR>";
  strCalendarString = strCalendarString + "<TR>";
  for (i = 0; i < nWeekDays; i++) {
    if (cal_LangId == "fr")
      strCalendarString = strCalendarString + "<TH class=\"Calweekdayheader\" width='24px'>" + cal_weekdayNames_fr[i] + "</TH>";
    else
      strCalendarString = strCalendarString + "<TH class=\"Calweekdayheader\" width='24px'>" + cal_weekdayNames[i] + "</TH>";
  }
  strCalendarString = strCalendarString + "<TR>";
  column = 0;
  for (i = 0; i < startDay; i++) {
    if ((column == 0) || (column == 6))
      strCalendarString = strCalendarString + "<TD style=\"background-color:" + cal_weekendBGColor + ";border: 1px solid" + cal_weekendBGColor + " \" class=\"CalUnavailable\">" + (pastStartDay + i) + "</TD>";
    else
      strCalendarString = strCalendarString + "<TD class=\"CalUnavailable\">" + (pastStartDay + i) + "</TD>";
    column++;
  }

  for (i = 1; i <= nDays; i++) {
    strCSSCLass = "CalSelectable";
    if (blnSelectPast == true) {
      if (document.all) {
        strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDayFuture(this.innerText, '" + futureObj.id + "');\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
      } else {
        strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDayFuture(this.textContent, '" + futureObj.id + "');\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
      }

      if (cal_isSelectedDate(cal_intDDSelected, cal_intMMSelected, cal_intYYYYSelected, i) == true) {
        if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
          strCSSCLass = "CalSelectedToday";
        else
          strCSSCLass = "CalSelectedday";
      } else {
        if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
          strCSSCLass = "CalToday";
      }
    } else {
      if (cal_isPastDate(curDay, curMonth, curYear, i) == true) {
        strCalendarString = strCalendarString + "<TD";
        strCSSCLass = "CalInvalidday";
      } else {

        if (document.all) {
          strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDayFuture(this.innerText, '" + futureObj.id + "');\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
        } else {
          strCalendarString = strCalendarString + "<TD style=\"width:22px; border:" + cal_dayInitialBorder + "\" onclick=\"cal_updateDayFuture(this.textContent, '" + futureObj.id + "');\" onmouseover=\"cal_mouseover(this);\" onmouseout=\"cal_mouseout(this);\"";
        }

        if (cal_isSelectedDate(cal_intDDSelected, cal_intMMSelected, cal_intYYYYSelected, i) == true) {
          if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
            strCSSCLass = "CalSelectedToday";
          else
            strCSSCLass = "CalSelectedday";
        } else {
          if (cal_isToday(i, today.getMonth(), cal_getYear(today)) == true)
            strCSSCLass = "CalToday";
        }  // thisDay
      }  // isPastDate
    }  //SelectPast
    if ((column == 0) || (column == 6)) {
      switch (strCSSCLass) {
        case "CalSelectedToday":
          strCalendarString = strCalendarString + " style=\"background-color:" + cal_weekendSelectedBGColor + ";border: 1px solid" + cal_weekendBGColor + " \" class=\"" + strCSSCLass + "\">" + i + "</TD>";
          break;
        case "CalSelectedday":
          strCalendarString = strCalendarString + " style=\"background-color:" + cal_weekendSelectedBGColor + ";border: 1px solid" + cal_weekendBGColor + " \" class=\"" + strCSSCLass + "\">" + i + "</TD>";
          break;
        default:
          strCalendarString = strCalendarString + " style=\"background-color:" + cal_weekendBGColor + ";border:1px solid" + cal_weekendBGColor + " \" class=\"" + strCSSCLass + "\">" + i + "</TD>";
      }
    } else
      strCalendarString = strCalendarString + " class=\"" + strCSSCLass + "\">" + i + "</TD>";
    column++;
    if (column == 7) {
      strCalendarString = strCalendarString + "</TR><TR>";
      column = 0;
    }
  }
  if ((column < 7) && (column > 0)) {
    for (i = 1; i <= (7 - column); i++) {
      if ((column + i) == 7)
        strCalendarString = strCalendarString + "<TD style=\"background-color:" + cal_weekendBGColor + ";border:1px solid" + cal_weekendBGColor + " \" class=\"CalUnavailable\">" + i + "</TD>";
      else
        strCalendarString = strCalendarString + "<TD class=\"CalUnavailable\">" + i + "</TD>";
    }
    strCalendarString = strCalendarString + "</TR><TR>";
  }
  if (cal_LangId == "fr")
    strCalendarString = strCalendarString + "</tr><tr><td class='Calgototoday' colspan='7' onclick=\"cal_setToday();\">(f)Go to today</td></tr>";
  else
    strCalendarString = strCalendarString + "</tr><tr><td class='Calgototoday' colspan='7' onclick=\"cal_setToday();\">Go to today</td></tr>";
  strCalendarString = strCalendarString + "</TABLE>";
  calendarUI.innerHTML = strCalendarString;
  //cal_targetEl.value = cal_intMM + "/" + cal_intDD + "/" + cal_intYYYY;

  calendarIF.style.width = 1;
  calendarIF.style.height = 1;

  /////////the code below works for IE only.
  //	calendarUIArea = calendarUI.getBoundingClientRect();
  //	calendarIF.style.width=calendarUIArea.right - calendarUIArea.left;
  //	
  //	calendarIF.style.height=calendarUIArea.bottom - calendarUIArea.top;

  calendarUI.focus();
}


function cal_isPastDate(d, m, y, n) {
  var arrDateParts = cal_getYesterday(d, m, y).split("/");

  //if (((n<d) && (cal_intMM <= m) && (cal_intYYYY <= y)) || ((cal_intMM < m) && (cal_intYYYY <= y))) 
  if (((n < arrDateParts[1]) && (cal_intMM <= arrDateParts[0]) && (cal_intYYYY <= arrDateParts[2])) || ((cal_intMM < arrDateParts[0]) && (cal_intYYYY <= arrDateParts[2])))
    return true;
  else
    return false;
}

function cal_getYesterday(d, m, y) {
  cal_monthDays[1] = cal_getFebDays(y);
  var day = d;
  var month = m;
  var year = y;
  if (d > 1) {
    day = day - 1;
  } else {
    if (month > 1) {
      month = month - 1;
      day = cal_monthDays[month - 1]
    } else {
      year = year - 1;
      month = 12;
      day = cal_monthDays[month - 1];
    }

  }

  return (month + "/" + day + "/" + year);
}

function cal_isSelectedDate(d, m, y, n) {
  if ((n == d) && (cal_intMM == m) && (cal_intYYYY == y))
    return true;
  else
    return false;
}

function cal_getYear(date) {
  if (date.getYear() < 2000)    // Netscape 7.1
    return date.getYear() + 1900;
  else
    return date.getYear();
}
function cal_isToday(d, m, y) {
  if ((d == cal_dteToday.getDate()) && (m == cal_dteToday.getMonth()) && (y == cal_getYear(cal_dteToday))) {
    return true;
  } else {
    return false;
  }
}

function cal_setToday() {
  cal_intDD = cal_dteToday.getDate();
  cal_intMM = cal_dteToday.getMonth() + 1;
  cal_intYYYY = cal_dteToday.getYear();
  if (cal_intYYYY < 2000) {
    cal_intYYYY = cal_intYYYY + 1900;
  }
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_calendar(currentDate);
}

function cal_updateDay(intDay) {
  cal_intDD = intDay;
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_targetEl.value = cal_intMM + "/" + cal_intDD + "/" + cal_intYYYY;
  cal_close();
}

function cal_updateDayFuture(intDay, futureobj) {
  var futureText = document.getElementById(futureobj);
  cal_intDD = intDay;
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_targetEl.value = cal_intMM + "/" + cal_intDD + "/" + cal_intYYYY;
  //alert("current " + currentDate);
  if (futureText.value != '') {
    var futureArrDateParts = futureText.value.split("/");
    var futureDateVal = new Date(cal_getDateString(futureArrDateParts[0], futureArrDateParts[1], futureArrDateParts[2]));

    if (currentDate > futureDateVal) {

      var changeDate = new Date();
      cal_intMM--;
      changeDate.setFullYear(cal_intYYYY, cal_intMM, cal_intDD);
      //   alert("also current " + changeDate);
      changeDate.setDate(currentDate.getDate() + 7);

      //   alert("full " + changeDate);

      futureText.value = changeDate.getMonth() + 1 + "/" + changeDate.getDate() + "/" + changeDate.getFullYear();

    }
  }
  cal_close();
}

function cal_getFebDays(y) {
  if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0))
    return 29;
  else
    return 28;
}

function cal_forward() {
  //// Section: Deciding Forward
  ////Tis section is to check the forward date is valid within the selectable date range and decide if it should move forward.
  var yearOnCalIndex = document.getElementById("CalYearSelect").selectedIndex;
  var yearOnCalValue = document.getElementById("CalYearSelect")[yearOnCalIndex].value;

  if ((yearOnCalValue == (cal_getYear(cal_dteToday) + cal_nMaxYears - 1)) && (cal_intMM == 12)) {
    return 0;
  }

  //////Section End: Deciding Forward


  //if (cal_intYYYY <  cal_getYear(cal_dteToday)-nyearsBack-1) return 0;

  cal_intMM++;
  if (cal_intMM > 12) {
    cal_intMM = 1;
    cal_intYYYY++;
  }
  //if (cal_intYYYY > cal_arrYears[cal_arrYears.length - 1])
  //	cal_intYYYY = cal_arrYears[0];

  cal_monthDays[1] = cal_getFebDays(cal_intYYYY);
  if (cal_intDD > cal_monthDays[cal_intMM - 1]) intDD = cal_monthDays[cal_intMM - 1];
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_calendar(currentDate);

}

function cal_forwardUpdate(futureObjId) {

  //// Section: Deciding Forward
  ////Tis section is to check the forward date is valid within the selectable date range and decide if it should move forward.
  var yearOnCalIndex = document.getElementById("CalYearSelect").selectedIndex;
  var yearOnCalValue = document.getElementById("CalYearSelect")[yearOnCalIndex].value;

  if ((yearOnCalValue == (cal_getYear(cal_dteToday) + cal_nMaxYears - 1)) && (cal_intMM == 12)) {
    return 0;
  }

  //////Section End: Deciding Forward

  var findObj = document.getElementById(futureObjId.toString());

  cal_intMM++;
  if (cal_intMM > 12) {
    cal_intMM = 1;
    cal_intYYYY++;
  }
  //if (cal_intYYYY > cal_arrYears[cal_arrYears.length - 1])
  //	cal_intYYYY = cal_arrYears[0];

  cal_monthDays[1] = cal_getFebDays(cal_intYYYY);
  if (cal_intDD > cal_monthDays[cal_intMM - 1])
    intDD = cal_monthDays[cal_intMM - 1];
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_calendarUpdate(currentDate, findObj.id.toString());

}

function cal_back() {
  //// Section: Deciding go back
  ////Tis section is to check the rollback date is valid within the selectable date range and decide if it should go back.
  var yearOnCalIndex = document.getElementById("CalYearSelect").selectedIndex;
  var yearOnCalValue = document.getElementById("CalYearSelect")[yearOnCalIndex].value;
  var prevMonth = cal_intMM - 1;

  if (prevMonth < 1) {
    prevMonth = 12;
  }

  if (yearOnCalValue < cal_getYear(cal_dteToday)) {
    return 0;
  }
  else {
    if ((yearOnCalValue == cal_getYear(cal_dteToday)) && (prevMonth < cal_dteToday.getMonth() + 1)) {

      return 0;
    }

  }

  //////Section End: Deciding go back

  if (blnRollPast == true) {
    cal_intMM--;
  } else {
    if ((cal_intMM > (cal_dteToday.getMonth() + 1)) && (cal_intYYYY >= cal_getYear(cal_dteToday)) || (cal_intYYYY > cal_getYear(cal_dteToday))) {
      cal_intMM--;
    }
  }  //RollPast

  if (cal_intMM < 1) {
    cal_intMM = 12;
    cal_intYYYY--;
  }
  if (cal_intYYYY < cal_arrYears[0])
    cal_intYYYY = cal_arrYears[cal_arrYears.length - 1];

  cal_monthDays[1] = cal_getFebDays(cal_intYYYY);
  if (cal_intDD > cal_monthDays[cal_intMM - 1]) cal_intDD = cal_monthDays[cal_intMM - 1];
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_calendar(currentDate);

}

function cal_backUpdate(futureObjId) {
  //// Section: Deciding go back
  ////Tis section is to check the rollback date is valid within the selectable date range and decide if it should go back.
  var yearOnCalIndex = document.getElementById("CalYearSelect").selectedIndex;
  var yearOnCalValue = document.getElementById("CalYearSelect")[yearOnCalIndex].value;
  var prevMonth = cal_intMM - 1;

  if (prevMonth < 1) {
    prevMonth = 12;
  }

  if (yearOnCalValue < cal_getYear(cal_dteToday)) {
    return 0;
  }
  else {
    if ((yearOnCalValue == cal_getYear(cal_dteToday)) && (prevMonth < cal_dteToday.getMonth() + 1)) {

      return 0;
    }

  }

  //////Section End: Deciding go back

  var findObj = document.getElementById(futureObjId);
  var futM = cal_intMM;
  if (futM < 10) {
    futM = "" + 0 + futM;
  }
  var moveDate = "" + cal_intYYYY + futM;

  var curY = cal_dteToday.getYear();
  if (curY < 2000) {
    curY = curY + 1900;
  }
  var curM = cal_dteToday.getMonth() + 1;
  if (curM < 10) {
    curM = "" + 0 + curM;
  }
  var curDate = "" + curY + curM;
  //alert("changeing "+ moveDate +" "+curDate);
  if (moveDate <= curDate) {

    return 0;
  }


  if (blnRollPast == true) {
    cal_intMM--;
  } else {
    if ((cal_intMM > (cal_dteToday.getMonth() + 1)) && (cal_intYYYY >= cal_getYear(cal_dteToday)) || (cal_intYYYY > cal_getYear(cal_dteToday))) {
      cal_intMM--;
    }
  }  //RollPast

  if (cal_intMM < 1) {
    cal_intMM = 12;
    cal_intYYYY--;
  }
  if (cal_intYYYY < cal_arrYears[0])
    cal_intYYYY = cal_arrYears[cal_arrYears.length - 1];

  cal_monthDays[1] = cal_getFebDays(cal_intYYYY);
  if (cal_intDD > cal_monthDays[cal_intMM - 1]) cal_intDD = cal_monthDays[cal_intMM - 1];
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_calendarUpdate(currentDate, findObj.id.toString());

}



function cal_refreshCal(intYear) {

  //// When year is selected back to current year, check if the month is valid. If yes, set the caledar to today
  var CalSelectedYear = intYear;
  if ((CalSelectedYear == cal_getYear(cal_dteToday)) && (cal_intMM < cal_dteToday.getMonth() + 1)) {
    cal_setToday();
    return 0;
  }
  ////////

  cal_intYYYY = intYear;
  cal_monthDays[1] = cal_getFebDays(cal_intYYYY);
  if (cal_intDD > cal_monthDays[cal_intMM - 1]) cal_intDD = cal_monthDays[cal_intMM - 1];
  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));
  cal_calendar(currentDate);

}

function cal_showFutureCalendar(elThisElement, langid, calid) {
  // 
  var arrDateParts = document.getElementById(calid).value.split("/");
  cal_dteToday = new Date(cal_getDateString(arrDateParts[0], arrDateParts[1], arrDateParts[2]));
  //alert("here " +cal_dteToday);
  cal_showCalendarNoUpdate(elThisElement, langid);
}

function cal_showCalendarNoUpdate(elThisElement, langid) {
  // the element passed is the button that was clicked
  // set the UI

  if (calendarIF == null) {
    calendarIF = document.createElement("iframe");
    calendarIF.style.position = "absolute";
    calendarIF.style.visibility = "hidden";
    calendarIF.disabled = true;
    calendarIF.style.zIndex = 0;
    document.body.appendChild(calendarIF);
  }
  if (calendarUI == null) {

    calendarUI = document.createElement("DIV");
    calendarUI.style.position = "absolute";
    calendarUI.style.visibility = "hidden";
    calendarUI.style.zIndex = 999;
    document.body.appendChild(calendarUI);
  }
  if ((calSelectList == null) && (cal_useCalSelect == true)) {
    calSelectList = document.createElement("DIV");
    calSelectList.style.position = "absolute";
    calSelectList.style.visibility = "hidden";
    calSelectList.style.height = "120";
    calSelectList.style.overflow = "auto";
    calSelectList.id = "cal_SelectList";
    calSelectList.style.zIndex = 9999;
    document.body.appendChild(calSelectList);
  }

  cal_LangId = langid.toLowerCase();

  var calendarImgObj = document.getElementById(elThisElement);
  cal_targetEl = calendarImgObj.previousSibling;
  //alert("here " + cal_targetEl.value);

  if (cal_targetEl.value == "") {
    var arrDateParts = new Array(cal_intMM, cal_intDD, cal_intYYYY);

  }
  else {
    var arrDateParts = cal_targetEl.value.split("/");
  }
  //var calendarTargerArea = cal_targetEl.getBoundingClientRect();


  cal_intMM = arrDateParts[0];
  cal_intDD = arrDateParts[1];
  cal_intYYYY = arrDateParts[2];
  cal_intMMSelected = arrDateParts[0];
  cal_intDDSelected = arrDateParts[1];
  cal_intYYYYSelected = arrDateParts[2];
  cal_genYearList(cal_intYYYY);


  calendarUI.x = cal_getposOffset(calendarImgObj, "left");
  calendarUI.y = cal_getposOffset(calendarImgObj, "top");
  calendarUI.style.left = calendarUI.x + "px";
  calendarUI.style.top = calendarUI.y + "px";
  calendarUI.style.visibility = "visible";
  //	calendarUI.style.left=calendarTargerArea.right - 2;
  //  
  //    calendarUI.style.top= calendarTargerArea.top +document.body.scrollTop -2;


  calendarIF.style.left = calendarUI.style.left;
  calendarIF.style.top = calendarUI.style.top;
  calendarIF.style.border = 0;
  calendarIF.style.visibility = "visible";

  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));

  cal_calendar(currentDate);
}

function cal_showCalendar(elThisElement, langid, futureDate) {
  // the element passed is the button that was clicked
  // set the UI

  var futureDateObj = futureDate.toString();
  if (calendarIF == null) {
    calendarIF = document.createElement("iframe");
    calendarIF.style.position = "absolute";
    calendarIF.style.visibility = "hidden";
    calendarIF.disabled = true;
    calendarIF.style.zIndex = 0;
    document.body.appendChild(calendarIF);
  }
  if (calendarUI == null) {

    calendarUI = document.createElement("DIV");
    calendarUI.style.position = "absolute";
    calendarUI.style.visibility = "hidden";
    calendarUI.style.zIndex = 999;
    document.body.appendChild(calendarUI);
  }
  if ((calSelectList == null) && (cal_useCalSelect == true)) {
    calSelectList = document.createElement("DIV");
    calSelectList.style.position = "absolute";
    calSelectList.style.visibility = "hidden";
    calSelectList.style.height = "120";
    calSelectList.style.overflow = "auto";
    calSelectList.id = "cal_SelectList";
    calSelectList.style.zIndex = 9999;
    document.body.appendChild(calSelectList);
  }

  cal_LangId = langid.toLowerCase();

  var calendarImageObj = document.getElementById(elThisElement);
  cal_targetEl = calendarImageObj.previousSibling;

  //  cal_targetEl? alert("Yes") : alert("No");

  if (cal_targetEl.value == "") {
    var arrDateParts = new Array(cal_intMM, cal_intDD, cal_intYYYY);

  }
  else {
    var arrDateParts = cal_targetEl.value.split("/");
  }



  //    var calendarTargerArea = cal_targetEl.getBoundingClientRect();


  cal_intMM = arrDateParts[0];
  cal_intDD = arrDateParts[1];
  cal_intYYYY = arrDateParts[2];
  cal_intMMSelected = arrDateParts[0];
  cal_intDDSelected = arrDateParts[1];
  cal_intYYYYSelected = arrDateParts[2];
  cal_genYearList(cal_intYYYY);


  calendarUI.x = cal_getposOffset(calendarImageObj, "left");
  calendarUI.y = cal_getposOffset(calendarImageObj, "top");
  calendarUI.style.left = calendarUI.x + "px";
  calendarUI.style.top = calendarUI.y + "px";
  calendarUI.style.visibility = "visible";

  //	calendarUI.style.left=calendarTargetLeft- 2;
  //  
  //    calendarUI.style.top= calendarTargetTop -2;
  //	calendarUI.style.left=calendarTargerArea.right - 2;
  //  
  //    calendarUI.style.top= calendarTargerArea.top +document.body.scrollTop -2;


  calendarIF.style.left = calendarUI.style.left;
  calendarIF.style.top = calendarUI.style.top;
  calendarIF.style.border = 0;
  calendarIF.style.visibility = "visible";


  var currentDate = new Date(cal_getDateString(cal_intMM, cal_intDD, cal_intYYYY));

  cal_calendarUpdate(currentDate, futureDateObj);
}

function cal_SelectValue(v) {
  var calSelectValue = document.getElementById("cal_SelectValue");
  calSelectList.style.visibility = "hidden";
  if (document.all) {
    calSelectValue.innerText = v;
  } else {
    calSelectValue.textContent = v;
  }

  cal_refreshCal(v);
}
function cal_showSelectlist() {
  if (calSelectList.style.visibility == "visible") {
    calSelectList.style.visibility = "hidden";
    return 0;
  }
  var calSelectValue = document.getElementById("cal_SelectValue");
  var calSelectDropDown = document.getElementById("cal_SelectDropDown");
  var calDropListArea = calSelectDropDown.getBoundingClientRect();
  if (parseInt(calSelectList.scrollHeight) > parseInt(calSelectList.style.height)) {
    calSelectList.style.width = 18 + calDropListArea.right - calDropListArea.left;
  } else {
    calSelectList.style.width = 2 + calDropListArea.right - calDropListArea.left;
    calSelectList.style.height = 2 + calDropListArea.bottom - calDropListArea.top;
  }
  calSelectList.style.left = calSelectValue.getBoundingClientRect().left - 2;
  calSelectList.style.top = calSelectValue.getBoundingClientRect().bottom - 2;
  calSelectList.style.visibility = "visible";

}

function cal_close() {
  cal_hideElement(calendarUI);
  cal_hideElement(calendarIF);
}

function cal_hideElement(elElement) {
  elElement.style.visibility = "hidden";
}

function cal_mouseover(el) {
  el.style.border = cal_dayMouseOverBorder;
  el.style.width = 22;
}
function cal_mouseout(el) {
  if (el.style.backgroundColor == cal_weekendBGColor) {
    el.style.border = "1px solid " + cal_weekendBGColor;
    el.style.width = 22;
  }
  else {
    el.style.border = cal_dayMouseOutBorder;
    el.style.width = 22;
  }
}

function cal_Selectmouseover(el) {
  el.style.border = cal_dayMouseOverBorder;
  el.style.width = 22;
}
function cal_Selectmouseout(el) {
  el.style.border = cal_SelectMouseOutBorder;
  el.style.width = 22;
}

function cal_getposOffset(what, offsettype) {

  var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
  var parentEl = what.offsetParent;
  while (parentEl != null) {
    totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
    parentEl = parentEl.offsetParent;
  }
  return totaloffset;
}

//  ---------------------------------------------------------
//  End Calendar Code
//  ---------------------------------------------------------

//  ---------------------------------------------------------
//  Start SWFObject v1.4.1: Flash Player detection and embed Code
//  ---------------------------------------------------------

/**
 * SWFObject v1.4.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, a, t, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.createElement || !document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
	if(c) { this.addParam('bgcolor', c); }
	if(a) { this.addParam('alt', a); }
	if(t) { this.addParam('title', t); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			swfNode += '<param name="wmode" value="transparent" />';
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				PlayerVersion = new deconcept.PlayerVersion([i,0,0]);
			}
		}catch(e){}
		if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion; // version is ok, skip minor detection
		// this only does the minor rev lookup if the user's major version 
		// is not 6 or we are checking for a specific minor or revision number
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || xiInstall) {
			try{
				PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}catch(e){}
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param){
		var q = document.location.search || document.location.hash;
		if(q){
			var startIndex = q.indexOf(param +"=");
			var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
			if (q.length > 1 && startIndex > -1) {
				return q.substring(q.indexOf("=", startIndex)+1, endIndex);
			}
		}
		return "";
	}
}

/* fix for video streaming bug */
/*
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = null;
			}
		}
	}
}
if (typeof window.onunload == 'function') {
	var oldunload = window.onunload;
		window.onunload = function() {
		deconcept.SWFObjectUtil.cleanupSWFs();
		oldunload();
	}
} else {
	window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}
*/

/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

//  ---------------------------------------------------------
//  End SWFObject v1.4.1: Flash Player detection and embed Code
//  ---------------------------------------------------------

