function getForm() { return document.SearchResultsForm; } function trim(value){ return value.replace(/^\s+|\s+$/,''); } function populatePuDate(dropList) { //if month selected is a month gone, select next year as the year. if(dropList != null && dropList == 'puMonth') { var date = new Date(); if(getForm().puMonth.value < date.getMonth()+1) { getForm().puYear.value = Number(date.getFullYear())+1; } } getForm().doDay.selectedIndex=getForm().puDay.selectedIndex; getForm().doMonth.selectedIndex=getForm().puMonth.selectedIndex; getForm().doYear.selectedIndex=getForm().puYear.selectedIndex; } function populateDoDate(dropList) { //if month selected is a month gone, select next year as the year. if(dropList != null && dropList == 'doMonth') { var date = new Date(); if(getForm().doMonth.value < date.getMonth()+1) { getForm().doYear.value = Number(date.getFullYear())+1; } } } function setPuMultipleValues(y,m,d) { getForm().puDay.value=d; getForm().puMonth.value=m; getForm().puYear.value=LZ(y); } function setDoMultipleValues(y,m,d) { getForm().doDay.value=d; getForm().doMonth.value=m; getForm().doYear.value=LZ(y); } function validateSearchResultsForm(searchForm){ var errors = ""; errors = validateDriversAge(searchForm.driversAge, "Drivers Age", errors); errors = validateMandatoryDroplist(searchForm.country, "Pickup Country", errors); errors = validateMandatoryDroplist(searchForm.city, "Pickup City", errors); errors = validateMandatoryDroplist(searchForm.location, "Pickup Location", errors); errors = validateMandatoryDroplist(searchForm.dropCountry, "Dropoff Country", errors); errors = validateMandatoryDroplist(searchForm.dropCity, "Dropoff City", errors); errors = validateMandatoryDroplist(searchForm.dropLocation, "Dropoff Location", errors); errors = validateDate(searchForm.puYear.value, searchForm.puMonth.value-1, searchForm.puDay.value, "Pickup Date", errors); errors = validateDate(searchForm.doYear.value, searchForm.doMonth.value-1, searchForm.doDay.value, "Dropoff Date", errors); errors = validateDates( searchForm.puYear.value, searchForm.puMonth.value-1, searchForm.puDay.value, searchForm.puHour.value, searchForm.puMinute.value, "Pickup Date", searchForm.doYear.value, searchForm.doMonth.value-1, searchForm.doDay.value, searchForm.doHour.value, searchForm.doMinute.value, "Dropoff Date", errors); errors = validateCutOffDate(searchForm.puYear.value, searchForm.puMonth.value-1, searchForm.puDay.value, "Pickup Date", errors); if(errors==""){ return true; } else { alert(errors); return false; } } function validateMandatoryDroplist(droplist, name, errors){ if(droplist.value=="" || droplist.value==0){ errors = errors + name + " must be specified\n"; } return errors; } function validateDates(yearFrom, monthFrom, dayFrom, hourFrom, minuteFrom, nameFrom, yearTo, monthTo, dayTo, hourTo, minuteTo, nameTo, errors){ var date = new Date(); var dateFrom = new Date(yearFrom, monthFrom, dayFrom, hourFrom, minuteFrom, 0); var dateTo = new Date(yearTo, monthTo, dayTo, hourTo, minuteTo, 0); if(dateFrom.valueOf() < date.valueOf()){ errors = errors + nameFrom + " is before today's date\n"; } if(dateFrom.valueOf() > dateTo.valueOf()){ errors = errors + nameFrom + " must be before " + nameTo + "\n"; } return errors; } function validateDate(year, month, day, name, errors){ if(!isValidDate(year, month, day)){ errors = errors + name + " is not a valid date\n"; } return errors; } function validateCutOffDate(year, month, day, name, errors){ var cutOffDate = new Date(2005, 11, 28); var newDate = new Date(year, month, day); if(cutOffDate.valueOf()>newDate.valueOf()){ errors = errors + "Pickup date must be after 27th December 2005\n"; } return errors; } function isValidDate(year, month, day){ var tempDate = new Date(year, month, day); var tempYear = tempDate.getYear()<2000?tempDate.getYear()+1900:tempDate.getYear(); return (tempYear==year && tempDate.getMonth()==month && tempDate.getDate()==day); } function isNumeric(sText){ var validChars = "0123456789"; var returnValue = true; var currentChar; for (var i = 0; i < sText.length && returnValue == true; i++) { currentChar = sText.charAt(i); if (validChars.indexOf(currentChar) == -1) { returnValue = false; } } return returnValue; } function validateDriversAge(driversAge, name, errors){ var minDriversAge = ; var maxDriversAge = ; if(driversAge.value==""){ errors = errors + name + " must be specified\n"; } /* else if(!isNumeric(driversAge.value)) { errors = errors + name + " must be a number\n"; } else if(driversAge.value < minDriversAge) { errors = errors + name + " must be at least " + minDriversAge + "\n"; } else if(driversAge.value > maxDriversAge) { errors = errors + name + " must be no more than " + maxDriversAge + "\n"; }*/ return errors; } function headingClick(checkbox, options, index){ var element = document.getElementById(options); if(checkbox.checked==true){ element.style.display='none'; var i=0; while(true){ var subelem = document.getElementById("optionCB" + index + ":" + i++); if(subelem==null || i>100) break; subelem.checked = false; } } else { element.style.display=''; } } function disableSearchResultsForm(isDisabled){ if(isDisabled){ getForm().country.disabled=isDisabled; getForm().city.disabled=isDisabled; getForm().location.disabled=isDisabled; getForm().dropCountry.disabled=isDisabled; getForm().dropCity.disabled=isDisabled; getForm().dropLocation.disabled=isDisabled; } getForm().puDay.disabled=isDisabled; getForm().puMonth.disabled=isDisabled; getForm().puYear.disabled=isDisabled; getForm().puHour.disabled=isDisabled; getForm().puMinute.disabled=isDisabled; getForm().doDay.disabled=isDisabled; getForm().doMonth.disabled=isDisabled; getForm().doYear.disabled=isDisabled; getForm().doHour.disabled=isDisabled; getForm().doMinute.disabled=isDisabled; } function makeUrl(start, parameters) { var url = start; for(var i=0; i < parameters.length; i++) { if(i==0){ url += "?"; }else{ url += "&"; } url += parameters[i][0] + "=" + parameters[i][1]; } return url; } function makeDynaDroplistUrl(dropList, serverUrl) { var debug=""; if(debug!=""){ disableSearchResultsForm(true); } var dynaParams = new Array(); dynaParams[dynaParams.length] = new Array("country", getForm().country.value); if(dropList!="country"){ dynaParams[dynaParams.length] = new Array("city", getForm().city.value); if(dropList!="city"){ dynaParams[dynaParams.length] = new Array("location", getForm().location.value); if(dropList!="location"){ dynaParams[dynaParams.length] = new Array("dropCountry", getForm().dropCountry.value); if(dropList!="dropCountry"){ dynaParams[dynaParams.length] = new Array("dropCity", getForm().dropCity.value); if(dropList!="dropCity"){ dynaParams[dynaParams.length] = new Array("dropLocation", getForm().dropLocation.value); if(dropList!="puYear"){ dynaParams[dynaParams.length] = new Array("puYear", getForm().puYear.value); if(dropList!="puMonth"){ dynaParams[dynaParams.length] = new Array("puMonth", getForm().puMonth.value); if(dropList!="puDay"){ dynaParams[dynaParams.length] = new Array("puDay", getForm().puDay.value); if(dropList!="puHour"){ dynaParams[dynaParams.length] = new Array("puHour", getForm().puHour.value); } } } } } } } } } /* Add debug parameter */ if(debug!=""){ dynaParams[dynaParams.length] = new Array("debug", "true"); } /* Get IE Version number */ var ua = navigator.userAgent; var MSIEOffset = ua.indexOf("MSIE "); var IEVerNum=6; if (MSIEOffset != -1){ IEVerNum=parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset))); } if (IEVerNum<5.5) { /* Encode each parameter */ for(var i=0; i < dynaParams.length; i++) { dynaParams[i][1] = escape(dynaParams[i][1]); } } var serverPart = ""; if(serverUrl!=null){ serverPart = serverUrl; } var dynaURL = makeUrl(serverPart+"/DynaDroplist.do;jsessionid=E2931B6959FD0AA2F0A704E6ACAB4551.node6", dynaParams); if(IEVerNum >= 5.5) { /* encode whole url */ dynaURL = encodeURI(dynaURL); } /* Show url to debug */ if(debug!=""){ alert(dynaURL); } return dynaURL; } function populateDroplists(dropList, serverUrl) { var dynaURL = makeDynaDroplistUrl(dropList, serverUrl); document.getElementById("dynaFrame").src = dynaURL; } function populateSecureDroplists(dropList, serverUrl) { var dynaURL = makeDynaDroplistUrl(dropList, serverUrl); var response=makeRequest(dynaURL); eval(response); } function makeRequest(url) { var req=false; var returnValue = ""; if(window.XMLHttpRequest) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } } else if(window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } } } if(req){ req.open("GET", url, false); req.send(null); if (req.readyState==4) { returnValue = req.responseText; } } return returnValue; } function addOption(droplist, name, value){ droplist.options[droplist.options.length] = new Option(name, value); }