function countChars(p_sText){ // count the number of characters (without line breaks) var nPos; var nCount = 0, nLength; for (nPos = 0; nPos < p_sText.length; nPos++){ // count the number of newlines if (p_sText.charAt(nPos) == '\n'){ nCount += 1 } } nLength = p_sText.length - (nCount * 2); // return the length of the character string return nLength; } function countCheckboxesSelected(p_sFormName, p_sCheckboxName){ // count the number of checkboxes selected var oCheckbox = document.forms[p_sFormName].elements[p_sCheckboxName]; var nCount = 0; var i; // count checked checkboxes for (i=0; i < oCheckbox.length; i++){ if (oCheckbox[i].checked){ nCount++ } } // return the number of checked checkboxes return nCount; } function formatCurrency(p_sText){ // format the string passed as currency var sText = p_sText.toString(); var sPence, nPence, i; // remove £ and , sText = sText.replace(/£|,/g, ''); // a non numeric is returned without change if (isNaN(sText)){ return p_sText; } // a negative number is returned without change if (parseFloat(sText) < 0){ return p_sText; } // empty string defaults to zero if (sText == ''){ sText = 0; } // extract the pence nPence = Math.floor((sText * 100 + 0.5) % 100); // add the leading zero if (nPence < 10){ sPence = "0" + nPence } else { sPence = nPence } // remove the pence sText = Math.floor(sText).toString(); return (sText + '.' + sPence); } function isNumber(p_sText, p_nNoOfDecimals){ // numeric check var sText = p_sText.toString(); var sDecimals; // value must be numeric if (isNaN(p_sText) || sText == ''){ return false; } // ensure it has a decimal point if (sText.indexOf('.') == -1){ sText += '.'; } sDecimals = sText.substring(sText.indexOf('.') + 1, sText.length); // must conform to the number of decimals specified if (sDecimals.length > p_nNoOfDecimals){ return false; } return true; } function trim(p_sText){ // remove leading and trailing spaces var sText = p_sText.toString(); var nPos; // remove leading spaces nPos = sText.length while (sText.charAt(0) == ' '){ sText = sText.substring(1, nPos); } // remove trailing spaces nPos = sText.length - 1; while (sText.charAt(nPos) == ' '){ sText = sText.substring(0, nPos); nPos -= 1 } return sText; } var defaultEmptyOK = false; var date1 = "", date2 = "", datestop = 0, allOK = 0; function makeArray(n) { for (var i = 1; i <= n; i++) { this[i] = 0 } return this } var daysInMonth = makeArray(12); daysInMonth[1] = 31; daysInMonth[2] = 29; // must programmatically check this daysInMonth[3] = 31; daysInMonth[4] = 30; daysInMonth[5] = 31; daysInMonth[6] = 30; daysInMonth[7] = 31; daysInMonth[8] = 31; daysInMonth[9] = 30; daysInMonth[10] = 31; daysInMonth[11] = 30; daysInMonth[12] = 31; function isEmpty(s) { return ((s == null) || (s.length == 0)) } function isDigit (c) { return ((c >= "0") && (c <= "9")) } function isInteger (s) { var i; if (isEmpty(s)) if (isInteger.arguments.length == 1) return defaultEmptyOK; else return (isInteger.arguments[1] == true); for (i = 0; i < s.length; i++) { var c = s.charAt(i); if (!isDigit(c)) return false; } return true; } function isSignedInteger (s) { if (isEmpty(s)) if (isSignedInteger.arguments.length == 1) return defaultEmptyOK; else return (isSignedInteger.arguments[1] == true); else { var startPos = 0; var secondArg = defaultEmptyOK; if (isSignedInteger.arguments.length > 1) secondArg = isSignedInteger.arguments[1]; if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") ) startPos = 1; return (isInteger(s.substring(startPos, s.length), secondArg)) } } function isNonnegativeInteger (s) { var secondArg = defaultEmptyOK; if (isNonnegativeInteger.arguments.length > 1) secondArg = isNonnegativeInteger.arguments[1]; return (isSignedInteger(s, secondArg) && ( (isEmpty(s) && secondArg) || (parseInt (s) >= 0) ) ); } function isYear (s) { if ((isEmpty(s)) || (!isNonnegativeInteger(s))) return false; s2 = s.substring(0,2); if (s2 != "18" && s2 != "19" && s2 != "20") return false; return (s.length == 4); } function isIntegerInRange (s, a, b) { if (isEmpty(s)) if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK; else return (isIntegerInRange.arguments[1] == true); if (!isInteger(s, false)) return false; var num = parseInt (s); return ((num >= a) && (num <= b)); } function isMonth (s) { if (isEmpty(s)) if (isMonth.arguments.length == 1) return defaultEmptyOK; else return (isMonth.arguments[1] == true); return isIntegerInRange (s, 1, 12); } function isDay (s) { if (isEmpty(s)) if (isDay.arguments.length == 1) return defaultEmptyOK; else return (isDay.arguments[1] == true); return isIntegerInRange (s, 1, 31); } function daysInFebruary (year) { return ( ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 ); } function isDate (year, month, day) { if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false; var intYear = parseInt(year); var intMonth = parseInt(month); var intDay = parseInt(day); if (intDay > daysInMonth[intMonth]) return false; if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false; return true; } function dateValidation(dateVal){ var novalid = 0; var thedate = ""; var yearvar = ""; var monthvar = ""; var dayvar = ""; if (dateVal != "") { pos = dateVal.indexOf("/"); myday = dateVal.substring(0,pos); if (myday.substring(0,1)=="0") myday = myday.substring(1,2); dateVal = dateVal.substring(pos+1,dateVal.length); if (isDay(myday)) { dayvar = myday; if (dayvar.length==1) dayvar = "0" + dayvar; pos = dateVal.indexOf("/"); mymonth = dateVal.substring(0,pos); myyear = dateVal.substring(pos+1,dateVal.length); if (mymonth.substring(0,1)=="0") mymonth = mymonth.substring(1,2); if (isMonth(mymonth)) { monthvar = mymonth; if (monthvar.length==1) monthvar = "0" + monthvar; if (isYear(myyear)) { yearvar = myyear; if (!(isDate(myyear,mymonth,myday))) novalid = 1; } else{ novalid = 1; } } else{ novalid = 1; } } else{ novalid = 1; } } if (novalid == 1){ return -1 } else { thedate = yearvar + monthvar + dayvar; return thedate; } } function dateLater(fieldVal,fieldname) { var datelower = 0; if (datestop == 0) { if (fieldVal != "" && date1 != null) { if (date2 < date1) { window.alert("This date must be the same or later than the other."); var obj=eval('document.form1.' + fieldname); allOK =0; obj.focus(); obj.select(); } else allOK = 1; } } } function ValidateDate(fieldVal1,fieldName1,fieldVal2,fieldName2,fieldVal3,fieldName3,radioName) { if (radioName != 'null'){ //check the period of interest var obj2=eval('document.form1.' + radioName); if ((obj2[0].checked || obj2[1].checked || obj2[2].checked) && !(fieldVal3 > 0)) { window.alert("You have to type a value greater than zero in this field."); var obj=eval('document.form1.' + fieldName3); obj2[0].checked = false; obj2[1].checked = false; obj2[2].checked = false; obj.focus(); obj.select(); return; } } allOK = 0; //check the 'from' date date1 = dateValidation(fieldVal1,fieldName1); if (allOK == 0) return; //check date 'to' is not later than today dnow = new Date(); var d1 = '' + dnow.getDate(); var m1 = '' + (dnow.getMonth()+1); //window.alert(m1); if (m1.substring(0,1)=="0") m1 = m1.substring(1,2); var y1 = '' + dnow.getYear(); if (y1.length == 2){ y1 = '19' + y1} var tdate = y1+m1+d1; //check the 'to' date date2 = dateValidation(fieldVal2,fieldName2); if (allOK == 0) return; dateLater(fieldVal2,fieldName2); if (allOK == 1) { document.form1.submit(); } } var postUrl='http://www.egpropertylink.com/searchV01/SearchResults.asp' var M_PERIOD_ALL = '5'; var isNS = (navigator.appName.indexOf("Netscape") >= 0) ? true : false; var m_bPostCodeDisabled = false; function submitform(strPropertyID,strRegionID,strMethod,strAction,strKeywords,nOffSet,nResults) { var i, nCount, sPeriod, sDateFrom, sDateTo; // trim unwanted spaces document.property.street.value = trim(document.property.street.value); document.property.town.value = trim(document.property.town.value); document.property.postcode.value = trim(document.property.postcode.value); document.property.NumTimeUnits.value = trim(document.property.NumTimeUnits.value); document.property.dateFrom.value = trim(document.property.dateFrom.value); document.property.dateTo.value = trim(document.property.dateTo.value); document.property.SIZE.value = trim(document.property.SIZE.value); document.property.schemename.value = trim(document.property.schemename.value); // option groups 1, 2 and 3 are mutually exclusive nCount = 0; if (document.property.street.value != "" || document.property.town.value != ""){ nCount++; } if (document.property.postcode.value != ""){ nCount++; } if (nCount > 1){ alert('Please use ONLY ONE of the two options under Location.'); document.property.street.focus(); return; } // check town has been entered when street has been entered if (document.property.street.value != "" && document.property.town.value == "") { alert('Please enter a Town for the Street'); document.property.town.focus(); document.property.town.select(); return; } // 'Number of Time Units'/period and From/To dates are mutually exclusive if (document.property.NumTimeUnits.value != "" && (document.property.dateFrom.value != "" || document.property.dateTo.value != "")){ alert('Please specify a period of time OR enter From and To date(s)'); document.property.NumTimeUnits.focus(); return; } // check 'Number of Time Units' entered is numeric if (document.property.NumTimeUnits.value != ''){ if (!isNumber(document.property.NumTimeUnits.value, 0) || document.property.NumTimeUnits.value == 0){ alert('Please enter a numeric value greater than zero for time period'); document.property.NumTimeUnits.focus(); document.property.NumTimeUnits.select(); return; } } // check period is not set to 'all' when 'Number of Time Units' is entered if (document.property.NumTimeUnits.value != ''){ sPeriod = -1; for (i=0; i < document.property.period.length; i++) { if (document.property.period[i].checked){ sPeriod = document.property.period[i].value } } if (sPeriod == M_PERIOD_ALL) { alert("Please select Day(s), Week(s), Month(s) or Year(s)"); document.property.NumTimeUnits.focus(); return; } } // check dateFrom is a valid date sDateFrom = dateValidation(document.property.dateFrom.value); if (sDateFrom == -1){ alert('Please enter a valid From date'); document.property.dateFrom.focus(); document.property.dateFrom.select(); return; } // From date is mandatory when To date is entered if (document.property.dateFrom.value == "" && document.property.dateTo.value != ""){ alert('Please enter a From date when To date is entered'); document.property.dateFrom.focus(); return; } // check dateTo is a valid date sDateTo = dateValidation(document.property.dateTo.value); if (sDateTo == -1){ alert('Please enter a valid To date'); document.property.dateTo.focus(); document.property.dateTo.select(); return; } // To date can not be earlier than the From date if (sDateTo != ""){ if (sDateTo < sDateFrom){ alert('Please enter a To date that is greater than or equal to the From date'); document.property.dateTo.focus(); document.property.dateTo.select(); return; } } // check size is a non zero numeric if (document.property.SIZE.value != ''){ if (!isNumber(document.property.SIZE.value, 4)){ alert('Please enter a numeric value for Size (up to 4 decimals)'); document.property.SIZE.focus(); document.property.SIZE.select(); return; } if (document.property.SIZE.value ==0){ alert('Please enter a numeric value greater than 0'); document.property.SIZE.focus(); document.property.SIZE.select(); return; } } document.property.METHOD.value = strMethod; document.property.PROPERTY_ID.value = strPropertyID; document.property.REGION_ID.value = strRegionID; if(document.property.TO_LET_PRICE_PER_SQ_FOOT.value==""){ document.property.TO_LET_PRICE_PER_SQ_FOOTWEIGHT.value = "0"; } else { document.property.TO_LET_PRICE_PER_SQ_FOOTWEIGHT.value = "30"; } if(document.property.TO_LET_PRICE_PER_ANNUM.value==""){ document.property.TO_LET_PRICE_PER_ANNUMWEIGHT.value = "0"; } else { document.property.TO_LET_PRICE_PER_ANNUMWEIGHT.value = "30"; } if(document.property.FOR_SALE_PRICE.value==""){ document.property.FOR_SALE_PRICEWEIGHT.value = "0"; } else { document.property.FOR_SALE_PRICEWEIGHT.value = "30"; } if(document.property.SIZE.value==""){ document.property.SIZEWEIGHT.value = "0"; } else { document.property.SIZEWEIGHT.value = "30"; } if(document.property.AIR_CONDITIONING.checked){ document.property.AIR_CONDITIONINGWEIGHT.value = "1"; } else { document.property.AIR_CONDITIONINGWEIGHT.value = "0"; } if(document.property.CAR_PARKING.checked){ document.property.CAR_PARKINGWEIGHT.value = "1"; } else { document.property.CAR_PARKINGWEIGHT.value = "0"; } if(document.property.RAISED_FLOORS.checked){ document.property.RAISED_FLOORSWEIGHT.value = "1"; } else { document.property.RAISED_FLOORSWEIGHT.value = "0"; } document.property.OFFSET.value = nOffSet document.property.RESULTS.value = nResults document.property.action = strAction document.property.submit(); } function NumTimeUnits_onchange(p_oText){ var i; // reset the period if the 'Number of Time Units' is cleared if (trim(p_oText.value) == ""){ for (i=0; i < document.property.period.length; i++) { if (document.property.period[i].value == M_PERIOD_ALL){ document.property.period[i].checked = true; } } } } function RegionId_onfocus(){ // disable REGION for Netscape if (m_bPostCodeDisabled){ document.property.town.focus(); } } function dopropertysearch() { submitform('0','0','QUERY',postUrl,'','0','10'); }