// *** WARNING - IF YOU CHANGE THIS FILE YOU MUST ALSO RENAME THE CHANGED FUNCTION AND THIS FILE AS IE AND SOME OTHER BROWSERS CACHE OLDER VERSIONS  ***

<!--- global vars/code for browser determination for this page --->
if(document.getElementById) {
   var upLevel = true;
}
else if(document.layers) {
   var ns4 = true;
}
else if(document.all) {
   var ie4 = true;
}


//
//    LSS Common functions
//
function setPointer() {
    if (document.all) {
       for (var i=0;i < document.all.length; i++)
	     document.all(i).style.cursor = 'wait'; 
    }
}
// Note changed name from resetPointer() as old routine was being cached when changed here. 
function resetAutoCursor() {
    if (document.all) {
       for (var i=0;i < document.all.length; i++)
	     document.all(i).style.cursor = 'auto';
    }
}

function setSID(linkObject, SID)
{
	//alert ('it work and SID: ' + SID);
	setPointer();
	var linkWithSID = linkObject.href + SID;
	linkObject.href = linkWithSID;
}

// Used for <a href...> links, to setPointer and submit form
// Note that if parmeters are passed in the URL statement of the action parm
// they are useless...they do NOT get submitted with the form data.
// If you need to use the parameters don't use this function. 
function goLink(action) {
   setPointer();
   var form = document.MainForm;
   form.action=action;
   form.submit();
}

/*
 * For use with links to submit form data and clear href so won't be overridden
 */
function goLink2(action,linkObj) {
   setPointer();
   var form = document.MainForm;
   form.action=action;
   if (linkObj != null){
       linkObj.href="#";
   }
   form.submit();
}
/*
 * For use with links to submit form data and clear href so won't be overridden
 * as well as setting type and path vars for use in geographic pages and listing
 * details pages decision maker pipelines. 
 */
function goGeoLink2(action,type, linkObj) {
   setPointer();
   var form = document.MainForm;
   form.action=action;
   form.type.value=type;
   form.path.value=action;
   if (linkObj != null){
       linkObj.href="#";
   }
   form.submit();
}

function goToListingDetails(id) {
	var form = document.MainForm;
    form.ListingID.value=id;
    form.action="/listings/listing/"+id+ ".htm";
    setPointer();
    form.submit();
    return false;//Don't have form double-submit
}

function viewListingDetails5(urlStr, tabType, linkObj) {
   var form = document.MainForm;
    //form.ListingID.value=id;
    form.action=urlStr;
    setPointer();
    if (linkObj != null){
        linkObj.href="#";
    }
    form.type.value=tabType;
    form.path.value=urlStr;
    form.submit();
    return false;
}




// If item represents a WA Bookable Unit that is NOT a Listing
function goToUnitDetails2(id,url, linkObj) {
	 var form = document.MainForm;
    form.UnitID.value=id;
    // todo implement custom WA Pipeline that will allow UnitDetails with only UnitID  
    form.action=url+"?UnitID="+id;
    setPointer();
    if (linkObj != null){
        linkObj.href="#";
    }
    form.submit();
    return false;//Don't have form objects double submit();
}

// if linkObj is not null assumed to be <a href> obj reference to be unset
function sortResults3(url,sortCol,ascDescFlag, linkObj) {
   var form = document.MainForm;
	form.SortCol.value = sortCol;
	form.SortDirection.value = ascDescFlag;
   form.action=url+sortCol+"/"+ascDescFlag+"/"+form.CityID.value+".html";		    
	setPointer();
   if (linkObj != null){
           linkObj.href="#";
   }
   form.submit();
	return false;
}



function ltrim(str) {
  if (str == null) {
    return "";
  }
  while(''+str.charAt(0)==' ')str=str.substring(1,str.length);
  return str;
}
function trim(str) {
  if (str == null) {
    return "";
  }
  return ltrim(rtrim(str));
}
function checkEmailAddress(str) {
  var goodEmail = str.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
  return goodEmail;
}

function printWindow(){
  bV = parseInt(navigator.appVersion)
  if (bV >= 4) window.print();
  return false;
}

function doSubmitBack() {
   setPointer();
   var form = document.MainForm;
   form.action=form.BackToURL.value;
   form.submit();
   return true;
}    
function showMsg(){
  // Hide elements on page and show please wait splash
  // This script is intended for use with a minimum of Netscape 4 or IE 4.
      if(document.getElementById) {
            var upLevel = true;
      }
      else if(document.layers) {
            var ns4 = true;
      }
      else if(document.all) {
            var ie4 = true;
      }
      if (ns4) {
          document.error_section.style.visibility="show";  
      }
      if (ie4 || upLevel) {
          var splash = document.getElementById("error_section");
          splash.style.visibility="visible";  
      }
}
   
function hideMsg(){
   // Hide elements on page and show please wait splash
   // This script is intended for use with a minimum of Netscape 4 or IE 4.
   if(document.getElementById) {
            var upLevel = true;
      }
      else if(document.layers) {
            var ns4 = true;
      }
      else if(document.all) {
            var ie4 = true;
      }
      if (ns4) {
          document.error_section.style.visibility="hide";  
      }
      if (ie4 || upLevel) {
          var splash = document.getElementById("error_section");
          splash.style.visibility="hidden";  
      }
}

function isEmpty(inStr) {
   if (inStr == null || inStr == "")  {
      return true;
   }
   return false;
}
	
function getInt(val) {
   return val - 1 + 1;  
   // David Chen:
   // there is BUG on javascript parseInt().
   // value 08 and 09 alway return 0 instead of 8 or 9!
}

function isNumber(inVal) {
   oneDec = false;
   inStr = inVal.toString();
   for (var i=0; i <inStr.length; i++) {
      var oneChar = inStr.charAt(i);
      if( i == 0 && oneChar == "-") {
         continue;
      }
      if (oneChar == "." && !oneDec) {
         oneDec = true;
         continue;
      }
      if (oneChar < "0" || oneChar > "9") {
         return false;
      }
   }
   return true;
}

function isPositiveNumber(inVal) {
   oneDec = false;
   inStr = inVal.toString();
   for (var i=0; i <inStr.length; i++) {
      var oneChar = inStr.charAt(i);
      if( i == 0 && oneChar == "+") {
         continue;
      }
      if (oneChar == "." && !oneDec) {
         oneDec = true;
         continue;
      }
      if (oneChar < "0" || oneChar > "9") {
         return false;
      }
   }
   return true;
}

/** 
 *  Returns true if the input value contains at least one '.'
 */            
function hasDecimal(inVal) {
   inStr = inVal.toString();
   for (var i=0; i <inStr.length; i++) {
      var oneChar = inStr.charAt(i);
      if (oneChar == ".") {
         return true;
      }
   }
   return false; 
}

function is2Decimal(inVal) {
   oneDec = false;
   var lastDig = 0;
   inStr = inVal.toString();
   for (var i=0; i <inStr.length; i++) {
      var oneChar = inStr.charAt(i);
      if( i == 0 && oneChar == "-") {
         continue;
      }
      if (oneChar == "." && !oneDec) {
         oneDec = true;
         continue;
      }
      if (oneChar < "0" || oneChar > "9") {
         return false;
      }
      else {
         if (oneDec) {
            lastDig++;
         }
         if (lastDig >= 3) {
            return false;
         }
      }
   }
   return true; 
}

function checkMonthDay(month, day) {
   var months = new Array("","January","February","March","April","May","June","July",
         "August","September","October","November","December");
   if ((month==4 || month==6 || month==9 || month==11) && day > 30) {
      alert(months[month] + " does not have 31 days.");
      return false;
   } 
   else if (day > 31) {
      alert(months[month] + " has only 31 days.");
      return false;
   }
   return true;
}

function checkLeapMonth(mm, dd, yyyy) {
   if( yyyy%4 > 0 && dd > 28) {
      alert("February of " + yyyy + " does not have " + dd + " days.");
      return false;
   }
   else if (dd > 29) {
      alert("February of " + yyyy + " does not have " + dd + " days.");
      return false;
   }
   return true;
}

function popupWindow(url, name) {
   mywindow = window.open(url,name,'status=no,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,width=450,height=400');
   mywindow.location = url;
   mywindow.focus();
}

function popupWindow3(url, name) {
   mywindow = window.open(url,name,'status=yes,toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=600');
   mywindow.location = url;
   mywindow.focus();
}



//
// Common Calendar functions
//

// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.2 (American date format)
// Date: 10/14/2002 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note - Scripts changed for use in our Enfinity application environment
// Note: Script now consists of two files: calendar2.isml and rtr_popupCalendar.isml

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function  calendar2(obj_target1,obj_target2,obj_target3) {
	// assigning methods
	this.gen_dateMonth = cal_gen_date2Month;
	this.gen_dateDay = cal_gen_date2Day;
	this.gen_dateYear = cal_gen_date2Year;
	this.gen_time = cal_gen_time2;
	this.gen_tsmp = cal_gen_tsmp2;
	this.prs_date = cal_prs_date2;
	this.prs_time = cal_prs_time2;
	this.prs_tsmp = cal_prs_tsmp2;
	this.popup    = cal_popup2;

	// validate input parameters
	if (!obj_target1)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target1.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target1 = obj_target1;
	this.target2 = obj_target2;
	this.target3 = obj_target3;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

// NOTE TODO REVISIT HARDCODING OF THE URL/PIPELINE IN WINDOWS.OPEN
// DID THIS TO GET THIS FUNCTION OUT OF ISML AND INTO THIS .JS INCLUDE
function cal_popup2 (str_datetime) {
     this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : "");
     if (!this.dt_current) return;
 
    // var obj_calwindow = window.open("#URL(action('rtr_ViewSearchHome-SelectDatePopup'))#"+"?datetime=" + this.dt_current.valueOf()+ '&id=' + this.id,
     var obj_calwindow = window.open("calendar.html?datetime=" + this.dt_current.valueOf()+ '&id=' + this.id,
         'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
         ',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
     );
     obj_calwindow.opener = window;
     obj_calwindow.focus();
 }

// timestamp generating function
function cal_gen_tsmp2 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}
// date generating function
function cal_gen_date2 (dt_datetime) {
	return (
		(dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
		+ (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
		+ dt_datetime.getFullYear()
	);
}

function cal_gen_date2Month (dt_datetime) {
	var monthNum = (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) ;
	switch (monthNum) 
	{ 
	   case "01" : 
	      return ("1");
	   case "02" : 
	      return ("2");
	   case "03" : 
	      return ("3");
	   case "04" : 
	      return ("4");
	   case "05" : 
	      return ("5");
	   case "06" : 
	      return ("6");
	   case "07" : 
	      return ("7");
	   case "08" : 
	      return ("8");
	   case "09" : 
	      return ("9");
	   case "10" : 
	      return ("10");
	   case "11" : 
	      return ("11");
	   case "12" : 
	      return ("12");
	   default : 
	      return ("1");
	} 
}

function cal_gen_date2Day (dt_datetime) {
	var dayNum = (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate()  ;
	switch (dayNum) 
	{ 
	   case "01" : 
	      return ("1");
	   case "02" : 
	      return ("2");
	   case "03" : 
	      return ("3");
	   case "04" : 
	      return ("4");
	   case "05" : 
	      return ("5");
	   case "06" : 
	      return ("6");
	   case "07" : 
	      return ("7");
	   case "08" : 
	      return ("8");
	   case "09" : 
	      return ("9");
	   default : 
	      return (dayNum);
	} 

	return (
		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() 
	);
}

function cal_gen_date2Year (dt_datetime) {
	return (
		dt_datetime.getFullYear()
	);
}

// time generating function
function cal_gen_time2 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp2 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date2 (str_date) {

	var arr_date = str_date.split('/');

	if (arr_date.length != 3) return alert ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd-mm-yyyy.");
	if (!arr_date[1]) return alert ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return alert ("Invalid day of month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[0]) return alert ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return alert ("Invalid month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return alert ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return alert ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[0] < 1 || arr_date[0] > 12) return alert ("Invalid month value: '" + arr_date[0] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[0]-1);
	 
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);

	var dt_numdays = new Date(arr_date[2], arr_date[0], 0);
	dt_date.setDate(arr_date[1]);
	if (dt_date.getMonth() != (arr_date[0]-1)) return alert ("Invalid day of month value: '" + arr_date[1] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time2 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0])) 
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

// functions from old dateutil.js

/** 
   Here's the list of tokens we support:
   m (or M) : month number, one or two digits.
   mm (or MM) : month number, strictly two digits (i.e. April is 04).
   d (or D) : day number, one or two digits.
   dd (or DD) : day number, strictly two digits.
   y (or Y) : year, two or four digits.
   yy (or YY) : year, strictly two digits.
   yyyy (or YYYY) : year, strictly four digits.
   mon : abbreviated month name (April is apr, Apr, APR, etc.)
   Mon : abbreviated month name, mixed-case (i.e. April is Apr only).
   MON : abbreviated month name, all upper-case (i.e. April is APR only).
   mon_strict : abbreviated month name, all lower-case (i.e. April is apr 
         only).
   month : full month name (April is april, April, APRIL, etc.)
   Month : full month name, mixed-case (i.e. April only).
   MONTH: full month name, all upper-case (i.e. APRIL only).
   month_strict : full month name, all lower-case (i.e. april only).
   h (or H) : hour, one or two digits.
   hh (or HH) : hour, strictly two digits.
   min (or MIN): minutes, one or two digits.
   mins (or MINS) : minutes, strictly two digits.
   s (or S) : seconds, one or two digits.
   ss (or SS) : seconds, strictly two digits.
   ampm (or AMPM) : am/pm setting.  Valid values to match this token are
         am, pm, AM, PM, a.m., p.m., A.M., P.M.
**/

// Be careful with this pattern.  Longer tokens should be placed before shorter
// tokens to disambiguate them.  For example, parsing "mon_strict" should 
// result in one token "mon_strict" and not two tokens "mon" and a literal
// "_strict".

var tokPat=new RegExp("^month_strict|month|Month|MONTH|yyyy|YYYY|mins|MINS|mon_strict|ampm|AMPM|mon|Mon|MON|min|MIN|dd|DD|mm|MM|yy|YY|hh|HH|ss|SS|m|M|d|D|y|Y|h|H|s|S");

// lowerMonArr is used to map months to their numeric values.

var lowerMonArr={jan:1, feb:2, mar:3, apr:4, may:5, jun:6, jul:7, aug:8, sep:9, oct:10, nov:11, dec:12}

// monPatArr contains regular expressions used for matching abbreviated months
// in a date string.

var monPatArr=new Array();
monPatArr['mon_strict']=new RegExp(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/);
monPatArr['Mon']=new RegExp(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/);
monPatArr['MON']=new RegExp(/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/);
monPatArr['mon']=new RegExp("jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",'i');

// monthPatArr contains regular expressions used for matching full months
// in a date string.

var monthPatArr=new Array();
monthPatArr['month']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/i);
monthPatArr['Month']=new RegExp(/^January|February|March|April|May|June|July|August|September|October|November|December/);
monthPatArr['MONTH']=new RegExp(/^JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER/);
monthPatArr['month_strict']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/);

// cutoffYear is the cut-off for assigning "19" or "20" as century.  Any
// two-digit year >= cutoffYear will get a century of "19", and everything
// else gets a century of "20".

var cutoffYear=50;

// FormatToken is a datatype we use for storing extracted tokens from the
// format string.

function FormatToken (token, type) {
  this.token=token;
  this.type=type;
}

function parseFormatString (formatStr) {
  var tokArr=new Array;
  var tokInd=0;
  var strInd=0;
  var foundTok=0;
      
  while (strInd < formatStr.length) {
    if (formatStr.charAt(strInd)=="%" &&
        (matchArray=formatStr.substr(strInd+1).match(tokPat)) != null) {
      strInd+=matchArray[0].length+1;
      tokArr[tokInd++]=new FormatToken(matchArray[0],"symbolic");
    } else {
      // No token matched current position, so current character should 
      // be saved as a required literal.
      if (tokInd>0 && tokArr[tokInd-1].type=="literal") {
        // Literal tokens can be combined.Just add to the last token.
        tokArr[tokInd-1].token+=formatStr.charAt(strInd++);
      } else {
        tokArr[tokInd++]=new FormatToken(formatStr.charAt(strInd++), "literal");
      }
    } //end of if-then-else
  } //end of while
  return tokArr;
}

/* buildDate does all the real work.It takes a date string and format string,
 tries to match the two up, and returns a Date object (with the supplied date
 string value).If a date string doesn't contain all the fields that a Date
 object contains (for example, a date string with just the month), all
 unprovided fields are defaulted to those characteristics of the current
 date. Time fields that aren't provided default to 0.Thus, a date string
 like "3/30/2000" in "%mm/%dd/%yyyy" format results in a Date object for that
 date at midnight.formatStr is a free-form string that indicates special
 tokens via the % character.Here are some examples that will return a Date
 object:

 buildDate('3/30/2000','%mm/%dd/%y') // March 30, 2000
 buildDate('March 30, 2000','%Mon %d, %y') // Same as above.
 buildDate('Here is the date: 30-3-00','Here is the date: %dd-%m-%yy')

 If the format string does not match the string provided, an error message
 (i.e. String object) is returned.Thus, to see if buildDate succeeded, the
 caller can use the "typeof" command on the return value.For example,
 here's the dateCheck function, which returns true if a given date is
 valid,and false otherwise (and reports an error in the false case):

 function dateCheck(dateStr,formatStr) {
   var myObj=buildDate(dateStr,formatStr);
   if (typeof myObj=="object") {
     // We got a Date object, so good.
     return true;
   } else {
     // We got an error string.
     alert(myObj);
     return false;
   }
 }

*/

function buildDate(dateStr,formatStr) {
  // parse the format string first.
  var tokArr=parseFormatString(formatStr);
  var strInd=0;
  var tokInd=0;
  var intMonth;
  var intDay;
  var intYear;
  var intHour;
  var intMin;
  var intSec;
  var ampm="";
  var strOffset;
  
  // Create a date object with the current date so that if the user only
  // gives a month or day string, we can still return a valid date.
  
  var curdate=new Date();
  intMonth=curdate.getMonth()+1;
  intDay=curdate.getDate();
  intYear=curdate.getFullYear();

  // Default time to midnight, so that if given just date info, we return
  // a Date object for that date at midnight.
  
  intHour=0;
  intMin=0;
  intSec=0;
  
  // Walk across dateStr, matching the parsed formatStr until we find a 
  // mismatch or succeed.
  while (strInd < dateStr.length && tokInd < tokArr.length) {
    // Start with the easy case of matching a literal.
    if (tokArr[tokInd].type=="literal") {
      if (dateStr.indexOf(tokArr[tokInd].token,strInd)==strInd) {
        // The current position in the string does match the format 
        // pattern.
        strInd+=tokArr[tokInd++].token.length;
        continue;
      } else {
        // ACK! There was a mismatch; return error.
        return "\"" + dateStr + "\" does not conform to the expected format: " + formatStr;
      } //end of if-then-else
    } //end of if

    // If we get here, we're matching to a symbolic token.
    switch (tokArr[tokInd].token) {
      case 'm':
      case 'M':
      case 'd':
      case 'D':
      case 'h':
      case 'H':
      case 'min':
      case 'MIN':
      case 's':
      case 'S':
    
        // Extract one or two characters from the date-time string and if 
        // it's a number, save it as the month, day, hour, or minute, as
        // appropriate.
        
        curChar=dateStr.charAt(strInd);
        nextChar=dateStr.charAt(strInd+1);
        matchArr=dateStr.substr(strInd).match(/^\d{1,2}/);
        if (matchArr==null) {
          // First character isn't a number; there's a mismatch between
          // the pattern and date string, so return error.
          switch (tokArr[tokInd].token.toLowerCase()) {
            case 'd': var unit="day"; break;
            case 'm': var unit="month"; break;
            case 'h': var unit="hour"; break;
            case 'min': var unit="minute"; break;
            case 's': var unit="second"; break;
          }
          return "Bad " + unit + " \"" + curChar + "\" or \"" + curChar + nextChar + "\".";
        }
        strOffset=matchArr[0].length;
        switch (tokArr[tokInd].token.toLowerCase()) {
          case 'd': intDay=parseInt(matchArr[0],10); break;
          case 'm': intMonth=parseInt(matchArr[0],10); break;
          case 'h': intHour=parseInt(matchArr[0],10); break;
          case 'min': intMin=parseInt(matchArr[0],10); break;
          case 's': intSec=parseInt(matchArr[0],10); break;
        }
        break;
        
      case 'mm':
      case 'MM':
      case 'dd':
      case 'DD':
      case 'hh':
      case 'HH':
      case 'mins':
      case 'MINS':
      case 'ss':
      case 'SS':
      
        // Extract two characters from the date string and if it's a 
        // number, save it as the month, day, or hour, as appropriate.
        
        strOffset=2;
        matchArr=dateStr.substr(strInd).match(/^\d{2}/);
        if (matchArr==null) {
          // The two characters aren't a number; there's a mismatch 
          // between the pattern and date string, so return an error
          // message.
          switch (tokArr[tokInd].token.toLowerCase()) {
            case 'dd': var unit="day"; break;
            case 'mm': var unit="month"; break;
            case 'hh': var unit="hour"; break;
            case 'mins': var unit="minute"; break;
            case 'ss': var unit="second"; break;
          }
          return "Bad " + unit + " \"" + dateStr.substr(strInd,2) + "\".";
        }
        switch (tokArr[tokInd].token.toLowerCase()) {
          case 'dd': intDay=parseInt(matchArr[0],10); break;
          case 'mm': intMonth=parseInt(matchArr[0],10); break;
          case 'hh': intHour=parseInt(matchArr[0],10); break;
          case 'mins': intMin=parseInt(matchArr[0],10); break;
          case 'ss': intSec=parseInt(matchArr[0],10); break;
        }
        break;
        
      case 'y':
      case 'Y':
      
        // Extract two or four characters from the date string and if it's
        // a number, save it as the year.Convert two-digit years to four
        // digit years by assigning a century of '19' if the year is >= 
        // cutoffYear, and '20' otherwise.
        
        if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {
          // Four digit year.
          intYear=parseInt(dateStr.substr(strInd,4),10);
          strOffset=4;
        } else {
          if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {
            // Two digit year.
            intYear=parseInt(dateStr.substr(strInd,2),10);
            if (intYear>=cutoffYear) {
              intYear+=1900;
            } else {
              intYear+=2000;
            }
            strOffset=2;
          } else {
            // Bad year; return error.
            return "Bad year \"" + dateStr.substr(strInd,2) + "\". Must be two or four digits.";
          }
        }
        break;
    
      case 'yy':
      case 'YY':
      
        // Extract two characters from the date string and if it's a 
        // number, save it as the year.Convert two-digit years to four 
        // digit years by assigning a century of '19' if the year is >= 
        // cutoffYear, and '20' otherwise.
        if (dateStr.substr(strInd,2).search(/\d{2}/) != -1) {
          // Two digit year.
          intYear=parseInt(dateStr.substr(strInd,2),10);
          if (intYear>=cutoffYear) {
            intYear+=1900;
          } else {
            intYear+=2000;
          }
          strOffset=2;
        } else {
          // Bad year; return error
          return "Bad year \"" + dateStr.substr(strInd,2) + "\". Must be two digits.";
        }
        break;
    
      case 'yyyy':
      case 'YYYY':
        
        // Extract four characters from the date string and if it's a 
        // number, save it as the year.
        if (dateStr.substr(strInd,4).search(/\d{4}/) != -1) {
        // Four digit year.
          intYear=parseInt(dateStr.substr(strInd,4),10);
          strOffset=4;
        } else {
          // Bad year; return error.
          return "Bad year \"" + dateStr.substr(strInd,4) + "\". Must be four digits.";
        }
        break;
    
      case 'mon':
      case 'Mon':
      case 'MON':
      case 'mon_strict':
      
        // Extract three characters from dateStr and parse them as 
        // lower-case, mixed-case, or upper-case abbreviated months,
        // as appropriate.
        monPat=monPatArr[tokArr[tokInd].token];
        if (dateStr.substr(strInd,3).search(monPat) != -1) {
          intMonth=lowerMonArr[dateStr.substr(strInd,3).toLowerCase()];
        } else {
          // Bad month, return error.
          switch (tokArr[tokInd].token) {
            case 'mon_strict': caseStat="lower-case"; break;
            case 'Mon': caseStat="mixed-case"; break;
            case 'MON': caseStat="upper-case"; break;
            case 'mon': caseStat="between Jan and Dec"; break;
          }
          return "Bad month \"" + dateStr.substr(strInd,3) + "\". Must be " + caseStat + ".";
        }
        strOffset=3;
        break;
    
      case 'month':
      case 'Month':
      case 'MONTH':
      case 'month_strict':
      
        // Extract a full month name at strInd from dateStr if possible.
        monPat=monthPatArr[tokArr[tokInd].token];
        matchArray=dateStr.substr(strInd).match(monPat);
        if (matchArray==null) {
          // Bad month, return error.
          return "Can't find a month beginning at \"" + dateStr.substr(strInd) + "\".";
        }
        
        // It's a good month.
        intMonth=lowerMonArr[matchArray[0].substr(0,3).toLowerCase()];
        strOffset=matchArray[0].length;
        break;
    
      case 'ampm':
      case 'AMPM':
        matchArr=dateStr.substr(strInd).match(/^(am|pm|AM|PM|a\.m\.|p\.m\.|A\.M\.|P\.M\.)/);
        if (matchArr==null) {
          // There's no am/pm in the string.Return error msg.
          return "Missing am/pm designation.";
        }
      
        // Store am/pm value for later (as just am or pm, to make things
        // easier later).
        
        if (matchArr[0].substr(0,1).toLowerCase() == "a") {
          // This is am.
          ampm = "am";
        } else {
          ampm = "pm";
        }
        strOffset = matchArr[0].length;
        break;
    } //end of switch

    strInd += strOffset;
    tokInd++;
    
  }
  
  if (tokInd != tokArr.length || strInd != dateStr.length) {
    /* We got through the whole date string or format string, but there's 
     more data in the other, so there's a mismatch. */
    return "\"" + dateStr + "\" is either missing desired information or has more information than the expected format: " + formatStr;
  }
  
  // Make sure all components are in the right ranges.
  if (intMonth < 1 || intMonth > 12) {
    return "Month must be between 1 and 12.";
  }
  if (intDay < 1 || intDay > 31) {
    return "Day must be between 1 and 31.";
  }
  
  // Make sure user doesn't put 31 for a month that only has 30 days
  if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay == 31) {
    return "Month "+intMonth+" doesn't have 31 days!";
  }
  
  // Check for February date validity (including leap years) 
  if (intMonth == 2) {
    // figure out if "year" is a leap year; don't forget that
    // century years are only leap years if divisible by 400
    var isleap=(intYear%4==0 && (intYear%100!=0 || intYear%400==0));
    if (intDay > 29 || (intDay == 29 && !isleap)) {
      return "February " + intYear + " doesn't have " + intDay + " days!";
    }
  }
  
  // Check that if am/pm is not provided, hours are between 0 and 23.
  if (ampm == "") {
    if (intHour < 0 || intHour > 23) {
      return "Hour must be between 0 and 23 for military time.";
    }
  } else {
  // non-military time, so make sure it's between 1 and 12.
    if (intHour < 1|| intHour > 12) {
      return "Hour must be between 1 and 12 for standard time.";
    }
  }
  
  // If user specified amor pm, convert intHour to military.
  if (ampm=="am" && intHour==12) {
    intHour=0;
  }
  if (ampm=="pm" && intHour < 12) {
    intHour += 12;
  }
  if (intMin < 0 || intMin > 59) {
    return "Minute must be between 0 and 59.";
  }
  if (intSec < 0 || intSec > 59) {
    return "Second must be between 0 and 59.";
  }
  return new Date(intYear,intMonth-1,intDay,intHour,intMin,intSec);

} //end of the function

function dateCheck(dateStr,formatStr) {
  var myObj = buildDate(dateStr,formatStr);
  if (typeof myObj == "object") {
    // We got a Date object, so good.
    return true;
  } else {
    // We got an error string.
    alert(myObj);
    return false;
  }
}

   function getTime() {
      // initialize time-related variables with current time settings
      var now    = new Date();
    	var hour   = now.getHours();
    	var minute = now.getMinutes();
    	now = null;
    	var ampm = "";
    
      // validate hour values and set value of ampm
    	if (hour >= 12) {
    		hour -= 12;
    		ampm = "PM";
    	} else
    		ampm = "AM";
    	hour = (hour == 0) ? 12 : hour;
    
    // add zero digit to a one digit minute
    	if (minute < 10)
    		minute = "0" + minute; // do not parse this number!
    
    // return time string
    	return hour + ":" + minute + " " + ampm;
    }
    
    function leapYear(year) {
    	if (year % 4 == 0) // basic rule
    		return true;	// is leap year
    /* else */ 
    	return false; // is not leap year
    }
    
    function getDays(month, year) {
      // create array to hold number of days in each month
    	var ar = new Array(12);
    	ar[0] = 31; // January
    	ar[1] = (leapYear(year)) ? 29 : 28; // February
    	ar[2] = 31; // March
    	ar[3] = 30; // April
    	ar[4] = 31; // May
    	ar[5] = 30; // June
    	ar[6] = 31; // July
    	ar[7] = 31; // August
    	ar[8] = 30; // September
    	ar[9] = 31; // October
    	ar[10] = 30;	// November
    	ar[11] = 31;	// December
    
    // return number of days in the specified month (parameter)
    	return ar[month];
    }
            
    function getMonthName(month) {
    // create array to hold name of each month
    	var ar = new Array(12);
    	ar[0] = "January";
    	ar[1] = "February";
    	ar[2] = "March";
    	ar[3] = "April";
    	ar[4] = "May";
    	ar[5] = "June";
    	ar[6] = "July";
    	ar[7] = "August";
    	ar[8] = "September";
    	ar[9] = "October";
    	ar[10] = "November";
    	ar[11] = "December";
    
    // return name of specified month (parameter)
    	return ar[month];
    }


function goSubmit(target) {
   setPointer();  
   var form = document.MainForm;
   form.action=target;
   return true;
}

//
//    LSS LM (owner) UI functions
//

// Used by input object that will submit the form themselves if true is returned. 
// Optional ability to indicate the Pipeline logic should route to next page in UI workflow. 
// goToNextVal parameter should be "true", "false" or not used (same as false). 
function goSubmit(target,goToNextVal) {
   setPointer();  
   var form = document.MainForm;
   form.action=target;
   if (goToNextVal != null && goToNextVal != "") {
      form.GoToNextPipeline.value=goToNextVal;
   }
   return true;
}

// Variation of above function with 3rd parm to indicate to route to checkout page after save. 
function goSubmit(target,goToNextVal,goToPaymentVal) {
   setPointer();  
   var form = document.MainForm;
   form.action=target;
   if (goToNextVal != null && goToNextVal != "") {
     form.GoToNextPipeline.value=goToNextVal;
   }
   if (goToPaymentVal != null && goToPaymentVal != "") {
     form.GoToPaymentPipeline.value=goToPaymentVal;
   }
   return true;
}


// For use when desired to return to previous pipeline 
// sets required hidden var called GoToPrevPipeline to true
function goSubmitPrev(target) {
     var form = document.MainForm;
     setPointer();
     form.GoToPrevPipeline.value="true";
     form.action=target;
     return true;
}

// For use on RoomAmenities and General Amenities pages, to do edit before submit
function goSubmitAmenities(target,goToNextVal) {
     setPointer();
     var form = document.MainForm;
     if (updateAmenitys() == false){
         resetAutoCursor();
         return false;
     }
     form.action=target;
     if (goToNextVal != null && goToNextVal != "") {
         form.GoToNextPipeline.value=goToNextVal;
     }
     return true;
}


// For use on RoomAmenities page, to do edit before submit
function goSubmitPrevRoomAmenities(target) {
   setPointer();
   var form = document.MainForm;
   if (updateAmenitys() == false){
       resetAutoCursor();
       return false;
   }
   form.GoToNextPipeline.value="";
   form.GoToPrevPipeline.value="true";
   form.action=target;
   return true;
}

// For use on General Attractions pages, to do edit before submit
function goSubmitAttractions(target,goToNextVal) {
     setPointer();
     var form = document.MainForm;
     if (updateAttractions() == false){
        resetAutoCursor(); 
        return false;
     }
     form.action=target;
     if (goToNextVal != null && goToNextVal != "") {
         form.GoToNextPipeline.value=goToNextVal;
     }
     return true;
}

function SaveContactSubmit(url,goToNextVal) {
   var form = document.MainForm;
   if (checkEmailAddress(form.Email.value)){
      form.action=url;
   } else {
      alert("The primary Email address you entered is not valid!");
      return false;
   }
   if (form.AltEmail.value == "" || checkEmailAddress(form.AltEmail.value)){
      form.action=url;
   } else {
      alert("The Alternate Email address you entered is not valid!");
      return false;
   }
   setPointer();  
   if (goToNextVal != null && goToNextVal != "") {
      form.GoToNextPipeline.value=goToNextVal;
   }
   return true;
}



function countryChangedLM2() {
   var form = document.MainForm;
   // frmState may not exist, clear it if it does
   if (typeof(form.StateProvinceID) == "undefined") {
   } else {
      form.StateProvinceID.value="";
   }
   // frmState may not exist, clear it if it does
   if (typeof(form.LocalRegionID) == "undefined") {
   } else {
      form.LocalRegionID.value="";
   }
   setPointer();
   form.CityID.value="";
   form.CountryText.value=form.CountryID.options[form.CountryID.selectedIndex].text;
   form.StateText.value="";
   form.CityText.value="";
   form.submit();
}
function stateChangedLM2() {
   var form = document.MainForm;
   setPointer();
   form.CityID.value="";
   form.StateText.value=form.StateProvinceID.options[form.StateProvinceID.selectedIndex].text;
   form.CountryText.value=form.CountryID.options[form.CountryID.selectedIndex].text;
   form.CityText.value="";
   form.submit();
}
function localRegionChangedLM2() {
   var form = document.MainForm;
   setPointer();
   form.CityID.value="";
   form.StateText.value=form.LocalRegionID.options[form.LocalRegionID.selectedIndex].text;
   form.CountryText.value=form.CountryID.options[form.CountryID.selectedIndex].text;
   form.CityText.value="";
   form.submit();
}

function cityChangedLM2() {
   var form = document.MainForm;
   form.CityText.value=form.CityID.options[form.CityID.selectedIndex].text;
   form.StateText.value=form.StateProvinceID.options[form.StateProvinceID.selectedIndex].text;
   form.CountryText.value=form.CountryID.options[form.CountryID.selectedIndex].text;
   return false;//don't submit on city change
}
function doListingFormOnLoad(){
      document.MainForm.UnitName.focus();
   // Populate geographic text selections from lists
   var form = document.MainForm;
   if (form.CountryText.value == ""){
      form.CountryText.value=form.CountryID.options[form.CountryID.selectedIndex].text;
   }
   if (form.StateText.value == ""){
      if (form.StateProvinceID != null && form.StateProvinceID.length > 0){
         form.StateText.value=form.StateProvinceID.options[form.StateProvinceID.selectedIndex].text;
      }
   }
   if (form.CityText.value == "") {
      if(form.CityID != null && form.CityID.length > 0){
         form.CityText.value=form.CityID.options[form.CityID.selectedIndex].text;
      }
   }
}   

function goPayOnline2(target) {
   var form = document.MainForm;
   form.action=target;
   if (checkEmailAddress(form.frmEmailAddress.value)){
      setPointer();
      // Hide the submit button so they can't hit it twice 	  
      if (ns4) {
          document.SubmitDiv.style.visibility="hide";  
      }
      if (ie4 || upLevel) {
          var splash = document.getElementById("SubmitDiv");
          splash.style.visibility="hidden";  
      }
      return true;
   } else {
      alert("The email address you entered is not valid!");
      return false;
   }				
   return true;
}
function decline(){
   alert("Sorry, we cannot process your order if you do not accept the terms and conditions.");
   return false;
}
function cardTypeChanged() {
   // reload page as CSC code is dependent on card type
   var form = document.MainForm;
   setPointer();
   form.submit();
}

function goPayOther2(target) {
   var form = document.MainForm;
   form.action=target;
   if (checkEmailAddress(form.frmEmailAddress.value)){
      setPointer();
      // Hide the submit button so they can't hit it twice 	  
      if (ns4) {
          document.SubmitDiv.style.visibility="hide";  
      }
      if (ie4 || upLevel) {
          var splash = document.getElementById("SubmitDiv");
          splash.style.visibility="hidden";  
      }
      return true;
   } else {
      alert("The email address you entered is not valid!");
      return false;
   }				
   return true;
}


// Need to unset ListingID when adding to total so same item 
// won't appear selected to be added to total again
function addToTotal(target) {
     var form = document.MainForm;
     setPointer();
     form.action=target;
     return true;//To submit the form
}
function removeFromTotal(target) {
     var form = document.MainForm;
      setPointer();     
     form.action=target;
     return true;
}

function selectListingSubscription(listingSubscriptionID,listingID) {
   var form = document.MainForm;
   setPointer(); 
   form.ListingID.value=listingID;   
   form.ListingSubscriptionID.value=listingSubscriptionID;
   if ( ! (typeof(form.ListingIDSelected) == "undefined")) {
      // Unselect all radio button choices from the Unpaid List
      for (counter = 0; counter < form.ListingIDSelected.length; counter++){
         form.ListingIDSelected[counter].checked = false; 
      }
      // Unselect for case when only 1 element
      form.ListingIDSelected.checked = false;
   }
   form.ListingSubscriptionSubmit.click();
}

function selectListing3(id) {
   var form = document.MainForm;
   setPointer();     
   form.ListingID.value=id;
   form.ListingSubscriptionID.value="";
   if ( ! (typeof(form.ListingSubscriptionIDSelected) == "undefined")) {
		// Unselect all radio button choices from the Paid List
		for (counter = 0; counter < form.ListingSubscriptionIDSelected.length; counter++){
	    	form.ListingSubscriptionIDSelected[counter].checked = false; 
      	}
		// Unselect for case when only 1 element
		form.ListingSubscriptionIDSelected.checked = false;
	}	    
   form.ListingSubmit.click();
}
function hideAddToTotal(){
   // Hide step 2 after submit of Add To Total Button
   // So user can't add same item multiple times. 
    if (ns4) {
        document.step2Submit.style.visibility="hide";  
    }
    if (ie4 || upLevel) {
        var splash = document.getElementById("step2Submit");
        splash.style.visibility="hidden";  
    }
}
function disablePaymentMethod(){
      if (ns4) {
          document.payment_section.style.visibility="hide";  
      }
      if (ie4 || upLevel) {
          var splash = document.getElementById("payment_section");
          splash.style.visibility="hidden";  
      }
}

function hideSubmitDiv(){
   // Hide step 2 after submit of Add To Total Button
   // So user can't add same item multiple times. 
    if (ns4) {
        document.SubmitDiv.style.visibility="hide";  
    }
    if (ie4 || upLevel) {
        var splash = document.getElementById("SubmitDiv");
        splash.style.visibility="hidden";  
    }
}


/**
  * Common Javascript code for attraction add/update management pages at any level 
  * Provides functions to select/unselect items as well as                        
  * editing form fields before submitting.                                        
  *
  * Loop through the amenity items on the page to determine
  * which were selected.  Edit Quantities for valid data.
  * Pass control to the target Pipeline and Start node identified
  * by the "actionTarget" input parameter. 
  *
  */

  function updateAmenitys() {
      var form = document.MainForm;
      var amenityElement    = form.Amenity;
      var amenityQtyElement = form.AmenityQty;
      var amenitys = ' ';
      var amenityQtys = ' ';
      for (var i=0; i < amenityElement.length; i++) {
          if ( amenityElement[i].checked ) {
                   
          var qtyField    = amenityQtyElement[i].value;
          if (qtyField == "" || !isPositiveNumber(qtyField) || parseInt(qtyField) == 0 || hasDecimal(qtyField)) {
              alert("Quantity Values must be numeric integers (no decimal), and greater than zero!"); 
              form.elements.AmenityQty[i].focus();
              return false;
          }
                              
           if ( amenitys == ' ' ) {
              amenitys    = amenityElement[i].value;
              amenityQtys = amenityQtyElement[i].value;
           }
           else {
              amenitys = amenitys + '^' + amenityElement[i].value;
              amenityQtys = amenityQtys +'^'+amenityQtyElement[i].value;
           }
        }
      }
      form.AmenityStr.value =  amenitys;
      form.AmenityQtyStr.value =  amenityQtys;
      // set on calling form //form.action = "#URL(action('lm_ViewListingAmenities-Update'))#";
      return true;
  }
  
  /**
   * Unselect all amenity item checkboxes and set quantities to default of 1.
   */      
  function unselectAllAmenitys() {
      var form = document.MainForm;
      var amenityElement    = form.Amenity;
      var amenityQtyElement = form.AmenityQty;
      for (var i=0; i < amenityElement.length; i++) {
          amenityElement[i].checked=false;
          amenityQtyElement[i].value=1;
      }
      return false;//don't submit form
  }
  /**
   * Select all amenity item checkboxes, don't change quantities.
   */      
  function selectAllAmenitys() {
      var form = document.MainForm;
      var amenityElement    = form.Amenity;
      var amenityQtyElement = form.AmenityQty;
      for (var i=0; i < amenityElement.length; i++) {
          amenityElement[i].checked=true;
      }
      return false;//don't submit form
  }

 /**
  * Common Javascript code for attraction add/update management pages at any level 
  * Provides functions to select/unselect items as well as                        
  * editing form fields before submitting.                                        
  *
  * Loop through the attraction items on the page to determine
  * which were selected.  Edit distances and units of measure 
  * for valid data.
  * Pass control to the target Pipeline and Start node identified
  * by the "actionTarget" input parameter. 
  *
  */
  function updateAttractions() {
      var form = document.MainForm;
      var attractionElement    = form.Attraction;
      var attractionDistanceElement = form.AttractionDistance;
      var distanceUomElement = form.DistanceUomMasterId;
      var attractions = ' ';
      var attractionDistances = ' ';
      var distanceUoms = ' ';

      for (var i=0; i < attractionElement.length; i++) {
          if ( attractionElement[i].checked ) {
              // If an attraction item is checked, 
              // we edit the entered distance and distanceUOM fields,
              //    1)  distance must be null or a valid positive non-zero float
              //    2)  distanceUOM must be valid value if distance is not null
              var distanceField    = form.AttractionDistance[i].value;
              var distanceUomField = form.DistanceUomMasterId[i].value;
              
              if (distanceField != "") {
                  if (!isPositiveNumber(distanceField) || parseFloat(distanceField) == 0) {
                      alert("Distance Values must be numeric and greater than zero, or left blank!"); 
                      form.elements.AttractionDistance[i].focus();
                      return false;
                  }
                  // Ok we now know that distanceField is a valid number, 
                  // So we also expect a valid DistanceUOMMasterId
                  // "NA" is the DistanceUOMMasterId for the "None" label
                  if (distanceUomField == "NA") {
                      alert("Distance Unit of Measure other than 'None' must be set if Distance is entered!"); 
                      form.DistanceUomMasterId[i].focus();
                      return false;
                  }
                  // String append selected items and their distances
                  if ( attractions == ' ' ) {
                      attractions    = attractionElement[i].value;
                      attractionDistances = attractionDistanceElement[i].value;
                      distanceUoms = distanceUomElement[i].value;
                  }
                  else {
                      attractions = attractions + '^' + attractionElement[i].value;
                      attractionDistances = attractionDistances +'^'+attractionDistanceElement[i].value;
                      distanceUoms = distanceUoms + '^' + distanceUomElement[i].value;
                  }
              } else {
                  // the item is checked and the distance field is 
                  // blank, set it to null for the database update
                  if ( attractions == ' ' ) {
                      attractions    = attractionElement[i].value;
                      attractionDistances = "NA";
                      distanceUoms = "NA"
                  }
                  else {
                      attractions = attractions + '^' + attractionElement[i].value;
                      attractionDistances = attractionDistances +'^'+"NA";
                      distanceUoms = distanceUoms + '^' + "NA";
                  }
              }
              
          }// end if
      }// end For
      form.AttractionStr.value =  attractions;
      form.AttractionDistanceStr.value =  attractionDistances;
      form.DistanceUomStr.value =  distanceUoms;
      // set on calling form //form.action = "#URL(action('lm_ViewListingAttractions-Update'))#";
      //form.submit();
      return true;
  }
  
  /**
   * Unselect all attraction item checkboxes and null out distances
   */      
  function unselectAllAttractions() {
      var form = document.MainForm;
      var attractionElement    = form.Attraction;
      var attractionDistanceElement = form.AttractionDistance;
      var distanceUomElement = form.DistanceUomMasterId;
      
      for (var i=0; i < attractionElement.length; i++) {
          attractionElement[i].checked=false;
          attractionDistanceElement[i].value="";
          distanceUomElement[i].value="None";
          
      }
      return false;
  }
  /**
   * Select all attraction item checkboxes, don't change distances.
   */      
  function selectAllAttractions() {
      var form = document.MainForm;
      var attractionElement    = form.Attraction;
      var attractionDistanceElement = form.AttractionDistance;
      var distanceUomElement = form.DistanceUomMasterId;
      
      for (var i=0; i < attractionElement.length; i++) {
          attractionElement[i].checked=true;
      }
      return false;
  }
  function roomTypeChanged () {
     var form = document.MainForm;
       form.RoomForm_RoomLabel.value=form.RoomForm_RoomTypeID.options[form.RoomForm_RoomTypeID.selectedIndex].text;
  }
   function doOnLoadRoom(){
      resetAutoCursor();
      var form = document.MainForm;
      if (form.RoomForm_RoomLabel.value == ""){
         form.RoomForm_RoomLabel.value=form.RoomForm_RoomTypeID.options[form.RoomForm_RoomTypeID.selectedIndex].text;
      }
   }

  function confirmDeleteRoom (id,url) {
     var form = document.MainForm;
     if ( confirm('Are you sure you want to delete the Room?') ) {
        form.action = url;
        form.RoomID.value=id;
        setPointer();
        form.submit();
     }
  }

  function confirmDeleteContact (id,url) {
     var form = document.MainForm;
     if ( confirm('Deleting a Contact will remove it from ALL Listings it may be related to.  Are you sure you want to delete this Contact?') ) {
        form.action = url;
        form.ListingContactID.value=id;
        form.submit();
     }
  }
  function confirmDeleteSpecial (id,url) {
     var form = document.MainForm;
     if ( confirm('Are you sure you want to delete the Special?') ) {
        form.action = url;
        form.ListingSpecialID.value=id;
        setPointer();
        form.submit();
     }
  }

  function confirmDeleteRates (id,url) {
		var form = document.MainForm;
		if ( confirm('Are you sure you want to delete the Rate Schedule?') ) {
	  		setPointer();
	  		form.action = url;
         form.RateScheduleID.value=id;
	  		form.submit();
		}
	}

  function confirmDeleteUnitSpecial (id,url) {
       var form = document.MainForm;
       if ( confirm('Are you sure you want to delete the Special?') ) {
          form.action = url;
          form.UnitSpecialID.value=id;
          setPointer();
          form.submit();
       }
    }

   function specialTypeChangedLM(action){
      var form=document.MainForm;
      form.action=action;
      form.submit();
   }
   function  sendOwnerInquirySubmitLM() {
      alert("Not implemented in Owner Interface");
      return false;
   }





//
//    LSS Renter UI functions
//
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("dummy")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf('?'))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// Renter UI Listbox Change functions
function countryChangedSearch3() {
   setPointer();
   var form = document.SearchForm;
   form.CountryID.value=form.frmCountryID.value;
     // frmState may not exist, clear it if it does
   if (typeof(form.frmStateProvinceID) == "undefined") {
   } else {
      form.frmStateProvinceID.value="";
   }
   // frmLocalRegionID may not exist, clear it if it does
   if (typeof(form.frmLocalRegionID) == "undefined") {
   } else {
      form.frmLocalRegionID.value="";
   }
   form.StateProvinceID.value="";
   form.LocalRegionID.value="";
   form.frmCityID.value="";
   form.CityID.value="";
   form.NoOfPeople.value=form.frmNoOfPeople.value;
   form.RestoreGeographyFromSession.value="false";
   form.submit();
}
function stateChangedSearch3() {
   setPointer();
   var form = document.SearchForm;
   form.StateProvinceID.value=form.frmStateProvinceID.value;
   form.CountryID.value=form.frmCountryID.value;
   form.LocalRegionID.value="";
   form.frmCityID.value="";
   form.CityID.value="";
   form.NoOfPeople.value=form.frmNoOfPeople.value;
   form.RestoreGeographyFromSession.value="false";
   form.submit();
}

function localRegionChangedSearch3() {
   setPointer();
   var form = document.SearchForm;
   form.CountryID.value=form.frmCountryID.value;
   form.LocalRegionID.value=form.frmLocalRegionID.value;
   form.StateProvinceID.value="";
   form.frmCityID.value="";
   form.CityID.value="";
   form.NoOfPeople.value=form.frmNoOfPeople.value;
   form.RestoreGeographyFromSession.value="false";
   form.submit();
}

function cityChangedSearch3() {
   var form = document.SearchForm;
   form.CityID.value=form.frmCityID.value;
   // don't submit on city change
}

function noOfPeopleChangedSearch() {
   var form = document.SearchForm;
   form.NoOfPeople.value=form.frmNoOfPeople.value;
}

function updateGeoNav(id,type,urlStr) {
   var form = document.MainForm;
   if (type == 1){      //City Level
      form.action=urlStr;
      form.CityID.value=id;
      form.StateProvinceID.value="";
      form.CountryID.value="";			
   }
   else if (type == 2){ //StateProvince Level
      form.action=urlStr;
      form.StateProvinceID.value=id;
      form.CityID.value="";
   }
   else if (type == 3){ //LocalRegionLevel
      form.action=urlStr;
      form.LocalRegionID.value=id; 
      if ( ! (typeof(form.frmStateProvinceID) == "undefined")) {
         form.StateProvinceID.value="";
      }
      form.CityID.value="";
   }
   else if (type == 4){ //CountryLevel
      form.CountryID.value=id;//Set the same country in the Advanced Search form fields or submit will use the one from the form.
      if ( ! (typeof(form.frmStateProvinceID) == "undefined")) {
         form.StateProvinceID.value="";
      }
      form.CityID.value="";
      form.action=urlStr;
   } else {    // Bad level for this page
               //	alert("updateGeoNav BAD LEVEL = "+id+"/"+type);
      return false;
   }
   setPointer();
   form.submit();
   return false;
}

function searchSubmit4(action) {
   var form = document.SearchForm;
   var cityID = form.frmCityID.value;
   var noOfPeople = form.frmNoOfPeople.value;
   form.CityID.value=form.frmCityID.value;
   form.NoOfPeople.value=form.frmNoOfPeople.value;
   if ( ! (typeof(form.frmStateProvinceID) == "undefined")) {
     form.StateProvinceID.value=form.frmStateProvinceID.value;
   }
   if ( ! (typeof(form.frmLocalRegionID) == "undefined")) {
     form.LocalRegionID.value=form.frmLocalRegionID.value;
   }
   form.CountryID.value=form.frmCountryID.value;
   
   // Validate check in date
   var formatStr = "%m-%d-%yyyy";
   //Validating check in date    
   var inDateStr = form.frmCheckInMonth.options[form.frmCheckInMonth.options.selectedIndex].value
              + "-" + 
              form.frmCheckInDay.options[form.frmCheckInDay.options.selectedIndex].value
              + "-" + 
              form.frmCheckInYear.options[form.frmCheckInYear.options.selectedIndex].value;
   var inDate = buildDate(inDateStr, formatStr);
   if (!(typeof(inDate) == "object")) {
      // We got an error string.
      alert(inDate);
      return false;
   }
   //Validating check out date
   var outDateStr = form.frmCheckOutMonth.options[form.frmCheckOutMonth.options.selectedIndex].value
                 + "-" + 
                 form.frmCheckOutDay.options[form.frmCheckOutDay.options.selectedIndex].value
                 + "-" + 
                 form.frmCheckOutYear.options[form.frmCheckOutYear.options.selectedIndex].value;
   var outDate = buildDate(outDateStr, formatStr);
   if (!(typeof(outDate) == "object")) {
      // We got an error string.
      alert(outDate);
      return false;
   }
   //Check if the in- date is before out- date
   if (inDate > outDate) {
      alert("Check-In Date cannot be after Check-Out Date");
      return false;
   }
   // Get today's date
   var today = new Date() ;
   // Only way I could figure out to set the same milliseconds component 
   // of time for comparison of dates with today.  To fix bug where the 
   // user could not select today as the check-in date.
   var todaycompare = new Date(inDate.getTime());
   todaycompare.setDate(today.getDate());
   todaycompare.setMonth(today.getMonth());
   todaycompare.setYear(today.getYear());
   //Check if the in- date is after today
   //if (inDate < new Date()) {
   if (inDate.getTime() < todaycompare.getTime()) {
      alert("Check-In Date cannot be before today.");
      return false;
   }
   //Check if the in- date and out- date is same
   if (inDate.getTime() == outDate.getTime()) {
      alert("Check-In Date and Check-Out Date cannot be the same.");
      return false;
   }
   setPointer();
   // If a ListingID was entered, try to go directly to it, 
   // otherwise do advanced search by city and other criteria
   if (form.SearchListingID.value != ""){
      form.action="/listings/listing/"+form.SearchListingID.value+".html";
      form.ListingID.value=form.SearchListingID.value;
   } else {
      form.action=action+"?CityID="+cityID+"&NoOfPeople="+noOfPeople;
   }
   form.submit();
   return false;// form already submitted here to avoid conflicts with other forms on page
}

function newsLetterSubmit(action) {
   var form = document.MainForm;
   var email = form.newsLetterSubscriptionEmail.value;
   if (checkEmailAddress(email)){
      form.action=action;
      var cityID = form.frmCityID.value;
      var noOfPeople = form.frmNoOfPeople.value;
      form.CityID.value=form.frmCityID.value;
        form.NoOfPeople.value=form.frmNoOfPeople.value;
      if ( ! (typeof(form.frmStateProvinceID) == "undefined")) {
           form.StateProvinceID.value=form.frmStateProvinceID.value;
      }
      form.CountryID.value=form.frmCountryID.value;
      setPointer();
      return true;
   } else {
      alert("The email address you entered is not valid!");
      return false;
   }
}
// Used to submit forms using enter key while in form element
// such as text control.  
// Executes click() event of the input element of 
// the input form
function submitOnEnter(form, elemName, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        form.elements[elemName].click();
    }
    return true;
}

function changePage(url,pageNo) {
   var form = document.MainForm;
   form.ListingUnitSearchResultsGetPage.value = pageNo;
   //form.action="#URL(action('rtr_ViewSearchHome-SearchResultsPage'))#";
   form.action=url;
   setPointer();
   form.submit();
   return false;
}

function changePage2(url,pageNo, linkObj) {
   var form = document.MainForm;
   form.ListingUnitSearchResultsGetPage.value = pageNo;
   //form.action="#URL(action('rtr_ViewSearchHome-SearchResultsPage'))#";
   form.action=url;
   setPointer();
   if (linkObj != null){
       linkObj.href="#";
   }
   form.submit();
   return false;
}

function changePageAdminPaymentSearch(url,pageNo) {
   var form = document.MainForm;
   form.AdmPaymentSearchResultsGetPage.value = pageNo;
   form.action=url;
   setPointer();
   form.submit();
   return false;
}
function changePageAdminListingSearch(url,pageNo) {
   var form = document.MainForm;
   form.AdmListingSearchResultsGetPage.value = pageNo;
   form.action=url;
   setPointer();
   form.submit();
   return false;
}

function availabilitySubmit(url,unitID) {
    var form = document.MainForm;
    //form.action="#URL(action('rtr_ViewListingDetails-Availability'))#?UnitID="+unitID;
    form.action=url+"?UnitID="+unitID;
    setPointer();
    form.submit();
    return false; //used from both form input and <a href> tags so we need to submit form
}  

function sendOwnerInquirySubmit(url) {
	var form = document.MainForm;
	if (checkEmailAddress(form.frmEmailAddress.value)){
		form.action=url;
		return true;
	} else {
		alert("The email address you entered is not valid!");
		return false;
	}
}

function LMRegisterSubmit(url) {
	var form = document.MainForm;
	if (checkEmailAddress(form.Email.value)){
		form.action=url;
		return true;
	} else {
		alert("The email address you entered is not valid!");
		return false;
	}
}
// *** WARNING - IF YOU CHANGE THIS FILE YOU MUST ALSO RENAME IT AS IE AND OTHER BROWSERS CACHE OLDER VERSIONS  ***
// BELOW IS CODE FOR PAGES FROM ANIL
/******************************************************************************
* functions.js								      *
*                                                                             *
* Copyright 2006 by vikarta.com				      *
* Visit http://www.vikarta.com					      *
*                                                                             *
* Provides functions for the website which will work on both Netscape	      *
* Communicator and Internet Explorer browsers (version 5.5 and up).  	      *
*									      *
******************************************************************************/

//-----------------------------------------------------------------------------
// Date Script
//-----------------------------------------------------------------------------

function current_date()
{
var day=new Array();
day[0]="Sunday";day[1]="Monday";day[2]="Tuesday";day[3]="Wednesday";day[4]="Thursday";day[5]="Friday";day[6]="Saturday";
var months=new Array(13);
months[0]="January";
months[1]="February";
months[2]="March";
months[3]="April";
months[4]="May";
months[5]="June";
months[6]="July";
months[7]="August";
months[8]="September";
months[9]="October";
months[10]="November";
months[11]="December";
var time=new Date();
var lmonth=months[time.getMonth()];
var tday=day[time.getDay()];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write("<font color='#FFFFFF' face='Verdana, Arial, Helvetica, sans-serif' font-size=10px> <b>"+tday+",&nbsp; "+lmonth+" "+date+",&nbsp; "+year+"</font> </b>");
}

//-----------------------------------------------------------------------------
// VacationRental Newsletter
//-----------------------------------------------------------------------------
function top10Deals()
{
 if (window.document.newsletter.name.value =="") 
 {
 alert("Please make sure Name is not left blank");
 window.document.newsletter.name.focus();
 return (false);
 }
 if (window.document.newsletter.from.value.indexOf('.')=="-1" || window.document.newsletter.from.value.indexOf('@')=="-1") 
 {
 alert("Please enter your Email properly!");
 window.document.newsletter.from.focus();
 return (false);
 }
 return true
}

//-----------------------------------------------------------------------------
// Email,Print and Bookmark
//-----------------------------------------------------------------------------


var selectedFeature = 1;

var printWin;
var fdIndex = 1;
var hIndex = 1;
var curMap = "hotel";

function selectFeature(id)
{
	if (id != selectedFeature)
	{
		document.getElementById("feature"+selectedFeature).className = "";
		document.getElementById("featureLink"+selectedFeature).className = "";
		document.getElementById("feature"+id).className = "selected";
		document.getElementById("featureLink"+id).className = "selected";
		selectedFeature = id;
		document.getElementById("featureContent").scrollTop = 0;
	}
}

function sendToFriend(cityName)
{
	var link = "http://" + window.location.host + window.location.pathname;
	var queryParams = window.location.search.substring(1).split("&");

	if (window.location.search != "")
	{	
		if (queryParams.length > 0)
			link += "?";
			
		for (var i=0; i<queryParams.length; i++){
			if (queryParams[i].indexOf("emlcid") == -1 && queryParams[i].indexOf("fname") == -1){
				if (i > 0) 
					link += "&";
			}
			link += queryParams[i];
		}
	}
	
	var subj = ""
	if (cityName == "")
	{
		subj = "Check out AlwaysOnVacaiton Destinattion Guides";
	}
	else
	{
		subj = "Check out the Destinattion Guides to " +  cityName;
	}
	window.location = "mailto:?subject=" + subj + "&body=" + escape(link);
}

function bookmarkPage()
{
	var url = window.location.href;
	var title = document.title;
	
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else
		alert("Your browser doesn't support automatic bookmarking. Please use your browser's Bookmarks menu to bookmark this site.");
}

function printPage()
{
	var url = document.location.href + "&print=1&fdindex=" + fdIndex + "&hindex=" + hIndex + "&map=" + curMap;
	printWin = window.open(url, "printWin", "width=697,height=500,resizable=1,scrollbars=1");
	printWin.focus();
}

function popup(url, width, height, params){
	var winWidth = (width != null) ? width : 685;
	var winHeight = (height != null) ? height : 650;
	var winParams = "width=" + winWidth + ",height=" + winHeight;
	if (params != null){
		winParams += "," + params;
	} else {
		winParams += ",scrollbars=no";
	}
	
	var newWin = window.open(url, "expPop", winParams);
	newWin.focus();
}

function win_open(href, width, height)
{
	if (width == '' && height == '')  
	{
		window.open(href, '_blank', 'toolbar=no,location=no,status=yes,menubar=no,personalbar=no,scrollbars=yes,resizable=yes,screenx=50,left=50,screenY=50,top=50');
	} 
	else
	{
		window.open(href, '_blank', 'toolbar=no,location=no,status=yes,menubar=no,personalbar=no,scrollbars=yes,width=' + width + ',height=' + height + ',resizable=yes,screenx=50,left=50,screenY=50,top=50')
	}
}

function openPage(href) {
	if(href!=""){
		window.open(href, '_blank', 'width="800",height="600",toolbar=yes,location=yes,status=yes,menubar=yes,personalbar=yes,scrollbars=yes,resizable=yes,screenx=50,left=50,screenY=50,top=50');
	}
}

function openFullPage(href) {
	if(href!=""){
		var wOptions = "toolbar=yes,location=yes,status=yes,menubar=yes,personalbar=yes," +
			"scrollbars=yes,resizable=yes,outerHeight=" + screen.availHeight + ",outerWidth=" +
			screen.availWidth + ",screenX=0,screenY=0,height=" + screen.availHeight + ",width=" +
			screen.availWidth + ",left=0,top=0";
		window.open(href, '_blank', wOptions);
	}
}


// *** WARNING - IF YOU CHANGE THIS FILE YOU MUST ALSO RENAME IT AS IE AND OTHER BROWSERS CACHE OLDER VERSIONS  ***

