 

/*---------------------------------------------------------------------------------------------------------
 Yardi Common JavaScript Library
 Copyright 1999-2000 (c) Yardi Systems, Inc.

[1] MaskAcct - formats text with the acct mask (i.e. 4500 -> 4500-0000)
[2] Find - find an element in a list
[3] Error - displays an error
[4] Empty - checks if string is empty
[5] ValidLength - checks is string is of a valid length
[6] ValidInt - checks if number is a valid integer
[7] ValidCurrency - checks if number is a valid currency
[8] ValidateDate - checks if object is valid date
[9] ValidPhone - checks if string is valid phone number
[12] ValidMinMax - checks if number is between two values
[13] ValidYesNo - checks if string is = yes or no
[14] WriteMenu - generalized menu writing function
[15] Nav0 - Specifies submit action depending on type of form
[16] GotChange - set bDataChanged = true
[20] MenuWindow - Create a test window
[21] SetCookie - Sets a cookie
[22] GetCookie - Returns a cookie
[23] Find2 - find text in a listbox after the '-'
[25] GetAppName - This function gets the name of the directory imediatly above the current htm file.
[26] UpdateHeader - accumulates amount in target with amount from source - peculiar to batches and movein.
[27] listWindow - puts a list of objects(tenant, prop, etc) in a seperate window
[28] PromptAmount - on double click of amount paid box, puts in amount from amount owed box - peculiar to batches.
[29] EditWindow - puts data from batch receipt screen into a new window for editing - peculiar to batches.
[30] FormatNumber - formats a number with the mask (i.e. 100 -> 100.00)
[31] NonBlank - input box may not be blank
[32] parseNum - strips commas out, executes parseFloat
[33] gotFocus - no op for now
[34] QueryIf - container for call on QueryIf2; for navigation purposes
[35] FT_FinalTest - checks for mandatory fields on sys generated filters
[36] Hand / Help - Changes cursor to a Hand or ? when table cell or image is moused over.
[37] Help for filter screen
[38] OPT_Update - updates boxes on Options screen
[39] SayStates - says the option statements for a state <SELECT
[40] ValidMintMaxt - checks if number is a valid integer & checks if number is between two values MDM000330
[41] MoveIt - moves elements from one list box to an other
[42] CompressIt - Takes out blank elements from a list box
[43] QueryIf2 - this procedure should be in all forms for which you want
                the user to be prompted if they want to save a form
                the one in here is to prevent errors when the current form
                (for what ever reason) doesn't have a QueryIf2
[44] SetFocusOnFirstField - Sets focus(cursor) on the first field of the form (if that field exists)
[45] FormatNumber2 - truncates extra digits from numbers
[46] Round - rounds numbers to 2 digits.
[47] bDelete - Ask the confirmation for delete
[48] Trims spaces before and after string. Usage just as in VB: trim(var.value), 
[49] FormatPhoneNum - guess
[50] PageBreak - printer page break
[51] GetToken - Get the specified param (sToken) from string (sURL)
[52] MaxDay - returns max day for given month/year
[53] PromptEndDate - given date and term, return end date (for leases)
[54] ValidateTime - validates time in hh:mm format
[55] CurrentDate - returns string of current date
[56] CurrentTime - returns string of current time
[57] DateAfter - checks if date1 is after date2
[58] QueryString1 - search for a specific name on the Query or Hash strings of the page's URL and return the value.
[59] OpenWindow2 - called by OpenWindow
[60] OpenWindow - opens a new window, used by form like resident/lease charges
[61] GetStyleSheet - gets the stylesheet name from the cookie and writes a string that includes the name.
[62] Filter - shows filter for object that's on screen, if appropriate
[63] ActiveMenu - Menubar uses this script to check if data on a present form has changed before redirecting.
[64] ExitForm - Checks to make sure to save if data has changed.
[65] TabTo - Forms with tabs use this to navigate
[66] ValidFloat - Similar to ValidCurrency, but no restriction on the number of digits to the right of the decimal.
[67] userList - call ysilist with a 'select' and optional property code and/or optional account code
[68] unMaskAcct = strip '-' or '.' out of account field for passing account code to userlist
[69] Get_Real_Asp_Name = returns ASP name for given iType, for filter button purposes
-----------------------------------------------------------------------------------------------------------*/

//[1]
function MaskAcct(obj, acctlen, acctmask, seperator)
{
  /*obj is text box.  obj might have a .isRequired property
  acctlen is length of acct mask not including seperators
  acctmask is the mask (i.e. ????-????)
  seperator is a '-'  or a '.'
  acct masks can have a '-' or a '.' as seperators, but not both
  and may have multiple seperators or no seperators*/


  var sout = "";        // output value
  var idashloc = 0;
  var ss = new String(obj.value);   //converts object to string
  var ilen = ss.length;
  var iSepCount = 0;
  var sTemp = "";


  // check for required field
  if( typeof(obj.isRequired) == "undefined")
    {obj.isRequired = false;} // default not required

  if (ss == "") {
    if (obj.isRequired) {return error(obj, 'Acct number required')}
          }
  if (ss == "") { return true; }

  //remove seperators from input
  for (i = 0; i <= acctlen; i++) {
      idashloc = ss.indexOf(seperator);
      if (idashloc <= 0) { break;  }
      ss = ss.substring(0, idashloc) + ss.substring(idashloc + 1, ss.length);
  }

  //count number of seperators in acctmask
  sTemp = acctmask
  for (i = 0; i <= acctlen; i++) {
      idashloc = sTemp.indexOf(seperator)
      if (idashloc <= 0) {break;}
      sTemp = sTemp.substring(idashloc + 1, sTemp.length)
      iSepCount = iSepCount + 1
  }

  //add zeros to input if input.length <> acctlen
  if (ss.length != acctlen.length) {
    for (i = ss.length; i < acctlen; i++) {
      ss = ss + "0";
    }
  }

  //now, mask it
  i = 0
  idashloc = 0
  while(i < iSepCount) {
    idashloc = idashloc + acctmask.indexOf(seperator)
    if (idashloc <= 0) { break; }
    acctmask = acctmask.substring(idashloc + 1, acctmask.length)
    ss = ss.substring(0, idashloc + i) + seperator + ss.substring(idashloc + i, ss.length + 1);
    i += 1
     }


  obj.value = ss;

  return true;
}

//[2]
// Find an element in the list
// Arguments: 1) the select list, 2) the textbox
function Find(list, text)
{

  // find the first matching
  if( text.value.length > 0){
    for( var i = 0; i < list.length; i++){
      if( list.item(i).text.substr(0,text.value.length).toUpperCase() == text.value.toUpperCase()){
        list.options[i].selected = true;
        return true;
      }
    }
  }
  return false;
}


//[3]
function error(elem, text, bSelect) {
// display the first error
   var ss;

   if (typeof(text)  == "undefined") { window.alert("Undefined error."); this.select()}
   window.alert(text);
   if (typeof(elem)  == "undefined") {return}
   if (elem == "n"){return}
   if (elem.disabled == true) {return}
   if (bSelect != "false") {
      if (bSelect != "combo") {          
      	document.forms[0].elements[elem.name].focus();        
      }

   };
   errorfound = true;
}

//[4]
function Empty(num) {
  if ((num=="") || (num==" "))  return true;
}


//[5]
function ValidLength(item, maxlen) {
   if (Empty(num)) return true;
   return (item.Length <= maxlen);
}

//[6]
function ValidInt(num) {
    var ss = new String(num.value);   //converts object to string
  var ilen = ss.length;
  var min = 0;
  var max = 32700;

   if (Empty(num.value)) {return true;} //{error(num, "Amount may not be blank"); return false;}
   for (var i = 0; i < ilen; i++) {
       if (((ss.charAt(i) < "0") || (ss.charAt(i) > "9")) && (ss.charAt(i) != ","))
        {
          error(num, "Invalid number"); 
          return false;
        }
   }
   
   //if (!ValidMinMax(num.value, min, max)) {error(num, "Expecting number from 0 to 32700"); return false;}
   return true;
}

//[7]
function ValidCurrency(num, min, max) {
  var n="";
  var periods=0;
  var ss = new String(num.value);   //converts object to string

    min = -1000000000 ; max = 1000000000
  //if ((Empty(ss)) && (num.isRequired == "true")) {error(num, "Amount may not be blank"); return false;}
    if (Empty(ss)) {return true;}
  for (var i = 0; (i < ss.length); i++) {
     if (ss.charAt(i) == ".") {
    periods = periods + 1;
    if (periods > 1) return error(num, "Invalid number.");        // only allow one period
    if (i + 3 < ss.length) return error(num, "Invalid number.");  //only two digits after the period
            n = n + ss.charAt(i);
            continue;
           }
           if (ss.charAt(i) == " ") continue;  //getting a trailing blank
           if (ss.charAt(i) == ",") continue;
           if (ss.charAt(i) == "-") {
            if (i != 0) return false;   //only allow - sign at first char
            n = n + ss.charAt(i);
            continue;
           }
           if ((ss.charAt(i) >= "0") && (ss.charAt(i) <= "9")) {
              n = n + ss.charAt(i);
              continue;
           }
     return error(num, "Invalid number.")    //error
       }
    FormatNumber(num);
    ValidMinMax(n, min, max);
    return true;  //all ok

}


//[8]
function ValidateDate(obj)
/*  if optional property .isDay is true, input must be:
    mm/dd/yy
    mm/dd/yyyy
    m/d/yy
    m/d/yyyy
    mm/d/yy
    mm/d/yyyy
    m/dd/yy
    m/dd/yyyy
    mmddyy
    mmddyyyy
  otherwise, input must be:
    mm/yy
    mm/yyyy
    m/yy
    m/yyyy
    mmyy
    mmyyyy
  "/" is the only valid seperator
  These are the only known valid inputs. Others might work
  but don't count on it (isn't this enough?)
*/
{
  var ilen;
  var sout;
  var yy, mm, dd;
  var tmp;
  var inumsep;
  var imonth, iyear, iday;
  var serr;
  var isep1, isep2;  //holds position of "/"
  var imstart, imlen;
  var idstart, idlen;
  var iystart, iylen;
  var ss = new String(obj.value);
  var d = new Date();
  var m = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
    var window = 50;  //year cutoff when yy is passed in (i.e. 49 = 2049, 50 = 1950)

        var sGUID = GetCookie("bEuroDate");
    if (sGUID == "true") {bEuro = true}
    else                 {bEuro = false}


  ilen = ss.length;
  iday = 0;  //in case is never gets set below
  
  // check for required field

  if( typeof(obj.isRequired) == "undefined"){
    obj.isRequired = false;   // default not required
  }



  if (ilen == 0) {return true;}

  // check for .isDay
  if( typeof(obj.isDay) == "undefined"){
    obj.isDay = false;      // default to not expecting days - month & year only
                           
  }

  //set error message
  if (bEuro == false) {
    if (obj.isDay) {serr = "Expecting date in mm/dd/yyyy format."}
    else {serr = "Expecting date in mm/yyyy format."}
  }
  else {
    if (obj.isDay) {serr = "Expecting date in dd/mm/yyyy format."}
    else {serr = "Expecting date in mm/yyyy format."}

  }

  // all chars must be numeric or "/"
  inumsep = 0
  for( var i = 0; i < ilen; i++){
    tmp = ss.charAt(i);
    if (tmp == '/') {
      inumsep = inumsep + 1;
      if (inumsep == 1) {isep1 = i}
      else if (inumsep == 2) {isep2 = i}
    }
  }

  //check for valid number of "/"
  if (obj.isDay && inumsep > 2) {error(obj, serr); return false;}
  else if (!obj.isDay && inumsep > 1) {error(obj, serr); return false;}

  //check for valid placement of "/"
  if (inumsep > 0) {
    if (isep1 != 1 && isep1 != 2) {error(obj, serr); return false;}
    }
  if (inumsep > 1) {
    if (isep2 != 3 && isep2 != 4 && isep2 != 5) {error(obj, serr); return false;}
    }


  //set start and length of month, day and year
  if (inumsep == 0) {
    if (ilen == 4) {
      imstart = 0; imlen = 2;
      iystart = 2; iylen = 2;
      }
    else if (ilen == 6 && obj.isDay) {
      imstart = 0; imlen = 2;
      idstart = 2; idlen = 2;
      iystart = 4; iylen = 2;
      }
    else if (ilen == 6 && !obj.isDay) {
      imstart = 0; imlen = 2;
      iystart = 2; iylen = 4;
      }
    else if (ilen == 8) {
      imstart = 0; imlen = 2;
      idstart = 2; idlen = 2;
      iystart = 4; iylen = 4;
      }
    }
  else if (inumsep == 1) {
    imstart = 0; imlen = isep1;
    iystart = isep1  + 1; iylen = ilen - isep1 - 1
    }
  else if (inumsep == 2) {
    imstart = 0; imlen = isep1;
    idstart = isep1  + 1; idlen = isep2 - isep1 - 1
    iystart = isep2 + 1; iylen = ilen - isep2 - 1
    }


  if (obj.isDay != false) {
  if (bEuro==true && obj.isDay.toUpperCase() == 'TRUE') {
    //switch it all around
    ii = imstart
    ij = imlen
    imstart = idstart
    imlen = idlen
    idstart = ii
    idlen = ij
  }
  }


  imonth = parseInt(ss.substr(imstart, imlen), 10);  //10 param sets to base 10 (default is 8!)
                 //without it, "08" and "09" returned 0
  iyear = parseInt(ss.substr(iystart, iylen), 10);
  if (obj.isDay) { iday = parseInt(ss.substr(idstart, idlen), 10) }

  if (isNaN(imonth) || isNaN(iyear) || isNaN(iday)) {error(obj, serr); return false;}

  if (obj.isDay) {serr = "Date out of range."} else {serr = "Expecting date in mm/yy format."}
  if (iylen != 4 && iylen != 2) {error(obj, serr); return false;}
  if (imlen != 1 && imlen != 2) {error(obj, serr); return false;}
  if (obj.isDay) {
  if (idlen != 1 && idlen != 2) {error(obj, serr); return false;}
    }

  if (imonth < 1 || imonth > 12) {error(obj, serr); return false;}
  if (iylen == 4 && (iyear < 1900 || iyear > 2100)) {error(obj, serr); return false;}
  if (iylen == 2 && (iyear < 0 || iyear > 99)) {error(obj, serr); return false;}
  if ( (obj.isDay) && (iday < 1 || iday > 31) ) {error(obj, serr); return false;}




  mm = imonth;
  mm = mm > 9 ? mm : "0" + mm.toString();
  dd = iday;
  dd = dd > 9 ? dd : "0" + dd.toString();
  yy = iyear;
  yy = yy > 9 ? yy : "0" + yy.toString();

    if (iyear < 1000) {
    if (parseInt(yy) < window ) {yy = "20" + yy }
    else { yy = "19" +  yy }
    iyear = parseInt(yy)
  }


  //30 days hath November...
  if ((imonth == 1) || (imonth == 3) || (imonth == 5) || (imonth == 7) || (imonth == 8) || (imonth == 10) || (imonth == 12)) {
      if (iday > 31) {error(obj, serr); return false;}
  }
  else if ((imonth == 4) || (imonth == 6) || (imonth == 9) || (imonth == 11) ) {
      if (iday > 30) {error(obj, serr); return false;}
  }
  else if (imonth == 2) {
      //leap year, every 4 years, except centuries that are not evenly
      //divisible by 100
      imod = iyear % 4
      imod2 = iyear % 100
      if (imod == 0 && ( (imod2 != 0) || (iyear % 400 == 0) )) {  
        if (iday > 29) {error(obj, serr); return false;}
      }
      else {
        if (iday > 28) {error(obj, serr); return false;}
      }
  }

if (bEuro == true) {
    if( obj.isDay){
      sout = dd + "/" + mm + "/" + yy;
    }
    else{
      sout = mm + "/" + yy;
    }
}
else {
    if( obj.isDay){
      sout = mm + "/" + dd + "/" + yy;
    }
    else{
      sout = mm + "/" + yy;
    }

}

  obj.value = sout;
  return true;
}

//[9]
function ValidPhone(num) {
        return true;  // todo
        if (Empty(num)) return true;
        for (var i = 0; (i < num.length); i++) {
        if (num.charAt(i) == " ") continue;
        if ((num.charAt(i) >= "0") && (num.charAt(i) <= "9")) continue;
        return false;
}
return true;
}

//[12]
function ValidMinMax(num, mini, maxi) {
        
        
        if (Empty(num)) {return true;}
        return ((num >= mini) && (num <= maxi))
}

//[13]
function ValidYesNo(num) {
        if (Empty(num)) return true;
        if ((num == "Yes") || (num == "No")) return true;
        return false
}



//[14]
// generalized menu write function
function WriteMenu( sCaption, sFileOrCode, sDirPath, sHeading, sASP)
{
  var RootPath;
  var temp;
  var slash = "\\"

  temp = window.location.href;
  RootPath = temp.substr(0,temp.lastIndexOf("/")+1);


  // write the heading
  with(document){
    write("<center><table width=100% cellpadding=0 cellspacing=0>");
    write("<tr><td rowspan=13 bgcolor=#336699 width=1></td><td>");
    write("<table width=100% border=0 cellpadding=2 cellspacing=0 bgcolor=white>");
    write("<tr><td bgcolor=#336699 height=10><font color=white><b><center>" + sHeading);
    write("</td></tr>");
  }

  // write the menu selections
  for( var i = 0; i < sCaption.length; i++){
    if( sCaption[i] == "<p>" || sCaption[i] == "<P>"){
      document.write("<tr><td height=1 bgcolor=#336699></td></tr>");
    }
    else{
      with (document){
        write("<tr>");
        write("<td onMouseOver=bgcolorin(this) onMouseOut=bgcolorout(this) onMouseUp=bgcolorup('" +sDirPath+slash+sFileOrCode[i] + "')>" );
        write("<A href=\""+RootPath+sASP+"?WCI=begin&amp;action=Filter&amp;select="+sDirPath+slash+sFileOrCode[i])
        write("\" target=filter>");
        write("<center>" + sCaption[i]);
        write("</A></td></tr>");
      }
    }
  }
  document.write("</center></table>");
        document.write("<td rowspan=13 bgcolor=#336699 width=1></td></tr>");
  document.write("<tr><td colspan=3 height=1 bgcolor=#336699></td></tr></table>");
  return;
}
  //Menu background elements
  function bgcolorin(elem,name){
      elem.style.backgroundColor = "orange";
      elem.style.cursor = "hand"
  }
  function bgcolorout(elem){
      elem.style.backgroundColor = "#ffffff";
  }
  function bgcolorclick(elem){
      elem.style.backgroundColor = "#6699CC";
    //parent.menubar.window.document.tracker.currentitem.value = ' ' + elem;
  }

  function bgcolorup(path){
        parent.filter.window.document.location.href = "iData.asp?WCI=begin&action=FILTER&select="+path;
  }


//[15]
function nav0(theValue,AppName) {
// Specifies submit action depending on type of form
// E==Form, F==Filter
// 1 = new
// 2 = save
//3 = jump to
  var bdata =0;
  var errorfound = false
  var ss = "";   
   if (theValue == 2 || theValue == 15) {
   	 if (typeof(document.forms[0].sJump) != "undefined") {document.forms[0].sJump.value = ""}
     if (!FT_FinalTest()) {return false};
     if (typeof(document.forms[0].BSAVE) != "undefined")  {
       document.forms[0].BSAVE.value = "1"
     }
   }  
   else {
     //if new or jump to, we create our version of the built in window that ExitForm will display
     //because if they say they don't want to save data, we need to set BDATACHANGED = 0 
     //otherwise, the DLL will save their data.
     if (typeof(document.forms[0].BDATACHANGED) != "undefined")  {
       bdata = document.forms[0].BDATACHANGED.value 
       if (bdata == 1) {
       	 ss = "You are about to naviagate away from this page?"
       	 ss = ss + String.fromCharCode(10, 13)
       	 ss = ss + String.fromCharCode(10, 13)
       	 ss = ss + "Your data has changed. "
       	 ss = ss + String.fromCharCode(10, 13)
       	 ss = ss + String.fromCharCode(10, 13)
       	 ss = ss + "Press OK to continue, or Cancel to stay on the current page."
         errorfound = (confirm (ss));
         if (!errorfound) {         	
         	 return false;
         }
         else {
           if (typeof(document.forms[0].BSAVE) != "undefined")  {
           	 document.forms[0].BDATACHANGED.value = "0"
             document.forms[0].BSAVE.value = "1"
           }         
         }
       }	
     }
   }
   
    if ((typeof(document.forms[0].DONTSAVE) != "undefined") && (document.forms[0].DONTSAVE.value != "0")) {
        document.forms[0].BDATACHANGED.value = "0";
        window.alert("Form will not be saved");
        }
 
    if (theValue != 3) {
      if (typeof(document.forms[0].BPOSTED) != "undefined")  {
        if (document.forms[0].BPOSTED.value != "0") {     
          window.alert("This page has already been sent.x");
          parent.location.href = "iData.asp?WCI=begin&Action=home";
          }
        else {
         document.forms[0].BPOSTED.value = "-1";
        }
      }
    }
    

    if (AppName == "iVista") {return errorfound;}
    if (theValue == 2) {theValue = 0}   //reset to 0 (display)
    document.forms[0].IFUNCTION.value = theValue;
    document.forms[0].ACTION.value = "E";
    if (theValue == 11) {document.forms[0].ACTION.value = "F";}    
    if (theValue == 15) {document.forms[0].BDATACHANGED.value = "0";} 
    document.forms[0].submit ();
}


//[16]
function gotChange() {        

        document.forms[0].BDATACHANGED.value = "1";
}

//[20]
// Create a test window
function MenuWindow(url) {
  return window.open(url,'newWin','toolbar=no,resizable=yes,location=no,scrollbars=no,width=370,height=300,name=test')
}

//[21]
// Create a cookie with the specified name and value.
function SetCookie(sName, sValue)
{
//  document.cookie = sName + "=" + escape(sValue) + ";";
  var d = new Date();
  d.setFullYear(d.getFullYear()+1);
  document.cookie=sName+"="+escape(sValue)+";"+"expires="+d;
}

//[22]
// Get the specified cookie
function GetCookie(sCookie)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split(";");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sCookie.replace(" ", "") == unescape(aCrumb[0].replace(" ", "")))
      return unescape(aCrumb[1]);
  }

  return null;
}


//[23]
// find text in a listbox after the '-'
function Find2(list, text)
{
  // find the first matching
  if( text.value.length > 0){
    for( var i = 0; i < list.length; i++){
      if (list.item(i).text.toUpperCase().indexOf(text.value.toUpperCase()) > 0) {
        list.options[i].selected = true;
        return true;
      }
    }
  }
  return false;
}


//[25]
// This function gets the name of the directory imediatly above the current htm file.
function GetAppName()
{
  var temp;

  temp = window.location.href;
  temp = temp.substr(0,temp.lastIndexOf("/"));
  temp = temp.substr(temp.lastIndexOf("/")+1);

  return temp;
}

//[26]
function UpdateHeader(num)
/*this function will loop through all controls on the form, looking for
  controls that start with the "txtAmount", add up the total in that box,
  add up the total non-zero boxes, and put that total in txtTotal and txtCount
  txtTotal is required, txtCount is optional
*/
{
  var tot;
  var amt;
  var count;
  var ij=document.forms[0].elements.length;  //higher than then max number of txtAmountPaids



  ValidCurrency(num, 13);
    amt = 0;
    count = 0;
    tot = 0;
    for (i=1;i<ij; i++) {
    if (typeof(document.forms[0].elements["txtAmountPaid" + i]) == "undefined") {break;}
    amt = parseFloat(document.forms[0].elements["txtAmountPaid" + i].value);
    ss = document.forms[0].elements["txtAmountPaid" + i].value;
    if (amt != 0 && !isNaN(amt)) {
      count = count + 1;
      tot = tot + amt;
      }
    }
    if (typeof(document.forms[0].txtCount) != "undefined") {
    document.forms[0].txtCount.value = count;
    }
  document.forms[0].txtTotal.value = tot;
  FormatNumber(document.forms[0].txtTotal);

}

//[27]
function listWindow(url, fieldname, bsub) {

  var newWindow;
  var ii=0;
  var sValue="";
  var ss="";
  var ij=document.forms[0].elements.length;
  if (ij > 200) {ij = 200}
  var bChangedSave=0;
  //if the field is disabled don't show the list
  if (document.forms[0].elements[fieldname].disabled) {return}
    s1 = GetToken("Parent1", url)
    s2 = GetToken("Parent2", url)
    s3 = GetToken("Parent3", url)
    s4 = GetToken("Parent4", url)
    s5 = GetToken("Parent1Handle", url)
    s6 = GetToken("Parent2Handle", url)
    s7 = "select"
  
  if (typeof(document.forms[0].elements["BSAVE"]) != "undefined") {
  	if (document.forms[0].elements["BSAVE"].value == "0"){  		
  		bChangedSave=1
  	  document.forms[0].elements["BSAVE"].value == "1"
  	}
  }
  
  //note that we don't send values with a #, because the DLL won't get anything after the first #!
  //we just send the first 250 chars, then we'll also send special Parentx tokens
  //don't send Parentx tokens in for loop 
  
  for (ii=0;ii<ij; ii++) {
    if (typeof(document.forms[0].elements["select"]) != "undefined") {
      if (document.forms[0].elements[ii].value !="" && document.forms[0].elements[ii].value.length < 60 && document.forms[0].elements[ii].value.indexOf("#") == -1 )
        {
        if (document.forms[0].elements[ii].name != s1 && document.forms[0].elements[ii].name != s2 && document.forms[0].elements[ii].name != s3 && document.forms[0].elements[ii].name != s4 && document.forms[0].elements[ii].name != s5 && document.forms[0].elements[ii].name != s6 && document.forms[0].elements[ii].name != s7){ 
          sValue = sValue + "&" + document.forms[0].elements[ii].name + "=" + document.forms[0].elements[ii].value;
        }
      }
    }   
    if (sValue.length > 250) {break}
  }


    url=url+sValue;
    //get special parent tags 

    if (s1 != null) {url = url + "&" + s1 + "=" + document.forms[0].elements[s1].value;}
    if (s2 != null) {url = url + "&" + s2 + "=" + document.forms[0].elements[s2].value;}
    if (s3 != null) {url = url + "&" + s3 + "=" + document.forms[0].elements[s3].value;}
    if (s4 != null) {url = url + "&" + s4 + "=" + document.forms[0].elements[s4].value;}
    if (s5 != null) {url = url + "&" + s5 + "=" + document.forms[0].elements[s5].value;}
    if (s6 != null) {url = url + "&" + s6 + "=" + document.forms[0].elements[s6].value;}
    if (typeof(document.forms[0].elements["select"]) != "undefined") {url = url + "&select=" + document.forms[0].elements["select"].value;}


    newWindow = window.open('','newWin','toolbar=no,resizable=yes,location=no,scrollbars=no,height=30,width=150,left=0,top=0,alwaysraised=yes');
    waiting = '<html><head><title>Yardi Lookup</title><body bgcolor=#CCCCCC><center>'
    if (bsub == "-1") {
       waiting = waiting + '<img src="../images/computer_working.gif"><font size=-1><p>Retrieving Records...</body></html>';
      } 
    else {
      waiting = waiting + '<img src="images/computer_working.gif"><font size=-1><p>Retrieving Records...</body></html>';
    }
    newWindow.document.write(waiting)
    newWindow.location = url+'&data='+document.forms[0].elements[fieldname].value;
    if( typeof newWindow != 'unknown'){
  newWindow.focus();
  }
  if (bChangedSave == 1) {
  document.forms[0].elements["BSAVE"].value == "0"
  }
}

//[28]
function PromptAmount(ctl, row)
/*this function will loop through all controls on the form, looking for
  "txtPromptAmt" = row
   and puts that value into ctl
*/
{
  var ss;
  var s2;

  for (i = 0; i <= document.forms[0].elements.length - 1; i++) {
    s2 = 'txtPromptAmt' + row
    ss = document.forms[0].elements[i].name
    if (ss == s2) {
      ctl.value = document.forms[0].elements[i].value;
      return true;
    }
  }
}


//[29]
function DepPreview() {

  var newWindow;
  var i=0;
  var sValue="";
  var ss="";
  var amt;
  var tot;
  var count;
  var obj = new Object();
  var samt;

    newWindow = window.open("", "newWin", "toolbar=yes,scrollbars=yes,resizable=yes,directories=no,menubar=no,width=800,height=600");
    newWindow.document.open()
    if( typeof newWindow != 'unknown'){newWindow.focus();}
  newWindow.document.writeln("<body bgcolor=silver >")
  newWindow.document.writeln("<font face = tahoma color=blue>")
  newWindow.document.writeln("<h3>&nbsp; &nbsp; Deposit Preview</h3>")
  newWindow.document.writeln("<h3>&nbsp; &nbsp; bank code: " + document.forms[0].elements["txtBankCode"].value + "</h3>")
    newWindow.document.writeln("<table bgcolor=silver width='50%' border=1 cellpadding=1 text='arial'>")
    newWindow.document.writeln("<td width=50><font size=-1>Unit</td>")
    newWindow.document.writeln("<td width=50><font size=-1>Tenant</td>")
    newWindow.document.writeln("<td width=100><font size=-1>Name</td>")
    newWindow.document.writeln("<td width=100><font size=-1>Amount</td>")
    newWindow.document.writeln("<td width=50><font size=-1>Check Num</td>")
    count = 0;
    tot = 0;
    maxrows = document.forms[0].elements["txtRowCount"].value
    for (i=1;i<=maxrows - 10; i++) {
    if (document.forms[0].elements["txtAmountPaid" + i].value.length > 0) {
        amt = parseFloat(document.forms[0].elements["txtAmountPaid" + i].value);
        s2 = document.forms[0].elements["txtCheckNum" + i].value;
      tot = tot + parseFloat(amt);
      count = count + 1;
      newWindow.document.writeln("<tr><td><font size=-1>" + document.forms[0].elements["txtUnit" + i].value + "</td>")
      newWindow.document.writeln("<td><font size=-1>" + document.forms[0].elements["txtTenant" + i].value + "</td>")
      newWindow.document.writeln("<td><font size=-1>" + document.forms[0].elements["txtTenantName" + i].value + "</td>")
      newWindow.document.writeln("<td align=right><font size=-1>" + document.forms[0].elements["txtAmountPaid" + i].value + "</td>")
      newWindow.document.writeln("<td align=right><font size=-1>" + s2 + "</td><tr>")
    }
    }
    for (i=maxrows - 9;i<=maxrows; i++) {
    if (document.forms[0].elements["txtAmountPaid" + i].value.length > 0) {
        amt = parseFloat(document.forms[0].elements["txtAmountPaid" + i].value);
        s2 = document.forms[0].elements["txtCheckNum" + i].value;
      tot = tot + parseFloat(amt);
      count = count + 1;
      newWindow.document.writeln("<td colspan=2><font size=-1>(non-tenant)</td>")
      newWindow.document.writeln("<td><font size=-1>" + document.forms[0].elements["txtNonTenant" + i].value + "</td>")
      //newWindow.document.writeln("<td><font size=-1>" + document.forms[0].elements["txtTenantName" + i].value + "</td>")
      newWindow.document.writeln("<td align=right><font size=-1>" + document.forms[0].elements["txtAmountPaid" + i].value + "</td>")
      newWindow.document.writeln("<td align=right><font size=-1>" + s2 + "</td><tr>")
    }
    }
  obj.value = tot;
  FormatNumber(obj);
    s2 = obj.value;
    newWindow.document.writeln("</table>")
    newWindow.document.writeln("<p>")
    newWindow.document.writeln("Amount to be deposited: $" + s2 + "<p>")
    newWindow.document.writeln("Number of items to be deposited: " + count)
    newWindow.document.close()

}
//[30]
function FormatNumber(obj) {
  /*called from ValidateCurrency
    2100    -> 2100.00
    2100.   -> 2100.00
    2100.1  -> 2100.10
    2100.10 -> 2100.10
*/

  var i;
  var s2;
  var ss = new String(obj.value);
  var ssformat = "";
  var sGUID = GetCookie("bEuroNum");
  if (sGUID == "true") {sChar2=","; sChar1 = "."}
  else                 {sChar2="."; sChar1 = ","}

 i = ss.indexOf(sChar2);
  if (i == -1) {ss = ss + sChar2 + "00"}
  else {
    s2 = ss.substring(i);
    if (s2.length == 2) {ss = ss + "0"}
    else if (s2.length == 1) {ss = ss + "00"}
  }
  //strip thousands seperator
  i = ss.len
  for (i = 0; i <= ss.length; i++) {
    if (ss.charAt(i) == sChar1) {ss = ss.substring(0, i) + ss.substring(i+1)}
  }

  for (i = ss.length; i >= 1; i--) {  	
    if (ss.substring(i- 1, i) != "-") {
  	  if (ss.length - i == 6 || ss.length - i == 9 || ss.length - i == 12 || ss.length - i == 15) {
  	  	ssformat = sChar1 + ssformat
  	  }
  	}
  	ssformat = ss.substring(i-1, i) + ssformat
  }
  obj.value = ssformat;

}

//[31]
function NonBlank(obj) {
  if (obj.value == "") {error(obj, "Field may not be left blank"); return true;}
}

//[32]
function parseNum(obj) {
//strips commas out of numbers, does a parseFloat on it.
  var ss = new String(obj.value);
  var i;

    //validate input
  if (!ValidCurrency(obj)) {return false;}
  ss = obj.value
  i = ss.indexOf(",")  
  if (i == -1) {
  if (isNaN(parseFloat(obj.value))) {return parseFloat(0)}
    else {return parseFloat(obj.value)}
  }
  for (i = 0; i <= ss.length; i++) {
    if (ss.charAt(i) == ',') {ss = ss.substring(0, i) + ss.substring(i+1)}
  }

  return parseFloat(ss)
}

//[33]
function gotFocus(theObject) {

}

//[34]
function QueryIf(ref) {

  parent.frames[1].QueryIf2(ref);
  return false;

}


//[35]
function FT_FinalTest() {
  var ij=document.forms[0].elements.length;
  var bb;  

    for (i=0;i<ij; i++) {
      if (document.forms[0].elements[i].type == "select-multiple" && document.forms[0].elements[i].mandatory == "true") {
        bb = false
        for (j=0; j < document.forms[0].elements[i].options.length; j++) {        	
        	if (document.forms[0].elements[i].options[j].selected == true && document.forms[0].elements[i].options[j].text != "") {
        		bb = true
        		break
        	}
        }
        if (bb == false) {error(document.forms[0].elements[i], 'Field may not be blank'); return false}
      }    
      else if (document.forms[0].elements[i].mandatory == "true" && document.forms[0].elements[i].value == "") {
      {error(document.forms[0].elements[i], 'Field may not be blank'); return false}
      }
  }
  return true;
 
}

//[36]
//send "(this)" from function call
function Hand(elem) {
    elem.style.cursor = "hand";
}


function Help(elem){
    elem.style.cursor = "help";
  }


//[37]
function FilterHelp(parm,link)
{

// Remarked out when we decided to not differentiate between new screens and existing records for help files.
//  var newWindow;
//  if(typeof(document[0].elements["Help"].value) != "undefined"){
//	  if (document[0].elements["Help"].value == 'new') {
//	    parm = 'create_' + parm;
//	  }
//	}
	if (link != "true") {
	  newWindow = window.open('fltrhelp.asp?sfile=' + parm + '&link=' + link,'newWin','toolbar=no,resizable=yes,location=no,scrollbars=yes,width=450,height=300,name=FltrHelp')
	  if( typeof newWindow != 'unknown'){newWindow.focus();}
	}
	else {
	  location.href = "fltrhelp.asp?sfile=" + parm + "&link=" + link
	}
 return newWindow;
}

//[38]
function OPT_Update()
{
  var cMonth=0;
  var cMovein=0;
  var cConcession=0;

  for (i = 1; i <= 100; i++) {
    if (typeof(document.forms[0].elements["txtAmount" + i]) == "undefined") {break;}
    amt = parseNum(document.forms[0].elements["txtAmount" + i])
    if (amt != 0 && !isNaN(amt) && (document.forms[0].elements["txtCheck" + i].checked == true || document.forms[0].elements["txtCheck" + i].type == "hidden")) {
      if( typeof(document.forms[0].elements["txtAmount" + i].Monthly) != "undefined") { cMonth = cMonth + amt }
      if( typeof(document.forms[0].elements["txtAmount" + i].Movein) != "undefined") { cMovein = cMovein + amt }
      if( typeof(document.forms[0].elements["txtAmount" + i].Concession) != "undefined") { cConcession = cConcession + amt }
     }
  }
  cMonth = Round(cMonth)
  cMovein = Round(cMovein)
  cConcession = Round(cConcession)
  document.forms[0].elements["txtMonthly"].value = cMonth
  document.forms[0].elements["txtMovein"].value = cMovein
  document.forms[0].elements["txtConcession"].value = cConcession
  FormatNumber(document.forms[0].elements["txtMonthly"]);
  FormatNumber(document.forms[0].elements["txtMovein"]);
  FormatNumber(document.forms[0].elements["txtConcession"]);
  }

//[39]
//Say the state <OPTION statments
//This functions goes between the <SELECT> and </SELECT> statements
function SayStates()
{
  var ss;
  var states = new Array(
  "AL>Alabama",
  "AK>Alaska",
  "AB>Alberta",
  "AZ>Arizona",
  "AR>Arkansas",
  "BC>British Columbia",
  "CA>California",
  "CO>Colorado",
  "CT>Connecticut",
  "DE>Delaware",
  "FL>Florida",
  "GA>Georgia",
  "HI>Hawaii",
  "ID>Idaho",
  "IL>Illinois",
  "IN>Indiana",
  "IA>Iowa",
  "KS>Kansas",
  "KY>Kentucky",
  "LA>Louisiana",
  "ME>Maine",
  "MB>Manitoba",
  "MD>Maryland",
  "MA>Massachusetts",
  "MI>Michigan",
  "MN>Minnesota",
  "MS>Mississippi",
  "MO>Missouri",
  "MT>Montana",
  "NE>Nebraska",
  "NV>Nevada",
  "NB>New Brunswick",
  "NF>Newfoundland",
  "NH>New Hampshire",
  "NJ>New Jersey",
  "NM>New Mexico",
  "NY>New York",
  "NC>North Carolina",
  "ND>North Dakota",
  "NT>Northwest Territories",
  "NS>Nova Scotia",
  "OH>Ohio",
  "OK>Oklahoma",
  "ON>Ontario",
  "OR>Oregon",
  "PA>Pennsylvania",
  "PE>Prince Edward Island",
  "PQ>Quebec",
  "RI>Rhode Island",
  "SK>Saskatchewan",
  "SC>South Carolina",
  "SD>South Dakota",
  "TN>Tennessee",
  "TX>Texas",
  "UT>Utah",
  "VT>Vermont",
  "VA>Virginia",
  "WA>Washington",
  "DC>Washington DC",
  "WV>West Virginia",
  "WI>Wisconsin",
  "WY>Wyoming",
  "YT>Yukon Territory");

  document.write("<OPTION selected value=% >North America</OPTION>");
  for( ss in states){
    document.write("<OPTION value="+states[ss]+"</OPTION>");
  }
}

//[40]
function ValidMintMaxt(num,mini,maxi)
{
  var ss = new String(num.value);   //converts object to string
  var ilen = ss.length;
  {
      for (var i = 0; i < ilen; i++)
      {
          if ((ss.charAt(i) < "0") || (ss.charAt(i) > "9")) {error(num, "Invalid number"); return false;}
        }

  if(parseInt(ss) < mini || parseInt(ss) > maxi )
      {
    //alert("Expecting number in range " + mini + " to " + maxi );
    error(num, "Expecting number in range " + mini + " to " + maxi, "false");
    document.forms[0].elements[num.name].focus();
    return false; ;
      }
   }
}

//[41]
function MoveIt(objSource, objTarget) {
var iSourceLen
var iTargetLen

iSourceLen = objSource.length - 1
iTargetLen = objTarget.length - 1
for (i = 0; i <= iSourceLen; i++) {
  if (objSource[i].selected == true) {
    for (j = 0; j <= iTargetLen; j++) {
      if (objTarget[j].text == "") {
        objTarget[j].text = objSource[i].text
        objTarget[j].value = objSource[i].value
        objSource[i].text = ""
        objSource[i].value = ""
        break
      }
    }
  }
}
CompressIt(objSource)
}

//[42]
function CompressIt(obj) {
 //compress the obj array
  var iLen
  var i
  var i2
  var i3

  iLen = obj.length - 1
  i = -1
  do {
    i = i + 1
    if (obj[i].text == "") {
      bNoMore = -1
      for (i2 = i; i2 <= iLen; i2++) {
        if (obj[i2].text != "") {
          bNoMore = 0
      for (i3 = 0; i3 <= iLen - 1 - i; i3++) {
        obj[i + i3].text = obj[i + i3 + 1].text
      obj[i + i3].value = obj[i + i3 + 1].value
      }
      i = -1  //reset loop to first list item
      break
    }
    }
    if (bNoMore == -1) {return}
    }
  }
  while (i < iLen);
}

//[43]
function QueryIf2(ref,AppName) {
  var bdata = "0";
  var bsaveable = "-1";//TR26529
  var errorfound = false
  if (typeof(document.forms[0].elements["SAVEABLE"]) != "undefined") {//TR26529
    bsaveable = document[0].elements["SAVEABLE"].value;//TR26529
  }//TR26529
  if (typeof(document.forms[0].elements["BDATACHANGED"]) != "undefined") {
    bdata = document[0].elements["BDATACHANGED"].value;
    if ((bdata == "1") && (bsaveable != "0")) {//if (bdata == "1") {TR26529
      errorfound = (confirm ("Do you wish to save changed data ?"));
      if (errorfound) {
        if (AppName == "iVista") {document.forms[0].sAction.value="Save";}
        document.forms[0].submit ();
        return;
      }
    }
  }
  location.href = ref;
}

//[44]
function SetFocusOnFirstField(txtFormName, txtFirstFieldName) {
    //Set Focus on the First Field on the Form
    
    if (typeof ( eval('document.' + txtFormName + '.' + txtFirstFieldName )) == "undefined") {return;} ;
    if (eval('document.' + txtFormName + '.' + txtFirstFieldName + '.disabled') == true) {return}
    if (eval('document.' + txtFormName + '.' + txtFirstFieldName)) {
      eval('document.' + txtFormName + '.' + txtFirstFieldName + '.focus()');
    }
}

//[45]
function FormatNumber2(num) {
/*
    2100.0000001    -> 2100.00
*/

  var i;
  var s2;
  var ss = new String(num);
  var sChar="."
  i = ss.indexOf(sChar);
  if (i == -1) {ss = ss + sChar + "00"}
  else {
    s2 = ss.substring(i);
    if (s2.length == 2) {ss = ss + "0"}
    else if (s2.length == 1) {ss = ss + "00"}
    else {ss = ss.substring(0,i) + sChar + s2.substring(1, 3)};
  }
  return ss
}






//[46]
function Round(num) {


    return Math.round((num) * 100) / 100

}

//[47]
//Ask the confirmation for delete
function bDelete() {
  bok = (confirm ("Are you sure you want to delete this ?"));
  return bok ;
}

//[48]
//Trims spaces before and after string. Usage trim(var.value)
function trim ( inputStringTrim ) {
  fixedTrim = "";
  for (x=0; x < inputStringTrim.length; x++) {
    ch = inputStringTrim.charAt(x);
    if (ch != " ") break;
  }
  for (y = inputStringTrim.length-1; y>=0; y--) {
    ch = inputStringTrim.charAt(y);
    if (ch != " ") break;
  }
  if (x>y) 
       {fixedTrim = ""}
  else 
       {fixedTrim = inputStringTrim.substr(x,y-x+1)};
  return fixedTrim;
}

//[49]
function FormatPhoneNum(txtFieldName, PhoneNum) {
  var sPhoneNum = "";
  var sNewPhoneNum = "";
  var sOrigPhoneNum = PhoneNum.value;
   var sGUID = GetCookie("BINTERNATIONAL");
  if (sGUID == "true") {return}

  /* --loop through to get just the numbers and not special characters */
  for (var i = 0; i <= PhoneNum.value.length; i++) {
    if ((PhoneNum.value.charAt(i) >= "0") && (PhoneNum.value.charAt(i) <= "9")) {
      sPhoneNum = sPhoneNum  + PhoneNum.value.charAt(i);
    }
  }
  if (sPhoneNum != "") {
    sNewPhoneNum = '(' + sPhoneNum.substring(0, 3) + ') ' + sPhoneNum.substring(3, 6) + "-" + sPhoneNum.substring(6, 10);
    if (sPhoneNum.substring(10, 15) != "") { sNewPhoneNum = sNewPhoneNum + " x" + sPhoneNum.substring(10, 15); }
  }
  else  /* If alphabets or other characters were entered in the phone num field, remove it.*/
  {    sNewPhoneNum = ""  }

  document.forms[0].elements[txtFieldName].value = sNewPhoneNum;

  if (sOrigPhoneNum != sNewPhoneNum) { gotChange(); }
}


//[50]
// printer page break
function PageBreak(){
	document.write("<p class='pagebreak'>");
}

//[51]
// Get the specified param (sToken) from string (sURL)
function GetToken(sToken, sURL)
{

  var aCookie = sURL.split("&");


  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    sToken = sToken.toUpperCase();
    aCrumb[0] = aCrumb[0].toUpperCase();
    if (sToken.replace(" ", "") == aCrumb[0].replace(" ", ""))
      return unescape(aCrumb[1]);
  }

  return null;
}

//[52]
function MaxDay(imonth, iyear){
//returns max day of month
  if ((imonth == 1) || (imonth == 3) || (imonth == 5) || (imonth == 7) || (imonth == 8) || (imonth == 10) || (imonth == 12)) 
    {return 31;}
  else if ((imonth == 4) || (imonth == 6) || (imonth == 9) || (imonth == 11) ) 
    {return 30;}
  else if (imonth == 2) {
      //leap year, every 4 years, except centuries that are not evenly
      //divisible by 100
      imod = iyear % 4
      imod2 = iyear % 100
      if (imod == 0 && ( (imod2 != 0) || (iyear % 400 == 0) )) 
        {return 29;}
      else 
        {return 28;}
  }
}

//[53]
function PromptEndDate (start, term, obj){
  var ii = new Number(term.value);  
  var dt = new Date(start.value)
  var month = 0;
  var day = 0;
  var year = 0;

  if (ii == 0) {return}
  if (isNaN(dt)) {return}
  ii = dt.getMonth() + ii;
  day = dt.getDate() 
  day = day - 1
  //If you don't set the day to 1 unexpected behavior happens when 
  //you add 1 month to for example 1/31. The date will be 3/3 instead of 2/28!
  dt.setDate(1);
  if (day == 0) 
		{dt.setMonth(ii)}
	else 
		{dt.setMonth(ii+1)};
	
  month = dt.getMonth()
  year = dt.getYear()
  if (month == 0) {month = 12; year = year - 1}
  if (day == 0) {day = MaxDay(month, year)}
  if (day > MaxDay(month, year)) {day = MaxDay(month, year)}
  
  ss = month + "/" + day + "/" + year;
  obj.value = ss;
}
//[54]
function ValidateTime(sTime) {
	var iColon=0;
	var iBeforeNum=0;
	var iAfterNum=0;
	var iFoundColon=0;
	var sAfterNum=''
	var sBeforeNum=''
  var s1 = "";
  var ss = new String(sTime.value);   //converts object to string

  if (Empty(ss)) {return true;}
  if (ss.indexOf(":") == -1) {
    if (ss.length == 3) {ss = ss.substring(0, 1) + ":" + ss.substring(1, 3)}
    else if (ss.length == 4) {ss = ss.substring(0, 2) + ":" + ss.substring(2, 4)}
  }

  for (var i = 0; (i < ss.length); i++) {
    if (ss.charAt(i) == ":") {
    	iColon = iColon + 1;
    	if (iColon > 1) return error(sTime, "Invalid time.");        // only allow one colon
    	if ((i != 1) && (i != 2)) return error(sTime, "Invalid time.");  //colon in correct position
    	iFoundColon = 1;
		}
		else {
        s1 = ss.charAt(i)
        s1 = s1.toUpperCase() 
        //only allow number or am/pm
        if (s1 >= "0" && s1 <= "9") {
  				if (iFoundColon == 1) {iAfterNum = iAfterNum + 1; sAfterNum = sAfterNum + ss.charAt(i)};
  				else {iBeforeNum = iBeforeNum + 1; sBeforeNum = sBeforeNum + ss.charAt(i)};
        } 
        else if (s1 == "A" || s1 == "P" || s1 == "M" || s1 == " ") {} //OK
        else {return error(sTime, "Invalid time.");}        
		}
//		if (i > 5) return error(sTime, "Invalid time.");
	}
	if (iAfterNum != 2) return error(sTime, "Invalid time.");
	if (iBeforeNum ==1) {
		if ((sBeforeNum >= "1") && (sBeforeNum <= "9")) {}
		else {return error(sTime, "Invalid time.");}
		}
	else {
		if ((sBeforeNum >= "01") && (sBeforeNum <= "12")) {}
		else {return error(sTime, "Invalid time.");}
		}
	if ((sAfterNum >= "0") && (sAfterNum <= "59")) {}
	else {return error(sTime, "Invalid time.");}
  sTime.value = ss
	return true;
}

//[55]
function CurrentDate() {
  var dt = new Date()
  var month = 0;
  var day = 0;
  var year = 0;
  var ss;

  month = dt.getMonth() + 1
  year = dt.getYear()
  day = dt.getDate()
  ss = month + "/" + day + "/" + year;
  return ss;

}

//[56]
function CurrentTime() {
  var dt = new Date();
  var hour = 0;
  var minute = 0;
  var ampm;
  var ss;
  var zero = "";

 hour = dt.getHours()
  if (hour > 12) {hour = hour - 12; ampm = " PM"}
  else {ampm = " AM"}
  minute = dt.getMinutes()
  if (minute <= 9) {zero = "0"}
  ss = hour + ":" + zero + minute + ampm
  return ss
}

//[57]
function DateAfter(sdt1, sdt2) {
  //returns true is sdt1 is after sdt2
  var dt1 = new Date(sdt1.value)
  var dt2 = new Date(sdt2.value)

  if (dt1 >= dt2) {return false;}
  return true;
}
//[58]
function QueryString1( param )
{
  var begin,end;
  if(self.location.search.length>1)
  {
    begin=self.location.search.indexOf(param) +param.length+1;
    end=self.location.search.indexOf("&",begin);
    if(end==(-1)) end=self.location.search.length;
    return(self.location.search.substring(begin,end));
  }
  else if(self.location.hash.length>1)
  {
    begin=self.location.hash.indexOf(param) +param.length+1;
    end=self.location.hash.indexOf("&",begin);
    if(end==(-1)) end=self.location.hash.length;
    return(self.location.hash.substring(begin,end));
  }
  else return("");
}

//[59]
function OpenWindow2(url) {
	dataWin.focus();      
  dataWin.frames[0].location = url 
}

//[60]
function OpenWindow(url, parm) {
  //use this function for all sub data forms (like resident/lease charges)
  //this function uses setTimeout method to wait 1000 msecs after the window.open command
  //to give the window time to get fully created.  
  ss = "";
  bGotError = 0;  
  ii = 1;
  ij = 0;
  sparm = "";
  
  if (typeof(parm) == "undefined") {sparm = 'toolbar=no,resizable=yes,location=no,scrollbars=no,height=425,width=780,left=0,top=0,alwaysraised=yes'}  
  else (sparm = parm)  
  //close window if it is open
  if(typeof(dataWin) == "object") {dataWin.close()}
  dataWin = window.open('forms/data.htm','dataWin',sparm);      
  window.setTimeout("OpenWindow2('" + url + "')", 1000);  
}


//[61]
function GetStyleSheet()  {
  css = "";
	css = GetCookie("StyleSheet")
	if (css != null) {
		css = css + ".css"
	}
	else if (css == null) {
		css = "ysi.css"
	}
	// must include all possible directories that we may be in, instead of sending a parameter every time through.
	line1 = "<LINK REL=STYLESHEET TYPE=TEXT/CSS HREF=" + css + ">"
	line2 = "<LINK REL=STYLESHEET TYPE=TEXT/CSS HREF=SYSTEM/" + css + ">"
	line3 = "<LINK REL=STYLESHEET TYPE=TEXT/CSS HREF=../SYSTEM/" + css + ">"
  document.writeln (line1)
	document.writeln (line2)
	document.writeln (line3)
}

//[62]
function Filter() {
  var itype = 0;
  var isubtype = 0;
  var ifunction = 0;  
  var res = -1;
  var sref = "";
  var sstatus = "";
  //debugger
  if (typeof(parent.frames[2].document.forms[0]) == "undefined") {return;}
  if (typeof(parent.frames[2].document.forms[0].elements["ITYPE"]) == "undefined") {return;}
  if (typeof(parent.frames[2].document.forms[0].elements["ISUBTYPE"]) != "undefined") {isubtype = parent.frames[2].document.forms[0].elements["ISUBTYPE"].value}
  if (typeof(parent.frames[2].document.forms[0].elements["Res"]) != "undefined") {res = parent.frames[2].document.forms[0].elements["Res"].value}
  itype = parent.frames[2].document.forms[0].elements["ITYPE"].value    
  //trans default to ifunction = 2, ignore
  if (itype == 16 || itype == 15 || itype == 13 || itype == 30 || itype == 191 || itype == 63 || itype == 37) {
    if (ifunction == 2) {ifunction = 0}
  }
  else {
    if (typeof(parent.frames[2].document.forms[0].elements["IFUNCTION"]) != "undefined") {ifunction = parent.frames[2].document.forms[0].elements["IFUNCTION"].value}
  }  
  if (itype == 1) {
    if (typeof(parent.frames[2].document.forms[0].elements["CMBSTATUS"]) != "undefined") {sstatus = parent.frames[2].document.forms[0].elements["CMBSTATUS"].value}
    if (sstatus == "Applicant" || sstatus == "Canceled" || sstatus == "Wait List" || sstatus == "Denied") {
    	itype = 192
    }	
  }  
  //alert(itype)
  //alert(isubtype)
  //alert(ifunction)
  if (itype == 0) {return}      
  if (isubtype != 0) {return}    
  if (ifunction != 0) {return}      
  sref = "../"
  sref = sref + Get_Real_Asp_Name(itype) + ".asp"
  sref = sref + "?WCI=begin&action=f&iType=" + itype 
  if (res != -1) {sref = sref + "&Res=" + res}
  parent.frames[2].location.href = sref
}

//[63]
function ActiveMenu(ref,sTarget) {
		
		if (sTarget == "parent") {parent.location.href = ref}
		else if (sTarget != "parent") {parent.frames[2].location.href = ref}
    return;	
try {
	var i = 0; var bReturn = false; var bSave = true
	if (typeof(parent.frames[2].document[0]) != "undefined") {
		if (typeof(parent.frames[2].document[0].elements["BDATACHANGED"]) == "undefined") {bReturn=true}
		if (typeof(parent.frames[2].document[0].elements["BSAVE"]) == "undefined") {bReturn=true; bSave=false}
		if (typeof(parent.frames[2].document[0].elements["SAVEABLE"]) != "undefined" && parent.frames[2].document[0].elements["SAVEABLE"].value=="0") {bReturn=true}
	}
	else if (typeof(parent.frames[2].document[0]) == "undefined"){
		bReturn = true ; bSave = false	
	}
	if (bReturn) {
		if (bSave) {
			parent.frames[2].document[0].elements["BSAVE"].value = "1";
		}
		if (sTarget == "parent") {parent.location.href = ref}
		else if (sTarget != "parent") {parent.frames[2].location.href = ref}
	}
	else if (!bReturn) {
	  	for (var i=0; i < 15; i++)  {
			if (parent.frames[2].document[0].elements[i].type != "hidden" && parent.frames[2].document[0].elements[i].disabled != true) {
				parent.frames[2].document[0].elements[i].focus()
				break;
			}
		}
		bdata = parent.frames[2].document[0].elements["BDATACHANGED"].value;
		if ( bdata == "1") {
	    	errorfound = (confirm ("Do you wish to save changed data 1 ?"));
			if (errorfound) {
				parent.frames[2].document[0].elements["BSAVE"].value = "1";
				parent.frames[2].document.forms[0].submit()
			}			
			if (!errorfound) {
				parent.frames[2].document[0].elements["BSAVE"].value = "1";
				if (sTarget == "parent") {parent.location.href = ref}
				else if (sTarget != "parent") {parent.frames[2].location.href = ref}
			}
			return;
		}
		if (sTarget == "parent") {parent.location.href = ref}
		else if (sTarget != "parent") {parent.frames[2].location.href = ref}
	}   
}
catch (dummy){
	if (sTarget == "parent") {parent.location.href = ref}
	else if (sTarget != "parent") {parent.frames[2].location.href = ref}
}
}

//[64]
function ExitForm(sForm) {
  //this routine will prompt if user has changed data without saving
  //BSAVE is required form variable.  Caller should set it = 1 if he wants to bypass this routine
  //i.e. if user hits save or if user hits something like prompt charges on detailed receipts.
  //NOTE:  common routine nav0 will set BSAVE = 1.
  //       if user click on a listWindow hRef, we'll do an early return
  //SAVEABLE is an optional form variable.  This routine will honor it.
  //note that if your link is an href, the unload will happen before you get to set bsave 

	var ii = 0 ; 		
	if (typeof(document[0].elements["BDATACHANGED"]) == "undefined") {return}	
	if (typeof(document[0].elements["BSAVE"]) == "undefined") {return}	
	if (typeof(document[0].elements["SAVEABLE"]) != "undefined" && document[0].elements["SAVEABLE"].value=="0") {return}
	if (typeof(document[0].elements["BSAVE"]) != "undefined" && document[0].elements["BSAVE"].value=="1") {document[0].elements["BSAVE"].value="0"; return}		
  if (typeof(document.activeElement.href) != "undefined") {
	  if (document.activeElement.href.indexOf("listWindow") > 0) {return}
	}
	//trigger a onBlur, which will trigger the BDATACHANGED, in case they made a change without leaving the control	
	if (typeof(document.activeElement) != "undefined" && typeof(document.activeElement.name) != "undefined") {
	  document.activeElement.blur()
	}	  
	if (document[0].elements["BDATACHANGED"].value == "1") { 				
	  event.returnValue="Your data has changed.";     			
	}	
}

//[65]
function TabTo(TabNumber) {
  if (typeof(document[0].elements["BSAVE"]) != "undefined") {document[0].elements["BSAVE"].value="1"}		
  location.href = "#" + TabNumber
}

//[66]
function ValidFloat(num, min, max) {
  var n="";
  var periods=0;
  var ss = new String(num.value);   //converts object to string

    min = -1000000000 ; max = 1000000000
  //if ((Empty(ss)) && (num.isRequired == "true")) {error(num, "Amount may not be blank"); return false;}
    if (Empty(ss)) {return true;}
  for (var i = 0; (i < ss.length); i++) {
     if (ss.charAt(i) == ".") {
    periods = periods + 1;
    if (periods > 1) return error(num, "Invalid number.");        // only allow one period
    //if (i + 3 < ss.length) return error(num, "Invalid number.");  //only two digits after the period
            n = n + ss.charAt(i);
            continue;
           }
           if (ss.charAt(i) == " ") continue;  //getting a trailing blank
           if (ss.charAt(i) == ",") continue;
           if (ss.charAt(i) == "-") {
            if (i != 0) return false;   //only allow - sign at first char
            n = n + ss.charAt(i);
            continue;
           }
           if ((ss.charAt(i) >= "0") && (ss.charAt(i) <= "9")) {
              n = n + ss.charAt(i);
              continue;
           }
     return error(num, "Invalid number.")    //error
       }
    //FormatNumber(num);
    ValidMinMax(n, min, max);
    return true;  //all ok

}
//[67]
function UserList(selcol,propcode,acctcode,where,aspname,formname){
	var sSelect = "";
	var stemp;
	var sunmask;
	sSelect = document[0].elements[selcol].value;
	i = sSelect.indexOf("[HPROP]")
	if (i > 0){ 
		if (typeof(document[0].elements[propcode]) != "undefined") {
			stemp = sSelect.substring(0,i-1)
			stemp += "(select hmy from property where scode = '" + document[0].elements[propcode].value + "')" + sSelect.substring(i+7)
			sSelect = stemp
			}
		else
	    		{
			alert("Cannot display list without property");
			return;
		  	 }
	}

	 i = sSelect.indexOf("[HACCT]")
	if (i > 0){
		if (typeof(document[0].elements[acctcode]) != "undefined") {
			stemp = sSelect.substring(0,i-1)
			stemp +="(select hmy from acct where scode = '" + unMaskAcct(acctcode) 
			stemp +=  "' and hChart = (select hChart from lockout where hprop = (select hmy from property where scode = '" + document[0].elements[propcode].value + "')))" + sSelect.substring(i+7)
			sSelect = stemp
		   }
		else
		    {
			alert("Cannot display list without account");
			return;
		   }
	}	 
         listWindow(trim(aspname)+'.ASP?WCI=begin&action=ysilist&field='+where+'&select='+sSelect+'&label=List&framename='+trim(formname)+'&PromptDesc=0',where)
}
//[68]
function unMaskAcct(acct){
	var AcctOut = new String(document[0].elements[acct].value)

	j = AcctOut.indexOf(" ")
       if (j < 0) 
       	{j = AcctOut.length}

       AcctOut=AcctOut.substring(0,j)
	isep =AcctOut.indexOf("-");
       while (isep >  0) {  
       	AcctOut=AcctOut.substring(0, isep) + AcctOut.substring(isep + 1, AcctOut.length)
       	isep =AcctOut.indexOf("-");
       	}
       isep =AcctOut.indexOf(".");    
  	while  (isep >  0) {  
  		AcctOut=AcctOut.substring(0, isep) + AcctOut.substring(isep + 1, AcctOut.length)
  		isep =AcctOut.indexOf(".");    
  		}
     return  AcctOut 
}

//[69]
function Get_Real_Asp_Name(itype) {
  sref = "iData"
  //debugger  
  if (itype == 1) { sref  = "iData"}         //tenant
  else if (itype == 2) { sref  = "iData"}    //owner
  else if (itype == 3) { sref  = "iData"}    //property
  else if (itype == 4) { sref  = "iData"}    //unit
  else if (itype == 5) { sref  = "iData"}    //vendor
  else if (itype == 7) { sref  = "iData"}    //account
  else if (itype == 10) { sref  = "iData"}   //unittype
  else if (itype == 13) { sref  = "iData"}   //charge
  else if (itype == 14) { sref  = "iData"}   //bank
  else if (itype == 15) { sref  = "iData"}   //receipt
  else if (itype == 16) { sref  = "iData"}   //journal
  else if (itype == 21) { sref  = "iData"}   //regular acct
  else if (itype == 22) { sref  = "iData"}   //total acct
  else if (itype == 23) { sref  = "iData"}   //prospect
  else if (itype == 25) { sref  = "iMMW"}    //WO
  else if (itype == 26) { sref  = "iMMW"}    //PO
  else if (itype == 27) { sref  = "iMMW"}    //stock
  else if (itype == 28) { sref  = "iMMW"}    //asset
  else if (itype == 29) { sref  = "iMMW"}    //recur wo
  else if (itype == 30) { sref  = "iData"}   //payable
  else if (itype == 33) { sref  = "iData"}   //cash acct
  else if (itype == 36) { sref  = "iData"}   //budget
  else if (itype == 37) { sref  = "iData"}   //recur JE
  else if (itype == 63) { sref  = "iMMW"}    //recur pay
  else if (itype == 42) { sref  = "iMMW"}    //recur PO
  else if (itype == 73) { sref  = "iData"}   //worksheet
  else if (itype == 74) { sref  = "iData"}   //lease charge
  else if (itype == 83) { sref  = "iData"}   //sqft
  else if (itype == 88) { sref  = "iData"}   //memo
  else if (itype == 93) { sref  = "iData"}   //roommate
  else if (itype == 141) { sref  = "iAffordable"}     //hmprop
  else if (itype == 142) { sref  = "iAffordable"}     //hmsumm
  else if (itype == 143) { sref  = "iAffordable"}     //hmfamily
  else if (itype == 144) { sref  = "iAffordable"}     //hmincome
  else if (itype == 163) { sref  = "iData"}  //post acct
  else if (itype == 164) { sref  = "iData"}  //ar acct
  else if (itype == 165) { sref  = "iData"}  //ap acct
  else if (itype == 171) { sref  = "iPHA"}   //H8INCOME 
  else if (itype == 172) { sref  = "iPHA"}   //H8PUBLIC 
  else if (itype == 173) { sref  = "iPHA"}   //H8CERTIF 
  else if (itype == 174) { sref  = "iPHA"}   //H8VOUCH  
  else if (itype == 175) { sref  = "iPHA"}   //H8MODREH 
  else if (itype == 176) { sref  = "iPHA"}   //H8MANUF  
  else if (itype == 177) { sref  = "iPHA"}   //H8MUTUAL 
  else if (itype == 178) { sref  = "iPHA"}   //H8FSS    
  else if (itype == 179) { sref  = "iPHA"}   //H8SUMM   
  else if (itype == 180) { sref  = "iPHA"}   //H8FAMILY 
  else if (itype == 184) { sref  = "iMMW"}   //pur req
  else if (itype == 188) { sref  = "iMMW"}   //inventory
  else if (itype == 189) { sref  = "iMMW"}   //supplier
  else if (itype == 191) { sref  = "iData"}  //check
  else if (itype == 192) { sref = "iData"}   //applicant
  else if (itype == 231) { sref  = "iAffordable"}  //hmtenant
  else if (itype == 233) { sref  = "iAffordable"}  //hmcontract
  else if (itype == 234) { sref  = "iAffordable"}  //hmunit
  else if (itype == 239) { sref  = "iAffordable"}  //building  
  else if (itype == 244) { sref  = "iAffordable"}  //HMTAXCR 
  else if (itype == 245) { sref  = "iAffordable"}  //HMTAXRULE 
  else if (itype == 241) { sref  = "iAffordable"}  //letters 
  else if (itype == 242) { sref  = "iAffordable"}  //correspondent
  else if (itype == 246) { sref  = "iInspect"}     //INSPECTION 
  else if (itype == 247) { sref  = "iInspect"}     //INSPEMPLOYEE 
  else if (itype == 248) { sref  = "iInspect"}     //INSPVENDOR 
  else if (itype == 300) { sref  = "iAssist"}      //WLINCLIMIT  
  else if (itype == 302) { sref  = "iWait"}        //WLPREFERENCE
  else if (itype == 303) { sref  = "iWait"}        //WLAPPLIC
  else if (itype == 304) { sref  = "iWait"}        //WLAPPLICPREFS
  else if (itype == 305) { sref  = "iWait"}        //WLWAITLISTWLAPPLIC
  else if (itype == 306) { sref  = "iWait"}        //WLWAITLISTPREFS
  else if (itype == 307) { sref  = "iWait"}        //WLWAITLIST
  else if (itype == 308) { sref  = "iWait"}        //WLINCLIMITXREF
  else if (itype == 314) { sref  = "iPHA"}         //UTLOCALITY
  else if (itype == 315) { sref  = "iPHA"}         //UTILSERV
  else if (itype == 316) { sref  = "iPHA"}         //UTALLOW
  else if (itype == 330) { sref  = "iPHA"}         //H8PROP
  else if (itype == 331) { sref  = "iPHA"}         //H8UNIT
  else { sref  = "iData"}
  return sref  
}  

