function doubleInput(e, field) {
	//0 = 48
	//9 = 57
	//. = 46
	var key = e.keyCode;
    //alert(key);

	if (key == 13) {
      //do nothing
    }
    else if (key == 46) {
		decimalCount = 0;
		numVal = field.value;
		numLen = numVal.length;
		for (var i = 0; i != numLen; i++) {
			aChar = numVal.substring(i, i+1);
			if (aChar < "0" || aChar > "9")	{
				if (aChar == '.') {
					decimalCount++
				}
			}
		}
		if (decimalCount > 0) {
			if (document.all)
				e.returnValue = false
			else
				return false;
		}
	}

	else if ((key < 48) || (key > 57)) {
		  if (document.all)
		  	e.returnValue = false
		  else
			return false;
	}
}

function integerInput(e, field) {
	//0 = 48
	//9 = 57
	var key = e.keyCode;
	if (key == 13) {
      //do nothing
    }
    else if ((key < 48) || (key > 57)) {
		  if (document.all)
		  	e.returnValue = false
		  else
			return false;
	}
}

function dateInput(e, field) {
	//0 = 48
	//9 = 57
	//forward slash=47
	var key = e.keyCode;
    if (key == 13) {
      //do nothing
    }
    else if ((key < 47) || (key > 57)) {
		  if (document.all)
		  	e.returnValue = false
		  else
			return false;
	  }
}

function selectPage(iBeginAt) {
	//alert(iBeginAt);
	document.Filter.BeginAt.value=iBeginAt;
	document.Filter.submit();
}

function selectPage(iBeginAt, iTotalCount) {
	//alert(iBeginAt);
	document.Filter.BeginAt.value=iBeginAt;
	//document.Filter.TotalCount.value=iTotalCount;
	document.Filter.submit();
}

function openHelp(Reference) {
	//alert(Reference);
	window.open("Help.asp?HH=1&Ref=" + Reference, "Help", "Height=500, Width=500, location=no, menubar=no, toolbar=no, resizable=yes, scrollbars=yes");
}

function openReport(Type, ItemID, OfficeID){
	if (Type=="Property") 
	  URL="PropertyReport.asp?HH=1&OID=" + OfficeID + "&PropertyID=" + ItemID
	else
	  URL="TenantReport.asp?HH=1&OID=" + OfficeID + "&TenantID=" + ItemID;
	window.open(URL, "Report"+ItemID, "location=no, menubar=yes, toolbar=yes, resizable=yes, scrollbars=yes");
}

function checkdate(objName) {
    var datefield = objName;
    if (chkdate(objName, true) == false) {
        datefield.select();
        alert("The date you entered is invalid.  Please try again, using the format MM/DD/YYYY.");
        datefield.focus();
        return false;
    } else {
        return true;
       }
}

function checkdateIgnore(objName) {
    var datefield = objName;
    if (chkdate(objName, false) == false) {
        datefield.select();
        alert("The date you entered is invalid.  Please try again, using the format MM/DD/YYYY.");
        datefield.focus();
        return false;
    } else {
        return true;
       }
}

function checkdatecustom(objName, errorMessage) {
    var datefield = objName;
    if (chkdate(objName, true) == false) {
        datefield.select();
        alert(errorMessage);
        datefield.focus();
        return false;
    } else {
        return true;
       }
}

function checkdatecustomIgnore(objName, errorMessage) {
    var datefield = objName;
    if (chkdate(objName, false) == false) {
        datefield.select();
        alert(errorMessage);
        datefield.focus();
        return false;
    } else {
        return true;
       }
}

function chkdate(objName, useDate) {
    var strDatestyle = "US"; // United States date style
    // var strDatestyle = "EU";  // European date style
    var strDate;
    var strDateArray;
    var strDay;
    var strMonth;
    var strYear;
    var intDay;
    var intMonth;
    var intYear;
    var booFound = false;
    var datefield = objName;
    var strSeparatorArray = new Array("-"," ","/",".", "\\");
    var intElementNr;
    var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    strDate = datefield.value;
    if (strDate.length < 1) {
        return true;
    }
    for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
        if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
            // assumption made that all the delimeters are the same
            strDateArray = strDate.split(strSeparatorArray[intElementNr]);
            if (strDateArray.length != 3) {
                err = 1;
                return false;
            }
            else {
                strMonth = strDateArray[0];
                strDay = strDateArray[1];
                strYear = strDateArray[2];
            }
            booFound = true;
        }
    }
    if (booFound == false) {
        if (strDate.length > 5) {
            strMonth = strDate.substr(0, 2);
            strDay = strDate.substr(2, 2);
            strYear = strDate.substr(4);
            booFound = true;
        }
    }
    
    if (booFound == false) {
        return false;
    }
    
    // NOTE -- Current Year sensitive code
    if (strYear.length == 2) {
        var decade = parseInt(strYear);
        if (decade < 16) {
            strYear = '20' + strYear;
        } else {
            strYear = '19' + strYear;
        }
    }
    
    // EU style
    if (strDatestyle == "EU") {
        strTemp = strMonth;
        strMonth = strDay;
        strDay = strTemp;
    }
    
    // check the day
    intDay = parseInt(strDay, 10);
    if (isNaN(intDay)) {
        err = 2;
        return false;
    }
    
    // check the month
    intMonth = parseInt(strMonth, 10);
    if (isNaN(intMonth)) {
        for (i = 0; i < 12; i++) {
            if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
                intMonth = i+1;
                strMonth = strMonthArray[i];
                i = 12;
            }
        }
        if (isNaN(intMonth)) {
            err = 3;
            return false;
       }
    }
    
    // check the year
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear)) {
        err = 4;
        return false;
    }
    
    // do validations
    if (intMonth > 12 || intMonth < 1) {
        err = 5;
        return false;
    }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31 || intDay < 1)) {
        err = 6;
        return false;
    }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30 || intDay < 1)) {
        err = 7;
        return false;
    }
    if (intMonth == 2) {
        if (intDay < 1) {
            err = 8;
            return false;
        }
        if (LeapYear(intYear) == true) {
            if (intDay > 29) {
                err = 9;
                return false;
            }
        } else {
            if (intDay > 28) {
                err = 10;
                return false;
            }
        }
    }
    
    // date itself is valid, but is it later than today?
    var compDate = new Date(intYear, intMonth - 1, intDay, 00, 00, 00, 000);
    if (useDate) {
        var today = new Date();
        if (compDate.getTime() > today.getTime()) {
            return false;
        }
    }
    
    var minDate = new Date(1900,0,1,00,00,00,000);
    if (compDate.getTime() < minDate.getTime()) {
        return false;
    }

    strMonth = intMonth.toString();
    if (strMonth.length == 1) {
        strMonth = '0' + strMonth;
    }
    strDay = intDay.toString();
    if (strDay.length == 1) {
        strDay = '0' + strDay;
    }
    if (strDatestyle == "US") {
        datefield.value = strMonth + "/" + strDay + "/" + strYear;
    } else {
        datefield.value = strDay + "/" + strMonth + "/" + strYear;
    }
    return true;
}
