Automatically exported from code.google.com/p/planningalerts
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

main.js 3.7 KiB

18 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. function previewMap(sAreaSize) {
  2. var sWarnings = "";
  3. //Check we have a valid postcode
  4. var sPostcode = document.getElementById('txtPostcode').value;
  5. if (sPostcode == ""){
  6. sWarnings = "Please enter a postcode";
  7. }else if (checkPostCode(sPostcode) ==false){
  8. sWarnings = "Sorry, the postcode you entered seems to be invalid";
  9. }
  10. if (sWarnings == ""){
  11. //hide any exisitng warnings
  12. hideWarning();
  13. document.getElementById('txtPostcode').className = document.getElementById('txtPostcode').className.replace(" error","");
  14. //build url and open new window
  15. var sUrl = 'preview.php?postcode=' + sPostcode + '&area_size=' + sAreaSize;
  16. document.open(sUrl,'name', 'width=515,height=490');
  17. }else{
  18. showWarning(sWarnings);
  19. document.getElementById('txtPostcode').className += " error";
  20. setFocus('txtPostcode');
  21. }
  22. }
  23. function checkPostCode (toCheck) {
  24. // Permitted letters depend upon their position in the postcode.
  25. var alpha1 = "[abcdefghijklmnoprstuwyz]"; // Character 1
  26. var alpha2 = "[abcdefghklmnopqrstuvwxy]"; // Character 2
  27. var alpha3 = "[abcdefghjkstuw]"; // Character 3
  28. var alpha4 = "[abehmnprvwxy]"; // Character 4
  29. var alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5
  30. // Array holds the regular expressions for the valid postcodes
  31. var pcexp = new Array ();
  32. pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  33. pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  34. pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  35. pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  36. pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  37. pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  38. // Load up the string to check
  39. var postCode = toCheck;
  40. var valid = false;
  41. // Check the string against the types of post codes
  42. for ( var i=0; i<pcexp.length; i++) {
  43. if (pcexp[i].test(postCode)) {
  44. // The post code is valid - split the post code into component parts
  45. pcexp[i].exec(postCode);
  46. // Copy it back into the original string, converting it to uppercase and
  47. // inserting a space between the inward and outward codes
  48. postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
  49. // If it is a BFPO c/o type postcode, tidy up the "c/o" part
  50. postCode = postCode.replace (/C\/O\s*/,"c/o ");
  51. // Load new postcode back into the form element
  52. valid = true;
  53. // Remember that we have found that the code is valid and break from loop
  54. break;
  55. }
  56. }
  57. // Return with either the reformatted valid postcode or the original invalid
  58. // postcode
  59. if (valid) {return postCode;} else return false;
  60. }
  61. function showWarning (sWarnings) {
  62. var sWarningHtml = '';
  63. if(sWarnings.indexOf('\n') > 0){
  64. var aWarnings = sWarnings.split('\n');
  65. sWarningHtml += '<ul>'
  66. for (var i=0;i<aWarnings.length -1;i++) {
  67. if (aWarnings[i]!= ''){
  68. sWarningHtml += '<li>' + aWarnings[i] + '</li>';
  69. }
  70. }
  71. sWarningHtml += '</ul>'
  72. }else{
  73. sWarningHtml = sWarnings;
  74. }
  75. var oWarning;
  76. oWarning = document.getElementById('divWarning');
  77. oWarning.innerHTML = sWarningHtml;
  78. window.scroll(0,0);
  79. oWarning.style.display = 'block'
  80. }
  81. function hideWarning(){
  82. oWarning = document.getElementById('divWarning');
  83. oWarning.innerHTML = "";
  84. oWarning.style.display = "none";
  85. }
  86. function setFocus (sID) {
  87. document.getElementById(sID).focus();
  88. }